[libgda/LIBGDA_4.2] Don't allow the user to hide columns explicitely hidden by the programmer



commit 6cf669ab728470fb4bf2222c4c9acda14f2214b3
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Mar 20 16:38:32 2011 +0100

    Don't allow the user to hide columns explicitely hidden by the programmer

 libgda-ui/demos/basic_form.c |    4 ++-
 libgda-ui/demos/grid.c       |    1 +
 libgda-ui/gdaui-basic-form.c |    9 ++++--
 libgda-ui/gdaui-raw-grid.c   |   58 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 58 insertions(+), 14 deletions(-)
---
diff --git a/libgda-ui/demos/basic_form.c b/libgda-ui/demos/basic_form.c
index eae99cd..f17ab70 100644
--- a/libgda-ui/demos/basic_form.c
+++ b/libgda-ui/demos/basic_form.c
@@ -42,7 +42,8 @@ do_basic_form (GtkWidget *do_widget)
 				       "same GdaSet. When a value is modified in one form, then it is\n"
 				       "automatically updated in the other form.\n\n"
 				       "Also the top form uses the default layout, while the bottom one\n"
-				       "uses a custom (2 columns) layout.");
+				       "uses a custom (2 columns) layout.\n"
+				       "The 'an int' entry is hidden in the top form.");
 		gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
 		
 		/* Create the demo widget */
@@ -54,6 +55,7 @@ do_basic_form (GtkWidget *do_widget)
 					  "a picture", GDA_TYPE_BINARY, NULL);
 		form = gdaui_basic_form_new (set);
 		gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
+		gdaui_basic_form_entry_set_visible (GDAUI_BASIC_FORM (form), gda_set_get_holder (set, "an int"), FALSE);
 
 		label = gtk_label_new ("2nd form is below:");
 		gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
diff --git a/libgda-ui/demos/grid.c b/libgda-ui/demos/grid.c
index 69fe21f..606a626 100644
--- a/libgda-ui/demos/grid.c
+++ b/libgda-ui/demos/grid.c
@@ -54,6 +54,7 @@ do_grid (GtkWidget *do_widget)
 		gdaui_grid_set_sample_size (GDAUI_GRID (grid), 100);
 		g_object_set (G_OBJECT (grid), "info-flags",
 			      GDAUI_DATA_PROXY_INFO_CURRENT_ROW | GDAUI_DATA_PROXY_INFO_CHUNCK_CHANGE_BUTTONS, NULL);
+		gdaui_data_selector_set_column_visible (GDAUI_DATA_SELECTOR (grid), 1, FALSE);
 
 		gtk_box_pack_start (GTK_BOX (vbox), grid, TRUE, TRUE, 0);
 	}
diff --git a/libgda-ui/gdaui-basic-form.c b/libgda-ui/gdaui-basic-form.c
index 5a17ec2..c385d5e 100644
--- a/libgda-ui/gdaui-basic-form.c
+++ b/libgda-ui/gdaui-basic-form.c
@@ -1,5 +1,4 @@
-/* gdaui-basic-form.c
- *
+/*
  * Copyright (C) 2002 - 2011 Vivien Malerba <malerba gnome-db org>
  *
  * This Library is free software; you can redistribute it and/or
@@ -66,7 +65,8 @@ typedef struct {
 	GdauiDataEntry *entry; /* ref held here */
 	GtkWidget      *label; /* ref held here */
 	gchar          *label_title;
-	gboolean        hidden;
+	gboolean        prog_hidden; /* status as requested by the programmer */
+	gboolean        hidden; /* real status of the data entry */
 	gboolean        not_null; /* TRUE if @entry's contents can't be NULL */
 	gboolean        can_expand; /* tells if @entry can expand */
 	gboolean        forward_param_updates; /* forward them to the GdauiDataEntry widgets ? */
@@ -338,6 +338,8 @@ do_popup_menu (GdauiBasicForm *form, GdkEventButton *event)
 	
 	for (list = form->priv->s_entries; list; list = list->next) {
 		SingleEntry *sentry = (SingleEntry*) list->data;
+		if (sentry->prog_hidden)
+			continue;
 		mitem = gtk_check_menu_item_new_with_label (sentry->label_title);
 		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mitem), !sentry->hidden);
 		gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
@@ -1892,6 +1894,7 @@ gdaui_basic_form_entry_set_visible (GdauiBasicForm *form, GdaHolder *param, gboo
 	}
 
 	real_gdaui_basic_form_entry_set_visible (form, sentry, show);
+	sentry->prog_hidden = !show;
 }
 
 /**
diff --git a/libgda-ui/gdaui-raw-grid.c b/libgda-ui/gdaui-raw-grid.c
index 3f66213..82a1fd7 100644
--- a/libgda-ui/gdaui-raw-grid.c
+++ b/libgda-ui/gdaui-raw-grid.c
@@ -1,5 +1,4 @@
-/* gdaui-raw-grid.c
- *
+/*
  * Copyright (C) 2002 - 2011 Vivien Malerba <malerba gnome-db org>
  *
  * This Library is free software; you can redistribute it and/or
@@ -84,9 +83,10 @@ static void              gdaui_raw_grid_selector_set_column_visible (GdauiDataSe
 typedef struct {
 	GtkCellRenderer   *data_cell;
 	GtkCellRenderer   *info_cell;
-	GtkTreeViewColumn *column;
+	GtkTreeViewColumn *column; /* no ref held */
 
