glade3 r1999 - in trunk: . gladeui plugins/gtk+



Author: tvb
Date: Sat Oct 25 16:37:55 2008
New Revision: 1999
URL: http://svn.gnome.org/viewvc/glade3?rev=1999&view=rev

Log:

	* plugins/gtk+/glade-cell-renderer-button.c: Fixed a warning.

	* plugins/gtk+/glade-column-types.c, plugins/gtk+/glade-model-data.c,
	plugins/gtk+/glade-icon-sources.c: Made sure add/remove works when
	deleting unedited icon sources, all add buttons result in focus and
	start-editing of an important cell in the underlying treeview.

	* gladeui/glade-utils.c: Fixed generic enum types to use enum_class->minimum
	as the default value.



Modified:
   trunk/ChangeLog
   trunk/gladeui/glade-utils.c
   trunk/plugins/gtk+/glade-cell-renderer-button.c
   trunk/plugins/gtk+/glade-column-types.c
   trunk/plugins/gtk+/glade-icon-sources.c
   trunk/plugins/gtk+/glade-model-data.c

Modified: trunk/gladeui/glade-utils.c
==============================================================================
--- trunk/gladeui/glade-utils.c	(original)
+++ trunk/gladeui/glade-utils.c	Sat Oct 25 16:37:55 2008
@@ -2127,8 +2127,12 @@
 			pspec = g_param_spec_object ("dummy", "dummy", "dummy",
 						     type, G_PARAM_READABLE|G_PARAM_WRITABLE);
 		else if (G_TYPE_IS_ENUM (type))
+		{
+			GEnumClass *eclass = g_type_class_ref (type);
 			pspec = g_param_spec_enum ("dummy", "dummy", "dummy",
-						   type, 0, G_PARAM_READABLE|G_PARAM_WRITABLE);
+						   type, eclass->minimum, G_PARAM_READABLE|G_PARAM_WRITABLE);
+			g_type_class_unref (eclass);
+		}
 		else if (G_TYPE_IS_FLAGS (type))
 			pspec = g_param_spec_flags ("dummy", "dummy", "dummy",
 						    type, 0, G_PARAM_READABLE|G_PARAM_WRITABLE);

Modified: trunk/plugins/gtk+/glade-cell-renderer-button.c
==============================================================================
--- trunk/plugins/gtk+/glade-cell-renderer-button.c	(original)
+++ trunk/plugins/gtk+/glade-cell-renderer-button.c	Sat Oct 25 16:37:55 2008
@@ -239,7 +239,7 @@
 		return NULL;
 
 	text_button = (GladeTextButton *)glade_text_button_new ();
-	gtk_entry_set_text (GTK_ENTRY (text_button->entry), cell_text->text);
+	gtk_entry_set_text (GTK_ENTRY (text_button->entry), cell_text->text ? cell_text->text : "");
 	gtk_entry_set_editable (GTK_ENTRY (text_button->entry), priv->entry_editable);
 
 	g_object_set (text_button->entry,

Modified: trunk/plugins/gtk+/glade-column-types.c
==============================================================================
--- trunk/plugins/gtk+/glade-column-types.c	(original)
+++ trunk/plugins/gtk+/glade-column-types.c	Sat Oct 25 16:37:55 2008
@@ -274,11 +274,15 @@
 {
 	GladeEditorProperty parent_instance;
 
-	GtkComboBox *combo;
-	GtkListStore *store;
+	GtkComboBox      *combo;
+	GtkListStore     *store;
+	GtkTreeView      *view;
 	GtkTreeSelection *selection;
 
 	GladeNameContext *context;
+
+	gboolean          adding_column;
+	GtkTreeViewColumn *name_column;
 } GladeEPropColumnTypes;
 
 GLADE_MAKE_EPROP (GladeEPropColumnTypes, glade_eprop_column_types)
@@ -382,7 +386,7 @@
 
 	columns = g_list_append (columns, data);
 
-
+	eprop_types->adding_column = TRUE;
 	glade_command_push_group (_("Setting columns on %s"), 
 				  glade_widget_get_name (eprop->property->widget));
 
@@ -394,6 +398,8 @@
 	g_value_unset (&value);
 
 	glade_command_pop_group ();
+
+	eprop_types->adding_column = FALSE;
 }
 
 static void
@@ -538,6 +544,37 @@
 					   -1);
 }
 
