[nautilus-actions] Creation of a root menu is a user preference



commit b45a7955ecfe2adc0526e87b2317f1b89899dfed
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Oct 18 01:08:03 2009 +0200

    Creation of a root menu is a user preference
    
    This is needed because creating automagically a root menu for displaying About item
    modifies the menu layout in a unfriendly way.

 ChangeLog                                |   20 ++++++
 data/nautilus-actions.schemas.in         |   11 +++
 src/nact/nact-main-window.c              |    1 +
 src/nact/nact-preferences-editor.c       |    9 +++
 src/nact/nautilus-actions-config-tool.ui |   33 +++++++---
 src/plugin/nautilus-actions.c            |  101 +++++++++++++++++++++---------
 src/runtime/na-ipivot-consumer.c         |   37 +++++++++--
 src/runtime/na-ipivot-consumer.h         |   24 +++++--
 src/runtime/na-iprefs.c                  |   48 ++++++++++++++-
 src/runtime/na-iprefs.h                  |    9 ++-
 src/runtime/na-pivot.c                   |   25 +++++++
 11 files changed, 263 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 66a5407..8771e5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2009-10-17 Pierre Wieser <pwieser trychlos org>
 
+	Creation of a root menu in the Nautilus context menu is now a
+	user preference.
+
+	* data/nautilus-actions.schemas.in: Define a schema for the preference.
+
+	* src/nact/nact-preferences-editor.c: Edit the preference.
+
+	* src/nact/nautilus-actions-config-tool.ui: Define a new checkbox.
+
+	* src/plugin/nautilus-actions.c:
+	Create a root menu only if users has asked for.
+
+	* src/runtime/na-ipivot-consumer.c:
+	* src/runtime/na-ipivot-consumer.h:
+	Define new virtual which handle the monitoring of the preference.
+
+	* src/runtime/na-iprefs.c:
+	* src/runtime/na-iprefs.h:
+	Read/write the preference in GConf.
+
 	* src/nact/nact-main-window.c (setup_dialog_title):
 	Restore function which had disappeared since v 1.12.
 
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index 46ef70a..ac7efc9 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -364,6 +364,17 @@ All schemes used by Nautilus can be used here.</long>
     </schema>
 
     <schema>
+      <key>/schemas/apps/nautilus-actions/preferences/iprefs-create-root-menu</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>Define a 'Nautilus Actions' root menu.</short>
+        <long>If TRUE, then a 'Nautilus Actions' item will be defined in the Nautilus context menu, and will a root menu of all available actions.</long>
+      </locale>
+      <default>true</default>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/nautilus-actions/preferences/iprefs-level-zero</key>
       <owner>nautilus-actions</owner>
       <type>list</type>
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 2febce3..55fa5bc 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -459,6 +459,7 @@ ipivot_consumer_iface_init( NAIPivotConsumerInterface *iface )
 	g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
 
 	iface->on_actions_changed = ipivot_consumer_on_actions_changed;
+	iface->on_create_root_menu_changed = NULL;
 	iface->on_display_about_changed = NULL;
 	iface->on_display_order_changed = ipivot_consumer_on_display_order_changed;
 }
diff --git a/src/nact/nact-preferences-editor.c b/src/nact/nact-preferences-editor.c
index 55ce406..4254238 100644
--- a/src/nact/nact-preferences-editor.c
+++ b/src/nact/nact-preferences-editor.c
@@ -267,6 +267,7 @@ on_base_runtime_init_dialog( NactPreferencesEditor *editor, gpointer user_data )
 	NAPivot *pivot;
 	gint order_mode;
 	gboolean add_about_item;
+	gboolean create_root_menu;
 	gboolean relabel;
 	gint import_mode;
 	GtkWidget *button;
@@ -295,6 +296,10 @@ on_base_runtime_init_dialog( NactPreferencesEditor *editor, gpointer user_data )
 	}
 	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
 
