[libgda/LIBGDA_4.2] GdauiDataProxy: merged the "ActionUndelete" into the "ActionDelet"



commit e2c0e7e07e9f50c62a79cfc916d593208f17bec6
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Jul 24 13:17:04 2011 +0200

    GdauiDataProxy: merged the "ActionUndelete" into the "ActionDelet"
    
    as a GtkToggleAction

 libgda-ui/gdaui-data-proxy-info.c |   27 +++++---
 libgda-ui/gdaui-data-proxy.c      |   11 ++--
 libgda-ui/gdaui-raw-form.c        |   88 +++++++++++++---------------
 libgda-ui/gdaui-raw-grid.c        |  117 ++++++++++++++++++-------------------
 4 files changed, 119 insertions(+), 124 deletions(-)
---
diff --git a/libgda-ui/gdaui-data-proxy-info.c b/libgda-ui/gdaui-data-proxy-info.c
index e3cdb4f..b017fa4 100644
--- a/libgda-ui/gdaui-data-proxy-info.c
+++ b/libgda-ui/gdaui-data-proxy-info.c
@@ -404,7 +404,6 @@ static const gchar *ui_row_modif =
 	"  <toolbar name='ToolBar'>"
 	"    <toolitem action='ActionNew'/>"
 	"    <toolitem action='ActionDelete'/>"
-	"    <toolitem action='ActionUndelete'/>"
 	"    <toolitem action='ActionCommit'/>"
 	"    <toolitem action='ActionReset'/>"
 	"  </toolbar>"
@@ -790,15 +789,23 @@ idle_modif_buttons_update (GdauiDataProxyInfo *info)
 				      flags & GDA_DATA_MODEL_ACCESS_INSERT ? TRUE : FALSE, NULL);
 
 			action = gtk_ui_manager_get_action (info->priv->uimanager, "/ToolBar/ActionDelete");
