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

Allow user to move Palettes to Trash/Recycle Bin instead of deleting them permanently #914

Merged
merged 7 commits into from Oct 11, 2023
Merged
7 changes: 7 additions & 0 deletions Translations/Translations.pot
Expand Up @@ -130,6 +130,13 @@ msgstr ""
msgid "Delete"
msgstr ""

msgid "Delete Permanently"
msgstr ""

#. When you move something to recycle bin
msgid "Move to Trash"
msgstr ""

msgid "New Brush"
msgstr ""

Expand Down
11 changes: 7 additions & 4 deletions src/Autoload/Palettes.gd
Expand Up @@ -213,13 +213,16 @@ func current_palette_edit(palette_name: String, comment: String, width: int, hei
palettes[palette_path] = current_palette


func _delete_palette(path: String) -> void:
DirAccess.open(path).remove(path)
func _delete_palette(path: String, permanent := true) -> void:
if permanent:
DirAccess.remove_absolute(path)
else:
OS.move_to_trash(path)
palettes.erase(path)


func current_palete_delete() -> void:
_delete_palette(current_palette.resource_path)
func current_palete_delete(permanent := true) -> void:
_delete_palette(current_palette.resource_path, permanent)

if palettes.size() > 0:
select_palette(palettes.keys()[0])
Expand Down
14 changes: 11 additions & 3 deletions src/Palette/CreatePaletteDialog.tscn
Expand Up @@ -3,16 +3,18 @@
[ext_resource type="Script" path="res://src/Palette/CreatePaletteDialog.gd" id="1"]

[node name="CreatePaletteDialog" type="ConfirmationDialog"]
title = "Create a new palette"
size = Vector2i(325, 437)
script = ExtResource("1")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchors_preset = -1
anchor_left = 0.000793701
anchor_right = 0.000793701
offset_left = 7.76189
offset_left = 7.74205
offset_top = 8.0
offset_right = 291.762
offset_bottom = 401.0
offset_right = 316.742
offset_bottom = 388.0

[node name="PaletteMetadata" type="GridContainer" parent="VBoxContainer"]
layout_mode = 2
Expand Down Expand Up @@ -118,12 +120,18 @@ layout_mode = 2
size_flags_vertical = 7
theme_override_colors/font_color = Color(1, 0.603922, 0.603922, 1)
text = "Palette with the same name and path already exists!"
horizontal_alignment = 1
vertical_alignment = 2
autowrap_mode = 3

[node name="EnterNameWarning" type="Label" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 7
theme_override_colors/font_color = Color(1, 0.603922, 0.603922, 1)
text = "Palette name is required!"
horizontal_alignment = 1
vertical_alignment = 2
autowrap_mode = 3

[connection signal="confirmed" from="." to="." method="_on_CreatePaletteDialog_confirmed"]
[connection signal="visibility_changed" from="." to="." method="_on_CreatePaletteDialog_visibility_changed"]
Expand Down
19 changes: 17 additions & 2 deletions src/Palette/EditPaletteDialog.gd
Expand Up @@ -5,6 +5,7 @@ signal saved(name, comment, width, height)
signal deleted

const DELETE_ACTION := "delete"
const BIN_ACTION := "trash"

# Keeps original size of edited palette
var origin_width := 0
Expand All @@ -16,15 +17,17 @@ var old_name := ""
@onready var comment_input := $VBoxContainer/PaletteMetadata/Comment
@onready var width_input := $VBoxContainer/PaletteMetadata/Width
@onready var height_input := $VBoxContainer/PaletteMetadata/Height
@onready var path_input := $VBoxContainer/PaletteMetadata/Path3D
@onready var path_input := $VBoxContainer/PaletteMetadata/Path

@onready var size_reduced_warning := $VBoxContainer/SizeReducedWarning
@onready var already_exists_warning := $VBoxContainer/AlreadyExistsWarning
@onready var delete_confirmation := $DeleteConfirmation


func _ready() -> void:
# Add delete button to edit palette dialog
add_button(tr("Delete"), false, DELETE_ACTION)
delete_confirmation.add_button(tr("Move to Trash"), false, BIN_ACTION)


func open(current_palette: Palette) -> void:
Expand Down Expand Up @@ -78,8 +81,20 @@ func _on_EditPaletteDialog_confirmed() -> void:

func _on_EditPaletteDialog_custom_action(action: String) -> void:
if action == DELETE_ACTION:
delete_confirmation.popup_centered()


func _on_delete_confirmation_confirmed() -> void:
deleted.emit(true)
delete_confirmation.hide()
hide()


func _on_delete_confirmation_custom_action(action: StringName) -> void:
if action == BIN_ACTION:
deleted.emit(false)
delete_confirmation.hide()
hide()
deleted.emit(deleted)


func _on_size_value_changed(_value):
Expand Down
37 changes: 34 additions & 3 deletions src/Palette/EditPaletteDialog.tscn
Expand Up @@ -3,6 +3,8 @@
[ext_resource type="Script" path="res://src/Palette/EditPaletteDialog.gd" id="1"]

[node name="EditPaletteDialog" type="ConfirmationDialog"]
title = "Edit Palette"
size = Vector2i(409, 559)
script = ExtResource("1")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
Expand All @@ -12,10 +14,11 @@ anchor_bottom = 1.0
offset_left = 8.0
offset_top = 8.0
offset_right = -8.0
offset_bottom = -36.0
offset_bottom = -49.0

[node name="PaletteMetadata" type="GridContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
columns = 2

[node name="NameLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
Expand All @@ -31,12 +34,14 @@ size_flags_horizontal = 3
[node name="CommentLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_vertical = 0
text = "Comment:"

[node name="Comment" type="TextEdit" parent="VBoxContainer/PaletteMetadata"]
custom_minimum_size = Vector2(0, 75)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="WidthLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
layout_mode = 2
Expand Down Expand Up @@ -64,9 +69,9 @@ value = 1.0

[node name="PathLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
layout_mode = 2
text = "Path3D:"
text = "Path:"

[node name="Path3D" type="TextEdit" parent="VBoxContainer/PaletteMetadata"]
[node name="Path" type="TextEdit" parent="VBoxContainer/PaletteMetadata"]
custom_minimum_size = Vector2(0, 50)
layout_mode = 2
size_flags_horizontal = 3
Expand All @@ -75,15 +80,41 @@ size_flags_horizontal = 3
layout_mode = 2
theme_override_colors/font_color = Color(1, 0.603922, 0.603922, 1)
text = "Reducing palette size will reset positions of colors. Colors that don't fit in new palette size will be lost!"
horizontal_alignment = 1
vertical_alignment = 2
autowrap_mode = 3

[node name="AlreadyExistsWarning" type="Label" parent="VBoxContainer"]
layout_mode = 2
theme_override_colors/font_color = Color(1, 0.603922, 0.603922, 1)
text = "Palette with the same name and path already exists!"
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 3

[node name="DeleteConfirmation" type="ConfirmationDialog" parent="."]
size = Vector2i(445, 105)
ok_button_text = "Delete Permanently"

[node name="Label" type="Label" parent="DeleteConfirmation"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 8.0
offset_top = 8.0
offset_right = -8.0
offset_bottom = -49.0
grow_horizontal = 2
grow_vertical = 2
text = "Delete Palette?"
horizontal_alignment = 1
vertical_alignment = 1

[connection signal="confirmed" from="." to="." method="_on_EditPaletteDialog_confirmed"]
[connection signal="custom_action" from="." to="." method="_on_EditPaletteDialog_custom_action"]
[connection signal="visibility_changed" from="." to="." method="_on_EditPaletteDialog_visibility_changed"]
[connection signal="text_changed" from="VBoxContainer/PaletteMetadata/Name" to="." method="_on_Name_text_changed"]
[connection signal="value_changed" from="VBoxContainer/PaletteMetadata/Width" to="." method="_on_size_value_changed"]
[connection signal="value_changed" from="VBoxContainer/PaletteMetadata/Height" to="." method="_on_size_value_changed"]
[connection signal="confirmed" from="DeleteConfirmation" to="." method="_on_delete_confirmation_confirmed"]
[connection signal="custom_action" from="DeleteConfirmation" to="." method="_on_delete_confirmation_custom_action"]
4 changes: 2 additions & 2 deletions src/Palette/PalettePanel.gd
Expand Up @@ -215,8 +215,8 @@ func _on_HiddenColorPickerButton_popup_closed():
Palettes.current_palette_set_color(edited_swatch_index, edited_swatch_color)


func _on_EditPaletteDialog_deleted() -> void:
Palettes.current_palete_delete()
func _on_EditPaletteDialog_deleted(permanent: bool) -> void:
Palettes.current_palete_delete(permanent)
setup_palettes_selector()
redraw_current_palette()

Expand Down
6 changes: 3 additions & 3 deletions src/UI/ReferenceImages/ReferenceImageButton.gd
Expand Up @@ -7,11 +7,11 @@ var _ignore_spinbox_changes := false

func _ready():
if OS.get_name() == "Web":
$Interior/PathHeader/Path3D.visible = false
$Interior/PathHeader/Path.visible = false
$Interior/PathHeader/PathHTML.text = element.image_path
else:
$Interior/PathHeader/PathHTML.visible = false
$Interior/PathHeader/Path3D.text = element.image_path
$Interior/PathHeader/Path.text = element.image_path

if !element.texture:
$Interior/PreviewAndOptions/PreviewPanel/Warning.text = "Image not found!"
Expand Down Expand Up @@ -79,7 +79,7 @@ func _on_Opacity_value_changed(value: float):


func _on_Path_pressed() -> void:
OS.shell_open($Interior/PathHeader/Path3D.text.get_base_dir())
OS.shell_open($Interior/PathHeader/Path.text.get_base_dir())


func _on_Silhouette_toggled(button_pressed: bool) -> void:
Expand Down
4 changes: 2 additions & 2 deletions src/UI/ReferenceImages/ReferenceImageButton.tscn
Expand Up @@ -19,7 +19,7 @@ layout_mode = 2
layout_mode = 2
theme_override_constants/separation = 0

[node name="Path3D" type="LinkButton" parent="Interior/PathHeader"]
[node name="Path" type="LinkButton" parent="Interior/PathHeader"]
modulate = Color(0.552941, 1, 0.298039, 1)
layout_mode = 2
size_flags_horizontal = 3
Expand Down Expand Up @@ -117,7 +117,7 @@ layout_mode = 2
theme_override_colors/font_color = Color(1, 0.266667, 0.266667, 1)
text = "Remove"

[connection signal="pressed" from="Interior/PathHeader/Path3D" to="." method="_on_Path_pressed"]
[connection signal="pressed" from="Interior/PathHeader/Path" to="." method="_on_Path_pressed"]
[connection signal="value_changed" from="Interior/PreviewAndOptions/Options/Position/X" to="." method="_on_X_value_changed"]
[connection signal="value_changed" from="Interior/PreviewAndOptions/Options/Position/Y" to="." method="_on_Y_value_changed"]
[connection signal="value_changed" from="Interior/PreviewAndOptions/Options/Scale" to="." method="_on_Scale_value_changed"]
Expand Down