Commit ee438780 authored by John Sullivan's avatar John Sullivan
Browse files

Added small icons to the Back and Forward context menus. Made window back and

forward lists store NautilusBookmark pointers instead of just char *.
parent 57ec5705
2000-02-15 John Sullivan <sullivan@eazel.com>
Right-click menus from Back and Forward buttons now include
small icons. To support this, window back/forward lists now
store NautilusBookmarks.
* src/nautilus-bookmarks-menu.c:
(bookmark_menu_item_new): Removed (moved to nautilus-bookmark.c/h,
and renamed nautilus_bookmark_menu_item_new).
(create_pixmap_widget_for_bookmark): Removed (moved to nautilus-bookmark.c/h)
(nautilus_bookmarks_menu_repopulate): updated caller to match name change.
* src/nautilus-bookmark.h:
(nautilus_bookmark_menu_item_new): New function.
* src/nautilus-bookmark.c:
(nautilus_bookmark_menu_item_new): New function, moved over from
nautilus-bookmarks-menu.c
(create_pixmap_widget_for_bookmark): New function, moved over from
nautilus-bookmarks-menu.c
* src/ntl-window.h:
Replaced uris_prev and uris_next with back_list and forward_list.
Added comment explaining that the data is now NautilusBookmark * and
not just char *.
* src/ntl-window-msgs.c:
(nautilus_window_update_internals): updated to use back_list and
forward_list.
* src/ntl-window.c:
(activate_back_or_forward_menu_item), (nautilus_window_destroy):
updated to use back_list and forward_list
(create_back_or_forward_menu): updated to use back_list and
forward_list; use nautilus_bookmark_menu_item_new to get icons.
(nautilus_window_back_or_forward): New function, consolidates
repeated code from nautilus_window_back and nautilus_window_forward.
(nautilus_window_back), (nautilus_window_fwd): Now call
nautilus_window_back_or_forward.
2000-02-15 Andy Hertzfeld <andy@eazel.com>
* src/nautilus-index-tabs/c:
......
......@@ -34,6 +34,8 @@ struct _NautilusBookmarkDetails
static GtkWidget *create_pixmap_widget_for_bookmark (const NautilusBookmark *bookmark);
static GtkObjectClass *parent_class = NULL;
/* GtkObject methods. */
......@@ -219,3 +221,60 @@ nautilus_bookmark_new (const gchar *name, const gchar *uri)
return new_bookmark;
}
static GtkWidget *
create_pixmap_widget_for_bookmark (const NautilusBookmark *bookmark)
{
GdkPixmap *gdk_pixmap;
GdkBitmap *mask;
if (!nautilus_bookmark_get_pixmap_and_mask (bookmark,
NAUTILUS_ICON_SIZE_SMALLER,
&gdk_pixmap,
&mask))
{
return NULL;
}
return gtk_pixmap_new (gdk_pixmap, mask);
}
/**
* nautilus_bookmark_menu_item_new:
*
* Return a menu item representing a bookmark.
* @bookmark: The bookmark the menu item represents.
* Return value: A newly-created bookmark.
**/
GtkWidget *
nautilus_bookmark_menu_item_new (const NautilusBookmark *bookmark)
{
GtkWidget *menu_item;
GtkWidget *pixmap_widget;
GtkWidget *accel_label;
/* Could check gnome_preferences_get_menus_have_icons here, but these
* are more important than stock menu icons, since they're connected to
* user data. For now let's not let them be turn-offable and see if
* anyone objects strenuously.
*/
menu_item = gtk_pixmap_menu_item_new ();
pixmap_widget = create_pixmap_widget_for_bookmark (bookmark);
if (pixmap_widget != NULL)
{
gtk_widget_show (pixmap_widget);
gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menu_item), pixmap_widget);
}
accel_label = gtk_accel_label_new (nautilus_bookmark_get_name (bookmark));
gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (menu_item), accel_label);
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), menu_item);
gtk_widget_show (accel_label);
return menu_item;
}
......@@ -59,15 +59,19 @@ NautilusBookmark *nautilus_bookmark_new (const gchar *name,
const gchar *uri);
NautilusBookmark *nautilus_bookmark_copy (const NautilusBookmark *bookmark);
const gchar *nautilus_bookmark_get_name (const NautilusBookmark *bookmark);
const gchar *nautilus_bookmark_get_uri (const NautilusBookmark *bookmark);
const gchar *nautilus_bookmark_get_uri (const NautilusBookmark *bookmark);
gint nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b);
/* Helper functions for displaying bookmarks */
gboolean nautilus_bookmark_get_pixmap_and_mask
(const NautilusBookmark *bookmark,
guint icon_size,
GdkPixmap **pixmap_return,
GdkBitmap **mask_return);
GtkWidget * nautilus_bookmark_menu_item_new
(const NautilusBookmark *bookmark);
gint nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b);
#endif /* NAUTILUS_BOOKMARK_H */
......@@ -39,8 +39,6 @@
static void add_bookmark_cb (GtkMenuItem *, gpointer);
static void bookmark_activated_cb (GtkMenuItem *, gpointer);
GtkWidget * bookmark_menu_item_new (const NautilusBookmark *bookmark);
static GtkWidget *create_pixmap_widget_for_bookmark (const NautilusBookmark *bookmark);
static void edit_bookmarks_cb (GtkMenuItem *, gpointer);
static void list_changed_cb (NautilusBookmarklist *,
gpointer);
......@@ -140,61 +138,6 @@ bookmark_activated_cb(GtkMenuItem* item, gpointer func_data)
nautilus_bookmarklist_item_at(bookmarks, item_index)));
}
static GtkWidget *
create_pixmap_widget_for_bookmark (const NautilusBookmark *bookmark)
{
GdkPixmap *gdk_pixmap;
GdkBitmap *mask;
if (!nautilus_bookmark_get_pixmap_and_mask (bookmark,
NAUTILUS_ICON_SIZE_SMALLER,
&gdk_pixmap,
&mask))
{
return NULL;
}
return gtk_pixmap_new (gdk_pixmap, mask);
}
/**
* bookmark_menu_item_new:
*
* Return a menu item representing a bookmark.
* @bookmark: The bookmark the menu item represents.
* Return value: A newly-created bookmark.
**/
GtkWidget *
bookmark_menu_item_new (const NautilusBookmark *bookmark)
{
GtkWidget *menu_item;
GtkWidget *pixmap_widget;
GtkWidget *accel_label;
/* Could check gnome_preferences_get_menus_have_icons here, but these
* are more important than stock menu icons, since they're connected to
* user data. For now let's not let them be turn-offable and see if
* anyone objects strenuously.
*/
menu_item = gtk_pixmap_menu_item_new ();
pixmap_widget = create_pixmap_widget_for_bookmark (bookmark);
if (pixmap_widget != NULL)
{
gtk_widget_show (pixmap_widget);
gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menu_item), pixmap_widget);
}
accel_label = gtk_accel_label_new (nautilus_bookmark_get_name (bookmark));
gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (menu_item), accel_label);
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), menu_item);
gtk_widget_show (accel_label);
return menu_item;
}
static void
edit_bookmarks_cb(GtkMenuItem* item, gpointer ignored)
{
......@@ -414,7 +357,7 @@ nautilus_bookmarks_menu_repopulate (NautilusBookmarksMenu *menu)
{
GtkWidget *item;
item = bookmark_menu_item_new (nautilus_bookmarklist_item_at(bookmarks, index));
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
......
......@@ -465,19 +465,21 @@ activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
gboolean back)
{
int index;
const char *uri;
NautilusBookmark *bookmark;
g_assert (GTK_IS_MENU_ITEM (menu_item));
g_assert (NAUTILUS_IS_WINDOW (window));
index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (menu_item)));
uri = g_slist_nth_data (back ? window->uris_prev : window->uris_next, index);
bookmark = NAUTILUS_BOOKMARK (g_slist_nth_data (back ? window->back_list
: window->forward_list,
index));
/* FIXME: This should do the equivalent of going back or forward n times,
* rather than just going to the right uri. This is needed to
* keep the back/forward chain intact.
*/
nautilus_window_goto_uri (window, uri);
*/
nautilus_window_goto_uri (window, nautilus_bookmark_get_uri (bookmark));
}
static void
......@@ -497,18 +499,18 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *uri_in_list;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
uri_in_list = back ? window->uris_prev : window->uris_next;
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (uri_in_list != NULL)
while (list_link != NULL)
{
menu_item = gtk_menu_item_new_with_label (uri_in_list->data);
menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list_link->data));
gtk_object_set_user_data (GTK_OBJECT (menu_item), GINT_TO_POINTER (index));
gtk_widget_show (GTK_WIDGET (menu_item));
gtk_signal_connect(GTK_OBJECT(menu_item),
......@@ -517,7 +519,7 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
window);
gtk_menu_append (menu, menu_item);
uri_in_list = g_slist_next (uri_in_list);
list_link = g_slist_next (list_link);
++index;
}
......@@ -751,10 +753,10 @@ static void nautilus_window_destroy (NautilusWindow *window)
g_slist_free(window->meta_views);
CORBA_free(window->ni);
CORBA_free(window->si);
g_slist_foreach(window->uris_prev, (GFunc)g_free, NULL);
g_slist_foreach(window->uris_next, (GFunc)g_free, NULL);
g_slist_free(window->uris_prev);
g_slist_free(window->uris_next);
g_slist_foreach(window->back_list, (GFunc)gtk_object_unref, NULL);
g_slist_foreach(window->forward_list, (GFunc)gtk_object_unref, NULL);
g_slist_free(window->back_list);
g_slist_free(window->forward_list);
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
......@@ -917,30 +919,33 @@ nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view
/* FIXME: Factor toolbar stuff out into ntl-window-toolbar.c */
static void
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
nautilus_window_back_or_forward (NautilusWindow *window, gboolean back)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_prev);
g_assert(back ? window->back_list : window->forward_list);
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_prev->data;
/* FIXME: Have to cast away the const for nri.requested_uri. This field should be
* declared const. */
nri.requested_uri = (char *)nautilus_bookmark_get_uri (back ?
window->back_list->data :
window->forward_list->data);
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, TRUE, FALSE);
nautilus_window_change_location(window, &nri, NULL, back, FALSE);
}
static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_next);
nautilus_window_back_or_forward (window, TRUE);
}
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_next->data;
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, FALSE, FALSE);
static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
{
nautilus_window_back_or_forward (window, FALSE);
}
const char *
......
......@@ -70,8 +70,9 @@ struct _NautilusWindow {
/* Information about current location/selection */
Nautilus_NavigationInfo *ni;
Nautilus_SelectionInfo *si;
/* History stuff */
GSList *uris_prev, *uris_next;
/* Back/Forward chain stuff. The data in these lists are NautilusBookmark pointers. */
GSList *back_list, *forward_list;
/* Current views stuff */
NautilusView *content_view;
......
......@@ -465,19 +465,21 @@ activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
gboolean back)
{
int index;
const char *uri;
NautilusBookmark *bookmark;
g_assert (GTK_IS_MENU_ITEM (menu_item));
g_assert (NAUTILUS_IS_WINDOW (window));
index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (menu_item)));
uri = g_slist_nth_data (back ? window->uris_prev : window->uris_next, index);
bookmark = NAUTILUS_BOOKMARK (g_slist_nth_data (back ? window->back_list
: window->forward_list,
index));
/* FIXME: This should do the equivalent of going back or forward n times,
* rather than just going to the right uri. This is needed to
* keep the back/forward chain intact.
*/
nautilus_window_goto_uri (window, uri);
*/
nautilus_window_goto_uri (window, nautilus_bookmark_get_uri (bookmark));
}
static void
......@@ -497,18 +499,18 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *uri_in_list;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
uri_in_list = back ? window->uris_prev : window->uris_next;
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (uri_in_list != NULL)
while (list_link != NULL)
{
menu_item = gtk_menu_item_new_with_label (uri_in_list->data);
menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list_link->data));
gtk_object_set_user_data (GTK_OBJECT (menu_item), GINT_TO_POINTER (index));
gtk_widget_show (GTK_WIDGET (menu_item));
gtk_signal_connect(GTK_OBJECT(menu_item),
......@@ -517,7 +519,7 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
window);
gtk_menu_append (menu, menu_item);
uri_in_list = g_slist_next (uri_in_list);
list_link = g_slist_next (list_link);
++index;
}
......@@ -751,10 +753,10 @@ static void nautilus_window_destroy (NautilusWindow *window)
g_slist_free(window->meta_views);
CORBA_free(window->ni);
CORBA_free(window->si);
g_slist_foreach(window->uris_prev, (GFunc)g_free, NULL);
g_slist_foreach(window->uris_next, (GFunc)g_free, NULL);
g_slist_free(window->uris_prev);
g_slist_free(window->uris_next);
g_slist_foreach(window->back_list, (GFunc)gtk_object_unref, NULL);
g_slist_foreach(window->forward_list, (GFunc)gtk_object_unref, NULL);
g_slist_free(window->back_list);
g_slist_free(window->forward_list);
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
......@@ -917,30 +919,33 @@ nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view
/* FIXME: Factor toolbar stuff out into ntl-window-toolbar.c */
static void
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
nautilus_window_back_or_forward (NautilusWindow *window, gboolean back)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_prev);
g_assert(back ? window->back_list : window->forward_list);
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_prev->data;
/* FIXME: Have to cast away the const for nri.requested_uri. This field should be
* declared const. */
nri.requested_uri = (char *)nautilus_bookmark_get_uri (back ?
window->back_list->data :
window->forward_list->data);
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, TRUE, FALSE);
nautilus_window_change_location(window, &nri, NULL, back, FALSE);
}
static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_next);
nautilus_window_back_or_forward (window, TRUE);
}
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_next->data;
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, FALSE, FALSE);
static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
{
nautilus_window_back_or_forward (window, FALSE);
}
const char *
......
......@@ -70,8 +70,9 @@ struct _NautilusWindow {
/* Information about current location/selection */
Nautilus_NavigationInfo *ni;
Nautilus_SelectionInfo *si;
/* History stuff */
GSList *uris_prev, *uris_next;
/* Back/Forward chain stuff. The data in these lists are NautilusBookmark pointers. */
GSList *back_list, *forward_list;
/* Current views stuff */
NautilusView *content_view;
......
......@@ -465,19 +465,21 @@ activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
gboolean back)
{
int index;
const char *uri;
NautilusBookmark *bookmark;
g_assert (GTK_IS_MENU_ITEM (menu_item));
g_assert (NAUTILUS_IS_WINDOW (window));
index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (menu_item)));
uri = g_slist_nth_data (back ? window->uris_prev : window->uris_next, index);
bookmark = NAUTILUS_BOOKMARK (g_slist_nth_data (back ? window->back_list
: window->forward_list,
index));
/* FIXME: This should do the equivalent of going back or forward n times,
* rather than just going to the right uri. This is needed to
* keep the back/forward chain intact.
*/
nautilus_window_goto_uri (window, uri);
*/
nautilus_window_goto_uri (window, nautilus_bookmark_get_uri (bookmark));
}
static void
......@@ -497,18 +499,18 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *uri_in_list;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
uri_in_list = back ? window->uris_prev : window->uris_next;
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (uri_in_list != NULL)
while (list_link != NULL)
{
menu_item = gtk_menu_item_new_with_label (uri_in_list->data);
menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list_link->data));
gtk_object_set_user_data (GTK_OBJECT (menu_item), GINT_TO_POINTER (index));
gtk_widget_show (GTK_WIDGET (menu_item));
gtk_signal_connect(GTK_OBJECT(menu_item),
......@@ -517,7 +519,7 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
window);
gtk_menu_append (menu, menu_item);
uri_in_list = g_slist_next (uri_in_list);
list_link = g_slist_next (list_link);
++index;
}
......@@ -751,10 +753,10 @@ static void nautilus_window_destroy (NautilusWindow *window)
g_slist_free(window->meta_views);
CORBA_free(window->ni);
CORBA_free(window->si);
g_slist_foreach(window->uris_prev, (GFunc)g_free, NULL);
g_slist_foreach(window->uris_next, (GFunc)g_free, NULL);
g_slist_free(window->uris_prev);
g_slist_free(window->uris_next);
g_slist_foreach(window->back_list, (GFunc)gtk_object_unref, NULL);
g_slist_foreach(window->forward_list, (GFunc)gtk_object_unref, NULL);
g_slist_free(window->back_list);
g_slist_free(window->forward_list);
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
......@@ -917,30 +919,33 @@ nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view
/* FIXME: Factor toolbar stuff out into ntl-window-toolbar.c */
static void
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
nautilus_window_back_or_forward (NautilusWindow *window, gboolean back)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_prev);
g_assert(back ? window->back_list : window->forward_list);
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_prev->data;
/* FIXME: Have to cast away the const for nri.requested_uri. This field should be
* declared const. */
nri.requested_uri = (char *)nautilus_bookmark_get_uri (back ?
window->back_list->data :
window->forward_list->data);
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, TRUE, FALSE);
nautilus_window_change_location(window, &nri, NULL, back, FALSE);
}
static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_next);
nautilus_window_back_or_forward (window, TRUE);
}
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_next->data;
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, FALSE, FALSE);
static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
{
nautilus_window_back_or_forward (window, FALSE);
}
const char *
......
......@@ -70,8 +70,9 @@ struct _NautilusWindow {
/* Information about current location/selection */