[nautilus-actions: 13/45] Uses GtkSortable interface to display actions



commit 9f536d8830d6a44c49998a45ef6667495bb5d209
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Jul 19 16:04:45 2009 +0200

    Uses GtkSortable interface to display actions

 ChangeLog                     |    6 ++++
 src/nact/nact-iactions-list.c |   53 +++++++++++++++++++++++-----------------
 src/nact/nact-iactions-list.h |    1 -
 src/nact/nact-main-window.c   |   19 +++++---------
 4 files changed, 43 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9d6f275..a3b46b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,11 @@
 
 	* src/nact/Makefile.am: Updated accordingly.
 
+	* src/nact/nact-iactions-list.c:
+	* src/nact/nact-iactions-list.h:
+	Uses GtkSortable interface.
+	Remove set_sorted_actions API.
+
 	* src/nact/nact-icommand-tab.c:
 	Disable the example label when there is no current profile.
 
@@ -23,6 +28,7 @@
 
 	* src/nact/nact-main-window.c:
 	Update menu tooltips to be dot-terminated.
+	New action is taken from GTK_STOCK_NEW.
 
 	* src/nact/nautilus-actions-config.ui:
 	Example label now wraps on more than two lines.
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 0c68d5f..be5ce4f 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -64,14 +64,13 @@ static void       interface_base_init( NactIActionsListInterface *klass );
 static void       interface_base_finalize( NactIActionsListInterface *klass );
 
 static GSList    *v_get_actions( NactWindow *window );
-static void       v_set_sorted_actions( NactWindow *window, GSList *actions );
 static void       v_on_selection_changed( GtkTreeSelection *selection, gpointer user_data );
 static gboolean   v_on_button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer data );
 static gboolean   v_on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, gpointer data );
 
+static gint       sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, NactWindow *window );
 static gboolean   filter_visible( GtkTreeModel *model, GtkTreeIter *iter, gpointer data );
 static GtkWidget *get_actions_list_widget( NactWindow *window );
-static gint       sort_actions_by_label( gconstpointer a1, gconstpointer a2 );
 
 GType
 nact_iactions_list_get_type( void )
@@ -163,6 +162,14 @@ nact_iactions_list_initial_load( NactWindow *window )
 
 	GtkTreeModel *tmf_model = gtk_tree_model_filter_new( GTK_TREE_MODEL( ts_model ), NULL );
 
+	gtk_tree_sortable_set_default_sort_func(
+			GTK_TREE_SORTABLE( ts_model ),
+	        ( GtkTreeIterCompareFunc ) sort_actions_list, window, NULL );
+
+	gtk_tree_sortable_set_sort_column_id(
+			GTK_TREE_SORTABLE( ts_model ),
+			IACTIONS_LIST_LABEL_COLUMN, GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID );
+
 	gtk_tree_model_filter_set_visible_func(
 			GTK_TREE_MODEL_FILTER( tmf_model ), ( GtkTreeModelFilterVisibleFunc ) filter_visible, window, NULL );
 
@@ -244,8 +251,8 @@ nact_iactions_list_fill( NactWindow *window )
 	gtk_tree_store_clear( ts_model );
 
 	GSList *actions = v_get_actions( window );
-	actions = g_slist_sort( actions, ( GCompareFunc ) sort_actions_by_label );
-	v_set_sorted_actions( window, actions );
+	/*actions = g_slist_sort( actions, ( GCompareFunc ) sort_actions_by_label );
+	v_set_sorted_actions( window, actions );*/
 
 	GSList *ia;
 	/*g_debug( "%s: actions has %d elements", thisfn, g_slist_length( actions ));*/
@@ -481,7 +488,7 @@ v_get_actions( NactWindow *window )
 	return( NULL );
 }
 
-static void
+/*static void
 v_set_sorted_actions( NactWindow *window, GSList *actions )
 {
 	g_assert( NACT_IS_IACTIONS_LIST( window ));
@@ -490,7 +497,7 @@ v_set_sorted_actions( NactWindow *window, GSList *actions )
 	if( NACT_IACTIONS_LIST_GET_INTERFACE( instance )->set_sorted_actions ){
 		NACT_IACTIONS_LIST_GET_INTERFACE( instance )->set_sorted_actions( window, actions );
 	}
-}
+}*/
 
 static void
 v_on_selection_changed( GtkTreeSelection *selection, gpointer user_data )
@@ -564,6 +571,23 @@ v_on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, gpointer user_dat
 	return( stop );
 }
 
