1 /*
2  * Nautilus-Actions
3  * A Nautilus extension which offers configurable context menu actions.
4  *
5  * Copyright (C) 2005 The GNOME Foundation
6  * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7  * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8  *
9  * Nautilus-Actions 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.
13  *
14  * Nautilus-Actions 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 GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Nautilus-Actions; see the file COPYING. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  * Authors:
24  *   Frederic Ruaudel <grumz@grumz.net>
25  *   Rodrigo Moya <rodrigo@gnome-db.org>
26  *   Pierre Wieser <pwieser@trychlos.org>
27  *   ... and many others (see AUTHORS)
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include "nact-main-toolbar.h"
35 #include "nact-menubar-priv.h"
36 
37 static void on_view_toolbar_activated( GtkToggleAction *action, BaseWindow *window, int toolbar_id );
38 
39 /**
40  * nact_menubar_view_on_update_sensitivities:
41  * @bar: this #NactMenubar object.
42  *
43  * Update sensitivity of items of the View menu.
44  */
45 void
nact_menubar_view_on_update_sensitivities(const NactMenubar * bar)46 nact_menubar_view_on_update_sensitivities( const NactMenubar *bar )
47 {
48 	guint count_list;
49 
50 	/* expand all/collapse all requires at least one item in the list */
51 	count_list = bar->private->count_menus + bar->private->count_actions + bar->private->count_profiles;
52 	nact_menubar_enable_item( bar, "ExpandAllItem", count_list > 0 );
53 	nact_menubar_enable_item( bar, "CollapseAllItem", count_list > 0 );
54 }
55 
56 /**
57  * nact_menubar_view_on_expand_all:
58  * @gtk_action: the #GtkAction action.
59  * @window: the #BaseWindow main window.
60  *
61  * Triggers View / Expand all item.
62  */
63 void
nact_menubar_view_on_expand_all(GtkAction * gtk_action,BaseWindow * window)64 nact_menubar_view_on_expand_all( GtkAction *gtk_action, BaseWindow *window )
65 {
66 	NactTreeView *items_view;
67 
68 	items_view = nact_main_window_get_items_view( NACT_MAIN_WINDOW( window ));
69 	nact_tree_view_expand_all( items_view );
70 }
71 
72 /**
73  * nact_menubar_view_on_collapse_all:
74  * @gtk_action: the #GtkAction action.
75  * @window: the #BaseWindow main window.
76  *
77  * Triggers View / Collapse all item.
78  */
79 void
nact_menubar_view_on_collapse_all(GtkAction * gtk_action,BaseWindow * window)80 nact_menubar_view_on_collapse_all( GtkAction *gtk_action, BaseWindow *window )
81 {
82 	NactTreeView *items_view;
83 
84 	items_view = nact_main_window_get_items_view( NACT_MAIN_WINDOW( window ));
85 	nact_tree_view_collapse_all( items_view );
86 }
87 
88 /**
89  * nact_menubar_view_on_toolbar_file:
90  * @gtk_action: the #GtkAction action.
91  * @window: the #BaseWindow main window.
92  *
93  * Triggers View / Toolbar / File item.
94  */
95 void
nact_menubar_view_on_toolbar_file(GtkToggleAction * action,BaseWindow * window)96 nact_menubar_view_on_toolbar_file( GtkToggleAction *action, BaseWindow *window )
97 {
98 	/*on_view_toolbar_activated( action, window, MENUBAR_IPREFS_FILE_TOOLBAR, "/ui/FileToolbar", MENUBAR_FILE_TOOLBAR_POS );*/
99 	on_view_toolbar_activated( action, window, MAIN_TOOLBAR_FILE_ID );
100 }
101 
102 /**
103  * nact_menubar_view_on_toolbar_edit:
104  * @gtk_action: the #GtkAction action.
105  * @window: the #BaseWindow main window.
106  *
107  * Triggers View / Toolbar / Edit item.
108  */
109 void
nact_menubar_view_on_toolbar_edit(GtkToggleAction * action,BaseWindow * window)110 nact_menubar_view_on_toolbar_edit( GtkToggleAction *action, BaseWindow *window )
111 {
112 	/*on_view_toolbar_activated( action, window, MENUBAR_IPREFS_EDIT_TOOLBAR, "/ui/EditToolbar", MENUBAR_EDIT_TOOLBAR_POS );*/
113 	on_view_toolbar_activated( action, window, MAIN_TOOLBAR_EDIT_ID );
114 }
115 
116 /**
117  * nact_menubar_view_on_toolbar_tools:
118  * @gtk_action: the #GtkAction action.
119  * @window: the #BaseWindow main window.
120  *
121  * Triggers View / Toolbar / Tools item.
122  */
123 void
nact_menubar_view_on_toolbar_tools(GtkToggleAction * action,BaseWindow * window)124 nact_menubar_view_on_toolbar_tools( GtkToggleAction *action, BaseWindow *window )
125 {
126 	/*on_view_toolbar_activated( action, window, MENUBAR_IPREFS_TOOLS_TOOLBAR, "/ui/ToolsToolbar", MENUBAR_TOOLS_TOOLBAR_POS );*/
127 	on_view_toolbar_activated( action, window, MAIN_TOOLBAR_TOOLS_ID );
128 }
129 
130 /**
131  * nact_menubar_view_on_toolbar_help:
132  * @gtk_action: the #GtkAction action.
133  * @window: the #BaseWindow main window.
134  *
135  * Triggers View / Toolbar / Help item.
136  */
137 void
nact_menubar_view_on_toolbar_help(GtkToggleAction * action,BaseWindow * window)138 nact_menubar_view_on_toolbar_help( GtkToggleAction *action, BaseWindow *window )
139 {
140 	/*on_view_toolbar_activated( action, window, MENUBAR_IPREFS_HELP_TOOLBAR, "/ui/HelpToolbar", MENUBAR_HELP_TOOLBAR_POS );*/
141 	on_view_toolbar_activated( action, window, MAIN_TOOLBAR_HELP_ID );
142 }
143 
144 static void
on_view_toolbar_activated(GtkToggleAction * action,BaseWindow * window,int toolbar_id)145 on_view_toolbar_activated( GtkToggleAction *action, BaseWindow *window, int toolbar_id )
146 {
147 	gboolean is_active;
148 
149 	BAR_WINDOW_VOID( window );
150 
151 	is_active = gtk_toggle_action_get_active( action );
152 
153 	nact_main_toolbar_activate( NACT_MAIN_WINDOW( window ), toolbar_id, bar->private->ui_manager, is_active );
154 }
155 
156 /*
157  * When activating one of the GtkRadioAction which handles the position
158  * of the notebook tabs
159  * @action: the first GtkRadioAction of the group
160  * @current: the activated GtkRadioAction
161  *
162  * This function is triggered once each time we are activating an item of
163  * the menu, after having set the "current_value" to the new value. All
164  * GtkRadioButtons items share the same "current_value".
165  */
166 void
nact_menubar_view_on_tabs_pos_changed(GtkRadioAction * action,GtkRadioAction * current,BaseWindow * window)167 nact_menubar_view_on_tabs_pos_changed( GtkRadioAction *action, GtkRadioAction *current, BaseWindow *window )
168 {
169 	GtkNotebook *notebook;
170 	guint new_pos;
171 
172 	notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
173 	new_pos = gtk_radio_action_get_current_value( action );
174 	gtk_notebook_set_tab_pos( notebook, new_pos );
175 }
176