-			wrows = is_inserted ||
-				((flags & GDA_DATA_MODEL_ACCESS_DELETE) &&
-				 (force_del_btn || (! to_be_deleted && has_selection)));
-			g_object_set (G_OBJECT (action), "sensitive", wrows, NULL);
-
-			action = gtk_ui_manager_get_action (info->priv->uimanager, "/ToolBar/ActionUndelete");
-			wrows = (flags & GDA_DATA_MODEL_ACCESS_DELETE) &&
-				(force_undel_btn || (to_be_deleted && has_selection));
-			g_object_set (G_OBJECT (action), "sensitive", wrows, NULL);
+			gtk_action_block_activate (action);
+			gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), to_be_deleted);
+			gtk_action_unblock_activate (action);
+
+			if (to_be_deleted) {
+				wrows = (flags & GDA_DATA_MODEL_ACCESS_DELETE) &&
+					(force_undel_btn || has_selection);
+				g_object_set (G_OBJECT (action), "sensitive", wrows, NULL);
+				gtk_action_set_tooltip (action, _("Undelete the selected entry"));
+			}
+			else {
+				wrows = is_inserted ||
+					((flags & GDA_DATA_MODEL_ACCESS_DELETE) &&
+					 (force_del_btn || has_selection));
+				g_object_set (G_OBJECT (action), "sensitive", wrows, NULL);
+				gtk_action_set_tooltip (action, _("Delete the selected entry"));
+			}
 
 			if ((mode == GDAUI_DATA_PROXY_WRITE_ON_ROW_CHANGE) ||
 			    (mode == GDAUI_DATA_PROXY_WRITE_ON_VALUE_CHANGE) ||
diff --git a/libgda-ui/gdaui-data-proxy.c b/libgda-ui/gdaui-data-proxy.c
index 4f602fd..17a5365 100644
--- a/libgda-ui/gdaui-data-proxy.c
+++ b/libgda-ui/gdaui-data-proxy.c
@@ -161,12 +161,13 @@ gdaui_data_proxy_column_show_actions (GdauiDataProxy *iface, gint column, gboole
  *
  * The actions are among: 
  * <itemizedlist><listitem><para>Data edition actions: "ActionNew", "ActionCommit", 
- *    "ActionDelete, "ActionUndelete, "ActionReset", </para></listitem>
+ *    "ActionDelete", "ActionReset". Note that the "ActionDelete" action is actually a #GtkToggleAction
+ *    action which can be used to delete a row or undelete it.</para></listitem>
  * <listitem><para>Record by record moving: "ActionFirstRecord", "ActionPrevRecord", 
- *    "ActionNextRecord", "ActionLastRecord",</para></listitem>
+ *    "ActionNextRecord", "ActionLastRecord".</para></listitem>
  * <listitem><para>Chuncks of records moving: "ActionFirstChunck", "ActionPrevChunck", 
  *     "ActionNextChunck", "ActionLastChunck".</para></listitem>
- * <listitem><para>Filtering: "ActionFilter"</para></listitem></itemizedlist>
+ * <listitem><para>Filtering: "ActionFilter".</para></listitem></itemizedlist>
  * 
  * Returns: (transfer none): the #GtkActionGroup with all the possible actions on the widget.
  *
@@ -217,10 +218,8 @@ gdaui_data_proxy_perform_action (GdauiDataProxy *iface, GdauiAction action)
 		action_name = "ActionCommit";
 		break;
         case GDAUI_ACTION_DELETE_SELECTED_DATA:
-		action_name = "ActionDelete";
-		break;
         case GDAUI_ACTION_UNDELETE_SELECTED_DATA:
-		action_name = "ActionUndelete";
+		action_name = "ActionDelete";
 		break;
         case GDAUI_ACTION_RESET_DATA:
 		action_name = "ActionReset";
diff --git a/libgda-ui/gdaui-raw-form.c b/libgda-ui/gdaui-raw-form.c
index a214639..dcb4ff5 100644
--- a/libgda-ui/gdaui-raw-form.c
+++ b/libgda-ui/gdaui-raw-form.c
@@ -184,8 +184,7 @@ gdaui_raw_form_class_init (GdauiRawFormClass *class)
 }
 
 static void action_new_cb (GtkAction *action, GdauiRawForm *form);
-static void action_delete_cb (GtkAction *action, GdauiRawForm *form);
-static void action_undelete_cb (GtkAction *action, GdauiRawForm *form);
+static void action_delete_cb (GtkToggleAction *action, GdauiRawForm *form);
 static void action_commit_cb (GtkAction *action, GdauiRawForm *form);
 static void action_reset_cb (GtkAction *action, GdauiRawForm *form);
 static void action_first_record_cb (GtkAction *action, GdauiRawForm *form);
@@ -194,23 +193,19 @@ static void action_next_record_cb (GtkAction *action, GdauiRawForm *form);
 static void action_last_record_cb (GtkAction *action, GdauiRawForm *form);
 static void action_filter_cb (GtkAction *action, GdauiRawForm *form);
 
+static GtkToggleActionEntry ui_actions_t[] = {
+	{ "ActionDelete", GTK_STOCK_REMOVE, "_Delete", NULL, N_("Delete the selected entry"), G_CALLBACK (action_delete_cb), FALSE},
+};
+
 static GtkActionEntry ui_actions[] = {
-	{ "ActionNew", GTK_STOCK_ADD, "_New", NULL, "Create a new data entry", G_CALLBACK (action_new_cb)},
-	{ "ActionDelete", GTK_STOCK_REMOVE, "_Delete", NULL, "Delete the selected entry", G_CALLBACK (action_delete_cb)},
-	{ "ActionUndelete", GTK_STOCK_UNDELETE, "_Undelete", NULL, "Cancels the deletion of the current entry",
-	  G_CALLBACK (action_undelete_cb)},
-	{ "ActionCommit", GTK_STOCK_SAVE, "_Commit", NULL, "Commit the latest changes", G_CALLBACK (action_commit_cb)},
-	{ "ActionReset", GTK_STOCK_REFRESH, "_Reset", NULL, "Reset the data", G_CALLBACK (action_reset_cb)},
-	{ "ActionFirstRecord", GTK_STOCK_GOTO_FIRST, "_First record", NULL, "Go to first record of records",
-	  G_CALLBACK (action_first_record_cb)},
-	{ "ActionLastRecord", GTK_STOCK_GOTO_LAST, "_Last record", NULL, "Go to last record of records",
-	  G_CALLBACK (action_last_record_cb)},
-	{ "ActionPrevRecord", GTK_STOCK_GO_BACK, "_Previous record", NULL, "Go to previous record of records",
-	  G_CALLBACK (action_prev_record_cb)},
-	{ "ActionNextRecord", GTK_STOCK_GO_FORWARD, "Ne_xt record", NULL, "Go to next record of records",
-	  G_CALLBACK (action_next_record_cb)},
-	{ "ActionFilter", GTK_STOCK_FIND, "Filter", NULL, "Filter records",
-	  G_CALLBACK (action_filter_cb)}
+	{ "ActionNew", GTK_STOCK_ADD, "_New", NULL, N_("Create a new data entry"), G_CALLBACK (action_new_cb)},
+	{ "ActionCommit", GTK_STOCK_SAVE, "_Commit", NULL, N_("Commit the latest changes"), G_CALLBACK (action_commit_cb)},
+	{ "ActionReset", GTK_STOCK_CLEAR, "_Clear", NULL, N_("Clear all the modifications"), G_CALLBACK (action_reset_cb)},
+	{ "ActionFirstRecord", GTK_STOCK_GOTO_FIRST, "_First record", NULL, N_("Go to first record of records"), G_CALLBACK (action_first_record_cb)},
+	{ "ActionLastRecord", GTK_STOCK_GOTO_LAST, "_Last record", NULL, N_("Go to last record of records"), G_CALLBACK (action_last_record_cb)},
+	{ "ActionPrevRecord", GTK_STOCK_GO_BACK, "_Previous record", NULL, N_("Go to previous record of records"), G_CALLBACK (action_prev_record_cb)},
+	{ "ActionNextRecord", GTK_STOCK_GO_FORWARD, "Ne_xt record", NULL, N_("Go to next record of records"), G_CALLBACK (action_next_record_cb)},
+	{ "ActionFilter", GTK_STOCK_FIND, "Filter", NULL, N_("Filter records"), G_CALLBACK (action_filter_cb)}
 };
 
 static void
@@ -228,7 +223,7 @@ form_activated_cb (GdauiRawForm *form, G_GNUC_UNUSED gpointer data)
 {
 	if (form->priv->write_mode == GDAUI_DATA_PROXY_WRITE_ON_VALUE_ACTIVATED) {
 		gint row;
-
+		
 		row = gda_data_model_iter_get_row (form->priv->iter);
 		if (row >= 0) {
 			/* write back the current row */
@@ -289,6 +284,7 @@ gdaui_raw_form_init (GdauiRawForm *wid)
 	gtk_action_group_set_translation_domain (wid->priv->actions_group, GETTEXT_PACKAGE);
 
         gtk_action_group_add_actions (wid->priv->actions_group, ui_actions, G_N_ELEMENTS (ui_actions), wid);
+        gtk_action_group_add_toggle_actions (wid->priv->actions_group, ui_actions_t, G_N_ELEMENTS (ui_actions_t), wid);
 	action = gtk_action_group_get_action (wid->priv->actions_group, "ActionNew");
 	g_signal_connect (G_OBJECT (action), "activate",
 			  G_CALLBACK (action_new_activated_cb), wid);
@@ -641,38 +637,36 @@ action_new_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawForm *form)
 }
 
 static void
-action_delete_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawForm *form)
+action_delete_cb (GtkToggleAction *action, GdauiRawForm *form)
 {
-	gint row;
-
-	row = gda_data_model_iter_get_row (form->priv->iter);
-	g_return_if_fail (row >= 0);
-	gda_data_proxy_delete (form->priv->proxy, row);
-
-	if (form->priv->write_mode >= GDAUI_DATA_PROXY_WRITE_ON_ROW_CHANGE) {
-		/* force the proxy to apply the current row deletion */
-		gint newrow;
-
-		newrow = gda_data_model_iter_get_row (form->priv->iter);
-		if (row == newrow) {/* => row has been marked as delete but not yet really deleted */
-			GError *error = NULL;
-			if (!gda_data_proxy_apply_row_changes (form->priv->proxy, row, &error)) {
-				_gdaui_utility_display_error ((GdauiDataProxy *) form, TRUE, error);
-				if (error)
-					g_error_free (error);
+	if (gtk_toggle_action_get_active (action)) {
+		gint row;
+		row = gda_data_model_iter_get_row (form->priv->iter);
+		g_return_if_fail (row >= 0);
+		gda_data_proxy_delete (form->priv->proxy, row);
+		
+		if (form->priv->write_mode >= GDAUI_DATA_PROXY_WRITE_ON_ROW_CHANGE) {
+			/* force the proxy to apply the current row deletion */
+			gint newrow;
+			
+			newrow = gda_data_model_iter_get_row (form->priv->iter);
+			if (row == newrow) {/* => row has been marked as delete but not yet really deleted */
+				GError *error = NULL;
+				if (!gda_data_proxy_apply_row_changes (form->priv->proxy, row, &error)) {
+					_gdaui_utility_display_error ((GdauiDataProxy *) form, TRUE, error);
+					if (error)
+						g_error_free (error);
+				}
 			}
 		}
 	}
-}
-
-static void
-action_undelete_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawForm *form)
-{
-	gint row;
-
-	row = gda_data_model_iter_get_row (form->priv->iter);
-	g_return_if_fail (row >= 0);
-	gda_data_proxy_undelete (form->priv->proxy, row);
+	else {
+		gint row;
+		
+		row = gda_data_model_iter_get_row (form->priv->iter);
+		g_return_if_fail (row >= 0);
+		gda_data_proxy_undelete (form->priv->proxy, row);
+	}
 }
 
 static void
diff --git a/libgda-ui/gdaui-raw-grid.c b/libgda-ui/gdaui-raw-grid.c
index 6459f77..77a6860 100644
--- a/libgda-ui/gdaui-raw-grid.c
+++ b/libgda-ui/gdaui-raw-grid.c
@@ -167,8 +167,7 @@ static void     tree_view_row_activated_cb     (GtkTreeView *tree_view, GtkTreeP
 						GtkTreeViewColumn *column, GdauiRawGrid *grid);
 
 static void action_new_cb (GtkAction *action, GdauiRawGrid *grid);
-static void action_delete_cb (GtkAction *action, GdauiRawGrid *grid);
-static void action_undelete_cb (GtkAction *action, GdauiRawGrid *grid);
+static void action_delete_cb (GtkToggleAction *action, GdauiRawGrid *grid);
 static void action_commit_cb (GtkAction *action, GdauiRawGrid *grid);
 static void action_reset_cb (GtkAction *action, GdauiRawGrid *grid);
 static void action_first_chunck_cb (GtkAction *action, GdauiRawGrid *grid);
@@ -177,23 +176,19 @@ static void action_next_chunck_cb (GtkAction *action, GdauiRawGrid *grid);
 static void action_last_chunck_cb (GtkAction *action, GdauiRawGrid *grid);
 static void action_filter_cb (GtkAction *action, GdauiRawGrid *grid);
 
+static GtkToggleActionEntry ui_actions_t[] = {
+	{ "ActionDelete", GTK_STOCK_REMOVE, "_Delete", NULL, N_("Delete the selected entry"), G_CALLBACK (action_delete_cb), FALSE},
+};
+
 static GtkActionEntry ui_actions[] = {
-	{ "ActionNew", GTK_STOCK_ADD, "_New", NULL, "Create a new data entry", G_CALLBACK (action_new_cb)},
-	{ "ActionDelete", GTK_STOCK_REMOVE, "_Delete", NULL, "Delete the selected entry", G_CALLBACK (action_delete_cb)},
-	{ "ActionUndelete", GTK_STOCK_UNDELETE, "_Undelete", NULL, "Cancels the deletion of the selected entry",
-	  G_CALLBACK (action_undelete_cb)},
-	{ "ActionCommit", GTK_STOCK_SAVE, "_Commit", NULL, "Commit the latest changes", G_CALLBACK (action_commit_cb)},
-	{ "ActionReset", GTK_STOCK_REFRESH, "_Reset", NULL, "Reset the data", G_CALLBACK (action_reset_cb)},
-	{ "ActionFirstChunck", GTK_STOCK_GOTO_FIRST, "_First chunck", NULL, "Go to first chunck of records",
-	  G_CALLBACK (action_first_chunck_cb)},
-	{ "ActionLastChunck", GTK_STOCK_GOTO_LAST, "_Last chunck", NULL, "Go to last chunck of records",
-	  G_CALLBACK (action_last_chunck_cb)},
-	{ "ActionPrevChunck", GTK_STOCK_GO_BACK, "_Previous chunck", NULL, "Go to previous chunck of records",
-	  G_CALLBACK (action_prev_chunck_cb)},
-	{ "ActionNextChunck", GTK_STOCK_GO_FORWARD, "Ne_xt chunck", NULL, "Go to next chunck of records",
-	  G_CALLBACK (action_next_chunck_cb)},
-	{ "ActionFilter", GTK_STOCK_FIND, "Filter", NULL, "Filter records",
-	  G_CALLBACK (action_filter_cb)}
+	{ "ActionNew", GTK_STOCK_ADD, "_New", NULL, N_("Create a new data entry"), G_CALLBACK (action_new_cb)},
+	{ "ActionCommit", GTK_STOCK_SAVE, "_Commit", NULL, N_("Commit the latest changes"), G_CALLBACK (action_commit_cb)},
+	{ "ActionReset", GTK_STOCK_CLEAR, "_Clear", NULL, N_("Clear all the modifications"), G_CALLBACK (action_reset_cb)},
+	{ "ActionFirstChunck", GTK_STOCK_GOTO_FIRST, "_First chunck", NULL, N_("Go to first chunck of records"), G_CALLBACK (action_first_chunck_cb)},
+	{ "ActionLastChunck", GTK_STOCK_GOTO_LAST, "_Last chunck", NULL, N_("Go to last chunck of records"), G_CALLBACK (action_last_chunck_cb)},
+	{ "ActionPrevChunck", GTK_STOCK_GO_BACK, "_Previous chunck", NULL, N_("Go to previous chunck of records"), G_CALLBACK (action_prev_chunck_cb)},
+	{ "ActionNextChunck", GTK_STOCK_GO_FORWARD, "Ne_xt chunck", NULL, N_("Go to next chunck of records"), G_CALLBACK (action_next_chunck_cb)},
+	{ "ActionFilter", GTK_STOCK_FIND, "Filter", NULL, N_("Filter records"), G_CALLBACK (action_filter_cb)}
 };
 
 GType
@@ -404,6 +399,7 @@ gdaui_raw_grid_init (GdauiRawGrid *grid)
 	grid->priv->actions_group = gtk_action_group_new ("Actions");
 	gtk_action_group_set_translation_domain (grid->priv->actions_group, GETTEXT_PACKAGE);
 	gtk_action_group_add_actions (grid->priv->actions_group, ui_actions, G_N_ELEMENTS (ui_actions), grid);
+	gtk_action_group_add_toggle_actions (grid->priv->actions_group, ui_actions_t, G_N_ELEMENTS (ui_actions_t), grid);
 
 	grid->priv->filter = NULL;
 	grid->priv->filter_window = NULL;
@@ -1381,53 +1377,52 @@ action_new_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawGrid *grid)
 }
 
 static void
-action_delete_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawGrid *grid)
+action_delete_cb (GtkToggleAction *action, GdauiRawGrid *grid)
 {
-	GtkTreeIter iter;
-	GtkTreeSelection *select;
-	GtkTreeModel *model;
-	GList *sel_rows;
-	GdaDataProxy *proxy;
-
-	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (grid));
-	sel_rows = gtk_tree_selection_get_selected_rows (select, &model);
-	proxy = gdaui_data_store_get_proxy (GDAUI_DATA_STORE (model));
-
-	/* rem: get the list of selected rows after each row deletion because the data model might have changed and
-	 * row numbers might also have changed */
-	while (sel_rows) {
-		gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) (sel_rows->data));
-		if (!gda_data_proxy_row_is_deleted (proxy,
-						    gdaui_data_store_get_row_from_iter (GDAUI_DATA_STORE (model),
-											&iter))) {
-			gdaui_data_store_delete (grid->priv->store, &iter);
-			g_list_foreach (sel_rows, (GFunc) gtk_tree_path_free, NULL);
-			g_list_free (sel_rows);
-			sel_rows = gtk_tree_selection_get_selected_rows (select, &model);
+	if (gtk_toggle_action_get_active (action)) {
+		GtkTreeIter iter;
+		GtkTreeSelection *select;
+		GtkTreeModel *model;
+		GList *sel_rows;
+		GdaDataProxy *proxy;
+		
+		select = gtk_tree_view_get_selection (GTK_TREE_VIEW (grid));
+		sel_rows = gtk_tree_selection_get_selected_rows (select, &model);
+		proxy = gdaui_data_store_get_proxy (GDAUI_DATA_STORE (model));
+		
+		/* rem: get the list of selected rows after each row deletion because the data model might have changed and
+		 * row numbers might also have changed */
+		while (sel_rows) {
+			gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) (sel_rows->data));
+			if (!gda_data_proxy_row_is_deleted (proxy,
+							    gdaui_data_store_get_row_from_iter (GDAUI_DATA_STORE (model),
+												&iter))) {
+				gdaui_data_store_delete (grid->priv->store, &iter);
+				g_list_foreach (sel_rows, (GFunc) gtk_tree_path_free, NULL);
+				g_list_free (sel_rows);
+				sel_rows = gtk_tree_selection_get_selected_rows (select, &model);
+			}
+			else
+				sel_rows = sel_rows->next;
 		}
