From 6c548145a25845fc7d5fc4fb21f28a43f9072c0c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 13 Feb 2023 18:50:35 +0100 Subject: [PATCH 1/4] Make sure to manually call folderwatcher when creating new folder from settings menu in macOS Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 876498bbcffec..9400cbb882ac2 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -420,14 +420,14 @@ void AccountSettings::slotEditCurrentIgnoredFiles() void AccountSettings::slotOpenMakeFolderDialog() { - const auto &selected = _ui->_folderList->selectionModel()->currentIndex(); + const auto selected = _ui->_folderList->selectionModel()->currentIndex(); if (!selected.isValid()) { qCWarning(lcAccountSettings) << "Selection model current folder index is not valid."; return; } - const auto &classification = _model->classify(selected); + const auto classification = _model->classify(selected); if (classification != FolderStatusModel::SubFolder && classification != FolderStatusModel::RootFolder) { return; @@ -455,6 +455,13 @@ void AccountSettings::slotOpenMakeFolderDialog() const auto folderCreationDialog = new FolderCreationDialog(fileName, this); folderCreationDialog->setAttribute(Qt::WA_DeleteOnClose); folderCreationDialog->open(); + + const auto folder = _model->infoForIndex(selected)->_folder; +#ifdef Q_OS_MAC + // The macOS FolderWatcher cannot detect file and folder changes made by the watching process -- us. + // So we need to manually invoke the slot that is called by watched folder changes. + connect(folderCreationDialog, &QDialog::finished, this, [folder, fileName] { folder->slotWatchedPathChanged(fileName, Folder::ChangeReason::Other); }); +#endif } } From 89d302264966de8c74614787800bedbe7e6c16ed Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 13 Feb 2023 19:37:12 +0100 Subject: [PATCH 2/4] Do not search for folder twice Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 9400cbb882ac2..77aba9dd0e116 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -433,13 +433,12 @@ void AccountSettings::slotOpenMakeFolderDialog() return; } - const auto fileName = [this, &selected, &classification] { + const auto folder = _model->infoForIndex(selected)->_folder; + Q_ASSERT(folder); + const auto fileName = [selected, classification, folder, this] { QString result; if (classification == FolderStatusModel::RootFolder) { - const auto alias = _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString(); - if (const auto folder = FolderMan::instance()->folder(alias)) { - result = folder->path(); - } + result = folder->path(); } else { result = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString(); } @@ -456,7 +455,6 @@ void AccountSettings::slotOpenMakeFolderDialog() folderCreationDialog->setAttribute(Qt::WA_DeleteOnClose); folderCreationDialog->open(); - const auto folder = _model->infoForIndex(selected)->_folder; #ifdef Q_OS_MAC // The macOS FolderWatcher cannot detect file and folder changes made by the watching process -- us. // So we need to manually invoke the slot that is called by watched folder changes. From 30ce2eab021fc11500d3c36dc6c87b14f350f69e Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 13 Feb 2023 19:42:43 +0100 Subject: [PATCH 3/4] Notify when folder is created with full folder path in FolderCreationDialog Signed-off-by: Claudio Cambra --- src/gui/foldercreationdialog.cpp | 8 ++++++-- src/gui/foldercreationdialog.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/foldercreationdialog.cpp b/src/gui/foldercreationdialog.cpp index 6b2944a1faaa7..a245c9f4dc461 100644 --- a/src/gui/foldercreationdialog.cpp +++ b/src/gui/foldercreationdialog.cpp @@ -67,12 +67,16 @@ void FolderCreationDialog::accept() { Q_ASSERT(!_destination.endsWith('/')); - if (QDir(_destination + "/" + ui->newFolderNameEdit->text()).exists()) { + const auto fullPath = QString(_destination + "/" + ui->newFolderNameEdit->text()); + + if (QDir(fullPath).exists()) { ui->labelErrorMessage->setVisible(true); return; } - if (!QDir(_destination).mkdir(ui->newFolderNameEdit->text())) { + if (QDir(_destination).mkdir(ui->newFolderNameEdit->text())) { + Q_EMIT folderCreated(fullPath); + } else { QMessageBox::critical(this, tr("Error"), tr("Could not create a folder! Check your write permissions.")); } diff --git a/src/gui/foldercreationdialog.h b/src/gui/foldercreationdialog.h index 3786b9f51018e..3d8642112f2c4 100644 --- a/src/gui/foldercreationdialog.h +++ b/src/gui/foldercreationdialog.h @@ -31,6 +31,9 @@ class FolderCreationDialog : public QDialog explicit FolderCreationDialog(const QString &destination, QWidget *parent = nullptr); ~FolderCreationDialog() override; +signals: + void folderCreated(const QString &fullFolderPath); + private slots: void accept() override; From 69d73d1333e702a28fadeae9be9fa0b0265c13ef Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 13 Feb 2023 19:45:16 +0100 Subject: [PATCH 4/4] Respond to folder creation at specific creation path on macOS Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 77aba9dd0e116..f9c6dc4deef98 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -458,7 +458,9 @@ void AccountSettings::slotOpenMakeFolderDialog() #ifdef Q_OS_MAC // The macOS FolderWatcher cannot detect file and folder changes made by the watching process -- us. // So we need to manually invoke the slot that is called by watched folder changes. - connect(folderCreationDialog, &QDialog::finished, this, [folder, fileName] { folder->slotWatchedPathChanged(fileName, Folder::ChangeReason::Other); }); + connect(folderCreationDialog, &FolderCreationDialog::folderCreated, this, [folder, fileName](const QString &fullFolderPath) { + folder->slotWatchedPathChanged(fullFolderPath, Folder::ChangeReason::Other); + }); #endif } }