glade3 r1808 - in trunk: . plugins/gtk+



Author: tvb
Date: Fri May  2 02:27:10 2008
New Revision: 1808
URL: http://svn.gnome.org/viewvc/glade3?rev=1808&view=rev

Log:

	* plugins/gtk+/glade-keys.c: Removed.

	* plugins/gtk+/glade-accels.c: Removed old modifier and handbuilt keycode
	  menus and obnoxious comboboxrenderers in favour of one simple accelrenderer.



Modified:
   trunk/ChangeLog
   trunk/plugins/gtk+/glade-accels.c

Modified: trunk/plugins/gtk+/glade-accels.c
==============================================================================
--- trunk/plugins/gtk+/glade-accels.c	(original)
+++ trunk/plugins/gtk+/glade-accels.c	Fri May  2 02:27:10 2008
@@ -93,20 +93,6 @@
 	return type_id;
 }
 
-gboolean
-glade_keyval_valid (guint val)
-{
-	gint i;
-
-	for (i = 0; GladeKeys[i].name != NULL; i++)
-	{
-		if (GladeKeys[i].value == val)
-			return TRUE;
-	}
-	return FALSE;
-}
-
-
 static void
 param_accel_init (GParamSpec *pspec)
 {
@@ -139,9 +125,7 @@
 	{
 		info = list->data;
 		
-		/* Is it an invalid key ? */
-		if (glade_keyval_valid (info->key) == FALSE ||
-		    /* Does the modifier contain any unwanted bits ? */
+		if (/* Does the modifier contain any unwanted bits ? */
 		    info->modifiers & GDK_MODIFIER_MASK ||
 		    /* Do we have a signal ? */
 		    /* FIXME: Check if the signal is valid for 'type' */
@@ -223,32 +207,6 @@
 				       G_PARAM_READWRITE);
 }
 
-guint
-glade_key_from_string (const gchar *string)
-{
-	gint i;
-
-	g_return_val_if_fail (string != NULL, 0);
-
-	for (i = 0; GladeKeys[i].name != NULL; i++)
-		if (!strcmp (string, GladeKeys[i].name))
-			return GladeKeys[i].value;
-
-	return 0;
-}
-
-const gchar *
-glade_string_from_key (guint key)
-{
-	gint i;
-
-	for (i = 0; GladeKeys[i].name != NULL; i++)
-		if (GladeKeys[i].value == key)
-			return GladeKeys[i].name;
-	return NULL;
-}
-
-
 /* This is not used to save in the glade file... and its a one-way conversion.
  * its only usefull to show the values in the UI.
  */
@@ -258,23 +216,17 @@
 	GladeAccelInfo *info;
 	GString        *string;
 	GList          *list;
+	gchar          *accel_text;
 
 	string = g_string_new ("");
 
 	for (list = accels; list; list = list->next)
 	{
 		info = list->data;
-		
-		if (info->modifiers & GDK_SHIFT_MASK)
-			g_string_append (string, "SHIFT-");
-
-		if (info->modifiers & GDK_CONTROL_MASK)
-			g_string_append (string, "CNTL-");
 
-		if (info->modifiers & GDK_MOD1_MASK)
-			g_string_append (string, "ALT-");
-
-		g_string_append (string, glade_string_from_key (info->key));
+		accel_text = gtk_accelerator_name (info->key, info->modifiers);
+		g_string_append (string, accel_text);
+		g_free (accel_text);
 
 		if (list->next)
 			g_string_append (string, ", ");
@@ -291,22 +243,16 @@
 enum {
 	ACCEL_COLUMN_SIGNAL = 0,
 	ACCEL_COLUMN_REAL_SIGNAL,
-	ACCEL_COLUMN_KEY,
-	ACCEL_COLUMN_MOD_SHIFT,
-	ACCEL_COLUMN_MOD_CNTL,
-	ACCEL_COLUMN_MOD_ALT,
+	ACCEL_COLUMN_TEXT,
 	ACCEL_COLUMN_IS_CLASS,
 	ACCEL_COLUMN_IS_SIGNAL,
 	ACCEL_COLUMN_KEY_ENTERED,
 	ACCEL_COLUMN_KEY_SLOT,
+	ACCEL_COLUMN_KEYCODE,
+	ACCEL_COLUMN_MODIFIERS,
 	ACCEL_NUM_COLUMNS
 };
 
-enum {
-	ACCEL_COMBO_COLUMN_TEXT = 0,
-	ACCEL_COMBO_NUM_COLUMNS,
-};
-
 typedef struct {
 	GladeEditorProperty parent_instance;
 	
@@ -320,9 +266,6 @@
 	gchar       *name; /* <-- dont free */
 } GladeEpropIterTab;
 
-
-static GtkTreeModel *keysyms_model   = NULL;
-
 GLADE_MAKE_EPROP (GladeEPropAccel, glade_eprop_accel)
 #define GLADE_EPROP_ACCEL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccel))
 #define GLADE_EPROP_ACCEL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccelClass))
@@ -330,65 +273,6 @@
 #define GLADE_IS_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ACCEL))
 #define GLADE_EPROP_ACCEL_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ACCEL, GladeEPropAccelClass))
 
-
-static GtkTreeModel *
-create_keysyms_model (void)
-{
-	GtkTreeModel *model;
-	GtkTreeIter   iter, alphanum, fkey, keypad, other, extra;
-	GtkTreeIter  *parent;
-	gint          i;
-
-	model = (GtkTreeModel *)gtk_tree_store_new
-		(ACCEL_COMBO_NUM_COLUMNS,
-		 G_TYPE_STRING);       /* The Key charachter name */
-
-	gtk_tree_store_append (GTK_TREE_STORE (model), &alphanum, NULL);
-	gtk_tree_store_set    
-		(GTK_TREE_STORE (model), &alphanum, 
-		 ACCEL_COMBO_COLUMN_TEXT, _("Alphanumerical"), -1);
-
-	gtk_tree_store_append (GTK_TREE_STORE (model), &extra, NULL);
-	gtk_tree_store_set    
-		(GTK_TREE_STORE (model), &extra, 
-		 ACCEL_COMBO_COLUMN_TEXT, _("Extra"), -1);
-
-	gtk_tree_store_append (GTK_TREE_STORE (model), &keypad, NULL);
-	gtk_tree_store_set    
-		(GTK_TREE_STORE (model), &keypad, 
-		 ACCEL_COMBO_COLUMN_TEXT, _("Keypad"), -1);
-
-	gtk_tree_store_append (GTK_TREE_STORE (model), &fkey, NULL);
-	gtk_tree_store_set    
-		(GTK_TREE_STORE (model), &fkey, 
-		 ACCEL_COMBO_COLUMN_TEXT, _("Functions"), -1);
-	
-	gtk_tree_store_append (GTK_TREE_STORE (model), &other, NULL);
-	gtk_tree_store_set    
-		(GTK_TREE_STORE (model), &other, 
-		 ACCEL_COMBO_COLUMN_TEXT, _("Other"), -1);
-
-	parent = &alphanum;
-
-	for (i = 0; GladeKeys[i].name != NULL; i++)
-	{
-		gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
-		gtk_tree_store_set    
-			(GTK_TREE_STORE (model), &iter, 
-			 ACCEL_COMBO_COLUMN_TEXT, GladeKeys[i].name, -1);
-
-		if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_ALPHANUM))
-			parent = &extra;
-		else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_EXTRA))
-			parent = &keypad;
-		else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_KP))
-			parent = &fkey;
-		else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_FKEY))
-			parent = &other;
-	}
-	return model;
-}
-
 static void
 glade_eprop_accel_finalize (GObject *object)
 {
@@ -449,7 +333,7 @@
 	GladeEpropIterTab  *parent_tab;
 	GladeAccelInfo     *info;
 	GList              *list, *l, *found, *accelerators;
-	gchar              *name;
+	gchar              *name, *accel_text;
 
 	accelerators = g_value_get_boxed (eprop->property->value);
 
@@ -510,24 +394,23 @@
 				if (strcmp (info->signal, sclass->name))
 					continue;
 
+				accel_text = gtk_accelerator_name (info->key, info->modifiers);
+
 				gtk_tree_store_append (model, &iter, parent_tab->iter);
 				gtk_tree_store_set    
 					(model, &iter,
 					 ACCEL_COLUMN_SIGNAL, name,
 					 ACCEL_COLUMN_REAL_SIGNAL, sclass->name,
+					 ACCEL_COLUMN_TEXT, accel_text,
 					 ACCEL_COLUMN_IS_CLASS, FALSE,
 					 ACCEL_COLUMN_IS_SIGNAL, TRUE,
-					 ACCEL_COLUMN_MOD_SHIFT, 
-					 (info->modifiers & GDK_SHIFT_MASK) != 0,
-					 ACCEL_COLUMN_MOD_CNTL, 
-					 (info->modifiers & GDK_CONTROL_MASK) != 0,
-					 ACCEL_COLUMN_MOD_ALT,
-					 (info->modifiers & GDK_MOD1_MASK) != 0,
-					 ACCEL_COLUMN_KEY, 
-					 glade_string_from_key (info->key),
+					 ACCEL_COLUMN_KEYCODE, info->key,
+					 ACCEL_COLUMN_MODIFIERS, info->modifiers,
 					 ACCEL_COLUMN_KEY_ENTERED, TRUE,
 					 ACCEL_COLUMN_KEY_SLOT, FALSE,
 					 -1);
+
+				g_free (accel_text);
 			}
 
 			/* Append a new empty slot at the end */
@@ -536,12 +419,11 @@
 				(model, &iter,
 				 ACCEL_COLUMN_SIGNAL, name,
 				 ACCEL_COLUMN_REAL_SIGNAL, sclass->name,
+				 ACCEL_COLUMN_TEXT, _("<choose a key>"),
 				 ACCEL_COLUMN_IS_CLASS, FALSE,
 				 ACCEL_COLUMN_IS_SIGNAL, TRUE,
-				 ACCEL_COLUMN_MOD_SHIFT, FALSE,
-				 ACCEL_COLUMN_MOD_CNTL, FALSE,
-				 ACCEL_COLUMN_MOD_ALT, FALSE,
-				 ACCEL_COLUMN_KEY, _("<choose a key>"),
+				 ACCEL_COLUMN_KEYCODE, 0,
+				 ACCEL_COLUMN_MODIFIERS, 0,
 				 ACCEL_COLUMN_KEY_ENTERED, FALSE,
 				 ACCEL_COLUMN_KEY_SLOT, TRUE,
 				 -1);
@@ -551,16 +433,17 @@
 	}
 }
 
-static void
-key_edited (GtkCellRendererText *cell,
-	    const gchar         *path_string,
-	    const gchar         *new_text,
-	    GladeEditorProperty *eprop)
+void
+accel_edited (GtkCellRendererAccel *accel,
+	      gchar                *path_string,
+	      guint                 accel_key,
+	      GdkModifierType       accel_mods,
+	      guint                 hardware_keycode,
+	      GladeEPropAccel      *eprop_accel)
 {
-	GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
 	gboolean         key_was_set;
-	const gchar     *text;
 	GtkTreeIter      iter, parent_iter, new_iter;
+	gchar           *accel_text;
 
 	if (!gtk_tree_model_get_iter_from_string (eprop_accel->model,
 						  &iter, path_string))
@@ -570,32 +453,19 @@
 			    ACCEL_COLUMN_KEY_ENTERED, &key_was_set,
 			    -1);
 
