diff --git a/ChangeLog-20000414 b/ChangeLog-20000414 index 16aa967ae..c090a3a4d 100644 --- a/ChangeLog-20000414 +++ b/ChangeLog-20000414 @@ -1,3 +1,20 @@ +1999-12-28 John Sullivan + + * src/nautilus-bookmark.[ch]: (nautilus_bookmark_compare_with): + new function, compares two bookmarks for equivalence, used by: + * src/nautilus-bookmarklist.[ch]: (nautilus_bookmarklist_contains): + new function, checks whether a given bookmark is already in the + list, used by: + * src/nautilus-bookmarks-menu.[ch]: + (add_bookmark_cb): now silently refuses to add another bookmark + for the current location if there's one already in the list. + (init): now uses connect_signal_while_alive to avoid nastiness + when trying to add a bookmark after one or more windows were closed. + * src/ntl-window.c: (file_menu_new_window_cb): Now calls + nautilus_app_create_window() instead of creating the new window + in line, so that the window count gets properly updated and closing + windows works correctly. + 1999-12-28 John Sullivan * src/ntl-view.c: (nautilus_view_load_client): diff --git a/src/nautilus-bookmark.c b/src/nautilus-bookmark.c index 69e345937..4c6155806 100644 --- a/src/nautilus-bookmark.c +++ b/src/nautilus-bookmark.c @@ -105,16 +105,41 @@ nautilus_bookmark_get_type (void) } -NautilusBookmark * -nautilus_bookmark_new (const gchar *name, const gchar *uri) +/** + * nautilus_bookmark_compare_with: + * + * Check whether two bookmarks are considered identical. + * @a: first NautilusBookmark*. + * @b: second NautilusBookmark*. + * + * Return value: 0 if @a and @b have same name and uri, 1 otherwise + * (GCompareFunc style) + **/ +gint +nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b) { - NautilusBookmark *new_bookmark; + NautilusBookmark *bookmark_a; + NautilusBookmark *bookmark_b; - new_bookmark = gtk_type_new (NAUTILUS_TYPE_BOOKMARK); - g_string_assign(new_bookmark->name, name); - g_string_assign(new_bookmark->uri, uri); + g_return_val_if_fail(NAUTILUS_IS_BOOKMARK(a), FALSE); + g_return_val_if_fail(NAUTILUS_IS_BOOKMARK(b), FALSE); - return new_bookmark; + bookmark_a = NAUTILUS_BOOKMARK(a); + bookmark_b = NAUTILUS_BOOKMARK(b); + + if (strcmp(nautilus_bookmark_get_name(bookmark_a), + nautilus_bookmark_get_name(bookmark_b)) != 0) + { + return 1; + } + + if (strcmp(nautilus_bookmark_get_uri(bookmark_a), + nautilus_bookmark_get_uri(bookmark_b)) != 0) + { + return 1; + } + + return 0; } const gchar * @@ -127,4 +152,17 @@ const gchar * nautilus_bookmark_get_uri (const NautilusBookmark *bookmark) { return bookmark->uri->str; -} \ No newline at end of file +} + +NautilusBookmark * +nautilus_bookmark_new (const gchar *name, const gchar *uri) +{ + NautilusBookmark *new_bookmark; + + new_bookmark = gtk_type_new (NAUTILUS_TYPE_BOOKMARK); + g_string_assign(new_bookmark->name, name); + g_string_assign(new_bookmark->uri, uri); + + return new_bookmark; +} + diff --git a/src/nautilus-bookmark.h b/src/nautilus-bookmark.h index edbf6f390..e61f40d7b 100644 --- a/src/nautilus-bookmark.h +++ b/src/nautilus-bookmark.h @@ -53,10 +53,12 @@ struct _NautilusBookmarkClass { typedef struct _NautilusBookmarkClass NautilusBookmarkClass; -GtkType nautilus_bookmark_get_type (void); -NautilusBookmark *nautilus_bookmark_new (const gchar *name, - const gchar *uri); -const gchar *nautilus_bookmark_get_name (const NautilusBookmark *); -const gchar *nautilus_bookmark_get_uri (const NautilusBookmark *); +GtkType nautilus_bookmark_get_type (void); +NautilusBookmark *nautilus_bookmark_new (const gchar *name, + const gchar *uri); +const gchar *nautilus_bookmark_get_name (const NautilusBookmark *); +const gchar *nautilus_bookmark_get_uri (const NautilusBookmark *); + +gint nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b); #endif /* NAUTILUS_BOOKMARK_H */ diff --git a/src/nautilus-bookmarklist.c b/src/nautilus-bookmarklist.c index 37e7977c9..32be98860 100644 --- a/src/nautilus-bookmarklist.c +++ b/src/nautilus-bookmarklist.c @@ -111,7 +111,7 @@ nautilus_bookmarklist_get_type (void) * nautilus_bookmarklist_append: * * Append a bookmark to a bookmarklist. - * @list: NautilusBookmarklist to append to. + * @bookmarks: NautilusBookmarklist to append to. * @bookmark: Bookmark to append a copy of. **/ void @@ -128,6 +128,25 @@ nautilus_bookmarklist_append (NautilusBookmarklist *bookmarks, nautilus_bookmarklist_contents_changed(bookmarks); } +/** + * nautilus_bookmarklist_contains: + * + * Check whether a bookmark with matching name and url is already in the list. + * @bookmarks: NautilusBookmarklist to check contents of. + * @bookmark: NautilusBookmark to match against. + * + * Return value: TRUE if matching bookmark is in list, FALSE otherwise + **/ +gboolean +nautilus_bookmarklist_contains (NautilusBookmarklist *bookmarks, + const NautilusBookmark *bookmark) +{ + return g_list_find_custom(bookmarks->list, + (gpointer)bookmark, + nautilus_bookmark_compare_with) + != NULL; +} + /** * nautilus_bookmarklist_contents_changed: * diff --git a/src/nautilus-bookmarklist.h b/src/nautilus-bookmarklist.h index 0be7e8104..41bb9a49e 100644 --- a/src/nautilus-bookmarklist.h +++ b/src/nautilus-bookmarklist.h @@ -59,6 +59,8 @@ 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_contents_changed (NautilusBookmarklist *); guint nautilus_bookmarklist_length (NautilusBookmarklist*); diff --git a/src/nautilus-bookmarks-menu.c b/src/nautilus-bookmarks-menu.c index 9eb7c0124..6709ce9e4 100644 --- a/src/nautilus-bookmarks-menu.c +++ b/src/nautilus-bookmarks-menu.c @@ -112,10 +112,11 @@ init (NautilusBookmarksMenu *bookmarks_menu) GINT_TO_POINTER(TRUE)); nautilus_bookmarks_menu_append(bookmarks_menu, item); - gtk_signal_connect(GTK_OBJECT(bookmarks), - "contents_changed", - GTK_SIGNAL_FUNC(list_changed_cb), - bookmarks_menu); + gtk_signal_connect_while_alive(GTK_OBJECT(bookmarks), + "contents_changed", + GTK_SIGNAL_FUNC(list_changed_cb), + bookmarks_menu, + GTK_OBJECT(bookmarks_menu)); nautilus_bookmarks_menu_repopulate(bookmarks_menu); } @@ -136,7 +137,11 @@ add_bookmark_cb(GtkMenuItem* item, gpointer func_data) /* FIXME: initial name should be extracted from http document title (e.g.) */ bookmark = nautilus_bookmark_new(current_uri, current_uri); - nautilus_bookmarklist_append(bookmarks, bookmark); + + if (!nautilus_bookmarklist_contains(bookmarks, bookmark)) + { + nautilus_bookmarklist_append(bookmarks, bookmark); + } gtk_object_destroy(GTK_OBJECT(bookmark)); } diff --git a/src/nautilus-navigation-window.c b/src/nautilus-navigation-window.c index 8f8771e0a..bbc442706 100644 --- a/src/nautilus-navigation-window.c +++ b/src/nautilus-navigation-window.c @@ -143,17 +143,19 @@ static void file_menu_new_window_cb (GtkWidget *widget, gpointer data) { - GtkWidget *current_mainwin; - GtkWidget *new_mainwin; + NautilusWindow *current_mainwin; + NautilusWindow *new_mainwin; + + g_return_if_fail(NAUTILUS_IS_WINDOW(data)); - current_mainwin = (GtkWidget *)(data); + current_mainwin = NAUTILUS_WINDOW(data); - new_mainwin = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL); + new_mainwin = nautilus_app_create_window(); - nautilus_window_goto_uri(NAUTILUS_WINDOW(new_mainwin), - nautilus_window_get_requested_uri(NAUTILUS_WINDOW(current_mainwin))); + nautilus_window_goto_uri(new_mainwin, + nautilus_window_get_requested_uri(current_mainwin)); - gtk_widget_show(new_mainwin); + gtk_widget_show(GTK_WIDGET(new_mainwin)); } static void diff --git a/src/nautilus-object-window.c b/src/nautilus-object-window.c index 8f8771e0a..bbc442706 100644 --- a/src/nautilus-object-window.c +++ b/src/nautilus-object-window.c @@ -143,17 +143,19 @@ static void file_menu_new_window_cb (GtkWidget *widget, gpointer data) { - GtkWidget *current_mainwin; - GtkWidget *new_mainwin; + NautilusWindow *current_mainwin; + NautilusWindow *new_mainwin; + + g_return_if_fail(NAUTILUS_IS_WINDOW(data)); - current_mainwin = (GtkWidget *)(data); + current_mainwin = NAUTILUS_WINDOW(data); - new_mainwin = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL); + new_mainwin = nautilus_app_create_window(); - nautilus_window_goto_uri(NAUTILUS_WINDOW(new_mainwin), - nautilus_window_get_requested_uri(NAUTILUS_WINDOW(current_mainwin))); + nautilus_window_goto_uri(new_mainwin, + nautilus_window_get_requested_uri(current_mainwin)); - gtk_widget_show(new_mainwin); + gtk_widget_show(GTK_WIDGET(new_mainwin)); } static void diff --git a/src/nautilus-spatial-window.c b/src/nautilus-spatial-window.c index 8f8771e0a..bbc442706 100644 --- a/src/nautilus-spatial-window.c +++ b/src/nautilus-spatial-window.c @@ -143,17 +143,19 @@ static void file_menu_new_window_cb (GtkWidget *widget, gpointer data) { - GtkWidget *current_mainwin; - GtkWidget *new_mainwin; + NautilusWindow *current_mainwin; + NautilusWindow *new_mainwin; + + g_return_if_fail(NAUTILUS_IS_WINDOW(data)); - current_mainwin = (GtkWidget *)(data); + current_mainwin = NAUTILUS_WINDOW(data); - new_mainwin = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL); + new_mainwin = nautilus_app_create_window(); - nautilus_window_goto_uri(NAUTILUS_WINDOW(new_mainwin), - nautilus_window_get_requested_uri(NAUTILUS_WINDOW(current_mainwin))); + nautilus_window_goto_uri(new_mainwin, + nautilus_window_get_requested_uri(current_mainwin)); - gtk_widget_show(new_mainwin); + gtk_widget_show(GTK_WIDGET(new_mainwin)); } static void diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 8f8771e0a..bbc442706 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -143,17 +143,19 @@ static void file_menu_new_window_cb (GtkWidget *widget, gpointer data) { - GtkWidget *current_mainwin; - GtkWidget *new_mainwin; + NautilusWindow *current_mainwin; + NautilusWindow *new_mainwin; + + g_return_if_fail(NAUTILUS_IS_WINDOW(data)); - current_mainwin = (GtkWidget *)(data); + current_mainwin = NAUTILUS_WINDOW(data); - new_mainwin = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL); + new_mainwin = nautilus_app_create_window(); - nautilus_window_goto_uri(NAUTILUS_WINDOW(new_mainwin), - nautilus_window_get_requested_uri(NAUTILUS_WINDOW(current_mainwin))); + nautilus_window_goto_uri(new_mainwin, + nautilus_window_get_requested_uri(current_mainwin)); - gtk_widget_show(new_mainwin); + gtk_widget_show(GTK_WIDGET(new_mainwin)); } static void diff --git a/src/ntl-window.c b/src/ntl-window.c index 8f8771e0a..bbc442706 100644 --- a/src/ntl-window.c +++ b/src/ntl-window.c @@ -143,17 +143,19 @@ static void file_menu_new_window_cb (GtkWidget *widget, gpointer data) { - GtkWidget *current_mainwin; - GtkWidget *new_mainwin; + NautilusWindow *current_mainwin; + NautilusWindow *new_mainwin; + + g_return_if_fail(NAUTILUS_IS_WINDOW(data)); - current_mainwin = (GtkWidget *)(data); + current_mainwin = NAUTILUS_WINDOW(data); - new_mainwin = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL); + new_mainwin = nautilus_app_create_window(); - nautilus_window_goto_uri(NAUTILUS_WINDOW(new_mainwin), - nautilus_window_get_requested_uri(NAUTILUS_WINDOW(current_mainwin))); + nautilus_window_goto_uri(new_mainwin, + nautilus_window_get_requested_uri(current_mainwin)); - gtk_widget_show(new_mainwin); + gtk_widget_show(GTK_WIDGET(new_mainwin)); } static void