+static gboolean
+eprop_types_focus_idle (GladeEPropColumnTypes *eprop_types)
+{
+	/* Focus and edit the first column of a newly added row */
+	if (eprop_types->store)
+	{
+		GtkTreePath *new_item_path;
+		GtkTreeIter  iter, *last_iter = NULL;
+
+		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_types->store), &iter))
+		{
+			do {
+				if (last_iter)
+					gtk_tree_iter_free (last_iter);
+				last_iter = gtk_tree_iter_copy (&iter);
+			} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_types->store), &iter));
+
+			new_item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_types->store), last_iter);
+
+			gtk_widget_grab_focus (GTK_WIDGET (eprop_types->view));
+			gtk_tree_view_expand_to_path (eprop_types->view, new_item_path);
+			gtk_tree_view_set_cursor (eprop_types->view, new_item_path,
+						  eprop_types->name_column, TRUE);
+			
+			gtk_tree_path_free (new_item_path);
+			gtk_tree_iter_free (last_iter);
+		}
+	}
+	return FALSE;
+}
+
 static void
 glade_eprop_column_types_load (GladeEditorProperty *eprop, GladeProperty *property)
 {
@@ -573,6 +610,9 @@
 		glade_name_context_add_name (eprop_types->context, data->column_name);
 	}
 
+	if (eprop_types->adding_column && list)
+		g_idle_add ((GSourceFunc)eprop_types_focus_idle, eprop);
+
 	g_signal_handlers_unblock_by_func (G_OBJECT (eprop_types->store), 
 					   eprop_treeview_row_deleted, eprop);
 }
@@ -649,7 +689,7 @@
 glade_eprop_column_types_create_input (GladeEditorProperty *eprop)
 {
 	GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop);
-	GtkWidget *vbox, *hbox, *button, *swin, *treeview, *label;
+	GtkWidget *vbox, *hbox, *button, *swin, *label;
 	GtkCellRenderer *cell;
 	GtkTreeViewColumn *col;
 	gchar *string;
@@ -710,11 +750,11 @@
 			  G_CALLBACK (eprop_treeview_row_deleted),
 			  eprop);
 	
-	treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (eprop_types->store));
-	eprop_types->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+	eprop_types->view = (GtkTreeView *)gtk_tree_view_new_with_model (GTK_TREE_MODEL (eprop_types->store));
+	eprop_types->selection = gtk_tree_view_get_selection (eprop_types->view);
 
 	
-	gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
+	gtk_tree_view_set_reorderable (eprop_types->view, TRUE);
 	//gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
 
 	/* type column */
@@ -722,7 +762,7 @@
 							gtk_cell_renderer_text_new (),
 							"text", COLUMN_NAME,
 							NULL);
-	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), col);	
+	gtk_tree_view_append_column (eprop_types->view, col);	
 
 
 	/* name column */
@@ -732,12 +772,13 @@
 	g_signal_connect (G_OBJECT (cell), "edited",
 			  G_CALLBACK (column_name_edited), eprop);
 	
-	col = gtk_tree_view_column_new_with_attributes ("Column name", 
-							cell,
-							"text", COLUMN_COLUMN_NAME,
-							NULL);
-	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), col);	
-	gtk_container_add (GTK_CONTAINER (swin), treeview);
+	eprop_types->name_column = 
+		gtk_tree_view_column_new_with_attributes ("Column name", 
+							  cell,
+							  "text", COLUMN_COLUMN_NAME,
+							  NULL);
+	gtk_tree_view_append_column (eprop_types->view, eprop_types->name_column);	
+	gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_types->view));
 	
 	g_object_set (G_OBJECT (vbox), "height-request", 200, NULL);
 

Modified: trunk/plugins/gtk+/glade-icon-sources.c
==============================================================================
--- trunk/plugins/gtk+/glade-icon-sources.c	(original)
+++ trunk/plugins/gtk+/glade-icon-sources.c	Sat Oct 25 16:37:55 2008
@@ -351,6 +351,7 @@
 	GtkTreePath *new_item_path;
 	gchar       *icon_name;
 	gchar       *selected_icon_name;
+	gint         index;
 
 	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (eprop_sources->combo), &iter))
 		gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->icon_names_store), &iter,
@@ -377,6 +378,23 @@
 			 gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_sources->store), &iter));
 	}
 
