Variable Viewer improvements (#47)

- Mark the active deck dirty on variable change
- disable editing array/dictionary columns' value displays in the variable viewer
- make selecting nothing in the variable tree more resilient

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/47
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-01-20 04:40:33 +00:00 committed by yagich
parent a3ceb54c48
commit 43cd05c79d
2 changed files with 88 additions and 63 deletions

View file

@ -117,11 +117,13 @@ func _ready() -> void:
bottom_dock.variable_viewer.top_field_edited.connect(
func(old_name: String, new_name: String, new_value: Variant) -> void:
get_active_deck_renderer().dirty = true
get_active_deck().update_variable(old_name, new_name, new_value)
)
bottom_dock.variable_viewer.top_field_removed.connect(
func(field_name: String) -> void:
get_active_deck_renderer().dirty = true
get_active_deck().remove_variable(field_name)
)
@ -158,6 +160,7 @@ func _on_file_id_pressed(id: int) -> void:
_ when id in range(FileMenuId.RECENTS, FileMenuId.RECENTS + max_recents + 1):
open_deck_at_path(recent_files[id - FileMenuId.RECENTS - 1])
## Adds an empty [DeckRendererGraphEdit] with a corresponding [Deck] for it's data.
func add_empty_deck() -> void:
var deck := DeckHolder.add_empty_deck()
@ -267,10 +270,20 @@ func get_active_deck() -> Deck:
## Returns the deck at [param tab] in the [member tab_container].
func get_deck_at_tab(tab: int) -> Deck:
return get_deck_renderer_at_tab(tab).deck
## Returns the current deck renderer in the [member tab_container].
func get_active_deck_renderer() -> DeckRendererGraphEdit:
return get_deck_renderer_at_tab(tab_container.get_current_tab())
## Returns the deck renderer at [param tab] in the [member tab_container].
func get_deck_renderer_at_tab(tab: int) -> DeckRendererGraphEdit:
if tab_container.is_empty():
return null
return (tab_container.get_content(tab) as DeckRendererGraphEdit).deck
return tab_container.get_content(tab) as DeckRendererGraphEdit
## Saves the active [Deck] in [member tab_container]

View file

@ -27,34 +27,34 @@ func _ready() -> void:
variable_tree.set_column_expand_ratio(2, 15)
root = variable_tree.create_item()
rebuild_variable_tree()
variable_tree.item_activated.connect(
variable_tree.item_activated.connect(edit_item)
variable_tree.item_edited.connect(commit_item_change)
variable_tree.nothing_selected.connect(
func():
var column := variable_tree.get_selected_column()
var item := variable_tree.get_selected()
var item := variable_tree.get_edited()
if item == null:
item = variable_tree.get_selected()
# do nothing if this is an array and user is trying to edit index
# (TODO: proper reordering)
if column == 0 && item.get_meta(&"indexed"):
return
if column < 2:
_old_name = item.get_text(0)
variable_tree.edit_selected(true)
else:
var pos := get_global_mouse_position()
var r := Rect2i(Vector2i(pos), Vector2i(0, 100))
for i in types_popup.get_item_count():
types_popup.set_item_checked(i, false)
types_popup.set_item_checked(item.get_metadata(2), true)
types_popup.popup(r)
if item != null:
commit_item_change(item)
item.deselect(variable_tree.get_selected_column())
)
variable_tree.item_edited.connect(
func():
var item := variable_tree.get_selected()
variable_tree.button_clicked.connect(_on_variable_tree_button_clicked)
for i in DeckType.Types.size() - 1:
types_popup.add_radio_check_item(DeckType.type_str(i))
types_popup.id_pressed.connect(_on_types_popup_id_pressed)
new_variable_button.pressed.connect(_on_new_variable_button_pressed)
disable_new_button()
func commit_item_change(item: TreeItem = variable_tree.get_edited()) -> void:
var new_name := item.get_text(0)
var new_value
var type: DeckType.Types = item.get_metadata(2)
@ -69,8 +69,6 @@ func _ready() -> void:
_:
new_value = item.get_meta(&"value")
#item.set_meta(&"value", new_value)
if !item.has_meta(&"container"):
top_field_edited.emit(_old_name, new_name, new_value)
else:
@ -88,20 +86,33 @@ func _ready() -> void:
set_item_value(item, new_value)
)
variable_tree.nothing_selected.connect(variable_tree.deselect_all)
func edit_item() -> void:
var column := variable_tree.get_selected_column()
var item := variable_tree.get_selected()
variable_tree.button_clicked.connect(_on_variable_tree_button_clicked)
# do nothing if this is an array and user is trying to edit index
# (TODO: proper reordering)
if column == 0 && item.get_meta(&"indexed"):
return
for i in DeckType.Types.size() - 1:
types_popup.add_radio_check_item(DeckType.type_str(i))
if column < 2:
var value = item.get_meta(&"value")
if column == 1 && (value is Array || value is Dictionary):
item.collapsed = !item.collapsed
return
_old_name = item.get_text(0)
types_popup.id_pressed.connect(_on_types_popup_id_pressed)
variable_tree.edit_selected(true)
elif column == 2:
var pos := get_global_mouse_position()
var r := Rect2i(Vector2i(pos), Vector2i(0, 100))
new_variable_button.pressed.connect(_on_new_variable_button_pressed)
for i in types_popup.get_item_count():
types_popup.set_item_checked(i, false)
disable_new_button()
types_popup.set_item_checked(item.get_metadata(2), true)
types_popup.popup(r)
func rebuild_variable_tree(data: Dictionary = {}) -> void:
@ -151,6 +162,7 @@ func set_item_value(item: TreeItem, value: Variant) -> void:
item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK)
item.set_checked(1, value)
_:
item.set_cell_mode(1, TreeItem.CELL_MODE_STRING)
item.set_text(1, str(value))
if item.has_meta(&"container"):