+static gint
+sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, NactWindow *window )
+{
+	g_debug( "sort_actions_list" );
+	gchar *labela, *labelb;
+
+	gtk_tree_model_get( model, a, IACTIONS_LIST_LABEL_COLUMN, &labela, -1 );
+	gtk_tree_model_get( model, b, IACTIONS_LIST_LABEL_COLUMN, &labelb, -1 );
+
+	gint ret = g_utf8_collate( labela, labelb );
+
+	g_free( labela );
+	g_free( labelb );
+
+	return( ret );
+}
+
 static gboolean
 filter_visible( GtkTreeModel *model, GtkTreeIter *iter, gpointer data )
 {
@@ -588,20 +612,3 @@ get_actions_list_widget( NactWindow *window )
 {
 	return( base_window_get_widget( BASE_WINDOW( window ), "ActionsList" ));
 }
-
-static gint
-sort_actions_by_label( gconstpointer a1, gconstpointer a2 )
-{
-	NAAction *action1 = NA_ACTION( a1 );
-	gchar *label1 = na_action_get_label( action1 );
-
-	NAAction *action2 = NA_ACTION( a2 );
-	gchar *label2 = na_action_get_label( action2 );
-
-	gint ret = g_utf8_collate( label1, label2 );
-
-	g_free( label1 );
-	g_free( label2 );
-
-	return( ret );
-}
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index 2a988fe..0481f8c 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -60,7 +60,6 @@ typedef struct {
 
 	/* api */
 	GSList * ( *get_actions )          ( NactWindow *window );
-	void     ( *set_sorted_actions )   ( NactWindow *window, GSList *actions );
 	void     ( *on_selection_changed ) ( GtkTreeSelection *selection, gpointer user_data );
 	gboolean ( *on_button_press_event )( GtkWidget *widget, GdkEventButton *event, gpointer data );
 	gboolean ( *on_key_pressed_event ) ( GtkWidget *widget, GdkEventKey *event, gpointer data );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index c303168..6896caf 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -91,7 +91,6 @@ static void             instance_finalize( GObject *application );
 static gchar           *get_iprefs_window_id( NactWindow *window );
 static gchar           *get_toplevel_name( BaseWindow *window );
 static GSList          *get_actions( NactWindow *window );
-static void             set_sorted_actions( NactWindow *window, GSList *actions );
 
 static void             on_initial_load_toplevel( BaseWindow *window );
 static void             create_file_menu( BaseWindow *window, GtkMenuBar *menubar );
@@ -259,7 +258,6 @@ iactions_list_iface_init( NactIActionsListInterface *iface )
 	g_debug( "%s: iface=%p", thisfn, iface );
 
 	iface->get_actions = get_actions;
-	iface->set_sorted_actions = set_sorted_actions;
 	iface->on_selection_changed = on_actions_list_selection_changed;
 	iface->on_double_click = on_actions_list_double_click;
 	iface->on_enter_key_pressed = on_actions_list_enter_key_pressed;
@@ -414,13 +412,6 @@ get_actions( NactWindow *window )
 	return( NACT_MAIN_WINDOW( window )->private->actions );
 }
 
-static void
-set_sorted_actions( NactWindow *window, GSList *actions )
-{
-	g_assert( NACT_IS_MAIN_WINDOW( window ));
-	NACT_MAIN_WINDOW( window )->private->actions = actions;
-}
-
 /*
  * note that for this NactMainWindow, on_initial_load_toplevel and
  * on_runtime_init_toplevel are equivalent, as there is only one
@@ -494,10 +485,10 @@ create_file_menu( BaseWindow *window, GtkMenuBar *menubar )
 	GtkWidget *menu = gtk_menu_new();
 	gtk_menu_item_set_submenu( GTK_MENU_ITEM( file ), menu );
 
-	/* i18n: 'New action' item in 'File' menu */
-	GtkWidget *item = gtk_image_menu_item_new_with_label( _( "New _action" ));
+	GtkWidget *item = gtk_image_menu_item_new_from_stock( GTK_STOCK_NEW, NULL );
+	/* i18n: 'New action' item in 'File' menu - use same accelerator than GTK_STOCK_NEW item */
+	gtk_menu_item_set_label( GTK_MENU_ITEM( item ), _( "_New action" ));
 	gtk_menu_shell_append( GTK_MENU_SHELL( menu ), item );
-	gtk_menu_item_set_use_underline( GTK_MENU_ITEM( item ), TRUE );
 	nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( item ), "activate", G_CALLBACK( on_new_action_activated ));
 	nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( item ), "select", G_CALLBACK( on_new_action_selected ));
 	nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( item ), "deselect", G_CALLBACK( on_menu_item_deselected ));
@@ -816,7 +807,11 @@ get_schemes( NactWindow *window )
 static void
 on_new_action_activated( GtkMenuItem *item, gpointer user_data )
 {
+	g_assert( NACT_IS_MAIN_WINDOW( user_data ));
+	NactMainWindow *window = NACT_MAIN_WINDOW( user_data );
 
+	NAAction *action = na_action_new_with_profile();
+	window->private->actions = g_slist_prepend( window->private->actions, action );
 }
 
 static void



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