[nautilus-actions] Display toolbars depending on user preferences



commit 03ec70fecdd6aff7acef01eea276c4b11143fb80
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Oct 21 22:10:38 2009 +0200

    Display toolbars depending on user preferences

 ChangeLog                                     |   10 ++
 data/nautilus-actions.schemas.in              |   44 +++++++++
 src/nact/nact-main-menubar.c                  |  124 +++++++++++++++++++++++--
 src/nact/nautilus-actions-config-tool.actions |   12 +-
 src/nact/nautilus-actions-config-tool.ui      |    6 +-
 5 files changed, 178 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3ff209e..009b3aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-10-21 Pierre Wieser <pwieser trychlos org>
 
+	* data/nautilus-actions.schemas.in:
+	Define new preferences for displaying toolbars.
+
+	* src/nact/nact-main-menubar.c:
+	Define new View/Toolbars menu.
+	Display the toolbars depending on user preferences.
+
+	* src/nact/nautilus-actions-config-tool.actions:
+	Toolbar placeholder is now a HBox.
+
 	* src/nact/nact-iactions-list.c:
 	Enable send of focus-in and focus-out messages.
 	Do not retest focus when dealing with accelerators.
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index ac7efc9..01d4740 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -420,6 +420,39 @@ All schemes used by Nautilus can be used here.</long>
     </schema>
 
     <schema>
+      <key>/schemas/apps/nautilus-actions/preferences/main-edit-toolbar</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>Display Edit toolbar</short>
+        <long>Whether to display or not the Edit toolbar in the main window</long>
+      </locale>
+      <default>false</default>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/nautilus-actions/preferences/main-file-toolbar</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>Display File toolbar</short>
+        <long>Whether to display or not the File toolbar in the main window</long>
+      </locale>
+      <default>true</default>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/nautilus-actions/preferences/main-help-toolbar</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>Display Help toolbar</short>
+        <long>Whether to display or not the Help toolbar in the main window</long>
+      </locale>
+      <default>false</default>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/nautilus-actions/preferences/main-paned</key>
       <owner>nautilus-actions</owner>
       <type>int</type>
@@ -431,6 +464,17 @@ All schemes used by Nautilus can be used here.</long>
     </schema>
 
     <schema>
+      <key>/schemas/apps/nautilus-actions/preferences/main-tools-toolbar</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>Display Tools toolbar</short>
+        <long>Whether to display or not the Tools toolbar in the main window</long>
+      </locale>
+      <default>false</default>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/nautilus-actions/preferences/main-window</key>
       <owner>nautilus-actions</owner>
       <type>list</type>
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 5baabd8..7cbb686 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -54,6 +54,10 @@
 #define MENUBAR_PROP_MAIN_STATUS_CONTEXT	"nact-menubar-main-status-context"
 #define MENUBAR_PROP_UI_MANAGER				"nact-menubar-ui-manager"
 #define MENUBAR_PROP_ACTIONS_GROUP			"nact-menubar-actions-group"
