Commit e6291e85 authored by Cosimo Cecchi's avatar Cosimo Cecchi

bookmarks: cleanup NautilusWindow bookmark code

- move NautilusBookmarkList ownership to NautilusApplication, and avoid
  making it a separate singleton
- move NautilusBookmarksWindow ownership to NautilusApplication as well,
  since it's global and not per-window
- remove nautilus-window-bookmarks.[ch], since at this point, it only
  contains dead or unused code
parent 2e71ec29
......@@ -154,8 +154,6 @@ nautilus_SOURCES = \
nautilus-view-dnd.h \
nautilus-view-factory.c \
nautilus-view-factory.h \
nautilus-window-bookmarks.c \
nautilus-window-bookmarks.h \
nautilus-window-manage-views.c \
nautilus-window-manage-views.h \
nautilus-window-menus.c \
......
......@@ -34,6 +34,7 @@
#include "nautilus-empty-view.h"
#endif /* ENABLE_EMPTY_VIEW */
#include "nautilus-bookmarks-window.h"
#include "nautilus-connect-server-dialog.h"
#include "nautilus-desktop-icon-view.h"
#include "nautilus-desktop-window.h"
......@@ -46,7 +47,6 @@
#include "nautilus-progress-ui-handler.h"
#include "nautilus-self-check-functions.h"
#include "nautilus-window.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-private.h"
#include "nautilus-window-slot.h"
......@@ -110,8 +110,37 @@ struct _NautilusApplicationPriv {
gchar *geometry;
NotifyNotification *unmount_notify;
GtkWidget *bookmarks_window;
NautilusBookmarkList *bookmark_list;
};
NautilusBookmarkList *
nautilus_application_get_bookmarks (NautilusApplication *application)
{
return application->priv->bookmark_list;
}
void
nautilus_application_edit_bookmarks (NautilusApplication *application,
NautilusWindow *window)
{
GtkWindow *bookmarks_window;
bookmarks_window = GTK_WINDOW (application->priv->bookmarks_window);
if (bookmarks_window == NULL) {
bookmarks_window = nautilus_bookmarks_window_new (window, application->priv->bookmark_list);
application->priv->bookmarks_window = GTK_WIDGET (bookmarks_window);
g_object_add_weak_pointer (G_OBJECT (bookmarks_window),
(gpointer *) &application->priv->bookmarks_window);
}
gtk_window_set_transient_for (bookmarks_window, GTK_WINDOW (window));
gtk_window_set_screen (bookmarks_window, gtk_window_get_screen (GTK_WINDOW (window)));
gtk_window_present (bookmarks_window);
}
void
nautilus_application_notify_unmount_done (NautilusApplication *application,
......@@ -921,6 +950,7 @@ nautilus_application_finalize (GObject *object)
g_clear_object (&application->priv->volume_monitor);
g_clear_object (&application->priv->progress_handler);
g_clear_object (&application->priv->bookmark_list);
g_free (application->priv->geometry);
......@@ -1354,6 +1384,8 @@ nautilus_application_startup (GApplication *app)
g_signal_connect_object (self->priv->volume_monitor, "mount_added",
G_CALLBACK (mount_added_callback), self, 0);
self->priv->bookmark_list = nautilus_bookmark_list_new ();
/* Check the user's ~/.nautilus directories and post warnings
* if there are problems.
*/
......
......@@ -28,6 +28,7 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#include "nautilus-bookmark-list.h"
#include "nautilus-window.h"
#define NAUTILUS_DESKTOP_ICON_VIEW_IID "OAFIID:Nautilus_File_Manager_Desktop_Icon_View"
......@@ -77,4 +78,9 @@ void nautilus_application_notify_unmount_show (NautilusApplication *application,
void nautilus_application_notify_unmount_done (NautilusApplication *application,
const gchar *message);
NautilusBookmarkList *
nautilus_application_get_bookmarks (NautilusApplication *application);
void nautilus_application_edit_bookmarks (NautilusApplication *application,
NautilusWindow *window);
#endif /* __NAUTILUS_APPLICATION_H__ */
......@@ -45,7 +45,6 @@ enum {
};
static guint signals[LAST_SIGNAL];
static NautilusBookmarkList *singleton = NULL;
/* forward declarations */
......@@ -172,34 +171,12 @@ do_finalize (GObject *object)
G_OBJECT_CLASS (nautilus_bookmark_list_parent_class)->finalize (object);
}
static GObject *
do_constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *retval;
if (singleton != NULL) {
return g_object_ref (singleton);
}
retval = G_OBJECT_CLASS (nautilus_bookmark_list_parent_class)->constructor
(type, n_construct_params, construct_params);
singleton = NAUTILUS_BOOKMARK_LIST (retval);
g_object_add_weak_pointer (retval, (gpointer) &singleton);
return retval;
}
static void
nautilus_bookmark_list_class_init (NautilusBookmarkListClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = do_finalize;
object_class->constructor = do_constructor;
signals[CHANGED] =
g_signal_new ("changed",
......
......@@ -3333,7 +3333,6 @@ nautilus_places_sidebar_dispose (GObject *object)
}
g_clear_object (&sidebar->store);
g_clear_object (&sidebar->bookmarks);
if (sidebar->go_to_after_mount_slot) {
g_object_remove_weak_pointer (G_OBJECT (sidebar->go_to_after_mount_slot),
......@@ -3393,12 +3392,13 @@ nautilus_places_sidebar_set_parent_window (NautilusPlacesSidebar *sidebar,
NautilusWindow *window)
{
NautilusWindowSlot *slot;
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
sidebar->window = window;
slot = nautilus_window_get_active_slot (window);
sidebar->bookmarks = nautilus_bookmark_list_new ();
sidebar->bookmarks = nautilus_application_get_bookmarks (app);
sidebar->uri = nautilus_window_slot_get_current_uri (slot);
sidebar->bookmarks_changed_id =
......
/* -*- 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-ui-utilities.h>
#include <eel/eel-debug.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <glib/gi18n.h>
#define MENU_ITEM_MAX_WIDTH_CHARS 32
static GtkWindow *bookmarks_window = NULL;
static void refresh_bookmarks_menu (NautilusWindow *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;
NautilusWindowSlot *slot;
NautilusBookmarkList *list;
slot = nautilus_window_get_active_slot (window);
bookmark = slot->current_location_bookmark;
list = window->details->bookmark_list;
if (!nautilus_bookmark_list_contains (list, bookmark)) {
nautilus_bookmark_list_append (list, bookmark);
}
}
void
nautilus_window_edit_bookmarks (NautilusWindow *window)
{
if (bookmarks_window == NULL) {
bookmarks_window = nautilus_bookmarks_window_new (window, window->details->bookmark_list);
g_object_add_weak_pointer (G_OBJECT (bookmarks_window), (gpointer *) &bookmarks_window);
}
gtk_window_set_transient_for (bookmarks_window, GTK_WINDOW (window));
gtk_window_set_screen (GTK_WINDOW (bookmarks_window), gtk_window_get_screen (GTK_WINDOW (window)));
gtk_window_present (bookmarks_window);
}
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)
{
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);
if (window->details->bookmark_list == NULL) {
window->details->bookmark_list = nautilus_bookmark_list_new ();
}
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);
}
static void
refresh_bookmarks_menu (NautilusWindow *window)
{
g_assert (NAUTILUS_IS_WINDOW (window));
remove_bookmarks_menu_items (window);
update_bookmarks (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));
refresh_bookmarks_menu (window);
}
/* -*- 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"
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);
#endif
......@@ -36,7 +36,6 @@
#include "nautilus-navigation-action.h"
#include "nautilus-notebook.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-private.h"
#include "nautilus-desktop-window.h"
#include <gtk/gtk.h>
......@@ -320,14 +319,27 @@ static void
action_add_bookmark_callback (GtkAction *action,
gpointer user_data)
{
nautilus_window_add_bookmark_for_current_location (NAUTILUS_WINDOW (user_data));
NautilusWindow *window = user_data;
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
NautilusBookmark *bookmark;
NautilusWindowSlot *slot;
NautilusBookmarkList *list;
slot = nautilus_window_get_active_slot (window);
bookmark = slot->current_location_bookmark;
list = nautilus_application_get_bookmarks (app);
if (!nautilus_bookmark_list_contains (list, bookmark)) {
nautilus_bookmark_list_append (list, bookmark);
}
}
static void
action_edit_bookmarks_callback (GtkAction *action,
gpointer user_data)
{
nautilus_window_edit_bookmarks (NAUTILUS_WINDOW (user_data));
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
nautilus_application_edit_bookmarks (app, NAUTILUS_WINDOW (user_data));
}
static void
......
......@@ -45,10 +45,6 @@ struct NautilusWindowDetails
guint extensions_menu_merge_id;
GtkActionGroup *extensions_menu_action_group;
GtkActionGroup *bookmarks_action_group;
guint bookmarks_merge_id;
NautilusBookmarkList *bookmark_list;
NautilusWindowShowHiddenFilesMode show_hidden_files_mode;
/* View As menu */
......
......@@ -41,7 +41,6 @@
#include "nautilus-toolbar.h"
#include "nautilus-view-factory.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-bookmarks.h"
#include "nautilus-window-slot.h"
#include <eel/eel-debug.h>
......@@ -1115,8 +1114,6 @@ nautilus_window_constructed (GObject *self)
gtk_widget_show (window->details->main_view);
window->details->notebook = create_notebook (window);
nautilus_window_initialize_bookmarks_menu (window);
nautilus_window_set_initial_window_geometry (window);
slot = nautilus_window_open_slot (window, 0);
......@@ -1218,7 +1215,6 @@ nautilus_window_finalize (GObject *object)
nautilus_window_finalize_menus (window);
g_clear_object (&window->details->nav_state);
g_clear_object (&window->details->bookmark_list);
g_clear_object (&window->details->ui_manager);
free_stored_viewers (window);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment