From de7e47fa217ef5598a379710873ed00afd86ed3f Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 14 Feb 2017 03:43:41 +0100 Subject: [PATCH] UI-top-level: solve several of the previously tricky wiring problems ...this solution feels good thus far --- src/gui/workspace/actions.hpp | 11 ++++------- src/gui/workspace/ui-manager.cpp | 10 +++++++++- src/gui/workspace/ui-manager.hpp | 5 +++++ src/gui/workspace/window-list.cpp | 20 ++++++++++++++------ src/gui/workspace/window-list.hpp | 3 ++- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/gui/workspace/actions.hpp b/src/gui/workspace/actions.hpp index c95ab234b..1f5c4e108 100644 --- a/src/gui/workspace/actions.hpp +++ b/src/gui/workspace/actions.hpp @@ -320,10 +320,8 @@ namespace workspace { void onMenu_file_quit() - { //////global -> InteractionDirector - Main *main = Main::instance(); - REQUIRE(main); - main->quit(); + { + globalCtx_.uiManager_.terminateUI(); } @@ -398,14 +396,13 @@ namespace workspace { void onMenu_window_new_window() { -// windowList_.newWindow(); //////////////////////////////////TODO move into UiManager?? + globalCtx_.windowList_.newWindow(); } void onMenu_window_close_window() { - getWorkspaceWindow().hide(); - // delete &workspaceWindow; + globalCtx_.windowList_.closeWindow(); } void diff --git a/src/gui/workspace/ui-manager.cpp b/src/gui/workspace/ui-manager.cpp index a5eb575a4..22d7423fa 100644 --- a/src/gui/workspace/ui-manager.cpp +++ b/src/gui/workspace/ui-manager.cpp @@ -110,7 +110,15 @@ namespace workspace { globals_->windowList_.newWindow(); } - + + void + UiManager::terminateUI() + { + Gtk::Main *main = Gtk::Main::instance(); /////////////////////////////////////TICKET #1032 : use gtk::Application instead of gtk::Main + REQUIRE(main); + main->quit(); + } + void UiManager::updateWindowFocusRelatedActions() { diff --git a/src/gui/workspace/ui-manager.hpp b/src/gui/workspace/ui-manager.hpp index 7bf212a79..a726b9a0e 100644 --- a/src/gui/workspace/ui-manager.hpp +++ b/src/gui/workspace/ui-manager.hpp @@ -116,6 +116,11 @@ namespace workspace { */ void createApplicationWindow(); + /** + * Cause the main event loop to terminate, so the application as a whole unwinds. + */ + void terminateUI(); + /** @todo find a solution how to enable/disable menu entries according to focus * /////////////////////////////////////////////////TICKET #1076 find out how to handle this properly */ diff --git a/src/gui/workspace/window-list.cpp b/src/gui/workspace/window-list.cpp index 0f9278bc1..e8d5360b6 100644 --- a/src/gui/workspace/window-list.cpp +++ b/src/gui/workspace/window-list.cpp @@ -68,6 +68,18 @@ namespace workspace { } + /** close (and thus destroy) the current active window. + * @note closing the last window terminates the application + * @warning when no window is currently active, + * the fist one in list will be killed + */ + void + WindowList::closeWindow() + { + findActiveWindow().hide(); + } + + /** find and retrieve a WorkspaceWindow (top-level window) * marked as 'active' by GTK. * @return the first matching window, or the first window @@ -132,12 +144,8 @@ namespace workspace { } if (windowList_.empty()) - { - // All windows have been closed - we should exit - Gtk::Main *main = Gtk::Main::instance(); ////////////////////////////////////////////////TICKET #1032 : use gtk::Application instead of gtk::Main - REQUIRE(main); - main->quit(); - } + // All windows have been closed - we should exit + globalCtx_.uiManager_.terminateUI(); updateCloseWindowInMenus(); diff --git a/src/gui/workspace/window-list.hpp b/src/gui/workspace/window-list.hpp index 389193859..461ebe04c 100644 --- a/src/gui/workspace/window-list.hpp +++ b/src/gui/workspace/window-list.hpp @@ -73,7 +73,8 @@ namespace workspace { bool empty() const; - void newWindow (); + void newWindow(); + void closeWindow(); WorkspaceWindow& findActiveWindow(); WorkspaceWindow& findFocusWindow();