Re: Freeze break request to improve context menu



Forgot the patch. It is also available at that website.

On Fri, 2006-02-17 at 00:00 +1100, Peter Harvey wrote:
> Hello,
> 
> The attached patch for Epiphany improves the context menu for bookmarks
> and other widgets on the toolbar. It also corrects some related bugs
> with the appearance and sensitivity of items on the context menu.
> 
> It has maintainer approval. Screenshots available at:
>   http://home.exetel.com.au/harvey/epiphany/060215/
> 
> Thanks,
> Peter Harvey.

Index: data/ui/epiphany-ui.xml
===================================================================
RCS file: /cvs/gnome/epiphany/data/ui/epiphany-ui.xml,v
retrieving revision 1.38
diff -u -d -r1.38 epiphany-ui.xml
--- data/ui/epiphany-ui.xml	30 Jan 2006 22:13:07 -0000	1.38
+++ data/ui/epiphany-ui.xml	16 Feb 2006 12:52:01 -0000
@@ -38,9 +38,13 @@
 <menu name="ViewMenu" action="View">
 	<placeholder name="ViewTogglesGroup" position="top">
 		<menu name="ToolbarMenu" action="Toolbar">
-		<menuitem name="ViewToolbarEditorMenu" action="ViewToolbarEditor"/>
+		<separator/>
+		<placeholder name="ViewToolbarsGroup" position="top">
+		</placeholder>
+		<separator/>
 		<menuitem name="ViewToolbarMenu" action="ViewToolbar"/>
-		<separator name="ToolbarSep1"/>
+		<menuitem name="ViewToolbarEditorMenu" action="ViewToolbarEditor"/>
+		<separator/>
 		</menu>
 		<menuitem name="ViewStatusbarMenu" action="ViewStatusbar"/>
 	</placeholder>
@@ -169,6 +173,15 @@
 </popup>
 
 <popup name="ToolbarPopup">
+	<placeholder name="SpecificItemsGroup">
+	</placeholder>
+	<separator/>
+     	<menuitem action="MoveToolItem"/>
+ 	<menuitem action="RemoveToolItem"/>    
+	<menuitem action="RemoveToolbar"/>
+	<separator/>
+	<placeholder name="ViewToolbarsGroup">
+	</placeholder>
 	<separator/>
         <menuitem action="ViewToolbarEditor"/>
 	<separator/>
Index: lib/ephy-stock-icons.c
===================================================================
RCS file: /cvs/gnome/epiphany/lib/ephy-stock-icons.c,v
retrieving revision 1.21
diff -u -d -r1.21 ephy-stock-icons.c
--- lib/ephy-stock-icons.c	16 Jan 2006 22:25:16 -0000	1.21
+++ lib/ephy-stock-icons.c	16 Feb 2006 12:52:01 -0000
@@ -48,6 +48,7 @@
 		STOCK_LOCK_INSECURE,
 		STOCK_LOCK_SECURE,
 		STOCK_LOCK_BROKEN,
+		STOCK_DRAG_MODE,
 	};
 
 	static const GtkStockItem items[] =
Index: lib/ephy-stock-icons.h
===================================================================
RCS file: /cvs/gnome/epiphany/lib/ephy-stock-icons.h,v
retrieving revision 1.18
diff -u -d -r1.18 ephy-stock-icons.h
--- lib/ephy-stock-icons.h	16 Jan 2006 22:25:16 -0000	1.18
+++ lib/ephy-stock-icons.h	16 Feb 2006 12:52:01 -0000
@@ -38,6 +38,7 @@
 #define STOCK_LOCK_INSECURE	   "stock_lock-open"
 #define STOCK_LOCK_SECURE	   "stock_lock"
 #define STOCK_LOCK_BROKEN	   "stock_lock-broken"
+#define STOCK_DRAG_MODE	   	   "stock_drag-mode"
 
 void ephy_stock_icons_init (void);
 
