Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Create new folder" menu entries in settings not working correctly on macOS #5435

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/gui/foldercreationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/foldercreationdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down