Skip to content

Commit

Permalink
Implement tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur committed Jan 28, 2025
1 parent 8aa1c1e commit 4cdb286
Show file tree
Hide file tree
Showing 92 changed files with 1,779 additions and 987 deletions.
1 change: 1 addition & 0 deletions assets/icons/Close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/icons/Close.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b0y4h5tuyrais"
path="res://.godot/imported/Close.svg-ec226890f15a36af010397a4558772f4.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/icons/Close.svg"
dest_files=["res://.godot/imported/Close.svg-ec226890f15a36af010397a4558772f4.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
1 change: 1 addition & 0 deletions assets/icons/CreateTab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/icons/CreateTab.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bnl24bflj771n"
path="res://.godot/imported/CreateTab.svg-5a4a2c79f40bbfe654b40ae41510476b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/icons/CreateTab.svg"
dest_files=["res://.godot/imported/CreateTab.svg-5a4a2c79f40bbfe654b40ae41510476b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
140 changes: 76 additions & 64 deletions project.godot

Large diffs are not rendered by default.

35 changes: 12 additions & 23 deletions src/autoload/Configs.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This singleton handles session data and settings.
extends Node

@warning_ignore("unused_signal")
signal file_path_changed
@warning_ignore("unused_signal")
signal highlighting_colors_changed
@warning_ignore("unused_signal")
Expand All @@ -21,6 +19,12 @@ signal basic_colors_changed
signal handle_visuals_changed
@warning_ignore("unused_signal")
signal shortcut_panel_changed
@warning_ignore("unused_signal")
signal active_tab_file_path_changed
@warning_ignore("unused_signal")
signal active_tab_changed
@warning_ignore("unused_signal")
signal tabs_changed

const savedata_path = "user://savedata.tres"
var savedata: SaveData:
Expand All @@ -30,13 +34,6 @@ var savedata: SaveData:
savedata.validate()
savedata.changed_deferred.connect(save)

var svg_text := "":
set(new_value):
if new_value != svg_text:
svg_text = new_value
FileAccess.open(svg_path, FileAccess.WRITE).store_string(svg_text)

const svg_path = "user://save.svg"

func save() -> void:
ResourceSaver.save(savedata, savedata_path)
Expand All @@ -50,9 +47,7 @@ func _enter_tree() -> void:
if InputMap.has_action(action):
default_shortcuts[action] = InputMap.action_get_events(action)
load_config()
load_svg_text()
ThemeUtils.generate_and_apply_theme()
update_window_title()


func load_config() -> void:
Expand All @@ -65,21 +60,18 @@ func load_config() -> void:
reset_settings()
return

update_window_title()
savedata.get_active_tab().activate()
change_background_color()
change_locale()

func load_svg_text() -> void:
var fa := FileAccess.open(svg_path, FileAccess.READ)
if fa != null:
svg_text = fa.get_as_text()

func reset_settings() -> void:
savedata = SaveData.new()
savedata.reset_to_default()
savedata.language = "en"
savedata.set_shortcut_panel_slots({ 0: "undo", 1: "redo" })
savedata.set_palettes([Palette.new("Pure", Palette.Preset.PURE)])
savedata.add_empty_tab()
save()


Expand All @@ -98,14 +90,11 @@ func generate_highlighter() -> SVGHighlighter:

# Global effects from settings. Some of them should also be used on launch.

func update_window_title() -> void:
if savedata.use_filename_for_window_title and !savedata.current_file_path.is_empty():
get_window().title = savedata.current_file_path.get_file() + " - GodSVG"
else:
get_window().title = "GodSVG"

func change_background_color() -> void:
RenderingServer.set_default_clear_color(savedata.background_color)

func change_locale() -> void:
TranslationServer.set_locale(savedata.language)
if not savedata.language in TranslationServer.get_loaded_locales():
savedata.language = "en"
else:
TranslationServer.set_locale(savedata.language)
29 changes: 21 additions & 8 deletions src/autoload/HandlerGUI.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extends Node

# Not a good idea to preload scenes inside a singleton.
const AlertDialog = preload("res://src/ui_parts/alert_dialog.tscn")
const ConfirmDialog = preload("res://src/ui_parts/confirm_dialog.tscn")
const AlertDialog = preload("res://src/ui_widgets/alert_dialog.tscn")
const ConfirmDialog = preload("res://src/ui_widgets/confirm_dialog.tscn")
const SettingsMenu = preload("res://src/ui_parts/settings_menu.tscn")
const AboutMenu = preload("res://src/ui_parts/about_menu.tscn")
const DonateMenu = preload("res://src/ui_parts/donate_menu.tscn")
Expand All @@ -24,6 +24,10 @@ func _enter_tree() -> void:
window.size_changed.connect(remove_all_popups)

func _ready() -> void:
Configs.active_tab_changed.connect(update_window_title)
Configs.active_tab_file_path_changed.connect(update_window_title)
update_window_title()

Configs.ui_scale_changed.connect(update_ui_scale)
await get_tree().process_frame # Helps make things more consistent.
update_ui_scale()
Expand Down Expand Up @@ -54,7 +58,7 @@ func add_dialog(new_dialog: Control) -> void:
_add_control(new_dialog)

func _add_control(new_control: Control) -> void:
# FIXME subpar workaround to drag & drop not able to be cancelled manually.
# FIXME subpar workaround to drag & drop not able to be canceled manually.
get_tree().root.propagate_notification(NOTIFICATION_DRAG_END)
remove_all_popups()

Expand Down Expand Up @@ -224,8 +228,8 @@ func _input(event: InputEvent) -> void:
return

# Global actions that should happen regardless of the context.
for action in ["import", "export", "save", "copy_svg_text", "clear_svg", "optimize",
"clear_file_path", "reset_svg"]:
for action in ["import", "export", "save", "close_tab", "new_tab", "select_next_tab",
"select_previous_tab", "copy_svg_text", "optimize", "reset_svg"]:
if ShortcutUtils.is_action_pressed(event, action):
get_viewport().set_input_as_handled()
ShortcutUtils.fn_call(action)
Expand All @@ -252,7 +256,7 @@ func _unhandled_input(event: InputEvent) -> void:
ShortcutUtils.fn_call(action)
return
if event is InputEventKey:
Indications.respond_to_key_input(event)
State.respond_to_key_input(event)


func update_ui_scale() -> void:
Expand Down Expand Up @@ -320,8 +324,8 @@ func open_donate() -> void:
add_menu(DonateMenu.instantiate())

func open_export() -> void:
var width := SVG.root_element.width
var height := SVG.root_element.height
var width := State.root_element.width
var height := State.root_element.height
if is_finite(width) and is_finite(height) and width > 0.0 and height > 0.0:
add_menu(ExportMenu.instantiate())
else:
Expand All @@ -333,6 +337,15 @@ func open_export() -> void:
Translator.translate("Export"), FileUtils.open_export_dialog.bind(svg_export_data))


func update_window_title() -> void:
if Configs.savedata.use_filename_for_window_title and\
not Configs.savedata.get_active_tab().svg_file_path.is_empty():
get_window().title = Configs.savedata.get_active_tab().get_presented_name() +\
" - GodSVG"
else:
get_window().title = "GodSVG"


# Helpers

# Used to trigger a mouse motion event, which can be used to update some things,
Expand Down
Loading

0 comments on commit 4cdb286

Please sign in to comment.