diff options
author | John Sullivan <sullivan@src.gnome.org> | 1999-12-30 19:14:07 +0000 |
---|---|---|
committer | John Sullivan <sullivan@src.gnome.org> | 1999-12-30 19:14:07 +0000 |
commit | 553e10a47b4708eca9a2b47f0d1613595c3ba308 (patch) | |
tree | faf735c2ee2688c331cc121be6ab25d3f40ba4cc | |
parent | 10b8bbe720e2b832c406b4669de2de6493401e96 (diff) | |
download | nautilus-553e10a47b4708eca9a2b47f0d1613595c3ba308.tar.gz |
Fixed bug with activating bookmarks in any but the first window.
Added working but simple Edit Bookmarks window that allows changing
name & uri, reordering, and deleting bookmarks.
-rw-r--r-- | ChangeLog-20000414 | 34 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/nautilus-bookmark.h | 6 | ||||
-rw-r--r-- | src/nautilus-bookmarklist.c | 48 | ||||
-rw-r--r-- | src/nautilus-bookmarklist.h | 24 | ||||
-rw-r--r-- | src/nautilus-bookmarks-menu.c | 63 | ||||
-rw-r--r-- | src/nautilus-bookmarks-menu.h | 2 |
7 files changed, 151 insertions, 28 deletions
diff --git a/ChangeLog-20000414 b/ChangeLog-20000414 index aeaea2c66..96311e69d 100644 --- a/ChangeLog-20000414 +++ b/ChangeLog-20000414 @@ -1,4 +1,36 @@ -1999-12-28 John Sullivan <sullivan@eazel.com> +1999-12-30 John Sullivan <sullivan@eazel.com> + + The bookmark-editing window is now functional, though simple. + It allows editing names & uris, reordering bookmarks via + dragging in the list, and removing bookmarks. Coming next: + bookmarks persisting across sessions. + + * src/nautilus-bookmarks-window.h: New file. + * src/nautilus-bookmarks-window.c: New file. + * src/Makefile.am: added nautilus-bookmarks-window.[ch] + * src/nautilus-bookmarklist.h, nautilus-bookmarklist.c: + (nautilus_bookmarklist_delete_item_at): New function + (nautilus_bookmarklist_insert_item): New function + * src/nautilus-bookmarks-menu.c: (init): Removed + insensitization of Edit Bookmarks item. + + Added parameter names to prototypes where they were missing + + * src/nautilus-bookmark.h + * src/nautilus-bookmarklist.h + * src/nautilus-bookmarks-menu.h + + Fixed bug where activating bookmarks failed in any but the + first window + + * src/nautilus-bookmarks-menu.c + (bookmark_activated_cb): + (nautilus_bookmarks_menu_repopulate): + Changed bookmark menu items to keep a pointer to their + menu, rather than the menu's window, because sometimes + the menu's window isn't set when the menu item is created. + +1999-12-29 John Sullivan <sullivan@eazel.com> * src/nautilus-bookmarklist.c: (nautilus_bookmarklist_contains): diff --git a/src/Makefile.am b/src/Makefile.am index e6e8ed69c..3bd66ccf7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,8 @@ nautilus_SOURCES= \ nautilus-bookmarklist.c \ nautilus-bookmarks-menu.h \ nautilus-bookmarks-menu.c \ + nautilus-bookmarks-window.h \ + nautilus-bookmarks-window.c \ ntl-app.h \ ntl-app.c \ ntl-content-view.h \ diff --git a/src/nautilus-bookmark.h b/src/nautilus-bookmark.h index 3becbf7f2..e54e8bd09 100644 --- a/src/nautilus-bookmark.h +++ b/src/nautilus-bookmark.h @@ -56,9 +56,9 @@ typedef struct _NautilusBookmarkClass NautilusBookmarkClass; GtkType nautilus_bookmark_get_type (void); NautilusBookmark *nautilus_bookmark_new (const gchar *name, const gchar *uri); -NautilusBookmark *nautilus_bookmark_copy (const NautilusBookmark *); -const gchar *nautilus_bookmark_get_name (const NautilusBookmark *); -const gchar *nautilus_bookmark_get_uri (const NautilusBookmark *); +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); gint nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b); diff --git a/src/nautilus-bookmarklist.c b/src/nautilus-bookmarklist.c index fa0fd909e..82c613c93 100644 --- a/src/nautilus-bookmarklist.c +++ b/src/nautilus-bookmarklist.c @@ -155,7 +155,7 @@ nautilus_bookmarklist_contains (NautilusBookmarklist *bookmarks, * @bookmarks: NautilusBookmarklist whose contents have been modified. **/ void -nautilus_bookmarklist_contents_changed(NautilusBookmarklist *bookmarks) +nautilus_bookmarklist_contents_changed (NautilusBookmarklist *bookmarks) { g_return_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks)); @@ -164,6 +164,52 @@ nautilus_bookmarklist_contents_changed(NautilusBookmarklist *bookmarks) } /** + * nautilus_bookmarklist_delete_item_at: + * + * Deletes the bookmark at the specified position. + * @bookmarks: the list of bookmarks. + * @index: index, must be less than length of list. + **/ +void +nautilus_bookmarklist_delete_item_at (NautilusBookmarklist *bookmarks, + guint index) +{ + GList *doomed; + + g_return_if_fail(NAUTILUS_IS_BOOKMARKLIST (bookmarks)); + g_return_if_fail(index < g_list_length(bookmarks->list)); + + doomed = g_list_nth (bookmarks->list, index); + /* FIXME: free the bookmark here */ + bookmarks->list = g_list_remove_link (bookmarks->list, doomed); + + nautilus_bookmarklist_contents_changed(bookmarks); +} + +/** + * nautilus_bookmarklist_insert_item: + * + * Inserts a bookmark at a specified position. + * @bookmarks: the list of bookmarks. + * @index: the position to insert the bookmark at. + * @new_bookmark: the bookmark to insert a copy of. + **/ +void +nautilus_bookmarklist_insert_item (NautilusBookmarklist *bookmarks, + const NautilusBookmark* new_bookmark, + guint index) +{ + g_return_if_fail(NAUTILUS_IS_BOOKMARKLIST (bookmarks)); + g_return_if_fail(index <= g_list_length(bookmarks->list)); + + bookmarks->list = g_list_insert(bookmarks->list, + nautilus_bookmark_copy(new_bookmark), + index); + + nautilus_bookmarklist_contents_changed(bookmarks); +} + +/** * nautilus_bookmarklist_item_at: * * Get the bookmark at the specified position. diff --git a/src/nautilus-bookmarklist.h b/src/nautilus-bookmarklist.h index 41bb9a49e..9d73997a0 100644 --- a/src/nautilus-bookmarklist.h +++ b/src/nautilus-bookmarklist.h @@ -49,7 +49,7 @@ struct _NautilusBookmarklist { struct _NautilusBookmarklistClass { GtkObjectClass parent_class; - void (* contents_changed) (NautilusBookmarklist *); + void (* contents_changed) (NautilusBookmarklist *bookmarks); }; typedef struct _NautilusBookmarklistClass NautilusBookmarklistClass; @@ -57,13 +57,21 @@ typedef struct _NautilusBookmarklistClass NautilusBookmarklistClass; GtkType nautilus_bookmarklist_get_type (void); NautilusBookmarklist *nautilus_bookmarklist_new (void); -void nautilus_bookmarklist_append (NautilusBookmarklist*, - const NautilusBookmark*); -gboolean nautilus_bookmarklist_contains (NautilusBookmarklist*, - const NautilusBookmark*); +void nautilus_bookmarklist_append (NautilusBookmarklist *bookmarks, + const NautilusBookmark *bookmark); +gboolean nautilus_bookmarklist_contains (NautilusBookmarklist *bookmarks, + const NautilusBookmark *bookmark); void nautilus_bookmarklist_contents_changed - (NautilusBookmarklist *); -guint nautilus_bookmarklist_length (NautilusBookmarklist*); -const NautilusBookmark *nautilus_bookmarklist_item_at (NautilusBookmarklist*, guint); + (NautilusBookmarklist *bookmarks); +void nautilus_bookmarklist_delete_item_at + (NautilusBookmarklist *bookmarks, + guint index); +void nautilus_bookmarklist_insert_item + (NautilusBookmarklist *bookmarks, + const NautilusBookmark *bookmark, + guint index); +guint nautilus_bookmarklist_length (NautilusBookmarklist *bookmarks); +const NautilusBookmark *nautilus_bookmarklist_item_at (NautilusBookmarklist *bookmarks, + guint index); #endif /* NAUTILUS_BOOKMARKLIST_H */ diff --git a/src/nautilus-bookmarks-menu.c b/src/nautilus-bookmarks-menu.c index 8cd2870b0..8255eecc4 100644 --- a/src/nautilus-bookmarks-menu.c +++ b/src/nautilus-bookmarks-menu.c @@ -24,19 +24,23 @@ #include "nautilus.h" #include "nautilus-bookmarks-menu.h" + #include "nautilus-bookmarklist.h" +#include "nautilus-bookmarks-window.h" /* object data strings */ #define LAST_STATIC_ITEM "last static item" -#define WINDOW_TO_UPDATE "window to update" +#define OWNING_MENU "owning menu" /* forward declarations for static functions */ static void add_bookmark_cb (GtkMenuItem *, gpointer); static void bookmark_activated_cb (GtkMenuItem *, gpointer); +static void edit_bookmarks_cb (GtkMenuItem *, gpointer); static void list_changed_cb (NautilusBookmarklist *, gpointer); +static GtkWidget *get_bookmarks_window (void); static void nautilus_bookmarks_menu_append (NautilusBookmarksMenu *, GtkWidget *); static void nautilus_bookmarks_menu_clear_bookmarks (NautilusBookmarksMenu *); @@ -91,6 +95,7 @@ init (NautilusBookmarksMenu *bookmarks_menu) gtk_tearoff_menu_item_new()); } + /* FIXME: Add Bookmark and Edit Bookmarks need accelerators */ item = gtk_menu_item_new_with_label(_("Add Bookmark")); gtk_signal_connect(GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (add_bookmark_cb), @@ -98,11 +103,9 @@ init (NautilusBookmarksMenu *bookmarks_menu) nautilus_bookmarks_menu_append(bookmarks_menu, item); item = gtk_menu_item_new_with_label(_("Edit Bookmarks...")); - /* FIXME: Implement this, currently marked insensitive until implemented. - * I will do this soon, but wanted to get in first cut at other bookmark - * stuff before leaving for holidays. - */ - gtk_widget_set_sensitive(GTK_WIDGET(item), FALSE); + gtk_signal_connect(GTK_OBJECT (item), "activate", + GTK_SIGNAL_FUNC (edit_bookmarks_cb), + NULL); nautilus_bookmarks_menu_append(bookmarks_menu, item); item = gtk_menu_item_new(); @@ -147,25 +150,56 @@ add_bookmark_cb(GtkMenuItem* item, gpointer func_data) static void bookmark_activated_cb(GtkMenuItem* item, gpointer func_data) { - NautilusWindow *window; + NautilusBookmarksMenu *menu; NautilusBookmark *bookmark; - g_return_if_fail(NAUTILUS_IS_WINDOW(gtk_object_get_data(GTK_OBJECT(item), WINDOW_TO_UPDATE))); + g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(gtk_object_get_data(GTK_OBJECT(item), OWNING_MENU))); g_return_if_fail(NAUTILUS_IS_BOOKMARK (func_data)); - window = NAUTILUS_WINDOW(gtk_object_get_data(GTK_OBJECT(item), WINDOW_TO_UPDATE)); + menu = NAUTILUS_BOOKMARKS_MENU(gtk_object_get_data(GTK_OBJECT(item), OWNING_MENU)); bookmark = NAUTILUS_BOOKMARK(func_data); /* FIXME: should check whether we know this to be an invalid uri. * If so, don't try to go there, and put up an alert asking user if * they want to edit bookmarks (or maybe remove this one). */ - nautilus_window_goto_uri(window, nautilus_bookmark_get_uri(bookmark)); + nautilus_window_goto_uri(menu->window, nautilus_bookmark_get_uri(bookmark)); /* FIXME: bookmark created for this signal is never destroyed. */ } static void +edit_bookmarks_cb(GtkMenuItem* item, gpointer func_data) +{ + GtkWidget *gtk_window = get_bookmarks_window(); + if (GTK_WIDGET_VISIBLE(gtk_window)) + { + // Handle behind-other-windows and iconified cases. + // This successfully leaves the window in its original position + // on top of other windows, but unfortunately does not always leave the + // window with focus. Changing window focus programatically is an + // X no-no that we'd like to find a workaround for. + gdk_window_show(gtk_window->window); + } + else + { + gtk_widget_show(gtk_window); + } +} + +static GtkWidget * +get_bookmarks_window() +{ + static GtkWidget *bookmarks_window = NULL; + if (bookmarks_window == NULL) + { + bookmarks_window = create_bookmarks_window(bookmarks); + } + g_assert(GTK_IS_WINDOW(bookmarks_window)); + return bookmarks_window; +} + +static void list_changed_cb(NautilusBookmarklist *bookmarks, gpointer data) { NautilusBookmarksMenu *menu; @@ -260,7 +294,7 @@ nautilus_bookmarks_menu_new (NautilusWindow *window) { NautilusBookmarksMenu *new; - g_return_val_if_fail (window != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_WINDOW (window), NULL); new = gtk_type_new (NAUTILUS_TYPE_BOOKMARKS_MENU); new->window = window; @@ -295,10 +329,11 @@ nautilus_bookmarks_menu_repopulate (NautilusBookmarksMenu *menu) bookmark = nautilus_bookmarklist_item_at(bookmarks, index); item = gtk_menu_item_new_with_label( nautilus_bookmark_get_name(bookmark)); - /* remember the window this menu is attached to */ + + /* remember the menu this item is attached to */ gtk_object_set_data(GTK_OBJECT(item), - WINDOW_TO_UPDATE, - menu->window); + OWNING_MENU, + menu); gtk_signal_connect(GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (bookmark_activated_cb), nautilus_bookmark_new( diff --git a/src/nautilus-bookmarks-menu.h b/src/nautilus-bookmarks-menu.h index f5e886175..475428072 100644 --- a/src/nautilus-bookmarks-menu.h +++ b/src/nautilus-bookmarks-menu.h @@ -53,6 +53,6 @@ typedef struct _NautilusBookmarksMenuClass NautilusBookmarksMenuClass; GtkType nautilus_bookmarks_menu_get_type (void); -GtkWidget *nautilus_bookmarks_menu_new (NautilusWindow*); +GtkWidget *nautilus_bookmarks_menu_new (NautilusWindow *window); #endif /* NAUTILUS_BOOKMARKS_MENU_H */ |