Merge lp:~jeremywootten/pantheon-files/fix-1626240-breadcrumb-name-with-hash into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Danielle Foré
Approved revision: 2394
Merged at revision: 2571
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1626240-breadcrumb-name-with-hash
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 229 lines (+61/-28)
6 files modified
libcore/FileUtils.vala (+3/-1)
libcore/gof-directory-async.vala (+8/-2)
libwidgets/Chrome/BasicBreadcrumbsEntry.vala (+2/-1)
src/Application.vala (+9/-3)
src/View/Sidebar.vala (+2/-2)
src/View/Window.vala (+37/-19)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1626240-breadcrumb-name-with-hash
Reviewer Review Type Date Requested Status
Dieter Debast (community) Approve
elementary Apps team Pending
Review via email: mp+312413@code.launchpad.net

Commit message

enable paths containing folders starting with a '#'

Description of the change

The changes made enable paths containing folders starting with a '#' character to be handled correctly both on local and remote (smb) file systems when creating and restoring views.

Also, the breadcrumb tooltip now displays the unescaped text.

Views are now only created via the Window.uri_path_change_request () function; the corresponding file_path_change_request function being made private. This is to ensure consistent treatment of the uri before creating the view.

(This branch is the basis for a more extensive reworking to make this kind of bug less likely and easier to fix - see lp:~jeremywootten/pantheon-files/refactor-path-change-requests)

TO TEST: See bug report.

To post a comment you must log in.
2391. By Jeremy Wootten

Merge trunk to r2444

2392. By Jeremy Wootten

Merge trunk to r2470

Revision history for this message
Dieter Debast (ddieter) wrote :

When launching files from the command line with an URI containing a #, it won't navigate to the correct location but has the same behaviour like a bookmark (before the fix of course).

Example:
pantheon-files "smb://localhost/share/#test/second/"
Will navigate to "smb://localhost/share/"

Otherwise seems to work as intended.

review: Needs Fixing
Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Hi Dieter, thanks very much for reviewing this branch. Strictly speaking the issue you raise is a separate bug from the one linked to this branch (which only refers to the headerbar/breadcrumbs). However, I agree it is closely related and can probably be fixed in a similar way. I'll check whether it can be included in this branch with minimal extra code.

Revision history for this message
Dieter Debast (ddieter) wrote :

Hello Jeremy, if this is too much work to also fix in this branch, let me know and I will accept it. It can be put in a different issue then.

2393. By Jeremy Wootten

Merge trunk to r2570 and fix conflict

2394. By Jeremy Wootten

Fix hash in commandline uri

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Hello Dieter, I have pushed a relatively simple fix to your issue. Ultimately, I would like to refactor the code so that path sanitization for new tabs/windows occurs in only one place but that can wait for another branch.

I also updated the branch to be compatible with the latest trunk.

Revision history for this message
Dieter Debast (ddieter) wrote :

Thanks Jeremy, it fixes the issue and there are no obvious code issues so I'll accept this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libcore/FileUtils.vala'
2--- libcore/FileUtils.vala 2017-03-10 17:31:17 +0000
3+++ libcore/FileUtils.vala 2017-06-03 12:06:40 +0000
4@@ -162,7 +162,9 @@
5 return Uri.escape_string ((Uri.unescape_string (uri) ?? uri), rc , allow_utf8);
6 }
7
8- /** Produce a valid unescaped path **/
9+ /** Produce a valid unescaped path. A current path can be provided and is used to get the scheme and
10+ * to interpret relative paths where necessary.
11+ **/
12 public string sanitize_path (string? p, string? cp = null) {
13 string path = "";
14 string scheme = "";
15
16=== modified file 'libcore/gof-directory-async.vala'
17--- libcore/gof-directory-async.vala 2017-05-08 10:39:31 +0000
18+++ libcore/gof-directory-async.vala 2017-06-03 12:06:40 +0000
19@@ -107,8 +107,14 @@
20 public string last_error_message {get; private set; default = "";}
21
22 private Async (GLib.File _file) {
23- /* Ensure uri is correctly escaped */
24- location = GLib.File.new_for_uri (PF.FileUtils.escape_uri (_file.get_uri ()));
25+ /* Ensure uri is correctly escaped and has scheme */
26+ var escaped_uri = PF.FileUtils.escape_uri (_file.get_uri ());
27+ scheme = Uri.parse_scheme (escaped_uri);
28+ if (scheme == null) {
29+ scheme = Marlin.ROOT_FS_URI;
30+ escaped_uri = scheme + escaped_uri;
31+ }
32+ location = GLib.File.new_for_uri (escaped_uri);
33 file = GOF.File.get (location);
34 selected_file = null;
35
36
37=== modified file 'libwidgets/Chrome/BasicBreadcrumbsEntry.vala'
38--- libwidgets/Chrome/BasicBreadcrumbsEntry.vala 2017-02-28 18:55:07 +0000
39+++ libwidgets/Chrome/BasicBreadcrumbsEntry.vala 2017-06-03 12:06:40 +0000
40@@ -284,7 +284,7 @@
41 set_tooltip_text ("");
42 var el = get_element_from_coordinates ((int)event.x, (int)event.y);
43 if (el != null) {
44- set_tooltip_text (_("Go to %s").printf (el.text));
45+ set_tooltip_text (_("Go to %s").printf (el.text_for_display));
46 set_entry_cursor (new Gdk.Cursor.from_name (Gdk.Display.get_default (), "default"));
47 } else {
48 set_entry_cursor (null);
49@@ -476,6 +476,7 @@
50 if (el != null && element == el)
51 break;
52 }
53+
54 return PF.FileUtils.sanitize_path (newpath);
55 }
56
57
58=== modified file 'src/Application.vala'
59--- src/Application.vala 2017-05-08 10:39:31 +0000
60+++ src/Application.vala 2017-06-03 12:06:40 +0000
61@@ -200,10 +200,16 @@
62
63 /* Convert remaining arguments to GFiles */
64 foreach (string filepath in remaining) {
65- var file = File.new_for_commandline_arg (filepath);
66-
67- if (file != null)
68+ string path = PF.FileUtils.sanitize_path (filepath, null);
69+ GLib.File? file = null;
70+
71+ if (path.length > 0) {
72+ file = File.new_for_uri (PF.FileUtils.escape_uri (path));
73+ }
74+
75+ if (file != null) {
76 files += (file);
77+ }
78 }
79 /* Open application */
80 if (create_new_window) {
81
82=== modified file 'src/View/Sidebar.vala'
83--- src/View/Sidebar.vala 2017-05-16 19:50:22 +0000
84+++ src/View/Sidebar.vala 2017-06-03 12:06:40 +0000
85@@ -1288,7 +1288,7 @@
86 } else if (flags == Marlin.OpenFlag.NEW_TAB) {
87 window.add_tab (location, Marlin.ViewMode.CURRENT);
88 } else {
89- window.file_path_change_request (location);
90+ window.uri_path_change_request (uri);
91 }
92 } else if (f != null) {
93 f (this);
94@@ -1328,7 +1328,7 @@
95 } else if (flags == Marlin.OpenFlag.NEW_TAB) {
96 window.add_tab (location, Marlin.ViewMode.CURRENT);
97 } else {
98- window.file_path_change_request (location);
99+ window.uri_path_change_request (location.get_uri ());
100 }
101 }
102 }
103
104=== modified file 'src/View/Window.vala'
105--- src/View/Window.vala 2017-05-16 20:04:17 +0000
106+++ src/View/Window.vala 2017-06-03 12:06:40 +0000
107@@ -324,11 +324,11 @@
108 });
109
110 tabs.tab_restored.connect ((label, restore_data, icon) => {
111- add_tab (File.new_for_uri (restore_data));
112+ add_tab_by_uri (restore_data);
113 });
114
115 tabs.tab_duplicated.connect ((tab) => {
116- add_tab (File.new_for_uri (((tab.page as ViewContainer).uri)));
117+ add_tab_by_uri (((ViewContainer)(tab.page)).uri);
118 });
119
120 tabs.tab_moved.connect ((tab, x, y) => {
121@@ -456,6 +456,15 @@
122 top_menu.working = current_tab.is_frozen;
123 }
124
125+ public void add_tab_by_uri (string uri, Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {
126+ var file = get_file_from_uri (uri);
127+ if (file != null) {
128+ add_tab (file, mode);
129+ } else {
130+ add_tab ();
131+ }
132+ }
133+
134 public void add_tab (File location = File.new_for_commandline_arg (Environment.get_home_dir ()),
135 Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {
136 mode = real_mode (mode);
137@@ -978,24 +987,15 @@
138 if (mode < 0 || mode >= Marlin.ViewMode.INVALID || root_uri == null || root_uri == "" || tip_uri == null)
139 continue;
140
141- string? unescaped_root_uri = PF.FileUtils.sanitize_path (root_uri);
142-
143- if (unescaped_root_uri == null) {
144- warning ("Invalid root location for tab");
145- continue;
146- }
147-
148- GLib.File root_location = GLib.File.new_for_commandline_arg (unescaped_root_uri);
149-
150 /* We do not check valid location here because it may cause the interface to hang
151 * before the window appears (e.g. if trying to connect to a server that has become unavailable)
152 * Leave it to GOF.Directory.Async to deal with invalid locations asynchronously.
153 */
154
155- add_tab (root_location, mode);
156+ add_tab_by_uri (root_uri, mode);
157
158 if (mode == Marlin.ViewMode.MILLER_COLUMNS && tip_uri != root_uri) {
159- expand_miller_view (tip_uri, root_location);
160+ expand_miller_view (tip_uri, root_uri);
161 }
162
163 tabs_added++;
164@@ -1037,7 +1037,7 @@
165 return tabs_added;
166 }
167
168- private void expand_miller_view (string tip_uri, GLib.File root_location) {
169+ private void expand_miller_view (string tip_uri, string unescaped_root_uri) {
170 /* It might be more elegant for Miller.vala to handle this */
171 var tab = tabs.current;
172 var view = tab.page as ViewContainer;
173@@ -1050,6 +1050,7 @@
174 }
175
176 var tip_location = PF.FileUtils.get_file_for_path (unescaped_tip_uri);
177+ var root_location = PF.FileUtils.get_file_for_path (unescaped_root_uri);
178 var relative_path = root_location.get_relative_path (tip_location);
179 GLib.File gfile;
180
181@@ -1059,7 +1060,7 @@
182
183 foreach (string dir in dirs) {
184 uri += (GLib.Path.DIR_SEPARATOR_S + dir);
185- gfile = PF.FileUtils.get_file_for_path (uri);
186+ gfile = get_file_from_uri (uri);
187
188 mwcols.add_location (gfile, mwcols.current_slot, false); /* Do not scroll at this stage */
189 }
190@@ -1111,7 +1112,7 @@
191 }
192 }
193
194- public void file_path_change_request (GLib.File loc, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {
195+ private void file_path_change_request (GLib.File loc, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {
196 /* ViewContainer deals with non-existent or unmounted directories
197 * and locations that are not directories */
198 if (restoring_tabs) {
199@@ -1130,11 +1131,28 @@
200 }
201
202 public void uri_path_change_request (string p, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {
203- string path = PF.FileUtils.sanitize_path (p, current_tab.location.get_path ());
204+ var file = get_file_from_uri (p);
205+ if (file != null) {
206+ /* Have to escape path and use File.new_for_uri () to correctly handle paths with certain characters such as "#" */
207+ file_path_change_request (file, flag);
208+ } else {
209+ warning ("Cannot browse %s", p);
210+ }
211+ }
212+
213+ /** Use this function to standardise how locations are generated from uris **/
214+ private File? get_file_from_uri (string uri) {
215+ /* Sanitize path removes file:// scheme if present, but GOF.Directory.Async will replace it */
216+ string? current_uri = null;
217+ if (current_tab != null && current_tab.location != null) {
218+ current_uri = current_tab.location.get_uri ();
219+ }
220+
221+ string path = PF.FileUtils.sanitize_path (uri, current_uri);
222 if (path.length > 0) {
223- file_path_change_request (File.new_for_commandline_arg (path), flag);
224+ return File.new_for_uri (PF.FileUtils.escape_uri (path));
225 } else {
226- warning ("Cannot browse %s", p);
227+ return null;
228 }
229 }
230

Subscribers

People subscribed via source and target branches

to all changes: