Commit a4f60a1b authored by William Jon McCann's avatar William Jon McCann

Add ability to reorder bookmarks

https://bugzilla.gnome.org/show_bug.cgi?id=575034
parent c59ee718
......@@ -330,15 +330,9 @@ nautilus_bookmark_list_move_item (NautilusBookmarkList *bookmarks,
bookmarks->list = g_list_remove_link (bookmarks->list,
bookmark_item);
if (index < destination) {
bookmarks->list = g_list_insert (bookmarks->list,
bookmark_item->data,
destination - 1);
} else {
bookmarks->list = g_list_insert (bookmarks->list,
bookmark_item->data,
destination);
}
bookmarks->list = g_list_insert (bookmarks->list,
bookmark_item->data,
destination);
nautilus_bookmark_list_save_file (bookmarks);
}
......
......@@ -53,7 +53,8 @@ static int selection_changed_id = 0;
static GtkWidget *name_field = NULL;
static int name_field_changed_signal_id;
static GtkWidget *remove_button = NULL;
static GtkWidget *jump_button = NULL;
static GtkWidget *up_button = NULL;
static GtkWidget *down_button = NULL;
static gboolean text_changed = FALSE;
static gboolean name_text_changed = FALSE;
static GtkWidget *uri_field = NULL;
......@@ -121,39 +122,6 @@ get_selected_bookmark (void)
return nautilus_bookmark_list_item_at(bookmarks, get_selected_row ());
}
static void
nautilus_bookmarks_window_response_cb (GtkDialog *dialog,
int response_id,
gpointer callback_data)
{
if (response_id == GTK_RESPONSE_HELP) {
GError *error = NULL;
gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (dialog)),
"help:gnome-help/nautilus-bookmarks-edit",
gtk_get_current_event_time (), &error);
if (error) {
GtkWidget *err_dialog;
err_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
_("There was an error displaying help: \n%s"),
error->message);
g_signal_connect (G_OBJECT (err_dialog),
"response", G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE);
gtk_widget_show (err_dialog);
g_error_free (error);
}
} else if (response_id == GTK_RESPONSE_CLOSE) {
gtk_widget_destroy (GTK_WIDGET (dialog));
}
}
static int
nautilus_bookmarks_window_key_press_event_cb (GtkWindow *window,
GdkEventKey *event,
......@@ -191,6 +159,27 @@ setup_empty_list (void)
-1);
}
static void
update_button_sensitivity (void)
{
NautilusBookmark *selected;
int n_active;
int index = -1;
selected = get_selected_bookmark ();
n_active = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (bookmark_list_store), NULL);
if (selected != NULL) {
index = get_selected_row ();
}
/* Set the sensitivity of widgets that require a selection */
gtk_widget_set_sensitive (remove_button, index >= 0 && n_active > 1);
gtk_widget_set_sensitive (up_button, index > 0);
gtk_widget_set_sensitive (down_button, index >= 0 && index < n_active - 1);
gtk_widget_set_sensitive (name_field, selected != NULL);
gtk_widget_set_sensitive (uri_field, selected != NULL);
}
static void
on_selection_changed (GtkTreeSelection *treeselection,
gpointer user_data)
......@@ -212,12 +201,8 @@ on_selection_changed (GtkTreeSelection *treeselection,
g_object_unref (location);
}
/* Set the sensitivity of widgets that require a selection */
gtk_widget_set_sensitive (remove_button, selected != NULL);
gtk_widget_set_sensitive (jump_button, selected != NULL);
gtk_widget_set_sensitive (name_field, selected != NULL);
gtk_widget_set_sensitive (uri_field, selected != NULL);
update_button_sensitivity ();
g_signal_handler_block (name_field, name_field_changed_signal_id);
nautilus_entry_set_text (NAUTILUS_ENTRY (name_field),
......@@ -416,13 +401,6 @@ open_selected_bookmark (NautilusWindow *window)
g_object_unref (location);
}
static void
on_jump_button_clicked (GtkButton *button,
gpointer user_data)
{
open_selected_bookmark (user_data);
}
static void
bookmarks_delete_bookmark (void)
{
......@@ -466,6 +444,33 @@ on_remove_button_clicked (GtkButton *button,
bookmarks_delete_bookmark ();
}
static void
on_up_button_clicked (GtkButton *button,
gpointer user_data)
{
guint row;
GtkTreeIter iter;
row = get_selected_row ();
nautilus_bookmark_list_move_item (bookmarks, row, row - 1);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (bookmark_list_store),
&iter, NULL, row - 1);
gtk_tree_selection_select_iter (bookmark_selection, &iter);
}
static void
on_down_button_clicked (GtkButton *button,
gpointer user_data)
{
guint row;
GtkTreeIter iter;
row = get_selected_row ();
nautilus_bookmark_list_move_item (bookmarks, row, row + 1);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (bookmark_list_store),
&iter, NULL, row + 1);
gtk_tree_selection_select_iter (bookmark_selection, &iter);
}
/* This is a bit of a kludge to get DnD to work. We check if the row in the
GtkListStore matches the one in the bookmark list. If it doesn't, we assume
......@@ -709,12 +714,11 @@ nautilus_bookmarks_window_new (NautilusWindow *parent_window,
g_signal_connect (window, "key-press-event",
G_CALLBACK (nautilus_bookmarks_window_key_press_event_cb), NULL);
g_signal_connect (window, "response",
G_CALLBACK (nautilus_bookmarks_window_response_cb), NULL);
bookmark_list_widget = GTK_TREE_VIEW (gtk_builder_get_object (builder, "bookmark_tree_view"));
remove_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_delete_button"));
jump_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_jump_button"));
remove_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_remove_button"));
up_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_up_button"));
down_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_down_button"));
rend = gtk_cell_renderer_pixbuf_new ();
g_object_set (rend,
......@@ -814,8 +818,10 @@ nautilus_bookmarks_window_new (NautilusWindow *parent_window,
G_CALLBACK (name_or_uri_field_activate), NULL);
g_signal_connect (remove_button, "clicked",
G_CALLBACK (on_remove_button_clicked), NULL);
g_signal_connect (jump_button, "clicked",
G_CALLBACK (on_jump_button_clicked), parent_window);
g_signal_connect (up_button, "clicked",
G_CALLBACK (on_up_button_clicked), NULL);
g_signal_connect (down_button, "clicked",
G_CALLBACK (on_down_button_clicked), NULL);
gtk_tree_selection_set_mode (bookmark_selection, GTK_SELECTION_BROWSE);
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 2.12 -->
<object class="GtkDialog" id="bookmarks_dialog">
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="bookmarks_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Edit Bookmarks</property>
<property name="window_position">center</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="border_width">6</property>
<property name="title" translatable="yes">Bookmarks</property>
<child>
<object class="GtkBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="border_width">5</property>
<property name="spacing">18</property>
<child>
<object class="GtkBox" id="box1">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="helpbutton1">
<property name="label">gtk-help</property>
<object class="GtkScrolledWindow" id="bookmark_list_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="bookmark_tree_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="reorderable">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bookmark_jump_button">
<property name="label">gtk-jump-to</property>
<object class="GtkToolbar" id="bookmarks_toolbar">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
<property name="icon_size">1</property>
<style>
<class name="inline-toolbar"/>
</style>
<child>
<object class="GtkToolButton" id="bookmark_remove_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Remove</property>
<property name="tooltip_text" translatable="yes">Remove</property>
<property name="icon_name">list-remove-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<object class="GtkSeparatorToolItem" id="toolbutton1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="draw">False</property>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
<child>
<object class="GtkToolItem" id="up_down_toolitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="bookmark_up_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-up-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bookmark_down_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage" id="image5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-down-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......@@ -50,74 +135,53 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bookmark_delete_button">
<property name="label">gtk-remove</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox1">
<object class="GtkBox" id="vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">18</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkAlignment" id="alignment1">
<object class="GtkBox" id="vbox4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="bookmark_name_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Name</property>
<property name="use_underline">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox1">
<object class="GtkBox" id="hbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Bookmarks</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">bookmark_tree_view</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
......@@ -126,44 +190,11 @@
</packing>
</child>
<child>
<object class="GtkBox" id="hbox4">
<object class="GtkBox" id="bookmark_name_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="bookmark_list_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="bookmark_tree_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="reorderable">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
</object>
<packing>
......@@ -173,166 +204,84 @@
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment2">
<object class="GtkBox" id="vbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="vbox2">
<object class="GtkLabel" id="bookmark_location_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">2</property>
<property name="ypad">2</property>
<property name="label" translatable="yes">_Location</property>
<property name="use_underline">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="orientation">vertical</property>
<property name="spacing">18</property>
<child>
<object class="GtkBox" id="vbox4">
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="bookmark_name_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Name</property>
<property name="use_underline">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="bookmark_name_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox3">
<object class="GtkBox" id="bookmark_location_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="bookmark_location_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">2</property>
<property name="ypad">2</property>
<property name="label" translatable="yes">_Location</property>
<property name="use_underline">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="bookmark_location_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
......@@ -346,11 +295,5 @@
</child>
</object>
</child>
<action-widgets>
<action-widget response="-11">helpbutton1</action-widget>
<action-widget response="-10">bookmark_jump_button</action-widget>
<action-widget response="-2">bookmark_delete_button</action-widget>
<action-widget response="-7">button2</action-widget>
</action-widgets>
</object>
</interface>
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