[nautilus-actions] Track the presence of the popup menu to apply edition actions



commit 21db55fd6c31f9d1a4da8be375e9994b8ad3bc46
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Oct 21 01:12:43 2009 +0200

    Track the presence of the popup menu to apply edition actions

 ChangeLog                     |   12 ++++
 src/nact/nact-iactions-list.c |   23 ++++++++
 src/nact/nact-iactions-list.h |    1 +
 src/nact/nact-main-menubar.c  |  121 ++++++++++++++++++++++++++++-------------
 4 files changed, 118 insertions(+), 39 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1582b34..06e2692 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2009-10-20 Pierre Wieser <pwieser trychlos org>
 
+	Enable edition actions when the popup menu is open.
+	Do not apply edition actions on ActionsList when the focus is
+	in a tab.
+
+	* src/nact/nact-iactions-list.c:
+	* src/nact/nact-iactions-list.h (nact_iactions_list_has_focus):
+	New function.
+
+	* src/nact/nact-main-menubar.c
+	(on_cut_activated, on_copy_activated, on_paste_activated,
+	on_delete_activated): Track the presence of a popup menu.
+
 	Enhance validity conditions of a profile.
 
 	* src/common/na-utils.c
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 94e6baa..e4ab7e4 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -999,6 +999,29 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
 }
 
 /**
+ * nact_iactions_list_has_focus:
+ * @window: this #NactIActionsList instance.
+ *
+ * Returns: %TRUE if the treeview has the focus, %FALSE else.
+ */
+gboolean
+nact_iactions_list_has_focus( NactIActionsList *instance )
+{
+	gboolean has_focus = FALSE;
+	GtkTreeView *treeview;
+
+	g_return_val_if_fail( NACT_IS_IACTIONS_LIST( instance ), FALSE );
+
+	if( st_initialized && !st_finalized ){
+
+		treeview = get_actions_list_treeview( instance );
+		has_focus = GTK_WIDGET_HAS_FOCUS( treeview );
+	}
+
+	return( has_focus );
+}
+
+/**
  * nact_iactions_list_has_modified_items:
  * @window: this #NactIActionsList instance.
  *
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index 2850bcd..f84d5f5 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -136,6 +136,7 @@ NAObject *nact_iactions_list_get_item( NactIActionsList *instance, const gchar *
 GList    *nact_iactions_list_get_items( NactIActionsList *instance );
 gint      nact_iactions_list_get_management_mode( NactIActionsList *instance );
 GList    *nact_iactions_list_get_selected_items( NactIActionsList *instance );
+gboolean  nact_iactions_list_has_focus( NactIActionsList *instance );
 gboolean  nact_iactions_list_has_modified_items( NactIActionsList *instance );
 void      nact_iactions_list_insert_at_path( NactIActionsList *instance, GList *items, GtkTreePath *path );
 void      nact_iactions_list_insert_items( NactIActionsList *instance, GList *items, NAObject *sibling );
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 220d700..cb308d8 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -86,6 +86,7 @@ typedef struct {
 	gboolean have_exportables;
 	gboolean treeview_has_focus;
 	gboolean level_zero_order_changed;
+	gulong   popup_handler;
 }
 	MenubarIndicatorsStruct;
 
@@ -134,6 +135,7 @@ static gboolean on_delete_event( GtkWidget *toplevel, GdkEvent *event, NactMainW
 static void     on_destroy_callback( gpointer data );
 static void     on_menu_item_selected( GtkMenuItem *proxy, NactMainWindow *window );
 static void     on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window );
+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 );
 
@@ -408,10 +410,14 @@ nact_main_menubar_open_popup( NactMainWindow *instance, GdkEventButton *event )
 {
 	GtkUIManager *ui_manager;
 	GtkWidget *menu;
+	MenubarIndicatorsStruct *mis;
 
 	ui_manager = ( GtkUIManager * ) g_object_get_data( G_OBJECT( instance ), MENUBAR_PROP_UI_MANAGER );
 	menu = gtk_ui_manager_get_widget( ui_manager, "/ui/Popup" );
 
+	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( instance ), MENUBAR_PROP_INDICATORS );
+	mis->popup_handler = g_signal_connect( menu, "selection-done", G_CALLBACK( on_popup_selection_done ), instance );
+
 	gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL, event->button, event->time );
 }
 
@@ -837,22 +843,28 @@ on_cut_activated( GtkAction *gtk_action, NactMainWindow *window )
 	static const gchar *thisfn = "nact_main_menubar_on_cut_activated";
 	GList *items;
 	NactClipboard *clipboard;
+	MenubarIndicatorsStruct *mis;
 
-	g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
-	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
-	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
 
-	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
-	nact_main_window_move_to_deleted( window, items );
-	clipboard = nact_main_window_get_clipboard( window );
-	nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_CUT );
-	update_clipboard_counters( window );
-	nact_iactions_list_delete( NACT_IACTIONS_LIST( window ), items );
+	if( nact_iactions_list_has_focus( NACT_IACTIONS_LIST( window )) || mis->popup_handler ){
 
-	/* do not unref selected items as the list has been concatenated
-	 * to main_deleted
-	 */
-	/*g_list_free( items );*/
+		g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
+		g_return_if_fail( GTK_IS_ACTION( gtk_action ));
+		g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+		items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
+		nact_main_window_move_to_deleted( window, items );
+		clipboard = nact_main_window_get_clipboard( window );
+		nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_CUT );
+		update_clipboard_counters( window );
+		nact_iactions_list_delete( NACT_IACTIONS_LIST( window ), items );
+
+		/* do not unref selected items as the list has been concatenated
+		 * to main_deleted
+		 */
+		/*g_list_free( items );*/
+	}
 }
 
 /*
@@ -869,18 +881,24 @@ on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 	static const gchar *thisfn = "nact_main_menubar_on_copy_activated";
 	GList *items;
 	NactClipboard *clipboard;
+	MenubarIndicatorsStruct *mis;
 
-	g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
-	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
-	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
 
-	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
-	clipboard = nact_main_window_get_clipboard( window );
-	nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_COPY );
-	update_clipboard_counters( window );
-	na_object_free_items_list( items );
+	if( nact_iactions_list_has_focus( NACT_IACTIONS_LIST( window )) || mis->popup_handler ){
 
-	g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
+		g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
+		g_return_if_fail( GTK_IS_ACTION( gtk_action ));
+		g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+		items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
+		clipboard = nact_main_window_get_clipboard( window );
+		nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_COPY );
+		update_clipboard_counters( window );
+		na_object_free_items_list( items );
+
+		g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
+	}
 }
 
 /*
@@ -900,12 +918,18 @@ on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	static const gchar *thisfn = "nact_main_menubar_on_paste_activated";
 	GList *items;
+	MenubarIndicatorsStruct *mis;
 
-	g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
+	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
 
-	items = prepare_for_paste( window );
-	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
-	na_object_free_items_list( items );
+	if( nact_iactions_list_has_focus( NACT_IACTIONS_LIST( window )) || mis->popup_handler ){
+
+		g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
+
+		items = prepare_for_paste( window );
+		nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
+		na_object_free_items_list( items );
+	}
 }
 
 /*
@@ -1034,22 +1058,28 @@ on_delete_activated( GtkAction *gtk_action, NactMainWindow *window )
 	static const gchar *thisfn = "nact_main_menubar_on_delete_activated";
 	GList *items;
 	GList *it;
+	MenubarIndicatorsStruct *mis;
 
-	g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
-	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
-	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
 
-	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
-	for( it = items ; it ; it = it->next ){
-		g_debug( "%s: item=%p (%s)", thisfn, ( void * ) it->data, G_OBJECT_TYPE_NAME( it->data ));
-	}
-	nact_main_window_move_to_deleted( window, items );
-	nact_iactions_list_delete( NACT_IACTIONS_LIST( window ), items );
+	if( nact_iactions_list_has_focus( NACT_IACTIONS_LIST( window )) || mis->popup_handler ){
 
-	/* do not unref selected items as the list has been concatenated
-	 * to main_deleted
-	 */
-	/*g_list_free( items );*/
+		g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
+		g_return_if_fail( GTK_IS_ACTION( gtk_action ));
+		g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+		items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
+		for( it = items ; it ; it = it->next ){
+			g_debug( "%s: item=%p (%s)", thisfn, ( void * ) it->data, G_OBJECT_TYPE_NAME( it->data ));
+		}
+		nact_main_window_move_to_deleted( window, items );
+		nact_iactions_list_delete( NACT_IACTIONS_LIST( window ), items );
+
+		/* do not unref selected items as the list has been concatenated
+		 * to main_deleted
+		 */
+		/*g_list_free( items );*/
+	}
 }
 
 /*
@@ -1222,6 +1252,19 @@ on_menu_item_deselected( GtkMenuItem *proxy, NactMainWindow *window )
 }
 
 static void
+on_popup_selection_done(GtkMenuShell *menushell, NactMainWindow *window )
+{
+	static const gchar *thisfn = "nact_main_menubar_on_popup_selection_done";
+	MenubarIndicatorsStruct *mis;
+
+	g_debug( "%s", thisfn );
+
+	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
+	g_signal_handler_disconnect( menushell, mis->popup_handler );
+	mis->popup_handler = ( gulong ) 0;
+}
+
+static void
 on_proxy_connect( GtkActionGroup *action_group, GtkAction *action, GtkWidget *proxy, NactMainWindow *window )
 {
 	static const gchar *thisfn = "nact_main_menubar_on_proxy_connect";



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