Fix handling of notification of .gtk-bookmark file changes.

2005-06-23  Alexander Larsson  <alexl@redhat.com>

	* src/nautilus-bookmark-list.c:
	Fix handling of notification of .gtk-bookmark file changes.

	* src/Makefile.am:
	* src/nautilus-window-bookmarks.[ch]:
	* src/nautilus-application.c:
	* src/nautilus-navigation-window-menus.c:
	* src/nautilus-navigation-window.[ch]:
	* src/nautilus-spatial-window-ui.xml:
	* src/nautilus-spatial-window.c:
	* src/nautilus-window-menus.c:
	* src/nautilus-window-private.h:
	* src/nautilus-window.[ch]:
	Move most bookmark stuff to nautilus-window-bookmarks and
	put bookmarks in spatial windows too.
This commit is contained in:
Alexander Larsson 2005-06-23 14:16:59 +00:00 committed by Alexander Larsson
parent 199f10b46d
commit 644877a5ee
15 changed files with 444 additions and 284 deletions

View file

@ -1,3 +1,21 @@
2005-06-23 Alexander Larsson <alexl@redhat.com>
* src/nautilus-bookmark-list.c:
Fix handling of notification of .gtk-bookmark file changes.
* src/Makefile.am:
* src/nautilus-window-bookmarks.[ch]:
* src/nautilus-application.c:
* src/nautilus-navigation-window-menus.c:
* src/nautilus-navigation-window.[ch]:
* src/nautilus-spatial-window-ui.xml:
* src/nautilus-spatial-window.c:
* src/nautilus-window-menus.c:
* src/nautilus-window-private.h:
* src/nautilus-window.[ch]:
Move most bookmark stuff to nautilus-window-bookmarks and
put bookmarks in spatial windows too.
2005-06-23 Alexander Larsson <alexl@redhat.com>
Patch from Jamie McCracken <jamiemcc@blueyonder.co.uk>

View file

@ -109,6 +109,8 @@ nautilus_SOURCES = \
nautilus-spatial-window.h \
nautilus-throbber.c \
nautilus-throbber.h \
nautilus-window-bookmarks.c \
nautilus-window-bookmarks.h \
nautilus-window-manage-views.c \
nautilus-window-manage-views.h \
nautilus-window-menus.c \

View file

@ -49,6 +49,7 @@
#include "nautilus-navigation-window.h"
#include "nautilus-shell-interface.h"
#include "nautilus-shell.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-private.h"
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-object.h>

View file

