From f1233e485ad14443ab05a46d3ee33cb1e8dfc7d7 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 17 Sep 2015 08:25:10 +0200 Subject: [PATCH] Improved state handling of toolbar actions --- .../Commands/RicTileWindowsFeature.cpp | 2 +- .../UserInterface/RiuMainWindow.cpp | 27 ++++++++++++------- ApplicationCode/UserInterface/RiuMainWindow.h | 3 +++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ApplicationCode/Commands/RicTileWindowsFeature.cpp b/ApplicationCode/Commands/RicTileWindowsFeature.cpp index faf5b27a86..8669acbf3b 100644 --- a/ApplicationCode/Commands/RicTileWindowsFeature.cpp +++ b/ApplicationCode/Commands/RicTileWindowsFeature.cpp @@ -30,7 +30,7 @@ CAF_CMD_SOURCE_INIT(RicTileWindowsFeature, "RicTileWindowsFeature"); //-------------------------------------------------------------------------------------------------- bool RicTileWindowsFeature::isCommandEnabled() { - return true; + return RiuMainWindow::instance()->isAnyMdiSubWindowVisible(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index ef7f41c4e8..1b6896ae7b 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -121,13 +121,9 @@ RiuMainWindow::RiuMainWindow() sm_mainWindowInstance = this; - slotRefreshFileActions(); - slotRefreshEditActions(); - m_dragDrop = new RiuDragDrop; - // Set pdm root so scripts are displayed - setPdmRoot(RiaApplication::instance()->project()); + initializeGuiNewProjectLoaded(); // Enabling the line below will activate the undo stack // When enableUndoCommandSystem is set false, all commands are executed and deleted immediately @@ -553,8 +549,6 @@ void RiuMainWindow::createToolBars() refreshAnimationActions(); refreshDrawStyleActions(); - - cmdFeatureMgr->refreshEnabledState(QStringList() << "RicLinkVisibleViewsFeature"); } @@ -766,6 +760,8 @@ void RiuMainWindow::slotRefreshViewActions() m_viewFromBelow->setEnabled(enabled); updateScaleValue(); + + caf::CmdFeatureManager::instance()->refreshEnabledState(QStringList() << "RicLinkVisibleViewsFeature" << "RicTileWindowsFeature"); } //-------------------------------------------------------------------------------------------------- @@ -1165,7 +1161,7 @@ void RiuMainWindow::removeViewer(QWidget* viewer) { m_mdiArea->removeSubWindow( findMdiSubWindow(viewer)); - caf::CmdFeatureManager::instance()->refreshEnabledState(QStringList() << "RicLinkVisibleViewsFeature"); + slotRefreshViewActions(); } @@ -1178,6 +1174,11 @@ public: { } + ~RiuMdiSubWindow() + { + RiuMainWindow::instance()->slotRefreshViewActions(); + } + protected: virtual void closeEvent(QCloseEvent* event) { @@ -1242,7 +1243,7 @@ void RiuMainWindow::addViewer(QWidget* viewer, const std::vector& windowsGe } } - caf::CmdFeatureManager::instance()->refreshEnabledState(QStringList() << "RicLinkVisibleViewsFeature"); + slotRefreshViewActions(); } //-------------------------------------------------------------------------------------------------- @@ -2240,3 +2241,11 @@ void RiuMainWindow::tileWindows() m_mdiArea->tileSubWindows(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiuMainWindow::isAnyMdiSubWindowVisible() +{ + return m_mdiArea->subWindowList().size() > 0; +} + diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index 781bca2d21..352b94bd6d 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -113,6 +113,7 @@ public: std::vector windowGeometryForWidget(QWidget* widget); void tileWindows(); + bool isAnyMdiSubWindowVisible(); protected: virtual void closeEvent(QCloseEvent* event); @@ -208,6 +209,8 @@ private: // Menu and action slots private slots: + friend class RiuMdiSubWindow; + // File slots void slotImportGeoMechModel(); void slotOpenProject();