Commit 409d8f5d authored by John Sullivan's avatar John Sullivan

Fixed problem with location bar vs. Back button, and moved more toolbar code

into its own file.
parent 1bec035f
2000-03-17 John Sullivan <sullivan@eazel.com>
Fixed bug 322 (going Back goes wacko).
* src/nautilus-location-bar.c:
(nautilus_location_bar_set_location): This function should
not emit the location_changed signal; it's intended only to
update the displayed text. This was causing a location-changing
loop, which for reasons I did not investigate was not infinite.
Added comments to clarify this function's purpose.
Moved some more toolbar-related code into
nautilus_window_toolbars.c.
* src/nautilus-window-toolbars.c,
* src/ntl-window.c: (activate_back_or_forward_menu_item),
(activate_back_menu_item_cb), (activate_forward_menu_item_cb),
(create_back_or_forward_menu), (back_or_forward_button_clicked_cb):
Moved these functions from ntl-window.c to nautilus-window-toolbars.c.
2000-03-17 John Sullivan <sullivan@eazel.com>
Separate out toolbar code as first step towards
......
......@@ -244,16 +244,22 @@ nautilus_location_bar_new (void)
return gtk_widget_new (nautilus_location_bar_get_type (), NULL);
}
/**
* nautilus_location_bar_set_location
*
* Change the text displayed in the location bar.
*
* @bar: A NautilusLocationBar.
* @location: The uri that should be displayed.
*/
void
nautilus_location_bar_set_location (NautilusLocationBar *bar,
const char *location)
{
g_return_if_fail (NAUTILUS_IS_LOCATION_BAR (bar));
/* Note: This is called in reaction to external changes, and
* thus should not emit the LOCATION_CHANGED signal.*/
gtk_entry_set_text (bar->entry,
location == NULL ? "" : location);
gtk_signal_emit (GTK_OBJECT (bar),
signals[LOCATION_CHANGED],
location);
}
......@@ -350,101 +350,6 @@ zoom_out_cb (NautilusZoomControl *zoom_control,
}
}
static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
NautilusWindow *window,
gboolean back)
{
int index;
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)));
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, nautilus_bookmark_get_uri (bookmark));
}
static void
activate_back_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, TRUE);
}
static void
activate_forward_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, FALSE);
}
static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (list_link != NULL)
{
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),
"activate",
back ? activate_back_menu_item_cb : activate_forward_menu_item_cb,
window);
gtk_menu_append (menu, menu_item);
list_link = g_slist_next (list_link);
++index;
}
return menu;
}
static int
back_or_forward_button_clicked_cb (GtkWidget *widget,
GdkEventButton *event,
gpointer *user_data)
{
gboolean back;
g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
back = NAUTILUS_WINDOW (user_data)->back_button == widget;
g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);
if (event->button == 3)
{
nautilus_pop_up_context_menu (
create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
back),
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT);
return TRUE;
}
return FALSE;
}
static void
nautilus_window_constructed(NautilusWindow *window)
......@@ -542,16 +447,6 @@ nautilus_window_constructed(NautilusWindow *window)
nautilus_window_initialize_menus (window);
nautilus_window_initialize_toolbars (window);
gtk_signal_connect (GTK_OBJECT (window->back_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
gtk_signal_connect (GTK_OBJECT (window->forward_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
/* Set initial sensitivity of some buttons & menu items
* now that they're all created.
*/
......
......@@ -350,101 +350,6 @@ zoom_out_cb (NautilusZoomControl *zoom_control,
}
}
static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
NautilusWindow *window,
gboolean back)
{
int index;
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)));
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, nautilus_bookmark_get_uri (bookmark));
}
static void
activate_back_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, TRUE);
}
static void
activate_forward_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, FALSE);
}
static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (list_link != NULL)
{
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),
"activate",
back ? activate_back_menu_item_cb : activate_forward_menu_item_cb,
window);
gtk_menu_append (menu, menu_item);
list_link = g_slist_next (list_link);
++index;
}
return menu;
}
static int
back_or_forward_button_clicked_cb (GtkWidget *widget,
GdkEventButton *event,
gpointer *user_data)
{
gboolean back;
g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
back = NAUTILUS_WINDOW (user_data)->back_button == widget;
g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);
if (event->button == 3)
{
nautilus_pop_up_context_menu (
create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
back),
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT);
return TRUE;
}
return FALSE;
}
static void
nautilus_window_constructed(NautilusWindow *window)
......@@ -542,16 +447,6 @@ nautilus_window_constructed(NautilusWindow *window)
nautilus_window_initialize_menus (window);
nautilus_window_initialize_toolbars (window);
gtk_signal_connect (GTK_OBJECT (window->back_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
gtk_signal_connect (GTK_OBJECT (window->forward_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
/* Set initial sensitivity of some buttons & menu items
* now that they're all created.
*/
......
......@@ -350,101 +350,6 @@ zoom_out_cb (NautilusZoomControl *zoom_control,
}
}
static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
NautilusWindow *window,
gboolean back)
{
int index;
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)));
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, nautilus_bookmark_get_uri (bookmark));
}
static void
activate_back_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, TRUE);
}
static void
activate_forward_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, FALSE);
}
static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (list_link != NULL)
{
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),
"activate",
back ? activate_back_menu_item_cb : activate_forward_menu_item_cb,
window);
gtk_menu_append (menu, menu_item);
list_link = g_slist_next (list_link);
++index;
}
return menu;
}
static int
back_or_forward_button_clicked_cb (GtkWidget *widget,
GdkEventButton *event,
gpointer *user_data)
{
gboolean back;
g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
back = NAUTILUS_WINDOW (user_data)->back_button == widget;
g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);
if (event->button == 3)
{
nautilus_pop_up_context_menu (
create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
back),
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT);
return TRUE;
}
return FALSE;
}
static void
nautilus_window_constructed(NautilusWindow *window)
......@@ -542,16 +447,6 @@ nautilus_window_constructed(NautilusWindow *window)
nautilus_window_initialize_menus (window);
nautilus_window_initialize_toolbars (window);
gtk_signal_connect (GTK_OBJECT (window->back_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
gtk_signal_connect (GTK_OBJECT (window->forward_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
/* Set initial sensitivity of some buttons & menu items
* now that they're all created.
*/
......
......@@ -27,6 +27,8 @@
#include "ntl-app.h"
#include <gnome.h>
#include <libnautilus/nautilus-bookmark.h>
#include <libnautilus/nautilus-gtk-extensions.h>
/* forward declarations */
static void nautilus_window_reload_cb (GtkWidget *widget, NautilusWindow *window);
......@@ -68,6 +70,102 @@ static GnomeUIInfo toolbar_info[] = {
GNOMEUIINFO_END
};
static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
NautilusWindow *window,
gboolean back)
{
int index;
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)));
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, nautilus_bookmark_get_uri (bookmark));
}
static void
activate_back_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, TRUE);
}
static void
activate_forward_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, FALSE);
}
static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (list_link != NULL)
{
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),
"activate",
back ? activate_back_menu_item_cb : activate_forward_menu_item_cb,
window);
gtk_menu_append (menu, menu_item);
list_link = g_slist_next (list_link);
++index;
}
return menu;
}
static int
back_or_forward_button_clicked_cb (GtkWidget *widget,
GdkEventButton *event,
gpointer *user_data)
{
gboolean back;
g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
back = NAUTILUS_WINDOW (user_data)->back_button == widget;
g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);
if (event->button == 3)
{
nautilus_pop_up_context_menu (
create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
back),
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT);
return TRUE;
}
return FALSE;
}
void
nautilus_window_initialize_toolbars (NautilusWindow *window)
{
......@@ -88,6 +186,16 @@ nautilus_window_initialize_toolbars (NautilusWindow *window)
window->up_button = toolbar_info[TOOLBAR_UP_BUTTON_INDEX].widget;
window->reload_button = toolbar_info[TOOLBAR_RELOAD_BUTTON_INDEX].widget;
window->stop_button = toolbar_info[TOOLBAR_STOP_BUTTON_INDEX].widget;
gtk_signal_connect (GTK_OBJECT (window->back_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
gtk_signal_connect (GTK_OBJECT (window->forward_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
}
static void
......
......@@ -350,101 +350,6 @@ zoom_out_cb (NautilusZoomControl *zoom_control,
}
}
static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
NautilusWindow *window,
gboolean back)
{
int index;
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)));
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, nautilus_bookmark_get_uri (bookmark));
}
static void
activate_back_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, TRUE);
}
static void
activate_forward_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
activate_back_or_forward_menu_item (menu_item, window, FALSE);
}
static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
GtkMenu *menu;
GtkWidget *menu_item;
GSList *list_link;
int index;
g_assert (NAUTILUS_IS_WINDOW (window));
menu = GTK_MENU (gtk_menu_new ());
list_link = back ? window->back_list : window->forward_list;
index = 0;
while (list_link != NULL)
{
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),
"activate",
back ? activate_back_menu_item_cb : activate_forward_menu_item_cb,
window);
gtk_menu_append (menu, menu_item);
list_link = g_slist_next (list_link);
++index;
}
return menu;
}
static int
back_or_forward_button_clicked_cb (GtkWidget *widget,
GdkEventButton *event,
gpointer *user_data)
{
gboolean back;
g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
back = NAUTILUS_WINDOW (user_data)->back_button == widget;
g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);
if (event->button == 3)
{
nautilus_pop_up_context_menu (
create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
back),
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT);
return TRUE;
}
return FALSE;
}
static void
nautilus_window_constructed(NautilusWindow *window)
......@@ -542,16 +447,6 @@ nautilus_window_constructed(NautilusWindow *window)
nautilus_window_initialize_menus (window);
nautilus_window_initialize_toolbars (window);
gtk_signal_connect (GTK_OBJECT (window->back_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);
gtk_signal_connect (GTK_OBJECT (window->forward_button),
"button_press_event",
GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb),
window);