disable saving if group deck

This commit is contained in:
Lera Elvoé 2023-12-15 20:39:19 +03:00
parent 68e1c312bf
commit 79f99043cd
No known key found for this signature in database
2 changed files with 37 additions and 20 deletions

View file

@ -71,6 +71,7 @@ var _deck_to_save: WeakRef
func _ready() -> void: func _ready() -> void:
get_tree().auto_accept_quit = false get_tree().auto_accept_quit = false
tab_container.add_button_pressed.connect(add_empty_deck) tab_container.add_button_pressed.connect(add_empty_deck)
tab_container.tab_changed.connect(_on_tab_container_tab_changed)
RendererPersistence.init_namespace(PERSISTENCE_NAMESPACE) RendererPersistence.init_namespace(PERSISTENCE_NAMESPACE)
var embed_subwindows: bool = RendererPersistence.get_or_create(PERSISTENCE_NAMESPACE, "config", "embed_subwindows", true) var embed_subwindows: bool = RendererPersistence.get_or_create(PERSISTENCE_NAMESPACE, "config", "embed_subwindows", true)
@ -114,6 +115,12 @@ func _ready() -> void:
file_popup_menu.set_item_shortcut(FileMenuId.CLOSE, close_deck_shortcut) file_popup_menu.set_item_shortcut(FileMenuId.CLOSE, close_deck_shortcut)
func _on_tab_container_tab_changed(tab: int) -> void:
var is_group = tab_container.get_tab_metadata(tab, "group", false)
file_popup_menu.set_item_disabled(FileMenuId.SAVE, is_group)
file_popup_menu.set_item_disabled(FileMenuId.SAVE_AS, is_group)
## Called when the File button in the [MenuBar] is pressed with the [param id] ## Called when the File button in the [MenuBar] is pressed with the [param id]
## of the button within it that was pressed. ## of the button within it that was pressed.
func _on_file_id_pressed(id: int) -> void: func _on_file_id_pressed(id: int) -> void:
@ -136,12 +143,13 @@ func add_empty_deck() -> void:
var deck := DeckHolder.add_empty_deck() var deck := DeckHolder.add_empty_deck()
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate() var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
inst.deck = deck inst.deck = deck
tab_container.add_content(inst, "<unsaved deck>") var tab := tab_container.add_content(inst, "<unsaved deck>")
tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) tab_container.set_tab_metadata(tab, "id", deck.id)
tab_container.set_tab_metadata(tab_container.get_current_tab(), "group", false) tab_container.set_tab_metadata(tab, "group", false)
tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", recent_path.path_join("")) tab_container.set_tab_metadata(tab, "path", recent_path.path_join(""))
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst)) inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
tab_container.set_current_tab(tab)
## Closes the current tab in [member tab_container] ## Closes the current tab in [member tab_container]
func close_current_tab() -> void: func close_current_tab() -> void:
@ -215,16 +223,17 @@ func open_deck_at_path(path: String) -> void:
var deck := DeckHolder.open_deck_from_file(path) var deck := DeckHolder.open_deck_from_file(path)
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate() var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
inst.deck = deck inst.deck = deck
tab_container.add_content(inst, path.get_file()) var tab := tab_container.add_content(inst, path.get_file())
tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) tab_container.set_tab_metadata(tab, "id", deck.id)
tab_container.set_tab_metadata(tab_container.get_current_tab(), "group", false) tab_container.set_tab_metadata(tab, "group", false)
tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", path) tab_container.set_tab_metadata(tab, "path", path)
inst.initialize_from_deck() inst.initialize_from_deck()
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst)) inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst))
add_recent_file(path) add_recent_file(path)
recent_path = path.get_base_dir() recent_path = path.get_base_dir()
RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_path", recent_path) RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_path", recent_path)
tab_container.set_current_tab(tab)
## Gets the currently active [Deck] from [member tab_container] ## Gets the currently active [Deck] from [member tab_container]
@ -240,6 +249,9 @@ func save_active_deck() -> void:
func save_tab(tab: int) -> void: func save_tab(tab: int) -> void:
if tab_container.get_tab_metadata(tab, "group"):
return
var renderer := tab_container.get_content(tab) as DeckRendererGraphEdit var renderer := tab_container.get_content(tab) as DeckRendererGraphEdit
var deck := renderer.deck var deck := renderer.deck
if deck.save_path.is_empty(): if deck.save_path.is_empty():
@ -273,10 +285,11 @@ func _on_deck_renderer_group_enter_requested(group_id: String) -> void:
var deck_renderer: DeckRendererGraphEdit = DECK_SCENE.instantiate() var deck_renderer: DeckRendererGraphEdit = DECK_SCENE.instantiate()
deck_renderer.deck = group_deck deck_renderer.deck = group_deck
deck_renderer.initialize_from_deck() deck_renderer.initialize_from_deck()
tab_container.add_content(deck_renderer, "(g) %s" % group_id.left(8)) var tab := tab_container.add_content(deck_renderer, "(g) %s" % group_id.left(8))
tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", group_id) tab_container.set_tab_metadata(tab, "id", group_id)
tab_container.set_tab_metadata(tab_container.get_current_tab(), "group", true) tab_container.set_tab_metadata(tab, "group", true)
deck_renderer.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) deck_renderer.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
tab_container.set_current_tab(tab)
func _on_connections_id_pressed(id: int) -> void: func _on_connections_id_pressed(id: int) -> void:
@ -324,18 +337,20 @@ func _on_debug_decks_viewer_item_pressed(deck_id: String, instance_id: String) -
var deck := DeckHolder.get_deck(deck_id) var deck := DeckHolder.get_deck(deck_id)
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate() var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
inst.deck = deck inst.deck = deck
tab_container.add_content(inst, "<Deck %s>" % [deck_id.left(8)]) var tab := tab_container.add_content(inst, "<Deck %s>" % [deck_id.left(8)])
tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) tab_container.set_tab_metadata(tab, "id", deck.id)
inst.initialize_from_deck() inst.initialize_from_deck()
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
tab_container.set_current_tab(tab)
else: else:
var deck := DeckHolder.get_group_instance(deck_id, instance_id) var deck := DeckHolder.get_group_instance(deck_id, instance_id)
var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate() var inst: DeckRendererGraphEdit = DECK_SCENE.instantiate()
inst.deck = deck inst.deck = deck
tab_container.add_content(inst, "<Group %s::%s>" % [deck_id.left(8), instance_id.left(8)]) var tab := tab_container.add_content(inst, "<Group %s::%s>" % [deck_id.left(8), instance_id.left(8)])
tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) tab_container.set_tab_metadata(tab, "id", deck.id)
inst.initialize_from_deck() inst.initialize_from_deck()
inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested)
tab_container.set_current_tab(tab)
func _on_deck_renderer_dirty_state_changed(renderer: DeckRendererGraphEdit) -> void: func _on_deck_renderer_dirty_state_changed(renderer: DeckRendererGraphEdit) -> void:

View file

@ -68,12 +68,12 @@ func _ready() -> void:
) )
## Adds the given [Node] as the displayed content for a tab. ## Adds the given [Node] as the displayed content for a tab.
func add_content(c: Node, tab_title: String) -> void: func add_content(c: Node, tab_title: String) -> int:
tab_bar.add_tab(tab_title) tab_bar.add_tab(tab_title)
content_container.add_child(c) content_container.add_child(c)
tab_bar.set_current_tab(tab_bar.tab_count - 1) #tab_bar.set_current_tab(tab_bar.tab_count - 1)
#_tab_metadata[tab_bar.tab_count - 1] = {}
_tab_metadata.append({}) _tab_metadata.append({})
return tab_bar.tab_count - 1
## Updates the tab at index [param tab_idx]'s title to [param title]. ## Updates the tab at index [param tab_idx]'s title to [param title].
@ -134,6 +134,8 @@ func set_tab_metadata(tab: int, key: String, value: Variant) -> void:
## Returns the metadata value set to the tab at index [param tab_idx] using [method set_tab_metadata]. ## Returns the metadata value set to the tab at index [param tab_idx] using [method set_tab_metadata].
## If no metadata was previously set, returns [code]null[/code] by default. ## If no metadata was previously set, returns [code]null[/code] by default.
func get_tab_metadata(tab: int, key: String) -> Variant: func get_tab_metadata(tab: int, key: String, default: Variant = null) -> Variant:
if _tab_metadata.size() - 1 < tab:
return default
var m = _tab_metadata[tab] var m = _tab_metadata[tab]
return m.get(key) return m.get(key, default)