+	create_root_menu = na_iprefs_should_create_root_menu( NA_IPREFS( pivot ));
+	button = base_window_get_widget( BASE_WINDOW( editor ), "CreateRootMenuButton" );
+	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), create_root_menu );
+
 	add_about_item = na_iprefs_should_add_about_item( NA_IPREFS( pivot ));
 	button = base_window_get_widget( BASE_WINDOW( editor ), "AddAboutButton" );
 	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), add_about_item );
@@ -409,6 +414,10 @@ save_preferences( NactPreferencesEditor *editor )
 	}
 	na_iprefs_set_order_mode( NA_IPREFS( pivot ), order_mode );
 
+	button = base_window_get_widget( BASE_WINDOW( editor ), "CreateRootMenuButton" );
+	enabled = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ));
+	na_iprefs_set_create_root_menu( NA_IPREFS( pivot ), enabled );
+
 	button = base_window_get_widget( BASE_WINDOW( editor ), "AddAboutButton" );
 	enabled = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ));
 	na_iprefs_set_add_about_item( NA_IPREFS( pivot ), enabled );
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index 3d94f91..5000d79 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -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="use_preview_label">False</property>
-            <property name="local_only">False</property>
           </object>
           <packing>
             <property name="position">0</property>
@@ -1761,13 +1761,12 @@ Be warned: this mode may be dangerous. You will not be prompted another time.</p
                                 <property name="border_width">6</property>
                                 <property name="homogeneous">True</property>
                                 <child>
-                                  <object class="GtkCheckButton" id="AddAboutButton">
-                                    <property name="label" translatable="yes">Add an '_About Nautilus Actions' item in the Nautilus context menu</property>
+                                  <object class="GtkCheckButton" id="CreateRootMenuButton">
+                                    <property name="label" translatable="yes">_Create a root 'Nautilus Actions' menu</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">False</property>
-                                    <property name="tooltip_text" translatable="yes">When this option is checked, an 'About Nautilus Actions' item is added as the last item of the first level of submenus in Nautilus context menu.
-If there is no root submenu, a 'Nautilus Actions' one is created.</property>
+                                    <property name="tooltip_text" translatable="yes">When this option is checked, a 'Nautilus Actions' item is added to the Nautilus context menu ; this item will be the root menu of all available actions.</property>
                                     <property name="use_underline">True</property>
                                     <property name="draw_indicator">True</property>
                                   </object>
@@ -1775,6 +1774,20 @@ If there is no root submenu, a 'Nautilus Actions' one is created.</property>
                                     <property name="position">0</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <object class="GtkCheckButton" id="AddAboutButton">
+                                    <property name="label" translatable="yes">Add an 'A_bout Nautilus Actions' item in the Nautilus context menu</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="tooltip_text" translatable="yes">When this option is checked, an 'About Nautilus Actions' item is added as the last item of the first level of submenus in Nautilus context menu.</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
                               </object>
                             </child>
                           </object>
@@ -2397,16 +2410,16 @@ Be warned: this mode may be dangerous. You will not be prompted another time.</p
   </object>
   <object class="GtkSizeGroup" id="CommandLabelSizeGroup">
     <widgets>
-      <widget name="CommandExamplePreLabel"/>
-      <widget name="CommandParametersLabel"/>
-      <widget name="CommandPathLabel"/>
       <widget name="ProfileLabelLabel"/>
+      <widget name="CommandPathLabel"/>
+      <widget name="CommandParametersLabel"/>
+      <widget name="CommandExamplePreLabel"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="CommandButtonSizeGroup">
     <widgets>
-      <widget name="CommandLegendButton"/>
       <widget name="CommandPathButton"/>
+      <widget name="CommandLegendButton"/>
     </widgets>
   </object>
 </interface>
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index 4e3e8f7..45697db 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -81,11 +81,13 @@ static void              attach_submenu_to_item( NautilusMenuItem *item, GList *
 
 static void              execute_action( NautilusMenuItem *item, NAObjectProfile *profile );
 
+static GList            *create_root_menu( NautilusActions *plugin, GList *nautilus_menu );
 static GList            *add_about_item( NautilusActions *plugin, GList *nautilus_menu );
 static gchar            *iabout_get_application_name( NAIAbout *instance );
 static void              execute_about( NautilusMenuItem *item, NautilusActions *plugin );
 
 static void              actions_changed_handler( NAIPivotConsumer *instance, gpointer user_data );
+static void              create_root_menu_changed_handler( NAIPivotConsumer *instance, gboolean enabled );
 static void              display_about_changed_handler( NAIPivotConsumer *instance, gboolean enabled );
 static void              display_order_changed_handler( NAIPivotConsumer *instance, gint order_mode );
 
@@ -189,6 +191,7 @@ ipivot_consumer_iface_init( NAIPivotConsumerInterface *iface )
 	g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
 
 	iface->on_actions_changed = actions_changed_handler;
+	iface->on_create_root_menu_changed = create_root_menu_changed_handler;
 	iface->on_display_about_changed = display_about_changed_handler;
 	iface->on_display_order_changed = display_order_changed_handler;
 }
@@ -303,6 +306,7 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 	NautilusActions *self;
 	GList *pivot_tree;
 	gboolean add_about;
+	gboolean root_menu;
 
 	g_debug( "%s: provider=%p, window=%p, files=%p, count=%d",
 			thisfn, ( void * ) provider, ( void * ) window, ( void * ) files, g_list_length( files ));
@@ -326,6 +330,11 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 		nautilus_menus_list = build_nautilus_menus( self, pivot_tree, files );
 		g_debug( "%s: menus has %d level zero items", thisfn, g_list_length( nautilus_menus_list ));
 
+		root_menu = na_iprefs_should_create_root_menu( NA_IPREFS( self->private->pivot ));
+		if( root_menu ){
+			nautilus_menus_list = create_root_menu( self, nautilus_menus_list );
+		}
+
 		add_about = na_iprefs_should_add_about_item( NA_IPREFS( self->private->pivot ));
 		g_debug( "%s: add_about=%s", thisfn, add_about ? "True":"False" );
 		if( add_about ){
@@ -540,9 +549,40 @@ execute_action( NautilusMenuItem *item, NAObjectProfile *profile )
 }
 
 /*
+ * create a root submenu
+ */
+static GList *
+create_root_menu( NautilusActions *plugin, GList *menu )
+{
+	static const gchar *thisfn = "nautilus_actions_create_root_menu";
+	GList *nautilus_menu;
+	NautilusMenuItem *root_item;
+	gchar *icon;
+
+	g_debug( "%s: plugin=%p, menu=%p (%d items)",
+			thisfn, ( void * ) plugin, ( void * ) menu, g_list_length( menu ));
+
+	if( !menu || !g_list_length( menu )){
+		return( NULL );
+	}
+
+	icon = na_iabout_get_icon_name();
+	root_item = nautilus_menu_item_new( "NautilusActionsExtensions",
+				/* i18n: label of an automagic root submenu */
+				_( "Nautilus Actions" ),
+				/* i18n: tooltip of an automagic root submenu */
+				_( "A submenu which embeds the currently available Nautilus Actions extensions" ),
+				icon );
+	attach_submenu_to_item( root_item, menu );
+	nautilus_menu = g_list_append( NULL, root_item );
+	g_free( icon );
+
+	return( nautilus_menu );
+}
+
+/*
  * if there is a root submenu,
  * then add the about item to the end of the first level of this menu
- * else create a root submenu
  */
 static GList *
 add_about_item( NautilusActions *plugin, GList *menu )
@@ -562,8 +602,8 @@ add_about_item( NautilusActions *plugin, GList *menu )
 		return( NULL );
 	}
 
-	icon = na_iabout_get_icon_name();
 	have_root_menu = FALSE;