Index: lib/egg/egg-editable-toolbar.c
===================================================================
RCS file: /cvs/gnome/epiphany/lib/egg/egg-editable-toolbar.c,v
retrieving revision 1.86
diff -u -d -r1.86 egg-editable-toolbar.c
--- lib/egg/egg-editable-toolbar.c	4 Feb 2006 10:43:23 -0000	1.86
+++ lib/egg/egg-editable-toolbar.c	16 Feb 2006 12:52:02 -0000
@@ -52,6 +52,7 @@
 
 #define MIN_TOOLBAR_HEIGHT 20
 #define EGG_ITEM_NAME      "egg-item-name"
+#define STOCK_DRAG_MODE    "stock_drag-mode"
 
 static const GtkTargetEntry dest_drag_types[] = {
   {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
@@ -63,7 +64,8 @@
   PROP_TOOLBARS_MODEL,
   PROP_UI_MANAGER,
   PROP_VISIBILITY_PATH,
-  PROP_SELECTED
+  PROP_SELECTED,
+  PROP_EDIT_MODE
 };
 
 enum
@@ -88,7 +90,6 @@
   
   GtkWidget *selected;
   GtkActionGroup *actions;
-  guint popup_id;
   
   guint visibility_id;
   char *visibility_path;
@@ -369,21 +370,29 @@
 }
 
 static void
+popup_context_deactivate (GtkMenuShell *menu,
+			  EggEditableToolbar *etoolbar)
+{
+  egg_editable_toolbar_set_selected (etoolbar, NULL);
+  g_object_notify (G_OBJECT (etoolbar), "selected");
+}
+
+static void
 popup_context_menu_cb (GtkWidget          *toolbar,
                        gint		   x,
                        gint		   y,
                        gint                button_number,
                        EggEditableToolbar *etoolbar)
 {
-  if (etoolbar->priv->popup_id != 0)
-    {
-      GtkMenu *menu;
-      egg_editable_toolbar_set_selected (etoolbar, toolbar);
-      g_object_notify (G_OBJECT (etoolbar), "selected");
+  GtkMenu *menu;
+  egg_editable_toolbar_set_selected (etoolbar, toolbar);
+  g_object_notify (G_OBJECT (etoolbar), "selected");
 	
-      menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager, "/ToolbarPopup"));
-      gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
-    }
+  menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager, "/ToolbarPopup"));
+  gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
+  g_signal_connect_object (menu, "selection-done",
+			   G_CALLBACK (popup_context_deactivate),
+			   etoolbar, 0);
 }
 
 static gboolean
@@ -391,7 +400,7 @@
                        GdkEventButton *event,
                        EggEditableToolbar *etoolbar)
 {
-  if (event->button == 3 && etoolbar->priv->popup_id != 0)
+  if (event->button == 3)
     {
       GtkMenu *menu;
       egg_editable_toolbar_set_selected (etoolbar, widget);
@@ -399,6 +408,9 @@
 	
       menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager, "/ToolbarPopup"));
       gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
+      g_signal_connect_object (menu, "selection-done",
+			       G_CALLBACK (popup_context_deactivate),
+			       etoolbar, 0);
       
       return TRUE;
     }
@@ -752,7 +764,7 @@
   gboolean visible;
   gint i;
   
-  visible = !gtk_toggle_action_get_active (action);
+  visible = gtk_toggle_action_get_active (action);
   for (i = 0; i < priv->visibility_actions->len; i++)
     if (g_ptr_array_index (priv->visibility_actions, i) == action)
       break;
@@ -865,7 +877,7 @@
 	k++;
       }
       tmp[k] = 0;
-      action_label = g_strdup_printf (_("Hide â??%sâ??"), tmp);
+      action_label = g_strdup_printf (_("Show â??%sâ??"), tmp);
       g_free (tmp);
       
       sprintf(action_name, "ToolbarToggle%d", i);
@@ -884,13 +896,21 @@
 	  action = g_ptr_array_index (priv->visibility_actions, i);
 	  g_object_set (action, "label", action_label, NULL);
         }
-      
-      gtk_toggle_action_set_active (action, !GTK_WIDGET_VISIBLE
+
+      gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i) 
+						    & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
+      gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
 				    (get_dock_nth (etoolbar, i)));
       
       gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
 			     priv->visibility_path, action_name, action_name,
 			     GTK_UI_MANAGER_MENUITEM, FALSE);
+      if (etoolbar->priv->selected != NULL)
+        {
+	  gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
+				 "/ToolbarPopup/ViewToolbarsGroup", action_name, action_name,
+				 GTK_UI_MANAGER_MENUITEM, FALSE);
+	}
 	    
       g_free (action_label);
     }
@@ -1301,11 +1321,11 @@
 				     GtkUIManager       *manager)
 {
   static const GtkActionEntry actions[] = {
-    { "MoveToolItem", NULL, N_("_Move on Toolbar"), NULL,
+    { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
       N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
-    { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
+    { "RemoveToolItem", GTK_STOCK_DELETE, N_("_Remove from Toolbar"), NULL,
       N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
-    { "RemoveToolbar", GTK_STOCK_REMOVE, N_("_Remove Toolbar"), NULL,
+    { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
       N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
   };
   
@@ -1318,13 +1338,6 @@
   gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
   g_object_unref (etoolbar->priv->actions);
 
-  etoolbar->priv->popup_id = gtk_ui_manager_add_ui_from_string (manager, 
-     "<popup name=\"ToolbarPopup\">"
-     "<menuitem action=\"MoveToolItem\"/>"
-     "<menuitem action=\"RemoveToolItem\"/>"							     
-     "<menuitem action=\"RemoveToolbar\"/>"
-     "</popup>", -1, NULL);  
-  
   toolbar_visibility_refresh (etoolbar);
 }
 
@@ -1341,17 +1354,65 @@
 
   etoolbar->priv->selected = widget;
   
-  toolitem = (gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) != 0);
-  toolbar = (gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) != 0);
+  toolitem = widget ? (gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) != NULL) : FALSE;
+  toolbar = widget ? (gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) != NULL) : FALSE;
   
   gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), toolbar && (etoolbar->priv->edit_mode > 0));
   gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), toolitem);
   gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), toolitem);
-  
+ 
   toolbar_visibility_refresh (etoolbar);
 }
 
 static void
