diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 876498bbcffec..f9c6dc4deef98 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -420,26 +420,25 @@ 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; } - 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(); } @@ -455,6 +454,14 @@ void AccountSettings::slotOpenMakeFolderDialog() const auto folderCreationDialog = new FolderCreationDialog(fileName, this); folderCreationDialog->setAttribute(Qt::WA_DeleteOnClose); folderCreationDialog->open(); + +#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, &FolderCreationDialog::folderCreated, this, [folder, fileName](const QString &fullFolderPath) { + folder->slotWatchedPathChanged(fullFolderPath, Folder::ChangeReason::Other); + }); +#endif } } 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;