pandemonium_engine/modules/text_editor/lastopenedfiles.cpp

106 lines
3.3 KiB
C++
Raw Normal View History

#include "lastopenedfiles.h"
2022-07-15 21:04:02 +02:00
#include "editor/editor_settings.h"
2022-07-15 21:04:02 +02:00
#include "core/variant.h"
#include "scene/gui/item_list.h"
#include "vanillaeditor.h"
2022-07-15 21:04:02 +02:00
void LastOpenedFiles::store_opened_files(ItemList *filecontainer) {
Array arr;
2022-07-15 21:04:02 +02:00
for (int child = 0; child < filecontainer->get_item_count(); ++child) {
Array metaarr = filecontainer->get_item_metadata(child);
Variant e = metaarr[0];
Control *c = e;
VanillaEditor *ed = Object::cast_to<VanillaEditor>(c);
2022-07-15 21:04:02 +02:00
String filepath = ed->get_current_path();
Array a = Array();
a.push_back(filepath.get_file());
a.push_back(filepath);
arr.push_back(a);
}
2022-07-15 21:04:02 +02:00
EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr);
}
2022-07-15 21:04:02 +02:00
void LastOpenedFiles::remove_opened_file(const int index, ItemList *filecontainer) {
Array metaarr = filecontainer->get_item_metadata(index);
Variant e = metaarr[0];
Control *c = e;
VanillaEditor *ed = Object::cast_to<VanillaEditor>(c);
2022-07-15 21:04:02 +02:00
String filepath = ed->get_current_path();
String f = filepath.get_file();
Array arr = EditorSettings::get_singleton()->get_project_metadata("file_editor", "files", Array());
2022-07-15 21:04:02 +02:00
for (int i = 0; i < arr.size(); ++i) {
Array a = arr[i];
2022-07-15 21:04:02 +02:00
if (a[0] == f) {
arr.remove(i);
break;
}
}
2022-07-15 21:04:02 +02:00
EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr);
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
2022-07-15 21:04:02 +02:00
if (fonts_dict.has(f)) {
fonts_dict.erase(f);
EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict);
}
}
2022-07-15 21:04:02 +02:00
Array LastOpenedFiles::load_opened_files() {
Array arr = EditorSettings::get_singleton()->get_project_metadata("file_editor", "files", Array());
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
Array keys;
2022-07-15 21:04:02 +02:00
for (int i = 0; i < arr.size(); ++i) { //i in range(arr.size())
Array a = arr[i];
// creating and returning an Array with this format [1:file name, 2:file path, 3:file font];
Array k;
k.push_back(a[0]);
k.push_back(a[1]);
2022-07-15 21:04:02 +02:00
if (fonts_dict.has(a[0])) {
k.push_back(fonts_dict[a[0]]);
}
2022-07-15 21:04:02 +02:00
else {
k.push_back("null");
}
2022-07-15 21:04:02 +02:00
keys.append(k);
}
2022-07-15 21:04:02 +02:00
return keys;
}
2022-07-15 21:04:02 +02:00
void LastOpenedFiles::store_editor_fonts(const String &file_name, const String &font_path) {
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
fonts_dict[file_name] = font_path;
EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict);
}
2022-07-15 21:04:02 +02:00
String LastOpenedFiles::get_editor_font() {
return EditorSettings::get_singleton()->get_setting("interface/editor/code_font");
}
2022-07-15 21:04:02 +02:00
LastOpenedFiles::LastOpenedFiles() {
}
2022-07-15 21:04:02 +02:00
LastOpenedFiles::~LastOpenedFiles() {
}
2022-07-15 21:04:02 +02:00
void LastOpenedFiles::_bind_methods() {
//ClassDB::bind_method(D_METHOD("store_opened_files", "filecontainer"), &LastOpenedFiles::store_opened_files);
//ClassDB::bind_method(D_METHOD("remove_opened_file", "index", "filecontainer"), &LastOpenedFiles::remove_opened_file);
//ClassDB::bind_method(D_METHOD("load_opened_files"), &LastOpenedFiles::load_opened_files);
//ClassDB::bind_method(D_METHOD("store_editor_fonts", "file_name", "font_path"), &LastOpenedFiles::store_editor_fonts);
//ClassDB::bind_method(D_METHOD("get_editor_font"), &LastOpenedFiles::get_editor_font);
}