2008-04-20 00:16:27 +02:00
|
|
|
/*
|
2017-01-27 20:42:42 +01:00
|
|
|
WindowList - manage all top level windows
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
2011-02-06 21:23:34 +01:00
|
|
|
|
2017-01-27 20:42:42 +01:00
|
|
|
/** @file window-list.cpp
|
|
|
|
|
** Implementation parts of the list to manage all top level windows.
|
|
|
|
|
** @see ui-manager.hpp
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2017-01-26 21:51:19 +01:00
|
|
|
#include "gui/workspace/ui-manager.hpp"
|
2017-01-27 20:42:42 +01:00
|
|
|
#include "gui/workspace/window-list.hpp"
|
2011-02-06 21:23:34 +01:00
|
|
|
#include "gui/workspace/workspace-window.hpp"
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
#include <memory>
|
|
|
|
|
#include <list>
|
2011-02-07 00:54:16 +01:00
|
|
|
|
|
|
|
|
using util::cStr;
|
2014-04-03 22:42:48 +02:00
|
|
|
using std::list;
|
2008-04-20 00:16:27 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2008-04-20 00:16:27 +02:00
|
|
|
namespace gui {
|
Rectify UI top-level -- introduce a global UiManager (#1067)
There seems to be a mismatch in the arrangement of the top-level entities
* we support multiple windows, yet from reading the code, you'd ge the impression we aren't really aware we have multiple top-level windows
* the `WindowManager` is the core UI manager, which feels like a mix-up in concerns
* the `WorkspaceWindow::createUI()` does the global UI initialisation. Again, we have multiple workspace windows.
* `GtkLumiera::main()` creates a `Model` and a `Controller` in local function scope, but stores the `WindowManager` in an object field.
* it seems, for that very reason, `GtlLumiera` needed to be a singleton, to allow by-name access to "the" `WindowManager`
* needless to say, this causes a host of problems when shutting down the UI.
The idea is to introduce a dedicated UiManager, to deal with the central
framework induced concerns solely, and to demote the WindowManager and the
WorkspaceWindows to care only for their local concerns
2017-01-23 00:40:17 +01:00
|
|
|
namespace workspace {
|
2008-10-10 11:56:07 +02:00
|
|
|
|
2009-01-31 19:12:04 +01:00
|
|
|
|
2009-01-31 19:49:44 +01:00
|
|
|
|
2017-01-27 20:42:42 +01:00
|
|
|
WindowList::WindowList (UiManager& uiManager)
|
2017-01-27 20:22:52 +01:00
|
|
|
: uiManager_{uiManager}
|
|
|
|
|
, windowList_{}
|
2017-01-26 21:51:19 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
2015-05-29 04:44:58 +02:00
|
|
|
void
|
2017-01-27 20:42:42 +01:00
|
|
|
WindowList::newWindow (gui::model::Project& source_project, gui::controller::Controller& source_controller)
|
2015-05-29 04:44:58 +02:00
|
|
|
{
|
2017-01-27 20:22:52 +01:00
|
|
|
PWindow window (new WorkspaceWindow{uiManager_, source_project, source_controller});
|
2015-05-29 04:44:58 +02:00
|
|
|
REQUIRE(window);
|
|
|
|
|
|
|
|
|
|
window->signal_delete_event().connect(sigc::mem_fun(
|
2017-01-27 20:42:42 +01:00
|
|
|
this, &WindowList::on_window_closed));
|
2015-05-29 04:44:58 +02:00
|
|
|
|
2017-01-27 20:22:52 +01:00
|
|
|
windowList_.push_back(window);
|
2015-05-29 04:44:58 +02:00
|
|
|
|
|
|
|
|
window->show();
|
|
|
|
|
|
|
|
|
|
updateCloseWindowInMenus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2017-01-27 20:42:42 +01:00
|
|
|
WindowList::on_window_closed (GdkEventAny* event)
|
2015-05-29 04:44:58 +02:00
|
|
|
{
|
|
|
|
|
REQUIRE(event);
|
|
|
|
|
REQUIRE(event->window);
|
|
|
|
|
|
2017-01-27 20:22:52 +01:00
|
|
|
list<PWindow>::iterator iterator{windowList_.begin()};
|
2015-05-29 04:44:58 +02:00
|
|
|
|
2017-01-27 20:22:52 +01:00
|
|
|
while (iterator != windowList_.end())
|
2015-05-29 04:44:58 +02:00
|
|
|
{
|
2017-01-27 20:22:52 +01:00
|
|
|
PWindow workspace_window(*iterator);
|
2015-05-29 04:44:58 +02:00
|
|
|
REQUIRE(workspace_window);
|
|
|
|
|
|
|
|
|
|
Glib::RefPtr<Gdk::Window> window = workspace_window->get_window();
|
|
|
|
|
REQUIRE(window);
|
|
|
|
|
if (window->gobj() == event->window)
|
|
|
|
|
{
|
|
|
|
|
// This window has been closed
|
2017-01-27 20:22:52 +01:00
|
|
|
iterator = windowList_.erase(iterator);
|
2015-05-29 04:44:58 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
iterator++;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 20:22:52 +01:00
|
|
|
if (windowList_.empty())
|
2015-05-29 04:44:58 +02:00
|
|
|
{
|
|
|
|
|
// All windows have been closed - we should exit
|
2017-01-23 01:13:38 +01:00
|
|
|
Gtk::Main *main = Gtk::Main::instance(); ////////////////////////////////////////////////TICKET #1032 : use gtk::Application instead of gtk::Main
|
2015-05-29 04:44:58 +02:00
|
|
|
REQUIRE(main);
|
|
|
|
|
main->quit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateCloseWindowInMenus();
|
|
|
|
|
|
|
|
|
|
// Unless this is false, the window won't close
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-01-27 20:42:42 +01:00
|
|
|
WindowList::updateCloseWindowInMenus()
|
2015-05-29 04:44:58 +02:00
|
|
|
{
|
2017-01-27 20:22:52 +01:00
|
|
|
uiManager_.allowCloseWindow ( 1 < windowList_.size());
|
2015-05-29 04:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
2008-08-13 20:15:13 +02:00
|
|
|
|
2011-02-07 00:54:16 +01:00
|
|
|
|
2015-05-29 04:44:58 +02:00
|
|
|
|
Rectify UI top-level -- introduce a global UiManager (#1067)
There seems to be a mismatch in the arrangement of the top-level entities
* we support multiple windows, yet from reading the code, you'd ge the impression we aren't really aware we have multiple top-level windows
* the `WindowManager` is the core UI manager, which feels like a mix-up in concerns
* the `WorkspaceWindow::createUI()` does the global UI initialisation. Again, we have multiple workspace windows.
* `GtkLumiera::main()` creates a `Model` and a `Controller` in local function scope, but stores the `WindowManager` in an object field.
* it seems, for that very reason, `GtlLumiera` needed to be a singleton, to allow by-name access to "the" `WindowManager`
* needless to say, this causes a host of problems when shutting down the UI.
The idea is to introduce a dedicated UiManager, to deal with the central
framework induced concerns solely, and to demote the WindowManager and the
WorkspaceWindows to care only for their local concerns
2017-01-23 00:40:17 +01:00
|
|
|
}}// namespace gui::workspace
|