+set_edit_mode (EggEditableToolbar *etoolbar,
+	       gboolean mode)
+{
+  EggEditableToolbarPrivate *priv = etoolbar->priv;
+  int i, l, n_items;
+
+  i = priv->edit_mode;
+  if (mode)
+    {
+      priv->edit_mode++;
+    }
+  else
+    {
+      g_return_if_fail (priv->edit_mode > 0);
+      priv->edit_mode--;
+    }
+  i *= priv->edit_mode;
+  
+  if (i == 0)
+    {
+      for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
+        {
+          GtkWidget *toolbar;
+          
+          toolbar = get_toolbar_nth (etoolbar, i);
+          n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
+
+          if (n_items == 0 && priv->edit_mode == 0)
+            {
+              egg_toolbars_model_remove_toolbar (priv->model, i);
+            }
+          else
+            {          
+              for (l = 0; l < n_items; l++)
+                {
+                  GtkToolItem *item;
+              
+                  item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
+                  
+                  configure_item_cursor (item, etoolbar);
+                  configure_item_sensitivity (item, etoolbar);
+                }
+            }
+        }
+    }
+}
+
+static void
 egg_editable_toolbar_set_property (GObject      *object,
 				   guint         prop_id,
 				   const GValue *value,
@@ -1373,6 +1434,9 @@
     case PROP_VISIBILITY_PATH:
       etoolbar->priv->visibility_path = g_strdup (g_value_get_string (value));
       break;
+    case PROP_EDIT_MODE:
+      set_edit_mode (etoolbar, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1398,6 +1462,9 @@
     case PROP_SELECTED:
       g_value_set_object (value, etoolbar->priv->selected);
       break;
+    case PROP_EDIT_MODE:
+      g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1453,6 +1520,14 @@
 							NULL,
 							G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
+  g_object_class_install_property (object_class,
+				   PROP_VISIBILITY_PATH,
+				   g_param_spec_boolean ("edit-mode",
+							 "Edit-Mode",
+							 "Edit Mode",
+							 FALSE,
+							 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
   g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
 }
 
@@ -1490,48 +1565,8 @@
 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
 				    gboolean mode)
 {
-  EggEditableToolbarPrivate *priv = etoolbar->priv;
-  int i, l, n_items;
-
-  i = priv->edit_mode;
-  if (mode)
-    {
-      priv->edit_mode++;
-    }
-  else
-    {
-      g_return_if_fail (priv->edit_mode > 0);
-      priv->edit_mode--;
-    }
-  i *= priv->edit_mode;
-  
-  if (i == 0)
-    {
-      for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
-        {
-          GtkWidget *toolbar;
-          
-          toolbar = get_toolbar_nth (etoolbar, i);
-          n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
-
-          if (n_items == 0 && priv->edit_mode == 0)
-            {
-              egg_toolbars_model_remove_toolbar (priv->model, i);
-            }
-          else
-            {          
-              for (l = 0; l < n_items; l++)
-                {
-                  GtkToolItem *item;
-              
-                  item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
-                  
-                  configure_item_cursor (item, etoolbar);
-                  configure_item_sensitivity (item, etoolbar);
-                }
-            }
-        }
-    }
+  set_edit_mode (etoolbar, mode);
+  g_object_notify (G_OBJECT (etoolbar), "edit-mode");
 }
 
 void
Index: src/ephy-toolbar.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/ephy-toolbar.c,v
retrieving revision 1.29
diff -u -d -r1.29 ephy-toolbar.c
--- src/ephy-toolbar.c	30 Jan 2006 22:13:07 -0000	1.29
+++ src/ephy-toolbar.c	16 Feb 2006 12:52:03 -0000
@@ -739,6 +739,6 @@
 	return EPHY_TOOLBAR (g_object_new (EPHY_TYPE_TOOLBAR,
 					   "window", window,
 					   "ui-manager", ephy_window_get_ui_manager (window),
-					   "visibility-path", "/menubar/ViewMenu/ViewTogglesGroup/ToolbarMenu",
+					   "visibility-path", "/menubar/ViewMenu/ViewTogglesGroup/ToolbarMenu/ViewToolbarsGroup",
 					   NULL));
 }
Index: src/ephy-window.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/ephy-window.c,v
retrieving revision 1.342
diff -u -d -r1.342 ephy-window.c
--- src/ephy-window.c	30 Jan 2006 22:13:07 -0000	1.342
+++ src/ephy-window.c	16 Feb 2006 12:52:05 -0000
@@ -280,9 +280,9 @@
 
 	/* View Menu */
 
-	{ "ViewToolbar", NULL, N_("_Show Toolbars"), "<shift><control>T",
+	{ "ViewToolbar", NULL, N_("_Hide Toolbars"), "<shift><control>T",
 	  N_("Show or hide toolbar"),
-	  G_CALLBACK (ephy_window_view_toolbar_cb), TRUE },
+	  G_CALLBACK (ephy_window_view_toolbar_cb), FALSE },
 	{ "ViewStatusbar", NULL, N_("St_atusbar"), NULL,
 	  N_("Show or hide statusbar"),
 	  G_CALLBACK (ephy_window_view_statusbar_cb), TRUE },
@@ -1228,7 +1228,7 @@
 	g_signal_handlers_block_by_func (G_OBJECT (action),
 		 			 G_CALLBACK (ephy_window_view_toolbar_cb),
 		 			 window);
-	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_toolbar);
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), !show_toolbar);
 	g_signal_handlers_unblock_by_func (G_OBJECT (action),
 		 			   G_CALLBACK (ephy_window_view_toolbar_cb),
 		 			   window);
@@ -2805,7 +2805,7 @@
 		g_signal_handlers_unblock_by_func
 			(action, G_CALLBACK (window_cmd_view_fullscreen), window);
 
-		action = gtk_action_group_get_action (action_group, "EditToolbar");
+		action = gtk_action_group_get_action (action_group, "ViewToolbarEditor");
 		ephy_action_change_sensitivity_flags (action, SENS_FLAG_CHROME, fullscreen);
 	}
 
