[nautilus-actions: 25/45] Reload actions



commit d6c1a90393214b5a6599ce036eb986b9bcd680f1
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Jul 27 20:35:16 2009 +0200

    Reload actions

 src/common/na-gconf.c               |   40 ++++++++++++----------------------
 src/common/na-iio-provider.c        |    7 +----
 src/nact/nact-iaction-tab.c         |   12 ++++++++++
 src/nact/nact-iactions-list.c       |   22 +++++++++++++++++++
 src/nact/nact-iactions-list.h       |    1 +
 src/nact/nact-icommand-tab.c        |   12 ++++++++++
 src/nact/nact-imenubar.c            |   12 +++++++--
 src/nact/nact-main-window.c         |   39 +++++++++++++++++++++++++--------
 src/nact/nautilus-actions-config.ui |   16 ++++++-------
 src/plugin/nautilus-actions.c       |   26 +++++++++++++---------
 10 files changed, 123 insertions(+), 64 deletions(-)
---
diff --git a/src/common/na-gconf.c b/src/common/na-gconf.c
index 1ba5a60..44948b3 100644
--- a/src/common/na-gconf.c
+++ b/src/common/na-gconf.c
@@ -114,9 +114,9 @@ static gboolean       iio_provider_is_writable( const NAIIOProvider *provider, c
 static guint          iio_provider_write_action( const NAIIOProvider *provider, NAAction *action, gchar **message );
 static guint          iio_provider_delete_action( const NAIIOProvider *provider, const NAAction *action, gchar **message );
 
-static gboolean       read_action( NAGConf *gconf, NAAction *action, const gchar *path );
-static gboolean       read_profile( NAGConf *gconf, NAActionProfile *profile, const gchar *path );
-static gboolean       fill_action_core_properties( NAGConf *gconf, NAAction *action, GSList *notifies );
+static void           read_action( NAGConf *gconf, NAAction *action, const gchar *path );
+static void           read_profile( NAGConf *gconf, NAActionProfile *profile, const gchar *path );
+static void           fill_action_core_properties( NAGConf *gconf, NAAction *action, GSList *notifies );
 static void           fill_action_v1_properties( NAGConf *gconf, NAAction *action, GSList *notifies );
 static void           fill_profile_properties( NAGConf *gconf, NAActionProfile *profile, GSList *notifies );
 
@@ -401,12 +401,9 @@ iio_provider_read_actions( const NAIIOProvider *provider )
 
 		NAAction *action = na_action_new();
 
-		if( read_action( self, action, path )){
-			items = g_slist_prepend( items, action );
+		read_action( self, action, path );
 
-		} else {
-			g_object_unref( action );
-		}
+		items = g_slist_prepend( items, action );
 
 		/*gchar *uuid = path_to_key( path );
 
@@ -558,10 +555,10 @@ load_action( NAGConf *gconf, NAAction *action, const gchar *path )
 	g_free( path );
 	return( ok );
 }*/
-static gboolean
+static void
 read_action( NAGConf *gconf, NAAction *action, const gchar *path )
 {
-	static const gchar *thisfn = "nacf_gconf_read_action";
+	static const gchar *thisfn = "na_gconf_read_action";
 	g_debug( "%s: gconf=%p, action=%p, path=%s", thisfn, gconf, action, path );
 
 	g_assert( NA_IS_GCONF( gconf ));
@@ -575,7 +572,7 @@ read_action( NAGConf *gconf, NAAction *action, const gchar *path )
 	GSList *notifies = entries_to_notifies( entries );
 	free_list_entries( entries );
 
-	gboolean ok = fill_action_core_properties( gconf, action, notifies  );
+	fill_action_core_properties( gconf, action, notifies  );
 
 	GSList *ip;
 	GSList *list_profiles = get_path_subdirs( gconf, path );
@@ -585,12 +582,9 @@ read_action( NAGConf *gconf, NAAction *action, const gchar *path )
 			const gchar *profile_path = ( const gchar * ) ip->data;
 			NAActionProfile *profile = na_action_profile_new();
 
-			if( read_profile( gconf, profile, profile_path )){
-				na_action_attach_profile( action, profile );
+			read_profile( gconf, profile, profile_path );
 
-			} else {
-				g_object_unref( profile );
-			}
+			na_action_attach_profile( action, profile );
 		}
 
 	} else {
@@ -600,14 +594,12 @@ read_action( NAGConf *gconf, NAAction *action, const gchar *path )
 	free_list_notifies( notifies );
 
 	na_action_set_readonly( action, !key_is_writable( gconf, path ));
-
-	return( ok );
 }
 
