Index: capplets/keybindings/ChangeLog
===================================================================
RCS file: /export/cvs/head/gnome-control-center/capplets/keybindings/ChangeLog,v
retrieving revision 1.83
diff -p -u -5 -r1.83 ChangeLog
--- capplets/keybindings/ChangeLog	8 Feb 2005 22:42:10 -0000	1.83
+++ capplets/keybindings/ChangeLog	17 Jun 2005 12:58:49 -0000
@@ -1,5 +1,12 @@
+2005-06-17  Vinay M R  <vinay.mandyakoppal@wipro.com>
+
+	* gnome-keybinding-properties.c: (append_keys_to_tree),
+	(accel_edited_callback), (accel_cleared_callback): To provide
+	additional shortcuts to Main Menu, Run App and Show Desktop.
+	Fixes Bug #164831.
+
 2005-02-08  Sebastien Bacher  <seb128@debian.org>
 
 	* eggcellrendererkeys.c: (egg_cell_renderer_keys_start_editing):
 	patch by Kjartan Maraas <kmaraas@gnome.org>, some code cleanups
         (Closes: #166267).
Index: capplets/keybindings/gnome-keybinding-properties.c
===================================================================
RCS file: /export/cvs/head/gnome-control-center/capplets/keybindings/gnome-keybinding-properties.c,v
retrieving revision 1.49
diff -p -u -5 -r1.49 gnome-keybinding-properties.c
--- capplets/keybindings/gnome-keybinding-properties.c	13 Jan 2005 01:08:54 -0000	1.49
+++ capplets/keybindings/gnome-keybinding-properties.c	17 Jun 2005 12:58:56 -0000
@@ -47,11 +47,13 @@ const KeyListEntry desktop_key_list[] =
   { "/apps/gnome_settings_daemon/keybindings/home", ALWAYS_VISIBLE, 0 },
   { "/apps/gnome_settings_daemon/keybindings/search", ALWAYS_VISIBLE, 0 },
   { "/apps/gnome_settings_daemon/keybindings/email", ALWAYS_VISIBLE, 0 },
   { "/apps/gnome_settings_daemon/keybindings/www", ALWAYS_VISIBLE, 0 },
   { "/apps/metacity/global_keybindings/panel_run_dialog", ALWAYS_VISIBLE, 0 },
+  { "/apps/metacity/global_keybindings/panel_run_dialog_alt", ALWAYS_VISIBLE, 0 },
   { "/apps/metacity/global_keybindings/panel_main_menu", ALWAYS_VISIBLE, 0 },
+  { "/apps/metacity/global_keybindings/panel_main_menu_alt", ALWAYS_VISIBLE, 0 },
   { "/apps/metacity/global_keybindings/run_command_screenshot", ALWAYS_VISIBLE, 0 },
   { "/apps/metacity/global_keybindings/run_command_window_screenshot", ALWAYS_VISIBLE, 0 },
   { "/apps/metacity/global_keybindings/run_command_terminal", ALWAYS_VISIBLE, 0 },
 #ifdef USE_FBLEVEL
   { "/apps/gnome_settings_daemon/keybindings/brightness_down", ALWAYS_VISIBLE, 0 },
@@ -112,10 +114,11 @@ const KeyListEntry metacity_key_list[] =
   { "/apps/metacity/global_keybindings/switch_windows",            ALWAYS_VISIBLE,  0 },
   { "/apps/metacity/global_keybindings/switch_panels",             ALWAYS_VISIBLE,  0 },
   { "/apps/metacity/global_keybindings/cycle_windows",             ALWAYS_VISIBLE,  0 },
   { "/apps/metacity/global_keybindings/cycle_panels",              ALWAYS_VISIBLE,  0 },
   { "/apps/metacity/global_keybindings/show_desktop",              ALWAYS_VISIBLE,  0 },
+  { "/apps/metacity/global_keybindings/show_desktop_alt",          ALWAYS_VISIBLE,  0 },
   { "/apps/metacity/global_keybindings/switch_to_workspace_1",     N_WORKSPACES_GT, 1 },
   { "/apps/metacity/global_keybindings/switch_to_workspace_2",     N_WORKSPACES_GT, 1 },
   { "/apps/metacity/global_keybindings/switch_to_workspace_3",     N_WORKSPACES_GT, 2 },
   { "/apps/metacity/global_keybindings/switch_to_workspace_4",     N_WORKSPACES_GT, 3 },
   { "/apps/metacity/global_keybindings/switch_to_workspace_5",     N_WORKSPACES_GT, 4 },
@@ -156,10 +159,15 @@ static void  reload_key_entries (gpointe
                                  GladeXML               *dialog);
 static char* binding_name       (guint                   keyval,
 				 guint			 keycode,
                                  EggVirtualModifierType  mask,
                                  gboolean                translate);
+static KeyEntry * create_keyentry (GConfEntry           *entry,
+				   GConfSchema          *schema,
+				   const gchar          *key_string,
+				   gchar                *key_value,
+				   GtkTreeModel         *model);
 
 static GtkTreeModel*
 get_real_model (GtkTreeView *tree_view)
 {
   GtkTreeModel *model;
@@ -173,10 +181,58 @@ get_real_model (GtkTreeView *tree_view)
     submodel = NULL;
   
   return submodel;
 }
 
+static GConfValueType
+get_gconfvalue_type (char *key, GConfEntry **entry_extra, GConfSchema **schema_extra)
+{
+  GConfClient *client;
+  GConfEntry *entry;
+  GConfSchema *schema = NULL;
+  GError *error = NULL;
+  GConfValueType type;
+
+  client = gconf_client_get_default();
+
+  entry = gconf_client_get_entry (client,
+                                  key,
+                                  NULL,
+                                  TRUE,
+                                  &error);
+  if (error || entry == NULL)
+    {
+      /* We don't actually want to popup a dialog - just skip this one */
+      if (error)
+	g_error_free (error);
+      return (GCONF_VALUE_INVALID);
+    }
+
+  if (gconf_entry_get_schema_name (entry))
+    schema = gconf_client_get_schema (client, gconf_entry_get_schema_name (entry), &error);
+
+  if (error || schema == NULL)
+    {
+      /* We don't actually want to popup a dialog - just skip this one */
+      if (error)
+	g_error_free (error);
+      return (GCONF_VALUE_INVALID);
+    }
+
+  if (entry_extra != NULL)
+    {
+      *entry_extra = entry;
+      *schema_extra = schema;
+    }
+
+  type = gconf_schema_get_type (schema);
+
+  g_object_unref (client);
+
+  return (type);
+}
+
 static GladeXML *
 create_dialog (void)
 {
   GladeXML *dialog;
 
@@ -287,18 +343,24 @@ keybinding_key_changed (GConfClient *cli
 			gpointer     user_data)
 {
   KeyEntry *key_entry;
   const gchar *key_value;
 
-  key_entry = (KeyEntry *)user_data;
-  key_value = gconf_value_get_string (entry->value);
+  key_entry = (KeyEntry *) user_data;
 
-  binding_from_string (key_value, &key_entry->keyval, &key_entry->keycode, &key_entry->mask);
-  key_entry->editable = gconf_entry_get_is_writable (entry);
-
-  /* update the model */
-  gtk_tree_model_foreach (key_entry->model, keybinding_key_changed_foreach, key_entry);
+  if (get_gconfvalue_type (key_entry->gconf_key, NULL, NULL) == GCONF_VALUE_STRING)
+    {
+      key_value = gconf_value_get_string (entry->value);
+      binding_from_string (key_value, &key_entry->keyval, &key_entry->keycode,
+			   &key_entry->mask);
+  
+      key_entry->editable = gconf_entry_get_is_writable (entry);
+  
+      /* update the model */
+      gtk_tree_model_foreach (key_entry->model, keybinding_key_changed_foreach,
+			      key_entry);
+    } 
 }
 
 static int
 keyentry_sort_func (GtkTreeModel *model,
                     GtkTreeIter  *a,
@@ -467,91 +529,152 @@ append_keys_to_tree (GladeXML           
     {
       GConfEntry *entry;
       GConfSchema *schema = NULL;
       KeyEntry *key_entry;
       GError *error = NULL;
-      GtkTreeIter iter;
+      GtkTreeIter iter, iter1, iter2;
       const gchar *key_string;
       gchar *key_value;
+      GConfValueType type;
 
       if (!should_show_key (&keys_list[j]))
 	continue;
       
       key_string = keys_list[j].name;
+      type = get_gconfvalue_type ((char *) key_string, &entry, &schema);
 
-      entry = gconf_client_get_entry (client,
-                                      key_string,
-				      NULL,
-				      TRUE,
-				      &error);
-      if (error || entry == NULL)
+      if (type == GCONF_VALUE_LIST)
 	{
-	  /* We don't actually want to popup a dialog - just skip this one */
-	  if (error)
-	    g_error_free (error);
-	  continue;
-	}
+	  GSList *slist;
+	  GtkTreeIter iter_list;
 
-      if (gconf_entry_get_schema_name (entry))
-	schema = gconf_client_get_schema (client, gconf_entry_get_schema_name (entry), &error);
-      
-      if (error || schema == NULL)
-	{
-	  /* We don't actually want to popup a dialog - just skip this one */
-	  if (error)
-	    g_error_free (error);
-	  continue;
-	}
-
-      key_value = gconf_client_get_string (client, key_string, &error);
-
-      key_entry = g_new0 (KeyEntry, 1);
-      key_entry->gconf_key = g_strdup (key_string);
-      key_entry->editable = gconf_entry_get_is_writable (entry);
-      key_entry->model = model;
-      gconf_client_add_dir (client, key_string, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
-      key_entry->gconf_cnxn = gconf_client_notify_add (client,
-						       key_string,
-						       (GConfClientNotifyFunc) &keybinding_key_changed,
-						       key_entry, NULL, NULL);
-      binding_from_string (key_value, &key_entry->keyval, &key_entry->keycode, &key_entry->mask);
-      g_free (key_value);
-      key_entry->description = g_strdup (gconf_schema_get_short_desc (schema));
+	  slist = gconf_client_get_list (client, key_string, GCONF_VALUE_STRING, &error);
+	  for ( ; slist != NULL ; slist = slist->next)
+	    {
+	      key_value = (char *) malloc ((strlen ((char *) slist->data)) +1 );
+	      strcpy(key_value, (gchar *) slist->data);
+	      key_entry = create_keyentry (entry, schema, key_string, key_value, model);
+	      g_free (key_value);
+
+	      if (i == MAX_ELEMENTS_BEFORE_SCROLLING)
+		{
+		  GtkRequisition rectangle;
+		  gtk_widget_ensure_style (WID ("shortcut_treeview"));
+		  gtk_widget_size_request (WID ("shortcut_treeview"), &rectangle);
+		  gtk_widget_set_size_request (WID ("shortcut_treeview"), -1, rectangle.height);
+		  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("actions_swindow")),
+						  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+		}
+	      i++;
+	      gtk_tree_store_append (GTK_TREE_STORE (model), &iter_list, &iter1);
+	      if (gconf_schema_get_short_desc (schema))
+		gtk_tree_store_set (GTK_TREE_STORE (model), &iter_list,
+				    DESCRIPTION_COLUMN,
+				    "Alternative",
+				    KEYENTRY_COLUMN, key_entry,
+				    -1);
+	      else
+		gtk_tree_store_set (GTK_TREE_STORE (model), &iter_list,
+				    DESCRIPTION_COLUMN, _("<Unknown Action>"),
+				    KEYENTRY_COLUMN, key_entry,
+				    -1);
+		gtk_tree_view_expand_all (GTK_TREE_VIEW (WID ("shortcut_treeview")));
+            }
 
-      if (i == MAX_ELEMENTS_BEFORE_SCROLLING)
+	  g_slist_foreach (slist, (GFunc) g_free, NULL);
+	  g_slist_free (slist);
+	}
+      else if (type == GCONF_VALUE_STRING)
 	{
-	  GtkRequisition rectangle;
-	  gtk_widget_ensure_style (WID ("shortcut_treeview"));
-	  gtk_widget_size_request (WID ("shortcut_treeview"), &rectangle);
-	  gtk_widget_set_size_request (WID ("shortcut_treeview"), -1, rectangle.height);
-	  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("actions_swindow")),
-					  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+	  key_value = gconf_client_get_string (client, key_string, &error);
+	  key_entry = create_keyentry (entry, schema, key_string, key_value, model);
+	  g_free (key_value);
+	  if (i == MAX_ELEMENTS_BEFORE_SCROLLING)
+	    {
+	      GtkRequisition rectangle;
+	      gtk_widget_ensure_style (WID ("shortcut_treeview"));
+	      gtk_widget_size_request (WID ("shortcut_treeview"), &rectangle);
+	      gtk_widget_set_size_request (WID ("shortcut_treeview"), -1, rectangle.height);
+	      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("actions_swindow")),
+					      GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+	    }
+	  i++;
+	  if ((char *) keys_list[j+1].name != NULL && get_gconfvalue_type ((char *) keys_list[j+1].name, NULL, NULL) == GCONF_VALUE_LIST)
+	    {
+	      gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, &parent_iter);
+	      gtk_tree_store_set (GTK_TREE_STORE (model), &iter1,
+				  DESCRIPTION_COLUMN,
+				  key_entry->description,
+				  -1);
+	      gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, &iter1); 
+	      gtk_tree_store_set (GTK_TREE_STORE (model), &iter2,
+				  DESCRIPTION_COLUMN,
+				  key_entry->description,
+				  KEYENTRY_COLUMN, key_entry,
+				  -1);
+	    }
+	  else 
+	    {
+	      gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent_iter);
+	      if (gconf_schema_get_short_desc (schema))
+		gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
+				    DESCRIPTION_COLUMN,
+				    key_entry->description,
+				    KEYENTRY_COLUMN, key_entry,
+				    -1);
+	      else
+		gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
+				    DESCRIPTION_COLUMN, _("<Unknown Action>"),
+				    KEYENTRY_COLUMN, key_entry,
+				    -1);
+	    }
+
+	  gtk_tree_view_expand_all (GTK_TREE_VIEW (WID ("shortcut_treeview")));
 	}
-      i++;
-      gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent_iter);
-      if (gconf_schema_get_short_desc (schema))
-	gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
-			    DESCRIPTION_COLUMN,
-                            key_entry->description,
-			    KEYENTRY_COLUMN, key_entry,
-			    -1);
-      else
-	gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
-			    DESCRIPTION_COLUMN, _("<Unknown Action>"),
-			    KEYENTRY_COLUMN, key_entry,
-			    -1);
-      gtk_tree_view_expand_all (GTK_TREE_VIEW (WID ("shortcut_treeview")));
+      else if (type == GCONF_VALUE_INVALID)
+        continue;
+
       gconf_entry_free (entry);
       gconf_schema_free (schema);
     }
 
+  g_object_unref (client);
+
   if (i == 0)
       gtk_widget_hide (WID ("shortcuts_vbox"));
   else
       gtk_widget_show (WID ("shortcuts_vbox"));
 }
 
+static KeyEntry *
+create_keyentry (GConfEntry *entry, 
+		 GConfSchema *schema, 
+		 const gchar *key_string, 
+		 gchar *key_value,
+		 GtkTreeModel *model)
+{
+  GConfClient *client = gconf_client_get_default();
+  KeyEntry *key_entry;
+
+  key_entry = g_new0 (KeyEntry, 1);
+  key_entry->gconf_key = g_strdup (key_string);
+  key_entry->editable = gconf_entry_get_is_writable (entry);
+  key_entry->model = model;
+  gconf_client_add_dir (client, key_string, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+  key_entry->gconf_cnxn = gconf_client_notify_add (client,
+                                                   key_string,
+                                                   (GConfClientNotifyFunc) &keybinding_key_changed,
+                                                   key_entry, NULL, NULL);
+  binding_from_string (key_value, &key_entry->keyval, &key_entry->keycode, &key_entry->mask);
+
+  key_entry->description = g_strdup (gconf_schema_get_short_desc (schema));
+
+  g_object_unref (client);
+  
+  return (key_entry);
+}
+
 static void
 reload_key_entries (gpointer wm_name, GladeXML *dialog)
 {
   clear_old_model (dialog, WID ("shortcut_treeview"));
   
@@ -584,12 +707,11 @@ cb_check_for_uniqueness (GtkTreeModel *m
   gtk_tree_model_get (new_key->model, iter,
 		      KEYENTRY_COLUMN, &element,
 		      -1);
 
   /* no conflict for : blanks, different modifiers, or ourselves */
-  if (element == NULL || new_key->mask != element->mask ||
-      !strcmp (new_key->gconf_key, element->gconf_key))
+  if (element == NULL || new_key->mask != element->mask)
     return FALSE;
 
   if (new_key->keyval != 0) {
       if (new_key->keyval != element->keyval)
 	  return FALSE;
@@ -615,15 +737,15 @@ accel_edited_callback (GtkCellRendererTe
   GtkTreeModel *model;
   GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
   GtkTreeIter iter;
   KeyEntry *key_entry, tmp_key;
   GError *err = NULL;
-  char *str;
+  char *str, *prev_str = NULL;
+  GConfValueType type;
 
   model = gtk_tree_view_get_model (view);
   gtk_tree_model_get_iter (model, &iter, path);
-  gtk_tree_path_free (path);
   gtk_tree_model_get (model, &iter,
 		      KEYENTRY_COLUMN, &key_entry,
 		      -1);
 
   /* sanity check */
@@ -670,35 +792,70 @@ accel_edited_callback (GtkCellRendererTe
 					      key_entry->keyval, key_entry->keycode, key_entry->mask);
       return;
     }
 
   str = binding_name (keyval, keycode, mask, FALSE);
+  prev_str = binding_name (key_entry->keyval, key_entry->keycode, key_entry->mask, FALSE);
 
   client = gconf_client_get_default();
-  gconf_client_set_string (client,
-                           key_entry->gconf_key,
-                           str,
-                           &err);
-  g_free (str);
+  type = get_gconfvalue_type (key_entry->gconf_key, NULL, NULL);
+
+  if (type == GCONF_VALUE_LIST)
+    {
+      GSList *list, *tmp;
+
+      list = gconf_client_get_list (client,
+				    key_entry->gconf_key,
+				    GCONF_VALUE_STRING,
+				    &err);
+      for (tmp = list; tmp ; tmp = tmp->next)
+        {
+	  if (strcmp (tmp->data, prev_str) == 0)
+	    {
+	      strcpy (tmp->data, str);
+	      break;
+	    }
+	}
+      gconf_client_set_list (client,
+			     key_entry->gconf_key,
+			     GCONF_VALUE_STRING,
+			     list,
+			     &err);
+      binding_from_string (str, &key_entry->keyval, &key_entry->keycode,
+			   &key_entry->mask);
+      key_entry->editable = TRUE;
+      gtk_tree_model_row_changed (key_entry->model, path, &iter);
+
+      gtk_tree_path_free (path);
+      g_slist_free (list);
+      g_free (prev_str);
+    } 
+  else if (type == GCONF_VALUE_STRING)
+    gconf_client_set_string (client,
+			     key_entry->gconf_key,
+			     str,
+			     &err);
+
   g_object_unref (G_OBJECT (client));
 
   if (err != NULL)
     {
       GtkWidget *dialog;
 
       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
-				       GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+				       GTK_DIALOG_DESTROY_WITH_PARENT,
 				       GTK_MESSAGE_WARNING,
 				       GTK_BUTTONS_OK,
-				       _("Error setting new accelerator in configuration database: %s\n"),
+				       _("Error setting new accelerator in configuration database: %s"),
 				       err->message);
       gtk_dialog_run (GTK_DIALOG (dialog));
 
       gtk_widget_destroy (dialog);
       g_error_free (err);
       key_entry->editable = FALSE;
     }
+  g_free (str);
 }
 
 static void
 accel_cleared_callback (GtkCellRendererText *cell,
 			const char          *path_string,
@@ -709,39 +866,76 @@ accel_cleared_callback (GtkCellRendererT
   GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
   KeyEntry *key_entry;
   GtkTreeIter iter;
   GError *err = NULL;
   GtkTreeModel *model;
+  char *str;
+  GConfValueType type;
 
   model = gtk_tree_view_get_model (view);
   gtk_tree_model_get_iter (model, &iter, path);
-  gtk_tree_path_free (path);
   gtk_tree_model_get (model, &iter,
 		      KEYENTRY_COLUMN, &key_entry,
 		      -1);
 
   /* sanity check */
   if (key_entry == NULL)
     return;
 
   /* Unset the key */
   client = gconf_client_get_default();
-  gconf_client_set_string (client,
-			   key_entry->gconf_key,
-			   "disabled",
-			   &err);
+
+  str = binding_name (key_entry->keyval, key_entry->keycode, key_entry->mask, FALSE);
+  type = get_gconfvalue_type (key_entry->gconf_key, NULL, NULL);
+
+  if (type == GCONF_VALUE_LIST)
+    {
+      GSList *list, *tmp;
+
+      list = gconf_client_get_list (client,
+				    key_entry->gconf_key,
+				    GCONF_VALUE_STRING,
+				    &err);
+      for (tmp = list; tmp ; tmp = tmp->next)
+	{
+	  if (strcmp (tmp->data, str) == 0)
+	    {
+	      strcpy (tmp->data, "disabled");
+	      break;
+	    }
+	}
+      gconf_client_set_list (client,
+			     key_entry->gconf_key,
+			     GCONF_VALUE_STRING,
+			     list,
+			     &err);
+      binding_from_string ("disabled", &key_entry->keyval, &key_entry->keycode,
+			   &key_entry->mask);
+      key_entry->editable = TRUE;
+      gtk_tree_model_row_changed (key_entry->model, path, &iter);
+
+      gtk_tree_path_free (path);
+      g_slist_free (list);
+      g_free (str);
+    }
+  else if (type == GCONF_VALUE_STRING)
+    gconf_client_set_string (client,
+			     key_entry->gconf_key,
+			     "disabled",
+			     &err);
+
   g_object_unref (G_OBJECT (client));
 
   if (err != NULL)
     {
       GtkWidget *dialog;
 
       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
-				       GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+				       GTK_DIALOG_DESTROY_WITH_PARENT,
 				       GTK_MESSAGE_WARNING,
 				       GTK_BUTTONS_OK,
-				       _("Error unsetting accelerator in configuration database: %s\n"),
+				       _("Error unsetting accelerator in configuration database: %s"),
 				       err->message);
       gtk_dialog_run (GTK_DIALOG (dialog));
 
       gtk_widget_destroy (dialog);
       g_error_free (err);
@@ -774,10 +968,15 @@ static gboolean
 start_editing_kb_cb (GtkTreeView *treeview, 
 			  GtkTreePath *path, 
 			  GtkTreeViewColumn *column,
 			  gpointer user_data)
 {
+  if (gtk_tree_view_row_expanded (treeview, path))
+    gtk_tree_view_collapse_row (treeview, path);
+  else
+    gtk_tree_view_expand_row (treeview, path, FALSE);
+
   gtk_widget_grab_focus (GTK_WIDGET (treeview));
   gtk_tree_view_set_cursor (treeview,
 			    path,
 			    gtk_tree_view_get_column (treeview, 1),
 			    TRUE);
@@ -807,10 +1006,15 @@ start_editing_cb (GtkTreeView    *tree_v
 	{
 	  gtk_tree_path_free (path);
 	  return FALSE;
 	}
 
+      if (gtk_tree_view_row_expanded (tree_view, path))
+	gtk_tree_view_collapse_row (tree_view, path);
+      else
+	gtk_tree_view_expand_row (tree_view, path, FALSE);
+
       idle_data = g_new (IdleData, 1);
       idle_data->tree_view = tree_view;
       idle_data->path = path;
       g_signal_stop_emission_by_name (G_OBJECT (tree_view), "button_press_event");
       g_idle_add ((GSourceFunc) real_start_editing_cb, idle_data);
