feat: new folder new interaction, no popup dialog
This commit is contained in:
parent
add106c57d
commit
f7ff4e1c77
5 changed files with 64 additions and 4 deletions
|
@ -105,6 +105,7 @@ FolderModel::FolderModel(QObject *parent)
|
||||||
, m_viewAdapter(nullptr)
|
, m_viewAdapter(nullptr)
|
||||||
, m_mimeAppManager(MimeAppManager::self())
|
, m_mimeAppManager(MimeAppManager::self())
|
||||||
, m_sizeJob(nullptr)
|
, m_sizeJob(nullptr)
|
||||||
|
, m_currentIndex(-1)
|
||||||
{
|
{
|
||||||
QSettings settings("cutefishos", qApp->applicationName());
|
QSettings settings("cutefishos", qApp->applicationName());
|
||||||
m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool();
|
m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool();
|
||||||
|
@ -144,6 +145,8 @@ FolderModel::FolderModel(QObject *parent)
|
||||||
|
|
||||||
// Position dropped items at the desired target position.
|
// Position dropped items at the desired target position.
|
||||||
connect(this, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) {
|
connect(this, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) {
|
||||||
|
QModelIndex changeIdx;
|
||||||
|
|
||||||
for (int i = first; i <= last; ++i) {
|
for (int i = first; i <= last; ++i) {
|
||||||
const auto idx = index(i, 0, parent);
|
const auto idx = index(i, 0, parent);
|
||||||
const auto url = itemForIndex(idx).url();
|
const auto url = itemForIndex(idx).url();
|
||||||
|
@ -153,7 +156,19 @@ FolderModel::FolderModel(QObject *parent)
|
||||||
m_dropTargetPositions.erase(it);
|
m_dropTargetPositions.erase(it);
|
||||||
Q_EMIT move(pos.x(), pos.y(), {url});
|
Q_EMIT move(pos.x(), pos.y(), {url});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (url == m_newDocumentUrl) {
|
||||||
|
changeIdx = idx;
|
||||||
|
m_newDocumentUrl.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, [=] {
|
||||||
|
if (changeIdx.isValid()) {
|
||||||
|
setSelected(changeIdx.row());
|
||||||
|
emit requestRename();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -334,6 +349,11 @@ KFileItem FolderModel::itemForIndex(const QModelIndex &index) const
|
||||||
return m_dirModel->itemForIndex(mapToSource(index));
|
return m_dirModel->itemForIndex(mapToSource(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex FolderModel::indexForUrl(const QUrl &url) const
|
||||||
|
{
|
||||||
|
return m_dirModel->indexForUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
KFileItem FolderModel::fileItem(int index) const
|
KFileItem FolderModel::fileItem(int index) const
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < count()) {
|
if (index >= 0 && index < count()) {
|
||||||
|
@ -357,6 +377,11 @@ QList<QUrl> FolderModel::selectedUrls() const
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FolderModel::currentIndex() const
|
||||||
|
{
|
||||||
|
return m_currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
QString FolderModel::url() const
|
QString FolderModel::url() const
|
||||||
{
|
{
|
||||||
return m_url;
|
return m_url;
|
||||||
|
@ -797,6 +822,9 @@ void FolderModel::setSelected(int row)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_selectionModel->select(index(row, 0), QItemSelectionModel::Select);
|
m_selectionModel->select(index(row, 0), QItemSelectionModel::Select);
|
||||||
|
m_currentIndex = row;
|
||||||
|
|
||||||
|
emit currentIndexChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderModel::selectAll()
|
void FolderModel::selectAll()
|
||||||
|
@ -866,9 +894,24 @@ void FolderModel::unpinSelection()
|
||||||
|
|
||||||
void FolderModel::newFolder()
|
void FolderModel::newFolder()
|
||||||
{
|
{
|
||||||
CreateFolderDialog *dlg = new CreateFolderDialog;
|
QString rootPath = rootItem().url().toString();
|
||||||
dlg->setPath(rootItem().url().toString());
|
QString baseName = tr("New Folder");
|
||||||
dlg->show();
|
QString newName = baseName;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (true) {
|
||||||
|
if (QFile::exists(rootItem().url().toLocalFile() + "/" + newName)) {
|
||||||
|
++i;
|
||||||
|
newName = QString("%1%2").arg(baseName).arg(QString::number(i));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_newDocumentUrl = QUrl(rootItem().url().toString() + "/" + newName);
|
||||||
|
|
||||||
|
auto job = KIO::mkdir(QUrl(rootItem().url().toString() + "/" + newName));
|
||||||
|
job->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderModel::rename(int row, const QString &name)
|
void FolderModel::rename(int row, const QString &name)
|
||||||
|
|
|
@ -61,6 +61,7 @@ class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus
|
||||||
Q_PROPERTY(QStringList filterMimeTypes READ filterMimeTypes WRITE setFilterMimeTypes NOTIFY filterMimeTypesChanged)
|
Q_PROPERTY(QStringList filterMimeTypes READ filterMimeTypes WRITE setFilterMimeTypes NOTIFY filterMimeTypesChanged)
|
||||||
Q_PROPERTY(QString selectedItemSize READ selectedItemSize NOTIFY selectedItemSizeChanged)
|
Q_PROPERTY(QString selectedItemSize READ selectedItemSize NOTIFY selectedItemSizeChanged)
|
||||||
Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles NOTIFY showHiddenFilesChanged)
|
Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles NOTIFY showHiddenFilesChanged)
|
||||||
|
Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum DataRole {
|
enum DataRole {
|
||||||
|
@ -113,11 +114,14 @@ public:
|
||||||
|
|
||||||
int indexForKeyboardSearch(const QString &text, int startFromIndex = 0) const;
|
int indexForKeyboardSearch(const QString &text, int startFromIndex = 0) const;
|
||||||
KFileItem itemForIndex(const QModelIndex &index) const;
|
KFileItem itemForIndex(const QModelIndex &index) const;
|
||||||
|
QModelIndex indexForUrl(const QUrl &url) const;
|
||||||
|
|
||||||
KFileItem fileItem(int index) const;
|
KFileItem fileItem(int index) const;
|
||||||
|
|
||||||
QList<QUrl> selectedUrls() const;
|
QList<QUrl> selectedUrls() const;
|
||||||
|
|
||||||
|
int currentIndex() const;
|
||||||
|
|
||||||
QString url() const;
|
QString url() const;
|
||||||
void setUrl(const QString &url);
|
void setUrl(const QString &url);
|
||||||
|
|
||||||
|
@ -250,6 +254,8 @@ signals:
|
||||||
void notification(const QString &message);
|
void notification(const QString &message);
|
||||||
void move(int x, int y, QList<QUrl> urls);
|
void move(int x, int y, QList<QUrl> urls);
|
||||||
|
|
||||||
|
void currentIndexChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void dragSelectedInternal(int x, int y);
|
void dragSelectedInternal(int x, int y);
|
||||||
|
@ -276,6 +282,7 @@ private:
|
||||||
QItemSelectionModel *m_selectionModel;
|
QItemSelectionModel *m_selectionModel;
|
||||||
QItemSelection m_pinnedSelection;
|
QItemSelection m_pinnedSelection;
|
||||||
QString m_url;
|
QString m_url;
|
||||||
|
QUrl m_newDocumentUrl;
|
||||||
|
|
||||||
Status m_status;
|
Status m_status;
|
||||||
int m_sortMode;
|
int m_sortMode;
|
||||||
|
@ -312,6 +319,8 @@ private:
|
||||||
MimeAppManager *m_mimeAppManager;
|
MimeAppManager *m_mimeAppManager;
|
||||||
|
|
||||||
CFileSizeJob *m_sizeJob;
|
CFileSizeJob *m_sizeJob;
|
||||||
|
|
||||||
|
int m_currentIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FOLDERMODEL_H
|
#endif // FOLDERMODEL_H
|
||||||
|
|
|
@ -47,6 +47,10 @@ Item {
|
||||||
isDesktop: true
|
isDesktop: true
|
||||||
sortMode: -1
|
sortMode: -1
|
||||||
viewAdapter: viewAdapter
|
viewAdapter: viewAdapter
|
||||||
|
|
||||||
|
onCurrentIndexChanged: {
|
||||||
|
_folderView.currentIndex = dirModel.currentIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FM.ItemViewAdapter {
|
FM.ItemViewAdapter {
|
||||||
|
|
|
@ -53,7 +53,6 @@ ListView {
|
||||||
|
|
||||||
signal keyPress(var event)
|
signal keyPress(var event)
|
||||||
|
|
||||||
currentIndex: -1
|
|
||||||
clip: true
|
clip: true
|
||||||
cacheBuffer: width
|
cacheBuffer: width
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,11 @@ Item {
|
||||||
else
|
else
|
||||||
dirModel.url = dirModel.homePath()
|
dirModel.url = dirModel.homePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For new folder rename.
|
||||||
|
onCurrentIndexChanged: {
|
||||||
|
_viewLoader.item.currentIndex = dirModel.currentIndex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
|
Loading…
Reference in a new issue