1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-30 23:19:49 +00:00

Add feature request #276 (#370)

* 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:
dasimonde 2020-10-26 21:51:55 +01:00 committed by GitHub
parent d85efce73a
commit 7126074a0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 4 deletions

View file

@ -175,6 +175,9 @@ msgstr ""
msgid "Import as:"
msgstr ""
msgid "Recent projects":
msgstr ""
msgid "New tab"
msgstr ""
@ -1377,6 +1380,9 @@ msgstr ""
msgid "Cannot find last project file."
msgstr ""
msgid "Cannot find project file."
msgstr ""
msgid "You haven't saved or opened any project in Pixelorama yet!"
msgstr ""

View file

@ -21,6 +21,8 @@ var projects := [] # Array of Projects
var current_project : Project
var current_project_index := 0 setget project_changed
var recent_projects := []
# Indices are as in the Direction enum
# This is the total time the key for
# that direction has been pressed.
@ -112,6 +114,8 @@ var help_menu : MenuButton
var cursor_position_label : Label
var zoom_level_label : Label
var recent_projects_submenu : PopupMenu
var new_image_dialog : ConfirmationDialog
var open_sprites_dialog : FileDialog
var save_sprites_dialog : FileDialog
@ -176,6 +180,8 @@ func _ready() -> void:
# Load settings from the config file
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
# XDGDataDirs depends on it nyaa
directory_module = XDGDataPaths.new()
@ -209,6 +215,9 @@ func _ready() -> void:
cursor_position_label = find_node_by_name(root, "CursorPosition")
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")
open_sprites_dialog = find_node_by_name(root, "OpenSprite")
save_sprites_dialog = find_node_by_name(root, "SaveSprite")
@ -506,3 +515,25 @@ func _exit_tree() -> void:
project.undo_redo.free()
OpenSave.remove_backup(i)
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())

View 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(5, tr("Export"))
Global.save_project_to_recent_list(path)
# For pxo files older than v0.8
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
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:
var project = Project.new([], path.get_file(), image.get_size())

View file

@ -143,6 +143,21 @@ func load_last_project() -> void:
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:
OpenSave.handle_loading_files([path])

View file

@ -23,12 +23,16 @@ func setup_file_menu() -> void:
"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 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(),
}
file_menu = Global.file_menu.get_popup()
var i := 0
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])
i += 1
@ -38,6 +42,14 @@ func setup_file_menu() -> void:
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:
var edit_menu_items := {
"Undo" : InputMap.get_action_list("undo")[0].get_scancode_with_modifiers(),
@ -202,6 +214,10 @@ func export_file() -> void:
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:
match id:
0: # Undo