/**************************************************************************/1/* text_editor.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "text_editor.h"3132#include "core/io/json.h"33#include "editor/script/script_editor_plugin.h"34#include "editor/settings/editor_settings.h"3536void TextEditor::_validate_script() {37TextEditorBase::_validate_script();3839Ref<JSON> json_file = edited_res;40if (json_file.is_valid()) {41CodeEdit *te = code_editor->get_text_editor();4243te->set_line_background_color(code_editor->get_error_pos().x, Color(0, 0, 0, 0));44code_editor->set_error("");4546if (json_file->parse(te->get_text(), true) != OK) {47code_editor->set_error(json_file->get_error_message().replace("[", "[lb]"));48code_editor->set_error_pos(json_file->get_error_line(), 0);49te->set_line_background_color(code_editor->get_error_pos().x, EDITOR_GET("text_editor/theme/highlighting/mark_color"));50}51}52}5354void TextEditor::apply_code() {55Ref<TextFile> text_file = edited_res;56if (text_file.is_valid()) {57text_file->set_text(code_editor->get_text_editor()->get_text());58}5960Ref<JSON> json_file = edited_res;61if (json_file.is_valid()) {62json_file->parse(code_editor->get_text_editor()->get_text(), true);63}64code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();65}6667ScriptEditorBase *TextEditor::create_editor(const Ref<Resource> &p_resource) {68if (Object::cast_to<TextFile>(*p_resource) || Object::cast_to<JSON>(*p_resource)) {69return memnew(TextEditor);70}71return nullptr;72}7374Control *TextEditor::get_edit_menu() {75if (!edit_menus) {76edit_menus = memnew(EditMenus);77}78return edit_menus;79}8081void TextEditor::register_editor() {82ScriptEditor::register_create_script_editor_function(create_editor);83}8485TextEditor::TextEditor() {86add_child(code_editor);87}888990