Commit 3f9e76af authored by Henrik Fehlauer's avatar Henrik Fehlauer

Fix ambiguous shortcut warning when pressing save shortcuts

Summary:
When {nav Remember last used save mode} is enabled, pressing
{key Ctrl S} or {key Ctrl Shift S} repeatedly would result in a
ambiguous shortcut warning dialog.

This is because on every save the action was re-added to the dropdown
button, resulting in multiple shortcuts. It should be enough to set the
actions once, and then only swap the default action.

BUG: 389691

Depends on D10468
Ref T7841

Test Plan:
Press {key Ctrl S} twice, no warning dialog is shown anymore.
Both {nav Save} options still work as before and the last-used button is
set as the default.

Reviewers: #spectacle, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: ngraham

Maniphest Tasks: T7841

Differential Revision: https://phabricator.kde.org/D10469
parent 0e04f7de
......@@ -61,6 +61,8 @@ KSMainWindow::KSMainWindow(bool onClickAvailable, QWidget *parent) :
mClipboardButton(new QToolButton),
mSaveButton(new QToolButton),
mSaveMenu(new QMenu),
mSaveAsAction(new QAction),
mSaveAction(new QAction),
mMessageWidget(new KMessageWidget),
mToolsMenu(new QMenu),
mExportMenu(new ExportMenu(this)),
......@@ -163,14 +165,19 @@ void KSMainWindow::init()
mSaveButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mSaveButton->setMenu(mSaveMenu);
mSaveButton->setPopupMode(QToolButton::MenuButtonPopup);
buildSaveMenu();
mDialogButtonBox->addButton(mSaveButton, QDialogButtonBox::ActionRole);
// the help menu
KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
mDialogButtonBox->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu());
// the save menu
mSaveAsAction = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this);
mSaveAction = KStandardAction::save(this, &KSMainWindow::save, this);
mSaveMenu->addAction(mSaveAsAction);
mSaveMenu->addAction(mSaveAction);
setDefaultSaveAction();
// message widget
connect(mMessageWidget, &KMessageWidget::linkActivated, this, [](const QString &str) { QDesktopServices::openUrl(QUrl(str)); } );
......@@ -222,24 +229,14 @@ int KSMainWindow::windowWidth(const QPixmap &pixmap) const
return alignedWindowWidth;
}
void KSMainWindow::buildSaveMenu()
void KSMainWindow::setDefaultSaveAction()
{
// first clear the menu
mSaveMenu->clear();
// get our actions in order
QAction *actionSave = KStandardAction::save(this, &KSMainWindow::save, this);
QAction *actionSaveAs = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this);
mSaveMenu->addAction(actionSaveAs);
mSaveMenu->addAction(actionSave);
// put the actions in order
switch (saveButtonMode()) {
case SaveMode::SaveAs:
mSaveButton->setDefaultAction(actionSaveAs);
mSaveButton->setDefaultAction(mSaveAsAction);
break;
case SaveMode::Save:
mSaveButton->setDefaultAction(actionSave);
mSaveButton->setDefaultAction(mSaveAction);
break;
}
}
......@@ -341,7 +338,7 @@ void KSMainWindow::setScreenshotWindowTitle(QUrl location)
void KSMainWindow::save()
{
SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save);
buildSaveMenu();
setDefaultSaveAction();
if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) {
ExportManager::instance()->doSave(QUrl(), true);
......@@ -356,7 +353,7 @@ void KSMainWindow::save()
void KSMainWindow::saveAs()
{
SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs);
buildSaveMenu();
setDefaultSaveAction();
if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) {
if (ExportManager::instance()->doSaveAs(this, true)) {
......
......@@ -54,7 +54,7 @@ class KSMainWindow : public QDialog
void showImageSharedFeedback(bool error, const QString &message);
void sendToClipboard();
void init();
void buildSaveMenu();
void setDefaultSaveAction();
void save();
void saveAs();
int windowWidth(const QPixmap &pixmap) const;
......@@ -84,6 +84,8 @@ class KSMainWindow : public QDialog
QToolButton *mClipboardButton;
QToolButton *mSaveButton;
QMenu *mSaveMenu;
QAction *mSaveAsAction;
QAction *mSaveAction;
KMessageWidget *mMessageWidget;
QMenu *mToolsMenu;
ExportMenu *mExportMenu;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment