class_name MainInspectorLink extends RefCounted ## Main's side of the Build inspector (docs/PLAIN.md §5). The inspector edits ## the selected card, result or pipe. The display side calls select_card / ## select_result / select_pipe / clear_inspector; Main also selects from the ## board: a card's title (drag start), focus entering a result's field on a ## card, a clicked pipe, the ⚙. var m: Main var _pipe_popover: PipePopover func _init(p_main: Main) -> void: m = p_main ## Build mode: a clicked pipe opens in the inspector. The old pop-up ## (PipePopover) is only a fallback for when there is no inspector. func open_pipe_options(key: String, at: Vector2) -> void: if m.inspector != null: m.details().hide_for() select_pipe(key) return if _pipe_popover == null: _pipe_popover = PipePopover.new() m.add_child(_pipe_popover) _pipe_popover.setup(m) m.details().hide_for() _pipe_popover.open(key, at) ## The card's ⚙ button. Main.open_table_settings comes from the app-shell work; ## until it exists this only says so. func request_table_settings(tid: String) -> void: if m.mode == Main.Mode.BUILD and m.inspector != null: select_card(tid) return m.open_table_settings(tid) func select_card(table_id: String) -> void: if m.inspector == null or m.data.get_table(table_id) == null: return m.inspector.select({"kind": "card", "tid": table_id}) func select_result(table_id: String, entry_id: String) -> void: var t := m.data.get_table(table_id) if m.inspector == null or t == null or t.find_entry(entry_id) == null: return m.inspector.select({"kind": "result", "tid": table_id, "eid": entry_id}) ## `key` is a pipe key, "tid:eid>to" (Roller.pipe_key). func select_pipe(key: String) -> void: var from := key.get_slice(">", 0) var tid := from.get_slice(":", 0) var eid := from.get_slice(":", 1) var to := key.get_slice(">", 1) var t := m.data.get_table(tid) var e := t.find_entry(eid) if t else null if m.inspector == null or e == null or not e.pipes.has(to): return m.inspector.select({"kind": "pipe", "tid": tid, "eid": eid, "to": to}) func clear_inspector() -> void: if m.inspector: m.inspector.clear() ## What the inspector shows: {kind: "card" | "result" | "pipe", tid, eid?, to?} or {}. func inspector_selection() -> Dictionary: return m.inspector.selection.duplicate() if m.inspector else {} ## After the inspector changed a card: refreshes it (every card when a ## variable's name or label changed, since other cards show it). func inspector_edited(tid: String, all_cards: bool = false) -> void: m.local_state._ref_cache.clear() if all_cards: for c in m.cards.values(): (c as TableCard).rebuild() else: var card := m.card_for(tid) if card: card.rebuild() ## Focus entering a field on a card in Build selects that result (or the card). func _inspect_focus(c: Control) -> void: if m.mode != Main.Mode.BUILD or m.inspector == null or c == null or m.inspector.is_ancestor_of(c): return var n: Node = c while n != null and not (n is TableCard): n = n.get_parent() var card := n as TableCard if card == null or card.table == null: return for eid: String in card.rows: var row: Node = card.rows[eid] if is_instance_valid(row) and row.is_ancestor_of(c): var s := m.inspector.selection if str(s.get("tid", "")) != card.table.id or str(s.get("eid", "")) != eid or str(s.get("kind", "")) == "card": select_result(card.table.id, eid) return if str(m.inspector.selection.get("tid", "")) != card.table.id: select_card(card.table.id)