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
=== modified file 'libcore/FileUtils.vala'
--- libcore/FileUtils.vala 2017-03-10 17:31:17 +0000
+++ libcore/FileUtils.vala 2017-06-03 12:06:40 +0000
@@ -162,7 +162,9 @@
162 return Uri.escape_string ((Uri.unescape_string (uri) ?? uri), rc , allow_utf8);162 return Uri.escape_string ((Uri.unescape_string (uri) ?? uri), rc , allow_utf8);
163 }163 }
164164
165 /** Produce a valid unescaped path **/165 /** Produce a valid unescaped path. A current path can be provided and is used to get the scheme and
166 * to interpret relative paths where necessary.
167 **/
166 public string sanitize_path (string? p, string? cp = null) {168 public string sanitize_path (string? p, string? cp = null) {
167 string path = "";169 string path = "";
168 string scheme = "";170 string scheme = "";
169171
=== modified file 'libcore/gof-directory-async.vala'
--- libcore/gof-directory-async.vala 2017-05-08 10:39:31 +0000
+++ libcore/gof-directory-async.vala 2017-06-03 12:06:40 +0000
@@ -107,8 +107,14 @@
107 public string last_error_message {get; private set; default = "";}107 public string last_error_message {get; private set; default = "";}
108108
109 private Async (GLib.File _file) {109 private Async (GLib.File _file) {
110 /* Ensure uri is correctly escaped */110 /* Ensure uri is correctly escaped and has scheme */
111 location = GLib.File.new_for_uri (PF.FileUtils.escape_uri (_file.get_uri ()));111 var escaped_uri = PF.FileUtils.escape_uri (_file.get_uri ());
112 scheme = Uri.parse_scheme (escaped_uri);
113 if (scheme == null) {
114 scheme = Marlin.ROOT_FS_URI;
115 escaped_uri = scheme + escaped_uri;
116 }
117 location = GLib.File.new_for_uri (escaped_uri);
112 file = GOF.File.get (location);118 file = GOF.File.get (location);
113 selected_file = null;119 selected_file = null;
114120
115121
=== modified file 'libwidgets/Chrome/BasicBreadcrumbsEntry.vala'
--- libwidgets/Chrome/BasicBreadcrumbsEntry.vala 2017-02-28 18:55:07 +0000
+++ libwidgets/Chrome/BasicBreadcrumbsEntry.vala 2017-06-03 12:06:40 +0000
@@ -284,7 +284,7 @@
284 set_tooltip_text ("");284 set_tooltip_text ("");
285 var el = get_element_from_coordinates ((int)event.x, (int)event.y);285 var el = get_element_from_coordinates ((int)event.x, (int)event.y);
286 if (el != null) {286 if (el != null) {
287 set_tooltip_text (_("Go to %s").printf (el.text));287 set_tooltip_text (_("Go to %s").printf (el.text_for_display));
288 set_entry_cursor (new Gdk.Cursor.from_name (Gdk.Display.get_default (), "default"));288 set_entry_cursor (new Gdk.Cursor.from_name (Gdk.Display.get_default (), "default"));
289 } else {289 } else {
290 set_entry_cursor (null);290 set_entry_cursor (null);
@@ -476,6 +476,7 @@
476 if (el != null && element == el)476 if (el != null && element == el)
477 break;477 break;
478 }478 }
479
479 return PF.FileUtils.sanitize_path (newpath);480 return PF.FileUtils.sanitize_path (newpath);
480 }481 }
481482
482483
=== modified file 'src/Application.vala'
--- src/Application.vala 2017-05-08 10:39:31 +0000
+++ src/Application.vala 2017-06-03 12:06:40 +0000
@@ -200,10 +200,16 @@
200200
201 /* Convert remaining arguments to GFiles */201 /* Convert remaining arguments to GFiles */
202 foreach (string filepath in remaining) {202 foreach (string filepath in remaining) {
203 var file = File.new_for_commandline_arg (filepath);203 string path = PF.FileUtils.sanitize_path (filepath, null);
204204 GLib.File? file = null;
205 if (file != null)205
206 if (path.length > 0) {
207 file = File.new_for_uri (PF.FileUtils.escape_uri (path));
208 }
209
210 if (file != null) {
206 files += (file);211 files += (file);
212 }
207 }213 }
208 /* Open application */214 /* Open application */
209 if (create_new_window) {215 if (create_new_window) {
210216
=== modified file 'src/View/Sidebar.vala'
--- src/View/Sidebar.vala 2017-05-16 19:50:22 +0000
+++ src/View/Sidebar.vala 2017-06-03 12:06:40 +0000
@@ -1288,7 +1288,7 @@
1288 } else if (flags == Marlin.OpenFlag.NEW_TAB) {1288 } else if (flags == Marlin.OpenFlag.NEW_TAB) {
1289 window.add_tab (location, Marlin.ViewMode.CURRENT);1289 window.add_tab (location, Marlin.ViewMode.CURRENT);
1290 } else {1290 } else {
1291 window.file_path_change_request (location);1291 window.uri_path_change_request (uri);
1292 }1292 }
1293 } else if (f != null) {1293 } else if (f != null) {
1294 f (this);1294 f (this);
@@ -1328,7 +1328,7 @@
1328 } else if (flags == Marlin.OpenFlag.NEW_TAB) {1328 } else if (flags == Marlin.OpenFlag.NEW_TAB) {
1329 window.add_tab (location, Marlin.ViewMode.CURRENT);1329 window.add_tab (location, Marlin.ViewMode.CURRENT);
1330 } else {1330 } else {
1331 window.file_path_change_request (location);1331 window.uri_path_change_request (location.get_uri ());
1332 }1332 }
1333 }1333 }
1334 }1334 }
13351335
=== modified file 'src/View/Window.vala'
--- src/View/Window.vala 2017-05-16 20:04:17 +0000
+++ src/View/Window.vala 2017-06-03 12:06:40 +0000
@@ -324,11 +324,11 @@
324 });324 });
325325
326 tabs.tab_restored.connect ((label, restore_data, icon) => {326 tabs.tab_restored.connect ((label, restore_data, icon) => {
327 add_tab (File.new_for_uri (restore_data));327 add_tab_by_uri (restore_data);
328 });328 });
329329
330 tabs.tab_duplicated.connect ((tab) => {330 tabs.tab_duplicated.connect ((tab) => {
331 add_tab (File.new_for_uri (((tab.page as ViewContainer).uri)));331 add_tab_by_uri (((ViewContainer)(tab.page)).uri);
332 });332 });
333333
334 tabs.tab_moved.connect ((tab, x, y) => {334 tabs.tab_moved.connect ((tab, x, y) => {
@@ -456,6 +456,15 @@
456 top_menu.working = current_tab.is_frozen;456 top_menu.working = current_tab.is_frozen;
457 }457 }
458458
459 public void add_tab_by_uri (string uri, Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {
460 var file = get_file_from_uri (uri);
461 if (file != null) {
462 add_tab (file, mode);
463 } else {
464 add_tab ();
465 }
466 }
467
459 public void add_tab (File location = File.new_for_commandline_arg (Environment.get_home_dir ()),468 public void add_tab (File location = File.new_for_commandline_arg (Environment.get_home_dir ()),
460 Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {469 Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {
461 mode = real_mode (mode);470 mode = real_mode (mode);
@@ -978,24 +987,15 @@
978 if (mode < 0 || mode >= Marlin.ViewMode.INVALID || root_uri == null || root_uri == "" || tip_uri == null)987 if (mode < 0 || mode >= Marlin.ViewMode.INVALID || root_uri == null || root_uri == "" || tip_uri == null)
979 continue;988 continue;
980989
981 string? unescaped_root_uri = PF.FileUtils.sanitize_path (root_uri);
982
983 if (unescaped_root_uri == null) {
984 warning ("Invalid root location for tab");
985 continue;
986 }
987
988 GLib.File root_location = GLib.File.new_for_commandline_arg (unescaped_root_uri);
989
990 /* We do not check valid location here because it may cause the interface to hang990 /* We do not check valid location here because it may cause the interface to hang
991 * before the window appears (e.g. if trying to connect to a server that has become unavailable)991 * before the window appears (e.g. if trying to connect to a server that has become unavailable)
992 * Leave it to GOF.Directory.Async to deal with invalid locations asynchronously. 992 * Leave it to GOF.Directory.Async to deal with invalid locations asynchronously.
993 */993 */
994994
995 add_tab (root_location, mode);995 add_tab_by_uri (root_uri, mode);
996996
997 if (mode == Marlin.ViewMode.MILLER_COLUMNS && tip_uri != root_uri) {997 if (mode == Marlin.ViewMode.MILLER_COLUMNS && tip_uri != root_uri) {
998 expand_miller_view (tip_uri, root_location);998 expand_miller_view (tip_uri, root_uri);
999 }999 }
10001000
1001 tabs_added++;1001 tabs_added++;
@@ -1037,7 +1037,7 @@
1037 return tabs_added;1037 return tabs_added;
1038 }1038 }
10391039
1040 private void expand_miller_view (string tip_uri, GLib.File root_location) {1040 private void expand_miller_view (string tip_uri, string unescaped_root_uri) {
1041 /* It might be more elegant for Miller.vala to handle this */1041 /* It might be more elegant for Miller.vala to handle this */
1042 var tab = tabs.current;1042 var tab = tabs.current;
1043 var view = tab.page as ViewContainer;1043 var view = tab.page as ViewContainer;
@@ -1050,6 +1050,7 @@
1050 }1050 }
10511051
1052 var tip_location = PF.FileUtils.get_file_for_path (unescaped_tip_uri);1052 var tip_location = PF.FileUtils.get_file_for_path (unescaped_tip_uri);
1053 var root_location = PF.FileUtils.get_file_for_path (unescaped_root_uri);
1053 var relative_path = root_location.get_relative_path (tip_location);1054 var relative_path = root_location.get_relative_path (tip_location);
1054 GLib.File gfile;1055 GLib.File gfile;
10551056
@@ -1059,7 +1060,7 @@
10591060
1060 foreach (string dir in dirs) {1061 foreach (string dir in dirs) {
1061 uri += (GLib.Path.DIR_SEPARATOR_S + dir);1062 uri += (GLib.Path.DIR_SEPARATOR_S + dir);
1062 gfile = PF.FileUtils.get_file_for_path (uri);1063 gfile = get_file_from_uri (uri);
10631064
1064 mwcols.add_location (gfile, mwcols.current_slot, false); /* Do not scroll at this stage */1065 mwcols.add_location (gfile, mwcols.current_slot, false); /* Do not scroll at this stage */
1065 }1066 }
@@ -1111,7 +1112,7 @@
1111 }1112 }
1112 }1113 }
11131114
1114 public void file_path_change_request (GLib.File loc, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {1115 private void file_path_change_request (GLib.File loc, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {
1115 /* ViewContainer deals with non-existent or unmounted directories1116 /* ViewContainer deals with non-existent or unmounted directories
1116 * and locations that are not directories */1117 * and locations that are not directories */
1117 if (restoring_tabs) {1118 if (restoring_tabs) {
@@ -1130,11 +1131,28 @@
1130 }1131 }
11311132
1132 public void uri_path_change_request (string p, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {1133 public void uri_path_change_request (string p, Marlin.OpenFlag flag = Marlin.OpenFlag.DEFAULT) {
1133 string path = PF.FileUtils.sanitize_path (p, current_tab.location.get_path ());1134 var file = get_file_from_uri (p);
1135 if (file != null) {
1136 /* Have to escape path and use File.new_for_uri () to correctly handle paths with certain characters such as "#" */
1137 file_path_change_request (file, flag);
1138 } else {
1139 warning ("Cannot browse %s", p);
1140 }
1141 }
1142
1143 /** Use this function to standardise how locations are generated from uris **/
1144 private File? get_file_from_uri (string uri) {
1145 /* Sanitize path removes file:// scheme if present, but GOF.Directory.Async will replace it */
1146 string? current_uri = null;
1147 if (current_tab != null && current_tab.location != null) {
1148 current_uri = current_tab.location.get_uri ();
1149 }
1150
1151 string path = PF.FileUtils.sanitize_path (uri, current_uri);
1134 if (path.length > 0) {1152 if (path.length > 0) {
1135 file_path_change_request (File.new_for_commandline_arg (path), flag);1153 return File.new_for_uri (PF.FileUtils.escape_uri (path));
1136 } else {1154 } else {
1137 warning ("Cannot browse %s", p);1155 return null;
1138 }1156 }
1139 }1157 }
11401158

Subscribers

People subscribed via source and target branches

to all changes: