Update copyright message
[nautilus-actions.git] / src / nact / nact-main-menubar.c
blob3e3d25e070aba0d1117cc2d06f10959bc3a2977c
1 /*
2 * Nautilus Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <glib/gi18n.h>
37 #include <api/na-object-api.h>
38 #include <api/na-core-utils.h>
40 #include <core/na-factory-object.h>
41 #include <core/na-iprefs.h>
42 #include <core/na-ipivot-consumer.h>
43 #include <core/na-io-provider.h>
45 #include "nact-application.h"
46 #include "nact-iactions-list.h"
47 #include "nact-clipboard.h"
48 #include "nact-main-statusbar.h"
49 #include "nact-main-toolbar.h"
50 #include "nact-main-tab.h"
51 #include "nact-main-menubar.h"
52 #include "nact-main-menubar-file.h"
53 #include "nact-main-menubar-edit.h"
54 #include "nact-main-menubar-view.h"
55 #include "nact-main-menubar-tools.h"
56 #include "nact-main-menubar-maintainer.h"
57 #include "nact-main-menubar-help.h"
58 #include "nact-sort-buttons.h"
60 #define MENUBAR_PROP_STATUS_CONTEXT "nact-menubar-status-context"
61 #define MENUBAR_PROP_MAIN_STATUS_CONTEXT "nact-menubar-main-status-context"
62 #define MENUBAR_PROP_ACTIONS_GROUP "nact-menubar-actions-group"
63 #define MENUBAR_IPREFS_FILE_TOOLBAR "main-file-toolbar"
64 #define MENUBAR_IPREFS_EDIT_TOOLBAR "main-edit-toolbar"
65 #define MENUBAR_IPREFS_TOOLS_TOOLBAR "main-tools-toolbar"
66 #define MENUBAR_IPREFS_HELP_TOOLBAR "main-help-toolbar"
68 enum {
69 MENUBAR_FILE_TOOLBAR_POS = 0,
70 MENUBAR_EDIT_TOOLBAR_POS,
71 MENUBAR_TOOLS_TOOLBAR_POS,
72 MENUBAR_HELP_TOOLBAR_POS
75 /* GtkActivatable
76 * gtk_action_get_tooltip are only available starting with Gtk 2.16
77 * until this is a required level, we must have some code to do the
78 * same thing
80 #undef GTK_HAS_ACTIVATABLE
81 #if(( GTK_MAJOR_VERSION > 2 ) || ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 16 ))
82 #define GTK_HAS_ACTIVATABLE
83 #endif
85 #ifndef GTK_HAS_ACTIVATABLE
86 #define MENUBAR_PROP_ITEM_ACTION "nact-menubar-item-action"
87 #endif
89 static void on_iactions_list_count_updated( NactMainWindow *window, gint menus, gint actions, gint profiles );
90 static void on_iactions_list_selection_changed( NactMainWindow *window, GList *selected );
91 static void on_iactions_list_focus_in( NactMainWindow *window, gpointer user_data );
92 static void on_iactions_list_focus_out( NactMainWindow *window, gpointer user_data );
93 static void on_iactions_list_status_changed( NactMainWindow *window, gpointer user_data );
94 static void on_level_zero_order_changed( NactMainWindow *window, gpointer user_data );
95 static void on_update_sensitivities( NactMainWindow *window, gpointer user_data );
97 static gboolean on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainWindow *window );
98 static void on_destroy_callback( gpointer data );
99 static void on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window );
100 static void on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window );
101 static void on_popup_selection_done(GtkMenuShell *menushell, NactMainWindow *window );
102 static void on_proxy_connect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window );
103 static void on_proxy_disconnect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window );
105 static const GtkActionEntry entries[] = {
107 { "FileMenu", NULL, N_( "_File" ) },
108 { "EditMenu", NULL, N_( "_Edit" ) },
109 { "ViewMenu", NULL, N_( "_View" ) },
110 { "ViewToolbarMenu", NULL, N_( "_Toolbars" ) },
111 { "ToolsMenu", NULL, N_( "_Tools" ) },
112 { "MaintainerMenu", NULL, N_( "_Maintainer" ) },
113 { "HelpMenu", NULL, N_( "_Help" ) },
115 { "NewMenuItem", NULL, N_( "New _menu" ), NULL,
116 /* i18n: tooltip displayed in the status bar when selecting the 'New menu' item */
117 N_( "Insert a new menu at the current position" ),
118 G_CALLBACK( nact_main_menubar_file_on_new_menu ) },
119 { "NewActionItem", GTK_STOCK_NEW, N_( "_New action" ), NULL,
120 /* i18n: tooltip displayed in the status bar when selecting the 'New action' item */
121 N_( "Define a new action" ),
122 G_CALLBACK( nact_main_menubar_file_on_new_action ) },
123 { "NewProfileItem", NULL, N_( "New _profile" ), NULL,
124 /* i18n: tooltip displayed in the status bar when selecting the 'New profile' item */
125 N_( "Define a new profile attached to the current action" ),
126 G_CALLBACK( nact_main_menubar_file_on_new_profile ) },
127 { "SaveItem", GTK_STOCK_SAVE, NULL, NULL,
128 /* i18n: tooltip displayed in the status bar when selecting 'Save' item */
129 N_( "Record all the modified actions. Invalid actions will be silently ignored" ),
130 G_CALLBACK( nact_main_menubar_file_on_save ) },
131 { "QuitItem", GTK_STOCK_QUIT, NULL, NULL,
132 /* i18n: tooltip displayed in the status bar when selecting 'Quit' item */
133 N_( "Quit the application" ),
134 G_CALLBACK( nact_main_menubar_file_on_quit ) },
135 { "CutItem" , GTK_STOCK_CUT, NULL, NULL,
136 /* i18n: tooltip displayed in the status bar when selecting the Cut item */
137 N_( "Cut the selected item(s) to the clipboard" ),
138 G_CALLBACK( nact_main_menubar_edit_on_cut ) },
139 { "CopyItem" , GTK_STOCK_COPY, NULL, NULL,
140 /* i18n: tooltip displayed in the status bar when selecting the Copy item */
141 N_( "Copy the selected item(s) to the clipboard" ),
142 G_CALLBACK( nact_main_menubar_edit_on_copy ) },
143 { "PasteItem" , GTK_STOCK_PASTE, NULL, NULL,
144 /* i18n: tooltip displayed in the status bar when selecting the Paste item */
145 N_( "Insert the content of the clipboard just before the current position" ),
146 G_CALLBACK( nact_main_menubar_edit_on_paste ) },
147 { "PasteIntoItem" , NULL, N_( "Paste _into" ), "<Shift><Ctrl>V",
148 /* i18n: tooltip displayed in the status bar when selecting the Paste Into item */
149 N_( "Insert the content of the clipboard as first child of the current item" ),
150 G_CALLBACK( nact_main_menubar_edit_on_paste_into ) },
151 { "DuplicateItem" , NULL, N_( "D_uplicate" ), "",
152 /* i18n: tooltip displayed in the status bar when selecting the Duplicate item */
153 N_( "Duplicate the selected item(s)" ),
154 G_CALLBACK( nact_main_menubar_edit_on_duplicate ) },
155 { "DeleteItem", GTK_STOCK_DELETE, NULL, "Delete",
156 /* i18n: tooltip displayed in the status bar when selecting the Delete item */
157 N_( "Delete the selected item(s)" ),
158 G_CALLBACK( nact_main_menubar_edit_on_delete ) },
159 { "ReloadActionsItem", GTK_STOCK_REFRESH, N_( "_Reload the items" ), "F5",
160 /* i18n: tooltip displayed in the status bar when selecting the 'Reload' item */
161 N_( "Cancel your current modifications and reload the initial list of menus and actions" ),
162 G_CALLBACK( nact_main_menubar_edit_on_reload ) },
163 { "PreferencesItem", GTK_STOCK_PREFERENCES, NULL, NULL,
164 /* i18n: tooltip displayed in the status bar when selecting the 'Preferences' item */
165 N_( "Edit your preferences" ),
166 G_CALLBACK( nact_main_menubar_edit_on_prefererences ) },
167 { "ExpandAllItem" , NULL, N_( "_Expand all" ), NULL,
168 /* i18n: tooltip displayed in the status bar when selecting the Expand all item */
169 N_( "Entirely expand the items hierarchy" ),
170 G_CALLBACK( nact_main_menubar_view_on_expand_all ) },
171 { "CollapseAllItem" , NULL, N_( "_Collapse all" ), NULL,
172 /* i18n: tooltip displayed in the status bar when selecting the Collapse all item */
173 N_( "Entirely collapse the items hierarchy" ),
174 G_CALLBACK( nact_main_menubar_view_on_collapse_all ) },
176 { "ImportItem" , GTK_STOCK_CONVERT, N_( "_Import assistant..." ), "",
177 /* i18n: tooltip displayed in the status bar when selecting the Import item */
178 N_( "Import one or more actions from external (XML) files into your configuration" ),
179 G_CALLBACK( nact_main_menubar_tools_on_import ) },
180 { "ExportItem", NULL, N_( "E_xport assistant..." ), NULL,
181 /* i18n: tooltip displayed in the status bar when selecting the Export item */
182 N_( "Export one or more actions from your configuration to external XML files" ),
183 G_CALLBACK( nact_main_menubar_tools_on_export ) },
185 { "DumpSelectionItem", NULL, N_( "_Dump the selection" ), NULL,
186 /* i18n: tooltip displayed in the status bar when selecting the Dump selection item */
187 N_( "Recursively dump selected items" ),
188 G_CALLBACK( nact_main_menubar_maintainer_on_dump_selection ) },
189 { "BriefTreeStoreDumpItem", NULL, N_( "_Brief tree store dump" ), NULL,
190 /* i18n: tooltip displayed in the status bar when selecting the BriefTreeStoreDump item */
191 N_( "Briefly dump the tree store" ),
192 G_CALLBACK( nact_main_menubar_maintainer_on_brief_tree_store_dump ) },
193 { "ListModifiedItems", NULL, N_( "_List modified items" ), NULL,
194 /* i18n: tooltip displayed in the status bar when selecting the ListModifiedItems item */
195 N_( "List the modified items" ),
196 G_CALLBACK( nact_main_menubar_maintainer_on_list_modified_items ) },
197 { "DumpClipboard", NULL, N_( "_Dump the clipboard" ), NULL,
198 /* i18n: tooltip displayed in the status bar when selecting the DumpClipboard item */
199 N_( "Dump the content of the clipboard object" ),
200 G_CALLBACK( nact_main_menubar_maintainer_on_dump_clipboard ) },
202 { "HelpItem" , GTK_STOCK_HELP, N_( "Contents" ), "F1",
203 /* i18n: tooltip displayed in the status bar when selecting the Help item */
204 N_( "Display help about this program" ),
205 G_CALLBACK( nact_main_menubar_help_on_help ) },
206 { "AboutItem", GTK_STOCK_ABOUT, NULL, NULL,
207 /* i18n: tooltip displayed in the status bar when selecting the About item */
208 N_( "Display informations about this program" ),
209 G_CALLBACK( nact_main_menubar_help_on_about ) },
212 static const GtkToggleActionEntry toolbar_entries[] = {
214 { "ViewFileToolbarItem", NULL, N_( "_File" ), NULL,
215 /* i18n: tooltip displayed in the status bar when selecting the 'View File toolbar' item */
216 N_( "Display the File toolbar" ),
217 G_CALLBACK( nact_main_menubar_view_on_toolbar_file ), FALSE },
218 { "ViewEditToolbarItem", NULL, N_( "_Edit" ), NULL,
219 /* i18n: tooltip displayed in the status bar when selecting the 'View Edit toolbar' item */
220 N_( "Display the Edit toolbar" ),
221 G_CALLBACK( nact_main_menubar_view_on_toolbar_edit ), FALSE },
222 { "ViewToolsToolbarItem", NULL, N_( "_Tools" ), NULL,
223 /* i18n: tooltip displayed in the status bar when selecting 'View Tools toolbar' item */
224 N_( "Display the Tools toolbar" ),
225 G_CALLBACK( nact_main_menubar_view_on_toolbar_tools ), FALSE },
226 { "ViewHelpToolbarItem", NULL, N_( "_Help" ), NULL,
227 /* i18n: tooltip displayed in the status bar when selecting 'View Help toolbar' item */
228 N_( "Display the Help toolbar" ),
229 G_CALLBACK( nact_main_menubar_view_on_toolbar_help ), FALSE },
233 * nact_main_menubar_runtime_init:
234 * @window: the #NactMainWindow to which the menubar is attached.
236 * Creates the menubar.
237 * Connects to all possible signals which may have an impact on action
238 * sensitivities.
240 void
241 nact_main_menubar_runtime_init( NactMainWindow *window )
243 static const gchar *thisfn = "nact_main_menubar_init";
244 GtkActionGroup *action_group;
245 GtkUIManager *ui_manager;
246 GError *error = NULL;
247 guint merge_id;
248 GtkAccelGroup *accel_group;
249 GtkWidget *menubar, *vbox;
250 GtkWindow *toplevel;
251 MenubarIndicatorsStruct *mis;
252 gboolean has_maintainer_menu;
254 g_debug( "%s: window=%p", thisfn, ( void * ) window );
256 /* create the menubar:
257 * - create action group, and insert list of actions in it
258 * - create ui_manager, and insert action group in it
259 * - merge inserted actions group with ui xml definition
260 * - install accelerators in the main window
261 * - pack menu bar in the main window
263 ui_manager = gtk_ui_manager_new();
264 g_object_set_data_full( G_OBJECT( window ), MENUBAR_PROP_UI_MANAGER, ui_manager, ( GDestroyNotify ) on_destroy_callback );
265 g_debug( "%s: ui_manager=%p", thisfn, ( void * ) ui_manager );
267 base_window_signal_connect(
268 BASE_WINDOW( window ),
269 G_OBJECT( ui_manager ),
270 "connect-proxy",
271 G_CALLBACK( on_proxy_connect ));
273 base_window_signal_connect(
274 BASE_WINDOW( window ),
275 G_OBJECT( ui_manager ),
276 "disconnect-proxy",
277 G_CALLBACK( on_proxy_disconnect ));
279 action_group = gtk_action_group_new( "MenubarActions" );
280 g_object_set_data_full( G_OBJECT( window ), MENUBAR_PROP_ACTIONS_GROUP, action_group, ( GDestroyNotify ) on_destroy_callback );
281 g_debug( "%s: action_group=%p", thisfn, ( void * ) action_group );
283 gtk_action_group_set_translation_domain( action_group, GETTEXT_PACKAGE );
284 gtk_action_group_add_actions( action_group, entries, G_N_ELEMENTS( entries ), window );
285 gtk_action_group_add_toggle_actions( action_group, toolbar_entries, G_N_ELEMENTS( toolbar_entries ), window );
286 gtk_ui_manager_insert_action_group( ui_manager, action_group, 0 );
288 merge_id = gtk_ui_manager_add_ui_from_file( ui_manager, PKGDATADIR "/nautilus-actions-config-tool.actions", &error );
289 if( merge_id == 0 || error ){
290 g_warning( "%s: error=%s", thisfn, error->message );
291 g_error_free( error );
294 has_maintainer_menu = FALSE;
295 #ifdef NA_MAINTAINER_MODE
296 has_maintainer_menu = TRUE;
297 #endif
299 if( has_maintainer_menu ){
300 merge_id = gtk_ui_manager_add_ui_from_file( ui_manager, PKGDATADIR "/nautilus-actions-maintainer.actions", &error );
301 if( merge_id == 0 || error ){
302 g_warning( "%s: error=%s", thisfn, error->message );
303 g_error_free( error );
307 toplevel = base_window_get_toplevel( BASE_WINDOW( window ));
308 accel_group = gtk_ui_manager_get_accel_group( ui_manager );
309 gtk_window_add_accel_group( toplevel, accel_group );
311 menubar = gtk_ui_manager_get_widget( ui_manager, "/ui/MainMenubar" );
312 vbox = base_window_get_widget( BASE_WINDOW( window ), "MenubarVBox" );
313 gtk_box_pack_start( GTK_BOX( vbox ), menubar, FALSE, FALSE, 0 );
315 /* this creates a submenu in the toolbar */
316 /*gtk_container_add( GTK_CONTAINER( vbox ), toolbar );*/
318 base_window_signal_connect(
319 BASE_WINDOW( window ),
320 G_OBJECT( toplevel ),
321 "delete-event",
322 G_CALLBACK( on_delete_event ));
324 base_window_signal_connect(
325 BASE_WINDOW( window ),
326 G_OBJECT( window ),
327 IACTIONS_LIST_SIGNAL_LIST_COUNT_UPDATED,
328 G_CALLBACK( on_iactions_list_count_updated ));
330 base_window_signal_connect(
331 BASE_WINDOW( window ),
332 G_OBJECT( window ),
333 IACTIONS_LIST_SIGNAL_SELECTION_CHANGED,
334 G_CALLBACK( on_iactions_list_selection_changed ));
336 base_window_signal_connect(
337 BASE_WINDOW( window ),
338 G_OBJECT( window ),
339 IACTIONS_LIST_SIGNAL_FOCUS_IN,
340 G_CALLBACK( on_iactions_list_focus_in ));
342 base_window_signal_connect(
343 BASE_WINDOW( window ),
344 G_OBJECT( window ),
345 IACTIONS_LIST_SIGNAL_FOCUS_OUT,
346 G_CALLBACK( on_iactions_list_focus_out ));
348 base_window_signal_connect(
349 BASE_WINDOW( window ),
350 G_OBJECT( window ),
351 IACTIONS_LIST_SIGNAL_STATUS_CHANGED,
352 G_CALLBACK( on_iactions_list_status_changed ));
354 base_window_signal_connect(
355 BASE_WINDOW( window ),
356 G_OBJECT( window ),
357 MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES,
358 G_CALLBACK( on_update_sensitivities ));
360 base_window_signal_connect(
361 BASE_WINDOW( window ),
362 G_OBJECT( window ),
363 MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED,
364 G_CALLBACK( on_level_zero_order_changed ));
366 mis = g_new0( MenubarIndicatorsStruct, 1 );
367 g_object_set_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS, mis );
369 nact_main_toolbar_init( window, action_group );
373 * nact_main_menubar_dispose:
374 * @window: this #NactMainWindow window.
376 * Release internally allocated resources.
378 void
379 nact_main_menubar_dispose( NactMainWindow *window )
381 static const gchar *thisfn = "nact_main_menubar_dispose";
382 MenubarIndicatorsStruct *mis;
384 g_debug( "%s: window=%p", thisfn, ( void * ) window );
385 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
387 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
388 g_free( mis );
392 * nact_main_menubar_is_level_zero_order_changed:
393 * @window: the #NactMainWindow main window.
395 * Returns: %TRUE if the level zero has changed, %FALSE else.
397 gboolean
398 nact_main_menubar_is_level_zero_order_changed( const NactMainWindow *window )
400 MenubarIndicatorsStruct *mis;
402 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
404 return( mis->level_zero_order_changed );
408 * nact_main_menubar_open_popup:
409 * @window: this #NactMainWindow window.
410 * @event: the mouse event.
412 * Opens a popup menu.
414 void
415 nact_main_menubar_open_popup( NactMainWindow *instance, GdkEventButton *event )
417 GtkUIManager *ui_manager;
418 GtkWidget *menu;
419 MenubarIndicatorsStruct *mis;
421 ui_manager = ( GtkUIManager * ) g_object_get_data( G_OBJECT( instance ), MENUBAR_PROP_UI_MANAGER );
422 menu = gtk_ui_manager_get_widget( ui_manager, "/ui/Popup" );
424 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( instance ), MENUBAR_PROP_INDICATORS );
425 mis->popup_handler = g_signal_connect( menu, "selection-done", G_CALLBACK( on_popup_selection_done ), instance );
427 g_signal_emit_by_name( instance, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
429 gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL, event->button, event->time );
433 * when the IActionsList is refilled, update our internal counters so
434 * that we are knowing if we have some exportables
436 static void
437 on_iactions_list_count_updated( NactMainWindow *window, gint menus, gint actions, gint profiles )
439 MenubarIndicatorsStruct *mis;
440 gchar *status;
442 g_debug( "nact_main_menubar_on_iactions_list_count_updated: menus=%u, actions=%u, profiles=%u", menus, actions, profiles );
443 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
445 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
446 mis->list_menus = menus;
447 mis->list_actions = actions;
448 mis->list_profiles = profiles;
449 mis->have_exportables = ( mis->list_menus + mis->list_actions > 0 );
451 nact_sort_buttons_enable_buttons( window, mis->list_menus + mis->list_actions > 0 );
453 /* i18n: note the space at the beginning of the sentence */
454 status = g_strdup_printf( _( " %d menu(s), %d action(s), %d profile(s) are currently loaded" ), menus, actions, profiles );
455 nact_main_statusbar_display_status( window, MENUBAR_PROP_MAIN_STATUS_CONTEXT, status );
456 g_free( status );
458 g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
462 * when the selection changes in IActionsList, see what is selected
464 static void
465 on_iactions_list_selection_changed( NactMainWindow *window, GList *selected )
467 MenubarIndicatorsStruct *mis;
469 g_debug( "nact_main_menubar_on_iactions_list_selection_changed: selected=%p (count=%d)",
470 ( void * ) selected, g_list_length( selected ));
471 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
473 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
474 mis->selected_menus = 0;
475 mis->selected_actions = 0;
476 mis->selected_profiles = 0;
477 na_object_item_count_items( selected, &mis->selected_menus, &mis->selected_actions, &mis->selected_profiles, FALSE );
478 g_debug( "nact_main_menubar_on_iactions_list_selection_changed: menus=%d, actions=%d, profiles=%d",
479 mis->selected_menus, mis->selected_actions, mis->selected_profiles );
481 g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
484 static void
485 on_iactions_list_focus_in( NactMainWindow *window, gpointer user_data )
487 MenubarIndicatorsStruct *mis;
489 g_debug( "nact_main_menubar_on_iactions_list_focus_in" );
490 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
492 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
493 mis->treeview_has_focus = TRUE;
494 g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
497 static void
498 on_iactions_list_focus_out( NactMainWindow *window, gpointer user_data )
500 MenubarIndicatorsStruct *mis;
502 g_debug( "nact_main_menubar_on_iactions_list_focus_out" );
503 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
505 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
506 mis->treeview_has_focus = FALSE;
507 g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
510 static void
511 on_iactions_list_status_changed( NactMainWindow *window, gpointer user_data )
513 g_debug( "nact_main_menubar_on_iactions_list_status_changed" );
514 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
516 g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
519 static void
520 on_level_zero_order_changed( NactMainWindow *window, gpointer user_data )
522 MenubarIndicatorsStruct *mis;
524 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
526 g_debug( "nact_main_menubar_on_level_zero_order_changed: change=%s", user_data ? "True":"False" );
528 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
529 mis->level_zero_order_changed = GPOINTER_TO_INT( user_data );
530 g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
533 static void
534 on_update_sensitivities( NactMainWindow *window, gpointer user_data )
536 static const gchar *thisfn = "nact_main_menubar_on_update_sensitivities";
537 NactApplication *application;
538 MenubarIndicatorsStruct *mis;
540 g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
541 g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
543 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
545 application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
546 mis->updater = nact_application_get_updater( application );
547 mis->is_level_zero_writable = na_pivot_is_level_zero_writable( NA_PIVOT( mis->updater ));
549 mis->has_writable_providers = nact_window_has_writable_providers( NACT_WINDOW( window ));
550 g_debug( "%s: has_writable_providers=%s", thisfn, mis->has_writable_providers ? "True":"False" );
552 mis->selected_items = nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window ));
553 mis->count_selected = mis->selected_items ? g_list_length( mis->selected_items ) : 0;
554 g_debug( "%s: count_selected=%d", thisfn, mis->count_selected );
556 nact_main_menubar_file_on_update_sensitivities( window, user_data, mis );
557 nact_main_menubar_edit_on_update_sensitivities( window, user_data, mis );
558 nact_main_menubar_view_on_update_sensitivities( window, user_data, mis );
559 nact_main_menubar_tools_on_update_sensitivities( window, user_data, mis );
560 nact_main_menubar_maintainer_on_update_sensitivities( window, user_data, mis );
561 nact_main_menubar_help_on_update_sensitivities( window, user_data, mis );
563 na_object_unref_selected_items( mis->selected_items );
564 mis->selected_items = NULL;
568 * nact_main_menubar_enable_item:
569 * @window: the #NactMainWindow main application window.
570 * @name: the name of the item in a menu.
571 * @enabled: whether this item should be enabled or not.
573 * Enable/disable an item in an menu.
575 void
576 nact_main_menubar_enable_item( NactMainWindow *window, const gchar *name, gboolean enabled )
578 GtkActionGroup *group;
579 GtkAction *action;
581 group = g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_ACTIONS_GROUP );
582 action = gtk_action_group_get_action( group, name );
583 gtk_action_set_sensitive( action, enabled );
586 static gboolean
587 on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainWindow *window )
589 static const gchar *thisfn = "nact_main_menubar_on_delete_event";
591 g_debug( "%s: toplevel=%p, event=%p, window=%p",
592 thisfn, ( void * ) toplevel, ( void * ) event, ( void * ) window );
594 nact_main_menubar_file_on_quit( NULL, window );
596 return( TRUE );
600 * this callback is declared when attaching ui_manager and actions_group
601 * as data to the window ; it is so triggered on NactMainWindow::finalize()
603 static void
604 on_destroy_callback( gpointer data )
606 static const gchar *thisfn = "nact_main_menubar_on_destroy_callback";
608 g_debug( "%s: data=%p (%s)", thisfn,
609 ( void * ) data, G_OBJECT_TYPE_NAME( data ));
611 g_object_unref( G_OBJECT( data ));
615 * gtk_activatable_get_related_action() and gtk_action_get_tooltip()
616 * are only available starting with Gtk 2.16
618 static void
619 on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window )
621 GtkAction *action;
622 gchar *tooltip;
624 /*g_debug( "nact_main_menubar_on_menu_item_selected: proxy=%p (%s), window=%p (%s)",
625 ( void * ) proxy, G_OBJECT_TYPE_NAME( proxy ),
626 ( void * ) window, G_OBJECT_TYPE_NAME( window ));*/
628 tooltip = NULL;
630 #ifdef GTK_HAS_ACTIVATABLE
631 action = gtk_activatable_get_related_action( GTK_ACTIVATABLE( proxy ));
632 if( action ){
633 tooltip = ( gchar * ) gtk_action_get_tooltip( action );
635 #else
636 action = GTK_ACTION( g_object_get_data( G_OBJECT( proxy ), MENUBAR_PROP_ITEM_ACTION ));
637 if( action ){
638 g_object_get( G_OBJECT( action ), "tooltip", &tooltip, NULL );
640 #endif
642 if( tooltip ){
643 nact_main_statusbar_display_status( window, MENUBAR_PROP_STATUS_CONTEXT, tooltip );
646 #ifndef GTK_HAS_ACTIVATABLE
647 g_free( tooltip );
648 #endif
651 static void
652 on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window )
654 nact_main_statusbar_hide_status( window, MENUBAR_PROP_STATUS_CONTEXT );
657 static void
658 on_popup_selection_done(GtkMenuShell *menushell, NactMainWindow *window )
660 static const gchar *thisfn = "nact_main_menubar_on_popup_selection_done";
661 MenubarIndicatorsStruct *mis;
663 g_debug( "%s", thisfn );
665 mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
666 g_signal_handler_disconnect( menushell, mis->popup_handler );
667 mis->popup_handler = ( gulong ) 0;
670 static void
671 on_proxy_connect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window )
673 static const gchar *thisfn = "nact_main_menubar_on_proxy_connect";
675 g_debug( "%s: action_group=%p (%s), action=%p (%s), proxy=%p (%s), window=%p (%s)",
676 thisfn,
677 ( void * ) action_group, G_OBJECT_TYPE_NAME( action_group ),
678 ( void * ) action, G_OBJECT_TYPE_NAME( action ),
679 ( void * ) proxy, G_OBJECT_TYPE_NAME( proxy ),
680 ( void * ) window, G_OBJECT_TYPE_NAME( window ));
682 if( GTK_IS_MENU_ITEM( proxy )){
684 base_window_signal_connect(
685 BASE_WINDOW( window ),
686 G_OBJECT( proxy ),
687 "select",
688 G_CALLBACK( on_menu_item_selected ));
690 base_window_signal_connect(
691 BASE_WINDOW( window ),
692 G_OBJECT( proxy ),
693 "deselect",
694 G_CALLBACK( on_menu_item_deselected ));
696 #ifndef GTK_HAS_ACTIVATABLE
697 g_object_set_data( G_OBJECT( proxy ), MENUBAR_PROP_ITEM_ACTION, action );
698 #endif
702 static void
703 on_proxy_disconnect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window )
705 /* signal handlers will be automagically disconnected on BaseWindow::dispose */