-static gboolean
+static void
 read_profile( NAGConf *gconf, NAActionProfile *profile, const gchar *path )
 {
-	static const gchar *thisfn = "nacf_gconf_read_profile";
+	static const gchar *thisfn = "na_gconf_read_profile";
 	g_debug( "%s: gconf=%p, profile=%p, path=%s", thisfn, gconf, profile, path );
 
 	g_assert( NA_IS_GCONF( gconf ));
@@ -624,15 +616,13 @@ read_profile( NAGConf *gconf, NAActionProfile *profile, const gchar *path )
 	fill_profile_properties( gconf, profile, notifies  );
 
 	free_list_notifies( notifies );
-
-	return( TRUE );
 }
 
 /*
  * set the item properties into the action, dealing with successive
  * versions
  */
-static gboolean
+static void
 fill_action_core_properties( NAGConf *gconf, NAAction *action, GSList *notifies )
 {
 	static const gchar *thisfn = "na_gconf_fill_action_properties";
@@ -642,7 +632,7 @@ fill_action_core_properties( NAGConf *gconf, NAAction *action, GSList *notifies
 		gchar *uuid = na_action_get_uuid( action );
 		g_warning( "%s: no label found for action '%s'", thisfn, uuid );
 		g_free( uuid );
-		return( FALSE );
+		label = g_strdup( "" );
 	}
 	na_action_set_label( action, label );
 	g_free( label );
@@ -664,8 +654,6 @@ fill_action_core_properties( NAGConf *gconf, NAAction *action, GSList *notifies
 		na_action_set_icon( action, icon );
 		g_free( icon );
 	}
-
-	return( TRUE );
 }
 
 /*
diff --git a/src/common/na-iio-provider.c b/src/common/na-iio-provider.c
index 6cf10f9..05d617d 100644
--- a/src/common/na-iio-provider.c
+++ b/src/common/na-iio-provider.c
@@ -297,7 +297,8 @@ write_action( const NAIIOProvider *provider, NAAction *action, gchar **message )
 		return( NA_IIO_PROVIDER_NOT_WRITABLE );
 	}
 
-	if( !NA_IIO_PROVIDER_GET_INTERFACE( provider )->delete_action ){
+	if( !NA_IIO_PROVIDER_GET_INTERFACE( provider )->delete_action ||
+		!NA_IIO_PROVIDER_GET_INTERFACE( provider )->write_action ){
 		return( NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE );
 	}
 
@@ -306,9 +307,5 @@ write_action( const NAIIOProvider *provider, NAAction *action, gchar **message )
 		return( ret );
 	}
 
-	if( !NA_IIO_PROVIDER_GET_INTERFACE( provider )->write_action ){
-		return( NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE );
-	}
-
 	return( NA_IIO_PROVIDER_GET_INTERFACE( provider )->write_action( provider, action, message ));
 }
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index 29b83b7..c4bebf4 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -66,6 +66,7 @@ static void          v_field_modified( NactWindow *window );
 
 static void          on_label_changed( GtkEntry *entry, gpointer user_data );
 static void          check_for_label( NactWindow *window, GtkEntry *entry, const gchar *label );
+static void          set_label_label( NactWindow *window, const gchar *color );
 static void          on_tooltip_changed( GtkEntry *entry, gpointer user_data );
 static void          on_icon_changed( GtkEntry *entry, gpointer user_data );
 static void          on_icon_browse( GtkButton *button, gpointer user_data );
@@ -334,16 +335,27 @@ static void
 check_for_label( NactWindow *window, GtkEntry *entry, const gchar *label )
 {
 	hide_status( window );
+	set_label_label( window, "black" );
 
 	NAAction *edited = v_get_edited_action( window );
 
 	if( edited && g_utf8_strlen( label, -1 ) == 0 ){
 		/* i18n: status bar message when the action label is empty */
 		display_status( window, _( "Caution: a label is mandatory for the action." ));
+		set_label_label( window, "red" );
 	}
 }
 
 static void