+#define MENUBAR_IPREFS_FILE_TOOLBAR			"main-file-toolbar"
+#define MENUBAR_IPREFS_EDIT_TOOLBAR			"main-edit-toolbar"
+#define MENUBAR_IPREFS_TOOLS_TOOLBAR		"main-tools-toolbar"
+#define MENUBAR_IPREFS_HELP_TOOLBAR			"main-help-toolbar"
 
 /* GtkActivatable
  * gtk_action_get_tooltip are only available starting with Gtk 2.16
@@ -120,6 +124,10 @@ static void     on_preferences_activated( GtkAction *action, NactMainWindow *win
 
 static void     on_expand_all_activated( GtkAction *action, NactMainWindow *window );
 static void     on_collapse_all_activated( GtkAction *action, NactMainWindow *window );
+static void     on_view_file_toolbar_activated( GtkToggleAction *action, NactMainWindow *window );
+static void     on_view_edit_toolbar_activated( GtkToggleAction *action, NactMainWindow *window );
+static void     on_view_tools_toolbar_activated( GtkToggleAction *action, NactMainWindow *window );
+static void     on_view_help_toolbar_activated( GtkToggleAction *action, NactMainWindow *window );
 
 static void     on_import_activated( GtkAction *action, NactMainWindow *window );
 static void     on_export_activated( GtkAction *action, NactMainWindow *window );
@@ -138,12 +146,15 @@ static void     on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *win
 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 );
+static void     on_view_toolbar_activated( GtkToggleAction *action, NactMainWindow *window, const gchar *pref, const gchar *path, int pos );
+static void     toolbar_init( NactMainWindow *window, const gchar *pref, gboolean default_value, const gchar *path, const gchar *item );
 
 static const GtkActionEntry entries[] = {
 
 		{ "FileMenu", NULL, N_( "_File" ) },
 		{ "EditMenu", NULL, N_( "_Edit" ) },
 		{ "ViewMenu", NULL, N_( "_View" ) },
+		{ "ViewToolbarMenu", NULL, N_( "_Toolbars" ) },
 		{ "ToolsMenu", NULL, N_( "_Tools" ) },
 		{ "MaintainerMenu", NULL, N_( "_Maintainer" ) },
 		{ "HelpMenu", NULL, N_( "_Help" ) },
@@ -234,6 +245,26 @@ static const GtkActionEntry entries[] = {
 				G_CALLBACK( on_about_activated ) },
 };
 
+static const GtkToggleActionEntry toolbar_entries[] = {
+
+		{ "ViewFileToolbarItem", NULL, N_( "_File" ), NULL,
+				/* i18n: tooltip displayed in the status bar when selecting the 'View File toolbar' item */
+				N_( "Display the File toolbar" ),
+				G_CALLBACK( on_view_file_toolbar_activated ), FALSE },
+		{ "ViewEditToolbarItem", NULL, N_( "_Edit" ), NULL,
+				/* i18n: tooltip displayed in the status bar when selecting the 'View Edit toolbar' item */
+				N_( "Display the Edit toolbar" ),
+				G_CALLBACK( on_view_edit_toolbar_activated ), FALSE },
+		{ "ViewToolsToolbarItem", NULL, N_( "_Tools" ), NULL,
+				/* i18n: tooltip displayed in the status bar when selecting 'View Tools toolbar' item */
+				N_( "Display the Tools toolbar" ),
+				G_CALLBACK( on_view_tools_toolbar_activated ), FALSE },
+		{ "ViewHelpToolbarItem", NULL, N_( "_Help" ), NULL,
+				/* i18n: tooltip displayed in the status bar when selecting 'View Help toolbar' item */
+				N_( "Display the Help toolbar" ),
+				G_CALLBACK( on_view_help_toolbar_activated ), FALSE },
+};
+
 /**
  * nact_main_menubar_runtime_init:
  * @window: the #NactMainWindow to which the menubar is attached.
@@ -251,7 +282,7 @@ nact_main_menubar_runtime_init( NactMainWindow *window )
 	GError *error = NULL;
 	guint merge_id;
 	GtkAccelGroup *accel_group;
-	GtkWidget *menubar, *vbox, *toolbar;
+	GtkWidget *menubar, *vbox;
 	GtkWindow *toplevel;
 	MenubarIndicatorsStruct *mis;
 	gboolean has_maintainer_menu;
@@ -287,6 +318,7 @@ nact_main_menubar_runtime_init( NactMainWindow *window )
 
 	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 );
@@ -316,13 +348,6 @@ nact_main_menubar_runtime_init( NactMainWindow *window )
 	vbox = base_window_get_widget( BASE_WINDOW( window ), "MenubarVBox" );
 	gtk_box_pack_start( GTK_BOX( vbox ), menubar, FALSE, FALSE, 0 );
 
-	/* this works, but we should only display buttons which have icons
-	 * (a button with only text in a toolbar is somewhat sad..
-	 */
-	toolbar = gtk_ui_manager_get_widget( ui_manager, "/ui/FileToolbar" );
-	vbox = base_window_get_widget( BASE_WINDOW( window ), "ToolbarVBox" );
-	gtk_box_pack_start( GTK_BOX( vbox ), toolbar, FALSE, FALSE, 0 );
-
 	/* this creates a submenu in the toolbar */
 	/*gtk_container_add( GTK_CONTAINER( vbox ), toolbar );*/
 
@@ -375,8 +400,12 @@ nact_main_menubar_runtime_init( NactMainWindow *window )
 			G_CALLBACK( on_level_zero_order_changed ));
 
 	mis = g_new0( MenubarIndicatorsStruct, 1 );
-	/*mis->treeview_has_focus = TRUE;*/
 	g_object_set_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS, mis );
+
+	toolbar_init( window, MENUBAR_IPREFS_FILE_TOOLBAR, TRUE, "/ui/FileToolbar", "ViewFileToolbarItem" );
+	toolbar_init( window, MENUBAR_IPREFS_EDIT_TOOLBAR, FALSE, "/ui/EditToolbar", "ViewEditToolbarItem" );
+	toolbar_init( window, MENUBAR_IPREFS_TOOLS_TOOLBAR, FALSE, "/ui/ToolsToolbar", "ViewToolsToolbarItem" );
+	toolbar_init( window, MENUBAR_IPREFS_HELP_TOOLBAR, FALSE, "/ui/HelpToolbar", "ViewHelpToolbarItem" );
 }
 
 /**
@@ -1103,6 +1132,30 @@ on_collapse_all_activated( GtkAction *gtk_action, NactMainWindow *window )
 }
 
 static void
+on_view_file_toolbar_activated( GtkToggleAction *action, NactMainWindow *window )
+{
+	on_view_toolbar_activated( action, window, MENUBAR_IPREFS_FILE_TOOLBAR, "/ui/FileToolbar", 0 );
+}
+
+static void
+on_view_edit_toolbar_activated( GtkToggleAction *action, NactMainWindow *window )
+{
+	on_view_toolbar_activated( action, window, MENUBAR_IPREFS_EDIT_TOOLBAR, "/ui/EditToolbar", 1 );
+}
+
+static void
+on_view_tools_toolbar_activated( GtkToggleAction *action, NactMainWindow *window )
+{
+	on_view_toolbar_activated( action, window, MENUBAR_IPREFS_TOOLS_TOOLBAR, "/ui/ToolsToolbar", 2 );
+}
+
+static void
+on_view_help_toolbar_activated( GtkToggleAction *action, NactMainWindow *window )
+{
+	on_view_toolbar_activated( action, window, MENUBAR_IPREFS_HELP_TOOLBAR, "/ui/HelpToolbar", 3 );
+}
+
+static void
 on_import_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	nact_assistant_import_run( BASE_WINDOW( window ));
@@ -1276,3 +1329,56 @@ on_proxy_disconnect( GtkActionGroup *action_group, GtkAction *action, GtkWidget
 {
 	/* signal handlers will be automagically disconnected on NactWindow::dispose */
 }