+	/* check if we're already adding one here... */
+	if (parent_iter &&
+	    gtk_tree_model_iter_children (GTK_TREE_MODEL (eprop_sources->store), &iter, parent_iter))
+	{
+		do {
+			gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
+					    COLUMN_LIST_INDEX, &index,
+					    -1);
+			
+			/* Iter is set, expand and return. */
+			if (index < 0)
+				goto expand_to_path_and_focus;
+
+		} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_sources->store), &iter));
+	}
+
+
 	if (!parent_iter)
 	{
 		/* Dont set COLUMN_ICON_NAME here */
@@ -397,6 +415,8 @@
 			    COLUMN_LIST_INDEX, -1,
 			    -1);
 
+	/* By now iter is valid. */
+ expand_to_path_and_focus:
 	new_item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store), &iter);
 
 	gtk_widget_grab_focus (GTK_WIDGET (eprop_sources->view));
@@ -459,6 +479,15 @@
 			    COLUMN_LIST_INDEX, &index,
 			    -1);
 
+	/* Could be the user pressed add and then delete without touching the
+	 * new item.
+	 */
+	if (index < 0)
+	{
+		g_idle_add ((GSourceFunc)reload_icon_sources_idle, eprop);
+		return;
+	}
+
 	glade_property_get (eprop->property, &icon_sources);
 	if (icon_sources)
 	{

Modified: trunk/plugins/gtk+/glade-model-data.c
==============================================================================
--- trunk/plugins/gtk+/glade-model-data.c	(original)
+++ trunk/plugins/gtk+/glade-model-data.c	Sat Oct 25 16:37:55 2008
@@ -315,6 +315,10 @@
 	GtkListStore *store;
 	GtkTreeSelection *selection;
 	GNode *pending_data_tree;
+
+	/* Used for setting focus on newly added rows */
+	gboolean             adding_row;
+	GtkTreeViewColumn   *first_column;
 } GladeEPropModelData;
 
 GLADE_MAKE_EPROP (GladeEPropModelData, glade_eprop_model_data)
@@ -382,6 +386,7 @@
 glade_eprop_model_data_add_clicked (GtkWidget *button, 
 				    GladeEditorProperty *eprop)
 {
+	GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
 	GValue value = { 0, };
 	GNode *node = NULL;
 	GList *columns = NULL;
@@ -401,11 +406,14 @@
 
 	append_row (node, columns);
 
+	eprop_data->adding_row = TRUE;
+
 	g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE);
 	g_value_take_boxed (&value, node);
 	glade_editor_property_commit (eprop, &value);
 	g_value_unset (&value);
 
+	eprop_data->adding_row = FALSE;
 }
 
 /* User pressed delete: remove selected row and commit values  */
@@ -849,6 +857,8 @@
 	if (!data_tree || !data_tree->children || !data_tree->children->children)
 		return;
 
+	eprop_data->first_column = NULL;
+
 	/* Append new columns */
 	for (colnum = 0, iter_node = data_tree->children->children; iter_node; 
 	     colnum++, iter_node = iter_node->next)
@@ -857,7 +867,41 @@
 
 		column = eprop_model_generate_column (eprop, colnum, iter_data);
 		gtk_tree_view_append_column (eprop_data->view, column);
+
+		if (!eprop_data->first_column)
+			eprop_data->first_column = column;
+	}
+}
+
+static gboolean
+eprop_data_focus_idle (GladeEPropModelData *eprop_data)
+{
+	/* Focus and edit the first column of a newly added row */
+	if (eprop_data->store && eprop_data->first_column)
+	{
+		GtkTreePath *new_item_path;
+		GtkTreeIter  iter, *last_iter = NULL;
+
+		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_data->store), &iter))
+		{
+			do {
+				if (last_iter)
+					gtk_tree_iter_free (last_iter);
+				last_iter = gtk_tree_iter_copy (&iter);
+			} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_data->store), &iter));
+
+			new_item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_data->store), last_iter);
+
+			gtk_widget_grab_focus (GTK_WIDGET (eprop_data->view));
+			gtk_tree_view_expand_to_path (eprop_data->view, new_item_path);
+			gtk_tree_view_set_cursor (eprop_data->view, new_item_path,
+						  eprop_data->first_column, TRUE);
+			
+			gtk_tree_path_free (new_item_path);
+			gtk_tree_iter_free (last_iter);
+		}
 	}
+	return FALSE;
 }
 
 static void
@@ -892,6 +936,9 @@
 
 	/* Create new columns with renderers */
 	eprop_model_data_generate_columns (eprop);
+
+	if (eprop_data->adding_row && eprop_data->store && eprop_data->first_column)
+		g_idle_add ((GSourceFunc)eprop_data_focus_idle, eprop_data);
 }
 
 static GtkWidget *



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