1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Choose which layout to copy from when adding a new layout

This commit is contained in:
Emmanouil Papadeas 2024-02-02 02:59:07 +02:00
parent 534a7fd356
commit 5824d2a0eb
3 changed files with 86 additions and 49 deletions

View file

@ -289,7 +289,13 @@ msgstr ""
msgid "Add Layout" msgid "Add Layout"
msgstr "" msgstr ""
msgid "Edit Layout" msgid "Copy from"
msgstr ""
msgid "Rename"
msgstr ""
msgid "Rename Layout"
msgstr "" msgstr ""
msgid "Are you sure you want to delete this layout?" msgid "Are you sure you want to delete this layout?"

View file

@ -3,13 +3,20 @@ extends AcceptDialog
var layout_selected := -1 var layout_selected := -1
var is_editing := false var is_editing := false
@onready var layout_list: ItemList = find_child("SavedLayouts") @onready var layout_list := %SavedLayouts as ItemList
@onready var edit_layout: Button = find_child("EditLayout") @onready var rename_layout := %RenameLayout as Button
@onready var delete_layout: Button = find_child("DeleteLayout") @onready var delete_layout := %DeleteLayout as Button
@onready var layout_settings: ConfirmationDialog = $LayoutSettings @onready var layout_settings := $LayoutSettings as ConfirmationDialog
@onready var layout_name: LineEdit = $LayoutSettings/LayoutName @onready var layout_name := %LayoutName as LineEdit
@onready var delete_confirmation: ConfirmationDialog = $DeleteConfirmation @onready var layout_from := %LayoutFrom as OptionButton
@onready var mimic_ui = find_child("LayoutPreview") @onready var delete_confirmation := $DeleteConfirmation as ConfirmationDialog
@onready var mimic_ui := %LayoutPreview as DockableContainer
func _ready() -> void:
# Fill the copy layout from option button with the default layouts
for layout in Global.default_layouts:
layout_from.add_item(layout.resource_path.get_basename().get_file())
func _on_ManageLayouts_about_to_show() -> void: func _on_ManageLayouts_about_to_show() -> void:
@ -33,13 +40,13 @@ func _on_SavedLayouts_item_activated(index: int) -> void:
func _on_SavedLayouts_item_selected(index: int) -> void: func _on_SavedLayouts_item_selected(index: int) -> void:
layout_selected = index layout_selected = index
edit_layout.disabled = false rename_layout.disabled = false
delete_layout.disabled = false delete_layout.disabled = false
refresh_preview() refresh_preview()
func _on_SavedLayouts_empty_clicked(_position: Vector2, _button_index: int) -> void: func _on_SavedLayouts_empty_clicked(_position: Vector2, _button_index: int) -> void:
edit_layout.disabled = true rename_layout.disabled = true
delete_layout.disabled = true delete_layout.disabled = true
@ -47,13 +54,15 @@ func _on_AddLayout_pressed() -> void:
is_editing = false is_editing = false
layout_name.text = "New Layout" layout_name.text = "New Layout"
layout_settings.title = "Add Layout" layout_settings.title = "Add Layout"
layout_from.get_parent().visible = true
layout_settings.popup_centered() layout_settings.popup_centered()
func _on_EditLayout_pressed() -> void: func _on_rename_layout_pressed() -> void:
is_editing = true is_editing = true
layout_name.text = layout_list.get_item_text(layout_selected) layout_name.text = layout_list.get_item_text(layout_selected)
layout_settings.title = "Edit Layout" layout_settings.title = "Rename Layout"
layout_from.get_parent().visible = false
layout_settings.popup_centered() layout_settings.popup_centered()
@ -64,13 +73,17 @@ func _on_DeleteLayout_pressed() -> void:
func _on_LayoutSettings_confirmed() -> void: func _on_LayoutSettings_confirmed() -> void:
var file_name := layout_name.text + ".tres" var file_name := layout_name.text + ".tres"
var path := Global.LAYOUT_DIR.path_join(file_name) var path := Global.LAYOUT_DIR.path_join(file_name)
var layout: DockableLayout = Global.control.main_ui.layout.clone() var layout: DockableLayout
if layout_from.selected == 0:
layout = Global.control.main_ui.layout.clone()
else:
layout = Global.default_layouts[layout_from.selected - 1].clone()
layout.resource_name = layout_name.text layout.resource_name = layout_name.text
layout.resource_path = path layout.resource_path = path
var err := ResourceSaver.save(layout, path) var err := ResourceSaver.save(layout, path)
if err != OK: if err != OK:
print(err) print(err)
else: return
if is_editing: if is_editing:
var old_file_name: String = layout_list.get_item_text(layout_selected) + ".tres" var old_file_name: String = layout_list.get_item_text(layout_selected) + ".tres"
if old_file_name != file_name: if old_file_name != file_name:
@ -104,12 +117,12 @@ func _on_DeleteConfirmation_confirmed() -> void:
layout_list.remove_item(layout_selected) layout_list.remove_item(layout_selected)
Global.top_menu_container.populate_layouts_submenu() Global.top_menu_container.populate_layouts_submenu()
layout_selected = -1 layout_selected = -1
edit_layout.disabled = true rename_layout.disabled = true
delete_layout.disabled = true delete_layout.disabled = true
refresh_preview() refresh_preview()
func refresh_preview(): func refresh_preview() -> void:
for tab in mimic_ui.get_tabs(): for tab in mimic_ui.get_tabs():
mimic_ui.remove_child(tab) mimic_ui.remove_child(tab)
for item in Global.control.main_ui.get_tabs(): for item in Global.control.main_ui.get_tabs():