-	gboolean           hidden;
+	gboolean           prog_hidden; /* status as requested by the programmer */
+	gboolean           hidden; /* real status of the column */
 	gchar             *title;
 
 	GdaHolder         *single_param;
@@ -668,7 +668,7 @@ _gdaui_raw_grid_get_selection (GdauiRawGrid *grid)
  * WARNING: the old string is free'ed so it is possible to do "str=double_underscores(str);"
  */
 static gchar *
-replace_double_underscores (gchar *str)
+add_double_underscores (gchar *str)
 {
         gchar **arr;
         gchar *ret;
@@ -681,6 +681,25 @@ replace_double_underscores (gchar *str)
         return ret;
 }
 
+/*
+ * Creates a NEW string
+ */
+static gchar *
+remove_double_underscores (gchar *str)
+{
+        gchar *ptr1, *ptr2, *ret;
+
+	ret = g_new (gchar, strlen (str) + 1);
+	for (ptr1 = str, ptr2 = ret; *ptr1; ptr1++, ptr2++) {
+		*ptr2 = *ptr1;
+		if ((ptr1[0] == '_') && (ptr1[1] == '_'))
+			ptr1++;
+	}
+	*ptr2 = 0;
+
+        return ret;
+}
+
 static void     cell_value_set_attributes (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
 					   GtkTreeModel *tree_model, GtkTreeIter *iter, GdauiRawGrid *grid);
 static void     cell_info_set_attributes  (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
@@ -751,7 +770,7 @@ create_columns_data (GdauiRawGrid *grid)
 								     "name");
 
 			if (title)
-				title = replace_double_underscores (g_strdup (title));
+				title = add_double_underscores (g_strdup (title));
 			else
 				/* FIXME: find a better label */
 				title = g_strdup (_("Value"));
@@ -784,7 +803,7 @@ create_columns_data (GdauiRawGrid *grid)
 
 			g_object_get (G_OBJECT (param), "name", &title, NULL);
 			if (title && *title)
-				title = replace_double_underscores (title);
+				title = add_double_underscores (title);
 			else
 				title = NULL;
 			if (!title)
@@ -829,6 +848,13 @@ create_columns_data (GdauiRawGrid *grid)
 	}
 }
 
+/* keep track of the columns shown and hidden */
+static void
+column_visibility_changed (GtkTreeViewColumn *column, GParamSpec *pspec, ColumnData *cdata)
+{
+	cdata->hidden = !gtk_tree_view_column_get_visible (column);
+}
+
 /*
  * Remove all columns from @grid, does not modify ColumnData
  */
@@ -868,6 +894,9 @@ create_tree_view_column (GdauiRawGrid *grid, ColumnData *cdata, gint pos)
 						 (GtkTreeCellDataFunc) cell_info_set_attributes,
 						 grid, NULL);
 	
+	g_signal_connect (column, "notify::visible",
+			  G_CALLBACK (column_visibility_changed), cdata);
+
 	/* Sorting data */
 	gtk_tree_view_column_set_clickable (column, TRUE);
 	g_signal_connect (G_OBJECT (column), "clicked",
@@ -882,7 +911,7 @@ reset_columns_default (GdauiRawGrid *grid)
 	remove_all_columns (grid);
 	for (list = grid->priv->columns_data; list; list = list->next) {
 		ColumnData *cdata = COLUMN_DATA (list->data);
-		if (cdata->hidden)
+		if (cdata->prog_hidden)
 			continue;
 
 		/* create treeview column */
@@ -918,6 +947,7 @@ reset_columns_in_xml_layout (GdauiRawGrid *grid, xmlNodePtr grid_node)
 			xmlFree (name);
 
 			/* create treeview column */
+			cdata->prog_hidden = FALSE;
 			cdata->hidden = FALSE;
 			create_tree_view_column (grid, cdata, -1);
 
@@ -1758,7 +1788,6 @@ hidden_column_mitem_toggled_cb (GtkCheckMenuItem *check, GdauiRawGrid *grid)
 	g_assert (cdata);
 	act = gtk_check_menu_item_get_active (check);
 	gtk_tree_view_column_set_visible (cdata->column, act);
-	cdata->hidden = !act;
 }
 
 static gint
@@ -1789,8 +1818,13 @@ tree_view_popup_button_pressed_cb (G_GNUC_UNUSED GtkWidget *widget, GdkEventButt
 	gtk_menu_item_set_submenu (GTK_MENU_ITEM (mitem), submenu);
 	for (list = grid->priv->columns_data; list; list = list->next) {
 		ColumnData *cdata = (ColumnData*) list->data;
+		gchar *tmp;
 
-		mitem = gtk_check_menu_item_new_with_label (cdata->title);
+		if (cdata->prog_hidden)
+			continue;
+		tmp = remove_double_underscores (cdata->title);
+		mitem = gtk_check_menu_item_new_with_label (tmp);
+		g_free (tmp);
 		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mitem), !cdata->hidden);
 		gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
 		gtk_widget_show (mitem);
@@ -3019,4 +3053,8 @@ gdaui_raw_grid_selector_set_column_visible (GdauiDataSelector *iface, gint colum
 
 	/* Sets the column's visibility */
 	gtk_tree_view_column_set_visible (viewcol, visible);
+	ColumnData *cdata;
+	cdata = g_slist_nth_data (grid->priv->columns_data, column);
+	g_assert (cdata);
+	cdata->prog_hidden = !visible;
 }



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