Merge lp:~jeremywootten/pantheon-files/fix-1467568-do-not-offer-to-bookmark-certain-locations into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Cody Garver
Approved revision: 2153
Merged at revision: 2157
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1467568-do-not-offer-to-bookmark-certain-locations
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 104 lines (+33/-11)
3 files modified
src/View/AbstractDirectoryView.vala (+5/-10)
src/View/Sidebar.vala (+20/-1)
src/View/Window.vala (+8/-0)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1467568-do-not-offer-to-bookmark-certain-locations
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+294724@code.launchpad.net

Commit message

Do not offer to bookmark if already a place in sidebar

Description of the change

The view context menu no longer shows the "Bookmark" option when there is already a bookmark or shortcut to the same uri in the sidebar (including builtins, mounted devices and network locations).

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/View/AbstractDirectoryView.vala'
2--- src/View/AbstractDirectoryView.vala 2016-05-13 21:06:02 +0000
3+++ src/View/AbstractDirectoryView.vala 2016-05-15 10:13:37 +0000
4@@ -1094,7 +1094,7 @@
5 else
6 location = slot.directory.file.get_target_location ();
7
8- window.sidebar.add_uri (location.get_uri (), null);
9+ window.bookmark_uri (location.get_uri (), null);
10 }
11
12 /** Background actions */
13@@ -1906,8 +1906,8 @@
14 }
15
16 if (common_actions.get_action_enabled ("bookmark")) {
17- /* Do not offer to bookmark if the home folder is selected */
18- if (!(file_location_is_builtin (selected_files.data))) {
19+ /* Do not offer to bookmark if location is already bookmarked */
20+ if (window.can_bookmark_uri (selected_files.data.uri)) {
21 menu.append_section (null, builder.get_object ("bookmark") as GLib.MenuModel);
22 }
23 }
24@@ -1962,8 +1962,8 @@
25 }
26
27 if (common_actions.get_action_enabled ("bookmark")) {
28- /* Do not insert bookmark for home or filesystem root (already have builtins) */
29- if (!(file_location_is_builtin (slot.directory.file))) {
30+ /* Do not offer to bookmark if location is already bookmarked */
31+ if (window.can_bookmark_uri (slot.directory.file.uri)) {
32 menu.append_section (null, builder.get_object ("bookmark") as GLib.MenuModel);
33 }
34 }
35@@ -3444,11 +3444,6 @@
36 unselect_path (p);
37 }
38 }
39- /** Check whether gof_file represents the user home directory or the root filesystem **/
40- protected bool file_location_is_builtin (GOF.File gof_file) {
41- var path = gof_file.location.get_path ();
42- return (path == Environment.get_home_dir () || path == Path.DIR_SEPARATOR_S);
43- }
44
45 public virtual void sync_selection () {}
46 public virtual void highlight_path (Gtk.TreePath? path) {}
47
48=== modified file 'src/View/Sidebar.vala'
49--- src/View/Sidebar.vala 2016-05-13 19:51:34 +0000
50+++ src/View/Sidebar.vala 2016-05-15 10:13:37 +0000
51@@ -421,6 +421,25 @@
52 return iter;
53 }
54
55+ public bool has_place (string uri) {
56+ bool found = false;
57+
58+ store.@foreach ((model, path, iter) => {
59+ string u;
60+ model.@get (iter, Column.URI, out u);
61+ if (u == null) { /* Category entries etc have null uri, for example */
62+ return false;
63+ } else if (u == uri) {
64+ found = true;
65+ return true;
66+ } else {
67+ return false;
68+ }
69+ });
70+
71+ return found;
72+ }
73+
74 private bool recent_is_supported () {
75 string [] supported;
76
77@@ -1057,7 +1076,7 @@
78 }
79
80 private bool can_accept_file_as_bookmark (GLib.File file) {
81- return file.query_exists (null);
82+ return file.query_exists (null) && window.can_bookmark_uri (file.get_uri ());
83 }
84
85 private bool can_accept_files_as_bookmarks (List<GLib.File> items) {
86
87=== modified file 'src/View/Window.vala'
88--- src/View/Window.vala 2016-05-06 17:39:08 +0000
89+++ src/View/Window.vala 2016-05-15 10:13:37 +0000
90@@ -471,6 +471,14 @@
91 tabs.current = tab;
92 }
93
94+ public void bookmark_uri (string uri, string? name = null) {
95+ sidebar.add_uri (uri, name);
96+ }
97+
98+ public bool can_bookmark_uri (string uri) {
99+ return !sidebar.has_place (uri);
100+ }
101+
102 public void remove_tab (ViewContainer view_container) {
103 actual_remove_tab (tabs.get_tab_by_widget (view_container as Gtk.Widget));
104 }

Subscribers

People subscribed via source and target branches

to all changes: