[nautilus-actions] NactMenubar: new convenience class
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] NactMenubar: new convenience class
- Date: Thu, 3 Feb 2011 00:50:30 +0000 (UTC)
commit 44ecfae822848cbf121ae261ecd5901dab942804
Author: Pierre Wieser <pwieser trychlos org>
Date: Tue Feb 1 01:14:15 2011 +0100
NactMenubar: new convenience class
The object is created at NactMainWindow instanciation time, destroys itself via a weak ref,
is supposed to make an heavy use of BaseWindow-class messages to reduce the need for a
public API.
ChangeLog | 17 +
src/nact/Makefile.am | 4 +-
src/nact/nact-iactions-list.c | 2 +-
src/nact/nact-main-menubar-edit.h | 4 +-
src/nact/nact-main-menubar-file.h | 4 +-
src/nact/nact-main-menubar-help.c | 1 -
src/nact/nact-main-menubar-help.h | 4 +-
src/nact/nact-main-menubar-maintainer.c | 1 -
src/nact/nact-main-menubar-maintainer.h | 4 +-
src/nact/nact-main-menubar-tools.c | 1 -
src/nact/nact-main-menubar-tools.h | 4 +-
src/nact/nact-main-menubar-view.c | 6 +-
src/nact/nact-main-menubar-view.h | 4 +-
src/nact/nact-main-menubar.h | 88 ---
src/nact/nact-main-window.c | 53 ++-
src/nact/{nact-main-menubar.c => nact-menubar.c} | 663 +++++++++++++---------
src/nact/nact-menubar.h | 143 +++++
17 files changed, 600 insertions(+), 403 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 67ce87e..1949ac4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2011-01-31 Pierre Wieser <pwieser trychlos org>
+ * src/nact/nact-main-menubar.c:
+ * src/nact/nact-main-menubar.h: Renamed as nact-menubar.{c,h}.
+
+ * src/nact/Makefile.am:
+ * src/nact/nact-iactions-list.c:
+ * src/nact/nact-main-menubar-edit.h:
+ * src/nact/nact-main-menubar-file.h:
+ * src/nact/nact-main-menubar-help.c:
+ * src/nact/nact-main-menubar-help.h:
+ * src/nact/nact-main-menubar-maintainer.c:
+ * src/nact/nact-main-menubar-maintainer.h:
+ * src/nact/nact-main-menubar-tools.c:
+ * src/nact/nact-main-menubar-tools.h:
+ * src/nact/nact-main-menubar-view.c:
+ * src/nact/nact-main-menubar-view.h:
+ * src/nact/nact-main-window.c: Updated accordingly.
+
* src/api/na-boxed.h:
* src/core/na-boxed.c (na_boxed_dump): New function.
diff --git a/src/nact/Makefile.am b/src/nact/Makefile.am
index a48f588..10ba391 100644
--- a/src/nact/Makefile.am
+++ b/src/nact/Makefile.am
@@ -117,8 +117,6 @@ nautilus_actions_config_tool_SOURCES = \
nact-iproperties-tab.h \
nact-ischemes-tab.c \
nact-ischemes-tab.h \
- nact-main-menubar.c \
- nact-main-menubar.h \
nact-main-menubar-edit.c \
nact-main-menubar-edit.h \
nact-main-menubar-file.c \
@@ -141,6 +139,8 @@ nautilus_actions_config_tool_SOURCES = \
nact-main-window.h \
nact-match-list.c \
nact-match-list.h \
+ nact-menubar.c \
+ nact-menubar.h \
nact-preferences-editor.c \
nact-preferences-editor.h \
nact-providers-list.c \
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 24c60fd..f87fdef 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -37,9 +37,9 @@
#include "base-window.h"
#include "base-keysyms.h"
#include "nact-application.h"
-#include "nact-main-menubar.h"
#include "nact-main-tab.h"
#include "nact-marshal.h"
+#include "nact-menubar.h"
#include "nact-tree-model.h"
#include "nact-iactions-list.h"
#include "nact-iactions-list-priv.h"
diff --git a/src/nact/nact-main-menubar-edit.h b/src/nact/nact-main-menubar-edit.h
index 3e84440..8932bc2 100644
--- a/src/nact/nact-main-menubar-edit.h
+++ b/src/nact/nact-main-menubar-edit.h
@@ -37,9 +37,7 @@
* @include: nact/nact-main-menubar-edit.h
*/
-#include <gtk/gtk.h>
-
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
G_BEGIN_DECLS
diff --git a/src/nact/nact-main-menubar-file.h b/src/nact/nact-main-menubar-file.h
index 8ac9ada..d29ba05 100644
--- a/src/nact/nact-main-menubar-file.h
+++ b/src/nact/nact-main-menubar-file.h
@@ -37,9 +37,7 @@
* @include: nact/nact-main-menubar-file.h
*/
-#include <gtk/gtk.h>
-
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
G_BEGIN_DECLS
diff --git a/src/nact/nact-main-menubar-help.c b/src/nact/nact-main-menubar-help.c
index 13f7357..5e07d16 100644
--- a/src/nact/nact-main-menubar-help.c
+++ b/src/nact/nact-main-menubar-help.c
@@ -34,7 +34,6 @@
#include <core/na-iabout.h>
-#include "nact-main-menubar.h"
#include "nact-main-menubar-help.h"
/**
diff --git a/src/nact/nact-main-menubar-help.h b/src/nact/nact-main-menubar-help.h
index 4d5dbba..fe96249 100644
--- a/src/nact/nact-main-menubar-help.h
+++ b/src/nact/nact-main-menubar-help.h
@@ -37,9 +37,7 @@
* @include: nact/nact-main-menubar-help.h
*/
-#include <gtk/gtk.h>
-
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
G_BEGIN_DECLS
diff --git a/src/nact/nact-main-menubar-maintainer.c b/src/nact/nact-main-menubar-maintainer.c
index bfa8909..fed18a4 100644
--- a/src/nact/nact-main-menubar-maintainer.c
+++ b/src/nact/nact-main-menubar-maintainer.c
@@ -36,7 +36,6 @@
#include "nact-iactions-list.h"
#include "nact-clipboard.h"
-#include "nact-main-menubar.h"
#include "nact-main-menubar-maintainer.h"
/**
diff --git a/src/nact/nact-main-menubar-maintainer.h b/src/nact/nact-main-menubar-maintainer.h
index b4abac2..fac3591 100644
--- a/src/nact/nact-main-menubar-maintainer.h
+++ b/src/nact/nact-main-menubar-maintainer.h
@@ -37,9 +37,7 @@
* @include: nact/nact-main-menubar-maintainer.h
*/
-#include <gtk/gtk.h>
-
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
G_BEGIN_DECLS
diff --git a/src/nact/nact-main-menubar-tools.c b/src/nact/nact-main-menubar-tools.c
index a951c08..2e81e2e 100644
--- a/src/nact/nact-main-menubar-tools.c
+++ b/src/nact/nact-main-menubar-tools.c
@@ -34,7 +34,6 @@
#include "nact-assistant-export.h"
#include "nact-assistant-import.h"
-#include "nact-main-menubar.h"
#include "nact-main-menubar-tools.h"
/**
diff --git a/src/nact/nact-main-menubar-tools.h b/src/nact/nact-main-menubar-tools.h
index 2e32248..9f85a8f 100644
--- a/src/nact/nact-main-menubar-tools.h
+++ b/src/nact/nact-main-menubar-tools.h
@@ -37,9 +37,7 @@
* @include: nact/nact-main-menubar-tools.h
*/
-#include <gtk/gtk.h>
-
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
G_BEGIN_DECLS
diff --git a/src/nact/nact-main-menubar-view.c b/src/nact/nact-main-menubar-view.c
index 1dd3cbd..7391403 100644
--- a/src/nact/nact-main-menubar-view.c
+++ b/src/nact/nact-main-menubar-view.c
@@ -143,10 +143,10 @@ static void
on_view_toolbar_activated( GtkToggleAction *action, NactMainWindow *window, int toolbar_id )
{
gboolean is_active;
- GtkUIManager *ui_manager;
+
+ BAR_WINDOW_VOID( window );
is_active = gtk_toggle_action_get_active( action );
- ui_manager = ( GtkUIManager * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_UI_MANAGER );
- nact_main_toolbar_activate( window, toolbar_id, ui_manager, is_active );
+ nact_main_toolbar_activate( window, toolbar_id, nact_menubar_get_ui_manager( bar ), is_active );
}
diff --git a/src/nact/nact-main-menubar-view.h b/src/nact/nact-main-menubar-view.h
index ef0d1eb..11b6795 100644
--- a/src/nact/nact-main-menubar-view.h
+++ b/src/nact/nact-main-menubar-view.h
@@ -37,9 +37,7 @@
* @include: nact/nact-main-menubar-view.h
*/
-#include <gtk/gtk.h>
-
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
G_BEGIN_DECLS
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 5be793f..413555d 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -57,11 +57,11 @@
#include "nact-iexecution-tab.h"
#include "nact-iproperties-tab.h"
#include "nact-main-tab.h"
-#include "nact-main-menubar.h"
#include "nact-main-menubar-file.h"
#include "nact-main-statusbar.h"
#include "nact-marshal.h"
#include "nact-main-window.h"
+#include "nact-menubar.h"
#include "nact-confirm-logout.h"
#include "nact-sort-buttons.h"
@@ -166,10 +166,10 @@ static void instance_set_property( GObject *object, guint property_id, const
static void instance_dispose( GObject *application );
static void instance_finalize( GObject *application );
-static void on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel );
-static void on_base_initialize_base_window( NactMainWindow *window );
+static void on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel, gpointer user_data );
+static void on_base_initialize_base_window( NactMainWindow *window, gpointer user_data );
static gchar *on_base_get_wsp_id( const BaseWindow *window );
-static void on_base_all_widgets_showed( NactMainWindow *window );
+static void on_base_all_widgets_showed( NactMainWindow *window, gpointer user_data );
static gboolean actually_delete_item( NactMainWindow *window, NAObject *item, NAUpdater *updater, GList **not_deleted, GSList **messages );
@@ -198,6 +198,8 @@ static void reload( NactMainWindow *window );
static gchar *iabout_get_application_name( NAIAbout *instance );
static GtkWindow *iabout_get_toplevel( NAIAbout *instance );
+static gboolean on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainWindow *window );
+
GType
nact_main_window_get_type( void )
{
@@ -763,7 +765,6 @@ instance_dispose( GObject *window )
nact_ienvironment_tab_dispose( NACT_IENVIRONMENT_TAB( window ));
nact_iexecution_tab_dispose( NACT_IEXECUTION_TAB( window ));
nact_iproperties_tab_dispose( NACT_IPROPERTIES_TAB( window ));
- nact_main_menubar_dispose( self );
/* chain up to the parent class */
if( G_OBJECT_CLASS( st_parent_class )->dispose ){
@@ -808,24 +809,27 @@ nact_main_window_new( const NactApplication *application )
BASE_PROP_TOPLEVEL_NAME, st_toplevel_name,
NULL );
+ nact_menubar_new( BASE_WINDOW( window ));
+
return( window );
}
/*
- * note that for this NactMainWindow, on_baseinitialize_gtk_toplevel() and
+ * note that for this NactMainWindow, on_base_initialize_gtk_toplevel() and
* on_base_initialize_base_window() are roughly equivalent, as there is only
* one occurrence on this window in the application: closing this window
* is the same than quitting the application
*/
static void
-on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel )
+on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel, gpointer user_data )
{
static const gchar *thisfn = "nact_main_window_on_base_initialize_gtk_toplevel";
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
if( !window->private->dispose_has_run ){
- g_debug( "%s: window=%p, toplevel=%p", thisfn, ( void * ) window, ( void * ) toplevel );
+ g_debug( "%s: window=%p, toplevel=%p, user_data=%p",
+ thisfn, ( void * ) window, ( void * ) toplevel, ( void * ) user_data );
nact_iactions_list_set_management_mode( NACT_IACTIONS_LIST( window ), IACTIONS_LIST_MANAGEMENT_MODE_EDITION );
nact_iactions_list_initial_load_toplevel( NACT_IACTIONS_LIST( window ));
@@ -846,7 +850,7 @@ on_base_initialize_gtk_toplevel( NactMainWindow *window, GtkWindow *toplevel )
}
static void
-on_base_initialize_base_window( NactMainWindow *window )
+on_base_initialize_base_window( NactMainWindow *window, gpointer user_data )
{
static const gchar *thisfn = "nact_main_window_on_base_initialize_base_window";
NactApplication *application;
@@ -859,7 +863,7 @@ on_base_initialize_base_window( NactMainWindow *window )
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
if( !window->private->dispose_has_run ){
- g_debug( "%s: window=%p", thisfn, ( void * ) window );
+ g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
updater = nact_application_get_updater( application );
@@ -890,8 +894,6 @@ on_base_initialize_base_window( NactMainWindow *window )
nact_iexecution_tab_runtime_init_toplevel( NACT_IEXECUTION_TAB( window ));
nact_iproperties_tab_runtime_init_toplevel( NACT_IPROPERTIES_TAB( window ));
- nact_main_menubar_runtime_init( window );
-
na_settings_register_key_callback( settings, NA_IPREFS_ITEMS_LIST_ORDER_MODE, G_CALLBACK( on_settings_order_mode_changed ), window );
/* fill the IActionsList at last so that all signals are connected
@@ -907,8 +909,9 @@ on_base_initialize_base_window( NactMainWindow *window )
base_window_signal_connect( BASE_WINDOW( window ),
G_OBJECT( window ), MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED, G_CALLBACK( on_main_window_level_zero_order_changed ));
- nact_main_menubar_file_install_autosave( window );
-
+ base_window_signal_connect( BASE_WINDOW( window ),
+ G_OBJECT( base_window_get_gtk_toplevel( BASE_WINDOW( window ))),
+ "delete-event", G_CALLBACK( on_delete_event ));
}
}
@@ -919,7 +922,7 @@ on_base_get_wsp_id( const BaseWindow *window )
}
static void
-on_base_all_widgets_showed( NactMainWindow *window )
+on_base_all_widgets_showed( NactMainWindow *window, gpointer user_data )
{
static const gchar *thisfn = "nact_main_window_on_base_all_widgets_showed";
@@ -936,7 +939,7 @@ on_base_all_widgets_showed( NactMainWindow *window )
g_return_if_fail( NACT_IS_IPROPERTIES_TAB( window ));
if( !window->private->dispose_has_run ){
- g_debug( "%s: window=%p", thisfn, ( void * ) window );
+ g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
raz_main_properties( window );
@@ -1607,3 +1610,21 @@ iabout_get_toplevel( NAIAbout *instance )
return( base_window_get_gtk_toplevel( BASE_WINDOW( instance )));
}
+
+/*
+ * triggered when the user clicks on the top right [X] button
+ * returns %TRUE to stop the signal to be propagated (which would cause the
+ * window to be destroyed); instead we gracefully quit the application
+ */
+static gboolean
+on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainWindow *window )
+{
+ static const gchar *thisfn = "nact_main_window_on_delete_event";
+
+ g_debug( "%s: toplevel=%p, event=%p, window=%p",
+ thisfn, ( void * ) toplevel, ( void * ) event, ( void * ) window );
+
+ nact_main_menubar_file_on_quit( NULL, window );
+
+ return( TRUE );
+}
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-menubar.c
similarity index 66%
rename from src/nact/nact-main-menubar.c
rename to src/nact/nact-menubar.c
index 9b1039c..df83553 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-menubar.c
@@ -34,6 +34,9 @@
#include <glib/gi18n.h>
+#include "nact-menubar.h"
+
+/* *** */
#include <api/na-object-api.h>
#include <api/na-core-utils.h>
@@ -48,7 +51,7 @@
#include "nact-main-statusbar.h"
#include "nact-main-toolbar.h"
#include "nact-main-tab.h"
-#include "nact-main-menubar.h"
+#include "nact-menubar.h"
#include "nact-main-menubar-file.h"
#include "nact-main-menubar-edit.h"
#include "nact-main-menubar-view.h"
@@ -57,10 +60,6 @@
#include "nact-main-menubar-help.h"
#include "nact-sort-buttons.h"
-#define MENUBAR_PROP_STATUS_CONTEXT "nact-menubar-status-context"
-#define MENUBAR_PROP_MAIN_STATUS_CONTEXT "nact-menubar-main-status-context"
-#define MENUBAR_PROP_ACTIONS_GROUP "nact-menubar-actions-group"
-
enum {
MENUBAR_FILE_TOOLBAR_POS = 0,
MENUBAR_EDIT_TOOLBAR_POS,
@@ -68,20 +67,6 @@ enum {
MENUBAR_HELP_TOOLBAR_POS
};
-/* GtkActivatable
- * gtk_action_get_tooltip() is only available starting with Gtk 2.16
- * until this is a required level, we must have some code to do the
- * same thing
- */
-#undef NA_HAS_GTK_ACTIVATABLE
-#if GTK_CHECK_VERSION( 2,16,0 )
- #define NA_HAS_GTK_ACTIVATABLE
-#endif
-
-#ifndef NA_HAS_GTK_ACTIVATABLE
-#define MENUBAR_PROP_ITEM_ACTION "nact-menubar-item-action"
-#endif
-
static void on_iactions_list_count_updated( NactMainWindow *window, gint menus, gint actions, gint profiles );
static void on_iactions_list_selection_changed( NactMainWindow *window, GList *selected );
static void on_iactions_list_focus_in( NactMainWindow *window, gpointer user_data );
@@ -90,13 +75,21 @@ static void on_iactions_list_status_changed( NactMainWindow *window, gpointe
static void on_level_zero_order_changed( NactMainWindow *window, gpointer user_data );
static void on_update_sensitivities( NactMainWindow *window, gpointer user_data );
-static gboolean on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainWindow *window );
-static void on_destroy_callback( gpointer data );
-static void on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window );
-static void on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window );
static void on_popup_selection_done(GtkMenuShell *menushell, NactMainWindow *window );
-static void on_proxy_connect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window );
-static void on_proxy_disconnect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window );
+/* *** */
+
+/* private class data
+ */
+struct _NactMenubarClassPrivate {
+ void *empty; /* so that gcc -pedantic is happy */
+};
+
+struct _NactMenubarPrivate {
+ gboolean dispose_has_run;
+ BaseWindow *window;
+ GtkUIManager *ui_manager;
+ GtkActionGroup *action_group;
+};
static const GtkActionEntry entries[] = {
@@ -225,21 +218,200 @@ static const GtkToggleActionEntry toolbar_entries[] = {
G_CALLBACK( nact_main_menubar_view_on_toolbar_help ), FALSE },
};
+/* GtkActivatable
+ * gtk_action_get_tooltip() is only available starting with Gtk 2.16
+ * until this is a required level, we must have some code to do the
+ * same thing
+ */
+#undef NA_HAS_GTK_ACTIVATABLE
+#if GTK_CHECK_VERSION( 2,16,0 )
+ #define NA_HAS_GTK_ACTIVATABLE
+#endif
+
+#ifndef NA_HAS_GTK_ACTIVATABLE
+#define MENUBAR_PROP_ITEM_ACTION "menubar-item-action"
+#endif
+
+#define MENUBAR_PROP_STATUS_CONTEXT "menubar-status-context"
+#define MENUBAR_PROP_MAIN_STATUS_CONTEXT "menubar-main-status-context"
+
+static const gchar *st_ui_menubar_actions = PKGDATADIR "/nautilus-actions-config-tool.actions";
+static const gchar *st_ui_maintainer_actions = PKGDATADIR "/nautilus-actions-maintainer.actions";
+
+static GObjectClass *st_parent_class = NULL;
+
+static GType register_type( void );
+static void class_init( NactMenubarClass *klass );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_dispose( GObject *application );
+static void instance_finalize( GObject *application );
+
+static void on_base_initialize_window( BaseWindow *window, gpointer user_data );
+static void on_ui_manager_proxy_connect( GtkUIManager *ui_manager, GtkAction *action, GtkWidget *proxy, BaseWindow *window );
+static void on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window );
+static void on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window );
+static void on_finalize_window( NactMenubar *bar, GObject *window );
+
+GType
+nact_menubar_get_type( void )
+{
+ static GType type = 0;
+
+ if( !type ){
+ type = register_type();
+ }
+
+ return( type );
+}
+
+static GType
+register_type( void )
+{
+ static const gchar *thisfn = "nact_menubar_register_type";
+ GType type;
+
+ static GTypeInfo info = {
+ sizeof( NactMenubarClass ),
+ ( GBaseInitFunc ) NULL,
+ ( GBaseFinalizeFunc ) NULL,
+ ( GClassInitFunc ) class_init,
+ NULL,
+ NULL,
+ sizeof( NactMenubar ),
+ 0,
+ ( GInstanceInitFunc ) instance_init
+ };
+
+ g_debug( "%s", thisfn );
+
+ type = g_type_register_static( G_TYPE_OBJECT, "NactMenubar", &info, 0 );
+
+ return( type );
+}
+
+static void
+class_init( NactMenubarClass *klass )
+{
+ static const gchar *thisfn = "nact_menubar_class_init";
+ GObjectClass *object_class;
+
+ g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+
+ st_parent_class = g_type_class_peek_parent( klass );
+
+ object_class = G_OBJECT_CLASS( klass );
+ object_class->dispose = instance_dispose;
+ object_class->finalize = instance_finalize;
+
+ klass->private = g_new0( NactMenubarClassPrivate, 1 );
+}
+
+static void
+instance_init( GTypeInstance *instance, gpointer klass )
+{
+ static const gchar *thisfn = "nact_menubar_instance_init";
+ NactMenubar *self;
+
+ g_return_if_fail( NACT_IS_MENUBAR( instance ));
+
+ g_debug( "%s: instance=%p (%s), klass=%p",
+ thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
+
+ self = NACT_MENUBAR( instance );
+
+ self->private = g_new0( NactMenubarPrivate, 1 );
+
+ self->private->dispose_has_run = FALSE;
+}
+
+static void
+instance_dispose( GObject *object )
+{
+ static const gchar *thisfn = "nact_menubar_instance_dispose";
+ NactMenubar *self;
+
+ g_return_if_fail( NACT_IS_MENUBAR( object ));
+
+ self = NACT_MENUBAR( object );
+
+ if( !self->private->dispose_has_run ){
+ g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
+
+ self->private->dispose_has_run = TRUE;
+
+ g_object_unref( self->private->action_group );
+ g_object_unref( self->private->ui_manager );
+
+ /* chain up to the parent class */
+ if( G_OBJECT_CLASS( st_parent_class )->dispose ){
+ G_OBJECT_CLASS( st_parent_class )->dispose( object );
+ }
+ }
+}
+
+static void
+instance_finalize( GObject *instance )
+{
+ static const gchar *thisfn = "nact_menubar_instance_finalize";
+ NactMenubar *self;
+ MenubarIndicatorsStruct *mis;
+
+ g_return_if_fail( NACT_IS_MENUBAR( instance ));
+
+ g_debug( "%s: instance=%p (%s)", thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ));
+
+ self = NACT_MENUBAR( instance );
+
+ mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( self->private->window ), MENUBAR_PROP_INDICATORS );
+ g_free( mis );
+
+ g_free( self->private );
+
+ /* chain call to parent class */
+ if( G_OBJECT_CLASS( st_parent_class )->finalize ){
+ G_OBJECT_CLASS( st_parent_class )->finalize( instance );
+ }
+}
+
/**
- * nact_main_menubar_runtime_init:
- * @window: the #NactMainWindow to which the menubar is attached.
+ * nact_menubar_new:
+ * @window: the main window which embeds the menubar, usually the #NactMainWindow.
+ *
+ * The created menubar attachs itself to the @window; it also connect a weak
+ * reference to this same @window, thus automatically g_object_unref() -ing
+ * itself at @window finalization time.
*
- * Creates the menubar.
- * Connects to all possible signals which may have an impact on action
- * sensitivities.
+ * The menubar also takes advantage of #BaseWindow messages to initialize
+ * its Gtk widgets.
+ *
+ * Returns: a new #NactMenubar object.
*/
-void
-nact_main_menubar_runtime_init( NactMainWindow *window )
+NactMenubar *
+nact_menubar_new( BaseWindow *window )
{
- static const gchar *thisfn = "nact_main_menubar_init";
- GtkActionGroup *action_group;
- GtkUIManager *ui_manager;
- GError *error = NULL;
+ NactMenubar *bar;
+
+ g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
+
+ bar = g_object_new( NACT_MENUBAR_TYPE, NULL );
+
+ bar->private->window = window;
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), BASE_SIGNAL_INITIALIZE_WINDOW, G_CALLBACK( on_base_initialize_window ));
+
+ g_object_weak_ref( G_OBJECT( window ), ( GWeakNotify ) on_finalize_window, bar );
+
+ g_object_set_data( G_OBJECT( window ), WINDOW_DATA_MENUBAR, bar );
+
+ return( bar );
+}
+
+static void
+on_base_initialize_window( BaseWindow *window, gpointer user_data )
+{
+ static const gchar *thisfn = "nact_menubar_on_base_initialize_window";
+ GError *error;
guint merge_id;
GtkAccelGroup *accel_group;
GtkWidget *menubar, *vbox;
@@ -247,141 +419,197 @@ nact_main_menubar_runtime_init( NactMainWindow *window )
MenubarIndicatorsStruct *mis;
gboolean has_maintainer_menu;
- g_debug( "%s: window=%p", thisfn, ( void * ) window );
-
- /* create the menubar:
- * - create action group, and insert list of actions in it
- * - create ui_manager, and insert action group in it
- * - merge inserted actions group with ui xml definition
- * - install accelerators in the main window
- * - pack menu bar in the main window
- */
- ui_manager = gtk_ui_manager_new();
- g_object_set_data_full( G_OBJECT( window ), MENUBAR_PROP_UI_MANAGER, ui_manager, ( GDestroyNotify ) on_destroy_callback );
- g_debug( "%s: ui_manager=%p", thisfn, ( void * ) ui_manager );
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( ui_manager ),
- "connect-proxy",
- G_CALLBACK( on_proxy_connect ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( ui_manager ),
- "disconnect-proxy",
- G_CALLBACK( on_proxy_disconnect ));
-
- action_group = gtk_action_group_new( "MenubarActions" );
- g_object_set_data_full( G_OBJECT( window ), MENUBAR_PROP_ACTIONS_GROUP, action_group, ( GDestroyNotify ) on_destroy_callback );
- g_debug( "%s: action_group=%p", thisfn, ( void * ) action_group );
-
- gtk_action_group_set_translation_domain( action_group, GETTEXT_PACKAGE );
- gtk_action_group_add_actions( action_group, entries, G_N_ELEMENTS( entries ), window );
- gtk_action_group_add_toggle_actions( action_group, toolbar_entries, G_N_ELEMENTS( toolbar_entries ), window );
- gtk_ui_manager_insert_action_group( ui_manager, action_group, 0 );
-
- merge_id = gtk_ui_manager_add_ui_from_file( ui_manager, PKGDATADIR "/nautilus-actions-config-tool.actions", &error );
- if( merge_id == 0 || error ){
- g_warning( "%s: error=%s", thisfn, error->message );
- g_error_free( error );
- }
+ BAR_WINDOW_VOID( window );
+
+ if( !bar->private->dispose_has_run ){
+ g_debug( "%s: window=%p (%s), user_data=%p", thisfn,
+ ( void * ) window, G_OBJECT_TYPE_NAME( window ), ( void * ) user_data );
+
+ /* create the menubar:
+ * - create action group, and insert list of actions in it
+ * - create the ui manager, and insert action group in it
+ * - merge inserted actions group with ui xml definition
+ * - install accelerators in the main window
+ * - pack menu bar in the main window
+ *
+ * "disconnect-proxy" signal is never triggered.
+ */
+ bar->private->ui_manager = gtk_ui_manager_new();
+ g_debug( "%s: ui_manager=%p", thisfn, ( void * ) bar->private->ui_manager );
+
+ base_window_signal_connect( window,
+ G_OBJECT( bar->private->ui_manager ),
+ "connect-proxy", G_CALLBACK( on_ui_manager_proxy_connect ));
+
+ bar->private->action_group = gtk_action_group_new( "MenubarActions" );
+ g_debug( "%s: action_group=%p", thisfn, ( void * ) bar->private->action_group );
+
+ gtk_action_group_set_translation_domain( bar->private->action_group, GETTEXT_PACKAGE );
+ gtk_action_group_add_actions( bar->private->action_group, entries, G_N_ELEMENTS( entries ), window );
+ gtk_action_group_add_toggle_actions( bar->private->action_group, toolbar_entries, G_N_ELEMENTS( toolbar_entries ), window );
+ gtk_ui_manager_insert_action_group( bar->private->ui_manager, bar->private->action_group, 0 );
+
+ error = NULL;
+ merge_id = gtk_ui_manager_add_ui_from_file( bar->private->ui_manager, st_ui_menubar_actions, &error );
+ if( merge_id == 0 || error ){
+ g_warning( "%s: error=%s", thisfn, error->message );
+ g_error_free( error );
+ }
- has_maintainer_menu = FALSE;
+ has_maintainer_menu = FALSE;
#ifdef NA_MAINTAINER_MODE
- has_maintainer_menu = TRUE;
+ has_maintainer_menu = TRUE;
#endif
- if( has_maintainer_menu ){
- merge_id = gtk_ui_manager_add_ui_from_file( ui_manager, PKGDATADIR "/nautilus-actions-maintainer.actions", &error );
- if( merge_id == 0 || error ){
- g_warning( "%s: error=%s", thisfn, error->message );
- g_error_free( error );
+ if( has_maintainer_menu ){
+ error = NULL;
+ merge_id = gtk_ui_manager_add_ui_from_file( bar->private->ui_manager, st_ui_maintainer_actions, &error );
+ if( merge_id == 0 || error ){
+ g_warning( "%s: error=%s", thisfn, error->message );
+ g_error_free( error );
+ }
}
+
+ toplevel = base_window_get_gtk_toplevel( window );
+ accel_group = gtk_ui_manager_get_accel_group( bar->private->ui_manager );
+ gtk_window_add_accel_group( toplevel, accel_group );
+
+ menubar = gtk_ui_manager_get_widget( bar->private->ui_manager, "/ui/MainMenubar" );
+ vbox = base_window_get_widget( window, "MenubarVBox" );
+ gtk_box_pack_start( GTK_BOX( vbox ), menubar, FALSE, FALSE, 0 );
+
+ /* this creates a submenu in the toolbar */
+ /*gtk_container_add( GTK_CONTAINER( vbox ), toolbar );*/
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), IACTIONS_LIST_SIGNAL_LIST_COUNT_UPDATED, G_CALLBACK( on_iactions_list_count_updated ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), IACTIONS_LIST_SIGNAL_SELECTION_CHANGED, G_CALLBACK( on_iactions_list_selection_changed ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), IACTIONS_LIST_SIGNAL_FOCUS_IN, G_CALLBACK( on_iactions_list_focus_in ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), IACTIONS_LIST_SIGNAL_FOCUS_OUT, G_CALLBACK( on_iactions_list_focus_out ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), IACTIONS_LIST_SIGNAL_STATUS_CHANGED, G_CALLBACK( on_iactions_list_status_changed ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, G_CALLBACK( on_update_sensitivities ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( window ), MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED, G_CALLBACK( on_level_zero_order_changed ));
+
+ mis = g_new0( MenubarIndicatorsStruct, 1 );
+ g_object_set_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS, mis );
+
+ nact_main_toolbar_init(( NactMainWindow * ) window, bar->private->action_group );
+ }
+}
+
+/*
+ * action: GtkAction, GtkToggleAction
+ * proxy: GtkImageMenuItem, GtkCheckMenuItem, GtkToolButton
+ */
+static void
+on_ui_manager_proxy_connect( GtkUIManager *ui_manager, GtkAction *action, GtkWidget *proxy, BaseWindow *window )
+{
+ static const gchar *thisfn = "nact_menubar_on_ui_manager_proxy_connect";
+
+ g_debug( "%s: ui_manager=%p (%s), action=%p (%s), proxy=%p (%s), window=%p (%s)",
+ thisfn,
+ ( void * ) ui_manager, G_OBJECT_TYPE_NAME( ui_manager ),
+ ( void * ) action, G_OBJECT_TYPE_NAME( action ),
+ ( void * ) proxy, G_OBJECT_TYPE_NAME( proxy ),
+ ( void * ) window, G_OBJECT_TYPE_NAME( window ));
+
+ if( GTK_IS_MENU_ITEM( proxy )){
+
+ base_window_signal_connect( window,
+ G_OBJECT( proxy ), "select", G_CALLBACK( on_menu_item_selected ));
+
+ base_window_signal_connect( window,
+ G_OBJECT( proxy ), "deselect", G_CALLBACK( on_menu_item_deselected ));
+
+#ifndef NA_HAS_GTK_ACTIVATABLE
+ g_object_set_data( G_OBJECT( proxy ), MENUBAR_PROP_ITEM_ACTION, action );
+#endif
}
+}
- toplevel = base_window_get_gtk_toplevel( BASE_WINDOW( window ));
- accel_group = gtk_ui_manager_get_accel_group( ui_manager );
- gtk_window_add_accel_group( toplevel, accel_group );
-
- menubar = gtk_ui_manager_get_widget( ui_manager, "/ui/MainMenubar" );
- vbox = base_window_get_widget( BASE_WINDOW( window ), "MenubarVBox" );
- gtk_box_pack_start( GTK_BOX( vbox ), menubar, FALSE, FALSE, 0 );
-
- /* this creates a submenu in the toolbar */
- /*gtk_container_add( GTK_CONTAINER( vbox ), toolbar );*/
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( toplevel ),
- "delete-event",
- G_CALLBACK( on_delete_event ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- IACTIONS_LIST_SIGNAL_LIST_COUNT_UPDATED,
- G_CALLBACK( on_iactions_list_count_updated ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- IACTIONS_LIST_SIGNAL_SELECTION_CHANGED,
- G_CALLBACK( on_iactions_list_selection_changed ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- IACTIONS_LIST_SIGNAL_FOCUS_IN,
- G_CALLBACK( on_iactions_list_focus_in ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- IACTIONS_LIST_SIGNAL_FOCUS_OUT,
- G_CALLBACK( on_iactions_list_focus_out ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- IACTIONS_LIST_SIGNAL_STATUS_CHANGED,
- G_CALLBACK( on_iactions_list_status_changed ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES,
- G_CALLBACK( on_update_sensitivities ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED,
- G_CALLBACK( on_level_zero_order_changed ));
-
- mis = g_new0( MenubarIndicatorsStruct, 1 );
- g_object_set_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS, mis );
-
- nact_main_toolbar_init( window, action_group );
+/*
+ * gtk_activatable_get_related_action() and gtk_action_get_tooltip()
+ * are only available starting with Gtk 2.16
+ */
+static void
+on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window )
+{
+ GtkAction *action;
+ gchar *tooltip;
+
+ /*g_debug( "nact_main_menubar_on_menu_item_selected: proxy=%p (%s), window=%p (%s)",
+ ( void * ) proxy, G_OBJECT_TYPE_NAME( proxy ),
+ ( void * ) window, G_OBJECT_TYPE_NAME( window ));*/
+
+ tooltip = NULL;
+
+#ifdef NA_HAS_GTK_ACTIVATABLE
+ action = gtk_activatable_get_related_action( GTK_ACTIVATABLE( proxy ));
+ if( action ){
+ tooltip = ( gchar * ) gtk_action_get_tooltip( action );
+ }
+#else
+ action = GTK_ACTION( g_object_get_data( G_OBJECT( proxy ), MENUBAR_PROP_ITEM_ACTION ));
+ if( action ){
+ g_object_get( G_OBJECT( action ), "tooltip", &tooltip, NULL );
+ }
+#endif
+
+ if( tooltip ){
+ nact_main_statusbar_display_status( window, MENUBAR_PROP_STATUS_CONTEXT, tooltip );
+ }
+
+#ifndef NA_HAS_GTK_ACTIVATABLE
+ g_free( tooltip );
+#endif
+}
+
+static void
+on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window )
+{
+ nact_main_statusbar_hide_status( window, MENUBAR_PROP_STATUS_CONTEXT );
+}
+
+/*
+ * triggered just before the NactMainWindow is finalized
+ */
+static void
+on_finalize_window( NactMenubar *bar, GObject *window )
+{
+ static const gchar *thisfn = "nact_menubar_on_finalize_window";
+
+ g_return_if_fail( NACT_IS_MENUBAR( bar ));
+
+ g_debug( "%s: bar=%p (%s), window=%p", thisfn,
+ ( void * ) bar, G_OBJECT_TYPE_NAME( bar ), ( void * ) window );
+
+ g_object_unref( bar );
}
/**
- * nact_main_menubar_dispose:
- * @window: this #NactMainWindow window.
+ * nact_menubar_get_ui_manager:
+ * @bar: this #NactMenubar instance.
*
- * Release internally allocated resources.
+ * Returns: the attached GtkUIManager.
*/
-void
-nact_main_menubar_dispose( NactMainWindow *window )
+GtkUIManager *
+nact_menubar_get_ui_manager( const NactMenubar *bar )
{
- static const gchar *thisfn = "nact_main_menubar_dispose";
- MenubarIndicatorsStruct *mis;
-
- g_debug( "%s: window=%p", thisfn, ( void * ) window );
- g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+ g_return_val_if_fail( NACT_IS_MENUBAR( bar ), NULL );
- mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
- g_free( mis );
+ return( bar->private->dispose_has_run ? NULL : bar->private->ui_manager );
}
/**
@@ -410,12 +638,12 @@ nact_main_menubar_is_level_zero_order_changed( const NactMainWindow *window )
void
nact_main_menubar_open_popup( NactMainWindow *instance, GdkEventButton *event )
{
- GtkUIManager *ui_manager;
GtkWidget *menu;
MenubarIndicatorsStruct *mis;
- ui_manager = ( GtkUIManager * ) g_object_get_data( G_OBJECT( instance ), MENUBAR_PROP_UI_MANAGER );
- menu = gtk_ui_manager_get_widget( ui_manager, "/ui/Popup" );
+ BAR_WINDOW_VOID( instance );
+
+ menu = gtk_ui_manager_get_widget( bar->private->ui_manager, "/ui/Popup" );
mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( instance ), MENUBAR_PROP_INDICATORS );
mis->popup_handler = g_signal_connect( menu, "selection-done", G_CALLBACK( on_popup_selection_done ), instance );
@@ -571,83 +799,12 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
void
nact_main_menubar_enable_item( NactMainWindow *window, const gchar *name, gboolean enabled )
{
- GtkActionGroup *group;
- GtkAction *action;
-
- group = g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_ACTIONS_GROUP );
- action = gtk_action_group_get_action( group, name );
- gtk_action_set_sensitive( action, enabled );
-}
-
-static gboolean
-on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainWindow *window )
-{
- static const gchar *thisfn = "nact_main_menubar_on_delete_event";
-
- g_debug( "%s: toplevel=%p, event=%p, window=%p",
- thisfn, ( void * ) toplevel, ( void * ) event, ( void * ) window );
-
- nact_main_menubar_file_on_quit( NULL, window );
-
- return( TRUE );
-}
-
-/*
- * this callback is declared when attaching ui_manager and actions_group
- * as data to the window ; it is so triggered on NactMainWindow::finalize()
- */
-static void
-on_destroy_callback( gpointer data )
-{
- static const gchar *thisfn = "nact_main_menubar_on_destroy_callback";
-
- g_debug( "%s: data=%p (%s)", thisfn,
- ( void * ) data, G_OBJECT_TYPE_NAME( data ));
-
- g_object_unref( G_OBJECT( data ));
-}
-
-/*
- * gtk_activatable_get_related_action() and gtk_action_get_tooltip()
- * are only available starting with Gtk 2.16
- */
-static void
-on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window )
-{
GtkAction *action;
- gchar *tooltip;
-
- /*g_debug( "nact_main_menubar_on_menu_item_selected: proxy=%p (%s), window=%p (%s)",
- ( void * ) proxy, G_OBJECT_TYPE_NAME( proxy ),
- ( void * ) window, G_OBJECT_TYPE_NAME( window ));*/
- tooltip = NULL;
-
-#ifdef NA_HAS_GTK_ACTIVATABLE
- action = gtk_activatable_get_related_action( GTK_ACTIVATABLE( proxy ));
- if( action ){
- tooltip = ( gchar * ) gtk_action_get_tooltip( action );
- }
-#else
- action = GTK_ACTION( g_object_get_data( G_OBJECT( proxy ), MENUBAR_PROP_ITEM_ACTION ));
- if( action ){
- g_object_get( G_OBJECT( action ), "tooltip", &tooltip, NULL );
- }
-#endif
+ BAR_WINDOW_VOID( window );
- if( tooltip ){
- nact_main_statusbar_display_status( window, MENUBAR_PROP_STATUS_CONTEXT, tooltip );
- }
-
-#ifndef NA_HAS_GTK_ACTIVATABLE
- g_free( tooltip );
-#endif
-}
-
-static void
-on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window )
-{
- nact_main_statusbar_hide_status( window, MENUBAR_PROP_STATUS_CONTEXT );
+ action = gtk_action_group_get_action( bar->private->action_group, name );
+ gtk_action_set_sensitive( action, enabled );
}
static void
@@ -662,41 +819,3 @@ on_popup_selection_done(GtkMenuShell *menushell, NactMainWindow *window )
g_signal_handler_disconnect( menushell, mis->popup_handler );
mis->popup_handler = ( gulong ) 0;
}
-
-static void
-on_proxy_connect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window )
-{
- static const gchar *thisfn = "nact_main_menubar_on_proxy_connect";
-
- g_debug( "%s: action_group=%p (%s), action=%p (%s), proxy=%p (%s), window=%p (%s)",
- thisfn,
- ( void * ) action_group, G_OBJECT_TYPE_NAME( action_group ),
- ( void * ) action, G_OBJECT_TYPE_NAME( action ),
- ( void * ) proxy, G_OBJECT_TYPE_NAME( proxy ),
- ( void * ) window, G_OBJECT_TYPE_NAME( window ));
-
- if( GTK_IS_MENU_ITEM( proxy )){
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( proxy ),
- "select",
- G_CALLBACK( on_menu_item_selected ));
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( proxy ),
- "deselect",
- G_CALLBACK( on_menu_item_deselected ));
-
-#ifndef NA_HAS_GTK_ACTIVATABLE
- g_object_set_data( G_OBJECT( proxy ), MENUBAR_PROP_ITEM_ACTION, action );
-#endif
- }
-}
-
-static void
-on_proxy_disconnect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window )
-{
- /* signal handlers will be automagically disconnected on BaseWindow::dispose */
-}
diff --git a/src/nact/nact-menubar.h b/src/nact/nact-menubar.h
new file mode 100644
index 0000000..b64d399
--- /dev/null
+++ b/src/nact/nact-menubar.h
@@ -0,0 +1,143 @@
+/*
+ * Nautilus-Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
+ *
+ * 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 Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+#ifndef __NACT_MENUBAR_H__
+#define __NACT_MENUBAR_H__
+
+/*
+ * SECTION: nact-menubar
+ * @title: NactMenubar
+ * @short_description: The Menubar class definition
+ * @include: nact-menubar.h
+ *
+ * This is a convenience which embeds the menubar of the application.
+ *
+ * There is one object (because there is one menubar). It is created by
+ * the main window at initialization time. It attachs itself to the window,
+ * and destroys itself - via a weak ref - when the window is finalizing.
+ *
+ * Attaching the object to the window let us connect easily to all 'window'-
+ * class messages, thus reducing the count of needed public functions.
+ *
+ * The #NactMenubar object connects to BASE_SIGNAL_INITIALIZE_WINDOW signal
+ * at instanciation time. The caller (usually a #NactMainWindow) should take
+ * care to connect itself to this signal before creating the #NactMenubar
+ * object if it wants its callback be triggered first.
+ */
+
+#include "base-window.h"
+
+/* *** */
+#include <api/na-object.h>
+#include <core/na-updater.h>
+#include "nact-main-window.h"
+/* *** */
+
+G_BEGIN_DECLS
+
+#define NACT_MENUBAR_TYPE ( nact_menubar_get_type())
+#define NACT_MENUBAR( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, NACT_MENUBAR_TYPE, NactMenubar ))
+#define NACT_MENUBAR_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, NACT_MENUBAR_TYPE, NactMenubarClass ))
+#define NACT_IS_MENUBAR( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, NACT_MENUBAR_TYPE ))
+#define NACT_IS_MENUBAR_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NACT_MENUBAR_TYPE ))
+#define NACT_MENUBAR_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), NACT_MENUBAR_TYPE, NactMenubarClass ))
+
+typedef struct _NactMenubarPrivate NactMenubarPrivate;
+
+typedef struct {
+ /*< private >*/
+ GObject parent;
+ NactMenubarPrivate *private;
+}
+ NactMenubar;
+
+typedef struct _NactMenubarClassPrivate NactMenubarClassPrivate;
+
+typedef struct {
+ /*< private >*/
+ GObjectClass parent;
+ NactMenubarClassPrivate *private;
+}
+ NactMenubarClass;
+
+/* Convenience macros to get a NactMenubar from a BaseWindow
+ */
+#define WINDOW_DATA_MENUBAR "window-data-menubar"
+#define BAR_WINDOW_VOID( window ) \
+ g_return_if_fail( BASE_IS_WINDOW( window )); \
+ NactMenubar *bar = ( NactMenubar * ) g_object_get_data( G_OBJECT( window ), WINDOW_DATA_MENUBAR ); \
+ g_return_if_fail( NACT_IS_MENUBAR( bar ));
+
+GType nact_menubar_get_type( void );
+
+NactMenubar *nact_menubar_new ( BaseWindow *window );
+
+GtkUIManager *nact_menubar_get_ui_manager( const NactMenubar *bar );
+
+/* *** */
+/* this structure is updated each time the user interacts in the
+ * interface ; it is then used to update action sensitivities
+ */
+typedef struct {
+ gint selected_menus;
+ gint selected_actions;
+ gint selected_profiles;
+ gint clipboard_menus;
+ gint clipboard_actions;
+ gint clipboard_profiles;
+ gint list_menus;
+ gint list_actions;
+ gint list_profiles;
+ gboolean is_modified;
+ gboolean have_exportables;
+ gboolean treeview_has_focus;
+ gboolean level_zero_order_changed;
+ gulong popup_handler;
+
+ /* set by the nact_main_menubar_on_update_sensitivities() function itself
+ */
+ gboolean is_level_zero_writable;
+ gboolean has_writable_providers;
+ guint count_selected;
+ GList *selected_items;
+ NAUpdater *updater;
+}
+ MenubarIndicatorsStruct;
+
+#define MENUBAR_PROP_INDICATORS "nact-menubar-indicators"
+
+gboolean nact_main_menubar_is_level_zero_order_changed( const NactMainWindow *window );
+void nact_main_menubar_open_popup( NactMainWindow *window, GdkEventButton *event );
+void nact_main_menubar_enable_item( NactMainWindow *window, const gchar *name, gboolean enabled );
+/* *** */
+
+G_END_DECLS
+
+#endif /* __NACT_MENUBAR_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]