+set_label_label( NactWindow *window, const gchar *color )
+{
+	GtkWidget *label = base_window_get_widget( BASE_WINDOW( window ), "ActionLabelLabel" );
+	/* i18n: label in front of the GtkEntry where user enters the action label */
+	gchar *text = g_markup_printf_escaped( "<span color=\"%s\">%s</span>", color, _( "Label :" ));
+	gtk_label_set_markup( GTK_LABEL( label ), text );
+}
+
+static void
 on_tooltip_changed( GtkEntry *entry, gpointer user_data )
 {
 	g_assert( NACT_IS_WINDOW( user_data ));
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 7b268de..ffde507 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -424,6 +424,28 @@ nact_iactions_list_set_selection( NactWindow *window, GType type, const gchar *u
 	}
 }
 
+void
+nact_iactions_list_select_first( NactWindow *window )
+{
+	static const gchar *thisfn = "nact_iactions_list_select_first";
+	g_debug( "%s: window=%p", thisfn, window );
+
+	GtkWidget *list = get_actions_list_widget( window );
+	GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( list ));
+
+	GtkTreeIter iter;
+	GtkTreeModel *model = gtk_tree_view_get_model( GTK_TREE_VIEW( list ));
+	gboolean iterok = gtk_tree_model_get_iter_first( model, &iter );
+	if( !iterok ){
+		g_debug( "%s: empty actions list: unselect all", thisfn );
+		gtk_tree_selection_unselect_all( selection );
+		v_on_selection_changed( selection, window );
+		return;
+	}
+
+	gtk_tree_selection_select_iter( selection, &iter );
+}
+
 /**
  * Reset the focus on the ActionsList listbox.
  */
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index 68ee951..f591a0f 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -81,6 +81,7 @@ void      nact_iactions_list_fill( NactWindow *window, gboolean keep_expanded );
 NAObject *nact_iactions_list_get_selected_object( NactWindow *window );
 GSList  * nact_iactions_list_get_selected_actions( NactWindow *window );
 void      nact_iactions_list_set_selection( NactWindow *window, GType type, const gchar *uuid, const gchar *label );
+void      nact_iactions_list_select_first( NactWindow *window );
 /*void      nact_iactions_list_set_focus( NactWindow *window );*/
 /*void      nact_iactions_list_set_modified( NactWindow *window, gboolean is_modified, gboolean can_save );*/
 gboolean  nact_iactions_list_is_expanded( NactWindow *window, const NAAction *action );
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index fde1b58..2f83736 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -72,6 +72,7 @@ static GSList          *v_get_schemes( NactWindow *window );
 
 static void             on_label_changed( GtkEntry *entry, gpointer user_data );
 static void             check_for_label( NactWindow *window, GtkEntry *entry, const gchar *label );
+static void             set_label_label( NactWindow *window, const gchar *color );
 static GtkWidget       *get_label_entry( NactWindow *window );
 static void             on_path_changed( GtkEntry *entry, gpointer user_data );
 static void             on_path_browse( GtkButton *button, gpointer user_data );
@@ -351,15 +352,26 @@ static void
 check_for_label( NactWindow *window, GtkEntry *entry, const gchar *label )
 {
 	hide_status( window );
+	set_label_label( window, "black" );
 
 	NAActionProfile *edited = v_get_edited_profile( window );
 
 	if( edited && g_utf8_strlen( label, -1 ) == 0 ){
 		/* i18n: status bar message when the profile label is empty */
 		display_status( window, _( "Caution: a label is mandatory for the profile." ));
+		set_label_label( window, "red" );
 	}
 }
 
+static void
+set_label_label( NactWindow *window, const gchar *color )
+{
+	GtkWidget *label = base_window_get_widget( BASE_WINDOW( window ), "ProfileLabelLabel" );
+	/* i18n: label in front of the GtkEntry where user enters the profile label */
+	gchar *text = g_markup_printf_escaped( "<span color=\"%s\">%s</span>", color, _( "Label :" ));
+	gtk_label_set_markup( GTK_LABEL( label ), text );
+}
+
 static GtkWidget *
 get_label_entry( NactWindow *window )
 {
diff --git a/src/nact/nact-imenubar.c b/src/nact/nact-imenubar.c
index 605b0d5..1f4a11a 100644
--- a/src/nact/nact-imenubar.c
+++ b/src/nact/nact-imenubar.c
@@ -435,6 +435,10 @@ on_new_profile_activated( GtkMenuItem *item, NactWindow *window )
 	NAActionProfile *new_profile = na_action_profile_new();
 	g_debug( "nact_imenubar_on_new_profile_activated: action=%p, profile=%p", action, new_profile );
 
+	gchar *name = na_action_get_new_profile_name( action );
+	na_action_profile_set_name( new_profile, name );
+	g_free( name );
+
 	add_profile( window, action, new_profile );
 }
 