+	nautilus_menu = menu;
 
 	if( g_list_length( menu ) == 1 ){
 		root_item = NAUTILUS_MENU_ITEM( menu->data );
@@ -575,38 +615,24 @@ add_about_item( NautilusActions *plugin, GList *menu )
 	}
 
 	if( have_root_menu ){
-		nautilus_menu = menu;
-
-	} else {
-		root_item = nautilus_menu_item_new( "NautilusActionsExtensions",
-				/* i18n: label of an automagic root submenu */
-				_( "Nautilus Actions" ),
-				/* i18n: tooltip of an automagic root submenu */
-				_( "A submenu which embeds the currently available Nautilus-Actions extensions" ),
-				icon );
-		attach_submenu_to_item( root_item, menu );
-		nautilus_menu = g_list_append( NULL, root_item );
-		g_object_get( G_OBJECT( root_item ), "menu", &first, NULL );
-	}
+		icon = na_iabout_get_icon_name();
 
-	g_return_val_if_fail( g_list_length( nautilus_menu ) == 1, NULL );
-	g_return_val_if_fail( NAUTILUS_IS_MENU( first ), NULL );
+		about_item = nautilus_menu_item_new( "AboutNautilusActions",
+					_( "About Nautilus Actions" ),
+					_( "Display information about Nautilus Actions" ),
+					icon );
 
-	about_item = nautilus_menu_item_new( "AboutNautilusActions",
-				_( "About Nautilus Actions" ),
-				_( "Display information about Nautilus Actions" ),
-				icon );
+		g_signal_connect_data( about_item,
+					"activate",
+					G_CALLBACK( execute_about ),
+					plugin,
+					NULL,
+					0 );
 
-	g_signal_connect_data( about_item,
-				"activate",
-				G_CALLBACK( execute_about ),
-				plugin,
-				NULL,
-				0 );
+		nautilus_menu_append_item( first, about_item );
 
-	nautilus_menu_append_item( first, about_item );
-
-	g_free( icon );
+		g_free( icon );
+	}
 
 	return( nautilus_menu );
 }
@@ -643,6 +669,21 @@ actions_changed_handler( NAIPivotConsumer *instance, gpointer user_data )
 }
 
 static void
+create_root_menu_changed_handler( NAIPivotConsumer *instance, gboolean enabled )
+{
+	static const gchar *thisfn = "nautilus_actions_create_root_menu_changed_handler";
+	NautilusActions *self;
+
+	g_debug( "%s: instance=%p, enabled=%s", thisfn, ( void * ) instance, enabled ? "True":"False" );
+	g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
+	self = NAUTILUS_ACTIONS( instance );
+
+	if( !self->private->dispose_has_run ){
+		nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( self ));
+	}
+}
+
+static void
 display_about_changed_handler( NAIPivotConsumer *instance, gboolean enabled )
 {
 	static const gchar *thisfn = "nautilus_actions_display_about_changed_handler";
diff --git a/src/runtime/na-ipivot-consumer.c b/src/runtime/na-ipivot-consumer.c
index e87139e..a68aec7 100644
--- a/src/runtime/na-ipivot-consumer.c
+++ b/src/runtime/na-ipivot-consumer.c
@@ -104,6 +104,7 @@ interface_base_init( NAIPivotConsumerInterface *klass )
 		klass->private = g_new0( NAIPivotConsumerInterfacePrivate, 1 );
 
 		klass->on_actions_changed = NULL;
+		klass->on_create_root_menu_changed = NULL;
 		klass->on_display_about_changed = NULL;
 		klass->on_display_order_changed = NULL;
 
@@ -185,15 +186,15 @@ void na_ipivot_consumer_notify_actions_changed( NAIPivotConsumer *instance )
 }
 
 /**
- * na_ipivot_consumer_notify_of_display_order_change:
+ * na_ipivot_consumer_notify_of_create_root_menu_change:
  * @instance: the #NAIPivotConsumer instance to be notified of the end
  * of the modifications.
- * @order_mode: new order mode.
+ * @enabled: whether a root menu should be created.
  *
- * Notifies the consumers that the display order has been changed.
+ * Notifies the consumers that the setting has been changed.
  */
 void
