gnome-dock patch



Hi,
Here are some patches that add a right click menu to the dock items, to allow
you to hide/show dock-items.
At the moment, if you hide all the items, you can't turn them back on again, but
that can be solved either by having a "# of dockitems shown" counter, or adding
an arg to GnomeDockItem to say whether it can be hidden or not.

If an application wants to have a menu attached to the dock, it can add it's
menu options to the dock->popup_menu.

Iain

--- gnome-libs/libgnomeui/gnome-dock.h	Thu Jan 27 16:16:01 2000
+++ gnome-dock.h	Thu Jan 27 16:16:48 2000
@@ -57,4 +57,5 @@
 
   GtkWidget *client_area;
+  GtkWidget *popup_menu;
 
   /* GnomeDockBands associated with this dock.  */
--- gnome-libs/libgnomeui/gnome-dock.c	Thu Jan 27 16:16:01 2000
+++ gnome-dock.c	Thu Jan 27 16:16:48 2000
@@ -197,4 +197,5 @@
 gnome_dock_init (GnomeDock *dock)
 {
+  GtkWidget *tearoff;
   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (dock), GTK_NO_WINDOW);
 
@@ -209,4 +210,9 @@
 
   dock->floating_items_allowed = TRUE;
+  
+  dock->popup_menu = gtk_menu_new ();
+  tearoff = gtk_tearoff_menu_item_new ();
+  gtk_menu_append (GTK_MENU (dock->popup_menu), tearoff);
+  gtk_widget_show (tearoff);
 }
 
@@ -495,4 +501,8 @@
 
   g_list_foreach (dock->floating_children, map_widget_foreach, NULL);
+
+  gnome_popup_menu_attach (dock->popup_menu,
+			   widget,
+			   NULL);
 }
 
@@ -654,7 +664,12 @@
 {
   GnomeDock *dock;
+  GtkWidget *menuitem;
 
   dock = GNOME_DOCK (container);
 
+  menuitem = gtk_object_get_data (GTK_OBJECT (widget), "menu-item");
+  if (menuitem)
+    gtk_container_remove (GTK_CONTAINER (dock->popup_menu), menuitem);
+
   if (dock->client_area == widget)
     {
@@ -1325,4 +1340,25 @@
 }
 
+static void
+hide_show_item (GtkCheckMenuItem *item,
+		GnomeDock *dock)
+{
+  GtkWidget *dockitem;
+
+  dockitem = gtk_object_get_data (GTK_OBJECT (item), "dock-item");
+  if (!GTK_WIDGET_VISIBLE (dockitem))
+    {
+      gtk_widget_show (dockitem);
+      gtk_check_menu_item_set_active (item, TRUE);
+    }
+  else
+    {
+      gtk_widget_hide (dockitem);
+      gtk_check_menu_item_set_active (item, FALSE);
+    }
+
+  gtk_widget_queue_resize (dock);
+}
+
 /**
  * gnome_dock_add_item:
@@ -1352,4 +1388,5 @@
 {
   GnomeDockBand *band;
+  GtkWidget *menuitem;
   GList **band_ptr;
   GList *p;
@@ -1419,4 +1456,14 @@
 
   gtk_signal_emit (GTK_OBJECT (dock), dock_signals[LAYOUT_CHANGED]);
+  menuitem = gtk_check_menu_item_new_with_label (item->name);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem),
+				  GTK_WIDGET_VISIBLE (item));
+  gtk_object_set_data (GTK_OBJECT (menuitem), "dock-item", item);
+  gtk_object_set_data (GTK_OBJECT (item), "menu-item", menuitem);
+  gtk_object_set_data (GTK_OBJECT (item), "dock", dock);
+  gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
+		      GTK_SIGNAL_FUNC (hide_show_item), dock);
+  gtk_menu_append (GTK_MENU (dock->popup_menu), menuitem);
+  gtk_widget_show (menuitem);
 }
 
@@ -1440,4 +1487,5 @@
 {
   GtkWidget *widget;
+  GtkWidget *menuitem;
 
   g_return_if_fail (GNOME_IS_DOCK_ITEM (item));
@@ -1474,4 +1522,14 @@
 
   gtk_signal_emit (GTK_OBJECT (dock), dock_signals[LAYOUT_CHANGED]);
+  menuitem = gtk_check_menu_item_new_with_label (item->name);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem),
+				  GTK_WIDGET_VISIBLE (item));
+  gtk_object_set_data (GTK_OBJECT (menuitem), "dock-item", item);
+  gtk_object_set_data (GTK_OBJECT (item), "menu-item", menuitem);
+  gtk_object_set_data (GTK_OBJECT (item), "dock", dock);
+  gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
+		      GTK_SIGNAL_FUNC (hide_show_item), dock);
+  gtk_menu_append (GTK_MENU (dock->popup_menu), menuitem);
+  gtk_widget_show (menuitem);
 }
 
--- gnome-libs/libgnomeui/gnome-dock-layout.c	Thu Jan 27 16:16:01 2000
+++ gnome-dock-layout.c	Thu Jan 27 16:16:48 2000
@@ -338,10 +338,19 @@
                                GnomeDockItem *item)
 {
+  GnomeDock *dock;
+  GtkWidget *menuitem;
   GList *list;
 
+  menuitem = gtk_object_get_data (GTK_OBJECT (item), "menu-item");
+  dock = gtk_object_get_data (GTK_OBJECT (item), "dock");
+
+  if (dock && menuitem)
+    gtk_container_remove (GTK_CONTAINER (dock->popup_menu), menuitem);
+
   list = find (layout, item, compare_item_by_pointer);
   if (list == NULL)
     return FALSE;
 
+  g_print ("List %p\n", list);
   remove_item (layout, list);
 



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