Prevented "Add Bookmark" from adding multiple identical bookmarks; fixed

bug about window count; fixed bug where "Add Bookmark" would crash if a
window had been closed previously.
This commit is contained in:
John Sullivan 1999-12-29 00:23:32 +00:00
parent 0650866570
commit 17a18859c6
11 changed files with 147 additions and 54 deletions

View file

@ -1,3 +1,20 @@
1999-12-28 John Sullivan <sullivan@eazel.com>
* 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 <sullivan@eazel.com>
* src/ntl-view.c: (nautilus_view_load_client):

View file

@ -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;
}
}
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;
}

View file

@ -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 */

View file

@ -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:
*

View file

@ -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*);

View file

@ -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));
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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