Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shortcut categories #652

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/GlobalSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,24 @@ const default_config = {

# No way to fetch defaults otherwise.
var default_input_events := {} # Dictionary{String: Array[InputEvent]}
const configurable_keybinds = ["import", "export", "save", "move_up", "move_down",
"undo", "redo", "duplicate", "select_all", "delete", "zoom_in", "zoom_out",
"zoom_reset"]

const configurable_keybinds = {
"file": ["import", "export", "save", "optimize_svg", "copy_svg_text", "clear_svg",
"clear_file_path", "reset_svg"],
"edit": ["undo", "redo", "select_all", "duplicate", "move_up", "move_down", "delete"],
"view": ["zoom_in", "zoom_out", "zoom_reset", "view_show_grid", "view_show_handles",
"view_rasterized_svg"]}

const unconfigurable_keybinds = [
"move_relative", "move_absolute", "line_relative", "line_absolute",
"horizontal_line_relative", "horizontal_line_absolute", "vertical_line_relative",
"vertical_line_absolute", "close_path_relative", "close_path_absolute",
"elliptical_arc_relative", "elliptical_arc_absolute", "quadratic_bezier_relative",
"quadratic_bezier_absolute", "shorthand_quadratic_bezier_relative",
"shorthand_quadratic_bezier_absolute", "cubic_bezier_relative",
"cubic_bezier_absolute", "shorthand_cubic_bezier_relative",
"shorthand_cubic_bezier_absolute"]


var language: String:
set(new_value):
Expand Down Expand Up @@ -182,9 +197,10 @@ func load_settings() -> void:
else:
for section in config.get_sections():
if section == "keybinds":
for action in configurable_keybinds:
if config.has_section_key("keybinds", action):
modify_keybind(action, config.get_value("keybinds", action))
for category in configurable_keybinds:
for action in GlobalSettings.configurable_keybinds[category]:
if config.has_section_key("keybinds", action):
modify_keybind(action, config.get_value("keybinds", action))
else:
for setting in config.get_section_keys(section):
set(setting, config.get_value(section, setting))
Expand All @@ -202,8 +218,9 @@ func reset_setting(section: String, setting: String) -> void:

func reset_keybinds() -> void:
InputMap.load_from_project_settings()
for action in configurable_keybinds:
save_keybind(action)
for category in configurable_keybinds:
for action in GlobalSettings.configurable_keybinds[category]:
save_keybind(action)

func reset_palettes() -> void:
palettes = [ColorPalette.new("Pure",
Expand Down
5 changes: 5 additions & 0 deletions src/SVG.gd
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ non_native_callable: Callable) -> void:
HandlerGUI.add_overlay(svg_export_dialog)
svg_export_dialog.file_selected.connect(non_native_callable)

func native_file_export(has_selected: bool, files: PackedStringArray,
_filter_idx: int, extension: String, upscale_amount := 1.0) -> void:
if has_selected:
SVG.finish_export(files[0], extension, upscale_amount)

func native_file_save(has_selected: bool, files: PackedStringArray,
_filter_idx: int) -> void:
if has_selected:
Expand Down
9 changes: 5 additions & 4 deletions src/Utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class_name Utils extends RefCounted
# In my opinion, this is nicer than groups.
enum CustomNotification {
LANGUAGE_CHANGED = 300,
NUMBER_PRECISION_CHANGED = 301,
HIGHLIGHT_COLORS_CHANGED = 302,
DEFAULT_VALUE_OPACITY_CHANGED = 303,
HANDLE_COLORS_CHANGED = 304,
THEME_CHANGED = 301,
NUMBER_PRECISION_CHANGED = 302,
HIGHLIGHT_COLORS_CHANGED = 303,
DEFAULT_VALUE_OPACITY_CHANGED = 304,
HANDLE_COLORS_CHANGED = 305,
}

const path_command_char_dict = {
Expand Down
37 changes: 32 additions & 5 deletions src/ui_parts/code_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ signal optimize_button_enable_updated(is_optimize_enabled: bool)

const ContextPopup = preload("res://src/ui_elements/context_popup.tscn")

@onready var panel_container: PanelContainer = $PanelContainer
@onready var code_edit: TextEdit = $ScriptEditor/SVGCodeEdit
@onready var error_bar: PanelContainer = $ScriptEditor/ErrorBar
@onready var error_label: RichTextLabel = $ScriptEditor/ErrorBar/Label
Expand All @@ -20,7 +21,7 @@ func _ready() -> void:
auto_update_text()
update_size_label()
update_file_button()
setup_theme(false)
setup_theme()
setup_highlighter()
code_edit.clear_undo_history()
SVG.root_tag.attribute_changed.connect(auto_update_text.unbind(1))
Expand All @@ -33,6 +34,8 @@ func _ready() -> void:
func _notification(what: int) -> void:
if what == Utils.CustomNotification.HIGHLIGHT_COLORS_CHANGED:
setup_highlighter()
if what == Utils.CustomNotification.THEME_CHANGED:
setup_theme()


func _unhandled_input(input_event: InputEvent) -> void:
Expand Down Expand Up @@ -66,7 +69,7 @@ func update_error(err_id: SVGParser.ParseError) -> void:
var error_bar_real_height := error_bar.size.y - 2
code_edit.custom_minimum_size.y += error_bar_real_height
code_edit.size.y += error_bar_real_height
setup_theme(false)
setup_theme()
else:
# When the error is shown, the code editor's theme is changed to match up.
if not error_bar.visible:
Expand All @@ -75,22 +78,46 @@ func update_error(err_id: SVGParser.ParseError) -> void:
var error_bar_real_height := error_bar.size.y - 2
code_edit.custom_minimum_size.y -= error_bar_real_height
code_edit.size.y -= error_bar_real_height
setup_theme(true)
setup_theme()

func setup_theme(match_below: bool) -> void:
func setup_theme() -> void:
# Set up the code edit.
code_edit.begin_bulk_theme_override()
for theming in ["normal", "focus", "hover"]:
var stylebox := get_theme_stylebox(theming, "TextEdit").duplicate()
stylebox.corner_radius_top_right = 0
stylebox.corner_radius_top_left = 0
stylebox.border_width_top = 2
if match_below:
if error_bar.visible:
stylebox.corner_radius_bottom_right = 0
stylebox.corner_radius_bottom_left = 0
stylebox.border_width_bottom = 1
code_edit.add_theme_stylebox_override(theming, stylebox)
code_edit.end_bulk_theme_override()

error_label.add_theme_color_override("default_color", GlobalSettings.basic_color_error)
var panel_stylebox := get_theme_stylebox("panel", "PanelContainer")
# Set up the top panel.
var top_stylebox := panel_stylebox.duplicate()
top_stylebox.border_color = code_edit.get_theme_stylebox("normal").border_color
top_stylebox.border_width_bottom = 0
top_stylebox.corner_radius_bottom_right = 0
top_stylebox.corner_radius_bottom_left = 0
top_stylebox.content_margin_left = 8
top_stylebox.content_margin_right = 6
top_stylebox.content_margin_top = 3
top_stylebox.content_margin_bottom = 1
panel_container.add_theme_stylebox_override("panel", top_stylebox)
# Set up the bottom panel.
var bottom_stylebox := panel_stylebox.duplicate()
bottom_stylebox.border_color = code_edit.get_theme_stylebox("normal").border_color
bottom_stylebox.corner_radius_top_right = 0
bottom_stylebox.corner_radius_top_left = 0
bottom_stylebox.content_margin_left = 10
bottom_stylebox.content_margin_right = 8
bottom_stylebox.content_margin_top = -1
bottom_stylebox.content_margin_bottom = -1
error_bar.add_theme_stylebox_override("panel", bottom_stylebox)


func _on_copy_button_pressed() -> void:
Expand Down
2 changes: 1 addition & 1 deletion src/ui_parts/display.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ script = ExtResource("6_3v3ve")
hover_pressed_stylebox = SubResource("StyleBoxFlat_eujxa")

[node name="SnapNumberEdit" parent="PanelContainer/HBoxContainer/LeftMenu/Snapping" instance=ExtResource("7_wrrfr")]
custom_minimum_size = Vector2(46, 22)
custom_minimum_size = Vector2(48, 22)
layout_mode = 2
tooltip_text = "Snap size"
theme_type_variation = &"LeftConnectedLineEdit"
Expand Down
11 changes: 4 additions & 7 deletions src/ui_parts/export_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,17 @@ func _on_dropdown_value_changed(new_value: String) -> void:
update_extension_configuration()


func native_file_export(has_selected: bool, files: PackedStringArray,
_filter_idx: int) -> void:
if has_selected:
SVG.finish_export(files[0], extension, upscale_amount)

func _on_ok_button_pressed() -> void:
if OS.has_feature("web"):
match extension:
"png":
HandlerGUI.web_save_png(SVG.generate_image_from_tags())
HandlerGUI.web_save_png(SVG.generate_image_from_tags(upscale_amount))
_:
HandlerGUI.web_save_svg()
else:
SVG.open_save_dialog(extension, native_file_export, SVG.finish_export.bind(extension))
SVG.open_save_dialog(extension,
SVG.native_file_export.bind(extension, upscale_amount),
SVG.finish_export.bind(extension, upscale_amount))

func _on_cancel_button_pressed() -> void:
HandlerGUI.remove_overlay()
Expand Down
9 changes: 7 additions & 2 deletions src/ui_parts/good_file_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const AlertDialog = preload("res://src/ui_parts/alert_dialog.tscn")
signal file_selected(path: String)

const folder_icon = preload("res://visual/icons/Folder.svg")
const broken_file_icon = preload("res://visual/icons/FileBroken.svg")

const system_dir_icons = {
OS.SYSTEM_DIR_DESKTOP: preload("res://visual/icons/DirDesktop.svg"),
OS.SYSTEM_DIR_DOCUMENTS: preload("res://visual/icons/DirDocuments.svg"),
Expand Down Expand Up @@ -203,8 +205,11 @@ func _setup_file_images() -> void:
var file := file_list.get_item_text(item_idx)
match file.get_extension():
"png":
file_list.set_item_icon(item_idx, ImageTexture.create_from_image(
Image.load_from_file(current_dir.path_join(file))))
var img := Image.load_from_file(current_dir.path_join(file))
if img == null:
file_list.set_item_icon(item_idx, broken_file_icon)
else:
file_list.set_item_icon(item_idx, ImageTexture.create_from_image(img))
"svg":
# Setup a clean SVG graphic by using the scaling parameter.
var svg_text := FileAccess.open(current_dir.path_join(file),
Expand Down
4 changes: 2 additions & 2 deletions src/ui_parts/import_warning_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ signal imported
var imported_text := ""

func _ready() -> void:
ok_button.grab_focus()
imported.connect(queue_free)
# Convert forward and backward to show how GodSVG would display the given SVG.
var imported_text_parse_result := SVGParser.text_to_svg(imported_text)
var preview_text := SVGParser.svg_to_text(imported_text_parse_result.svg)
Expand All @@ -37,7 +37,7 @@ func _ready() -> void:
GlobalSettings.basic_color_warning)
for warning in svg_warnings:
warnings_label.text += warning + "\n"
imported.connect(queue_free)
ok_button.grab_focus()
cancel_button.pressed.connect(queue_free)


Expand Down
40 changes: 26 additions & 14 deletions src/ui_parts/settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ const SettingColor = preload("res://src/ui_elements/setting_color.gd")

@onready var lang_button: Button = %Language
@onready var palette_container: VBoxContainer = %PaletteContainer
@onready var shortcut_container: VBoxContainer = %ShortcutContainer
@onready var content_container: MarginContainer = %ContentContainer
@onready var tabs: VBoxContainer = %Tabs

@onready var wrap_mouse: HBoxContainer = %WrapMouse
@onready var use_native_file_dialog: HBoxContainer = %UseNativeFileDialog

@onready var configurable_shortcuts: VBoxContainer = %ConfigurableShortcuts
@onready var non_configurable_shortcuts: VBoxContainer = %NonConfigurableShortcuts
@onready var shortcut_categories: HFlowContainer = %Categories
@onready var shortcut_container: VBoxContainer = %Shortcuts

var focused_content := 0

Expand Down Expand Up @@ -218,27 +217,40 @@ func disable_autoformat_checkboxes() -> void:


func setup_shortcuts_tab() -> void:
for action in GlobalSettings.configurable_keybinds:
shortcut_categories.add_child(Utils.create_btn(tr("File"), show_keybinds.bind("file")))
shortcut_categories.add_child(Utils.create_btn(tr("Edit"), show_keybinds.bind("edit")))
shortcut_categories.add_child(Utils.create_btn(tr("View"), show_keybinds.bind("view")))
shortcut_categories.add_child(Utils.create_btn(tr("Tool"), show_tool_keybinds))
# Add them all to a button group.
var button_group := ButtonGroup.new()
for btn: Button in shortcut_categories.get_children():
btn.toggle_mode = true
btn.button_group = button_group
shortcut_categories.get_child(0).button_pressed = true
show_keybinds("file")

func show_keybinds(category: String):
for child in shortcut_container.get_children():
child.queue_free()
for action in GlobalSettings.configurable_keybinds[category]:
var keybind_config := ShortcutConfigWidget.instantiate()
configurable_shortcuts.add_child(keybind_config)
shortcut_container.add_child(keybind_config)
keybind_config.label.text = shortcut_descriptions[action] if\
action in shortcut_descriptions else action
keybind_config.setup(action)
for action in ["move_relative", "move_absolute", "line_relative", "line_absolute",
"horizontal_line_relative", "horizontal_line_absolute", "vertical_line_relative",
"vertical_line_absolute", "close_path_relative", "close_path_absolute",
"elliptical_arc_relative", "elliptical_arc_absolute", "quadratic_bezier_relative",
"quadratic_bezier_absolute", "shorthand_quadratic_bezier_relative",
"shorthand_quadratic_bezier_absolute", "cubic_bezier_relative",
"cubic_bezier_absolute", "shorthand_cubic_bezier_relative",
"shorthand_cubic_bezier_absolute"]:

func show_tool_keybinds() -> void:
for child in shortcut_container.get_children():
child.queue_free()
for action in GlobalSettings.unconfigurable_keybinds:
var keybind_config := ShortcutShowcaseWidget.instantiate()
non_configurable_shortcuts.add_child(keybind_config)
shortcut_container.add_child(keybind_config)
keybind_config.label.text = shortcut_descriptions[action] if\
action in shortcut_descriptions else action
keybind_config.setup(action)



func setup_theming_tab() -> void:
for child in %HighlighterVBox.get_children():
if child is SettingColor:
Expand Down
11 changes: 2 additions & 9 deletions src/ui_parts/settings_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,11 @@ unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3

[node name="ConfigurableShortcuts" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/MainPanel/ContentContainer/Shortcuts/ShortcutContainer"]
[node name="Categories" type="HFlowContainer" parent="VBoxContainer/HBoxContainer/MainPanel/ContentContainer/Shortcuts/ShortcutContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 3

[node name="NonConfigurableShortcuts" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/MainPanel/ContentContainer/Shortcuts/ShortcutContainer"]
[node name="Shortcuts" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/MainPanel/ContentContainer/Shortcuts/ShortcutContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
Expand Down Expand Up @@ -541,12 +538,8 @@ text = "Close"

[connection signal="pressed" from="VBoxContainer/Language" to="." method="_on_language_pressed"]
[connection signal="toggled" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/AutoformattingTab" to="." method="_on_autoformatting_tab_toggled"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/PalettesTab" to="." method="_on_palettes_tab_pressed"]
[connection signal="toggled" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/PalettesTab" to="." method="_on_palettes_tab_toggled"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/ShortcutsTab" to="." method="_on_shortcuts_tab_pressed"]
[connection signal="toggled" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/ShortcutsTab" to="." method="_on_shortcuts_tab_toggled"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/ThemeTab" to="." method="_on_theme_tab_pressed"]
[connection signal="toggled" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/ThemeTab" to="." method="_on_theme_tab_toggled"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/OtherTab" to="." method="_on_other_tab_pressed"]
[connection signal="toggled" from="VBoxContainer/HBoxContainer/ContentPicker/ScrollContainer/Tabs/OtherTab" to="." method="_on_other_tab_toggled"]
[connection signal="pressed" from="VBoxContainer/Close" to="." method="_on_close_pressed"]
1 change: 1 addition & 0 deletions visual/icons/FileBroken.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 visual/icons/FileBroken.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cr4fc0hsu58lf"
path="res://.godot/imported/FileBroken.svg-08ba8dbd963d3e7aff9ab514b7618a79.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://visual/icons/FileBroken.svg"
dest_files=["res://.godot/imported/FileBroken.svg-08ba8dbd963d3e7aff9ab514b7618a79.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 visual/icons/PlatformLinux.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading