[nautilus-actions] Reload actions



commit 3952bb33e8d1a3ffe7c65fa3b0f3af9ff20b604a
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Sep 24 20:35:24 2009 +0200

    Reload actions

 ChangeLog                       |    5 ++
 src/nact/base-dialog.c          |    4 +-
 src/nact/base-iprefs.c          |   30 ++++----
 src/nact/base-window.c          |    2 +
 src/nact/nact-iaction-tab.c     |    2 +-
 src/nact/nact-iadvanced-tab.c   |    5 +-
 src/nact/nact-icommand-tab.c    |    2 +-
 src/nact/nact-iconditions-tab.c |    3 +-
 src/nact/nact-main-menubar.c    |    3 +-
 src/nact/nact-main-window.c     |  135 ++++++++++++++++++++++++++++++++------
 src/nact/nact-main-window.h     |    1 +
 src/nact/nact-window.c          |    2 +-
 src/plugin/nautilus-actions.c   |    4 +-
 13 files changed, 150 insertions(+), 48 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5bb620a..c63c0a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-09-24 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/nact-main-menubar.c:
+	* src/nact/nact-main-window.c:
+	* src/nact/nact-main-window.h (nact_main_window_reload):
+	New function.
+
 	* data/nautilus-actions.schemas.in: Rename preferences keys.
 	Add iprefs-level-zero key.
 
diff --git a/src/nact/base-dialog.c b/src/nact/base-dialog.c
index f8fc60e..99875a8 100644
--- a/src/nact/base-dialog.c
+++ b/src/nact/base-dialog.c
@@ -130,7 +130,7 @@ instance_dispose( GObject *window )
 	BaseDialog *self;
 
 	g_debug( "%s: window=%p", thisfn, ( void * ) window );
-	g_return_if_fail( BASE_IS_DIALOG( instance ));
+	g_return_if_fail( BASE_IS_DIALOG( window ));
 	self = BASE_DIALOG( window );
 
 	if( !self->private->dispose_has_run ){
@@ -151,7 +151,7 @@ instance_finalize( GObject *window )
 	BaseDialog *self;
 
 	g_debug( "%s: window=%p", thisfn, ( void * ) window );
-	g_return_if_fail( BASE_IS_DIALOG( instance ));
+	g_return_if_fail( BASE_IS_DIALOG( window ));
 	self = BASE_DIALOG( window );
 
 	g_free( self->private );
diff --git a/src/nact/base-iprefs.c b/src/nact/base-iprefs.c
index cfeeb72..85bddaa 100644
--- a/src/nact/base-iprefs.c
+++ b/src/nact/base-iprefs.c
@@ -165,7 +165,7 @@ base_iprefs_migrate_key( BaseWindow *window, const gchar *old_key, const gchar *
 
 	g_debug( "%s: window=%p, old_key=%s, new_key=%s", thisfn, ( void * ) window, old_key, new_key );
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 
@@ -196,7 +196,7 @@ base_iprefs_position_window( BaseWindow *window )
 	gchar *key = v_iprefs_get_window_id( window );
 
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 		if( key ){
@@ -224,7 +224,7 @@ base_iprefs_position_named_window( BaseWindow *window, GtkWindow *toplevel, cons
 	gint x=0, y=0, width=0, height=0;
 
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 
@@ -254,7 +254,7 @@ base_iprefs_save_window_position( BaseWindow *window )
 	gchar *key;
 
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 
@@ -283,7 +283,7 @@ base_iprefs_save_named_window_position( BaseWindow *window, GtkWindow *toplevel,
 	GSList *list;
 
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 
@@ -311,8 +311,8 @@ base_iprefs_get_bool( BaseWindow *window, const gchar *name )
 {
 	gboolean ret = FALSE;
 
-	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_val_if_fail( BASE_IS_WINDOW( window ), FALSE );
+	g_return_val_if_fail( BASE_IS_IPREFS( window ), FALSE );
 
 	if( st_initialized && !st_finalized ){
 		ret = read_bool( window, name );
@@ -333,7 +333,7 @@ void
 base_iprefs_set_bool( BaseWindow *window, const gchar *name, gboolean value )
 {
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 		write_bool( window, name, value );
@@ -352,8 +352,8 @@ base_iprefs_get_int( BaseWindow *window, const gchar *name )
 {
 	gint ret = 0;
 
-	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_val_if_fail( BASE_IS_WINDOW( window ), 0 );
+	g_return_val_if_fail( BASE_IS_IPREFS( window ), 0 );
 
 	if( st_initialized && !st_finalized ){
 		ret = read_int( window, name );
@@ -374,7 +374,7 @@ void
 base_iprefs_set_int( BaseWindow *window, const gchar *name, gint value )
 {
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 		write_int( window, name, value );
@@ -394,8 +394,8 @@ base_iprefs_get_string( BaseWindow *window, const gchar *name )
 {
 	gchar *string = NULL;
 
-	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
+	g_return_val_if_fail( BASE_IS_IPREFS( window ), NULL );
 
 	if( st_initialized && !st_finalized ){
 		string = read_str( window, name );
@@ -416,7 +416,7 @@ void
 base_iprefs_set_string( BaseWindow *window, const gchar *name, const gchar *string )
 {
 	g_return_if_fail( BASE_IS_WINDOW( window ));
-	g_return_if_fail( NACT_IS_IPREFS( window ));
+	g_return_if_fail( BASE_IS_IPREFS( window ));
 
 	if( st_initialized && !st_finalized ){
 		write_str( window, name, string );
@@ -426,7 +426,7 @@ base_iprefs_set_string( BaseWindow *window, const gchar *name, const gchar *stri
 static gchar *
 v_iprefs_get_window_id( BaseWindow *window )
 {
-	g_assert( BASE_IS_IPREFS( window ));
+	g_return_val_if_fail( BASE_IS_IPREFS( window ), NULL );
 
 	if( BASE_IPREFS_GET_INTERFACE( window )->iprefs_get_window_id ){
 		return( BASE_IPREFS_GET_INTERFACE( window )->iprefs_get_window_id( window ));
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index b917dd1..836e686 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -837,6 +837,8 @@ v_dialog_response( GtkDialog *dialog, gint code, BaseWindow *window )
 			stop = window_do_dialog_response( dialog, code, window );
 		}
 	}
+
+	return( stop );
 }
 
 static BaseApplication *
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index 621d078..c88b35d 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -263,7 +263,7 @@ nact_iaction_tab_has_label( NactIActionTab *instance )
 	const gchar *label;
 	gboolean has_label = FALSE;
 
-	g_return_if_fail( NACT_IS_IACTION_TAB( instance ));
+	g_return_val_if_fail( NACT_IS_IACTION_TAB( instance ), FALSE );
 
 	if( st_initialized && !st_finalized ){
 
diff --git a/src/nact/nact-iadvanced-tab.c b/src/nact/nact-iadvanced-tab.c
index 1d92aa1..d095d28 100644
--- a/src/nact/nact-iadvanced-tab.c
+++ b/src/nact/nact-iadvanced-tab.c
@@ -361,6 +361,7 @@ nact_iadvanced_tab_dispose( NactIAdvancedTab *instance )
 
 	if( st_initialized && !st_finalized ){
 	}
+}
 
 /**
  * Returns selected schemes as a list of strings.
@@ -370,9 +371,9 @@ GSList *
 nact_iadvanced_tab_get_schemes( NactIAdvancedTab *instance )
 {
 	GSList *list = NULL;
-	GtkTreeModel* scheme_model;
+	GtkTreeModel *scheme_model;
 
-	g_return_if_fail( NACT_IS_IADVANCED_TAB( instance ));
+	g_return_val_if_fail( NACT_IS_IADVANCED_TAB( instance ), NULL );
 
 	if( st_initialized && !st_finalized ){
 		scheme_model = get_schemes_tree_model( instance );
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index a8f487e..719cb06 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -288,7 +288,7 @@ nact_icommand_tab_has_label( NactICommandTab *instance )
 	GtkWidget *label_entry;
 	const gchar *label;
 
-	g_return_if_fail( NACT_IS_ICOMMAND_TAB( instance ));
+	g_return_val_if_fail( NACT_IS_ICOMMAND_TAB( instance ), FALSE );
 
 	if( st_initialized && !st_finalized ){
 
diff --git a/src/nact/nact-iconditions-tab.c b/src/nact/nact-iconditions-tab.c
index b0d23c3..9686f18 100644
--- a/src/nact/nact-iconditions-tab.c
+++ b/src/nact/nact-iconditions-tab.c
@@ -276,7 +276,7 @@ nact_iconditions_tab_get_multiple( NactIConditionsTab *instance )
 	gboolean multiple = FALSE;
 	GtkButton *button;
 
-	g_return_if_fail( NACT_IS_ICONDITIONS_TAB( instance ));
+	g_return_val_if_fail( NACT_IS_ICONDITIONS_TAB( instance ), FALSE );
 
 	if( st_initialized && !st_finalized ){
 		button = get_multiple_button( instance );
@@ -346,6 +346,7 @@ on_tab_updatable_selection_changed( NactIConditionsTab *instance, gint count_sel
 		multiple = profile ? na_object_profile_get_multiple( profile ) : FALSE;
 		gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( multiple_button ), multiple );
 		gtk_widget_set_sensitive( GTK_WIDGET( multiple_button ), profile != NULL );
+	}
 }
 
 static GtkWidget *
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 82923d3..2af523e 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -148,7 +148,7 @@ static const GtkActionEntry entries[] = {
 				/* i18n: tooltip displayed in the status bar when selecting the Delete item */
 				N_( "Delete the selected item(s)" ),
 				G_CALLBACK( on_delete_activated ) },
-		{ "ReloadActionsItem", NULL, N_( "_Reload the list of actions" ), "<Ctrl>R",
+		{ "ReloadActionsItem", GTK_STOCK_REFRESH, N_( "_Reload the list of actions" ), "F5",
 				/* i18n: tooltip displayed in the status bar when selecting the 'Reload' item */
 				N_( "Cancel your current modifications and reload the list of actions" ),
 				G_CALLBACK( on_reload_activated ) },
@@ -602,6 +602,7 @@ on_delete_activated( GtkAction *gtk_action, NactMainWindow *window )
 static void
 on_reload_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
+	nact_main_window_reload( window );
 }
 
 static void
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 1e8c658..a9ffb3b 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -145,8 +145,11 @@ static void     set_current_profile( NactMainWindow *window, gboolean set_action
 
 static void     on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data );
 
+static gboolean confirm_for_giveup_from_menu( NactMainWindow *window );
+static gboolean confirm_for_giveup_from_pivot( NactMainWindow *window );
 static void     ipivot_consumer_on_actions_changed( NAIPivotConsumer *instance, gpointer user_data );
 static void     ipivot_consumer_on_display_order_changed( NAIPivotConsumer *instance, gpointer user_data );
+static void     reload( NactMainWindow *window );
 
 GType
 nact_main_window_get_type( void )
@@ -650,6 +653,31 @@ nact_main_window_move_to_deleted( NactMainWindow *window, GList *items )
 }
 
 /**
+ * nact_main_window_reload:
+ * @window: this #NactMainWindow instance.
+ *
+ * Refresh the list of items.
+ * If there is some non-yet saved modifications, a confirmation is
+ * required before giving up with them.
+ */
+void
+nact_main_window_reload( NactMainWindow *window )
+{
+	gboolean reload_ok;
+
+	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+	if( !window->private->dispose_has_run ){
+
+		reload_ok = confirm_for_giveup_from_menu( window );
+
+		if( reload_ok ){
+			reload( window );
+		}
+	}
+}
+
+/**
  * nact_main_window_remove_deleted:
  * @window: this #NactMainWindow instance.
  *
@@ -965,6 +993,68 @@ on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data )
 }
 
 /*
+ * requires a confirmation from the user when is has asked for reloading
+ * the actions via the Edit menu
+ */
+static gboolean
+confirm_for_giveup_from_menu( NactMainWindow *window )
+{
+	gboolean reload_ok = TRUE;
+	gchar *first, *second;
+
+	if( nact_main_window_has_modified_items( window )){
+
+		first = g_strdup(
+					_( "Reloading a fresh list of actions requires "
+						"that you give up with your current modifications." ));
+
+		second = g_strdup( _( "Do you really want to do this ?" ));
+
+		reload_ok = base_window_yesno_dlg( BASE_WINDOW( window ), GTK_MESSAGE_QUESTION, first, second );
+
+		g_free( second );
+		g_free( first );
+	}
+
+	return( reload_ok );
+}
+
+/*
+ * informs the user that the actions in underlying storage subsystem
+ * have changed, and propose for reloading
+ *
+ */
+static gboolean
+confirm_for_giveup_from_pivot( NactMainWindow *window )
+{
+	gboolean reload_ok;
+	gchar *first, *second;
+
+	first = g_strdup(
+				_( "One or more actions have been modified in the filesystem.\n"
+					"You could keep to work with your current list of actions, "
+					"or you may want to reload a fresh one." ));
+
+	if( nact_main_window_has_modified_items( window )){
+
+		gchar *tmp = g_strdup_printf( "%s\n\n%s", first,
+				_( "Note that reloading a fresh list of actions requires "
+					"that you give up with your current modifications." ));
+		g_free( first );
+		first = tmp;
+	}
+
+	second = g_strdup( _( "Do you want to reload a fresh list of actions ?" ));
+
+	reload_ok = base_window_yesno_dlg( BASE_WINDOW( window ), GTK_MESSAGE_QUESTION, first, second );
+
+	g_free( second );
+	g_free( first );
+
+	return( reload_ok );
+}
+
+/*
  * called by NAPivot because this window implements the IIOConsumer
  * interface, i.e. it wish to be advertised when the list of actions
  * changes in the underlying I/O storage subsystem (typically, when we
@@ -977,39 +1067,40 @@ static void
 ipivot_consumer_on_actions_changed( NAIPivotConsumer *instance, gpointer user_data )
 {
 	static const gchar *thisfn = "nact_main_window_ipivot_consumer_on_actions_changed";
-	NactApplication *application;
-	NAPivot *pivot;
-	gchar *first, *second;
-	gboolean ok;
+	NactMainWindow *window;
+	gboolean reload_ok;
 
 	g_debug( "%s: instance=%p, user_data=%p", thisfn, ( void * ) instance, ( void * ) user_data );
-	g_assert( NACT_IS_MAIN_WINDOW( instance ));
+	g_return_if_fail( NACT_IS_MAIN_WINDOW( instance ));
+	window = NACT_MAIN_WINDOW( instance );
 
-	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( instance )));
-	pivot = nact_application_get_pivot( application );
+	if( !window->private->dispose_has_run ){
 
-	first = g_strdup(_( "One or more actions have been modified in the filesystem.\n"
-								"You could keep to work with your current list of actions, "
-								"or you may want to reload a fresh one." ));
+		reload_ok = confirm_for_giveup_from_pivot( window );
 
-	if( nact_main_window_has_modified_items( NACT_MAIN_WINDOW( instance ))){
-		gchar *tmp = g_strdup_printf( "%s\n\n%s", first,
-				_( "Note that reloading a fresh list of actions requires "
-					"that you give up with your current modifications." ));
-		g_free( first );
-		first = tmp;
+		if( reload_ok ){
+			reload( window );
+		}
 	}
+}
 
-	second = g_strdup( _( "Do you want to reload a fresh list of actions ?" ));
+static void
+reload( NactMainWindow *window )
+{
+	NactApplication *application;
+	NAPivot *pivot;
 
-	ok = base_window_yesno_dlg( BASE_WINDOW( instance ), GTK_MESSAGE_QUESTION, first, second );
+	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
-	g_free( second );
-	g_free( first );
+	if( !window->private->dispose_has_run ){
 
-	if( ok ){
+		application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+		pivot = nact_application_get_pivot( application );
 		na_pivot_reload_items( pivot );
-		nact_iactions_list_fill( NACT_IACTIONS_LIST( instance ), na_pivot_get_items( pivot ));
+		nact_iactions_list_fill( NACT_IACTIONS_LIST( window ), na_pivot_get_items( pivot ));
+
+		na_object_free_items( window->private->deleted );
+		window->private->deleted = NULL;
 	}
 }
 
diff --git a/src/nact/nact-main-window.h b/src/nact/nact-main-window.h
index 5ada6fb..10745cc 100644
--- a/src/nact/nact-main-window.h
+++ b/src/nact/nact-main-window.h
@@ -73,6 +73,7 @@ NactMainWindow *nact_main_window_new( BaseApplication *application );
 gboolean        nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid );
 gboolean        nact_main_window_has_modified_items( const NactMainWindow *window );
 void            nact_main_window_move_to_deleted( NactMainWindow *window, GList *items );
+void            nact_main_window_reload( NactMainWindow *window );
 void            nact_main_window_remove_deleted( NactMainWindow *window );
 
 G_END_DECLS
diff --git a/src/nact/nact-window.c b/src/nact/nact-window.c
index 9aead0d..8fd3018 100644
--- a/src/nact/nact-window.c
+++ b/src/nact/nact-window.c
@@ -378,5 +378,5 @@ nact_window_warn_modified( NactWindow *window )
 		g_free( first );
 	}
 
-	return( ok );
+	return( confirm );
 }
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index fb945de..6707330 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -207,7 +207,7 @@ instance_dispose( GObject *object )
 	NautilusActions *self;
 
 	g_debug( "%s: object=%p", thisfn, ( void * ) object );
-	g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
+	g_return_if_fail( NAUTILUS_IS_ACTIONS( object ));
 	self = NAUTILUS_ACTIONS( object );
 
 	if( !self->private->dispose_has_run ){
@@ -230,7 +230,7 @@ instance_finalize( GObject *object )
 	NautilusActions *self;
 
 	g_debug( "%s: object=%p", thisfn, ( void * ) object );
-	g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
+	g_return_if_fail( NAUTILUS_IS_ACTIONS( object ));
 	self = NAUTILUS_ACTIONS( object );
 
 	g_free( self->private );



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