diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.cpp index ff6d208b50..e61eb35325 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.cpp @@ -1,35 +1,63 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkFileExitAction.h" +#include "internal/org_mitk_gui_qt_application_Activator.h" #include QmitkFileExitAction::QmitkFileExitAction(berry::IWorkbenchWindow::Pointer window) -: QAction(nullptr) + : QAction(nullptr) + , m_Window(nullptr) { - m_Window = window.GetPointer(); + this->init(window.GetPointer()); +} - this->setParent(static_cast(m_Window->GetShell()->GetControl())); - this->setText("&Exit"); +QmitkFileExitAction::QmitkFileExitAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window) + : QAction(nullptr) + , m_Window(nullptr) +{ + this->setIcon(icon); + this->init(window.GetPointer()); +} + +QmitkFileExitAction::QmitkFileExitAction(berry::IWorkbenchWindow* window) + : QAction(nullptr) + , m_Window(nullptr) +{ + this->init(window); +} + +QmitkFileExitAction::QmitkFileExitAction(const QIcon& icon, berry::IWorkbenchWindow* window) + : QAction(nullptr) + , m_Window(nullptr) +{ + this->setIcon(icon); + this->init(window); +} +void QmitkFileExitAction::init(berry::IWorkbenchWindow* window) +{ + m_Window = window; + this->setText("&Exit"); + this->setToolTip("Exit the application. Please save your data before exiting."); this->connect(this, SIGNAL(triggered(bool)), this, SLOT(Run())); } void QmitkFileExitAction::Run() { berry::PlatformUI::GetWorkbench()->Close(); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.h index 606049d458..7b52029d14 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileExitAction.h @@ -1,47 +1,54 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKFILEEXITACTION_H_ #define QMITKFILEEXITACTION_H_ +#include + #include #include -#include +namespace berry { + struct IWorkbenchWindow; +} /** * \ingroup org_mitk_gui_qt_application */ class MITK_QT_APP QmitkFileExitAction : public QAction { Q_OBJECT public: - QmitkFileExitAction(berry::IWorkbenchWindow::Pointer window); + QmitkFileExitAction(berry::SmartPointer window); + QmitkFileExitAction(berry::IWorkbenchWindow* window); + QmitkFileExitAction(const QIcon & icon, berry::SmartPointer window); + QmitkFileExitAction(const QIcon & icon, berry::IWorkbenchWindow* window); protected slots: void Run(); private: - + void init(berry::IWorkbenchWindow* window); berry::IWorkbenchWindow* m_Window; }; #endif /*QMITKFILEOPENACTION_H_*/ diff --git a/Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionBarAdvisor.cpp b/Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionBarAdvisor.cpp index 024338e131..37bb4ef466 100644 --- a/Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionBarAdvisor.cpp +++ b/Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionBarAdvisor.cpp @@ -1,279 +1,285 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkExtActionBarAdvisor.h" #include "QmitkFileOpenAction.h" #include "QmitkFileSaveAction.h" #include "QmitkExtFileSaveProjectAction.h" #include "QmitkCloseProjectAction.h" +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include QmitkExtActionBarAdvisor::QmitkExtActionBarAdvisor(berry::IActionBarConfigurer::Pointer configurer) : berry::ActionBarAdvisor(configurer) { window = configurer->GetWindowConfigurer()->GetWindow().GetPointer(); } void QmitkExtActionBarAdvisor::MakeActions(berry::IWorkbenchWindow* window) { QAction* fileOpenAction = new QmitkFileOpenAction( QIcon::fromTheme("document-open", QIcon(":/org_mitk_icons/icons/tango/scalable/actions/document-open.svg")), window); fileOpenAction->setShortcut(QKeySequence::Open); this->Register(fileOpenAction, berry::IWorkbenchCommandConstants::FILE_OPEN); QAction* fileSaveAction = new QmitkFileSaveAction( QIcon(":/org.mitk.gui.qt.ext/Save_48.png"), window); fileSaveAction->setShortcut(QKeySequence::Save); this->Register(fileSaveAction, berry::IWorkbenchCommandConstants::FILE_SAVE); QAction* fileSaveProjectAction = new QmitkExtFileSaveProjectAction(window); fileSaveProjectAction->setIcon(QIcon::fromTheme("document-save", QIcon(":/org_mitk_icons/icons/tango/scalable/actions/document-save.svg"))); this->Register(fileSaveProjectAction, mitk::WorkbenchCommandConstants::PROJECT_SAVE); QAction* closeProjectAction = new QmitkCloseProjectAction(window); closeProjectAction->setIcon(QIcon::fromTheme("edit-delete", QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-delete.svg"))); this->Register(closeProjectAction, mitk::WorkbenchCommandConstants::PROJECT_CLOSE); + QAction* fileExitAction = new QmitkFileExitAction(window); + fileExitAction->setIcon(QIcon::fromTheme("system-log-out", QIcon(":/org_mitk_icons/icons/tango/scalable/actions/system-log-out.svg"))); + fileExitAction->setShortcut(QKeySequence::Quit); + this->Register(fileExitAction, mitk::WorkbenchCommandConstants::FILE_EXIT); } void QmitkExtActionBarAdvisor::FillMenuBar(berry::IMenuManager* menuBar) { menuBar->Add(CreateFileMenu()); menuBar->Add(CreateEditMenu()); menuBar->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::MB_ADDITIONS))); menuBar->Add(CreateWindowMenu()); menuBar->Add(CreateHelpMenu()); } void QmitkExtActionBarAdvisor::FillToolBar(berry::IToolBarManager* /*toolBar*/) { } berry::SmartPointer QmitkExtActionBarAdvisor::CreateFileMenu() { berry::MenuManager::Pointer menu(new berry::MenuManager("&File", berry::WorkbenchActionConstants::M_FILE)); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::FILE_START))); { // create the New submenu, using the same id for it as the New action QString newText = "&New"; QString newId = "org.blueberry.ui.newWizard"; berry::MenuManager::Pointer newMenu(new berry::MenuManager(newText, newId)); newMenu->SetCommandId("org.blueberry.ui.file.newQuickMenu"); newMenu->Add(berry::IContributionItem::Pointer(new berry::Separator(newId))); //this.newWizardMenu = new NewWizardMenu(getWindow()); //newMenu.add(this.newWizardMenu); newMenu->Add(berry::IContributionItem::Pointer(new berry::Separator(berry::WorkbenchActionConstants::MB_ADDITIONS))); menu->Add(newMenu); } menu->Add(this->GetAction(berry::IWorkbenchCommandConstants::FILE_OPEN), berry::IWorkbenchCommandConstants::FILE_OPEN); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::NEW_EXT))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); //menu.add(closeAction); //menu.add(closeAllAction); // // menu.add(closeAllSavedAction); menu->Add(this->GetAction(mitk::WorkbenchCommandConstants::PROJECT_CLOSE), mitk::WorkbenchCommandConstants::PROJECT_CLOSE); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::CLOSE_EXT))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); menu->Add(this->GetAction(berry::IWorkbenchCommandConstants::FILE_SAVE), berry::IWorkbenchCommandConstants::FILE_SAVE); menu->Add(this->GetAction(mitk::WorkbenchCommandConstants::PROJECT_SAVE), mitk::WorkbenchCommandConstants::PROJECT_SAVE); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::SAVE_EXT))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); menu->Add(berry::IContributionItem::Pointer(new berry::Separator(berry::WorkbenchActionConstants::MB_ADDITIONS))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); menu->Add(berry::ContributionItemFactory::REOPEN_EDITORS->Create(window)); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::MRU))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); // If we're on OS X we shouldn't show this command in the File menu. It // should be invisible to the user. However, we should not remove it - // the carbon UI code will do a search through our menu structure // looking for it when Cmd-Q is invoked (or Quit is chosen from the // application menu. //ActionContributionItem quitItem = new ActionContributionItem(quitAction); //quitItem.setVisible(!Util.isMac()); //menu.add(quitItem); - menu->Add(GetItem(berry::IWorkbenchCommandConstants::FILE_EXIT, "Exit")); + menu->Add(this->GetAction(berry::IWorkbenchCommandConstants::FILE_EXIT), + berry::IWorkbenchCommandConstants::FILE_EXIT); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::FILE_END))); return menu; } berry::SmartPointer QmitkExtActionBarAdvisor::CreateEditMenu() { berry::MenuManager::Pointer menu(new berry::MenuManager("&Edit", berry::WorkbenchActionConstants::M_EDIT)); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::EDIT_START))); menu->Add(GetItem(berry::IWorkbenchCommandConstants::EDIT_UNDO, "&Undo")); menu->Add(GetItem(berry::IWorkbenchCommandConstants::EDIT_REDO, "&Redo")); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::UNDO_EXT))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); /* menu.add(getCutItem()); menu.add(getCopyItem()); menu.add(getPasteItem()); menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT)); menu.add(new Separator()); menu.add(getDeleteItem()); menu.add(getSelectAllItem()); menu.add(new Separator()); menu.add(getFindItem()); menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT)); menu.add(new Separator()); menu.add(getBookmarkItem()); menu.add(getTaskItem()); menu.add(new GroupMarker(IWorkbenchActionConstants.ADD_EXT)); */ menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::EDIT_END))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator(berry::WorkbenchActionConstants::MB_ADDITIONS))); return menu; } berry::SmartPointer QmitkExtActionBarAdvisor::CreateHelpMenu() { berry::MenuManager::Pointer menu(new berry::MenuManager("&Help", berry::WorkbenchActionConstants::M_HELP)); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::HELP_START))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator("group.intro"))); // See if a welcome or intro page is specified if (window->GetWorkbench()->GetIntroManager()->HasIntro()) { menu->Add(GetItem(berry::IWorkbenchCommandConstants::HELP_WELCOME, "Welcome")); } menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker("group.intro.ext"))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator("group.main"))); menu->Add(GetItem(berry::IWorkbenchCommandConstants::HELP_HELP_CONTENTS, "Help &Contents")); //menu->Add(GetItem(berry::IWorkbenchCommandConstants::HELP_HELP_SEARCH, "Help Search")); menu->Add(GetItem(berry::IWorkbenchCommandConstants::HELP_DYNAMIC_HELP, "Conte&xt Help", "", QIcon(), QKeySequence::HelpContents)); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker(berry::WorkbenchActionConstants::HELP_END))); menu->Add(berry::IContributionItem::Pointer(new berry::Separator(berry::WorkbenchActionConstants::MB_ADDITIONS))); // about should always be at the bottom menu->Add(berry::IContributionItem::Pointer(new berry::Separator("group.about"))); menu->Add(GetItem(berry::IWorkbenchCommandConstants::HELP_ABOUT, "&About")); menu->Add(berry::IContributionItem::Pointer(new berry::GroupMarker("group.about.ext"))); return menu; } berry::MenuManager::Pointer QmitkExtActionBarAdvisor::CreateWindowMenu() { berry::MenuManager::Pointer menu(new berry::MenuManager("&Window", berry::WorkbenchActionConstants::M_WINDOW)); menu->Add(GetItem(berry::IWorkbenchCommandConstants::WINDOW_NEW_WINDOW, "New Window")); menu->Add(GetItem(berry::IWorkbenchCommandConstants::WINDOW_NEW_EDITOR, "New Editor")); menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); AddPerspectiveActions(menu.GetPointer()); //menu.add(new Separator()); //AddKeyboardShortcuts(menu); berry::Separator::Pointer sep(new berry::Separator(berry::WorkbenchActionConstants::MB_ADDITIONS)); //sep.setVisible(!Util.isMac()); menu->Add(berry::IContributionItem::Pointer(sep.GetPointer())); //if(Util.isCocoa()) // menu.add(arrangeWindowsItem); // See the comment for quit in createFileMenu berry::IContributionItem::Pointer openPreferencesItem = GetItem(berry::IWorkbenchCommandConstants::WINDOW_PREFERENCES, "Preferences"); //openPreferencesItem.setVisible(!Util.isMac()); menu->Add(openPreferencesItem); menu->Add(berry::ContributionItemFactory::OPEN_WINDOWS->Create(window)); return menu; } void QmitkExtActionBarAdvisor::AddPerspectiveActions(berry::MenuManager* menu) { { berry::MenuManager::Pointer changePerspMenuMgr(new berry::MenuManager("Open Perspective", "openPerspective")); berry::IContributionItem::Pointer changePerspMenuItem = berry::ContributionItemFactory::PERSPECTIVES_SHORTLIST->Create(window); changePerspMenuMgr->Add(changePerspMenuItem); menu->Add(changePerspMenuMgr); } { berry::MenuManager::Pointer showViewMenuMgr(new berry::MenuManager("Show &View", "showView")); berry::IContributionItem::Pointer showViewMenu = berry::ContributionItemFactory::VIEWS_SHORTLIST->Create(window); showViewMenuMgr->Add(showViewMenu); menu->Add(showViewMenuMgr); } menu->Add(berry::IContributionItem::Pointer(new berry::Separator())); //menu.add(editActionSetAction); menu->Add(GetItem(berry::IWorkbenchCommandConstants::WINDOW_SAVE_PERSPECTIVE_AS, "Save Perspective &As...")); menu->Add(GetItem(berry::IWorkbenchCommandConstants::WINDOW_RESET_PERSPECTIVE, "&Reset Perspective...")); menu->Add(GetItem(berry::IWorkbenchCommandConstants::WINDOW_CLOSE_PERSPECTIVE, "&Close Perspective")); menu->Add(GetItem(berry::IWorkbenchCommandConstants::WINDOW_CLOSE_ALL_PERSPECTIVES, "Close All Perspectives")); } berry::SmartPointer QmitkExtActionBarAdvisor::GetItem(const QString& commandId, const QString& label, const QString& tooltip, const QIcon& icon, const QKeySequence& shortcut) { berry::CommandContributionItemParameter::Pointer param( new berry::CommandContributionItemParameter(window, QString(), commandId, berry::CommandContributionItem::STYLE_PUSH)); param->icon = icon; param->label = label; param->tooltip = tooltip; param->shortcut = shortcut; berry::IContributionItem::Pointer item(new berry::CommandContributionItem(param)); return item; }