mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
* Add request #276 * Remove a warning message * Some fixes * Bug fix. Remove Global.save_project_to_recent_list() from src/Main.gd Co-authored-by: Daniel Simon <dasimon@gmx.org>
This commit is contained in:
parent
d85efce73a
commit
7126074a0e
|
@ -175,6 +175,9 @@ msgstr ""
|
||||||
msgid "Import as:"
|
msgid "Import as:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Recent projects":
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "New tab"
|
msgid "New tab"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -1377,6 +1380,9 @@ msgstr ""
|
||||||
msgid "Cannot find last project file."
|
msgid "Cannot find last project file."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Cannot find project file."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "You haven't saved or opened any project in Pixelorama yet!"
|
msgid "You haven't saved or opened any project in Pixelorama yet!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ var projects := [] # Array of Projects
|
||||||
var current_project : Project
|
var current_project : Project
|
||||||
var current_project_index := 0 setget project_changed
|
var current_project_index := 0 setget project_changed
|
||||||
|
|
||||||
|
var recent_projects := []
|
||||||
|
|
||||||
# Indices are as in the Direction enum
|
# Indices are as in the Direction enum
|
||||||
# This is the total time the key for
|
# This is the total time the key for
|
||||||
# that direction has been pressed.
|
# that direction has been pressed.
|
||||||
|
@ -112,6 +114,8 @@ var help_menu : MenuButton
|
||||||
var cursor_position_label : Label
|
var cursor_position_label : Label
|
||||||
var zoom_level_label : Label
|
var zoom_level_label : Label
|
||||||
|
|
||||||
|
var recent_projects_submenu : PopupMenu
|
||||||
|
|
||||||
var new_image_dialog : ConfirmationDialog
|
var new_image_dialog : ConfirmationDialog
|
||||||
var open_sprites_dialog : FileDialog
|
var open_sprites_dialog : FileDialog
|
||||||
var save_sprites_dialog : FileDialog
|
var save_sprites_dialog : FileDialog
|
||||||
|
@ -176,6 +180,8 @@ func _ready() -> void:
|
||||||
# Load settings from the config file
|
# Load settings from the config file
|
||||||
config_cache.load("user://cache.ini")
|
config_cache.load("user://cache.ini")
|
||||||
|
|
||||||
|
recent_projects = config_cache.get_value("data", "recent_projects", [])
|
||||||
|
|
||||||
# The fact that root_dir is set earlier than this is important
|
# The fact that root_dir is set earlier than this is important
|
||||||
# XDGDataDirs depends on it nyaa
|
# XDGDataDirs depends on it nyaa
|
||||||
directory_module = XDGDataPaths.new()
|
directory_module = XDGDataPaths.new()
|
||||||
|
@ -209,6 +215,9 @@ func _ready() -> void:
|
||||||
cursor_position_label = find_node_by_name(root, "CursorPosition")
|
cursor_position_label = find_node_by_name(root, "CursorPosition")
|
||||||
zoom_level_label = find_node_by_name(root, "ZoomLevel")
|
zoom_level_label = find_node_by_name(root, "ZoomLevel")
|
||||||
|
|
||||||
|
recent_projects_submenu = PopupMenu.new()
|
||||||
|
recent_projects_submenu.set_name("recent_projects_submenu")
|
||||||
|
|
||||||
new_image_dialog = find_node_by_name(root, "CreateNewImage")
|
new_image_dialog = find_node_by_name(root, "CreateNewImage")
|
||||||
open_sprites_dialog = find_node_by_name(root, "OpenSprite")
|
open_sprites_dialog = find_node_by_name(root, "OpenSprite")
|
||||||
save_sprites_dialog = find_node_by_name(root, "SaveSprite")
|
save_sprites_dialog = find_node_by_name(root, "SaveSprite")
|
||||||
|
@ -506,3 +515,25 @@ func _exit_tree() -> void:
|
||||||
project.undo_redo.free()
|
project.undo_redo.free()
|
||||||
OpenSave.remove_backup(i)
|
OpenSave.remove_backup(i)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
func save_project_to_recent_list(path : String) -> void:
|
||||||
|
if path.get_file().substr(0, 7) == "backup-" or path == "":
|
||||||
|
return
|
||||||
|
|
||||||
|
if recent_projects.has(path):
|
||||||
|
return
|
||||||
|
|
||||||
|
if recent_projects.size() >= 5:
|
||||||
|
recent_projects.pop_front()
|
||||||
|
recent_projects.push_back(path)
|
||||||
|
|
||||||
|
config_cache.set_value("data", "recent_projects", recent_projects)
|
||||||
|
|
||||||
|
recent_projects_submenu.clear()
|
||||||
|
update_recent_projects_submenu()
|
||||||
|
|
||||||
|
|
||||||
|
func update_recent_projects_submenu() -> void:
|
||||||
|
for project in Global.recent_projects:
|
||||||
|
recent_projects_submenu.add_item(project.get_file())
|
||||||
|
|
|
@ -120,6 +120,8 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
||||||
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
|
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
|
||||||
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
|
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
|
||||||
|
|
||||||
|
Global.save_project_to_recent_list(path)
|
||||||
|
|
||||||
|
|
||||||
# For pxo files older than v0.8
|
# For pxo files older than v0.8
|
||||||
func open_old_pxo_file(file : File, new_project : Project, first_line : String) -> void:
|
func open_old_pxo_file(file : File, new_project : Project, first_line : String) -> void:
|
||||||
|
@ -337,6 +339,8 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
|
||||||
project.was_exported = false
|
project.was_exported = false
|
||||||
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
|
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
|
||||||
|
|
||||||
|
Global.save_project_to_recent_list(path)
|
||||||
|
|
||||||
|
|
||||||
func open_image_as_new_tab(path : String, image : Image) -> void:
|
func open_image_as_new_tab(path : String, image : Image) -> void:
|
||||||
var project = Project.new([], path.get_file(), image.get_size())
|
var project = Project.new([], path.get_file(), image.get_size())
|
||||||
|
|
15
src/Main.gd
15
src/Main.gd
|
@ -143,6 +143,21 @@ func load_last_project() -> void:
|
||||||
Global.dialog_open(true)
|
Global.dialog_open(true)
|
||||||
|
|
||||||
|
|
||||||
|
func load_recent_project_file(path : String) -> void:
|
||||||
|
if OS.get_name() == "HTML5":
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check if file still exists on disk
|
||||||
|
var file_check := File.new()
|
||||||
|
if file_check.file_exists(path): # If yes then load the file
|
||||||
|
OpenSave.handle_loading_files([path])
|
||||||
|
else:
|
||||||
|
# If file doesn't exist on disk then warn user about this
|
||||||
|
Global.error_dialog.set_text("Cannot find project file.")
|
||||||
|
Global.error_dialog.popup_centered()
|
||||||
|
Global.dialog_open(true)
|
||||||
|
|
||||||
|
|
||||||
func _on_OpenSprite_file_selected(path : String) -> void:
|
func _on_OpenSprite_file_selected(path : String) -> void:
|
||||||
OpenSave.handle_loading_files([path])
|
OpenSave.handle_loading_files([path])
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,16 @@ func setup_file_menu() -> void:
|
||||||
"Save as..." : InputMap.get_action_list("save_file_as")[0].get_scancode_with_modifiers(),
|
"Save as..." : InputMap.get_action_list("save_file_as")[0].get_scancode_with_modifiers(),
|
||||||
"Export..." : InputMap.get_action_list("export_file")[0].get_scancode_with_modifiers(),
|
"Export..." : InputMap.get_action_list("export_file")[0].get_scancode_with_modifiers(),
|
||||||
"Export as..." : InputMap.get_action_list("export_file_as")[0].get_scancode_with_modifiers(),
|
"Export as..." : InputMap.get_action_list("export_file_as")[0].get_scancode_with_modifiers(),
|
||||||
|
"Recent projects": 0,
|
||||||
"Quit" : InputMap.get_action_list("quit")[0].get_scancode_with_modifiers(),
|
"Quit" : InputMap.get_action_list("quit")[0].get_scancode_with_modifiers(),
|
||||||
}
|
}
|
||||||
file_menu = Global.file_menu.get_popup()
|
file_menu = Global.file_menu.get_popup()
|
||||||
var i := 0
|
var i := 0
|
||||||
|
|
||||||
for item in file_menu_items.keys():
|
for item in file_menu_items.keys():
|
||||||
|
if item == "Recent projects":
|
||||||
|
setup_recent_projects_submenu(item)
|
||||||
|
else:
|
||||||
file_menu.add_item(item, i, file_menu_items[item])
|
file_menu.add_item(item, i, file_menu_items[item])
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
@ -38,6 +42,14 @@ func setup_file_menu() -> void:
|
||||||
file_menu.set_item_disabled(2, true)
|
file_menu.set_item_disabled(2, true)
|
||||||
|
|
||||||
|
|
||||||
|
func setup_recent_projects_submenu(item : String) -> void:
|
||||||
|
Global.recent_projects_submenu.connect("id_pressed", self, "on_recent_projects_submenu_id_pressed")
|
||||||
|
Global.update_recent_projects_submenu()
|
||||||
|
|
||||||
|
file_menu.add_child(Global.recent_projects_submenu)
|
||||||
|
file_menu.add_submenu_item(item, Global.recent_projects_submenu.get_name())
|
||||||
|
|
||||||
|
|
||||||
func setup_edit_menu() -> void:
|
func setup_edit_menu() -> void:
|
||||||
var edit_menu_items := {
|
var edit_menu_items := {
|
||||||
"Undo" : InputMap.get_action_list("undo")[0].get_scancode_with_modifiers(),
|
"Undo" : InputMap.get_action_list("undo")[0].get_scancode_with_modifiers(),
|
||||||
|
@ -202,6 +214,10 @@ func export_file() -> void:
|
||||||
Export.external_export()
|
Export.external_export()
|
||||||
|
|
||||||
|
|
||||||
|
func on_recent_projects_submenu_id_pressed(id : int) -> void:
|
||||||
|
Global.control.load_recent_project_file(Global.recent_projects[id])
|
||||||
|
|
||||||
|
|
||||||
func edit_menu_id_pressed(id : int) -> void:
|
func edit_menu_id_pressed(id : int) -> void:
|
||||||
match id:
|
match id:
|
||||||
0: # Undo
|
0: # Undo
|
||||||
|
|
Loading…
Reference in a new issue