@@ -3652,8 +3652,8 @@
 	gboolean active;
 
 	active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-	window->priv->chrome = active ? window->priv->chrome | chrome_flag :
-					window->priv->chrome & (~chrome_flag);
+	window->priv->chrome = active ? window->priv->chrome & (~chrome_flag) :
+	                                window->priv->chrome | chrome_flag;
 
 	sync_chromes_visibility (window);
 	sync_prefs_with_chrome (window);
Index: src/bookmarks/ephy-bookmarks-ui.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/bookmarks/ephy-bookmarks-ui.c,v
retrieving revision 1.13
diff -u -d -r1.13 ephy-bookmarks-ui.c
--- src/bookmarks/ephy-bookmarks-ui.c	10 Feb 2006 23:25:36 -0000	1.13
+++ src/bookmarks/ephy-bookmarks-ui.c	16 Feb 2006 12:52:05 -0000
@@ -161,12 +161,19 @@
 {
 	GtkAction *baction;
 	GtkWidget *widget;
-
-	widget = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar),
-					  GTK_TYPE_TOOL_ITEM);
-	baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL;
-
-	gtk_action_set_visible (action, EPHY_IS_BOOKMARK_ACTION (baction));
+	gboolean visible;
+	
+	visible = FALSE;
+	
+	if (!egg_editable_toolbar_get_edit_mode (etoolbar))
+	{
+		widget = egg_editable_toolbar_get_selected (etoolbar);
+		widget = widget ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
+		baction = widget ? g_object_get_data (G_OBJECT (widget), "gtk-action") : NULL;
+		visible = EPHY_IS_BOOKMARK_ACTION (baction);
+	}
+	  
+	gtk_action_set_visible (action, visible);
 }
 
 static void
@@ -287,7 +294,7 @@
 	g_object_unref (action);
 
 	/* Add popup menu actions that are specific to the bookmark widgets */
-	action = gtk_action_new ("ToolbarBookmarkProperties", _("Properties"), 
+	action = gtk_action_new ("ToolbarBookmarkProperties", _("_Properties"), 
 				 _("Show properties for this bookmark"), GTK_STOCK_PROPERTIES);
 	g_signal_connect_object (action, "activate",
 				 G_CALLBACK (activate_bookmark_properties), 
@@ -300,7 +307,7 @@
 
 	/* FIXME ngettext */
 	action = gtk_action_new ("ToolbarBookmarkOpenInTab", _("Open in New _Tab"),
-				 _("Open this bookmark in a new tab"), NULL);
+				 _("Open this bookmark in a new tab"), STOCK_NEW_TAB);
 	g_signal_connect_object (action, "activate",
 				 G_CALLBACK (activate_bookmark_open_tab), 
 				 G_OBJECT (etoolbar), 0);
@@ -312,7 +319,7 @@
 
 	/* FIXME ngettext */
 	action = gtk_action_new ("ToolbarBookmarkOpenInWindow", _("Open in New _Window"), 
-				 _("Open this bookmark in a new window"), NULL);
+				 _("Open this bookmark in a new window"), GTK_STOCK_NEW);
 	g_signal_connect_object (action, "activate",
 				 G_CALLBACK (activate_bookmark_open_window),
 				 G_OBJECT (etoolbar), 0);
@@ -324,11 +331,11 @@
 
 	data->toolbar_menu = gtk_ui_manager_add_ui_from_string (manager,
 	   "<popup name=\"ToolbarPopup\">"
-	   "<separator/>"
+	   "<placeholder name=\"SpecificItemsGroup\">"
 	   "<menuitem action=\"ToolbarBookmarkOpenInTab\"/>"
 	   "<menuitem action=\"ToolbarBookmarkOpenInWindow\"/>"
-	   "<separator/>"
 	   "<menuitem action=\"ToolbarBookmarkProperties\"/>"
+	   "</placeholder>"
 	   "</popup>", -1, NULL);  
 
 	/* Add signal handlers for the bookmark database */


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