-na_ipivot_consumer_notify_of_display_order_change( NAIPivotConsumer *instance, gint order_mode )
+na_ipivot_consumer_notify_of_create_root_menu_change( NAIPivotConsumer *instance, gboolean enabled )
 {
 	g_return_if_fail( NA_IS_IPIVOT_CONSUMER( instance ));
 
@@ -201,8 +202,8 @@ na_ipivot_consumer_notify_of_display_order_change( NAIPivotConsumer *instance, g
 
 		if( is_notify_allowed( instance )){
 
-			if( NA_IPIVOT_CONSUMER_GET_INTERFACE( instance )->on_display_order_changed ){
-				NA_IPIVOT_CONSUMER_GET_INTERFACE( instance )->on_display_order_changed( instance, order_mode );
+			if( NA_IPIVOT_CONSUMER_GET_INTERFACE( instance )->on_create_root_menu_changed ){
+				NA_IPIVOT_CONSUMER_GET_INTERFACE( instance )->on_create_root_menu_changed( instance, enabled );
 			}
 		}
 	}
@@ -233,6 +234,30 @@ na_ipivot_consumer_notify_of_display_about_change( NAIPivotConsumer *instance, g
 	}
 }
 
+/**
+ * na_ipivot_consumer_notify_of_display_order_change:
+ * @instance: the #NAIPivotConsumer instance to be notified of the end
+ * of the modifications.
+ * @order_mode: new order mode.
+ *
+ * Notifies the consumers that the display order has been changed.
+ */
+void
+na_ipivot_consumer_notify_of_display_order_change( NAIPivotConsumer *instance, gint order_mode )
+{
+	g_return_if_fail( NA_IS_IPIVOT_CONSUMER( instance ));
+
+	if( st_initialized && !st_finalized ){
+
+		if( is_notify_allowed( instance )){
+
+			if( NA_IPIVOT_CONSUMER_GET_INTERFACE( instance )->on_display_order_changed ){
+				NA_IPIVOT_CONSUMER_GET_INTERFACE( instance )->on_display_order_changed( instance, order_mode );
+			}
+		}
+	}
+}
+
 static gboolean
 is_notify_allowed( const NAIPivotConsumer *instance )
 {
diff --git a/src/runtime/na-ipivot-consumer.h b/src/runtime/na-ipivot-consumer.h
index 1fec091..fe1cc42 100644
--- a/src/runtime/na-ipivot-consumer.h
+++ b/src/runtime/na-ipivot-consumer.h
@@ -69,29 +69,40 @@ typedef struct {
 	 * a bunch of modifications. At this time, the embedded list of
 	 * #NAAction has been updated to be up to date.
 	 */
-	void ( *on_actions_changed )      ( NAIPivotConsumer *instance, gpointer user_data );
+	void ( *on_actions_changed )         ( NAIPivotConsumer *instance, gpointer user_data );
+
+	/**
+	 * on_create_root_menu_changed:
+	 * @instance: the #NAIPivotConsumer instance which implements this
+	 * interface.
+	 * @enabled: whether a root menu should be created.
+	 *
+	 * This function is triggered each time the setting of the display
+	 * of an 'About' item in the Nautilus context menu is changed.
+	 */
+	void ( *on_create_root_menu_changed )( NAIPivotConsumer *instance, gboolean enabled );
 
 	/**
 	 * on_display_about_changed:
 	 * @instance: the #NAIPivotConsumer instance which implements this
 	 * interface.
-	 * @order_mode: the new order mode.
+	 * @enabled: whether the 'About' may be displayed.
 	 *
 	 * This function is triggered each time the setting of the display
 	 * of an 'About' item in the Nautilus context menu is changed.
 	 */
-	void ( *on_display_about_changed )( NAIPivotConsumer *instance, gint order_mode );
+	void ( *on_display_about_changed )   ( NAIPivotConsumer *instance, gboolean enabled );
 
 	/**
 	 * on_display_order_changed:
 	 * @instance: the #NAIPivotConsumer instance which implements this
 	 * interface.
-	 * @enabled: whether the 'About' item should be enabled.
+	 * @order_mode: new order mode.
 	 *
 	 * This function is triggered each time the display order preference
 	 * is changed.
 	 */
-	void ( *on_display_order_changed )( NAIPivotConsumer *instance, gboolean enabled );
+	void ( *on_display_order_changed )   ( NAIPivotConsumer *instance, gint order_mode );
 }
 	NAIPivotConsumerInterface;
 
@@ -100,8 +111,9 @@ GType na_ipivot_consumer_get_type( void );
 void  na_ipivot_consumer_delay_notify( NAIPivotConsumer *instance );
 
 void  na_ipivot_consumer_notify_actions_changed( NAIPivotConsumer *instance );
-void  na_ipivot_consumer_notify_of_display_order_change( NAIPivotConsumer *instance, gint order_mode );
+void  na_ipivot_consumer_notify_of_create_root_menu_change( NAIPivotConsumer *instance, gboolean enabled );
 void  na_ipivot_consumer_notify_of_display_about_change( NAIPivotConsumer *instance, gboolean enabled );
+void  na_ipivot_consumer_notify_of_display_order_change( NAIPivotConsumer *instance, gint order_mode );
 
 G_END_DECLS
 
diff --git a/src/runtime/na-iprefs.c b/src/runtime/na-iprefs.c
index dc92d05..fbbe93e 100644
--- a/src/runtime/na-iprefs.c
+++ b/src/runtime/na-iprefs.c
@@ -252,7 +252,7 @@ na_iprefs_set_order_mode( NAIPrefs *instance, gint mode )
  * na_iprefs_should_add_about_item:
  * @instance: this #NAIPrefs interface instance.
  *
- * Returns: #TRUE if an "About Nautilus Actions" item may be added to
+ * Returns: #TRUE if an "About Nautilus Actions" item should be added to
  * the first level of Nautilus context submenus (if any), #FALSE else.
  *
  * Note: this function returns a suitable default value if the key is
@@ -295,6 +295,52 @@ na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled )
 }
 
 /**
+ * na_iprefs_should_create_root_menu:
+ * @instance: this #NAIPrefs interface instance.
+ *
+ * Returns: #TRUE if a root submenu should be created in the Nautilus
+ * context menus, #FALSE else.
+ *
+ * Note: this function returns a suitable default value if the key is
+ * not found in GConf preferences.
+ *
+ * Note: please take care of keeping the default value synchronized with
+ * those defined in schemas.
+ */
+gboolean
+na_iprefs_should_create_root_menu( NAIPrefs *instance )
+{
+	gboolean create = FALSE;
+
+	g_return_val_if_fail( NA_IS_IPREFS( instance ), FALSE );
+
+	if( st_initialized && !st_finalized ){
+
+		create = na_iprefs_read_bool( instance, IPREFS_CREATE_ROOT_MENU, FALSE );
+	}
+
+	return( create );
+}
+
+/**
+ * na_iprefs_set_create_root_menu:
+ * @instance: this #NAIPrefs interface instance.
+ * @enabled: the new value to be written.
+ *
+ * Writes the new value to the GConf preference system.
+ */
+void
+na_iprefs_set_create_root_menu( NAIPrefs *instance, gboolean enabled )
+{
+	g_return_if_fail( NA_IS_IPREFS( instance ));
+
+	if( st_initialized && !st_finalized ){
+
+		na_iprefs_write_bool( instance, IPREFS_CREATE_ROOT_MENU, enabled );
+	}
+}
+
+/**
  * na_iprefs_get_gconf_client:
  * @instance: this #NAIPrefs interface instance.
  *
diff --git a/src/runtime/na-iprefs.h b/src/runtime/na-iprefs.h
index a98127c..e448799 100644
--- a/src/runtime/na-iprefs.h
+++ b/src/runtime/na-iprefs.h
@@ -62,8 +62,9 @@
  *   When checked, an 'About Nautilus Actions' is displayed as the last
  *   item of the root submenu of Nautilus Actions actions.
  *
- *   It the user didn't have defined a root submenu, the plugin
- *   provides one.
+ *   It the user didn't have defined a root submenu, whether in the NACT
+ *   user interface or by choosing the ad-hoc preference, the plugin
+ *   doesn't provides one, and the 'About' item will not be displayed.
  */
 
 #include <glib-object.h>
@@ -99,6 +100,9 @@ void         na_iprefs_set_order_mode( NAIPrefs *instance, gint mode );
 gboolean     na_iprefs_should_add_about_item( NAIPrefs *instance );
 void         na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled );
 
+gboolean     na_iprefs_should_create_root_menu( NAIPrefs *instance );
+void         na_iprefs_set_create_root_menu( NAIPrefs *instance, gboolean enabled );
+
 GConfClient *na_iprefs_get_gconf_client( NAIPrefs *instance );
 
 gboolean     na_iprefs_read_bool( NAIPrefs *instance, const gchar *key, gboolean default_value );
@@ -118,6 +122,7 @@ void         na_iprefs_write_string_list( NAIPrefs *instance, const gchar *key,
  */
 #define IPREFS_LEVEL_ZERO_ITEMS				"iprefs-level-zero"
 #define IPREFS_DISPLAY_ALPHABETICAL_ORDER	"iprefs-alphabetical-order"
+#define IPREFS_CREATE_ROOT_MENU				"iprefs-create-root-menu"
 #define IPREFS_ADD_ABOUT_ITEM				"iprefs-add-about-item"
 
 /* alphabetical order values
diff --git a/src/runtime/na-pivot.c b/src/runtime/na-pivot.c
index e03b282..fdffd59 100644
--- a/src/runtime/na-pivot.c
+++ b/src/runtime/na-pivot.c
@@ -117,6 +117,7 @@ static void      monitor_runtime_preferences( NAPivot *pivot );
 
 static void      on_preferences_change( GConfClient *client, guint cnxn_id, GConfEntry *entry, NAPivot *pivot );
 static void      display_order_changed( NAPivot *pivot );
+static void      create_root_menu_changed( NAPivot *pivot );
 static void      display_about_changed( NAPivot *pivot );
 
 GType
@@ -945,6 +946,10 @@ on_preferences_change( GConfClient *client, guint cnxn_id, GConfEntry *entry, NA
 	key_entry = na_utils_path_extract_last_dir( key );
 	/*g_debug( "%s: key=%s", thisfn, key_entry );*/
 
+	if( !g_ascii_strcasecmp( key_entry, IPREFS_CREATE_ROOT_MENU )){
+		create_root_menu_changed( pivot );
+	}
+
 	if( !g_ascii_strcasecmp( key_entry, IPREFS_ADD_ABOUT_ITEM )){
 		display_about_changed( pivot );
 	}
@@ -977,6 +982,26 @@ display_order_changed( NAPivot *pivot )
 }
 
 static void
+create_root_menu_changed( NAPivot *pivot )
+{
+	static const gchar *thisfn = "na_pivot_create_root_menu_changed";
+	GList *ic;
+	gboolean enabled;
+
+	g_debug( "%s: pivot=%p", thisfn, ( void * ) pivot );
+	g_assert( NA_IS_PIVOT( pivot ));
+
+	if( !pivot->private->dispose_has_run ){
+
+		enabled = na_iprefs_should_create_root_menu( NA_IPREFS( pivot ));
+
+		for( ic = pivot->private->consumers ; ic ; ic = ic->next ){
+			na_ipivot_consumer_notify_of_create_root_menu_change( NA_IPIVOT_CONSUMER( ic->data ), enabled );
+		}
+	}
+}
+
+static void
 display_about_changed( NAPivot *pivot )
 {
 	static const gchar *thisfn = "na_pivot_display_about_changed";



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