-	/* If user selects "none"; remove old entry or ignore new one.
-	 */
-	if (!new_text || new_text[0] == '\0' ||
-	    glade_string_from_key ((guint)new_text[0]) == NULL ||
-	    g_utf8_collate (new_text, _("None")) == 0 ||
-	    g_utf8_collate (new_text, _("<choose a key>")) == 0)
-	{
-		if (key_was_set)
-			gtk_tree_store_remove
-				(GTK_TREE_STORE (eprop_accel->model), &iter);
-
-		return;
-	}
-
-	if (glade_key_from_string (new_text) != 0)
-		text = new_text;
-	else
-		text = glade_string_from_key ((guint)new_text[0]);
+	accel_text = gtk_accelerator_name (accel_key, accel_mods);
 
 	gtk_tree_store_set    
 		(GTK_TREE_STORE (eprop_accel->model), &iter,
-		 ACCEL_COLUMN_KEY, text,
 		 ACCEL_COLUMN_KEY_ENTERED, TRUE,
 		 ACCEL_COLUMN_KEY_SLOT, FALSE,
+		 ACCEL_COLUMN_TEXT, accel_text,
+		 ACCEL_COLUMN_KEYCODE, accel_key,
+		 ACCEL_COLUMN_MODIFIERS, accel_mods,
 		 -1);
 
+	g_free (accel_text);
+
 	/* Append a new one if needed
 	 */
 	if (key_was_set == FALSE &&
@@ -615,12 +485,11 @@
 		gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter,
 				    ACCEL_COLUMN_SIGNAL, signal,
 				    ACCEL_COLUMN_REAL_SIGNAL, real_signal,
+				    ACCEL_COLUMN_TEXT, _("<choose a key>"),
 				    ACCEL_COLUMN_IS_CLASS, FALSE,
 				    ACCEL_COLUMN_IS_SIGNAL, TRUE,
-				    ACCEL_COLUMN_MOD_SHIFT, FALSE,
-				    ACCEL_COLUMN_MOD_CNTL, FALSE,
-				    ACCEL_COLUMN_MOD_ALT, FALSE,
-				    ACCEL_COLUMN_KEY, _("<choose a key>"),
+				    ACCEL_COLUMN_KEYCODE, 0,
+				    ACCEL_COLUMN_MODIFIERS, 0,
 				    ACCEL_COLUMN_KEY_ENTERED, FALSE,
 				    ACCEL_COLUMN_KEY_SLOT, TRUE,
 				    -1);
