2008-04-20 00:16:27 +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
UiManager - Global UI Manager
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 >
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
2017 , Hermann Vosseler < Ichthyostega @ web . de >
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 0213 9 , 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
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
/** @file ui-manager.cpp
* * Implementation of global UI resource and instance management .
*/
2011-02-06 21:23:34 +01:00
# include "gui/gtk-lumiera.hpp"
2017-02-01 02:21:04 +01:00
# include "gui/config-keys.hpp"
2017-01-26 20:51:43 +01:00
# include "gui/ui-bus.hpp"
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
# include "gui/workspace/ui-manager.hpp"
2017-02-01 03:55:20 +01:00
# include "gui/workspace/workspace-window.hpp"
2011-02-07 00:54:16 +01:00
# include "lib/searchpath.hpp"
# include "lib/util.hpp"
2014-10-07 03:13:58 +02:00
# include <gtkmm/stylecontext.h>
2011-02-07 00:54:16 +01:00
# include <boost/filesystem.hpp>
2014-04-03 22:42:48 +02:00
# include <memory>
# include <list>
2011-02-07 00:54:16 +01:00
2017-01-23 01:13:38 +01:00
using Gtk : : IconSize ;
using Gtk : : IconFactory ;
2011-02-07 00:54:16 +01:00
using util : : cStr ;
2014-04-03 22:42:48 +02:00
using std : : list ;
using std : : shared_ptr ;
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
2017-01-23 01:13:38 +01:00
namespace fsys = boost : : filesystem ;
IconSize UiManager : : GiantIconSize = Gtk : : ICON_SIZE_INVALID ;
IconSize UiManager : : MenuIconSize = Gtk : : ICON_SIZE_INVALID ;
2011-02-07 00:54:16 +01:00
2014-10-07 03:13:58 +02:00
2017-01-26 20:51:43 +01:00
UiManager : : UiManager ( UiBus & bus )
: Gtk : : UIManager ( )
, uiBus_ ( bus )
2017-02-01 03:55:20 +01:00
, windowList_ { * this }
, actions_ { [ this ] ( ) - > WorkspaceWindow & { return windowList_ . findActiveWindow ( ) ; } }
2017-02-01 02:21:04 +01:00
, iconSearchPath_ { Config : : get ( KEY_ICON_PATH ) }
, resourceSerachPath_ { Config : : get ( KEY_UIRES_PATH ) }
2017-02-02 19:41:58 +01:00
{
initGlobalUI ( ) ;
}
2017-01-26 20:51:43 +01:00
2017-02-01 03:55:20 +01:00
/**
2017-02-02 19:41:58 +01:00
* Initialise the interface manager on application start .
2017-02-01 03:55:20 +01:00
* Register the icon configuration and sizes and lookup
* all the icons - - either from the default theme of via
* the given Lumiera icon search paths ( see \ c setup . ini ) .
* @ see lumiera : : Config
*/
2015-05-29 04:44:58 +02:00
void
2017-02-01 03:55:20 +01:00
UiManager : : initGlobalUI ( )
2015-05-29 04:44:58 +02:00
{
2017-02-01 02:21:04 +01:00
Glib : : set_application_name ( Config : : get ( KEY_TITLE ) ) ;
2015-05-29 04:44:58 +02:00
registerAppIconSizes ( ) ;
registerStockItems ( ) ;
2017-02-01 02:21:04 +01:00
setTheme ( Config : : get ( KEY_STYLESHEET ) ) ;
2017-02-01 03:55:20 +01:00
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 ( )
{
UNIMPLEMENTED ( " create the first top-level window " ) ;
2015-05-29 04:44:58 +02:00
}
2009-01-31 19:12:04 +01:00
2017-02-01 03:55:20 +01:00
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()
}
2009-01-31 19:12:04 +01:00
2015-05-29 04:44:58 +02:00
void
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
UiManager : : setTheme ( string const & stylesheetName )
2015-05-29 04:44:58 +02:00
{
auto screen = Gdk : : Screen : : get_default ( ) ;
2017-01-23 01:13:38 +01:00
auto css_provider = Gtk : : CssProvider : : create ( ) ;
2015-11-03 05:04:06 +01:00
try
{
css_provider - > load_from_path ( lib : : resolveModulePath ( stylesheetName , resourceSerachPath_ ) ) ;
2015-05-29 04:44:58 +02:00
/////////////////////////////////TICKET #953 should detect and notify CSS parsing errors. CssProvider offers a signal for this purpose
2015-11-03 05:04:06 +01:00
/////////////////////////////////TICKET #953 ...seems to be supported properly starting with gtkmm 3.18 (Debian/Jessie has 3.14)
}
catch ( Glib : : Error const & failure )
{
WARN ( gui , " Failure while loading stylesheet '%s': %s " , cStr ( stylesheetName ) , cStr ( failure . what ( ) ) ) ;
}
2015-05-29 04:44:58 +02:00
2017-01-23 01:13:38 +01:00
Gtk : : StyleContext : : add_provider_for_screen ( screen , css_provider ,
GTK_STYLE_PROVIDER_PRIORITY_USER ) ;
2015-05-29 04:44:58 +02:00
}
2008-08-13 20:15:13 +02:00
2015-05-29 04:44:58 +02:00
Cairo : : RefPtr < Cairo : : SolidPattern >
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
UiManager : : readStyleColourProperty ( Gtk : : Widget & widget
2017-01-27 20:42:42 +01:00
, const gchar * property_name
, guint16 red , guint16 green , guint16 blue )
2015-05-29 04:44:58 +02:00
{
REQUIRE ( property_name ) ;
// TODO: Can we get rid of the GdkColor completely here?
GdkColor * color ;
gtk_widget_style_get ( widget . gobj ( ) , property_name , & color , NULL ) ;
Cairo : : RefPtr < Cairo : : SolidPattern > pattern ;
// Did the color load successfully?
if ( color ! = NULL )
{
pattern = Cairo : : SolidPattern : : create_rgb ( ( double ) color - > red / 0xFFFF ,
( double ) color - > green / 0xFFFF ,
( double ) color - > blue / 0xFFFF ) ;
}
else
{
WARN ( gui , " %s style value failed to load " , property_name ) ;
pattern = Cairo : : SolidPattern : : create_rgb ( red , green , blue ) ;
}
return pattern ;
}
2008-08-13 20:15:13 +02:00
2009-01-31 17:31:15 +01:00
2015-05-29 04:44:58 +02:00
void
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
UiManager : : registerAppIconSizes ( )
2015-05-29 04:44:58 +02:00
{
2017-01-23 01:13:38 +01:00
if ( GiantIconSize = = Gtk : : ICON_SIZE_INVALID )
2015-05-29 04:44:58 +02:00
GiantIconSize = IconSize : : register_new ( " giant " , 48 , 48 ) ;
2017-01-23 01:13:38 +01:00
if ( MenuIconSize = = Gtk : : ICON_SIZE_INVALID )
2015-05-29 04:44:58 +02:00
MenuIconSize = IconSize : : register_new ( " menu " , 16 , 16 ) ;
}
2008-10-23 00:11:23 +02:00
2008-08-13 20:15:13 +02:00
2017-02-01 03:55:20 +01:00
/**
* Registers application stock items :
* icons and labels associated with IDs
*/
2015-05-29 04:44:58 +02:00
void
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
UiManager : : registerStockItems ( )
2015-05-29 04:44:58 +02:00
{
2017-01-23 01:13:38 +01:00
Glib : : RefPtr < IconFactory > factory = Gtk : : IconFactory : : create ( ) ;
2015-05-29 04:44:58 +02:00
addStockIconSet ( factory , " panel-assets " , " panel_assets " , _ ( " _Assets " ) ) ;
addStockIconSet ( factory , " panel-viewer " , " panel_viewer " , _ ( " _Viewer " ) ) ;
2016-10-26 19:33:00 +02:00
addStockIconSet ( factory , " panel-timeline " , " panel_timeline " , _ ( " _Timeline " ) ) ;
addStockIconSet ( factory , " panel-timeline " , " panel_timeline_obsolete " , _ ( " _ZombieTimeline " ) ) ;
2015-05-29 04:44:58 +02:00
addStockIconSet ( factory , " window-new " , " new_window " , _ ( " New _Window " ) ) ;
addStockIconSet ( factory , " tool-arrow " , " tool_arrow " , _ ( " _Arrow " ) ) ;
addStockIconSet ( factory , " tool-i-beam " , " tool_i_beam " , _ ( " _I-Beam " ) ) ;
addStockIconSet ( factory , " track-disabled " , " track_disabled " , _ ( " Track Disabled " ) ) ;
addStockIconSet ( factory , " track-enabled " , " track_enabled " , _ ( " Track Enabled " ) ) ;
addStockIconSet ( factory , " track-locked " , " track_locked " , _ ( " Track Locked " ) ) ;
addStockIconSet ( factory , " track-unlocked " , " track_unlocked " , _ ( " Track Unlocked " ) ) ;
factory - > add_default ( ) ; //Add factory to list of factories.
}
2008-10-10 11:56:07 +02:00
2015-05-29 04:44:58 +02:00
bool
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
UiManager : : addStockIconSet ( Glib : : RefPtr < IconFactory > const & factory
2017-01-27 20:42:42 +01:00
, cuString & icon_name
, cuString & id
, cuString & label )
2015-05-29 04:44:58 +02:00
{
Glib : : RefPtr < Gtk : : IconSet > icon_set = Gtk : : IconSet : : create ( ) ;
2017-01-27 20:42:42 +01:00
// Load all the sizes, wildcarding the first, largest icon to be loaded
2015-05-29 04:44:58 +02:00
bool no_icons = true ;
no_icons & = ! addStockIcon (
icon_set , icon_name , GiantIconSize , no_icons ) ;
no_icons & = ! addStockIcon (
2017-01-23 01:13:38 +01:00
icon_set , icon_name , Gtk : : ICON_SIZE_BUTTON , no_icons ) ;
2015-05-29 04:44:58 +02:00
no_icons & = ! addStockIcon (
2017-01-23 01:13:38 +01:00
icon_set , icon_name , Gtk : : ICON_SIZE_MENU , no_icons ) ;
2015-05-29 04:44:58 +02:00
no_icons & = ! addStockIcon (
2017-01-23 01:13:38 +01:00
icon_set , icon_name , Gtk : : ICON_SIZE_LARGE_TOOLBAR , no_icons ) ;
2015-05-29 04:44:58 +02:00
no_icons & = ! addStockIcon (
icon_set , icon_name , MenuIconSize , no_icons ) ;
if ( no_icons )
{
// No icons were loaded
ERROR ( gui , " Unable to load icon '%s' " , cStr ( icon_name ) ) ;
return false ;
}
// Add the icon set to the icon factory
const Gtk : : StockID stock_id ( id ) ;
factory - > add ( stock_id , icon_set ) ;
2016-10-26 19:33:00 +02:00
Gtk : : Stock : : add ( Gtk : : StockItem ( stock_id , label ) ) ; //////////////////////TICKET #1030 : use "icon names" instead of Gtk::StockItem
2009-01-31 17:31:15 +01:00
return true ;
2015-05-29 04:44:58 +02:00
}
2008-08-13 20:15:13 +02:00
2015-05-29 04:44:58 +02:00
bool
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
UiManager : : addStockIcon ( Glib : : RefPtr < Gtk : : IconSet > const & icon_set
2015-05-29 04:44:58 +02:00
, cuString & icon_name
, Gtk : : IconSize size
, bool wildcard )
{
// Try the icon theme
2017-01-27 20:42:42 +01:00
if ( addThemeIconSource ( icon_set , icon_name , size , wildcard ) )
2011-02-07 00:54:16 +01:00
return true ;
2015-05-29 04:44:58 +02:00
// Try to resolve the icon via the configured search path
lib : : SearchPathSplitter iconLocations ( iconSearchPath_ ) ;
while ( iconLocations )
if ( addNonThemeIconSource ( icon_set
, iconLocations . next ( )
, icon_name
, size
, wildcard ) )
return true ;
return false ; // icon not found
}
2011-02-07 00:54:16 +01:00
2009-01-31 17:31:15 +01:00
2015-05-29 04:44:58 +02:00
bool
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
UiManager : : addThemeIconSource ( Glib : : RefPtr < Gtk : : IconSet > const & icon_set
2017-01-27 20:42:42 +01:00
, cuString & icon_name
, Gtk : : IconSize size
, bool wildcard )
2015-05-29 04:44:58 +02:00
{
// Get the size
int width = 0 , height = 0 ;
if ( ! IconSize : : lookup ( size , width , height ) )
return false ;
REQUIRE ( width > 0 ) ;
// Try to load the icon
Glib : : RefPtr < Gtk : : IconTheme > theme = Gtk : : IconTheme : : get_default ( ) ;
REQUIRE ( theme ) ;
2016-10-26 19:33:00 +02:00
///////////////////////////////////////////TODO find out how IconInfo could be made const. For example, GTKmm 2.10.10 is missing the const on operator bool() in iconinfo.h
2017-01-23 01:13:38 +01:00
Gtk : : IconInfo info = theme - > lookup_icon ( icon_name , width , ( Gtk : : IconLookupFlags ) 0 ) ;
2015-05-29 04:44:58 +02:00
if ( ! info ) return false ; // unable to resolve Icon
cuString path ( info . get_filename ( ) ) ;
return addStockIconFromPath ( path , icon_set , size , wildcard ) ;
}
2009-02-01 19:56:49 +01:00
2011-02-07 00:54:16 +01:00
2015-05-29 04:44:58 +02:00
bool
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
UiManager : : addNonThemeIconSource ( Glib : : RefPtr < Gtk : : IconSet > const & icon_set
2017-01-27 20:42:42 +01:00
, cuString & base_dir
, cuString & icon_name
, Gtk : : IconSize size
, bool wildcard )
2015-05-29 04:44:58 +02:00
{
// Get the size
int width = 0 , height = 0 ;
if ( ! IconSize : : lookup ( size , width , height ) )
return false ;
REQUIRE ( width > 0 ) ;
// Try to load the icon
2017-01-23 01:13:38 +01:00
cuString path ( Glib : : ustring : : compose ( " %1/%2x%3/%4.png " ,
2015-05-29 04:44:58 +02:00
base_dir , width , height , icon_name ) ) ;
return addStockIconFromPath ( path , icon_set , size , wildcard ) ;
}
2009-01-31 17:31:15 +01:00
2008-10-08 00:02:27 +02:00
2015-05-29 04:44:58 +02:00
bool
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
UiManager : : addStockIconFromPath ( string path
2017-01-27 20:42:42 +01:00
, Glib : : RefPtr < Gtk : : IconSet > const & icon_set
, Gtk : : IconSize size
, bool wildcard )
2015-05-29 04:44:58 +02:00
{
if ( ! fsys : : exists ( path ) ) return false ;
try {
Gtk : : IconSource source ;
source . set_pixbuf ( Gdk : : Pixbuf : : create_from_file ( path ) ) ;
source . set_size_wildcarded ( wildcard ) ;
source . set_size ( size ) ;
icon_set - > add_source ( source ) ;
return true ;
}
catch ( Glib : : Exception const & ex )
{
WARN ( gui , " Failure when accessing icon '%s'. Problem: %s " , cStr ( path ) , cStr ( ex . what ( ) ) ) ;
return false ;
}
}
2011-02-07 00:54:16 +01:00
2015-05-29 04:44:58 +02:00
2017-01-26 21:51:19 +01:00
void
UiManager : : allowCloseWindow ( bool yes )
{
this - > get_action ( " /MenuBar/WindowMenu/WindowCloseWindow " )
- > set_sensitive ( yes ) ;
}
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