diff --git a/plasmoid/package6/contents/ui/DirectoriesPage.qml b/plasmoid/package6/contents/ui/DirectoriesPage.qml index f2ba02a..2756605 100644 --- a/plasmoid/package6/contents/ui/DirectoriesPage.qml +++ b/plasmoid/package6/contents/ui/DirectoriesPage.qml @@ -191,8 +191,8 @@ ColumnLayout { } PlasmaExtras.MenuItem { id: showIgnorePatternsItem - text: qsTr("Show ignore patterns") - icon: "selection-symbolic" + text: qsTr("Show/edit ignore patterns") + icon: "document-edit" onClicked: directoryView.triggerNativeActionWithCurrentItemData( "showIgnorePatterns", "dirId_") visible: plasmoid.wipFeaturesEnabled diff --git a/syncthingwidgets/misc/otherdialogs.cpp b/syncthingwidgets/misc/otherdialogs.cpp index 00f4fba..fd9819d 100644 --- a/syncthingwidgets/misc/otherdialogs.cpp +++ b/syncthingwidgets/misc/otherdialogs.cpp @@ -167,47 +167,63 @@ TextViewDialog *ignorePatternsDialog(Data::SyncthingConnection &connection, cons auto *const dlg = new TextViewDialog(QCoreApplication::translate("QtGui::OtherDialogs", "Ignore patterns of folder \"%1\"").arg(dir.displayName()), parent); dlg->browser()->setText(QStringLiteral("Loading…")); - auto res = connection.ignores(dir.id, [dlg](Data::SyncthingIgnores &&ignores, QString &&errorMessage) { - auto *const browser = dlg->browser(); - browser->clear(); - if (!errorMessage.isEmpty()) { - browser->setText(errorMessage); - return; - } - for (const auto &ignore : ignores.ignore) { - browser->append(ignore); - } - browser->setUndoRedoEnabled(true); - browser->setReadOnly(false); + QObject::connect(dlg, &TextViewDialog::reload, dlg, [&connection, dirId = dir.id, dlg] { + dlg->browser()->setReadOnly(true); + auto res = connection.ignores(dirId, [dlg](Data::SyncthingIgnores &&ignores, QString &&errorMessage) { + auto *const browser = dlg->browser(); + browser->setUndoRedoEnabled(false); + browser->clear(); + browser->document()->clearUndoRedoStacks(); + if (!errorMessage.isEmpty()) { + browser->setText(errorMessage); + return; + } + for (const auto &ignore : ignores.ignore) { + browser->append(ignore); + } + browser->setUndoRedoEnabled(true); + browser->setReadOnly(false); + dlg->setProperty("savedRevision", browser->document()->revision()); + }); + QObject::connect(dlg, &QObject::destroyed, res.reply, &QNetworkReply::deleteLater); }); - dlg->setCloseHandler([&connection, dirId = dir.id, pending = false](TextViewDialog *textViewDlg) mutable { - if (pending) { - return true; - } - auto *const browser = textViewDlg->browser(); - if (!browser->document()->isUndoAvailable() - || QMessageBox::question( - textViewDlg, textViewDlg->windowTitle(), QCoreApplication::translate("QtGui::OtherDialogs", "Do you want to save the changes?")) - != QMessageBox::Yes) { - return false; - } + emit dlg->reload(); + QObject::connect(dlg, &TextViewDialog::save, dlg, [&connection, dirId = dir.id, dlg] { + dlg->setProperty("isSaving", true); + auto *const browser = dlg->browser(); auto newIgnores = SyncthingIgnores{ .ignore = browser->toPlainText().split(QChar('\n')), .expanded = QStringList() }; - auto setRes = connection.setIgnores(dirId, newIgnores, [textViewDlg, &pending](const QString &error) { + auto setRes = connection.setIgnores(dirId, newIgnores, [dlg](const QString &error) { if (error.isEmpty()) { QMessageBox::information( - nullptr, textViewDlg->windowTitle(), QCoreApplication::translate("QtGui::OtherDialogs", "Ignore patterns have been changed.")); - textViewDlg->setCloseHandler(std::function()); - textViewDlg->close(); + nullptr, dlg->windowTitle(), QCoreApplication::translate("QtGui::OtherDialogs", "Ignore patterns have been changed.")); + if (dlg->property("isClosing").toBool()) { + dlg->setCloseHandler(std::function()); + dlg->close(); + } } else { - QMessageBox::critical(nullptr, textViewDlg->windowTitle(), - QCoreApplication::translate("QtGui::OtherDialogs", "Unable to save ignore patterns: %1").arg(error)); - pending = false; + QMessageBox::critical( + nullptr, dlg->windowTitle(), QCoreApplication::translate("QtGui::OtherDialogs", "Unable to save ignore patterns: %1").arg(error)); } + dlg->setProperty("isSaving", false); + dlg->setProperty("savedRevision", dlg->browser()->document()->revision()); }); - QObject::connect(textViewDlg, &QObject::destroyed, setRes.reply, &QNetworkReply::deleteLater); - return pending = true; + QObject::connect(dlg, &QObject::destroyed, setRes.reply, &QNetworkReply::deleteLater); + }); + dlg->setCloseHandler([](TextViewDialog *textViewDlg) { + textViewDlg->setProperty("isClosing", true); + if (textViewDlg->property("isSaving").toBool()) { + return true; + } + if (textViewDlg->browser()->document()->revision() <= textViewDlg->property("savedRevision").toInt()) { + return false; + } + const auto question = QMessageBox::question( + textViewDlg, textViewDlg->windowTitle(), QCoreApplication::translate("QtGui::OtherDialogs", "Do you want to save the changes?")); + if (question == QMessageBox::Yes) { + emit textViewDlg->save(); + } + return question != QMessageBox::No; }); - QObject::connect(dlg, &QObject::destroyed, res.reply, &QNetworkReply::deleteLater); return dlg; } diff --git a/syncthingwidgets/misc/textviewdialog.cpp b/syncthingwidgets/misc/textviewdialog.cpp index 993715e..cd8433c 100644 --- a/syncthingwidgets/misc/textviewdialog.cpp +++ b/syncthingwidgets/misc/textviewdialog.cpp @@ -82,6 +82,11 @@ void TextViewDialog::keyPressEvent(QKeyEvent *event) case Qt::Key_F5: emit reload(); break; + case Qt::Key_S: + if (event->modifiers() == Qt::ControlModifier) { + emit save(); + } + break; default:; } } diff --git a/syncthingwidgets/misc/textviewdialog.h b/syncthingwidgets/misc/textviewdialog.h index c63f835..8e85efd 100644 --- a/syncthingwidgets/misc/textviewdialog.h +++ b/syncthingwidgets/misc/textviewdialog.h @@ -31,6 +31,7 @@ public: Q_SIGNALS: void reload(); + void save(); protected: void keyPressEvent(QKeyEvent *event) override; diff --git a/tray/CMakeLists.txt b/tray/CMakeLists.txt index 6325743..e4782ce 100644 --- a/tray/CMakeLists.txt +++ b/tray/CMakeLists.txt @@ -50,6 +50,7 @@ set(REQUIRED_ICONS dialog-cancel dialog-ok dialog-ok-apply + document-edit document-open document-open-remote download @@ -89,7 +90,6 @@ set(REQUIRED_ICONS preferences-other process-stop qtcreator - selection-symbolic system-run system-search system-file-manager diff --git a/tray/gui/dirview.cpp b/tray/gui/dirview.cpp index 350dbae..a9a3970 100644 --- a/tray/gui/dirview.cpp +++ b/tray/gui/dirview.cpp @@ -109,7 +109,7 @@ void DirView::showContextMenu(const QPoint &position) QIcon(QStringLiteral(":/icons/hicolor/scalable/places/document-open-remote.svg"))), tr("Browse remote files")), &QAction::triggered, triggerActionForSelectedRow(this, &DirView::browseRemoteFiles)); - connect(menu.addAction(QIcon::fromTheme(QStringLiteral("selection-symbolic")), tr("Show ignore patterns")), &QAction::triggered, + connect(menu.addAction(QIcon::fromTheme(QStringLiteral("document-edit")), tr("Show/edit ignore patterns")), &QAction::triggered, triggerActionForSelectedRow(this, &DirView::showIgnorePatterns)); } }