From 7998c3d94f67a19d187674fd8514e881600211b4 Mon Sep 17 00:00:00 2001 From: kate Date: Sat, 1 Jan 2022 12:20:58 +0800 Subject: [PATCH] fix: delete dialog --- model/foldermodel.cpp | 38 ++++++++++++++++++++---------------- model/foldermodel.h | 2 ++ qml/Dialogs/DeleteDialog.qml | 27 ++++++++++++++++--------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 27074a4..a3cc779 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -25,6 +25,7 @@ #include "foldermodel.h" #include "dirlister.h" +#include "window.h" #include "../dialogs/filepropertiesdialog.h" #include "../dialogs/createfolderdialog.h" @@ -106,10 +107,15 @@ FolderModel::FolderModel(QObject *parent) , m_mimeAppManager(MimeAppManager::self()) , m_sizeJob(nullptr) , m_currentIndex(-1) + , m_updateNeedSelectTimer(new QTimer(this)) { QSettings settings("cutefishos", qApp->applicationName()); m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool(); + m_updateNeedSelectTimer->setSingleShot(true); + m_updateNeedSelectTimer->setInterval(500); + connect(m_updateNeedSelectTimer, &QTimer::timeout, this, &FolderModel::updateNeedSelectUrls); + m_dirLister = new DirLister(this); m_dirLister->setDelayedMimeTypes(true); m_dirLister->setAutoErrorHandlingEnabled(false, nullptr); @@ -973,7 +979,7 @@ void FolderModel::paste() } KIO::Job *job = KIO::paste(data, m_dirModel->dirLister()->url()); - connect(job, &KIO::Job::finished, this, &FolderModel::delayUpdateNeedSelectUrls); + // connect(job, &KIO::Job::finished, this, &FolderModel::delayUpdateNeedSelectUrls); job->start(); // Clear system clipboard. @@ -1371,22 +1377,9 @@ void FolderModel::openChangeWallpaperDialog() void FolderModel::openDeleteDialog() { - QQuickView *view = new QQuickView; - view->setModality(Qt::ApplicationModal); - view->setFlags(Qt::Dialog); - view->setTitle(tr("File Manager")); - view->setResizeMode(QQuickView::SizeRootObjectToView); - view->setSource(QUrl("qrc:/qml/Dialogs/DeleteDialog.qml")); - view->rootContext()->setContextProperty("model", this); - view->rootContext()->setContextProperty("view", view); - - connect(view, &QQuickView::visibleChanged, this, [=] { - if (!view->isVisible()) { - view->deleteLater(); - } - }); - - view->show(); + Window *w = new Window; + w->load(QUrl("qrc:/qml/Dialogs/DeleteDialog.qml")); + w->rootContext()->setContextProperty("model", this); } void FolderModel::openInNewWindow(const QString &url) @@ -1578,6 +1571,10 @@ void FolderModel::dragSelectedInternal(int x, int y) void FolderModel::onRowsInserted(const QModelIndex &parent, int first, int last) { + if (m_updateNeedSelectTimer->isActive()) { + m_updateNeedSelectTimer->stop(); + } + QModelIndex changeIdx; for (int i = first; i <= last; ++i) { @@ -1602,6 +1599,8 @@ void FolderModel::onRowsInserted(const QModelIndex &parent, int first, int last) emit requestRename(); } }); + + m_updateNeedSelectTimer->start(); } void FolderModel::delayUpdateNeedSelectUrls() @@ -1624,6 +1623,11 @@ void FolderModel::updateNeedSelectUrls() m_needSelectUrls.clear(); + // If the selected item already exists, clear it immediately. + if (!needSelectList.isEmpty()) { + clearSelection(); + } + for (const QModelIndex &idx : needSelectList) { setSelected(idx.row()); } diff --git a/model/foldermodel.h b/model/foldermodel.h index 078f6cf..351a827 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -326,6 +326,8 @@ private: CFileSizeJob *m_sizeJob; int m_currentIndex; + + QTimer *m_updateNeedSelectTimer; }; #endif // FOLDERMODEL_H diff --git a/qml/Dialogs/DeleteDialog.qml b/qml/Dialogs/DeleteDialog.qml index 58e5306..4207f47 100644 --- a/qml/Dialogs/DeleteDialog.qml +++ b/qml/Dialogs/DeleteDialog.qml @@ -24,16 +24,25 @@ import QtQuick.Layouts 1.12 import FishUI 1.0 as FishUI import Cutefish.FileManager 1.0 -Item { +FishUI.Window { id: control - width: 300 + FishUI.Units.largeSpacing * 2 - height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 2 + flags: Qt.Dialog | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint + minimizeButtonVisible: false + visible: true - Rectangle { - anchors.fill: parent - color: FishUI.Theme.secondBackgroundColor - } + width: contentWidth + height: contentHeight + + minimumWidth: contentWidth + minimumHeight: contentHeight + maximumWidth: contentWidth + maximumHeight: contentHeight + + property var contentWidth: _mainLayout.implicitWidth + FishUI.Units.largeSpacing * 2 + property var contentHeight: _mainLayout.implicitHeight + control.header.height + FishUI.Units.largeSpacing * 2 + + background.color: FishUI.Theme.secondBackgroundColor ColumnLayout { id: _mainLayout @@ -55,7 +64,7 @@ Item { Button { text: qsTr("Cancel") Layout.fillWidth: true - onClicked: view.close() + onClicked: control.close() } Button { @@ -63,7 +72,7 @@ Item { focus: true Layout.fillWidth: true onClicked: { - view.close() + control.close() model.deleteSelected() } flat: true