[nautilus-actions] Primary clipboard makes use of convenience NactClipboard class



commit afa8121dafc1a1d177b9224b4f72e83236c33c65
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Sep 27 00:43:33 2009 +0200

    Primary clipboard makes use of convenience NactClipboard class

 ChangeLog                    |   14 ++++++
 src/nact/nact-clipboard.c    |  107 +++++++++++++++++++++++-------------------
 src/nact/nact-clipboard.h    |    6 +-
 src/nact/nact-main-menubar.c |   16 +++++--
 src/nact/nact-main-window.c  |   21 ++++++++-
 src/nact/nact-main-window.h  |    2 +
 6 files changed, 109 insertions(+), 57 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f18396d..45eb447 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-09-27 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/nact-clipboard.c:
+	* src/nact/nact-clipboard.h (nact_clipboard_primary_set,
+	nact_clipboard_primary_get, nact_clipboard_primary_counts):
+	Now use the NactClipboard convenience object.
+
+	* src/nact/nact-main-menubar.c:
+	Now use the NactClipboard convenience object.
+
+	* src/nact/nact-main-window.c:
+	* src/nact/nact-main-window.h (nact_main_window_get_clipboard):
+	New function.
+
 2009-09-26 Pierre Wieser <pwieser trychlos org>
 
 	* src/common/na-iduplicable.c:
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index a965e1c..5a7c1da 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -341,6 +341,7 @@ nact_clipboard_export_items( const gchar *uri, GList *items )
 
 /**
  * nact_clipboard_primary_set:
+ * @clipboard: this #NactClipboard object.
  * @items: a list of #NAObject items
  * @renumber_items: whether the actions or menus items should be
  * renumbered when copied in the clipboard ?
@@ -360,43 +361,47 @@ nact_clipboard_export_items( const gchar *uri, GList *items )
  * data out of the clipboard.
  */
 void
