diff --git a/src/lib_gui/qt/element/QtUndoRedo.cpp b/src/lib_gui/qt/element/QtUndoRedo.cpp index 043ece44..b37b0024 100644 --- a/src/lib_gui/qt/element/QtUndoRedo.cpp +++ b/src/lib_gui/qt/element/QtUndoRedo.cpp @@ -58,14 +58,14 @@ void QtUndoRedo::redo() void QtUndoRedo::setUndoButtonEnabled(bool enabled) { m_undoButton->setEnabled(enabled); - QtContextMenu::enableUndo(enabled); + QtContextMenu::getInstance()->enableUndo(enabled); } void QtUndoRedo::setRedoButtonEnabled(bool enabled) { m_redoButton->setEnabled(enabled); - QtContextMenu::enableRedo(enabled); + QtContextMenu::getInstance()->enableRedo(enabled); } void QtUndoRedo::refreshStyle() diff --git a/src/lib_gui/qt/utility/QtContextMenu.cpp b/src/lib_gui/qt/utility/QtContextMenu.cpp index 177de73a..78c9e350 100644 --- a/src/lib_gui/qt/utility/QtContextMenu.cpp +++ b/src/lib_gui/qt/utility/QtContextMenu.cpp @@ -23,30 +23,7 @@ QtContextMenu::QtContextMenu(QContextMenuEvent* event, QWidget* origin) : m_menu(origin) , m_point(event->globalPos()) { - if (!s_instance) - { - s_instance = new QtContextMenu(); - - s_undoAction = new QAction(tr("Back"), s_instance); - s_undoAction->setStatusTip(tr("Go back to last active symbol")); - s_undoAction->setToolTip(tr("Go back to last active symbol")); - connect(s_undoAction, SIGNAL(triggered()), s_instance, SLOT(undoActionTriggered())); - - s_redoAction = new QAction(tr("Forward"), s_instance); - s_redoAction->setStatusTip(tr("Go forward to next active symbol")); - s_redoAction->setToolTip(tr("Go forward to next active symbol")); - connect(s_redoAction, SIGNAL(triggered()), s_instance, SLOT(redoActionTriggered())); - - s_copyFullPathAction = new QAction(tr("Copy Full Path"), s_instance); - s_copyFullPathAction->setStatusTip(tr("Copies the path of this file to the clipboard")); - s_copyFullPathAction->setToolTip(tr("Copies the path of this file to the clipboard")); - connect(s_copyFullPathAction, SIGNAL(triggered()), s_instance, SLOT(copyFullPathActionTriggered())); - - s_openContainingFolderAction = new QAction(tr("Open Containing Folder"), s_instance); - s_openContainingFolderAction->setStatusTip(tr("Opens the folder that contains this file")); - s_openContainingFolderAction->setToolTip(tr("Opens the folder that contains this file")); - connect(s_openContainingFolderAction, SIGNAL(triggered()), s_instance, SLOT(openContainingFolderActionTriggered())); - } + getInstance(); addUndoActions(); } @@ -80,6 +57,36 @@ void QtContextMenu::addFileActions(FilePath filePath) addAction(s_openContainingFolderAction); } +QtContextMenu* QtContextMenu::getInstance() +{ + if (!s_instance) + { + s_instance = new QtContextMenu(); + + s_undoAction = new QAction(tr("Back"), s_instance); + s_undoAction->setStatusTip(tr("Go back to last active symbol")); + s_undoAction->setToolTip(tr("Go back to last active symbol")); + connect(s_undoAction, SIGNAL(triggered()), s_instance, SLOT(undoActionTriggered())); + + s_redoAction = new QAction(tr("Forward"), s_instance); + s_redoAction->setStatusTip(tr("Go forward to next active symbol")); + s_redoAction->setToolTip(tr("Go forward to next active symbol")); + connect(s_redoAction, SIGNAL(triggered()), s_instance, SLOT(redoActionTriggered())); + + s_copyFullPathAction = new QAction(tr("Copy Full Path"), s_instance); + s_copyFullPathAction->setStatusTip(tr("Copies the path of this file to the clipboard")); + s_copyFullPathAction->setToolTip(tr("Copies the path of this file to the clipboard")); + connect(s_copyFullPathAction, SIGNAL(triggered()), s_instance, SLOT(copyFullPathActionTriggered())); + + s_openContainingFolderAction = new QAction(tr("Open Containing Folder"), s_instance); + s_openContainingFolderAction->setStatusTip(tr("Opens the folder that contains this file")); + s_openContainingFolderAction->setToolTip(tr("Opens the folder that contains this file")); + connect(s_openContainingFolderAction, SIGNAL(triggered()), s_instance, SLOT(openContainingFolderActionTriggered())); + } + + return s_instance; +} + void QtContextMenu::addSeparator() { m_menu.addSeparator(); diff --git a/src/lib_gui/qt/utility/QtContextMenu.h b/src/lib_gui/qt/utility/QtContextMenu.h index 8440da6d..0ab2d1fb 100644 --- a/src/lib_gui/qt/utility/QtContextMenu.h +++ b/src/lib_gui/qt/utility/QtContextMenu.h @@ -21,12 +21,14 @@ public: void addUndoActions(); void addFileActions(FilePath filePath); + static QtContextMenu* getInstance(); + void addSeparator(); void show(); - static void enableUndo(bool enabled); - static void enableRedo(bool enabled); + void enableUndo(bool enabled); + void enableRedo(bool enabled); private slots: void undoActionTriggered();