-		else
-			sel_rows = sel_rows->next;
 	}
-}
-
-static void
-action_undelete_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawGrid *grid)
-{
-	GtkTreeIter iter;
-	GtkTreeSelection *select;
-	GtkTreeModel *model;
-	GList *sel_rows, *cur_row;
-
-	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (grid));
-	sel_rows = gtk_tree_selection_get_selected_rows (select, &model);
-	cur_row = sel_rows;
-	while (cur_row) {
-		gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) (cur_row->data));
-		gdaui_data_store_undelete (grid->priv->store, &iter);
-		cur_row = g_list_next (cur_row);
+	else {
+		GtkTreeIter iter;
+		GtkTreeSelection *select;
+		GtkTreeModel *model;
+		GList *sel_rows, *cur_row;
+		
+		select = gtk_tree_view_get_selection (GTK_TREE_VIEW (grid));
+		sel_rows = gtk_tree_selection_get_selected_rows (select, &model);
+		cur_row = sel_rows;
+		while (cur_row) {
+			gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) (cur_row->data));
+			gdaui_data_store_undelete (grid->priv->store, &iter);
+			cur_row = g_list_next (cur_row);
+		}
+		g_list_foreach (sel_rows, (GFunc) gtk_tree_path_free, NULL);
+		g_list_free (sel_rows);
 	}
-	g_list_foreach (sel_rows, (GFunc) gtk_tree_path_free, NULL);
-	g_list_free (sel_rows);
 }
 
 static void



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