View file

@ -20,6 +20,7 @@ save_on_change = false
[node name="ManageLayouts" type="AcceptDialog"] [node name="ManageLayouts" type="AcceptDialog"]
title = "Manage Layouts" title = "Manage Layouts"
size = Vector2i(500, 500)
exclusive = false exclusive = false
popup_window = true popup_window = true
script = ExtResource("1") script = ExtResource("1")
@ -31,7 +32,7 @@ anchor_bottom = 1.0
offset_left = 8.0 offset_left = 8.0
offset_top = 8.0 offset_top = 8.0
offset_right = -8.0 offset_right = -8.0
offset_bottom = -36.0 offset_bottom = -49.0
[node name="PreviewHeader" type="HBoxContainer" parent="VBoxContainer"] [node name="PreviewHeader" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2 layout_mode = 2
@ -55,6 +56,7 @@ layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="LayoutPreview" type="Container" parent="VBoxContainer/PreviewContainer"] [node name="LayoutPreview" type="Container" parent="VBoxContainer/PreviewContainer"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
@ -80,6 +82,7 @@ layout_mode = 2
text = "Double click to set as new startup layout" text = "Double click to set as new startup layout"
[node name="SavedLayouts" type="ItemList" parent="VBoxContainer"] [node name="SavedLayouts" type="ItemList" parent="VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 100) custom_minimum_size = Vector2(0, 100)
layout_mode = 2 layout_mode = 2
@ -88,38 +91,53 @@ layout_mode = 2
[node name="AddLayout" type="Button" parent="VBoxContainer/ButtonsContainer"] [node name="AddLayout" type="Button" parent="VBoxContainer/ButtonsContainer"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 0 size_flags_horizontal = 3
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
text = "Add" text = "Add"
[node name="EditLayout" type="Button" parent="VBoxContainer/ButtonsContainer"] [node name="RenameLayout" type="Button" parent="VBoxContainer/ButtonsContainer"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 0 size_flags_horizontal = 3
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
disabled = true disabled = true
text = "Edit" text = "Rename"
[node name="DeleteLayout" type="Button" parent="VBoxContainer/ButtonsContainer"] [node name="DeleteLayout" type="Button" parent="VBoxContainer/ButtonsContainer"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 0 size_flags_horizontal = 3
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
disabled = true disabled = true
text = "Delete" text = "Delete"
[node name="LayoutSettings" type="ConfirmationDialog" parent="."] [node name="LayoutSettings" type="ConfirmationDialog" parent="."]
[node name="LayoutName" type="LineEdit" parent="LayoutSettings"] [node name="VBoxContainer" type="VBoxContainer" parent="LayoutSettings"]
anchors_preset = 14 offset_right = 40.0
anchor_top = 0.5 offset_bottom = 40.0
anchor_right = 1.0
anchor_bottom = 0.5 [node name="LayoutName" type="LineEdit" parent="LayoutSettings/VBoxContainer"]
offset_left = 8.0 unique_name_in_owner = true
offset_top = -26.0 layout_mode = 2
offset_right = -8.0
offset_bottom = -2.0
size_flags_horizontal = 3 size_flags_horizontal = 3
placeholder_text = "Insert name" placeholder_text = "Insert name"
[node name="HBoxContainer" type="HBoxContainer" parent="LayoutSettings/VBoxContainer"]
layout_mode = 2
[node name="LayoutFromLabel" type="Label" parent="LayoutSettings/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Copy from"
[node name="LayoutFrom" type="OptionButton" parent="LayoutSettings/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
item_count = 1
selected = 0
popup/item_0/text = "Current layout"
popup/item_0/id = 0
[node name="DeleteConfirmation" type="ConfirmationDialog" parent="."] [node name="DeleteConfirmation" type="ConfirmationDialog" parent="."]
dialog_text = "Are you sure you want to delete this layout?" dialog_text = "Are you sure you want to delete this layout?"
@ -129,7 +147,7 @@ dialog_text = "Are you sure you want to delete this layout?"
[connection signal="item_activated" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_activated"] [connection signal="item_activated" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_activated"]
[connection signal="item_selected" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_selected"] [connection signal="item_selected" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_selected"]
[connection signal="pressed" from="VBoxContainer/ButtonsContainer/AddLayout" to="." method="_on_AddLayout_pressed"] [connection signal="pressed" from="VBoxContainer/ButtonsContainer/AddLayout" to="." method="_on_AddLayout_pressed"]
[connection signal="pressed" from="VBoxContainer/ButtonsContainer/EditLayout" to="." method="_on_EditLayout_pressed"] [connection signal="pressed" from="VBoxContainer/ButtonsContainer/RenameLayout" to="." method="_on_rename_layout_pressed"]
[connection signal="pressed" from="VBoxContainer/ButtonsContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"] [connection signal="pressed" from="VBoxContainer/ButtonsContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"]
[connection signal="confirmed" from="LayoutSettings" to="." method="_on_LayoutSettings_confirmed"] [connection signal="confirmed" from="LayoutSettings" to="." method="_on_LayoutSettings_confirmed"]
[connection signal="confirmed" from="DeleteConfirmation" to="." method="_on_DeleteConfirmation_confirmed"] [connection signal="confirmed" from="DeleteConfirmation" to="." method="_on_DeleteConfirmation_confirmed"]