From baf21362e165ce642c47d2a312336e28a16e32f3 Mon Sep 17 00:00:00 2001 From: Doc West Date: Wed, 4 Jul 2018 21:47:16 +0200 Subject: [PATCH] Fixed undo / redo actions losing their shortcuts --- apps/opencs/view/doc/view.cpp | 22 +++++++++++++++++++++- apps/opencs/view/doc/view.hpp | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 10de46e06..f4d9b8ede 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -101,15 +102,34 @@ void CSVDoc::View::setupFileMenu() file->addAction(exit); } +static void updateUndoRedoAction(QAction *action, const std::string &settingsKey) +{ + QKeySequence seq; + CSMPrefs::State::get().getShortcutManager().getSequence(settingsKey, seq); + action->setShortcut(seq); +} + +void CSVDoc::View::undoActionChanged() +{ + updateUndoRedoAction(mUndo, "document-edit-undo"); +} + +void CSVDoc::View::redoActionChanged() +{ + updateUndoRedoAction(mRedo, "document-edit-redo"); +} + void CSVDoc::View::setupEditMenu() { QMenu *edit = menuBar()->addMenu (tr ("Edit")); mUndo = mDocument->getUndoStack().createUndoAction (this, tr("Undo")); setupShortcut("document-edit-undo", mUndo); + connect(mUndo, SIGNAL (changed ()), this, SLOT (undoActionChanged ())); edit->addAction (mUndo); - mRedo= mDocument->getUndoStack().createRedoAction (this, tr("Redo")); + mRedo = mDocument->getUndoStack().createRedoAction (this, tr("Redo")); + connect(mRedo, SIGNAL (changed ()), this, SLOT (redoActionChanged ())); setupShortcut("document-edit-redo", mRedo); edit->addAction (mRedo); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 46aa87891..5418b7720 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -152,6 +152,10 @@ namespace CSVDoc void settingChanged (const CSMPrefs::Setting *setting); + void undoActionChanged(); + + void redoActionChanged(); + void newView(); void save();