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

[0.x] Allow user to move Palettes to Trash/Recycle Bin instead of deleting them permanently (#918)

* backport #914

move palettes to bin instead of deleting them permanently

* update backport to use dialog
This commit is contained in:
Variable 2023-10-11 21:20:49 +05:00 committed by GitHub
parent be093f3490
commit 7416ed375c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 28 deletions

View file

@ -211,14 +211,17 @@ func current_palette_edit(name: String, comment: String, width: int, height: int
palettes[palette_path] = current_palette
func _delete_palette(path: String) -> void:
var dir = Directory.new()
dir.remove(path)
func _delete_palette(path: String, permanent := true) -> void:
if permanent:
var dir = Directory.new()
dir.remove(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])

View file

@ -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
@ -20,11 +21,14 @@ 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.get_ok().text = tr("Delete Permanently")
delete_confirmation.add_button(tr("Move to Trash"), false, BIN_ACTION)
func open(current_palette: Palette) -> void:
@ -78,8 +82,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:
emit_signal("deleted", true)
delete_confirmation.hide()
hide()
func _on_delete_confirmation_custom_action(action: String) -> void:
if action == BIN_ACTION:
emit_signal("deleted", false)
delete_confirmation.hide()
hide()
emit_signal("deleted")
func _on_size_value_changed(_value):

View file

@ -5,6 +5,7 @@
[node name="EditPaletteDialog" type="ConfirmationDialog"]
margin_right = 409.0
margin_bottom = 535.0
rect_min_size = Vector2( 170, 59.5 )
window_title = "Edit Palette"
resizable = true
script = ExtResource( 1 )
@ -25,7 +26,7 @@ __meta__ = {
[node name="PaletteMetadata" type="GridContainer" parent="VBoxContainer"]
margin_right = 393.0
margin_bottom = 188.0
margin_bottom = 213.0
columns = 2
__meta__ = {
"_edit_use_anchors_": false
@ -46,9 +47,9 @@ rect_min_size = Vector2( 0, 24 )
size_flags_horizontal = 3
[node name="CommentLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
margin_top = 46.0
margin_top = 58.0
margin_right = 67.0
margin_bottom = 60.0
margin_bottom = 72.0
rect_min_size = Vector2( 50, 0 )
text = "Comment:"
@ -56,21 +57,21 @@ text = "Comment:"
margin_left = 71.0
margin_top = 28.0
margin_right = 393.0
margin_bottom = 78.0
margin_bottom = 103.0
rect_min_size = Vector2( 0, 75 )
size_flags_horizontal = 3
[node name="WidthLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
margin_top = 87.0
margin_top = 112.0
margin_right = 67.0
margin_bottom = 101.0
margin_bottom = 126.0
text = "Width:"
[node name="Width" type="SpinBox" parent="VBoxContainer/PaletteMetadata"]
margin_left = 71.0
margin_top = 82.0
margin_top = 107.0
margin_right = 393.0
margin_bottom = 106.0
margin_bottom = 131.0
rect_min_size = Vector2( 0, 24 )
size_flags_horizontal = 3
min_value = 1.0
@ -79,16 +80,16 @@ value = 1.0
align = 2
[node name="HeightLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
margin_top = 115.0
margin_top = 140.0
margin_right = 67.0
margin_bottom = 129.0
margin_bottom = 154.0
text = "Height:"
[node name="Height" type="SpinBox" parent="VBoxContainer/PaletteMetadata"]
margin_left = 71.0
margin_top = 110.0
margin_top = 135.0
margin_right = 393.0
margin_bottom = 134.0
margin_bottom = 159.0
rect_min_size = Vector2( 0, 24 )
size_flags_horizontal = 3
min_value = 1.0
@ -97,25 +98,25 @@ value = 1.0
align = 2
[node name="PathLabel" type="Label" parent="VBoxContainer/PaletteMetadata"]
margin_top = 156.0
margin_top = 181.0
margin_right = 67.0
margin_bottom = 170.0
margin_bottom = 195.0
text = "Path:"
[node name="Path" type="TextEdit" parent="VBoxContainer/PaletteMetadata"]
margin_left = 71.0
margin_top = 138.0
margin_top = 163.0
margin_right = 393.0
margin_bottom = 188.0
margin_bottom = 213.0
rect_min_size = Vector2( 0, 50 )
size_flags_horizontal = 3
readonly = true
wrap_enabled = true
[node name="SizeReducedWarning" type="Label" parent="VBoxContainer"]
margin_top = 192.0
margin_top = 217.0
margin_right = 393.0
margin_bottom = 223.0
margin_bottom = 248.0
custom_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!"
align = 1
@ -126,9 +127,9 @@ __meta__ = {
}
[node name="AlreadyExistsWarning" type="Label" parent="VBoxContainer"]
margin_top = 227.0
margin_top = 252.0
margin_right = 393.0
margin_bottom = 241.0
margin_bottom = 266.0
custom_colors/font_color = Color( 1, 0.603922, 0.603922, 1 )
text = "Palette with the same name and path already exists!"
align = 1
@ -138,9 +139,27 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="DeleteConfirmation" type="ConfirmationDialog" parent="."]
margin_right = 170.0
margin_bottom = 60.0
rect_min_size = Vector2( 170, 59.5 )
[node name="Label2" type="Label" parent="DeleteConfirmation"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -36.0
text = "Delete Palette?"
align = 1
valign = 1
[connection signal="confirmed" from="." to="." method="_on_EditPaletteDialog_confirmed"]
[connection signal="custom_action" from="." to="." method="_on_EditPaletteDialog_custom_action"]
[connection signal="popup_hide" from="." to="." method="_on_EditPaletteDialog_popup_hide"]
[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"]

View file

@ -204,8 +204,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()