Delete key deletes the selection, asking first (View ▾ → Ask before deleting)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bc2936cf15
commit
05508e1c05
8 changed files with 141 additions and 9 deletions
|
|
@ -296,6 +296,7 @@ Click any item in the report to jump to that card. A spread that can loop foreve
|
||||||
- [b]M[/b]: show or hide the minimap
|
- [b]M[/b]: show or hide the minimap
|
||||||
- [b]Ctrl+Z[/b]: undo. [b]Ctrl+Shift+Z[/b] or [b]Ctrl+Y[/b]: redo
|
- [b]Ctrl+Z[/b]: undo. [b]Ctrl+Shift+Z[/b] or [b]Ctrl+Y[/b]: redo
|
||||||
- [b]Ctrl+G[/b]: group the selected cards and groups
|
- [b]Ctrl+G[/b]: group the selected cards and groups
|
||||||
|
- [b]Delete[/b] (Build): delete the selected cards and groups, or the thread, result or card in the inspector. It asks first; turn that off in [b]View ▾ → Ask before deleting[/b]. Ctrl+Z brings it back.
|
||||||
- [b]Esc[/b]: clear the selection, or close a window
|
- [b]Esc[/b]: clear the selection, or close a window
|
||||||
- In a question pop-up: [b]1–9[/b] pick an option, [b]R[/b] Random, [b]M[/b] or [b]Tab[/b] look at the spread
|
- In a question pop-up: [b]1–9[/b] pick an option, [b]R[/b] Random, [b]M[/b] or [b]Tab[/b] look at the spread
|
||||||
## Mouse
|
## Mouse
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ func _init() -> void:
|
||||||
return
|
return
|
||||||
await _test_lists()
|
await _test_lists()
|
||||||
await _test_popup_and_run()
|
await _test_popup_and_run()
|
||||||
|
await _test_delete_key()
|
||||||
finish()
|
finish()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,3 +69,30 @@ func _test_popup_and_run() -> void:
|
||||||
bar_pm.about_to_popup.emit()
|
bar_pm.about_to_popup.emit()
|
||||||
_check(bar_pm.item_count > 4, "the ☰ menu fills with the spread's actions")
|
_check(bar_pm.item_count > 4, "the ☰ menu fills with the spread's actions")
|
||||||
|
|
||||||
|
|
||||||
|
## The Delete key: asks first (by default), deletes the selection as one undo
|
||||||
|
## step, and skips the question when "Ask before deleting" is off.
|
||||||
|
func _test_delete_key() -> void:
|
||||||
|
main.set_mode(Main.Mode.BUILD)
|
||||||
|
await _frames()
|
||||||
|
main.clear_selection()
|
||||||
|
main.editing.toggle_selected("loot")
|
||||||
|
main.editing.toggle_selected("names")
|
||||||
|
var found := DeleteKey.target(main)
|
||||||
|
_eq(str(found.get("what", "")), "2 cards", "Delete names what it would delete")
|
||||||
|
DeleteKey.press(main)
|
||||||
|
await _frames()
|
||||||
|
var asked := main.get_children().filter(func(n: Node) -> bool: return n is ModalCard)
|
||||||
|
_check(not asked.is_empty() and main.data.get_table("loot") != null, "by default it asks first and deletes nothing yet")
|
||||||
|
for dialog: ModalCard in asked:
|
||||||
|
dialog.close()
|
||||||
|
DeleteKey.set_asks(main, false)
|
||||||
|
DeleteKey.press(main)
|
||||||
|
await _frames()
|
||||||
|
_check(main.data.get_table("loot") == null and main.data.get_table("names") == null, "with asking off it deletes both cards")
|
||||||
|
main.undo_redo.undo()
|
||||||
|
await _frames()
|
||||||
|
_check(main.data.get_table("loot") != null and main.data.get_table("names") != null, "one undo brings both back")
|
||||||
|
DeleteKey.set_asks(main, true)
|
||||||
|
main.clear_selection()
|
||||||
|
main.set_mode(Main.Mode.PLAY)
|
||||||
|
|
|
||||||
85
ui/delete_key.gd
Normal file
85
ui/delete_key.gd
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
class_name DeleteKey
|
||||||
|
extends RefCounted
|
||||||
|
## The Delete key in Build mode: deletes what's selected (the selected cards
|
||||||
|
## and groups, else the inspector's thread, result or card), as one undo step.
|
||||||
|
## It asks "Are you sure?" first unless View ▾ → Ask before deleting is off
|
||||||
|
## (the setting "confirm_delete", on by default).
|
||||||
|
|
||||||
|
const SETTING := "confirm_delete"
|
||||||
|
## Used when saving is off (--sample / --screenshot) and there's no state.
|
||||||
|
static var _asks_mem := true
|
||||||
|
|
||||||
|
|
||||||
|
static func asks(m: Main) -> bool:
|
||||||
|
return bool(m.state.get_setting(SETTING, true)) if m.state else _asks_mem
|
||||||
|
|
||||||
|
|
||||||
|
static func set_asks(m: Main, on: bool) -> void:
|
||||||
|
_asks_mem = on
|
||||||
|
if m.state:
|
||||||
|
m.state.set_setting(SETTING, on)
|
||||||
|
m.state.save()
|
||||||
|
|
||||||
|
|
||||||
|
## What the key would delete now: {"what": words for the question, "do":
|
||||||
|
## Callable}, or {} when nothing is selected.
|
||||||
|
static func target(m: Main) -> Dictionary:
|
||||||
|
var cards: Array[String] = []
|
||||||
|
for t in m.data.tables:
|
||||||
|
if m.selection.has(t.id):
|
||||||
|
cards.append(t.id)
|
||||||
|
var groups: Array = m.selecting.groups.keys()
|
||||||
|
if not cards.is_empty() or not groups.is_empty():
|
||||||
|
var parts := PackedStringArray()
|
||||||
|
if not cards.is_empty():
|
||||||
|
parts.append(_name(m, cards[0]) if cards.size() == 1 else "%d cards" % cards.size())
|
||||||
|
if not groups.is_empty():
|
||||||
|
parts.append("%d %s and the cards in %s" % [groups.size(), "group" if groups.size() == 1 else "groups", "it" if groups.size() == 1 else "them"])
|
||||||
|
return {"what": " and ".join(parts), "do": func() -> void: _delete_many(m, cards, groups)}
|
||||||
|
var sel: Dictionary = m.inspector.selection if m.inspector else {}
|
||||||
|
match str(sel.get("kind", "")):
|
||||||
|
"pipe":
|
||||||
|
var key := "%s:%s>%s" % [sel["tid"], sel["eid"], sel["to"]]
|
||||||
|
return {"what": "the thread to %s" % _name(m, str(sel["to"])), "do": m.remove_pipe.bind(key)}
|
||||||
|
"result":
|
||||||
|
var t := m.data.get_table(str(sel["tid"]))
|
||||||
|
var e := t.find_entry(str(sel["eid"])) if t else null
|
||||||
|
if e:
|
||||||
|
return {"what": "“%s”" % Formatter.strip_tags(e.text).strip_edges(), "do": m.delete_entry.bind(t.id, e.id)}
|
||||||
|
"card":
|
||||||
|
if m.data.get_table(str(sel["tid"])):
|
||||||
|
return {"what": _name(m, str(sel["tid"])), "do": m.delete_table.bind(str(sel["tid"]))}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
## Handles the key: asks first (unless turned off), then deletes.
|
||||||
|
static func press(m: Main) -> void:
|
||||||
|
var found := target(m)
|
||||||
|
if found.is_empty():
|
||||||
|
return
|
||||||
|
if not asks(m):
|
||||||
|
(found["do"] as Callable).call()
|
||||||
|
return
|
||||||
|
var dialog := ModalCard.confirm("Delete?", "Delete %s? You can undo it with Ctrl+Z." % found["what"], "Delete", found["do"], true)
|
||||||
|
var dont_ask := InspectorKit.check_box("Don't ask again (View ▾ → Ask before deleting)", false)
|
||||||
|
dont_ask.toggled.connect(func(on: bool) -> void: set_asks(m, not on))
|
||||||
|
dialog.body.add_child(dont_ask)
|
||||||
|
m._add_modal(dialog)
|
||||||
|
|
||||||
|
|
||||||
|
static func _delete_many(m: Main, cards: Array[String], groups: Array) -> void:
|
||||||
|
m.undo_redo._begin_edit()
|
||||||
|
for gid: String in groups:
|
||||||
|
m.grouping.delete_group(gid, false)
|
||||||
|
for tid in cards:
|
||||||
|
if m.data.get_table(tid):
|
||||||
|
m.editing.delete_table(tid, false)
|
||||||
|
m.selecting.clear()
|
||||||
|
m.clear_selection()
|
||||||
|
m.undo_redo._end_edit("Delete")
|
||||||
|
m.toast("Deleted", true)
|
||||||
|
|
||||||
|
|
||||||
|
static func _name(m: Main, tid: String) -> String:
|
||||||
|
var t := m.data.get_table(tid)
|
||||||
|
return Formatter.strip_tags(t.name).strip_edges() if t else "the card"
|
||||||
1
ui/delete_key.gd.uid
Normal file
1
ui/delete_key.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dbtni4kflrep0
|
||||||
|
|
@ -183,10 +183,13 @@ func delete_entry(tid: String, eid: String) -> void:
|
||||||
m.toast("Deleted “%s”" % e.text, true)
|
m.toast("Deleted “%s”" % e.text, true)
|
||||||
|
|
||||||
|
|
||||||
func delete_table(tid: String) -> void:
|
## Deletes a card. `commit` false leaves the undo step to the caller (several
|
||||||
|
## at once, DeleteKey).
|
||||||
|
func delete_table(tid: String, commit: bool = true) -> void:
|
||||||
var t := m.data.get_table(tid)
|
var t := m.data.get_table(tid)
|
||||||
if t == null:
|
if t == null:
|
||||||
return
|
return
|
||||||
|
if commit:
|
||||||
m.undo_redo._begin_edit()
|
m.undo_redo._begin_edit()
|
||||||
var in_group := m.data.group_of(tid)
|
var in_group := m.data.group_of(tid)
|
||||||
m.data.remove_table(tid)
|
m.data.remove_table(tid)
|
||||||
|
|
@ -201,6 +204,7 @@ func delete_table(tid: String) -> void:
|
||||||
if in_group:
|
if in_group:
|
||||||
m.grouping._groups_changed()
|
m.grouping._groups_changed()
|
||||||
_update_selection_bar()
|
_update_selection_bar()
|
||||||
|
if commit:
|
||||||
m.undo_redo._end_edit()
|
m.undo_redo._end_edit()
|
||||||
m.toast("Deleted %s" % t.name, true)
|
m.toast("Deleted %s" % t.name, true)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,11 +271,13 @@ func confirm_delete_group(gid: String) -> void:
|
||||||
"Delete group and cards", func() -> void: delete_group(gid), true))
|
"Delete group and cards", func() -> void: delete_group(gid), true))
|
||||||
|
|
||||||
|
|
||||||
## Deletes a group and every card in it (undo from the toast).
|
## Deletes a group and every card in it (undo from the toast). `commit`
|
||||||
func delete_group(gid: String) -> void:
|
## false leaves the undo step to the caller (DeleteKey).
|
||||||
|
func delete_group(gid: String, commit: bool = true) -> void:
|
||||||
var g := m.data.get_group(gid)
|
var g := m.data.get_group(gid)
|
||||||
if g == null:
|
if g == null:
|
||||||
return
|
return
|
||||||
|
if commit:
|
||||||
m.undo_redo._begin_edit()
|
m.undo_redo._begin_edit()
|
||||||
var gname := Formatter.strip_tags(g.name)
|
var gname := Formatter.strip_tags(g.name)
|
||||||
var gone := m.data.delete_group(gid)
|
var gone := m.data.delete_group(gid)
|
||||||
|
|
@ -290,6 +292,7 @@ func delete_group(gid: String) -> void:
|
||||||
for c in m.cards.values():
|
for c in m.cards.values():
|
||||||
(c as TableCard).rebuild()
|
(c as TableCard).rebuild()
|
||||||
_groups_changed()
|
_groups_changed()
|
||||||
|
if commit:
|
||||||
m.undo_redo._end_edit()
|
m.undo_redo._end_edit()
|
||||||
m.toast("Deleted “%s” and its %d %s" % [gname, gone.size(), "card" if gone.size() == 1 else "cards"], true)
|
m.toast("Deleted “%s” and its %d %s" % [gname, gone.size(), "card" if gone.size() == 1 else "cards"], true)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,10 @@ func _unhandled_input(ev: InputEvent) -> void:
|
||||||
elif k.keycode == KEY_ESCAPE and not m.selection.is_empty():
|
elif k.keycode == KEY_ESCAPE and not m.selection.is_empty():
|
||||||
m.clear_selection()
|
m.clear_selection()
|
||||||
m.get_viewport().set_input_as_handled()
|
m.get_viewport().set_input_as_handled()
|
||||||
|
elif k.keycode == KEY_DELETE and not (k.ctrl_pressed or k.meta_pressed or k.alt_pressed):
|
||||||
|
# Text fields keep Delete for themselves; this only sees it when none has focus.
|
||||||
|
DeleteKey.press(m)
|
||||||
|
m.get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
|
|
||||||
## "plain" (Describe's phrases) or "text" (the stored rule text).
|
## "plain" (Describe's phrases) or "text" (the stored rule text).
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ const ID_THEME := 5
|
||||||
const ID_LIST := 6
|
const ID_LIST := 6
|
||||||
const ID_BOOK := 7
|
const ID_BOOK := 7
|
||||||
const ID_SOUND := 8
|
const ID_SOUND := 8
|
||||||
|
const ID_CONFIRM_DELETE := 9
|
||||||
|
|
||||||
var m: Main
|
var m: Main
|
||||||
|
|
||||||
|
|
@ -35,6 +36,8 @@ func setup(p_main: Main) -> void:
|
||||||
pm.add_check_item("Minimap (M)", ID_MINIMAP)
|
pm.add_check_item("Minimap (M)", ID_MINIMAP)
|
||||||
pm.add_check_item("List view", ID_LIST)
|
pm.add_check_item("List view", ID_LIST)
|
||||||
pm.add_check_item("Book", ID_BOOK)
|
pm.add_check_item("Book", ID_BOOK)
|
||||||
|
pm.add_check_item("Ask before deleting", ID_CONFIRM_DELETE)
|
||||||
|
pm.set_item_tooltip(pm.get_item_index(ID_CONFIRM_DELETE), "The Delete key asks “Are you sure?” first")
|
||||||
pm.set_item_tooltip(pm.get_item_index(ID_BOOK), "Reusable results (Pages) to drag onto tables")
|
pm.set_item_tooltip(pm.get_item_index(ID_BOOK), "Reusable results (Pages) to drag onto tables")
|
||||||
pm.set_item_tooltip(pm.get_item_index(ID_LIST), "The cards as a list with folders, beside the spread")
|
pm.set_item_tooltip(pm.get_item_index(ID_LIST), "The cards as a list with folders, beside the spread")
|
||||||
pm.add_separator()
|
pm.add_separator()
|
||||||
|
|
@ -56,6 +59,7 @@ func sync() -> void:
|
||||||
pm.set_item_checked(pm.get_item_index(ID_MINIMAP), m.board.minimap.visible)
|
pm.set_item_checked(pm.get_item_index(ID_MINIMAP), m.board.minimap.visible)
|
||||||
pm.set_item_checked(pm.get_item_index(ID_LIST), m.list_view.visible)
|
pm.set_item_checked(pm.get_item_index(ID_LIST), m.list_view.visible)
|
||||||
pm.set_item_checked(pm.get_item_index(ID_BOOK), m.book.visible)
|
pm.set_item_checked(pm.get_item_index(ID_BOOK), m.book.visible)
|
||||||
|
pm.set_item_checked(pm.get_item_index(ID_CONFIRM_DELETE), DeleteKey.asks(m))
|
||||||
|
|
||||||
|
|
||||||
func collapse_label() -> String:
|
func collapse_label() -> String:
|
||||||
|
|
@ -80,5 +84,7 @@ func activate(id: int) -> void:
|
||||||
m.book.toggle()
|
m.book.toggle()
|
||||||
ID_THEME:
|
ID_THEME:
|
||||||
m.add_child(ThemeDialog.new(m))
|
m.add_child(ThemeDialog.new(m))
|
||||||
|
ID_CONFIRM_DELETE:
|
||||||
|
DeleteKey.set_asks(m, not DeleteKey.asks(m))
|
||||||
ID_SOUND:
|
ID_SOUND:
|
||||||
SoundPanel.open(m, get_global_rect().position + Vector2(0, size.y + 4))
|
SoundPanel.open(m, get_global_rect().position + Vector2(0, size.y + 4))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue