[nautilus-actions] Prevent a capability to be inserted twice
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Prevent a capability to be inserted twice
- Date: Tue, 27 Jul 2010 21:47:12 +0000 (UTC)
commit 2cfb0a2f81bf399fa0d6080107622ad64858b16c
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Jul 26 19:31:37 2010 +0200
Prevent a capability to be inserted twice
ChangeLog | 11 +++++++++
src/nact/nact-add-capability-dialog.c | 17 +++++++++++++-
src/nact/nact-icapabilities-tab.c | 6 +++-
src/nact/nact-match-list.c | 38 +++++++++++++++++++++++++++++++++
src/nact/nact-match-list.h | 26 ++++++++++++----------
5 files changed, 82 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 83bf69b..0b38564 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2010-07-26 Pierre Wieser <pwieser trychlos org>
+ Prevent a capability to be inserted twice.
+
+ * src/nact/nact-add-capability-dialog.c (on_button_press_event):
+ On double-clic, check for OK sensitivity.
+
+ * src/nact/nact-icapabilities-tab.c (on_add_clicked):
+ Provide the dialog with our current content rather than current capabilities.
+
+ * src/nact/nact-match-list.c:
+ * src/nact/nact-match-list.h (nact_match_list_get_rows): New function.
+
Fix parameters conversion to v3.
* src/core/na-object-action.c (icontext_is_candidate):
diff --git a/src/nact/nact-add-capability-dialog.c b/src/nact/nact-add-capability-dialog.c
index 05fbfd7..b8437fa 100644
--- a/src/nact/nact-add-capability-dialog.c
+++ b/src/nact/nact-add-capability-dialog.c
@@ -101,6 +101,7 @@ static void display_keyword( GtkTreeViewColumn *column, GtkCellRenderer *cel
static void display_description( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, BaseWindow *window );
static void display_label( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, BaseWindow *window, guint column_id );
static gboolean setup_values_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GSList *capabilities );
+static void try_for_send_ok( NactAddCapabilityDialog *dialog );
static void send_ok( NactAddCapabilityDialog *dialog );
static void validate_dialog( NactAddCapabilityDialog *editor );
static gboolean base_dialog_response( GtkDialog *dialog, gint code, BaseWindow *window );
@@ -448,7 +449,7 @@ on_button_press_event( GtkWidget *widget, GdkEventButton *event, NactAddCapabili
/* double-click of left button */
if( event->type == GDK_2BUTTON_PRESS && event->button == 1 ){
- send_ok( dialog );
+ try_for_send_ok( dialog );
stop = TRUE;
}
@@ -527,7 +528,7 @@ setup_values_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GS
if( na_core_utils_slist_find_negated( capabilities, keyword )){
/* i18n: add a comment when a capability is already used by current item */
- new_description = g_strdup_printf( _( "%s (already used)"), description );
+ new_description = g_strdup_printf( _( "%s (already inserted)"), description );
gtk_list_store_set( GTK_LIST_STORE( model ), iter, CAPABILITY_DESC_COLUMN, new_description, CAPABILITY_ALREADY_USED_COLUMN, TRUE, -1 );
g_free( new_description );
}
@@ -539,6 +540,18 @@ setup_values_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GS
}
static void
+try_for_send_ok( NactAddCapabilityDialog *dialog )
+{
+ GtkWidget *button;
+
+ button = base_window_get_widget( BASE_WINDOW( dialog ), "OKButton" );
+
+ if( gtk_widget_get_sensitive( button )){
+ send_ok( dialog );
+ }
+}
+
+static void
send_ok( NactAddCapabilityDialog *dialog )
{
GtkWindow *toplevel = base_window_get_toplevel( BASE_WINDOW( dialog ));
diff --git a/src/nact/nact-icapabilities-tab.c b/src/nact/nact-icapabilities-tab.c
index 41a82ba..6675a80 100644
--- a/src/nact/nact-icapabilities-tab.c
+++ b/src/nact/nact-icapabilities-tab.c
@@ -34,6 +34,7 @@
#include <glib/gi18n.h>
+#include <api/na-core-utils.h>
#include <api/na-object-api.h>
#include "nact-main-tab.h"
@@ -223,14 +224,15 @@ on_add_clicked( GtkButton *button, BaseWindow *window )
context = nact_main_tab_get_context( NACT_MAIN_WINDOW( window ), NULL );
if( context ){
- capabilities = na_object_get_capabilities( context );
+ capabilities = nact_match_list_get_rows( window, ITAB_NAME );
new_cap = nact_add_capability_dialog_run( window, capabilities );
- g_debug( "nact_icapabilities_tab_on_add_clicked: new_cap=%s", new_cap );
if( new_cap ){
nact_match_list_insert_row( window, ITAB_NAME, new_cap, FALSE, FALSE );
g_free( new_cap );
}
+
+ na_core_utils_slist_free( capabilities );
}
}
diff --git a/src/nact/nact-match-list.c b/src/nact/nact-match-list.c
index c5da795..1811aed 100644
--- a/src/nact/nact-match-list.c
+++ b/src/nact/nact-match-list.c
@@ -67,6 +67,8 @@ static ColumnHeaderStruct st_match_headers[] = {
static gboolean st_on_selection_change = FALSE;
+static gboolean get_rows_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GSList **filters );
+
static void on_add_filter_clicked( GtkButton *button, MatchListStr *data );
static void on_filter_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data );
static void on_filter_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, MatchListStr *data );
@@ -378,6 +380,42 @@ nact_match_list_insert_row( BaseWindow *window, const gchar *tab_name, const gch
}
/**
+ * nact_match_list_get_rows:
+ * @window: the #BaseWindow window which contains the view.
+ * @tab_name: a string constant which identifies this page.
+ *
+ * Returns the list of rows as a newly allocated string list which should
+ * be na_core_utils_slist_free() by the caller.
+ */
+GSList *
+nact_match_list_get_rows( BaseWindow *window, const gchar *tab_name )
+{
+ GSList *filters;
+ MatchListStr *data;
+ GtkTreeModel *model;
+
+ filters = NULL;
+ data = ( MatchListStr * ) g_object_get_data( G_OBJECT( window ), tab_name );
+ g_return_val_if_fail( data != NULL, NULL );
+
+ model = gtk_tree_view_get_model( data->listview );
+ gtk_tree_model_foreach( model, ( GtkTreeModelForeachFunc ) get_rows_iter, &filters );
+
+ return( filters );
+}
+
+static gboolean
+get_rows_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GSList **filters )
+{
+ gchar *keyword;
+
+ gtk_tree_model_get( model, iter, ITEM_COLUMN, &keyword, -1 );
+ *filters = g_slist_prepend( *filters, keyword );
+
+ return( FALSE ); /* don't stop looping */
+}
+
+/**
* nact_match_list_dispose:
* @window: the #BaseWindow window which contains the view.
* @tab_name: a string constant which identifies this page.
diff --git a/src/nact/nact-match-list.h b/src/nact/nact-match-list.h
index 9855f01..eec0982 100644
--- a/src/nact/nact-match-list.h
+++ b/src/nact/nact-match-list.h
@@ -67,22 +67,24 @@ typedef struct {
}
MatchListStr;
-void nact_match_list_create_model ( BaseWindow *window, const gchar *tab_name,
- guint tab_id,
- GtkWidget *listview, GtkWidget *addbutton, GtkWidget *removebutton,
- pget_filters pget, pset_filters pset, pon_add_cb pon_add,
- guint match_header,
- const gchar *item_header );
+void nact_match_list_create_model ( BaseWindow *window, const gchar *tab_name,
+ guint tab_id,
+ GtkWidget *listview, GtkWidget *addbutton, GtkWidget *removebutton,
+ pget_filters pget, pset_filters pset, pon_add_cb pon_add,
+ guint match_header,
+ const gchar *item_header );
-void nact_match_list_init_view ( BaseWindow *window, const gchar *tab_name );
+void nact_match_list_init_view ( BaseWindow *window, const gchar *tab_name );
-void nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
- guint count );
+void nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
+ guint count );
-void nact_match_list_insert_row ( BaseWindow *window, const gchar *tab_name,
- const gchar *filter, gboolean match, gboolean not_match );
+void nact_match_list_insert_row ( BaseWindow *window, const gchar *tab_name,
+ const gchar *filter, gboolean match, gboolean not_match );
-void nact_match_list_dispose ( BaseWindow *window, const gchar *tab_name );
+GSList *nact_match_list_get_rows ( BaseWindow *window, const gchar *tab_name );
+
+void nact_match_list_dispose ( BaseWindow *window, const gchar *tab_name );
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]