[nautilus-actions] Rewrite scheme row insertion



commit 7258a8c95d935ca84833e95c6497c1ca71e5b086
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Apr 15 20:27:48 2010 +0200

    Rewrite scheme row insertion
    
    As scheme description is not saved with the action, then it is really useless
    to insert a row which has a non-editable scheme description.

 ChangeLog                    |    3 ++
 src/nact/nact-schemes-list.c |   44 ++++++-----------------------------------
 2 files changed, 10 insertions(+), 37 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 507d8ce..e620d20 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,9 @@
 
 2010-04-15 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/nact-schemes-list.c (insert_new_row):
+	Rewrite row insertion; do not insert a - non-editable - description.
+
 	* src/nact/nact-preferences.ui: Fix typo.
 
 	* src/io-gconf/nagp-keys.h:
diff --git a/src/nact/nact-schemes-list.c b/src/nact/nact-schemes-list.c
index 3807f74..8cf5907 100644
--- a/src/nact/nact-schemes-list.c
+++ b/src/nact/nact-schemes-list.c
@@ -59,8 +59,6 @@ enum {
 #define SCHEMES_LIST_EDITABLE			"nact-schemes-list-editable"
 #define SCHEMES_LIST_TREEVIEW			"nact-schemes-list-treeview"
 
-#define SCHEMES_LIST_DESC_TITLE			"schemes-description"
-
 static gboolean st_on_selection_change = FALSE;
 
 static void       init_view_setup_defaults( GtkTreeView *treeview, BaseWindow *window );
@@ -138,7 +136,7 @@ nact_schemes_list_create_model( GtkTreeView *treeview, gboolean for_action )
 
 	text_cell = gtk_cell_renderer_text_new();
 	column = gtk_tree_view_column_new_with_attributes(
-			SCHEMES_LIST_DESC_TITLE,
+			"scheme-description",
 			text_cell,
 			"text", SCHEMES_DESC_COLUMN,
 			NULL );
@@ -743,52 +741,24 @@ insert_new_row( BaseWindow *window )
 {
 	GtkTreeView *listview;
 	GtkTreeModel *model;
-	GtkTreeSelection *selection;
-	GList *listrows;
+	GtkTreeIter iter;
+	gboolean for_action;
 	GtkTreePath *path;
-	GtkTreeIter iter, sibling;
-	gboolean inserted;
 	GtkTreeViewColumn *column;
 
 	listview = GTK_TREE_VIEW( g_object_get_data( G_OBJECT( window ), SCHEMES_LIST_TREEVIEW ));
 	model = gtk_tree_view_get_model( listview );
-	selection = gtk_tree_view_get_selection( listview );
-	listrows = gtk_tree_selection_get_selected_rows( selection, NULL );
-	inserted = FALSE;
-	column = NULL;
-
-	if( g_list_length( listrows ) == 1 ){
-		gtk_tree_view_get_cursor( listview, &path, &column );
-		if( gtk_tree_model_get_iter( model, &sibling, path )){
-			/* though the path of sibling is correct, the new row is always
-			 * inserted at path=0 !
-			 */
-			/*g_debug( "insert_new_row: sibling=%s", gtk_tree_model_get_string_from_iter( &sibling ));*/
-			gtk_list_store_insert_before( GTK_LIST_STORE( model ), &iter, &sibling );
-			inserted = TRUE;
-		}
-		gtk_tree_path_free( path );
-	}
-
-	if( !inserted ){
-		gtk_list_store_append( GTK_LIST_STORE( model ), &iter );
-	}
+	for_action = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( listview ), SCHEMES_LIST_FOR_ACTION ));
 
-	if( !column || column == gtk_tree_view_get_column( listview, SCHEMES_CHECKBOX_COLUMN )){
-		column = gtk_tree_view_get_column( listview, SCHEMES_KEYWORD_COLUMN );
-	}
-
-	gtk_list_store_set( GTK_LIST_STORE( model ), &iter,
+	gtk_list_store_insert_with_values( GTK_LIST_STORE( model ), &iter, 0,
 			SCHEMES_CHECKBOX_COLUMN, FALSE,
 			/* i18n notes : scheme name set for a new entry in the scheme list */
 			SCHEMES_KEYWORD_COLUMN, _( "new-scheme" ),
-			SCHEMES_DESC_COLUMN, _( "New scheme description" ),
+			SCHEMES_DESC_COLUMN, for_action ? "" : _( "New scheme description" ),
 			-1 );
 
-	g_list_foreach( listrows, ( GFunc ) gtk_tree_path_free, NULL );
-	g_list_free( listrows );
-
 	path = gtk_tree_model_get_path( model, &iter );
+	column = gtk_tree_view_get_column( listview, SCHEMES_KEYWORD_COLUMN );
 	gtk_tree_view_set_cursor( listview, path, column, TRUE );
 	gtk_tree_path_free( path );
 }



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