+
+static void
+on_view_toolbar_activated( GtkToggleAction *action, NactMainWindow *window, const gchar *pref, const gchar *path, int pos )
+{
+	NactApplication *application;
+	NAPivot *pivot;
+	gboolean is_active;
+	GtkUIManager *ui_manager;
+	GtkWidget *hbox, *toolbar;
+
+	is_active = gtk_toggle_action_get_active( action );
+
+	ui_manager = ( GtkUIManager * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_UI_MANAGER );
+	toolbar = gtk_ui_manager_get_widget( ui_manager, path );
+	hbox = base_window_get_widget( BASE_WINDOW( window ), "ToolbarHBox" );
+	if( is_active ){
+		/*gtk_box_pack_start( GTK_BOX( hbox ), toolbar, FALSE, FALSE, 0 );*/
+		gtk_container_add( GTK_CONTAINER( hbox ), toolbar );
+		gtk_box_reorder_child( GTK_BOX( hbox ), toolbar, pos );
+	} else {
+		gtk_container_remove( GTK_CONTAINER( hbox ), toolbar );
+	}
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
+	na_iprefs_write_bool( NA_IPREFS( pivot ), pref, is_active );
+}
+
+static void
+toolbar_init( NactMainWindow *window, const gchar *pref, gboolean default_value, const gchar *path, const gchar *item )
+{
+	NactApplication *application;
+	NAPivot *pivot;
+	gboolean is_active;
+	GtkUIManager *ui_manager;
+	GtkWidget *hbox, *toolbar;
+	GtkActionGroup *group;
+	GtkToggleAction *action;
+
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
+	is_active = na_iprefs_read_bool( NA_IPREFS( pivot ), pref, default_value );
+	if( is_active ){
+		ui_manager = ( GtkUIManager * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_UI_MANAGER );
+		toolbar = gtk_ui_manager_get_widget( ui_manager, path );
+		hbox = base_window_get_widget( BASE_WINDOW( window ), "ToolbarHBox" );
+		/*gtk_box_pack_start( GTK_BOX( hbox ), toolbar, TRUE, FALSE, 0 );*/
+		gtk_container_add( GTK_CONTAINER( hbox ), toolbar );
+
+		group = g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_ACTIONS_GROUP );
+		action = GTK_TOGGLE_ACTION( gtk_action_group_get_action( group, item ));
+		gtk_toggle_action_set_active( action, TRUE );
+	}
+}
diff --git a/src/nact/nautilus-actions-config-tool.actions b/src/nact/nautilus-actions-config-tool.actions
index 85b53c5..d3c9259 100644
--- a/src/nact/nautilus-actions-config-tool.actions
+++ b/src/nact/nautilus-actions-config-tool.actions
@@ -25,12 +25,12 @@
             <menuitem action="ExpandAllItem" />
             <menuitem action="CollapseAllItem" />
             <separator />
-            <menuitem action="ViewFileToolbarItem" />
-            <menuitem action="ViewEditToolbarItem" />
-            <menuitem action="ViewViewToolbarItem" />
-            <menuitem action="ViewToolsToolbarItem" />
-            <menuitem action="ViewMaintainerToolbarItem" />
-            <menuitem action="ViewHelpToolbarItem" />
+            <menu action="ViewToolbarMenu">
+                <menuitem action="ViewFileToolbarItem" />
+                <menuitem action="ViewEditToolbarItem" />
+                <menuitem action="ViewToolsToolbarItem" />
+                <menuitem action="ViewHelpToolbarItem" />
+            </menu>
         </menu>
         <menu action="ToolsMenu">
             <menuitem action="ImportItem" />
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index 5000d79..18f282c 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -19,7 +19,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkVBox" id="ToolbarVBox">
+          <object class="GtkHBox" id="ToolbarHBox">
             <property name="visible">True</property>
             <child>
               <placeholder/>
@@ -1017,10 +1017,10 @@ Defining several profiles lets you have several commands, each applying with a d
         <child>
           <object class="GtkFileChooserWidget" id="ImportFileChooser">
             <property name="visible">True</property>
-            <property name="local_only">False</property>
-            <property name="use_preview_label">False</property>
             <property name="select_multiple">True</property>
             <property name="preview_widget_active">False</property>
+            <property name="local_only">False</property>
+            <property name="use_preview_label">False</property>
           </object>
           <packing>
             <property name="position">0</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]