TableTower/ui/list_view.gd
RobinFiredrake 07d96a68f8 Spread folders: pick from a list, nesting, keep empty folders, Recent
- Move to folder is a submenu of existing folders (+ No folder, New folder…);
  typed names match existing folders without regard to case.
- Folders nest ("Traveller/Worlds"); each folder has New spread here… and
  Rename folder….
- When the last spread leaves a folder, ask Keep / Remove it; kept empty
  folders have Remove folder.
- Recent spreads at the top of the switcher.
- List view's "folders" are called groups in the UI (+ Group).
- TestBase gets the shared _wipe helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 19:19:47 -06:00

91 lines
2.7 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name ListView
extends PanelContainer
## List view: the spread's cards as a plain list, docked on the left (or
## filling the window on phones). Groups show as nested rows; rows roll, select
## (Build) and show where their threads go. It has its own search and
## "+ Group". Shown from View ▾, ☰ or right-clicking the spread.
const WIDTH := 320.0
const MIN_WIDTH := 220.0
const SETTING := "list_view"
var m: Main
var tree: ListTree
var splitter: PanelSplitter
var _search: LineEdit
var close_button: Button
var _rev := -1
func setup(p_main: Main) -> void:
m = p_main
add_theme_stylebox_override("panel", Style.panel_box([10, 10, 10, 10]))
var col := VBoxContainer.new()
col.add_theme_constant_override("separation", 8)
add_child(col)
var head := HBoxContainer.new()
head.add_theme_constant_override("separation", 6)
col.add_child(head)
var title := Style.make_label("List", Style.display(), 20, Style.ON_BG)
title.size_flags_horizontal = SIZE_EXPAND_FILL
head.add_child(title)
var group := Style.bar_button("+ Group")
group.tooltip_text = "A new, empty group on the spread. Drag cards onto it."
group.pressed.connect(new_group)
head.add_child(group)
close_button = Style.bar_button("×")
var close := close_button
close.tooltip_text = "Close the list"
close.pressed.connect(func() -> void: set_shown(false))
head.add_child(close)
_search = LineEdit.new()
_search.placeholder_text = "Search the list"
_search.clear_button_enabled = true
ModalCard.style_line_edit(_search)
_search.text_changed.connect(func(s: String) -> void:
tree.filter = s.strip_edges().to_lower()
tree.rebuild())
col.add_child(_search)
tree = ListTree.new(m)
tree.size_flags_vertical = SIZE_EXPAND_FILL
col.add_child(tree)
var hint := Style.make_label("Drag to reorder or into a group. Double-click shows the card on the spread.", Style.body(), 12, Style.ON_BG_MUTED)
hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
col.add_child(hint)
func _process(_delta: float) -> void:
if visible and m.data and m.edit_rev != _rev:
_rev = m.edit_rev
tree.rebuild()
func set_width(px: float) -> void:
custom_minimum_size.x = px
## Shows or hides the list and remembers it.
func set_shown(on: bool) -> void:
visible = on
if splitter:
splitter.visible = on
_rev = -1
if m.state:
m.state.set_setting(SETTING, on)
m.state.save()
func toggle() -> void:
set_shown(not visible)
## A new, empty group in the middle of the view.
func new_group() -> void:
m.undo_redo._begin_edit()
var g := m.data.add_group(m.grouping._free_group_name(), [])
var c := m.board.screen_to_world(m.board.size / 2.0)
g.position = (c - g.size / 2.0).round()
m.grouping._groups_changed()
m.mark_dirty()
m.undo_redo._end_edit()
_rev = -1