static void bookmarks_delete_bookmark (void) { GtkTreeIter iter; GtkTreePath *path; gint *indices, row, rows; g_assert (GTK_IS_TREE_VIEW (bookmark_list_widget)); if (!gtk_tree_selection_get_selected (bookmark_selection, NULL, &iter)) return; /* Remove the selected item from the list store. on_row_deleted() will remove it from the bookmark list. */ path = gtk_tree_model_get_path (GTK_TREE_MODEL (bookmark_list_store), &iter); indices = gtk_tree_path_get_indices (path); row = indices[0]; gtk_tree_path_free (path); gtk_list_store_remove (bookmark_list_store, &iter); /* Try to select the same row, or the last one in the list. */ rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (bookmark_list_store), NULL); if (row >= rows) row = rows - 1; if (row < 0) { bookmarks_set_empty (TRUE); } else { gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (bookmark_list_store), &iter, NULL, row); gtk_tree_selection_select_iter (bookmark_selection, &iter); } }
static void bookmarks_delete_bookmark (NautilusBookmarksWindow *self) { GtkTreeIter iter; GtkTreePath *path; gint *indices, row, rows; if (!gtk_tree_selection_get_selected (self->priv->selection, NULL, &iter)) { return; } /* Remove the selected item from the list store. on_row_deleted() will remove it from the bookmark list. */ path = gtk_tree_model_get_path (GTK_TREE_MODEL (self->priv->model), &iter); indices = gtk_tree_path_get_indices (path); row = indices[0]; gtk_tree_path_free (path); gtk_list_store_remove (self->priv->model, &iter); /* Try to select the same row, or the last one in the list. */ rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (self->priv->model), NULL); if (row >= rows) { row = rows - 1; } if (row < 0) { bookmarks_set_empty (self, TRUE); } else { gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (self->priv->model), &iter, NULL, row); gtk_tree_selection_select_iter (self->priv->selection, &iter); } }
static void repopulate (void) { NautilusBookmark *selected; GtkListStore *store; GtkTreePath *path; GtkTreeRowReference *reference; guint index; g_assert (GTK_IS_TREE_VIEW (bookmark_list_widget)); g_assert (NAUTILUS_IS_BOOKMARK_LIST (bookmarks)); store = GTK_LIST_STORE (bookmark_list_store); selected = get_selected_bookmark (); g_signal_handler_block (bookmark_selection, selection_changed_id); g_signal_handler_block (bookmark_list_store, row_deleted_signal_id); g_signal_handler_block (bookmark_list_widget, row_activated_signal_id); g_signal_handler_block (bookmark_list_widget, key_pressed_signal_id); g_signal_handler_block (bookmark_list_widget, button_pressed_signal_id); gtk_list_store_clear (store); g_signal_handler_unblock (bookmark_list_widget, row_activated_signal_id); g_signal_handler_unblock (bookmark_list_widget, key_pressed_signal_id); g_signal_handler_unblock (bookmark_list_widget, button_pressed_signal_id); g_signal_handler_unblock (bookmark_list_store, row_deleted_signal_id); g_signal_handler_unblock (bookmark_selection, selection_changed_id); /* Fill the list in with the bookmark names. */ g_signal_handler_block (store, row_changed_signal_id); reference = NULL; for (index = 0; index < nautilus_bookmark_list_length (bookmarks); ++index) { NautilusBookmark *bookmark; const char *bookmark_name; GIcon *bookmark_icon; GtkTreeIter iter; bookmark = nautilus_bookmark_list_item_at (bookmarks, index); bookmark_name = nautilus_bookmark_get_name (bookmark); bookmark_icon = nautilus_bookmark_get_icon (bookmark); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, BOOKMARK_LIST_COLUMN_ICON, bookmark_icon, BOOKMARK_LIST_COLUMN_NAME, bookmark_name, BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark, BOOKMARK_LIST_COLUMN_STYLE, PANGO_STYLE_NORMAL, -1); if (bookmark == selected) { /* save old selection */ GtkTreePath *path; path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path); gtk_tree_path_free (path); } g_object_unref (bookmark_icon); } g_signal_handler_unblock (store, row_changed_signal_id); if (reference != NULL) { /* restore old selection */ /* bookmarks_set_empty() will call the selection change handler, * so we block it here in case of selection change. */ g_signal_handler_block (bookmark_selection, selection_changed_id); g_assert (index != 0); g_assert (gtk_tree_row_reference_valid (reference)); path = gtk_tree_row_reference_get_path (reference); gtk_tree_selection_select_path (bookmark_selection, path); gtk_tree_row_reference_free (reference); gtk_tree_path_free (path); g_signal_handler_unblock (bookmark_selection, selection_changed_id); } bookmarks_set_empty (index == 0); }