@ -158,16 +158,19 @@ static void
nautilus_bookmark_list_init (NautilusBookmarkList *bookmarks)
{
char *uri;
char *file, *uri;
GnomeVFSResult res;
nautilus_bookmark_list_load_file (bookmarks);
uri = nautilus_bookmark_list_get_file_path ();
gnome_vfs_monitor_add ( &bookmarks->handle,
file = nautilus_bookmark_list_get_file_path ();
uri = gnome_vfs_get_uri_from_local_path (file);
res = gnome_vfs_monitor_add ( &bookmarks->handle,
uri,
GNOME_VFS_MONITOR_FILE,
bookmark_monitor_notify_cb,
bookmarks);
g_free (uri);
g_free (file);
}
EEL_CLASS_BOILERPLATE (NautilusBookmarkList, nautilus_bookmark_list, GTK_TYPE_OBJECT)
@ -573,6 +576,7 @@ nautilus_bookmark_list_save_file (NautilusBookmarkList *bookmarks)
/* temporarily disable bookmark file monitoring when writing file */
if (bookmarks->handle != NULL) {
gnome_vfs_monitor_cancel (bookmarks->handle);
bookmarks->handle = NULL;
}
if (rename (tmp_filename, filename) == -1) {
@ -599,7 +603,6 @@ io_error:
out:
/* re-enable bookmark file monitoring */
gnome_vfs_monitor_add (&bookmarks->handle,
filename,
@ -648,7 +651,8 @@ bookmark_monitor_notify_cb (GnomeVFSMonitorHandle *handle,
GnomeVFSMonitorEventType event_type,
gpointer user_data)
{
if (event_type == GNOME_VFS_MONITOR_EVENT_CHANGED) {
if (event_type == GNOME_VFS_MONITOR_EVENT_CHANGED ||
event_type == GNOME_VFS_MONITOR_EVENT_CREATED) {
g_return_if_fail (NAUTILUS_IS_BOOKMARK_LIST (NAUTILUS_BOOKMARK_LIST(user_data)));
nautilus_bookmark_list_load_file (NAUTILUS_BOOKMARK_LIST(user_data));
g_signal_emit (user_data,

View file

@ -39,10 +39,9 @@
#include "nautilus-signaller.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-private.h"
#include <eel/eel-debug.h>
#include "nautilus-window-bookmarks.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gnome-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>
#include <eel/eel-vfs-extensions.h>
@ -63,20 +62,10 @@
#include <libnautilus-private/nautilus-undo-manager.h>
#define MENU_PATH_HISTORY_PLACEHOLDER "/MenuBar/Other Menus/Go/History Placeholder"
#define MENU_PATH_BOOKMARKS_PLACEHOLDER "/MenuBar/Other Menus/Bookmarks/Bookmarks Placeholder"
#define RESPONSE_FORGET 1000
static GtkWindow *bookmarks_window = NULL;
static NautilusBookmarkList *bookmarks = NULL;
static void schedule_refresh_go_menu (NautilusNavigationWindow *window);
static void append_dynamic_bookmarks (NautilusNavigationWindow *window);
static void schedule_refresh_bookmarks_menu (NautilusNavigationWindow *window);
static void refresh_bookmarks_menu (NautilusNavigationWindow *window);
static void add_bookmark_for_current_location (NautilusNavigationWindow *window);
static void edit_bookmarks (NautilusNavigationWindow *window);
static NautilusBookmarkList *get_bookmark_list (void);
static void
action_close_all_windows_callback (GtkAction *action,
@ -226,178 +215,14 @@ static void
action_add_bookmark_callback (GtkAction *action,
gpointer user_data)
{
add_bookmark_for_current_location (NAUTILUS_NAVIGATION_WINDOW (user_data));
nautilus_window_add_bookmark_for_current_location (NAUTILUS_WINDOW (user_data));
}
static void
action_edit_bookmarks_callback (GtkAction *action,
gpointer user_data)
{
edit_bookmarks (NAUTILUS_NAVIGATION_WINDOW (user_data));
}
static void
free_bookmark_list (void)
{
g_object_unref (bookmarks);
}
static NautilusBookmarkList *
get_bookmark_list (void)
{
if (bookmarks == NULL) {
bookmarks = nautilus_bookmark_list_new ();
eel_debug_call_at_shutdown (free_bookmark_list);
}
return bookmarks;
}
static void
remove_bookmarks_for_uri_if_yes (GtkDialog *dialog, int response, gpointer callback_data)
{
const char *uri;
g_assert (GTK_IS_DIALOG (dialog));
g_assert (callback_data != NULL);
if (response == GTK_RESPONSE_YES) {
uri = callback_data;
nautilus_bookmark_list_delete_items_with_uri (get_bookmark_list (), uri);
}
gtk_object_destroy (GTK_OBJECT (dialog));
}
static void
show_bogus_bookmark_window (NautilusWindow *window,
NautilusBookmark *bookmark)
{
GtkDialog *dialog;
char *uri;
char *uri_for_display;
char *prompt;
char *detail;
uri = nautilus_bookmark_get_uri (bookmark);
uri_for_display = eel_format_uri_for_display (uri);
prompt = _("Do you want to remove any bookmarks with the "
"non-existing location from your list?");
detail = g_strdup_printf (_("The location \"%s\" does not exist."), uri_for_display);
dialog = eel_show_yes_no_dialog (prompt, detail,
_("Bookmark for Nonexistent Location"),
_("Remove"), GTK_STOCK_CANCEL,
GTK_WINDOW (window));
eel_gtk_signal_connect_free_data
(GTK_OBJECT (dialog),
"response",
G_CALLBACK (remove_bookmarks_for_uri_if_yes),
g_strdup (uri));
gtk_dialog_set_default_response (dialog, GTK_RESPONSE_NO);
g_free (uri);
g_free (uri_for_display);
g_free (detail);
}
static GtkWindow *
get_or_create_bookmarks_window (GObject *undo_manager_source)
{
if (bookmarks_window == NULL) {
bookmarks_window = create_bookmarks_window (get_bookmark_list(), undo_manager_source);
} else {
edit_bookmarks_dialog_set_signals (undo_manager_source);
}
return bookmarks_window;
}
/**
* nautilus_bookmarks_exiting:
*
* Last chance to save state before app exits.
* Called when application exits; don't call from anywhere else.
**/
void
nautilus_bookmarks_exiting (void)
{
if (bookmarks_window != NULL) {
nautilus_bookmarks_window_save_geometry (bookmarks_window);
}
}
/**
* add_bookmark_for_current_location
*
* Add a bookmark for the displayed location to the bookmarks menu.
* Does nothing if there's already a bookmark for the displayed location.
*/
static void
add_bookmark_for_current_location (NautilusNavigationWindow *window)
{
NautilusBookmark *bookmark;
g_return_if_fail (NAUTILUS_IS_NAVIGATION_WINDOW (window));
bookmark = NAUTILUS_WINDOW (window)->current_location_bookmark;
if (!nautilus_bookmark_list_contains (get_bookmark_list (), bookmark)) {
nautilus_bookmark_list_append (get_bookmark_list (), bookmark);
}
}
static void
edit_bookmarks (NautilusNavigationWindow *window)
{
GtkWindow *dialog;
dialog = get_or_create_bookmarks_window (G_OBJECT (window));
gtk_window_set_screen (
dialog, gtk_window_get_screen (GTK_WINDOW (window)));
gtk_window_present (dialog);
}
static void
refresh_bookmarks_menu (NautilusNavigationWindow *window)
{
g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
/* Unregister any pending call to this function. */
nautilus_navigation_window_remove_bookmarks_menu_callback (window);
nautilus_navigation_window_remove_bookmarks_menu_items (window);
append_dynamic_bookmarks (window);
}
/**
* nautilus_navigation_window_initialize_bookmarks_menu
*
* Fill in bookmarks menu with stored bookmarks, and wire up signals
* so we'll be notified when bookmark list changes.
*/
static void
nautilus_navigation_window_initialize_bookmarks_menu (NautilusNavigationWindow *window)
{
g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
/* Construct the initial set of bookmarks. */
refresh_bookmarks_menu (window);
/* Recreate dynamic part of menu if bookmark list changes */
g_signal_connect_object (get_bookmark_list (), "contents_changed",
G_CALLBACK (schedule_refresh_bookmarks_menu),
window, G_CONNECT_SWAPPED);
/* Recreate static & dynamic parts of menu if icon theme changes */
g_signal_connect_object (nautilus_icon_factory_get (), "icons_changed",
G_CALLBACK (schedule_refresh_bookmarks_menu),
window, G_CONNECT_SWAPPED);
nautilus_window_edit_bookmarks (NAUTILUS_WINDOW (user_data));
}
void
@ -427,6 +252,30 @@ nautilus_navigation_window_remove_go_menu_items (NautilusNavigationWindow *windo
}
}
static void
show_bogus_history_window (NautilusWindow *window,
NautilusBookmark *bookmark)
{
char *uri;
char *uri_for_display;
char *detail;
uri = nautilus_bookmark_get_uri (bookmark);
uri_for_display = eel_format_uri_for_display (uri);
detail = g_strdup_printf (_("The location \"%s\" does not exist."), uri_for_display);
eel_show_warning_dialog (_("The history location doesn't exist."),
detail,
_("Bookmark for Nonexistent Location"),
GTK_WINDOW (window));
g_free (uri);
g_free (uri_for_display);
g_free (detail);
}
/**
* refresh_go_menu:
*
@ -471,7 +320,7 @@ refresh_go_menu (NautilusNavigationWindow *window)
window->details->go_menu_action_group,
window->details->go_menu_merge_id,
G_CALLBACK (schedule_refresh_go_menu),
show_bogus_bookmark_window);
show_bogus_history_window);
}
}
@ -660,98 +509,5 @@ nautilus_navigation_window_initialize_menus (NautilusNavigationWindow *window)
nautilus_navigation_window_update_show_hide_menu_items (window);
nautilus_navigation_window_initialize_go_menu (window);
nautilus_navigation_window_initialize_bookmarks_menu (window);
}
void
nautilus_navigation_window_remove_bookmarks_menu_callback (NautilusNavigationWindow *window)
{
if (window->details->refresh_bookmarks_menu_idle_id != 0) {
g_source_remove (window->details->refresh_bookmarks_menu_idle_id);
window->details->refresh_bookmarks_menu_idle_id = 0;
}
}
void
nautilus_navigation_window_remove_bookmarks_menu_items (NautilusNavigationWindow *window)
{
GtkUIManager *ui_manager;
ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
if (window->details->bookmarks_merge_id != 0) {
gtk_ui_manager_remove_ui (ui_manager,
window->details->bookmarks_merge_id);
window->details->bookmarks_merge_id = 0;
}
if (window->details->bookmarks_action_group != NULL) {
gtk_ui_manager_remove_action_group (ui_manager,
window->details->bookmarks_action_group);
window->details->bookmarks_action_group = NULL;
}
}
static void
append_dynamic_bookmarks (NautilusNavigationWindow *window)
{
NautilusBookmarkList *bookmarks;
guint bookmark_count;
guint index;
GtkUIManager *ui_manager;
g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
g_assert (window->details->bookmarks_merge_id == 0);
g_assert (window->details->bookmarks_action_group == NULL);
bookmarks = get_bookmark_list ();
ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
window->details->bookmarks_merge_id = gtk_ui_manager_new_merge_id (ui_manager);
window->details->bookmarks_action_group = gtk_action_group_new ("BookmarksGroup");
gtk_ui_manager_insert_action_group (ui_manager,
window->details->bookmarks_action_group,
-1);
g_object_unref (window->details->bookmarks_action_group);
/* append new set of bookmarks */
bookmark_count = nautilus_bookmark_list_length (bookmarks);
for (index = 0; index < bookmark_count; ++index) {
nautilus_menus_append_bookmark_to_menu
(NAUTILUS_WINDOW (window),
nautilus_bookmark_list_item_at (bookmarks, index),
MENU_PATH_BOOKMARKS_PLACEHOLDER,
"dynamic",
index,
window->details->bookmarks_action_group,
window->details->bookmarks_merge_id,
G_CALLBACK (schedule_refresh_bookmarks_menu),
show_bogus_bookmark_window);
}
}
static gboolean
refresh_bookmarks_menu_idle_callback (gpointer data)
{
g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (data));
refresh_bookmarks_menu (NAUTILUS_NAVIGATION_WINDOW (data));
/* Don't call this again (unless rescheduled) */
return FALSE;
}
static void
schedule_refresh_bookmarks_menu (NautilusNavigationWindow *window)
{
g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
if (window->details->refresh_bookmarks_menu_idle_id == 0) {
window->details->refresh_bookmarks_menu_idle_id
= g_idle_add (refresh_bookmarks_menu_idle_callback,
window);
}
}

View file

@ -93,6 +93,8 @@
#define MAX_TITLE_LENGTH 180
#define MENU_PATH_BOOKMARKS_PLACEHOLDER "/MenuBar/Other Menus/Bookmarks/Bookmarks Placeholder"
enum {
ARG_0,
ARG_APP_ID,
@ -435,7 +437,6 @@ nautilus_navigation_window_finalize (GObject *object)
window = NAUTILUS_NAVIGATION_WINDOW (object);
nautilus_navigation_window_remove_bookmarks_menu_callback (window);
nautilus_navigation_window_remove_go_menu_callback (window);
nautilus_navigation_window_clear_back_list (window);
nautilus_navigation_window_clear_forward_list (window);
@ -1090,7 +1091,8 @@ static void
nautilus_navigation_window_class_init (NautilusNavigationWindowClass *class)
{
NAUTILUS_WINDOW_CLASS (class)->window_type = NAUTILUS_WINDOW_NAVIGATION;
NAUTILUS_WINDOW_CLASS (class)->bookmarks_placeholder = MENU_PATH_BOOKMARKS_PLACEHOLDER;
G_OBJECT_CLASS (class)->finalize = nautilus_navigation_window_finalize;
GTK_OBJECT_CLASS (class)->destroy = nautilus_navigation_window_destroy;
GTK_WIDGET_CLASS (class)->show = nautilus_navigation_window_show;

View file

@ -85,7 +85,6 @@ void nautilus_navigation_window_allow_forward (NautilusNavigationWind
void nautilus_navigation_window_clear_back_list (NautilusNavigationWindow *window);
void nautilus_navigation_window_clear_forward_list (NautilusNavigationWindow *window);
void nautilus_forget_history (void);
void nautilus_bookmarks_exiting (void);
gint nautilus_navigation_window_get_base_page_index (NautilusNavigationWindow *window);
void nautilus_navigation_window_hide_location_bar (NautilusNavigationWindow *window,
gboolean save_preference);

View file

@ -17,6 +17,11 @@
<menuitem name="Go to Templates" action="Go to Templates"/>
<menuitem name="Go to Trash" action="Go to Trash"/>
<menuitem name="Go to Burn CD" action="Go to Burn CD"/>
<separator/>
<placeholder name="Bookmarks Placeholder"/>
<separator/>
<menuitem name="Add Bookmark" action="Add Bookmark"/>
<menuitem name="Edit Bookmark" action="Edit Bookmarks"/>
</menu>
</placeholder>
</menubar>

View file

@ -30,6 +30,7 @@
#include <config.h>
#include "nautilus-spatial-window.h"
#include "nautilus-window-private.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-actions.h"
#include "nautilus-application.h"
@ -85,6 +86,7 @@
#define SPATIAL_ACTION_GO_TO_LOCATION "Go to Location"
#define SPATIAL_ACTION_CLOSE_PARENT_FOLDERS "Close Parent Folders"
#define SPATIAL_ACTION_CLOSE_ALL_FOLDERS "Close All Folders"
#define MENU_PATH_SPATIAL_BOOKMARKS_PLACEHOLDER "/MenuBar/Other Menus/Places/Bookmarks Placeholder"
struct _NautilusSpatialWindowDetails {
GtkActionGroup *spatial_action_group; /* owned by ui_manager */
@ -744,6 +746,20 @@ action_go_to_location_callback (GtkAction *action,
nautilus_window_prompt_for_location (window);
}
static void
action_add_bookmark_callback (GtkAction *action,
gpointer user_data)
{
nautilus_window_add_bookmark_for_current_location (NAUTILUS_WINDOW (user_data));
}
static void
action_edit_bookmarks_callback (GtkAction *action,
gpointer user_data)
{
nautilus_window_edit_bookmarks (NAUTILUS_WINDOW (user_data));
}
static const GtkActionEntry spatial_entries[] = {
{ SPATIAL_ACTION_PLACES, NULL, N_("_Places") }, /* name, stock id, label */
{ SPATIAL_ACTION_GO_TO_LOCATION, NULL, N_("Open _Location..."), /* name, stock id, label */
@ -755,6 +771,12 @@ static const GtkActionEntry spatial_entries[] = {
{ SPATIAL_ACTION_CLOSE_ALL_FOLDERS, NULL, N_("Clos_e All Folders"), /* name, stock id, label */
"<control>Q", N_("Close all folder windows"),
G_CALLBACK (action_close_all_folders_callback) },
{ "Add Bookmark", GTK_STOCK_ADD, N_("_Add Bookmark"), /* name, stock id, label */
"<control>d", N_("Add a bookmark for the current location to this menu"),
G_CALLBACK (action_add_bookmark_callback) },
{ "Edit Bookmarks", NULL, N_("_Edit Bookmarks"), /* name, stock id, label */
"<control>b", N_("Display a window that allows editing the bookmarks in this menu"),
G_CALLBACK (action_edit_bookmarks_callback) },
};
static void
@ -859,6 +881,7 @@ nautilus_spatial_window_class_init (NautilusSpatialWindowClass *class)
GtkBindingSet *binding_set;
NAUTILUS_WINDOW_CLASS (class)->window_type = NAUTILUS_WINDOW_SPATIAL;
NAUTILUS_WINDOW_CLASS (class)->bookmarks_placeholder = MENU_PATH_SPATIAL_BOOKMARKS_PLACEHOLDER;
G_OBJECT_CLASS (class)->finalize = nautilus_spatial_window_finalize;
GTK_OBJECT_CLASS (class)->destroy = nautilus_spatial_window_destroy;

View file

@ -0,0 +1,302 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Nautilus
*
* Copyright (C) 2000, 2001 Eazel, Inc.
* Copyright (C) 2005 Red Hat, Inc.
*
* Nautilus is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* Nautilus 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: John Sullivan <sullivan@eazel.com>
* Alexander Larsson <alexl@redhat.com>
*/
#include <config.h>
#include <locale.h>
#include "nautilus-actions.h"
#include "nautilus-bookmark-list.h"
#include "nautilus-bookmarks-window.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-private.h"
#include <libnautilus-private/nautilus-undo-manager.h>
#include <eel/eel-debug.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-gtk-extensions.h>
static GtkWindow *bookmarks_window = NULL;
static NautilusBookmarkList *bookmarks = NULL;
static void schedule_refresh_bookmarks_menu (NautilusWindow *window);
static void
free_bookmark_list (void)
{
g_object_unref (bookmarks);
}
NautilusBookmarkList *
nautilus_get_bookmark_list (void)
{
if (bookmarks == NULL) {
bookmarks = nautilus_bookmark_list_new ();
eel_debug_call_at_shutdown (free_bookmark_list);
}
return bookmarks;
}
static void
remove_bookmarks_for_uri_if_yes (GtkDialog *dialog, int response, gpointer callback_data)
{
const char *uri;
g_assert (GTK_IS_DIALOG (dialog));
g_assert (callback_data != NULL);
if (response == GTK_RESPONSE_YES) {
uri = callback_data;
nautilus_bookmark_list_delete_items_with_uri (nautilus_get_bookmark_list (), uri);
}
gtk_object_destroy (GTK_OBJECT (dialog));
}
static void
show_bogus_bookmark_window (NautilusWindow *window,
NautilusBookmark *bookmark)
{
GtkDialog *dialog;
char *uri;
char *uri_for_display;
char *prompt;
char *detail;
uri = nautilus_bookmark_get_uri (bookmark);
uri_for_display = eel_format_uri_for_display (uri);
prompt = _("Do you want to remove any bookmarks with the "
"non-existing location from your list?");
detail = g_strdup_printf (_("The location \"%s\" does not exist."), uri_for_display);
dialog = eel_show_yes_no_dialog (prompt, detail,
_("Bookmark for Nonexistent Location"),
_("Remove"), GTK_STOCK_CANCEL,
GTK_WINDOW (window));
eel_gtk_signal_connect_free_data
(GTK_OBJECT (dialog),
"response",
G_CALLBACK (remove_bookmarks_for_uri_if_yes),
g_strdup (uri));
gtk_dialog_set_default_response (dialog, GTK_RESPONSE_NO);
g_free (uri);
g_free (uri_for_display);
g_free (detail);
}
static GtkWindow *
get_or_create_bookmarks_window (GObject *undo_manager_source)
{
if (bookmarks_window == NULL) {
bookmarks_window = create_bookmarks_window (nautilus_get_bookmark_list(), undo_manager_source);
} else {
edit_bookmarks_dialog_set_signals (undo_manager_source);
}
return bookmarks_window;
}
/**
* nautilus_bookmarks_exiting:
*
* Last chance to save state before app exits.
* Called when application exits; don't call from anywhere else.
**/
void
nautilus_bookmarks_exiting (void)
{
if (bookmarks_window != NULL) {
nautilus_bookmarks_window_save_geometry (bookmarks_window);
}
}
/**
* add_bookmark_for_current_location
*
* Add a bookmark for the displayed location to the bookmarks menu.
* Does nothing if there's already a bookmark for the displayed location.
*/
void
nautilus_window_add_bookmark_for_current_location (NautilusWindow *window)
{
NautilusBookmark *bookmark;
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
bookmark = window->current_location_bookmark;
if (!nautilus_bookmark_list_contains (nautilus_get_bookmark_list (), bookmark)) {
nautilus_bookmark_list_append (nautilus_get_bookmark_list (), bookmark);
}
}
void
nautilus_window_edit_bookmarks (NautilusWindow *window)
{
GtkWindow *dialog;
dialog = get_or_create_bookmarks_window (G_OBJECT (window));
gtk_window_set_screen (
dialog, gtk_window_get_screen (GTK_WINDOW (window)));
gtk_window_present (dialog);
}
void
nautilus_window_remove_bookmarks_menu_callback (NautilusWindow *window)
{
if (window->details->refresh_bookmarks_menu_idle_id != 0) {
g_source_remove (window->details->refresh_bookmarks_menu_idle_id);
window->details->refresh_bookmarks_menu_idle_id = 0;
}
}
static void
remove_bookmarks_menu_items (NautilusWindow *window)
{
GtkUIManager *ui_manager;
ui_manager = nautilus_window_get_ui_manager (window);
if (window->details->bookmarks_merge_id != 0) {
gtk_ui_manager_remove_ui (ui_manager,
window->details->bookmarks_merge_id);
window->details->bookmarks_merge_id = 0;
}
if (window->details->bookmarks_action_group != NULL) {
gtk_ui_manager_remove_action_group (ui_manager,
window->details->bookmarks_action_group);
window->details->bookmarks_action_group = NULL;
}
}
static void
update_bookmarks (NautilusWindow *window)
{
NautilusBookmarkList *bookmarks;
guint bookmark_count;
guint index;
GtkUIManager *ui_manager;
g_assert (NAUTILUS_IS_WINDOW (window));
g_assert (window->details->bookmarks_merge_id == 0);
g_assert (window->details->bookmarks_action_group == NULL);
bookmarks = nautilus_get_bookmark_list ();
ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
window->details->bookmarks_merge_id = gtk_ui_manager_new_merge_id (ui_manager);
window->details->bookmarks_action_group = gtk_action_group_new ("BookmarksGroup");
gtk_ui_manager_insert_action_group (ui_manager,
window->details->bookmarks_action_group,
-1);
g_object_unref (window->details->bookmarks_action_group);
/* append new set of bookmarks */
bookmark_count = nautilus_bookmark_list_length (bookmarks);
for (index = 0; index < bookmark_count; ++index) {
nautilus_menus_append_bookmark_to_menu
(NAUTILUS_WINDOW (window),
nautilus_bookmark_list_item_at (bookmarks, index),
NAUTILUS_WINDOW_GET_CLASS (window)->bookmarks_placeholder,
"dynamic",
index,
window->details->bookmarks_action_group,
window->details->bookmarks_merge_id,
G_CALLBACK (schedule_refresh_bookmarks_menu),
show_bogus_bookmark_window);
}
}
static void
refresh_bookmarks_menu (NautilusWindow *window)
{
g_assert (NAUTILUS_IS_WINDOW (window));
/* Unregister any pending call to this function. */
nautilus_window_remove_bookmarks_menu_callback (window);
remove_bookmarks_menu_items (window);
update_bookmarks (window);
}
static gboolean
refresh_bookmarks_menu_idle_callback (gpointer data)
{
g_assert (NAUTILUS_IS_WINDOW (data));
refresh_bookmarks_menu (NAUTILUS_WINDOW (data));
/* Don't call this again (unless rescheduled) */
return FALSE;
}
static void
schedule_refresh_bookmarks_menu (NautilusWindow *window)
{
g_assert (NAUTILUS_IS_WINDOW (window));
if (window->details->refresh_bookmarks_menu_idle_id == 0) {
window->details->refresh_bookmarks_menu_idle_id
= g_idle_add (refresh_bookmarks_menu_idle_callback,
window);
}
}
/**
* nautilus_window_initialize_bookmarks_menu
*
* Fill in bookmarks menu with stored bookmarks, and wire up signals
* so we'll be notified when bookmark list changes.
*/
void
nautilus_window_initialize_bookmarks_menu (NautilusWindow *window)
{
g_assert (NAUTILUS_IS_WINDOW (window));
/* Construct the initial set of bookmarks. */
/* We do this in an idle, since this is called in the constructor
* where we don't know the real type of the window */
schedule_refresh_bookmarks_menu (window);
/* Recreate dynamic part of menu if bookmark list changes */
g_signal_connect_object (nautilus_get_bookmark_list (), "contents_changed",
G_CALLBACK (schedule_refresh_bookmarks_menu),
window, G_CONNECT_SWAPPED);
/* Recreate static & dynamic parts of menu if icon theme changes */
g_signal_connect_object (nautilus_icon_factory_get (), "icons_changed",
G_CALLBACK (schedule_refresh_bookmarks_menu),
window, G_CONNECT_SWAPPED);
}

View file

@ -0,0 +1,39 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Nautilus
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Nautilus is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* Nautilus 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#ifndef NAUTILUS_WINDOW_BOOKMARKS_H
#define NAUTILUS_WINDOW_BOOKMARKS_H
#include <libnautilus-private/nautilus-bookmark.h>
#include <nautilus-window.h>
#include "nautilus-bookmark-list.h"
NautilusBookmarkList *nautilus_get_bookmark_list (void);
void nautilus_bookmarks_exiting (void);
void nautilus_window_add_bookmark_for_current_location (NautilusWindow *window);
void nautilus_window_edit_bookmarks (NautilusWindow *window);
void nautilus_window_initialize_bookmarks_menu (NautilusWindow *window);
void nautilus_window_remove_bookmarks_menu_callback (NautilusWindow *window);
#endif

View file

@ -36,6 +36,7 @@
#include "nautilus-property-browser.h"
#include "nautilus-signaller.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-private.h"
#include "nautilus-desktop-window.h"
#include <eel/eel-debug.h>
@ -718,6 +719,8 @@ nautilus_window_initialize_menus (NautilusWindow *window)
action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_GO_TO_BURN_CD);
gtk_action_set_visible (action, FALSE);
}
nautilus_window_initialize_bookmarks_menu (window);
}
static GList *
@ -809,3 +812,5 @@ nautilus_window_load_extension_menus (NautilusWindow *window)
g_list_free (items);
}

View file

@ -61,6 +61,10 @@ struct NautilusWindowDetails
guint extensions_menu_merge_id;
GtkActionGroup *extensions_menu_action_group;
GtkActionGroup *bookmarks_action_group;
guint refresh_bookmarks_menu_idle_id;
guint bookmarks_merge_id;
/* Current location. */
char *location;
char *title;
@ -103,10 +107,6 @@ struct _NautilusNavigationWindowDetails {
NautilusSidebar *current_side_panel;
/* Menus */
GtkActionGroup *bookmarks_action_group;
guint refresh_bookmarks_menu_idle_id;
guint bookmarks_merge_id;
GtkActionGroup *go_menu_action_group;
guint refresh_go_menu_idle_id;
guint go_menu_merge_id;

View file

@ -37,6 +37,7 @@
#include "nautilus-main.h"
#include "nautilus-signaller.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-zoom-control.h"
#include <eel/eel-debug.h>
#include <eel/eel-marshal.h>
@ -535,6 +536,8 @@ nautilus_window_finalize (GObject *object)
window = NAUTILUS_WINDOW (object);
nautilus_window_remove_bookmarks_menu_callback (window);
nautilus_window_manage_views_finalize (window);
nautilus_window_set_viewed_file (window, NULL);

View file

@ -54,6 +54,7 @@ typedef struct {
GtkWindowClass parent_spot;
NautilusWindowType window_type;
const char *bookmarks_placeholder;
/* Function pointers for overriding, without corresponding signals */