-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command-line "Go-To-Line" option (#1382)
* Add option entry for command line go-to option * Parse go-to range from command line argument using syntax from #415 * Files can now be opened at a selected range As long as they haven't already opened/restored * Able to open new file at selected range while app is running * go-to arg overrides document restore behviour * Go to args also update seleccted range of files already opened * Encapsulate go-to option arg handling into LocationJumpManager Fixes #415 * Change SelectionRange.EMPTY into a public const value * Fix lint errors * Add license headers to new source code files * Add null checks when parsing integers from selection range string * Merge DocumentView.open_document methods into one method * Amend license headers in new source code files * Resolve code-style formatting issues * Avoid unnecesaary function return in LocationJumpManager
- Loading branch information
1 parent
51dd521
commit 723348c
Showing
8 changed files
with
238 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io> | ||
* | ||
* Authored by: Colin Kiama <[email protected]> | ||
*/ | ||
|
||
namespace Scratch { | ||
public class LocationJumpManager : GLib.Object { | ||
public GLib.File file { get; set; } | ||
public SelectionRange range { get; set; } | ||
|
||
public bool has_override_target () { | ||
if (file == null) { | ||
return false; | ||
} | ||
|
||
bool is_override_target = false; | ||
|
||
if (privacy_settings.get_boolean ("remember-recent-files")) { | ||
var doc_infos = settings.get_value ("opened-files"); | ||
var doc_info_iter = new VariantIter (doc_infos); | ||
|
||
string uri; | ||
int pos; | ||
while (doc_info_iter.next ("(si)", out uri, out pos)) { | ||
if (uri != "") { | ||
GLib.File file_to_restore; | ||
if (Uri.parse_scheme (uri) != null) { | ||
file_to_restore = File.new_for_uri (uri); | ||
} else { | ||
file_to_restore = File.new_for_commandline_arg (uri); | ||
} | ||
|
||
if (file_to_restore.query_exists () && file_to_restore.get_path () == file.get_path ()) { | ||
is_override_target = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return is_override_target; | ||
} | ||
|
||
public RestoreOverride create_restore_override () { | ||
return new RestoreOverride (file, range); | ||
} | ||
|
||
public void clear () { | ||
range = SelectionRange.EMPTY; | ||
file = null; | ||
} | ||
|
||
public bool has_selection_range () { | ||
return range != SelectionRange.EMPTY; | ||
} | ||
|
||
public bool parse_selection_range_string (string selection_range_string) { | ||
Regex go_to_line_regex = /^(?<start_line>[0-9]+)+(?:\.(?<start_column>[0-9]+)+)?(?:-(?:(?<end_line>[0-9]+)+(?:\.(?<end_column>[0-9]+)+)?))?$/; // vala-lint=space-before-paren, line-length | ||
MatchInfo match_info; | ||
if (go_to_line_regex.match (selection_range_string, 0, out match_info)) { | ||
range = parse_go_to_range_from_match_info (match_info); | ||
debug ("Selection Range - start_line: %d", range.start_line); | ||
debug ("Selection Range - start_column: %d", range.start_column); | ||
debug ("Selection Range - end_line: %d", range.end_line); | ||
debug ("Selection Range - end_column: %d", range.end_column); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static SelectionRange parse_go_to_range_from_match_info (GLib.MatchInfo match_info) { | ||
return SelectionRange () { | ||
start_line = parse_num_from_match_info (match_info, "start_line"), | ||
end_line = parse_num_from_match_info (match_info, "end_line"), | ||
start_column = parse_num_from_match_info (match_info, "start_column"), | ||
end_column = parse_num_from_match_info (match_info, "end_column"), | ||
}; | ||
} | ||
|
||
private static int parse_num_from_match_info (MatchInfo match_info, string match_name) { | ||
var str = match_info.fetch_named (match_name); | ||
int num = 0; | ||
|
||
if (str != null) { | ||
int.try_parse (str, out num); | ||
} | ||
|
||
return num; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io> | ||
* | ||
* Authored by: Colin Kiama <[email protected]> | ||
*/ | ||
|
||
public class RestoreOverride : GLib.Object { | ||
public GLib.File file { get; construct; } | ||
public SelectionRange range { get; construct; } | ||
|
||
public RestoreOverride (GLib.File file, SelectionRange range) { | ||
Object ( | ||
file: file, | ||
range: range | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io> | ||
* | ||
* Authored by: Colin Kiama <[email protected]> | ||
*/ | ||
|
||
public struct SelectionRange { | ||
public int start_line; | ||
public int start_column; | ||
public int end_line; | ||
public int end_column; | ||
|
||
public const SelectionRange EMPTY = {0, 0, 0, 0}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters