mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-18 07:17:18 +01:00
Fixed reopening files from the previous session in the editor's text editor module. Also small cleanups.
This commit is contained in:
parent
7747a4ee36
commit
b9a0b8253f
@ -38,6 +38,8 @@
|
|||||||
#include "text_editor_vanilla_editor.h"
|
#include "text_editor_vanilla_editor.h"
|
||||||
|
|
||||||
void TextEditorSettings::store_opened_files(ItemList *filecontainer) {
|
void TextEditorSettings::store_opened_files(ItemList *filecontainer) {
|
||||||
|
ERR_FAIL_COND(!filecontainer);
|
||||||
|
|
||||||
Array arr;
|
Array arr;
|
||||||
|
|
||||||
for (int child = 0; child < filecontainer->get_item_count(); ++child) {
|
for (int child = 0; child < filecontainer->get_item_count(); ++child) {
|
||||||
@ -71,6 +73,10 @@ void TextEditorSettings::remove_opened_file(const int index, ItemList *fileconta
|
|||||||
for (int i = 0; i < arr.size(); ++i) {
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
Array a = arr[i];
|
Array a = arr[i];
|
||||||
|
|
||||||
|
if (a.size() < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (a[0] == f) {
|
if (a[0] == f) {
|
||||||
arr.remove(i);
|
arr.remove(i);
|
||||||
break;
|
break;
|
||||||
@ -78,12 +84,15 @@ void TextEditorSettings::remove_opened_file(const int index, ItemList *fileconta
|
|||||||
}
|
}
|
||||||
|
|
||||||
EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr);
|
EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr);
|
||||||
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
|
||||||
|
|
||||||
if (fonts_dict.has(f)) {
|
if (fonts_dict.has(f)) {
|
||||||
fonts_dict.erase(f);
|
fonts_dict.erase(f);
|
||||||
EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict);
|
EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Array TextEditorSettings::load_opened_files() {
|
Array TextEditorSettings::load_opened_files() {
|
||||||
@ -91,20 +100,25 @@ Array TextEditorSettings::load_opened_files() {
|
|||||||
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
|
Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary());
|
||||||
Array keys;
|
Array keys;
|
||||||
|
|
||||||
for (int i = 0; i < arr.size(); ++i) { //i in range(arr.size())
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
Array a = arr[i];
|
Array a = arr[i];
|
||||||
|
|
||||||
|
if (a.size() < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// creating and returning an Array with this format [1:file name, 2:file path, 3:file font];
|
// creating and returning an Array with this format [1:file name, 2:file path, 3:file font];
|
||||||
Array k;
|
Array k;
|
||||||
k.push_back(a[0]);
|
k.push_back(a[0]);
|
||||||
k.push_back(a[1]);
|
k.push_back(a[1]);
|
||||||
|
|
||||||
if (fonts_dict.has(a[0])) {
|
/*
|
||||||
k.push_back(fonts_dict[a[0]]);
|
if (fonts_dict.has(a[2])) {
|
||||||
}
|
k.push_back(fonts_dict[a[2]]);
|
||||||
|
} else {
|
||||||
else {
|
|
||||||
k.push_back("null");
|
k.push_back("null");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
keys.append(k);
|
keys.append(k);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ void TextFileEditor::_on_font_selected(const String &font_path) {
|
|||||||
current_editor->set_font(font_path);
|
current_editor->set_font(font_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_opened_files->store_editor_fonts(current_file_path.get_file(), font_path);
|
_text_editor_settings->store_editor_fonts(current_file_path.get_file(), font_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextFileEditor::_on_fileitem_pressed(const int index) {
|
void TextFileEditor::_on_fileitem_pressed(const int index) {
|
||||||
@ -250,15 +250,18 @@ void TextFileEditor::open_file(const String &path, const String &font) {
|
|||||||
current_file_path = path;
|
current_file_path = path;
|
||||||
TextEditorVanillaEditor *vanilla_editor = open_in_vanillaeditor(path);
|
TextEditorVanillaEditor *vanilla_editor = open_in_vanillaeditor(path);
|
||||||
|
|
||||||
|
/*
|
||||||
Ref<Font> edf = vanilla_editor->get("custom_fonts/font");
|
Ref<Font> edf = vanilla_editor->get("custom_fonts/font");
|
||||||
|
|
||||||
//TODO this logic seems wrong
|
//TODO this logic seems wrong
|
||||||
if (font != "null" && edf.is_valid()) {
|
if (font != "null" && edf.is_valid()) {
|
||||||
vanilla_editor->set_font(font);
|
vanilla_editor->set_font(font);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
generate_file_item(path, vanilla_editor);
|
generate_file_item(path, vanilla_editor);
|
||||||
last_opened_files->store_opened_files(_open_file_list);
|
|
||||||
|
_text_editor_settings->store_opened_files(_open_file_list);
|
||||||
|
|
||||||
current_editor->show();
|
current_editor->show();
|
||||||
}
|
}
|
||||||
@ -324,7 +327,7 @@ void TextFileEditor::close_file(const int index) {
|
|||||||
void TextFileEditor::confirm_close(const int index) {
|
void TextFileEditor::confirm_close(const int index) {
|
||||||
ERR_FAIL_INDEX(index, _open_file_list->get_item_count());
|
ERR_FAIL_INDEX(index, _open_file_list->get_item_count());
|
||||||
|
|
||||||
last_opened_files->remove_opened_file(index, _open_file_list);
|
_text_editor_settings->remove_opened_file(index, _open_file_list);
|
||||||
_open_file_list->remove_item(index);
|
_open_file_list->remove_item(index);
|
||||||
open_file_name->clear();
|
open_file_name->clear();
|
||||||
current_editor->queue_delete();
|
current_editor->queue_delete();
|
||||||
@ -435,7 +438,6 @@ void TextFileEditor::clean_editor() {
|
|||||||
current_file_path = "";
|
current_file_path = "";
|
||||||
open_file_name->clear();
|
open_file_name->clear();
|
||||||
_open_file_list->clear();
|
_open_file_list->clear();
|
||||||
last_opened_files->store_opened_files(_open_file_list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextFileEditor::csv_preview() {
|
void TextFileEditor::csv_preview() {
|
||||||
@ -548,7 +550,7 @@ void TextFileEditor::_on_ConfirmationDialog_confirmed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextFileEditor::TextFileEditor() {
|
TextFileEditor::TextFileEditor() {
|
||||||
last_opened_files.instance();
|
_text_editor_settings.instance();
|
||||||
|
|
||||||
DIRECTORY = "res://";
|
DIRECTORY = "res://";
|
||||||
EXCEPTIONS = "addons";
|
EXCEPTIONS = "addons";
|
||||||
@ -776,12 +778,16 @@ void TextFileEditor::_notification(int p_what) {
|
|||||||
clean_editor();
|
clean_editor();
|
||||||
connect_signals();
|
connect_signals();
|
||||||
|
|
||||||
Array opened_files = last_opened_files->load_opened_files();
|
Array opened_files = _text_editor_settings->load_opened_files();
|
||||||
|
|
||||||
for (int i = 0; i < opened_files.size(); ++i) {
|
for (int i = 0; i < opened_files.size(); ++i) {
|
||||||
Array opened_file = opened_files[i];
|
Array opened_file = opened_files[i];
|
||||||
|
|
||||||
open_file(opened_file[1], opened_file[2]);
|
if (opened_file.size() < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
open_file(opened_file[0], opened_file[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_list->set_filters(EXTENSIONS);
|
file_list->set_filters(EXTENSIONS);
|
||||||
|
@ -141,7 +141,7 @@ protected:
|
|||||||
ConfirmationDialog *confirmation_close;
|
ConfirmationDialog *confirmation_close;
|
||||||
FileDialog *select_font_dialog;
|
FileDialog *select_font_dialog;
|
||||||
|
|
||||||
Ref<TextEditorSettings> last_opened_files;
|
Ref<TextEditorSettings> _text_editor_settings;
|
||||||
|
|
||||||
Array directories;
|
Array directories;
|
||||||
Array files;
|
Array files;
|
||||||
|
Loading…
Reference in New Issue
Block a user