always use the gtk stock icons in toolbars, set the priority property for

2002-05-20  Jorn Baayen  <jorn@nl.linux.org>

	* src/nautilus-shell-ui.xml:
	* src/nautilus-window-private.h:
	* src/nautilus-window-toolbars.c: always use the gtk stock
	icons in toolbars, set the priority property for some buttons,
	add history dropdown buttons, remove rightclick menu.
This commit is contained in:
Jorn Baayen 2002-05-22 16:26:31 +00:00 committed by Alexander Larsson
parent db472a19ee
commit 7adbdb655b
4 changed files with 95 additions and 185 deletions

View file

@ -1,3 +1,11 @@
2002-05-20 Jorn Baayen <jorn@nl.linux.org>
* src/nautilus-shell-ui.xml:
* src/nautilus-window-private.h:
* src/nautilus-window-toolbars.c: always use the gtk stock
icons in toolbars, set the priority property for some buttons,
add history dropdown buttons, remove rightclick menu.
2002-05-22 Eric Baudais <baudais@okstate.edu>
* help/nautilus-user-manual/C/nautilus-user-manual-C.omf

View file

@ -291,24 +291,26 @@
<dockitem name="Toolbar" behavior="exclusive">
<control name="BackWrapper"
min_width="48"
pixtype="stock" pixname="gtk-go-back"/>
<control name="ForwardWrapper"
min_width="48"
pixtype="stock" pixname="gtk-go-forward"/>
<toolitem name="Back"
_label="Back"
priority="1"
pixtype="stock" pixname="gtk-go-back"
verb="Back"/>
<control name="BackMenu"/>
<toolitem name="Forward"
_label="Forward"
pixtype="stock" pixname="gtk-go-forward"
verb="Forward"/>
<control name="ForwardMenu"/>
<toolitem name="Up"
_label="Up"
min_width="48"
pixtype="stock" pixname="gtk-go-up"
verb="Up"/>
<toolitem name="Stop" _label="Stop"
min_width="48"
pixtype="stock" pixname="gtk-stop"
verb="Stop"/>
<toolitem name="Reload"
_label="Reload"
min_width="48"
pixtype="stock" pixname="gtk-refresh"
verb="Reload"/>
@ -316,11 +318,11 @@
<toolitem name="Home"
_label="Home"
min_width="48"
priority="1"
pixtype="stock" pixname="gtk-home"
verb="Home"/>
<toolitem name="Toggle Find Mode"
min_width="48"
priority="1"
type="toggle"
pixtype="stock" pixname="Search"
verb="Toggle Find Mode"/>

View file

@ -62,8 +62,8 @@ struct NautilusWindowDetails
/* Toolbar. */
GtkTooltips *tooltips;
BonoboUIToolbarButtonItem *back_button_item;
BonoboUIToolbarButtonItem *forward_button_item;
BonoboUIToolbarItem *back_button_item;
BonoboUIToolbarItem *forward_button_item;
/* Current location. */
char *location;

View file

@ -44,7 +44,9 @@
#include <eel/eel-string.h>
#include <gtk/gtkframe.h>
#include <gtk/gtktogglebutton.h>
#include <gdk/gdkkeysyms.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-popup-menu.h>
#include <libnautilus-private/nautilus-bonobo-extensions.h>
#include <libnautilus-private/nautilus-bookmark.h>
#include <libnautilus-private/nautilus-file-utilities.h>
@ -124,20 +126,44 @@ create_back_or_forward_menu (NautilusWindow *window, gboolean back)
static GtkWidget *
get_back_button (NautilusWindow *window)
{
return GTK_WIDGET (bonobo_ui_toolbar_button_item_get_button_widget
(window->details->back_button_item));
return GTK_WIDGET (GTK_BIN
(window->details->back_button_item)->child);
}
static GtkWidget *
get_forward_button (NautilusWindow *window)
{
return GTK_WIDGET (bonobo_ui_toolbar_button_item_get_button_widget
(window->details->forward_button_item));
return GTK_WIDGET (GTK_BIN
(window->details->forward_button_item)->child);
}
static int
static void
menu_position_under_widget (GtkMenu *menu, int *x, int *y,
gboolean *push_in, gpointer user_data)
{
GtkWidget *w;
int width, height;
int screen_width, screen_height;
GtkRequisition requisition;
w = GTK_WIDGET (user_data);
gdk_drawable_get_size (w->window, &width, &height);
gdk_window_get_origin (w->window, x, y);
*y = *y + height;
gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
screen_width = gdk_screen_width ();
screen_height = gdk_screen_height ();
*x = CLAMP (*x, 0, MAX (0, screen_width - requisition.width));
*y = CLAMP (*y, 0, MAX (0, screen_height - requisition.height));
}
static gboolean
back_or_forward_button_pressed_callback (GtkWidget *widget,
GdkEventButton *event,
GdkEventButton *event,
gpointer *user_data)
{
NautilusWindow *window;
@ -145,165 +171,37 @@ back_or_forward_button_pressed_callback (GtkWidget *widget,
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);
window = NAUTILUS_WINDOW (user_data);
back = widget == get_back_button (window);
g_assert (back || widget == get_forward_button (window));
if (event->button == 3) {
eel_pop_up_context_menu (
create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
back),
EEL_DEFAULT_POPUP_MENU_DISPLACEMENT,
EEL_DEFAULT_POPUP_MENU_DISPLACEMENT,
event);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
return TRUE;
gnome_popup_menu_do_popup_modal (GTK_WIDGET (create_back_or_forward_menu (NAUTILUS_WINDOW (user_data), back)),
menu_position_under_widget, widget, event, widget, widget);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
return TRUE;
}
static gboolean
back_or_forward_key_pressed_callback (GtkWidget *widget,
GdkEventKey *event,
gpointer *user_data)
{
if (event->keyval == GDK_space ||
event->keyval == GDK_KP_Space ||
event->keyval == GDK_Return ||
event->keyval == GDK_KP_Enter) {
back_or_forward_button_pressed_callback (widget, NULL, user_data);
}
return FALSE;
}
static void
back_or_forward_button_clicked_callback (GtkWidget *widget,
gpointer *user_data)
{
NautilusWindow *window;
gboolean back;
g_return_if_fail (GTK_IS_BUTTON (widget));
g_return_if_fail (NAUTILUS_IS_WINDOW (user_data));
window = NAUTILUS_WINDOW (user_data);
back = widget == get_back_button (window);
g_assert (back || widget == get_forward_button (window));
if (back) {
nautilus_window_go_back (window);
} else {
nautilus_window_go_forward (window);
}
}
static char *
get_file_name_from_icon_name (const char *icon_name, gboolean is_custom)
{
char *full_path_name, *icon_theme, *theme_path_name;
/* look in the theme to see if there's a redirection found; if so, prefer the
* redirection to the ordinary theme look-up */
icon_theme = nautilus_theme_get_theme_data ("toolbar", "icon_theme");
if (icon_theme != NULL) {
/* special case the "standard" theme which indicates using the stock gnome icons,
* except for the custom ones, that are not present in stock
*/
if (!is_custom && eel_strcmp (icon_theme, "standard") == 0) {
g_free (icon_theme);
return NULL;
}
theme_path_name = g_strdup_printf ("%s/%s.png", icon_theme, icon_name);
full_path_name = nautilus_pixmap_file (theme_path_name);
if (full_path_name == NULL) {
full_path_name = nautilus_theme_get_image_path (icon_name);
}
g_free (theme_path_name);
g_free (icon_theme);
} else {
full_path_name = nautilus_theme_get_image_path (icon_name);
}
return full_path_name;
}
static void
set_up_standard_bonobo_button (NautilusWindow *window,
const char *item_path,
const char *icon_name,
const char *stock_item_fallback)
{
char *file_name;
file_name = get_file_name_from_icon_name (icon_name, (stock_item_fallback == NULL));
/* set up the toolbar component with the new image */
bonobo_ui_component_set_prop (window->details->shell_ui,
item_path,
"pixtype",
file_name == NULL ? "stock" : "filename",
NULL);
bonobo_ui_component_set_prop (window->details->shell_ui,
item_path,
"pixname",
file_name == NULL ? stock_item_fallback : file_name,
NULL);
g_free (file_name);
}
/* Use only for toolbar buttons that had to be explicitly created so they
* could have behaviors not present in standard Bonobo toolbar buttons.
*/
static void
set_up_special_bonobo_button (NautilusWindow *window,
BonoboUIToolbarButtonItem *item,
const char *control_path,
const char *icon_name,
const char *stock_item_fallback)
{
char *icon_file_name;
GtkWidget *image;
GtkStockItem stock_item;
image = NULL;
icon_file_name = get_file_name_from_icon_name (icon_name, FALSE);
if (icon_file_name == NULL) {
if (gtk_stock_lookup (stock_item_fallback, &stock_item)) {
image = gtk_image_new_from_stock (stock_item_fallback,
GTK_ICON_SIZE_BUTTON);
}
} else {
image = gtk_image_new_from_file (icon_file_name);
g_free (icon_file_name);
}
if (image == NULL) {
return;
}
bonobo_ui_toolbar_button_item_set_image (item, image);
}
static void
set_up_toolbar_images (NautilusWindow *window)
{
nautilus_window_ui_freeze (window);
bonobo_ui_component_freeze (window->details->shell_ui, NULL);
set_up_special_bonobo_button (window, window->details->back_button_item,
"/Toolbar/BackWrapper", "Back", GTK_STOCK_GO_BACK);
set_up_special_bonobo_button (window, window->details->forward_button_item,
"/Toolbar/ForwardWrapper", "Forward", GTK_STOCK_GO_FORWARD);
set_up_standard_bonobo_button (window, "/Toolbar/Up", "Up", GTK_STOCK_GO_UP);
set_up_standard_bonobo_button (window, "/Toolbar/Home", "Home", GTK_STOCK_HOME);
set_up_standard_bonobo_button (window, "/Toolbar/Reload", "Refresh", GTK_STOCK_REFRESH);
set_up_standard_bonobo_button (window, "/Toolbar/Toggle Find Mode", "Search", GTK_STOCK_FIND);
set_up_standard_bonobo_button (window, "/Toolbar/Stop", "Stop", GTK_STOCK_STOP);
bonobo_ui_component_thaw (window->details->shell_ui, NULL);
nautilus_window_ui_thaw (window);
}
/* handle theme changes */
static void
theme_changed_callback (gpointer callback_data)
@ -312,8 +210,6 @@ theme_changed_callback (gpointer callback_data)
window = NAUTILUS_WINDOW (callback_data);
set_up_toolbar_images (window);
/* if the toolbar is visible, toggle it's visibility to force a relayout */
if (nautilus_window_toolbar_showing (window)) {
nautilus_window_hide_toolbar (window);
@ -352,31 +248,37 @@ back_or_forward_toolbar_item_property_set_cb (BonoboPropertyBag *bag,
}
}
static BonoboUIToolbarButtonItem *
static BonoboUIToolbarItem *
create_back_or_forward_toolbar_item (NautilusWindow *window,
const char *label,
const char *tooltip,
const char *control_path)
{
BonoboUIToolbarButtonItem *item;
BonoboUIToolbarItem *item;
BonoboPropertyBag *pb;
BonoboControl *wrapper;
GtkButton *button;
GtkWidget *button;
item = BONOBO_UI_TOOLBAR_BUTTON_ITEM
(bonobo_ui_toolbar_button_item_new (NULL, label)); /* Fill in image later */
gtk_widget_show (GTK_WIDGET (item));
item = BONOBO_UI_TOOLBAR_ITEM (bonobo_ui_toolbar_item_new ());
button = gtk_toggle_button_new ();
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
gtk_container_add (GTK_CONTAINER (button),
gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT));
gtk_container_add (GTK_CONTAINER (item), button);
gtk_widget_show_all (GTK_WIDGET (item));
button = bonobo_ui_toolbar_button_item_get_button_widget (item);
gtk_tooltips_set_tip (window->details->tooltips,
GTK_WIDGET (button),
tooltip, NULL);
g_signal_connect_object (button, "key_press_event",
G_CALLBACK (back_or_forward_key_pressed_callback),
window, 0);
g_signal_connect_object (button, "button_press_event",
G_CALLBACK (back_or_forward_button_pressed_callback),
window, 0);
g_signal_connect_object (button, "clicked",
G_CALLBACK (back_or_forward_button_clicked_callback),
window, 0);
wrapper = bonobo_control_new (GTK_WIDGET (item));
pb = bonobo_property_bag_new
@ -579,13 +481,11 @@ nautilus_window_initialize_toolbars (NautilusWindow *window)
}
window->details->back_button_item = create_back_or_forward_toolbar_item
(window, _("Back"), _("Go to the previous visited location"),
"/Toolbar/BackWrapper");
(window, _("Go back a few pages"),
"/Toolbar/BackMenu");
window->details->forward_button_item = create_back_or_forward_toolbar_item
(window, _("Forward"), _("Go to the next visited location"),
"/Toolbar/ForwardWrapper");
set_up_toolbar_images (window);
(window, _("Go forward a number of pages"),
"/Toolbar/ForwardMenu");
eel_preferences_add_callback (NAUTILUS_PREFERENCES_THEME,
theme_changed_callback,