Commit 60213cdc authored by John Sullivan's avatar John Sullivan
Browse files

Reworked all menu-handling code to do it the BonoboUIHandler way. This will

allow us to start merging menu items into existing menus.
parent 463f4883
2000-02-06 Andy Hertzfeld <andy@eazel.com>
2000-02-28 John Sullivan <sullivan@eazel.com>
Switched NautilusWindow over to using BonoboUIHandler-style
menus. Everything works except that the Go and Bookmarks
menu items don't show icons for now. Apparently the part of
Bonobo that would support using arbitrary GdkPixbufs as
menu item icons is not yet implemented. Other than the
missing items problem, this change has no visible effect,
but is required to support merging items into the standard
menus.
* src/nautilus-bookmarks-menu.h: Deleted this file.
* src/nautilus-bookmarks-menu.c: Deleted this file, moved/morphed its
code into ntl-window.c and nautilus-window-menus.c as appropriate.
* src/nautilus-window-menus.c: New file, avoids making ntl-window.c
any huger by keeping some of the menu-specific stuff in here. Right
now this file includes only stuff I had to change or create for this
checkin. I will soon make another pass at moving a bunch of old menu
code into here.
* src/Makefile.am: Removed deleted files, added new file.
* src/nautilus.h: Removed #include nautilus-bookmarks-menu.h.
* src/ntl-window-msgs.c: Added #include <libnautilus/nautilus-bookmark.h>
that became necessary when nautilus.h changed.
* src/ntl-app.c: (nautilus_app_exiting):
Changed nautilus_bookmarks_menu_exiting to nautilus_bookmarks_exiting,
since there's no menu involved in this code now.
* src/ntl-window-private.h: Added prototypes for functions called
between ntl-window.c and nautilus-window-menus.c.
* src/ntl-window.h: Added prototype for nautilus_bookmarks_exiting;
removed fields for various stored menu items.
* src/ntl-window.c:
Removed #defines for GO_MENU_<foo>_ITEM_INDEX, since menu-item
accessing is now done with paths the Bonobo way.
Removed separator from static part of Go menu; the separator is
now added when the dynamic items are added.
Added static items in Bookmarks menu to GnomeUIInfo array.
(add_bookmark_cb), (edit_bookmarks_cb): New callback functions used
by the static part of the Bookmarks menu.
(clear_go_menu_history), (activate_bookmark_in_menu_item),
(refresh_history_list_in_go_menu): Removed functions; new versions
are in nautilus-window-menus.c.
(nautilus_window_init): Removed go-menu signal connections; new
versions are in nautilus-window-menus.c.
(nautilus_window_constructed): Create and access menus the Bonobo way;
also call functions to initialize the two dynamic menus.
(nautilus_window_allow_back), (nautilus_window_allow_forward),
(nautilus_window_allow_up): Access menu items with paths, the Bonobo way.
(nautilus_get_history_list): New function, wrapper around static
variable so it can be accessed from nautilus-window-menus.c.
2000-02-26 Andy Hertzfeld <andy@eazel.com>
fixed bug where title tab was initially pre-lit
......
......@@ -24,8 +24,6 @@ nautilus_SOURCES= \
explorer-location-bar.h \
nautilus-bookmarklist.c \
nautilus-bookmarklist.h \
nautilus-bookmarks-menu.c \
nautilus-bookmarks-menu.h \
nautilus-bookmarks-window.c \
nautilus-bookmarks-window.h \
nautilus-index-tabs.c \
......@@ -36,6 +34,7 @@ nautilus_SOURCES= \
nautilus-self-check-functions.h \
nautilus-signaller.c \
nautilus-signaller.h \
nautilus-window-menus.c \
nautilus-zoom-control.c \
nautilus-zoom-control.h \
ntl-app.c \
......
......@@ -65,7 +65,7 @@ nautilus_app_exiting()
{
/* Do those things that gotta be done just once before quitting */
nautilus_prefs_save();
nautilus_bookmarks_menu_exiting();
nautilus_bookmarks_exiting();
}
void
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-bookmarks-menu.c - implementation of Bookmarks menu.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: John Sullivan <sullivan@eazel.com>
*/
#include "nautilus.h"
#include "nautilus-bookmarks-menu.h"
#include "nautilus-bookmarklist.h"
#include "nautilus-bookmarks-window.h"
#include <libnautilus/nautilus-gtk-extensions.h>
#include <libnautilus/nautilus-icon-factory.h>
/* object data strings */
#define LAST_STATIC_ITEM "last static item"
#define OWNING_MENU "owning menu"
/* forward declarations for static functions */
static void add_bookmark_cb (GtkMenuItem *, gpointer);
static void bookmark_activated_cb (GtkMenuItem *, gpointer);
static void edit_bookmarks_cb (GtkMenuItem *, gpointer);
static void list_changed_cb (NautilusBookmarklist *,
gpointer);
static GtkWidget *get_bookmarks_window (void);
static void nautilus_bookmarks_menu_append (NautilusBookmarksMenu *,
GtkWidget *);
static void nautilus_bookmarks_menu_clear_bookmarks (NautilusBookmarksMenu *);
static void nautilus_bookmarks_menu_fill (NautilusBookmarksMenu *);
static void nautilus_bookmarks_menu_repopulate (NautilusBookmarksMenu *);
/* static variables */
static GtkMenuClass *parent_class = NULL;
static NautilusBookmarklist *bookmarks = NULL;
/* GtkObject methods. */
static void
destroy (GtkObject *object)
{
if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
static void
finalize (GtkObject *object)
{
if (GTK_OBJECT_CLASS (parent_class)->finalize != NULL)
(* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
}
/* Initialization. */
static void
class_init (NautilusBookmarksMenuClass *class)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (class);
parent_class = gtk_type_class (GTK_TYPE_MENU);
bookmarks = nautilus_bookmarklist_new();
object_class->destroy = destroy;
object_class->finalize = finalize;
}
static void
init (NautilusBookmarksMenu *bookmarks_menu)
{
/* All the work is done in nautilus_bookmarks_new(). This is a little
* unpleasant, but required so that the initialization code can access
* the window parameter to _new().
*/
}
static void
add_bookmark_cb(GtkMenuItem* item, gpointer func_data)
{
NautilusBookmarksMenu *bookmarks_menu;
NautilusBookmark *bookmark;
const char* current_uri;
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU (func_data));
bookmarks_menu = NAUTILUS_BOOKMARKS_MENU (func_data);
current_uri = nautilus_window_get_requested_uri(bookmarks_menu->window);
bookmark = nautilus_bookmark_new(current_uri);
if (!nautilus_bookmarklist_contains(bookmarks, bookmark))
{
nautilus_bookmarklist_append(bookmarks, bookmark);
}
gtk_object_destroy(GTK_OBJECT(bookmark));
}
static void
bookmark_activated_cb(GtkMenuItem* item, gpointer func_data)
{
NautilusBookmarksMenu *menu;
guint item_index;
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(gtk_object_get_data(GTK_OBJECT(item), OWNING_MENU)));
menu = NAUTILUS_BOOKMARKS_MENU(gtk_object_get_data(GTK_OBJECT(item), OWNING_MENU));
item_index = GPOINTER_TO_UINT(func_data);
/* FIXME: should check whether we know this to be an invalid uri.
* If so, don't try to go there, and put up an alert asking user if
* they want to edit bookmarks (or maybe remove this one).
*/
nautilus_window_goto_uri(menu->window,
nautilus_bookmark_get_uri(
nautilus_bookmarklist_item_at(bookmarks, item_index)));
}
static void
edit_bookmarks_cb(GtkMenuItem* item, gpointer ignored)
{
nautilus_gtk_window_present (GTK_WINDOW (get_bookmarks_window()));
}
static GtkWidget *
get_bookmarks_window()
{
static GtkWidget *bookmarks_window = NULL;
if (bookmarks_window == NULL)
{
bookmarks_window = create_bookmarks_window(bookmarks);
}
g_assert(GTK_IS_WINDOW(bookmarks_window));
return bookmarks_window;
}
static void
list_changed_cb(NautilusBookmarklist *bookmarks, gpointer data)
{
NautilusBookmarksMenu *menu;
g_return_if_fail(NAUTILUS_IS_BOOKMARKLIST(bookmarks));
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(data));
menu = NAUTILUS_BOOKMARKS_MENU(data);
nautilus_bookmarks_menu_repopulate(menu);
}
GtkType
nautilus_bookmarks_menu_get_type (void)
{
static GtkType type = 0;
if (type == 0) {
static GtkTypeInfo info = {
"NautilusBookmarksMenu",
sizeof (NautilusBookmarksMenu),
sizeof (NautilusBookmarksMenuClass),
(GtkClassInitFunc) class_init,
(GtkObjectInitFunc) init,
NULL,
NULL,
NULL
};
type = gtk_type_unique (GTK_TYPE_MENU, &info);
}
return type;
}
static void
nautilus_bookmarks_menu_append(NautilusBookmarksMenu *bookmarks_menu, GtkWidget *item)
{
g_return_if_fail(GTK_IS_MENU_ITEM(item));
gtk_widget_show(item);
gtk_menu_append(&(bookmarks_menu->menu), item);
}
/**
* nautilus_bookmarks_menu_clear_bookmarks:
*
* Remove all bookmarks from the menu, leaving static items intact.
* @menu: The NautilusBookmarksMenu whose bookmarks will be removed.
**/
static void
nautilus_bookmarks_menu_clear_bookmarks (NautilusBookmarksMenu *menu)
{
GList *children;
GList *iter;
gboolean found_dynamic_items;
g_return_if_fail (NAUTILUS_IS_BOOKMARKS_MENU (menu));
children = gtk_container_children (GTK_CONTAINER (menu));
iter = children;
found_dynamic_items = FALSE;
while (iter != NULL)
{
if (found_dynamic_items)
{
gtk_container_remove (GTK_CONTAINER (menu), iter->data);
}
else if (gtk_object_get_data (iter->data, LAST_STATIC_ITEM))
{
found_dynamic_items = TRUE;
}
iter = g_list_next (iter);
}
g_list_free (children);
}
/**
* nautilus_bookmarks_menu_exiting:
*
* Last chance to save state before app exits.
* Called when application exits; don't call from anywhere else.
**/
void
nautilus_bookmarks_menu_exiting ()
{
nautilus_bookmarks_window_save_geometry (get_bookmarks_window ());
}
/**
* nautilus_bookmarks_menu_fill:
*
* Starting with a completely empty menu, adds in the static items
* then one for each bookmark. Broken out only for clarity; don't call outside of
* nautilus_bookmarks_menu_new().
* @menu: The freshly-created NautilusBookmarksMenu that needs to be filled in.
**/
static void
nautilus_bookmarks_menu_fill (NautilusBookmarksMenu *menu)
{
GtkWidget *item;
gboolean has_tearoff_item;
GnomeUIInfo static_items[] =
{
{
GNOME_APP_UI_ITEM,
N_("_Add Bookmark"),
N_("Add a bookmark for the current location to this menu."),
(gpointer)add_bookmark_cb, menu, NULL,
GNOME_APP_PIXMAP_NONE, NULL, 0, (GdkModifierType) 0, NULL
},
GNOMEUIINFO_ITEM_NONE(N_("_Edit Bookmarks..."),
N_("Display a window that allows editing the bookmarks in this menu."),
edit_bookmarks_cb),
GNOMEUIINFO_END
};
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(menu));
g_return_if_fail(NAUTILUS_IS_WINDOW(menu->window));
has_tearoff_item = gnome_preferences_get_menus_have_tearoff();
if (has_tearoff_item)
{
nautilus_bookmarks_menu_append(menu,
gtk_tearoff_menu_item_new());
}
gnome_app_fill_menu(GTK_MENU_SHELL(menu),
static_items,
(GNOME_APP(menu->window))->accel_group,
TRUE,
has_tearoff_item ? 1 : 0);
gnome_app_install_menu_hints(GNOME_APP(menu->window), static_items);
item = gtk_menu_item_new();
/* mark this menu item specially so we can recognize it later */
gtk_object_set_data(GTK_OBJECT(item),
LAST_STATIC_ITEM,
GINT_TO_POINTER(TRUE));
nautilus_bookmarks_menu_append(menu, item);
gtk_signal_connect_while_alive(GTK_OBJECT(bookmarks),
"contents_changed",
GTK_SIGNAL_FUNC(list_changed_cb),
menu,
GTK_OBJECT(menu));
nautilus_bookmarks_menu_repopulate(menu);
}
/**
* nautilus_bookmarks_menu_new:
*
* Create a new bookmarks menu for use in @window. It's the caller's
* responsibility to install the menu into the window's menubar.
* @window: The NautilusWindow in which the menu will be installed
*
* Return value: A pointer to the new widget.
**/
GtkWidget *
nautilus_bookmarks_menu_new (NautilusWindow *window)
{
NautilusBookmarksMenu *new_bookmarks_menu;
g_return_val_if_fail (NAUTILUS_IS_WINDOW (window), NULL);
new_bookmarks_menu = gtk_type_new (NAUTILUS_TYPE_BOOKMARKS_MENU);
new_bookmarks_menu->window = window;
nautilus_bookmarks_menu_fill(new_bookmarks_menu);
/* Register to find out about icon theme changes */
gtk_signal_connect_object_while_alive (nautilus_icon_factory_get (),
"theme_changed",
nautilus_bookmarks_menu_repopulate,
GTK_OBJECT (new_bookmarks_menu));
return GTK_WIDGET (new_bookmarks_menu);
}
/**
* nautilus_bookmarks_menu_repopulate:
*
* Refresh list of bookmarks at end of menu to match centralized list.
* @menu: The NautilusBookmarksMenu whose contents will be refreshed.
**/
static void
nautilus_bookmarks_menu_repopulate (NautilusBookmarksMenu *menu)
{
guint bookmark_count;
guint index;
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(menu));
nautilus_bookmarks_menu_clear_bookmarks(menu);
/* append new set of bookmarks */
bookmark_count = nautilus_bookmarklist_length(bookmarks);
for (index = 0; index < bookmark_count; ++index)
{
GtkWidget *item;
item = nautilus_bookmark_menu_item_new (nautilus_bookmarklist_item_at(bookmarks, index));
/* The signal will need to know both the menu that this item is
* attached to (to get at the window), and the bookmark
* that this item represents. The menu is stored as the item
* data. The bookmark is passed as an index. This assumes
* that the signal will not be called on this item if the
* menu is reordered (which is true since the menu is
* repopulated from scratch at that time) */
gtk_object_set_data(GTK_OBJECT(item),
OWNING_MENU,
menu);
gtk_signal_connect(GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (bookmark_activated_cb),
GUINT_TO_POINTER(index));
nautilus_bookmarks_menu_append(menu, item);
}
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-bookmarks-menu.h - public interface for creating a Bookmarks menu.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: John Sullivan <sullivan@eazel.com>
*/
#ifndef NAUTILUS_BOOKMARKS_MENU_H
#define NAUTILUS_BOOKMARKS_MENU_H 1
#include <gnome.h>
#include "nautilus-bookmarklist.h"
typedef struct _NautilusBookmarksMenu NautilusBookmarksMenu;
#define NAUTILUS_TYPE_BOOKMARKS_MENU \
(nautilus_bookmarks_menu_get_type ())
#define NAUTILUS_BOOKMARKS_MENU(obj) \
(GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_BOOKMARKS_MENU, NautilusBookmarksMenu))
#define NAUTILUS_BOOKMARKS_MENU_CLASS(klass) \
(GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_BOOKMARKS_MENU, NautilusBookmarksMenuClass))
#define NAUTILUS_IS_BOOKMARKS_MENU(obj) \
(GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_BOOKMARKS_MENU))
#define NAUTILUS_IS_BOOKMARKS_MENU_CLASS(klass) \
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BOOKMARKS_MENU))
struct _NautilusBookmarksMenu {
GtkMenu menu;
NautilusWindow *window;
};
struct _NautilusBookmarksMenuClass {
GtkMenuClass parent_class;
};
typedef struct _NautilusBookmarksMenuClass NautilusBookmarksMenuClass;
GtkType nautilus_bookmarks_menu_get_type (void);
GtkWidget *nautilus_bookmarks_menu_new (NautilusWindow *window);
void nautilus_bookmarks_menu_exiting (void);
#endif /* NAUTILUS_BOOKMARKS_MENU_H */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-window-menus.h - implementation of nautilus window menu operations,
split into separate file just for convenience.
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: John Sullivan <sullivan@eazel.com>
*/
#include "nautilus-bookmarklist.h"
#include "nautilus-bookmarks-window.h"
#include "nautilus-signaller.h"
#include "ntl-window-private.h"
#include <libnautilus/nautilus-gtk-extensions.h>
#include <libnautilus/nautilus-icon-factory.h>
static void activate_bookmark_in_menu_item (BonoboUIHandler *uih,
gpointer user_data,
const char *path);
static void append_bookmark_to_menu (NautilusWindow *window,
const NautilusBookmark *bookmark,
const char *menu_item_path);
static void append_separator_to_menu (NautilusWindow *window,
const char *separator_path);
static void clear_appended_bookmark_items (NautilusWindow *window,
const char *menu_path,
const char *last_static_item_path);
static NautilusBookmarklist *get_bookmark_list ();
static GtkWidget *get_bookmarks_window ();
static void refresh_bookmarks_in_go_menu (NautilusWindow *window);
static void refresh_bookmarks_in_bookmarks_menu (NautilusWindow *window);
/* Struct that stores all the info necessary to activate a bookmark. */
typedef struct {
const NautilusBookmark *bookmark;
NautilusWindow *window;
} BookmarkHolder;
static void
activate_bookmark_in_menu_item (BonoboUIHandler *uih, gpointer user_data, const char *path)
{
BookmarkHolder *holder = (BookmarkHolder *)user_data;
nautilus_window_goto_uri (holder->window,
nautilus_bookmark_get_uri (holder->bookmark));
}
static void
append_bookmark_to_menu (NautilusWindow *window,
const NautilusBookmark *bookmark,
const char *menu_item_path)
{
BookmarkHolder *bookmark_holder;
bookmark_holder = g_new (BookmarkHolder, 1);
bookmark_holder->window = window;
bookmark_holder->bookmark = bookmark;
/* FIXME: Need to get the bookmark's icon in here, but how? */
bonobo_ui_handler_menu_new_item (window->uih,
menu_item_path,
nautilus_bookmark_get_name (bookmark),
_("Go to the specified location"),
-1,
BONOBO_UI_HANDLER_PIXMAP_NONE,
NULL,
0,
0,
activate_bookmark_in_menu_item,
bookmark_holder);
}
static void
append_separator_to_menu (NautilusWindow *window, const char *separator_path)
{
bonobo_ui_handler_menu_new_item (window->uih,
separator_path,
NULL,
NULL,
-1,