@@ -629,32 +498,18 @@
 	}
 }
 
-static void
-modifier_toggled (GtkCellRendererToggle *cell,
-		  gchar                 *path_string,
-		  GladeEditorProperty   *eprop)
+void
+accel_cleared (GtkCellRendererAccel *accel,
+	       gchar                *path_string,
+	       GladeEPropAccel      *eprop_accel)
 {
-	GladeEPropAccel   *eprop_accel = GLADE_EPROP_ACCEL (eprop);
-	GtkTreeIter        iter;
-	gint               column;
-	gboolean           active, key_entered;
+	GtkTreeIter      iter;
 
 	if (!gtk_tree_model_get_iter_from_string (eprop_accel->model,
 						  &iter, path_string))
 		return;
-
-	column = GPOINTER_TO_INT (g_object_get_data
-				  (G_OBJECT (cell), "model-column"));
-
-	gtk_tree_model_get
-		(eprop_accel->model, &iter,
-		 ACCEL_COLUMN_KEY_ENTERED, &key_entered,
-		 column, &active, -1);
-
-	if (key_entered)
-		gtk_tree_store_set
-			(GTK_TREE_STORE (eprop_accel->model), &iter,
-			 column, !active, -1);
+	
+	gtk_tree_store_remove (GTK_TREE_STORE (eprop_accel->model), &iter);
 }
 
 
@@ -670,14 +525,13 @@
 		(ACCEL_NUM_COLUMNS,
 		 G_TYPE_STRING,        /* The GSignal name formatted for display */
 		 G_TYPE_STRING,        /* The GSignal name */
-		 G_TYPE_STRING,        /* The Gdk keycode */
-		 G_TYPE_BOOLEAN,       /* The shift modifier */
-		 G_TYPE_BOOLEAN,       /* The cntl modifier */
-		 G_TYPE_BOOLEAN,       /* The alt modifier */
+		 G_TYPE_STRING,        /* The text to show in the accelerator cell */
 		 G_TYPE_BOOLEAN,       /* Whether this is a class entry */
 		 G_TYPE_BOOLEAN,       /* Whether this is a signal entry (oposite of above) */
 		 G_TYPE_BOOLEAN,       /* Whether the key has been entered for this row */
-		 G_TYPE_BOOLEAN);      /* Oposite of above */
+		 G_TYPE_BOOLEAN,       /* Oposite of above */
+		 G_TYPE_UINT,          /* Hardware keycode */
+		 G_TYPE_INT);          /* GdkModifierType */
 
 	view_widget = gtk_tree_view_new_with_model (eprop_accel->model);
 	g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL);
@@ -709,80 +563,28 @@
 
  	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
 
-	/********************* key name column *********************/
-	if (keysyms_model == NULL)
-		keysyms_model = create_keysyms_model ();
-
- 	renderer = gtk_cell_renderer_combo_new ();
+	/********************* accel editor column *********************/
+ 	renderer = gtk_cell_renderer_accel_new ();
 	g_object_set (G_OBJECT (renderer), 
 		      "editable",    TRUE,
-		      "model",       keysyms_model,
-		      "text-column", ACCEL_COMBO_COLUMN_TEXT,
-		      "has-entry",   TRUE,
 		      "style",       PANGO_STYLE_ITALIC,
 		      "foreground",  "Gray", 
 		      NULL);
 
-	g_signal_connect (renderer, "edited",
-			  G_CALLBACK (key_edited), eprop);
+	g_signal_connect (renderer, "accel-edited",
+			  G_CALLBACK (accel_edited), eprop);
+	g_signal_connect (renderer, "accel-cleared",
+			  G_CALLBACK (accel_cleared), eprop);
 
 	column = gtk_tree_view_column_new_with_attributes
-		(_("Key"),         renderer, 
-		 "text",           ACCEL_COLUMN_KEY,
+		(_("Accelerator Key"),       renderer, 
+		 "text",           ACCEL_COLUMN_TEXT, 
 		 "style-set",      ACCEL_COLUMN_KEY_SLOT,
 		 "foreground-set", ACCEL_COLUMN_KEY_SLOT,
  		 "visible",        ACCEL_COLUMN_IS_SIGNAL,
 		 NULL);
 
-	g_object_set (G_OBJECT (column), "expand", TRUE, NULL);
-
- 	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
-	/********************* shift modifier column *********************/
- 	renderer = gtk_cell_renderer_toggle_new ();
-	column   = gtk_tree_view_column_new_with_attributes
-		(_("Shift"),  renderer, 
-		 "visible", ACCEL_COLUMN_IS_SIGNAL,
-		 "sensitive", ACCEL_COLUMN_KEY_ENTERED,
-		 "active", ACCEL_COLUMN_MOD_SHIFT,
-		 NULL);
-
-	g_object_set_data (G_OBJECT (renderer), "model-column",
-			   GINT_TO_POINTER (ACCEL_COLUMN_MOD_SHIFT));
-	g_signal_connect (G_OBJECT (renderer), "toggled",
-			  G_CALLBACK (modifier_toggled), eprop);
-
- 	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
-	/********************* control modifier column *********************/
- 	renderer = gtk_cell_renderer_toggle_new ();
-	column   = gtk_tree_view_column_new_with_attributes
-		(_("Control"),  renderer, 
-		 "visible", ACCEL_COLUMN_IS_SIGNAL,
-		 "sensitive", ACCEL_COLUMN_KEY_ENTERED,
-		 "active", ACCEL_COLUMN_MOD_CNTL,
-		 NULL);
-
-	g_object_set_data (G_OBJECT (renderer), "model-column",
-			   GINT_TO_POINTER (ACCEL_COLUMN_MOD_CNTL));
-	g_signal_connect (G_OBJECT (renderer), "toggled",
-			  G_CALLBACK (modifier_toggled), eprop);
-
- 	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
-	/********************* alt modifier column *********************/
- 	renderer = gtk_cell_renderer_toggle_new ();
-	column   = gtk_tree_view_column_new_with_attributes
-		(_("Alt"),  renderer, 
-		 "visible", ACCEL_COLUMN_IS_SIGNAL,
-		 "sensitive", ACCEL_COLUMN_KEY_ENTERED,
-		 "active", ACCEL_COLUMN_MOD_ALT,
-		 NULL);
-
-	g_object_set_data (G_OBJECT (renderer), "model-column",
-			   GINT_TO_POINTER (ACCEL_COLUMN_MOD_ALT));
-	g_signal_connect (G_OBJECT (renderer), "toggled",
-			  G_CALLBACK (modifier_toggled), eprop);
+ 	g_object_set (G_OBJECT (column), "expand", TRUE, NULL);
 
  	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
 
@@ -795,32 +597,28 @@
 				      GtkTreeIter    *iter,
 				      GList         **ret)
 {
-	GladeAccelInfo *info;
-	gchar          *signal, *key_str;
-	gboolean        shift, cntl, alt, entered;
+	GladeAccelInfo  *info;
+	gchar           *signal;
+	GdkModifierType  accel_mods;
+	guint            accel_key;
+	gboolean         entered = FALSE;
 
 	gtk_tree_model_get (model, iter, ACCEL_COLUMN_KEY_ENTERED, &entered, -1);
-	if (entered == FALSE) return FALSE;
+	if (!entered) return FALSE;
 	
 	gtk_tree_model_get (model, iter,
 			    ACCEL_COLUMN_REAL_SIGNAL, &signal,
-			    ACCEL_COLUMN_KEY,         &key_str,
-			    ACCEL_COLUMN_MOD_SHIFT,   &shift,
-			    ACCEL_COLUMN_MOD_CNTL,    &cntl,
-			    ACCEL_COLUMN_MOD_ALT,     &alt,
+			    ACCEL_COLUMN_KEYCODE,     &accel_key,
+			    ACCEL_COLUMN_MODIFIERS,   &accel_mods,
 			    -1);
 
 	info            = g_new0 (GladeAccelInfo, 1);
 	info->signal    = signal;
-	info->key       = glade_key_from_string (key_str);
-	info->modifiers = (shift ? GDK_SHIFT_MASK   : 0) |
-			  (cntl  ? GDK_CONTROL_MASK : 0) |
-			  (alt   ? GDK_MOD1_MASK    : 0);
+	info->key       = accel_key;
+	info->modifiers = accel_mods;
 
 	*ret = g_list_prepend (*ret, info);
 
-	g_free (key_str);
-	
 	return FALSE;
 }
 



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