mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-23 07:54:17 +01:00
Now text files will show up in the editor if the text editor plugin is enabled. Also clicking them will open them in the text editor.
This commit is contained in:
parent
521934ff55
commit
e019ccc64b
@ -6,6 +6,9 @@ module_env = env.Clone()
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"text_editor_file.cpp")
|
||||
module_env.add_source_files(env.modules_sources,"text_editor_format_loader.cpp")
|
||||
|
||||
if env["tools"]:
|
||||
module_env.add_source_files(env.modules_sources,"text_editor_plugin.cpp")
|
||||
module_env.add_source_files(env.modules_sources,"text_editor_settings.cpp")
|
||||
|
1
modules/text_editor/icons/icon_text_editor_file.svg
Normal file
1
modules/text_editor/icons/icon_text_editor_file.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg enable-background="new" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m13.370548 12.198712 1.078638-.0225c-.004-.738576-.008-1.477152-.01198-2.215728-1.429703.011985-2.859406.02397-4.289109.035955.004.759672.008 1.519344.01198 2.279016.40349-.01135.806981-.02271 1.210471-.03406v3.755044h2m-7.2700003-3.749287c.332722.21587.665444.431741.998166.647611-.3328629.218648-.6657258.437297-.9985887.655945-.0000001.818044-.0000002 1.636088-.0000003 2.454132.5662705-.533749 1.1325409-1.067498 1.6988114-1.601247.6353035.532396 1.2706071 1.064791 1.9059106 1.597187-.00095-.757409-.0019-1.514817-.00285-2.272226-.2987204-.278501-.5974407-.557002-.8961611-.835503.2983766-.205775.5967531-.41155.8951297-.617325.00283-.73844.00565-1.476881.00848-2.215321-.63732.474447-1.27464.948893-1.91196 1.42334-.5656447-.504299-1.1312895-1.008599-1.6969342-1.5128982m-1.4606388 2.2314242c.3595459-.0075.7190917-.015 1.0786376-.0225-.00399-.738576-.00799-1.477152-.011985-2.2157276-1.4297028.011985-2.8594057.02397-4.2891085.035955.00399.7596716.00799 1.5193436.011985 2.2790156.4034903-.01135.8069806-.02271 1.2104709-.03406v3.755044h2m2.3600877-14.999998c-.18815.7526-.3763 1.5052-.56445 2.2578-.3833928.1379205-.7411891.4041566-1.0765556.0469548-.5337315-.3203516-1.0674629-.6407032-1.6011944-.9610548-.4713667.4713667-.9427333.9427333-1.4141 1.4141.3984333.6647.7968667 1.3294 1.1953 1.9941-.1706946.369732-.2331288.8106877-.7232054.7948719-.6052849.1510593-1.2105697.3021187-1.8158546.4531781v2h5.2715c-.6869282-1.0800497-.0133438-2.6625661 1.2286888-2.9370347 1.2082391-.3582 2.5455142.6777799 2.4998312 1.9370347.104409.4657408-.6052318 1.1778026.181951 1h4.818019c0-.6666667 0-1.3333333 0-2-.7526-.18815-1.5052-.3763-2.2578-.56445-.138671-.3826756-.40361-.7396543-.047118-1.0747035.320406-.5343322.640812-1.0686643.961218-1.6029965-.471367-.4713667-.942733-.9427333-1.4141-1.4141-.6647.3984333-1.3294.7968667-1.9941 1.1953-.3697319-.1706947-.8106877-.2331288-.7948719-.7232054-.1510593-.6052849-.3021187-1.2105697-.4531781-1.8158546-.6666322.00004002-1.3334865-.00008002-1.99998.00006z" fill="#e0e0e0"/></svg>
|
After Width: | Height: | Size: 2.1 KiB |
@ -22,12 +22,20 @@ SOFTWARE.
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "text_editor_file.h"
|
||||
#include "text_editor_format_loader.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "text_editor_plugin.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
#endif
|
||||
|
||||
void register_text_editor_types() {
|
||||
//ClassDB::register_class<PaintWindow>();
|
||||
ClassDB::register_class<TextEditorFile>();
|
||||
|
||||
Ref<TextEditorTextLoader> loader;
|
||||
loader.instance();
|
||||
ResourceLoader::add_resource_format_loader(loader);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
EditorPlugins::add_by_type<TextEditorEditorPlugin>();
|
||||
|
15
modules/text_editor/text_editor_file.cpp
Normal file
15
modules/text_editor/text_editor_file.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "text_editor_file.h"
|
||||
|
||||
String TextEditorFile::get_file_path() {
|
||||
return _file_path;
|
||||
}
|
||||
|
||||
void TextEditorFile::set_file_path(const String &file_path) {
|
||||
_file_path = file_path;
|
||||
}
|
||||
|
||||
void TextEditorFile::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_file_path"), &TextEditorFile::get_file_path);
|
||||
ClassDB::bind_method(D_METHOD("set_file_path", "file_path"), &TextEditorFile::set_file_path);
|
||||
//ADD_PROPERTY(PropertyInfo(Variant::STRING, "file_path"), "set_file_path", "get_file_path");
|
||||
}
|
22
modules/text_editor/text_editor_file.h
Normal file
22
modules/text_editor/text_editor_file.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef TEXT_EDITOR_FILE_H
|
||||
#define TEXT_EDITOR_FILE_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
|
||||
class TextEditorFile : public Resource {
|
||||
GDCLASS(TextEditorFile, Resource);
|
||||
|
||||
public:
|
||||
String get_file_path();
|
||||
void set_file_path(const String &file_path);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
String _file_path;
|
||||
};
|
||||
|
||||
#endif
|
71
modules/text_editor/text_editor_format_loader.cpp
Normal file
71
modules/text_editor/text_editor_format_loader.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "text_editor_format_loader.h"
|
||||
|
||||
#include "text_editor_file.h"
|
||||
|
||||
RES TextEditorTextLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
||||
if (r_error) {
|
||||
*r_error = ERR_FILE_CANT_OPEN;
|
||||
}
|
||||
|
||||
Ref<TextEditorFile> file;
|
||||
file.instance();
|
||||
file->set_file_path(p_original_path);
|
||||
|
||||
if (r_error) {
|
||||
*r_error = OK;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void TextEditorTextLoader::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
p_extensions->push_back("txt");
|
||||
p_extensions->push_back("md");
|
||||
p_extensions->push_back("xml");
|
||||
p_extensions->push_back("sql");
|
||||
p_extensions->push_back("csv");
|
||||
p_extensions->push_back("cfg");
|
||||
p_extensions->push_back("ini");
|
||||
p_extensions->push_back("log");
|
||||
p_extensions->push_back("json");
|
||||
p_extensions->push_back("yml");
|
||||
p_extensions->push_back("yaml");
|
||||
p_extensions->push_back("toml");
|
||||
p_extensions->push_back("html");
|
||||
p_extensions->push_back("js");
|
||||
p_extensions->push_back("css");
|
||||
p_extensions->push_back("htmpl");
|
||||
}
|
||||
|
||||
bool TextEditorTextLoader::handles_type(const String &p_type) const {
|
||||
return p_type == "TextEditorFile";
|
||||
}
|
||||
|
||||
String TextEditorTextLoader::get_resource_type(const String &p_path) const {
|
||||
return "TextEditorFile";
|
||||
}
|
||||
|
||||
void TextEditorTextLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
||||
}
|
42
modules/text_editor/text_editor_format_loader.h
Normal file
42
modules/text_editor/text_editor_format_loader.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef TEXT_EDITOR_FORMAT_LOADER_H
|
||||
#define TEXT_EDITOR_FORMAT_LOADER_H
|
||||
|
||||
/*
|
||||
Copyright (c) 2019-2022 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "core/io/resource_loader.h"
|
||||
|
||||
class TextFileEditor;
|
||||
class Texture;
|
||||
|
||||
class TextEditorTextLoader : public ResourceFormatLoader {
|
||||
GDCLASS(TextEditorTextLoader, ResourceFormatLoader);
|
||||
|
||||
public:
|
||||
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr);
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
virtual bool handles_type(const String &p_type) const;
|
||||
virtual String get_resource_type(const String &p_path) const;
|
||||
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
|
||||
};
|
||||
|
||||
#endif
|
@ -22,6 +22,7 @@ SOFTWARE.
|
||||
|
||||
#include "text_editor_plugin.h"
|
||||
|
||||
#include "text_editor_file.h"
|
||||
#include "text_file_editor.h"
|
||||
|
||||
void TextEditorEditorPlugin::make_visible(const bool visible) {
|
||||
@ -35,10 +36,23 @@ String TextEditorEditorPlugin::get_name() const {
|
||||
const Ref<Texture> TextEditorEditorPlugin::get_icon() const {
|
||||
return _icon;
|
||||
}
|
||||
|
||||
bool TextEditorEditorPlugin::has_main_screen() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextEditorEditorPlugin::edit(Object *p_object) {
|
||||
Ref<TextEditorFile> f = Object::cast_to<TextEditorFile>(p_object);
|
||||
|
||||
if (f.is_valid()) {
|
||||
window->open_file(f->get_path());
|
||||
}
|
||||
}
|
||||
|
||||
bool TextEditorEditorPlugin::handles(Object *p_object) const {
|
||||
return p_object->is_class("TextEditorFile");
|
||||
}
|
||||
|
||||
TextEditorEditorPlugin::TextEditorEditorPlugin(EditorNode *p_node) {
|
||||
editor = p_node;
|
||||
|
||||
|
@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "core/io/resource_importer.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
|
||||
@ -37,6 +38,8 @@ public:
|
||||
const Ref<Texture> get_icon() const;
|
||||
bool has_main_screen() const;
|
||||
String get_name() const;
|
||||
void edit(Object *p_object);
|
||||
bool handles(Object *p_object) const;
|
||||
|
||||
TextEditorEditorPlugin(EditorNode *p_node);
|
||||
~TextEditorEditorPlugin();
|
||||
|
Loading…
Reference in New Issue
Block a user