@@ -476,7 +480,7 @@ on_save_activated( GtkMenuItem *item, NactWindow *window )
 		}
 	}
 
-	/* save the modified actions
+	/* save the valid modified actions
 	 * - remove the origin of pivot if any
 	 * - add a duplicate of this action to pivot
 	 * - set the duplicate as the origin of this action
@@ -484,7 +488,9 @@ on_save_activated( GtkMenuItem *item, NactWindow *window )
 	 */
 	for( ia = actions ; ia ; ia = ia->next ){
 		NAAction *current = NA_ACTION( ia->data );
-		if( na_object_get_modified_status( NA_OBJECT( current ))){
+		if( na_object_get_modified_status( NA_OBJECT( current )) &&
+			na_object_get_valid_status( NA_OBJECT( current ))){
+
 			if( nact_window_save_action( window, current )){
 
 				NAAction *origin = NA_ACTION( na_object_get_origin( NA_OBJECT( current )));
@@ -536,7 +542,7 @@ static void
 on_save_selected( GtkMenuItem *item, NactWindow *window )
 {
 	/* i18n: tooltip displayed in the status bar when selecting 'Save' item */
-	display_status( window, _( "Record all the modified actions." ));
+	display_status( window, _( "Record all the modified actions. Invalid actions will be silently ignored." ));
 }
 
 static void
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 3797505..3c31f16 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -505,14 +505,6 @@ on_initial_load_toplevel( BaseWindow *window )
 	g_assert( NACT_IS_MAIN_WINDOW( window ));
 	NactMainWindow *wnd = NACT_MAIN_WINDOW( window );
 
-	NactApplication *application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( wnd )));
-	NAPivot *pivot = nact_application_get_pivot( application );
-	na_pivot_set_automatic_reload( pivot, FALSE );
-	wnd->private->actions = na_pivot_get_duplicate_actions( pivot );
-	wnd->private->initial_count = g_slist_length( wnd->private->actions );
-
-	g_get_current_time( &wnd->private->last_saved );
-
 	wnd->private->status_bar = GTK_STATUSBAR( base_window_get_widget( window, "StatusBar" ));
 	wnd->private->status_context = gtk_statusbar_get_context_id( wnd->private->status_bar, "nact-main-window" );
 
@@ -553,6 +545,25 @@ on_runtime_init_toplevel( BaseWindow *window )
 		BASE_WINDOW_CLASS( st_parent_class )->runtime_init_toplevel( window );
 	}
 
+	g_assert( NACT_IS_MAIN_WINDOW( window ));
+	NactMainWindow *wnd = NACT_MAIN_WINDOW( window );
+
+	NactApplication *application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( wnd )));
+	NAPivot *pivot = nact_application_get_pivot( application );
+	na_pivot_set_automatic_reload( pivot, FALSE );
+	wnd->private->actions = na_pivot_get_duplicate_actions( pivot );
+	wnd->private->initial_count = g_slist_length( wnd->private->actions );
+
+	/* initialize the current edition status as a loaded action may be
+	 * invalid (without having been modified)
+	 */
+	GSList *ia;
+	for( ia = wnd->private->actions ; ia ; ia = ia->next ){
+		na_object_check_edited_status( NA_OBJECT( ia->data ));
+	}
+
+	g_get_current_time( &wnd->private->last_saved );
+
 	g_debug( "%s: window=%p", thisfn, window );
 	g_assert( NACT_IS_MAIN_WINDOW( window ));
 	/*NactMainWindow *wnd = NACT_MAIN_WINDOW( window );*/
@@ -574,7 +585,7 @@ on_runtime_init_toplevel( BaseWindow *window )
 
 	/* forces a no-selection when the list is initially empty
 	 */
-	if( !g_slist_length( NACT_MAIN_WINDOW( window )->private->actions )){
+	if( !wnd->private->initial_count ){
 		set_current_action( NACT_MAIN_WINDOW( window ));
 	}
 }
