fix: delete dialog

This commit is contained in:
kate 2022-01-01 12:20:58 +08:00
parent 8319832a92
commit 7998c3d94f
3 changed files with 41 additions and 26 deletions

View file

@ -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());
}

View file

@ -326,6 +326,8 @@ private:
CFileSizeJob *m_sizeJob;
int m_currentIndex;
QTimer *m_updateNeedSelectTimer;
};
#endif // FOLDERMODEL_H

View file

@ -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