Skip to content

Commit

Permalink
Implement Show in File Manager option (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur authored Jan 28, 2025
1 parent 9c2f6c9 commit 947fd70
Show file tree
Hide file tree
Showing 22 changed files with 2,093 additions and 1,340 deletions.
303 changes: 183 additions & 120 deletions assets/translations/GodSVG.pot

Large diffs are not rendered by default.

341 changes: 199 additions & 142 deletions assets/translations/bg.po

Large diffs are not rendered by default.

369 changes: 230 additions & 139 deletions assets/translations/de.po

Large diffs are not rendered by default.

303 changes: 183 additions & 120 deletions assets/translations/en.po

Large diffs are not rendered by default.

362 changes: 226 additions & 136 deletions assets/translations/fr.po

Large diffs are not rendered by default.

362 changes: 226 additions & 136 deletions assets/translations/nl.po

Large diffs are not rendered by default.

369 changes: 230 additions & 139 deletions assets/translations/ru.po

Large diffs are not rendered by default.

369 changes: 230 additions & 139 deletions assets/translations/uk.po

Large diffs are not rendered by default.

369 changes: 230 additions & 139 deletions assets/translations/zh.po

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions godot_only/scripts/update_translations.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@tool
extends EditorScript

const TRANSLATIONS_DIR = "assets/translations"

const HEADER = """#, fuzzy
msgid \"\"
msgstr \"\"
Expand Down Expand Up @@ -82,28 +84,28 @@ func search_directory(dir: String) -> void:


func update_translations() -> void:
var location := ProjectSettings.globalize_path("translations/GodSVG.pot")
var location := ProjectSettings.globalize_path(TRANSLATIONS_DIR + "/GodSVG.pot")
var fa := FileAccess.open(location, FileAccess.WRITE)
fa.store_string(HEADER)

for msg in messages:
fa.store_string(msg.to_string())
fa = null
print("Created translations/GodSVG.pot with %d strings" % (messages.size() + 1))
print("Created " + TRANSLATIONS_DIR + "/GodSVG.pot with %d strings" % (messages.size() + 1))

var files := DirAccess.get_files_at(ProjectSettings.globalize_path("translations"))
var files := DirAccess.get_files_at(ProjectSettings.globalize_path(TRANSLATIONS_DIR))
for file in files:
if not (file.get_extension() == "po" or file == "GodSVG.pot"):
continue

var args := PackedStringArray(["--update", "--quiet", "--verbose", "--backup=off",
ProjectSettings.globalize_path("translations").path_join(file), location])
ProjectSettings.globalize_path(TRANSLATIONS_DIR).path_join(file), location])
var output: Array = []
var result := OS.execute("msgmerge", args, output, true)
if not result == -1:
if file == "GodSVG.pot":
continue
elif not output.is_empty():
print("Updated translations/%s: %s" % [file, output[0].rstrip("\n")])
print("Updated " + TRANSLATIONS_DIR + "/%s: %s" % [file, output[0].rstrip("\n")])
else:
print("Updated translations%s" % file)
print("Updated " + TRANSLATIONS_DIR + "%s" % file)
6 changes: 5 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ reset_svg={
"deadzone": 0.2,
"events": []
}
open_svg={
open_externally={
"deadzone": 0.2,
"events": []
}
open_in_folder={
"deadzone": 0.2,
"events": []
}
Expand Down
6 changes: 6 additions & 0 deletions src/ui_parts/display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ConfirmDialog := preload("res://src/ui_widgets/confirm_dialog.tscn")
@onready var debug_container: MarginContainer = $ViewportPanel/DebugMargins
@onready var debug_label: Label = %DebugContainer/DebugLabel
@onready var input_debug_label: Label = %DebugContainer/InputDebugLabel
@onready var toolbar: PanelContainer = $ViewportPanel/VBoxContainer/Toolbar

var reference_overlay := false

Expand Down Expand Up @@ -68,6 +69,11 @@ func update_translations() -> void:
"Snap size")

func update_theme() -> void:
var toolbar_stylebox := StyleBoxFlat.new()
toolbar_stylebox.bg_color = ThemeUtils.overlay_panel_inner_color.lerp(Color.WHITE, 0.01)
toolbar_stylebox.set_content_margin_all(4)
toolbar.add_theme_stylebox_override("panel", toolbar_stylebox)

var frame := StyleBoxFlat.new()
frame.draw_center = false
frame.border_width_left = 2
Expand Down
36 changes: 16 additions & 20 deletions src/ui_parts/display.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,20 @@ size_flags_vertical = 3
layout_mode = 2
theme_override_constants/separation = 0

[node name="MarginContainer" type="MarginContainer" parent="ViewportPanel/VBoxContainer"]
[node name="Toolbar" type="PanelContainer" parent="ViewportPanel/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 4
theme_override_constants/margin_top = 4
theme_override_constants/margin_right = 4
theme_override_constants/margin_bottom = 4

[node name="ViewportOptions" type="HBoxContainer" parent="ViewportPanel/VBoxContainer/MarginContainer"]
[node name="ViewportOptions" type="HBoxContainer" parent="ViewportPanel/VBoxContainer/Toolbar"]
layout_mode = 2
alignment = 2

[node name="LeftMenu" type="HBoxContainer" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions"]
[node name="LeftMenu" type="HBoxContainer" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 2
theme_override_constants/separation = 5

[node name="Visuals" type="Button" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu"]
[node name="Visuals" type="Button" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu"]
layout_mode = 2
size_flags_horizontal = 2
focus_mode = 0
Expand All @@ -74,7 +70,7 @@ theme_type_variation = &"IconButton"
icon = ExtResource("4_n3qjt")
icon_alignment = 1

[node name="Reference" type="Button" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu"]
[node name="Reference" type="Button" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu"]
layout_mode = 2
size_flags_horizontal = 2
focus_mode = 0
Expand All @@ -83,11 +79,11 @@ theme_type_variation = &"IconButton"
icon = ExtResource("4_2hiq7")
icon_alignment = 1

[node name="Snapping" type="HBoxContainer" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu"]
[node name="Snapping" type="HBoxContainer" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu"]
layout_mode = 2
theme_override_constants/separation = 0

[node name="SnapButton" type="Button" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu/Snapping"]
[node name="SnapButton" type="Button" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu/Snapping"]
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
Expand All @@ -97,7 +93,7 @@ icon = ExtResource("5_1k2cq")
script = ExtResource("6_3v3ve")
hover_pressed_stylebox = SubResource("StyleBoxFlat_eujxa")

[node name="SnapNumberEdit" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu/Snapping" instance=ExtResource("7_wrrfr")]
[node name="SnapNumberEdit" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu/Snapping" instance=ExtResource("7_wrrfr")]
custom_minimum_size = Vector2(48, 22)
layout_mode = 2
theme_type_variation = &"LeftConnectedLineEdit"
Expand All @@ -106,7 +102,7 @@ editable = false
min_value = 0.001
allow_lower = false

[node name="ZoomMenu" parent="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions" instance=ExtResource("8_xtdmn")]
[node name="ZoomMenu" parent="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions" instance=ExtResource("8_xtdmn")]
unique_name_in_owner = true
layout_mode = 2

Expand All @@ -121,7 +117,7 @@ unique_name_in_owner = true
disable_3d = true
handle_input_locally = false
gui_snap_controls_to_pixels = false
size = Vector2i(1040, 587)
size = Vector2i(1040, 595)
size_2d_override_stretch = true
render_target_update_mode = 4
script = ExtResource("9_4xrk7")
Expand Down Expand Up @@ -197,10 +193,10 @@ theme_override_constants/outline_size = 4
theme_override_font_sizes/font_size = 14
horizontal_alignment = 2

[connection signal="pressed" from="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu/Visuals" to="." method="_on_visuals_button_pressed"]
[connection signal="pressed" from="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu/Reference" to="." method="_on_reference_pressed"]
[connection signal="toggled" from="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu/Snapping/SnapButton" to="." method="_on_snap_button_toggled"]
[connection signal="value_changed" from="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/LeftMenu/Snapping/SnapNumberEdit" to="." method="_on_snap_number_edit_value_changed"]
[connection signal="zoom_changed" from="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/ZoomMenu" to="ViewportPanel/VBoxContainer/ViewportContainer/Viewport" method="_on_zoom_changed"]
[connection signal="zoom_reset_pressed" from="ViewportPanel/VBoxContainer/MarginContainer/ViewportOptions/ZoomMenu" to="ViewportPanel/VBoxContainer/ViewportContainer/Viewport" method="center_frame"]
[connection signal="pressed" from="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu/Visuals" to="." method="_on_visuals_button_pressed"]
[connection signal="pressed" from="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu/Reference" to="." method="_on_reference_pressed"]
[connection signal="toggled" from="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu/Snapping/SnapButton" to="." method="_on_snap_button_toggled"]
[connection signal="value_changed" from="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/LeftMenu/Snapping/SnapNumberEdit" to="." method="_on_snap_number_edit_value_changed"]
[connection signal="zoom_changed" from="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/ZoomMenu" to="ViewportPanel/VBoxContainer/ViewportContainer/Viewport" method="_on_zoom_changed"]
[connection signal="zoom_reset_pressed" from="ViewportPanel/VBoxContainer/Toolbar/ViewportOptions/ZoomMenu" to="ViewportPanel/VBoxContainer/ViewportContainer/Viewport" method="center_frame"]
[connection signal="size_changed" from="ViewportPanel/VBoxContainer/ViewportContainer/Viewport" to="ViewportPanel/VBoxContainer/ViewportContainer/Viewport" method="_on_size_changed"]
1 change: 1 addition & 0 deletions src/ui_parts/editor_scene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ theme_override_constants/margin_bottom = 6

[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/HSplitContainer/MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 6

[node name="GlobalActions" parent="PanelContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("3_852uu")]
layout_mode = 2
Expand Down
80 changes: 80 additions & 0 deletions src/ui_parts/global_actions.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ extends HBoxContainer
@onready var export_button: Button = $RightSide/ExportButton
@onready var more_options: Button = $LeftSide/MoreOptions
@onready var settings_button: Button = $LeftSide/SettingsButton
@onready var size_button: Button = $RightSide/SizeButton
@onready var file_button: Button = $RightSide/FileButton

func update_translations() -> void:
import_button.tooltip_text = Translator.translate("Import")
Expand All @@ -13,12 +15,61 @@ func update_translations() -> void:
func _ready() -> void:
Configs.language_changed.connect(update_translations)
update_translations()

State.svg_changed.connect(update_size_button)
Configs.active_tab_file_path_changed.connect(update_file_button)
Configs.active_tab_changed.connect(update_file_button)
Configs.basic_colors_changed.connect(update_size_button_colors)
update_file_button()

# Fix the size button sizing.
size_button.begin_bulk_theme_override()
for theming in ["normal", "hover", "pressed", "disabled"]:
var stylebox := size_button.get_theme_stylebox(theming).duplicate()
stylebox.content_margin_bottom = 0
stylebox.content_margin_top = 0
size_button.add_theme_stylebox_override(theming, stylebox)
size_button.end_bulk_theme_override()

import_button.pressed.connect(ShortcutUtils.fn("import"))
export_button.pressed.connect(ShortcutUtils.fn("export"))
more_options.pressed.connect(_on_more_options_pressed)
size_button.pressed.connect(_on_size_button_pressed)
file_button.pressed.connect(_on_file_button_pressed)
settings_button.pressed.connect(ShortcutUtils.fn_call.bind("open_settings"))


func _on_size_button_pressed() -> void:
var btn_array: Array[Button] = [
ContextPopup.create_button(Translator.translate("Optimize"),
ShortcutUtils.fn("optimize"), false, load("res://assets/icons/Compress.svg"),
"optimize")]
var context_popup := ContextPopup.new()
context_popup.setup(btn_array, true)
HandlerGUI.popup_under_rect_center(context_popup, size_button.get_global_rect(),
get_viewport())

func _on_file_button_pressed() -> void:
var btn_array: Array[Button] = []
btn_array.append(ContextPopup.create_button(Translator.translate("Save SVG"),
FileUtils.save_svg, false, load("res://assets/icons/Save.svg"), "save"))
btn_array.append(ContextPopup.create_button(Translator.translate("Reset SVG"),
ShortcutUtils.fn("reset_svg"),
FileUtils.compare_svg_to_disk_contents() != FileUtils.FileState.DIFFERENT,
load("res://assets/icons/Reload.svg"), "reset_svg"))
btn_array.append(ContextPopup.create_button(Translator.translate("Open externally"),
ShortcutUtils.fn("open_externally"),
not FileAccess.file_exists(Configs.savedata.get_active_tab().svg_file_path),
load("res://assets/icons/OpenFile.svg"), "open_externally"))
btn_array.append(ContextPopup.create_button(Translator.translate("Show in File Manager"),
ShortcutUtils.fn("open_in_folder"),
not FileAccess.file_exists(Configs.savedata.get_active_tab().svg_file_path),
load("res://assets/icons/OpenFolder.svg"), "open_in_folder"))
var context_popup := ContextPopup.new()
context_popup.setup(btn_array, true, file_button.size.x, -1, PackedInt32Array([2]))
HandlerGUI.popup_under_rect_center(context_popup, file_button.get_global_rect(),
get_viewport())

func _on_more_options_pressed() -> void:
var can_show_savedata_folder := DisplayServer.has_feature(
DisplayServer.FEATURE_NATIVE_DIALOG_FILE)
Expand Down Expand Up @@ -58,3 +109,32 @@ func _on_more_options_pressed() -> void:

func open_savedata_folder() -> void:
OS.shell_show_in_file_manager(ProjectSettings.globalize_path("user://"))


func update_size_button() -> void:
var svg_text_size := State.svg_text.length()
size_button.text = String.humanize_size(svg_text_size)
size_button.tooltip_text = String.num_uint64(svg_text_size) + " B"
if State.root_element.optimize(true):
size_button.disabled = false
size_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
update_size_button_colors()
else:
size_button.disabled = true
size_button.mouse_default_cursor_shape = Control.CURSOR_ARROW
size_button.remove_theme_color_override("font_color")

func update_size_button_colors() -> void:
size_button.begin_bulk_theme_override()
for theming in ["font_color", "font_hover_color", "font_pressed_color"]:
size_button.add_theme_color_override(theming,
Configs.savedata.basic_color_warning.lerp(Color.WHITE, 0.5))
size_button.end_bulk_theme_override()

func update_file_button() -> void:
var file_name := State.transient_tab_path.get_file() if\
not State.transient_tab_path.is_empty() else\
Configs.savedata.get_active_tab().get_presented_name()
file_button.text = file_name
file_button.tooltip_text = file_name
Utils.set_max_text_width(file_button, 140.0, 12.0)
18 changes: 17 additions & 1 deletion src/ui_parts/global_actions.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[gd_scene load_steps=6 format=3 uid="uid://cxmrx6t4jkhyj"]
[gd_scene load_steps=7 format=3 uid="uid://cxmrx6t4jkhyj"]

[ext_resource type="Script" uid="uid://cgbgw4ok5jxk5" path="res://src/ui_parts/global_actions.gd" id="1_x4rqo"]
[ext_resource type="Texture2D" uid="uid://ccbta5q43jobk" path="res://assets/icons/More.svg" id="2_71075"]
[ext_resource type="Texture2D" uid="uid://6ymbl3jqersp" path="res://assets/icons/Import.svg" id="2_giwu1"]
[ext_resource type="Texture2D" uid="uid://d0uvwj0t44n6v" path="res://assets/icons/Export.svg" id="3_4ckhj"]
[ext_resource type="Texture2D" uid="uid://ckkkgof1hcbld" path="res://assets/icons/Gear.svg" id="3_xl5uh"]
[ext_resource type="FontFile" uid="uid://dc0w4sx0h0fui" path="res://assets/fonts/FontBold.ttf" id="4_xl5uh"]

[node name="GlobalActions" type="HBoxContainer"]
offset_right = 52.0
Expand Down Expand Up @@ -36,6 +37,21 @@ icon_alignment = 1
[node name="RightSide" type="HBoxContainer" parent="."]
layout_mode = 2

[node name="SizeButton" type="Button" parent="RightSide"]
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"TranslucentButton"
theme_override_fonts/font = ExtResource("4_xl5uh")

[node name="FileButton" type="Button" parent="RightSide"]
layout_mode = 2
size_flags_horizontal = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"FlatButton"
text_overrun_behavior = 3

[node name="ImportButton" type="Button" parent="RightSide"]
layout_mode = 2
focus_mode = 0
Expand Down
14 changes: 11 additions & 3 deletions src/ui_parts/tab_bar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func _gui_input(event: InputEvent) -> void:
if hovered_idx == -1:
btn_arr.append(ContextPopup.create_button(Translator.translate("Create tab"),
Configs.savedata.add_empty_tab, false,
load("res://assets/icons/CreateTab.svg"), "close_tab"))
load("res://assets/icons/CreateTab.svg"), "new_tab"))
else:
btn_arr.append(ContextPopup.create_button(Translator.translate("Close tab"),
close_tab.bind(hovered_idx), false, null, "close_tab"))
Expand All @@ -107,8 +107,16 @@ func _gui_input(event: InputEvent) -> void:
Translator.translate("Close tabs to the right"),
close_tabs_to_right.bind(hovered_idx),
hovered_idx == Configs.savedata.get_tab_count() - 1, null))
btn_arr.append(ContextPopup.create_button(Translator.translate("Open externally"),
ShortcutUtils.fn("open_externally"),
not FileAccess.file_exists(Configs.savedata.get_active_tab().svg_file_path),
load("res://assets/icons/OpenFile.svg"), "open_externally"))
btn_arr.append(ContextPopup.create_button(Translator.translate("Show in File Manager"),
ShortcutUtils.fn("open_in_folder"),
not FileAccess.file_exists(Configs.savedata.get_active_tab().svg_file_path),
load("res://assets/icons/OpenFolder.svg"), "open_in_folder"))
var tab_popup := ContextPopup.new()
tab_popup.setup(btn_arr, true)
tab_popup.setup(btn_arr, true, -1, -1, PackedInt32Array([4]))

if hovered_idx != -1:
var tab_global_rect := get_tab_rect(hovered_idx)
Expand Down Expand Up @@ -197,7 +205,7 @@ func activate() -> void:
add_button.position = add_rect.position
add_button.size = add_rect.size
add_button.mouse_filter = Control.MOUSE_FILTER_PASS
add_button.tooltip_text = Translator.translate("Add new tab")
add_button.tooltip_text = Translator.translate("Create a new tab")
add_child(add_button)
active_controls.append(add_button)
add_button.pressed.connect(Configs.savedata.add_empty_tab)
Expand Down
Loading

0 comments on commit 947fd70

Please sign in to comment.