mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
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:
parent
a3ceb54c48
commit
43cd05c79d
2 changed files with 88 additions and 63 deletions
|
@ -117,11 +117,13 @@ func _ready() -> void:
|
||||||
|
|
||||||
bottom_dock.variable_viewer.top_field_edited.connect(
|
bottom_dock.variable_viewer.top_field_edited.connect(
|
||||||
func(old_name: String, new_name: String, new_value: Variant) -> void:
|
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)
|
get_active_deck().update_variable(old_name, new_name, new_value)
|
||||||
)
|
)
|
||||||
|
|
||||||
bottom_dock.variable_viewer.top_field_removed.connect(
|
bottom_dock.variable_viewer.top_field_removed.connect(
|
||||||
func(field_name: String) -> void:
|
func(field_name: String) -> void:
|
||||||
|
get_active_deck_renderer().dirty = true
|
||||||
get_active_deck().remove_variable(field_name)
|
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):
|
_ when id in range(FileMenuId.RECENTS, FileMenuId.RECENTS + max_recents + 1):
|
||||||
open_deck_at_path(recent_files[id - FileMenuId.RECENTS - 1])
|
open_deck_at_path(recent_files[id - FileMenuId.RECENTS - 1])
|
||||||
|
|
||||||
|
|
||||||
## Adds an empty [DeckRendererGraphEdit] with a corresponding [Deck] for it's data.
|
## Adds an empty [DeckRendererGraphEdit] with a corresponding [Deck] for it's data.
|
||||||
func add_empty_deck() -> void:
|
func add_empty_deck() -> void:
|
||||||
var deck := DeckHolder.add_empty_deck()
|
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].
|
## Returns the deck at [param tab] in the [member tab_container].
|
||||||
func get_deck_at_tab(tab: int) -> Deck:
|
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():
|
if tab_container.is_empty():
|
||||||
return null
|
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]
|
## Saves the active [Deck] in [member tab_container]
|
||||||
|
|
|
@ -27,34 +27,34 @@ func _ready() -> void:
|
||||||
variable_tree.set_column_expand_ratio(2, 15)
|
variable_tree.set_column_expand_ratio(2, 15)
|
||||||
root = variable_tree.create_item()
|
root = variable_tree.create_item()
|
||||||
rebuild_variable_tree()
|
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():
|
func():
|
||||||
var column := variable_tree.get_selected_column()
|
var item := variable_tree.get_edited()
|
||||||
var item := variable_tree.get_selected()
|
if item == null:
|
||||||
|
item = variable_tree.get_selected()
|
||||||
|
|
||||||
# do nothing if this is an array and user is trying to edit index
|
if item != null:
|
||||||
# (TODO: proper reordering)
|
commit_item_change(item)
|
||||||
if column == 0 && item.get_meta(&"indexed"):
|
item.deselect(variable_tree.get_selected_column())
|
||||||
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)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
variable_tree.item_edited.connect(
|
variable_tree.button_clicked.connect(_on_variable_tree_button_clicked)
|
||||||
func():
|
|
||||||
var item := variable_tree.get_selected()
|
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_name := item.get_text(0)
|
||||||
var new_value
|
var new_value
|
||||||
var type: DeckType.Types = item.get_metadata(2)
|
var type: DeckType.Types = item.get_metadata(2)
|
||||||
|
@ -69,8 +69,6 @@ func _ready() -> void:
|
||||||
_:
|
_:
|
||||||
new_value = item.get_meta(&"value")
|
new_value = item.get_meta(&"value")
|
||||||
|
|
||||||
#item.set_meta(&"value", new_value)
|
|
||||||
|
|
||||||
if !item.has_meta(&"container"):
|
if !item.has_meta(&"container"):
|
||||||
top_field_edited.emit(_old_name, new_name, new_value)
|
top_field_edited.emit(_old_name, new_name, new_value)
|
||||||
else:
|
else:
|
||||||
|
@ -88,20 +86,33 @@ func _ready() -> void:
|
||||||
|
|
||||||
set_item_value(item, new_value)
|
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:
|
if column < 2:
|
||||||
types_popup.add_radio_check_item(DeckType.type_str(i))
|
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:
|
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_cell_mode(1, TreeItem.CELL_MODE_CHECK)
|
||||||
item.set_checked(1, value)
|
item.set_checked(1, value)
|
||||||
_:
|
_:
|
||||||
|
item.set_cell_mode(1, TreeItem.CELL_MODE_STRING)
|
||||||
item.set_text(1, str(value))
|
item.set_text(1, str(value))
|
||||||
|
|
||||||
if item.has_meta(&"container"):
|
if item.has_meta(&"container"):
|
||||||
|
|
Loading…
Reference in a new issue