-nact_clipboard_primary_set( GList *items, gboolean renumber )
+nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gboolean renumber )
 {
-	GtkClipboard *clipboard;
 	NactClipboardData *data;
 	GList *it;
 
-	clipboard = get_primary_clipboard();
-	data = g_new0( NactClipboardData, 1 );
+	g_return_if_fail( NACT_IS_CLIPBOARD( clipboard ));
 
-	for( it = items ; it ; it = it->next ){
-		data->items = g_list_prepend( data->items, na_object_duplicate( it->data ));
+	if( !clipboard->private->dispose_has_run ){
 
-		if( NA_IS_OBJECT_ACTION( it->data )){
-			data->nb_actions += 1;
+		data = g_new0( NactClipboardData, 1 );
 
-		} else if( NA_IS_OBJECT_MENU( it->data )){
-			data->nb_menus += 1;
+		for( it = items ; it ; it = it->next ){
+			data->items = g_list_prepend( data->items, na_object_duplicate( it->data ));
 
-		} else if( NA_IS_OBJECT_PROFILE( it->data )){
-			data->nb_profiles += 1;
+			if( NA_IS_OBJECT_ACTION( it->data )){
+				data->nb_actions += 1;
+
+			} else if( NA_IS_OBJECT_MENU( it->data )){
+				data->nb_menus += 1;
+
+			} else if( NA_IS_OBJECT_PROFILE( it->data )){
+				data->nb_profiles += 1;
+			}
 		}
-	}
-	data->items = g_list_reverse( data->items );
+		data->items = g_list_reverse( data->items );
 
-	if( renumber ){
-		renumber_items( data->items );
-	}
+		if( renumber ){
+			renumber_items( data->items );
+		}
 
-	gtk_clipboard_set_with_data( clipboard,
-			clipboard_formats, G_N_ELEMENTS( clipboard_formats ),
-			( GtkClipboardGetFunc ) get_from_clipboard_callback,
-			( GtkClipboardClearFunc ) clear_clipboard_callback,
-			data );
+		gtk_clipboard_set_with_data( clipboard->private->primary,
+				clipboard_formats, G_N_ELEMENTS( clipboard_formats ),
+				( GtkClipboardGetFunc ) get_from_clipboard_callback,
+				( GtkClipboardClearFunc ) clear_clipboard_callback,
+				data );
+	}
 }
 
 /**
  * nact_clipboard_primary_get:
+ * @clipboard: this #NactClipboard object.
  *
  * Returns: a copy of the list of items previously referenced in the
  * internal clipboard.
@@ -405,31 +410,32 @@ nact_clipboard_primary_set( GList *items, gboolean renumber )
  * time.
  */
 GList *
-nact_clipboard_primary_get( void )
+nact_clipboard_primary_get( NactClipboard *clipboard )
 {
-	GtkClipboard *clipboard;
 	GtkSelectionData *selection;
 	NactClipboardData *data;
-	GList *items, *it;
+	GList *items = NULL;
+	GList *it;
 	NAObject *obj;
 
-	clipboard = get_primary_clipboard();
+	g_return_val_if_fail( NACT_IS_CLIPBOARD( clipboard ), NULL );
 
-	items = NULL;
+	if( !clipboard->private->dispose_has_run ){
 
-	selection = gtk_clipboard_wait_for_contents( clipboard, NACT_CLIPBOARD_NACT_ATOM );
+		selection = gtk_clipboard_wait_for_contents( clipboard->private->primary, NACT_CLIPBOARD_NACT_ATOM );
 
-	if( selection ){
-		data = ( NactClipboardData * ) selection->data;
+		if( selection ){
+			data = ( NactClipboardData * ) selection->data;
 
-		for( it = data->items ; it ; it = it->next ){
-			obj = na_object_duplicate( it->data );
-			na_object_set_origin( obj, NULL );
-			items = g_list_prepend( items, obj );
-		}
-		items = g_list_reverse( items );
+			for( it = data->items ; it ; it = it->next ){
+				obj = na_object_duplicate( it->data );
+				na_object_set_origin( obj, NULL );
+				items = g_list_prepend( items, obj );
+			}
+			items = g_list_reverse( items );
 
-		renumber_items( data->items );
+			renumber_items( data->items );
+		}
 	}
 
 	return( items );
@@ -437,31 +443,34 @@ nact_clipboard_primary_get( void )
 
 /**
  * nact_clipboard_primary_counts:
+ * @clipboard: this #NactClipboard object.
  *
  * Returns some counters on content of primary clipboard.
  */
 void
-nact_clipboard_primary_counts( guint *actions, guint *profiles, guint *menus )
+nact_clipboard_primary_counts( NactClipboard *clipboard, guint *actions, guint *profiles, guint *menus )
 {
-	GtkClipboard *clipboard;
 	GtkSelectionData *selection;
 	NactClipboardData *data;
 
+	g_return_if_fail( NACT_IS_CLIPBOARD( clipboard ));
 	g_return_if_fail( actions && profiles && menus );
-	*actions = 0;
-	*profiles = 0;
-	*menus = 0;
 
-	clipboard = get_primary_clipboard();
+	if( !clipboard->private->dispose_has_run ){
 
-	selection = gtk_clipboard_wait_for_contents( clipboard, NACT_CLIPBOARD_NACT_ATOM );
+		*actions = 0;
+		*profiles = 0;
+		*menus = 0;
 
-	if( selection ){
-		data = ( NactClipboardData * ) selection->data;
+		selection = gtk_clipboard_wait_for_contents( clipboard->private->primary, NACT_CLIPBOARD_NACT_ATOM );
 
-		*actions = data->nb_actions;
-		*profiles = data->nb_profiles;
-		*menus = data->nb_menus;
+		if( selection ){
+			data = ( NactClipboardData * ) selection->data;
+
+			*actions = data->nb_actions;
+			*profiles = data->nb_profiles;
+			*menus = data->nb_menus;
+		}
 	}
 }
 
diff --git a/src/nact/nact-clipboard.h b/src/nact/nact-clipboard.h
index 2b15d76..0092226 100644
--- a/src/nact/nact-clipboard.h
+++ b/src/nact/nact-clipboard.h
@@ -75,9 +75,9 @@ NactClipboard *nact_clipboard_new( void );
 void           nact_clipboard_get_data_for_intern_use( GList *selected_items, gboolean copy_data );
 char          *nact_clipboard_get_data_for_extern_use( GList *selected_items );
 
-void           nact_clipboard_primary_set( GList *items, gboolean renumber_items );
-GList         *nact_clipboard_primary_get( void );
-void           nact_clipboard_primary_counts( guint *actions, guint *profiles, guint *menus );
+void           nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gboolean renumber_items );
+GList         *nact_clipboard_primary_get( NactClipboard *clipboard );
+void           nact_clipboard_primary_counts( NactClipboard *clipboard, guint *actions, guint *profiles, guint *menus );
 
 void           nact_clipboard_free_items( GSList *items );
 
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 3ddfbfd..26a14b0 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -482,13 +482,15 @@ static void
 on_cut_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	GList *items;
+	NactClipboard *clipboard;
 
 	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 );
-	nact_clipboard_primary_set( items, FALSE );
+	clipboard = nact_main_window_get_clipboard( window );
+	nact_clipboard_primary_set( clipboard, items, FALSE );
 	nact_iactions_list_delete( NACT_IACTIONS_LIST( window ), items );
 
 	/* do not unref selected items as the ref has been moved to main_deleted
@@ -508,12 +510,14 @@ static void
 on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	GList *items;
+	NactClipboard *clipboard;
 
 	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_clipboard_primary_set( items, TRUE );
+	clipboard = nact_main_window_get_clipboard( window );
+	nact_clipboard_primary_set( clipboard, items, TRUE );
 	na_object_free_items( items );
 	nact_main_menubar_refresh_actions_sensitivity( window );
 }
@@ -533,8 +537,10 @@ static void
 on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	GList *items;
+	NactClipboard *clipboard;
 
-	items = nact_clipboard_primary_get();
+	clipboard = nact_main_window_get_clipboard( window );
+	items = nact_clipboard_primary_get( clipboard );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 	na_object_free_items( items );
 }
@@ -770,6 +776,7 @@ refresh_actions_sensitivity_with_count( NactMainWindow *window, gint count_selec
 	gboolean has_modified;
 	guint nb_actions, nb_profiles, nb_menus;
 	gboolean paste_enabled;
+	NactClipboard *clipboard;
 
 	g_debug( "%s: window=%p, count_selected=%d", thisfn, ( void * ) window, count_selected );
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -784,7 +791,8 @@ refresh_actions_sensitivity_with_count( NactMainWindow *window, gint count_selec
 	has_modified = nact_main_window_has_modified_items( window );
 
 	paste_enabled = FALSE;
-	nact_clipboard_primary_counts( &nb_actions, &nb_profiles, &nb_menus );
+	clipboard = nact_main_window_get_clipboard( window );
+	nact_clipboard_primary_counts( clipboard, &nb_actions, &nb_profiles, &nb_menus );
 	g_debug( "%s: actions=%d, profiles=%d, menus=%d", thisfn, nb_actions, nb_profiles, nb_menus );
 	if( nb_profiles ){
 		paste_enabled = NA_IS_OBJECT_ACTION( item );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index d535e9c..498c706 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -45,7 +45,6 @@
 
 #include "base-iprefs.h"
 #include "nact-application.h"
-#include "nact-clipboard.h"
 #include "nact-iactions-list.h"
 #include "nact-iaction-tab.h"
 #include "nact-icommand-tab.h"
@@ -597,6 +596,26 @@ nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid
 }
 
 /**
+ * nact_main_window_get_clipboard:
+ * @window: this #NactMainWindow instance.
+ *
+ * Returns: the #nactClipboard convenience object.
+ */
+NactClipboard *
+nact_main_window_get_clipboard( const NactMainWindow *window )
+{
+	NactClipboard *clipboard = NULL;
+
+	g_return_val_if_fail( NACT_IS_MAIN_WINDOW( window ), NULL );
+
+	if( !window->private->dispose_has_run ){
+		clipboard = window->private->clipboard;
+	}
+
+	return( clipboard );
+}
+
+/**
  * nact_main_window_has_modified_items:
  * @window: this #NactMainWindow instance.
  *
diff --git a/src/nact/nact-main-window.h b/src/nact/nact-main-window.h
index 10745cc..15b1b8f 100644
--- a/src/nact/nact-main-window.h
+++ b/src/nact/nact-main-window.h
@@ -39,6 +39,7 @@
  * This class is derived from BaseWindow and manages the main window.
  */
 
+#include "nact-clipboard.h"
 #include "nact-window.h"
 
 G_BEGIN_DECLS
@@ -71,6 +72,7 @@ GType           nact_main_window_get_type( void );
 NactMainWindow *nact_main_window_new( BaseApplication *application );
 
 gboolean        nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid );
+NactClipboard  *nact_main_window_get_clipboard( const NactMainWindow *window );
 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 );



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