Skip to content

Commit b5935c8

Browse files
Re-enable CLI file opening
1 parent a6f027d commit b5935c8

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/autoload/State.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ extends Node
44
const OptionsDialogScene = preload("res://src/ui_widgets/options_dialog.tscn")
55
const PathCommandPopupScene = preload("res://src/ui_widgets/path_popup.tscn")
66

7-
87
signal svg_unknown_change
98
signal svg_resized
109

@@ -63,6 +62,10 @@ func _enter_tree() -> void:
6362

6463
Configs.active_tab_changed.connect(setup_from_tab)
6564
setup_from_tab.call_deferred() # Let everything load before emitting signals.
65+
66+
# Need to wait a frame so the import warnings panel becomes available.
67+
await get_tree().process_frame
68+
FileUtils.apply_svgs_from_paths(OS.get_cmdline_args(), false)
6669

6770
func setup_from_tab() -> void:
6871
var active_tab := Configs.savedata.get_active_tab()

src/utils/FileUtils.gd

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ static func reset_svg() -> void:
1717
if FileAccess.file_exists(file_path):
1818
State.apply_svg_text(FileAccess.get_file_as_string(file_path))
1919

20-
static func apply_svgs_from_paths(paths: PackedStringArray) -> void:
21-
_start_file_import_process(paths, _apply_svg, PackedStringArray(["svg"]))
20+
static func apply_svgs_from_paths(paths: PackedStringArray,
21+
show_incorrect_extension_errors := true) -> void:
22+
_start_file_import_process(paths, _apply_svg, PackedStringArray(["svg"]),
23+
show_incorrect_extension_errors)
2224

2325
static func compare_svg_to_disk_contents(idx := -1) -> FileState:
2426
var tab := Configs.savedata.get_active_tab() if idx == -1 else Configs.savedata.get_tab(idx)
@@ -216,16 +218,28 @@ completion_callback: Callable, multi_select := false) -> void:
216218

217219
# Preprocessing step where all files with wrong extensions are discarded.
218220
static func _start_file_import_process(file_paths: PackedStringArray,
219-
completion_callback: Callable, allowed_extensions: PackedStringArray) -> void:
221+
completion_callback: Callable, allowed_extensions: PackedStringArray,
222+
show_incorrect_extension_errors := true) -> void:
223+
if not show_incorrect_extension_errors:
224+
for i in range(file_paths.size() - 1, -1, -1):
225+
if not file_paths[i].get_extension() in allowed_extensions:
226+
file_paths.remove_at(i)
227+
if not file_paths.is_empty():
228+
_file_import_proceed(file_paths, completion_callback)
229+
return
230+
220231
var incorrect_extension_file_paths := PackedStringArray()
221232
for i in range(file_paths.size() - 1, -1, -1):
222233
if not file_paths[i].get_extension() in allowed_extensions:
223234
incorrect_extension_file_paths.append(Utils.simplify_file_path(file_paths[i]))
224235
file_paths.remove_at(i)
225236

237+
if file_paths.is_empty():
238+
return
239+
226240
var proceed_callback := _file_import_proceed.bind(file_paths, completion_callback)
227241

228-
if not incorrect_extension_file_paths.is_empty():
242+
if show_incorrect_extension_errors and not incorrect_extension_file_paths.is_empty():
229243
var error_text := TranslationUtils.get_extension_alert_text(allowed_extensions) + "\n"
230244
var passed_list := PackedStringArray() # Only pass if there are more than two.
231245
if incorrect_extension_file_paths.size() >= 2:

0 commit comments

Comments
 (0)