From 01ce3a3932f11fe7e6688629bb0b35081154b9d3 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sun, 7 Jun 2020 01:48:35 +0300 Subject: [PATCH] When opening a project and the current tab is empty, open it in that tab If the current project is empty (only 1 layer and frame, no tags and the image has no content - is invisible) and the user is opening a project, then the opened project will not open a new tab of its own, and will use the currently opened one instead. --- src/Autoload/OpenSave.gd | 31 ++++++++++++++++++------------- src/Classes/Project.gd | 4 +++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index e82ea285b..7f7229fb9 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -27,7 +27,16 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: file.close() return - var new_project := Project.new([], path.get_file()) + var empty_project : bool = Global.current_project.frames.size() == 1 and Global.current_project.layers.size() == 1 and Global.current_project.frames[0].cels[0].image.is_invisible() and Global.current_project.animation_tags.size() == 0 + var new_project : Project + if empty_project: + new_project = Global.current_project + new_project.frames = [] + new_project.layers = [] + new_project.animation_tags.clear() + new_project.name = path.get_file() + else: + new_project = Project.new([], path.get_file()) var file_version := file.get_line() # Example, "v0.7.10-beta" var file_ver_splitted := file_version.split("-") @@ -119,11 +128,6 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: frame_line = file.get_line() frame += 1 -# new_project.frames = new_project.frames # Just to call Global.frames_changed -# new_project.current_layer = new_project.layers.size() - 1 -# new_project.current_frame = frame - 1 -# new_project.layers = new_project.layers # Just to call Global.layers_changed - if new_guides: var guide_line := file.get_line() # "guideline" no pun intended while guide_line == "|": # Load guides @@ -178,8 +182,12 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: tag_line = file.get_line() file.close() - Global.projects.append(new_project) - Global.tabs.current_tab = Global.tabs.get_tab_count() - 1 + if !empty_project: + Global.projects.append(new_project) + Global.tabs.current_tab = Global.tabs.get_tab_count() - 1 + else: + new_project.frames = new_project.frames # Just to call frames_changed + new_project.layers = new_project.layers # Just to call layers_changed Global.canvas.camera_zoom() if not untitled_backup: @@ -336,13 +344,10 @@ func reload_backup_file(project_paths : Array, backup_paths : Array) -> void: for i in range(project_paths.size()): # If project path is the same as backup save path -> the backup was untitled open_pxo_file(backup_paths[i], project_paths[i] == backup_paths[i]) - # We need "i + 1" because the paths must be stored in - # the new array slots, created from the Project class which was - # created in the above open_pxo_file() method - backup_save_paths[i + 1] = backup_paths[i] + backup_save_paths[i] = backup_paths[i] if project_paths[i] != backup_paths[i]: # If the user has saved - current_save_paths[i + 1] = project_paths[i] + current_save_paths[i] = project_paths[i] Global.window_title = project_paths[i].get_file() + " - Pixelorama(*) " + Global.current_version Global.current_project.has_changed = true diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 679ad2336..f8d840b2b 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -230,7 +230,7 @@ func frame_changed(value : int) -> void: # Select the new frame if current_frame < Global.frame_ids.get_child_count(): Global.frame_ids.get_child(current_frame).add_color_override("font_color", Global.control.theme.get_color("Selected Color", "Label")) - if current_frame < layers[current_layer].frame_container.get_child_count(): + if layers and current_frame < layers[current_layer].frame_container.get_child_count(): layers[current_layer].frame_container.get_child(current_frame).pressed = true Global.disable_button(Global.remove_frame_button, frames.size() == 1) @@ -259,6 +259,8 @@ func layer_changed(value : int) -> void: func toggle_layer_buttons_layers() -> void: + if !layers: + return if layers[current_layer].locked: Global.disable_button(Global.remove_layer_button, true)