@@ -1068,6 +1079,14 @@ reload_actions( NactWindow *window )
 	na_pivot_reload_actions( pivot );
 	self->private->actions = na_pivot_get_duplicate_actions( pivot );
 	self->private->initial_count = g_slist_length( self->private->actions );
+
+	nact_iactions_list_fill( window, FALSE );
+
+	if( self->private->initial_count ){
+		nact_iactions_list_select_first( window );
+	}
+	/*self->private->edited_action = NULL;
+	set_current_action( NACT_MAIN_WINDOW( window ));*/
 }
 
 static GSList *
@@ -1095,7 +1114,7 @@ free_actions( GSList *actions )
  * during one seconde after each save
  *
  * note that last_saved is initialized in initial_load_toplevel()
- * there is so a race condition if NAPivot detects a modification
+ * so we will not be advertised if NAPivot detects a modification
  * in the seconde after this initialization - just ignore this case
  */
 static void
diff --git a/src/nact/nautilus-actions-config.ui b/src/nact/nautilus-actions-config.ui
index 1823955..ce9a83f 100644
--- a/src/nact/nautilus-actions-config.ui
+++ b/src/nact/nautilus-actions-config.ui
@@ -96,7 +96,6 @@
                                   <object class="GtkLabel" id="ActionLabelLabel">
                                     <property name="visible">True</property>
                                     <property name="xalign">1</property>
-                                    <property name="label" translatable="yes">Label :</property>
                                   </object>
                                   <packing>
                                     <property name="y_options"></property>
@@ -273,7 +272,6 @@
                                       <object class="GtkLabel" id="ProfileLabelLabel">
                                         <property name="visible">True</property>
                                         <property name="xalign">1</property>
-                                        <property name="label" translatable="yes">Label :</property>
                                       </object>
                                       <packing>
                                         <property name="expand">False</property>
@@ -887,9 +885,9 @@
         <property name="visible">True</property>
         <property name="orientation">vertical</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>
+        <property name="preview_widget_active">False</property>
       </object>
     </child>
     <child>
@@ -972,10 +970,10 @@ to extend a selection.</property>
           <object class="GtkFileChooserWidget" id="ExportFolderChooser">
             <property name="visible">True</property>
             <property name="orientation">vertical</property>
-            <property name="preview_widget_active">False</property>
-            <property name="local_only">False</property>
             <property name="action">select-folder</property>
+            <property name="local_only">False</property>
             <property name="use_preview_label">False</property>
+            <property name="preview_widget_active">False</property>
           </object>
           <packing>
             <property name="position">0</property>
@@ -1402,16 +1400,16 @@ file(s)/folder(s)</property>
   </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 18c6b54..b9a5d71 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -253,9 +253,7 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 	GSList *ia, *ip;
 	NautilusMenuItem *item;
 	GSList *actions = NULL;
-#ifdef NACT_MAINTAINER_MODE
-	gchar *debug_label;
-#endif
+	gchar *label, *uuid;
 
 	g_return_val_if_fail( NAUTILUS_IS_ACTIONS( provider ), NULL );
 	NautilusActions *self = NAUTILUS_ACTIONS( provider );
@@ -272,11 +270,17 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 
 			NAAction *action = NA_ACTION( ia->data );
 
-#ifdef NACT_MAINTAINER_MODE
-			debug_label = na_action_get_label( action );
-			g_debug( "%s: examining '%s' action", thisfn, debug_label );
-			g_free( debug_label );
-#endif
+			label = na_action_get_label( action );
+
+			if( !label || !g_utf8_strlen( label, -1 )){
+				uuid = na_action_get_uuid( action );
+				g_warning( "%s: label null or empty for uuid=%s", thisfn, uuid );
+				g_free( uuid );
+				continue;
+			}
+
+			g_debug( "%s: examining '%s' action", thisfn, label );
+			g_free( label );
 
 			profiles = na_action_get_profiles( action );
 
@@ -285,9 +289,9 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 				NAActionProfile *profile = NA_ACTION_PROFILE( ip->data );
 
 #ifdef NACT_MAINTAINER_MODE
-				debug_label = na_action_profile_get_label( profile );
-				g_debug( "%s: examining '%s' profile", thisfn, debug_label );
-				g_free( debug_label );
+				label = na_action_profile_get_label( profile );
+				g_debug( "%s: examining '%s' profile", thisfn, label );
+				g_free( label );
 #endif
 
 				if( na_action_profile_is_candidate( profile, files )){



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