mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 21:31:10 +01:00
Cleaned up LastOpenedFiles.
This commit is contained in:
parent
8a98ebf0ed
commit
61909cb0fa
@ -236,22 +236,22 @@ void FileEditor::open_file(const String &path, const String &font) {
|
||||
VanillaEditor *vanilla_editor = open_in_vanillaeditor(path);
|
||||
|
||||
if (font != "null" && vanilla_editor.get("custom_fonts/font") != nullptr) {
|
||||
vanilla_editor.set_font(font);
|
||||
vanilla_editor->set_font(font);
|
||||
}
|
||||
|
||||
generate_file_item(path, vanilla_editor);
|
||||
last_opened_files->store_opened_files(open_file_list);
|
||||
last_opened_files->store_opened_files(_open_file_list);
|
||||
}
|
||||
|
||||
current_editor->show();
|
||||
}
|
||||
|
||||
void FileEditor::generate_file_item(const String &path, const Control &veditor) {
|
||||
open_file_name.set_text(path);
|
||||
open_file_list.add_item(path.get_file(), null, true);
|
||||
current_file_index = open_file_list.get_item_count() - 1;
|
||||
open_file_list.set_item_metadata(current_file_index, [veditor]);
|
||||
open_file_list.select(open_file_list.get_item_count() - 1);
|
||||
open_file_name->set_text(path);
|
||||
_open_file_list->add_item(path.get_file(), nullptr, true);
|
||||
current_file_index = _open_file_list.get_item_count() - 1;
|
||||
open_file_list->set_item_metadata(current_file_index, [veditor]);
|
||||
_open_file_list->select(_open_file_list->get_item_count() - 1);
|
||||
}
|
||||
|
||||
Control FileEditor::open_in_vanillaeditor(const String &path) {
|
||||
|
@ -1,140 +1,105 @@
|
||||
|
||||
#include "lastopenedfiles.h"
|
||||
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
EditorPlugin LastOpenedFiles::get_*editor_plugin() {
|
||||
return *editor_plugin;
|
||||
#include "core/variant.h"
|
||||
#include "scene/gui/item_list.h"
|
||||
#include "vanillaeditor.h"
|
||||
|
||||
void LastOpenedFiles::store_opened_files(ItemList *filecontainer) {
|
||||
Array arr;
|
||||
|
||||
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);
|
||||
|
||||
String filepath = ed->get_current_path();
|
||||
Array a = Array();
|
||||
a.push_back(filepath.get_file());
|
||||
a.push_back(filepath);
|
||||
arr.push_back(a);
|
||||
}
|
||||
|
||||
EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr);
|
||||
}
|
||||
|
||||
void LastOpenedFiles::set_*editor_plugin(const EditorPlugin &val) {
|
||||
*editor_plugin = val;
|
||||
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);
|
||||
|
||||
String filepath = ed->get_current_path();
|
||||
String f = filepath.get_file();
|
||||
Array arr = EditorSettings::get_singleton()->get_project_metadata("file_editor", "files", Array());
|
||||
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
Array a = arr[i];
|
||||
|
||||
if (a[0] == f) {
|
||||
arr.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr);
|
||||
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
|
||||
|
||||
if (fonts_dict.has(f)) {
|
||||
fonts_dict.erase(f);
|
||||
EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Ref<EditorSettings> LastOpenedFiles::get_editor_settings() {
|
||||
return editor_settings;
|
||||
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]);
|
||||
|
||||
if (fonts_dict.has(a[0])) {
|
||||
k.push_back(fonts_dict[a[0]]);
|
||||
}
|
||||
|
||||
else {
|
||||
k.push_back("null");
|
||||
}
|
||||
|
||||
keys.append(k);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
void LastOpenedFiles::set_editor_settings(const Ref<EditorSettings> &val) {
|
||||
editor_settings = val;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//tool;
|
||||
EditorPlugin *editor_plugin = null;
|
||||
Ref<EditorSettings> editor_settings = null;
|
||||
|
||||
void LastOpenedFiles::store_opened_files(const Control &filecontainer) {
|
||||
Array arr = Array();
|
||||
|
||||
for (int child = 0; child < filecontainer.get_item_count(); ++child) { //child in range(filecontainer.get_item_count())
|
||||
String filepath = filecontainer.get_item_metadata(child)[0].current_path;
|
||||
Array a = Array();
|
||||
a.push_back(filepath.get_file());
|
||||
a.push_back(filepath);
|
||||
arr.push_back(a);
|
||||
String LastOpenedFiles::get_editor_font() {
|
||||
return EditorSettings::get_singleton()->get_setting("interface/editor/code_font");
|
||||
}
|
||||
|
||||
editor_settings.set_project_metadata("file_editor", "files", arr);
|
||||
LastOpenedFiles::LastOpenedFiles() {
|
||||
}
|
||||
|
||||
|
||||
void LastOpenedFiles::remove_opened_file(const int index, const Control &filecontainer) {
|
||||
String filepath = filecontainer.get_item_metadata(index)[0].current_path;
|
||||
String f = filepath.get_file();
|
||||
Array arr = editor_settings.get_project_metadata("file_editor", "files", Array());
|
||||
|
||||
for (int i = 0; i < arr.size(); ++i) { //i in range(arr.size())
|
||||
Array a = arr[i];
|
||||
|
||||
if (a[0] == f) {
|
||||
arr.remove(i);
|
||||
break;
|
||||
LastOpenedFiles::~LastOpenedFiles() {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
editor_settings.set_project_metadata("file_editor", "files", arr);
|
||||
Dictionary fonts_dict = 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Array LastOpenedFiles::load_opened_files() {
|
||||
Array arr = editor_settings.get_project_metadata("file_editor", "files", Array());
|
||||
Dictionary fonts_dict = editor_settings.get_project_metadata("file_editor", "file_fonts", Dictionary());
|
||||
Array keys = Array();
|
||||
|
||||
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]);
|
||||
|
||||
if (fonts_dict.has(a[0])) {
|
||||
k.push_back(fonts_dict[a[0]]);
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
k.push_back("null");
|
||||
}
|
||||
|
||||
keys.append(k);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
void LastOpenedFiles::store_editor_fonts(const String &file_name, const String &font_path) {
|
||||
Dictionary fonts_dict = editor_settings.get_project_metadata("file_editor", "file_fonts", Dictionary());
|
||||
fonts_dict[file_name] = font_path;
|
||||
editor_settings.set_project_metadata("file_editor", "file_fonts", fonts_dict);
|
||||
}
|
||||
|
||||
|
||||
String LastOpenedFiles::get_editor_font() {
|
||||
//var editor_plugin : EditorPlugin = EditorPlugin.new();
|
||||
return editor_plugin.get_editor_interface().get_editor_settings().get_setting("interface/editor/code_font");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LastOpenedFiles::LastOpenedFiles() {
|
||||
*editor_plugin = null;
|
||||
editor_settings = null;
|
||||
}
|
||||
|
||||
LastOpenedFiles::~LastOpenedFiles() {
|
||||
}
|
||||
|
||||
|
||||
static void LastOpenedFiles::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_*editor_plugin"), &LastOpenedFiles::get_*editor_plugin);
|
||||
ClassDB::bind_method(D_METHOD("set_*editor_plugin", "value"), &LastOpenedFiles::set_*editor_plugin);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "*editor_plugin", PROPERTY_HINT_RESOURCE_TYPE, "EditorPlugin"), "set_*editor_plugin", "get_*editor_plugin");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_editor_settings"), &LastOpenedFiles::get_editor_settings);
|
||||
ClassDB::bind_method(D_METHOD("set_editor_settings", "value"), &LastOpenedFiles::set_editor_settings);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "editor_settings", PROPERTY_HINT_RESOURCE_TYPE, "Ref<EditorSettings>"), "set_editor_settings", "get_editor_settings");
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,20 +1,16 @@
|
||||
#ifndef LASTOPENEDFILES_H
|
||||
#define LASTOPENEDFILES_H
|
||||
|
||||
//This will not need EditorPlugin and EditorSettings, as now it can get them using singletons
|
||||
#include "core/reference.h"
|
||||
|
||||
class ItemList;
|
||||
|
||||
class LastOpenedFiles : public Reference {
|
||||
GDCLASS(LastOpenedFiles, Reference);
|
||||
|
||||
public:
|
||||
EditorPlugin get_ *editor_plugin();
|
||||
void set_ *editor_plugin(const EditorPlugin &val);
|
||||
|
||||
Ref<EditorSettings> get_editor_settings();
|
||||
void set_editor_settings(const Ref<EditorSettings> &val);
|
||||
|
||||
void store_opened_files(const Control &filecontainer);
|
||||
void remove_opened_file(const int index, const Control &filecontainer);
|
||||
void store_opened_files(ItemList *filecontainer);
|
||||
void remove_opened_file(const int index, ItemList *filecontainer);
|
||||
Array load_opened_files();
|
||||
void store_editor_fonts(const String &file_name, const String &font_path);
|
||||
String get_editor_font();
|
||||
@ -24,10 +20,6 @@ public:
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
EditorPlugin *editor_plugin = null;
|
||||
Ref<EditorSettings> editor_settings = null;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user