Reworked LastOpenedFiles, now it uses EditorSettings.

This commit is contained in:
Relintai 2022-07-15 11:16:30 +02:00
parent 5d1ca70aef
commit 22696e97f3

View File

@ -4,45 +4,67 @@ extends Reference
var editor_plugin : EditorPlugin = null var editor_plugin : EditorPlugin = null
var editor_settings : EditorSettings = null var editor_settings : EditorSettings = null
const lastopenedfile_path : String = "res://addons/file-editor/lastopenedfiles.lastcfg"
func _ready():
pass
func store_opened_files(filecontainer : Control): func store_opened_files(filecontainer : Control):
var file = ConfigFile.new() var arr : Array = Array()
file.load(lastopenedfile_path)
for child in range(0,filecontainer.get_item_count()):
var filepath = filecontainer.get_item_metadata(child)[0].current_path
file.set_value("Opened",filepath.get_file(),filepath)
file.save(lastopenedfile_path) for child in range(filecontainer.get_item_count()):
var filepath : String = filecontainer.get_item_metadata(child)[0].current_path
var a : Array = Array()
a.push_back(filepath.get_file())
a.push_back(filepath)
arr.push_back(a)
editor_settings.set_project_metadata("file_editor", "files", arr)
func remove_opened_file(index : int , filecontainer : Control): func remove_opened_file(index : int , filecontainer : Control):
var file = ConfigFile.new() var filepath : String = filecontainer.get_item_metadata(index)[0].current_path
file.load(lastopenedfile_path) var f : String = filepath.get_file()
var filepath = filecontainer.get_item_metadata(index)[0].current_path
file.set_value("Opened",filepath.get_file(),null) var arr : Array = editor_settings.get_project_metadata("file_editor", "files", Array())
file.save(lastopenedfile_path)
for i in range(arr.size()):
var a : Array = arr[i]
if a[0] == f:
arr.remove(i)
break
editor_settings.set_project_metadata("file_editor", "files", arr)
var fonts_dict : Dictionary = editor_settings.get_project_metadata("file_editor", "file_fonts", Dictionary())
if fonts_dict.has(f):
fonts_dict.erase(f)
editor_settings.set_project_metadata("file_editor", "file_fonts", fonts_dict)
func load_opened_files() -> Array: func load_opened_files() -> Array:
var file = ConfigFile.new() var arr : Array = editor_settings.get_project_metadata("file_editor", "files", Array())
file.load(lastopenedfile_path) var fonts_dict : Dictionary = editor_settings.get_project_metadata("file_editor", "file_fonts", Dictionary())
var keys = [] var keys : Array = Array()
# Load opened files for i in range(arr.size()):
if file.has_section("Opened"): var a : Array = arr[i]
var openedfiles = file.get_section_keys("Opened")
for openedfile in openedfiles: # creating and returning an Array with this format [1:file name, 2:file path, 3:file font]
# Load each single file which was opened var k : Array
# creating and returning an Array with this format [1:file name, 2:file path, 3:file font] k.push_back(a[0])
keys.append([openedfile, file.get_value("Opened",openedfile), file.get_value("Fonts",openedfile) if file.has_section_key("Fonts",openedfile) else "null"]) k.push_back(a[1])
if fonts_dict.has(a[0]):
k.push_back(fonts_dict[a[0]])
else:
k.push_back("null")
keys.append(k)
return keys return keys
func store_editor_fonts(file_name : String, font_path : String): func store_editor_fonts(file_name : String, font_path : String):
var file = ConfigFile.new() var fonts_dict : Dictionary = editor_settings.get_project_metadata("file_editor", "file_fonts", Dictionary())
file.load(lastopenedfile_path) fonts_dict[file_name] = font_path
file.set_value("Fonts",file_name,font_path) editor_settings.set_project_metadata("file_editor", "file_fonts", fonts_dict)
file.save(lastopenedfile_path)
func get_editor_font(): func get_editor_font():
#var editor_plugin : EditorPlugin = EditorPlugin.new() #var editor_plugin : EditorPlugin = EditorPlugin.new()