LUMIERA.clone/src/gui/ctrl/ui-manager.cpp
Ichthyostega e59e8d0ab5 UI-top-level: consider how to rework the UI main object (#1067)
Gtk::Main is deprecated, but the new solution, instantiating a
Gtk::Application object does not match our use case, since we handle
all application concerns already and just need a Gtk main loop to run.

Anyway, it became clear that the "main object" will be the new UiManager.
As a first step, I've now moved the (deprecated) Gtk::Main object
down there. Next step (planned) will be to inherit from Gio::Application
and clone some functionality from Gtk::Application
2017-05-03 02:37:48 +02:00

128 lines
3.4 KiB
C++

/*
UiManager - Global UI Manager
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
2017, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
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.
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.
* *****************************************************/
/** @file ui-manager.cpp
** Implementation of global concerns regarding a coherent UI and global state.
** Especially, the wiring of top-level components is done here, as is the
** basic initialisation of the interface and global configuration on
** UI toolkit level.
**
*/
#include "gui/gtk-lumiera.hpp"
#include "gui/config-keys.hpp"
#include "gui/ctrl/ui-manager.hpp"
#include "gui/ctrl/global-ctx.hpp"
#include "gui/ctrl/actions.hpp"
#include "gui/workspace/style-manager.hpp"
#include "lib/searchpath.hpp"
#include "lib/util.hpp"
using Gtk::IconSize;
using Gtk::IconFactory;
using util::cStr;
using util::isnil;
namespace gui {
namespace ctrl {
using workspace::StyleManager;
namespace { // dummy command line for GTK
int argc =0;
}
// dtors via smart-ptr invoked from here...
UiManager::~UiManager()
{ }
/**
* Initialise the interface globally on application start.
* Setup the main application menu and bind the corresponding actions.
* Register the icon configuration and sizes and lookup all the icons.
* @see lumiera::Config
*/
UiManager::UiManager (UiBus& bus)
: Gtk::UIManager()
, globals_{new GlobalCtx{bus, *this}}
, actions_{new Actions{*globals_}}
, styleManager_{new StyleManager{}}
, gtkMain_(&argc, nullptr)
{
Glib::thread_init();
Gdl::init();
actions_->populateMainActions (*this);
}
/**
* @remarks this function is invoked once from the main application object,
* immediately prior to starting the GTK event loop. */
void
UiManager::createApplicationWindow()
{
if (globals_->windowList_.empty())
globals_->windowList_.newWindow();
}
void
UiManager::performMainLoop()
{
gtkMain_.run(); // GTK event loop
}
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()
{
UNIMPLEMENTED ("how to handle activation of menu entries depending on window focus"); ////////TICKET #1076 find out how to handle this properly
//////see Actions::updateActionState()
}
void
UiManager::allowCloseWindow (bool yes)
{
this->get_action("/MenuBar/WindowMenu/WindowCloseWindow")
->set_sensitive (yes);
}
}}// namespace gui::ctrl