diff --git a/SConstruct b/SConstruct index 81ef3b0..c30b64a 100644 --- a/SConstruct +++ b/SConstruct @@ -268,7 +268,7 @@ env_base["platform"] = selected_platform # Must always be re-set after calling # Detect modules. modules_detected = OrderedDict() -module_search_paths = [ "modules", methods.convert_custom_modules_path("editor_modules") ] # Built-in path. +module_search_paths = [ "modules" ] # Built-in path. # maybe? #if env_base["tools"]: diff --git a/editor_modules/cvtt/SCsub b/editor_modules/cvtt/SCsub deleted file mode 100644 index 8f6759b..0000000 --- a/editor_modules/cvtt/SCsub +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_modules") - -env_cvtt = env_modules.Clone() - -# Thirdparty source files - -thirdparty_obj = [] - -thirdparty_dir = "#thirdparty/cvtt/" -thirdparty_sources = ["ConvectionKernels.cpp"] - -thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - -env_cvtt.Prepend(CPPPATH=[thirdparty_dir]) - -env_thirdparty = env_cvtt.Clone() -env_thirdparty.disable_warnings() -env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) -env.modules_sources += thirdparty_obj - -# Pandemonium source files - -module_obj = [] - -env_cvtt.add_source_files(module_obj, "*.cpp") -env.modules_sources += module_obj - -# Needed to force rebuilding the module files when the thirdparty library is updated. -env.Depends(module_obj, thirdparty_obj) diff --git a/editor_modules/cvtt/config.py b/editor_modules/cvtt/config.py deleted file mode 100644 index 53b8f2f..0000000 --- a/editor_modules/cvtt/config.py +++ /dev/null @@ -1,6 +0,0 @@ -def can_build(env, platform): - return env["tools"] - - -def configure(env): - pass diff --git a/editor_modules/cvtt/image_compress_cvtt.cpp b/editor_modules/cvtt/image_compress_cvtt.cpp deleted file mode 100644 index e402189..0000000 --- a/editor_modules/cvtt/image_compress_cvtt.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/*************************************************************************/ -/* image_compress_cvtt.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "image_compress_cvtt.h" - -#include "core/os/os.h" -#include "core/os/thread.h" -#include "core/string/print_string.h" -#include "core/os/safe_refcount.h" - -#include - -struct CVTTCompressionJobParams { - bool is_hdr; - bool is_signed; - int bytes_per_pixel; - - cvtt::Options options; -}; - -struct CVTTCompressionRowTask { - const uint8_t *in_mm_bytes; - uint8_t *out_mm_bytes; - int y_start; - int width; - int height; -}; - -struct CVTTCompressionJobQueue { - CVTTCompressionJobParams job_params; - const CVTTCompressionRowTask *job_tasks; - uint32_t num_tasks; - SafeNumeric current_task; -}; - -static void _digest_row_task(const CVTTCompressionJobParams &p_job_params, const CVTTCompressionRowTask &p_row_task) { - const uint8_t *in_bytes = p_row_task.in_mm_bytes; - uint8_t *out_bytes = p_row_task.out_mm_bytes; - int w = p_row_task.width; - int h = p_row_task.height; - - int y_start = p_row_task.y_start; - int y_end = y_start + 4; - - int bytes_per_pixel = p_job_params.bytes_per_pixel; - bool is_hdr = p_job_params.is_hdr; - bool is_signed = p_job_params.is_signed; - - cvtt::PixelBlockU8 input_blocks_ldr[cvtt::NumParallelBlocks]; - cvtt::PixelBlockF16 input_blocks_hdr[cvtt::NumParallelBlocks]; - - for (int x_start = 0; x_start < w; x_start += 4 * cvtt::NumParallelBlocks) { - int x_end = x_start + 4 * cvtt::NumParallelBlocks; - - for (int y = y_start; y < y_end; y++) { - int first_input_element = (y - y_start) * 4; - const uint8_t *row_start; - if (y >= h) { - row_start = in_bytes + (h - 1) * (w * bytes_per_pixel); - } else { - row_start = in_bytes + y * (w * bytes_per_pixel); - } - - for (int x = x_start; x < x_end; x++) { - const uint8_t *pixel_start; - if (x >= w) { - pixel_start = row_start + (w - 1) * bytes_per_pixel; - } else { - pixel_start = row_start + x * bytes_per_pixel; - } - - int block_index = (x - x_start) / 4; - int block_element = (x - x_start) % 4 + first_input_element; - if (is_hdr) { - memcpy(input_blocks_hdr[block_index].m_pixels[block_element], pixel_start, bytes_per_pixel); - input_blocks_hdr[block_index].m_pixels[block_element][3] = 0x3c00; // 1.0 (unused) - } else { - memcpy(input_blocks_ldr[block_index].m_pixels[block_element], pixel_start, bytes_per_pixel); - } - } - } - - uint8_t output_blocks[16 * cvtt::NumParallelBlocks]; - - if (is_hdr) { - if (is_signed) { - cvtt::Kernels::EncodeBC6HS(output_blocks, input_blocks_hdr, p_job_params.options); - } else { - cvtt::Kernels::EncodeBC6HU(output_blocks, input_blocks_hdr, p_job_params.options); - } - } else { - cvtt::Kernels::EncodeBC7(output_blocks, input_blocks_ldr, p_job_params.options); - } - - unsigned int num_real_blocks = ((w - x_start) + 3) / 4; - if (num_real_blocks > cvtt::NumParallelBlocks) { - num_real_blocks = cvtt::NumParallelBlocks; - } - - memcpy(out_bytes, output_blocks, 16 * num_real_blocks); - out_bytes += 16 * num_real_blocks; - } -} - -static void _digest_job_queue(void *p_job_queue) { - CVTTCompressionJobQueue *job_queue = static_cast(p_job_queue); - - for (uint32_t next_task = job_queue->current_task.increment(); next_task <= job_queue->num_tasks; next_task = job_queue->current_task.increment()) { - _digest_row_task(job_queue->job_params, job_queue->job_tasks[next_task - 1]); - } -} - -void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressSource p_source) { - if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) { - return; //do not compress, already compressed - } - - int w = p_image->get_width(); - int h = p_image->get_height(); - - bool is_ldr = (p_image->get_format() <= Image::FORMAT_RGBA8); - bool is_hdr = (p_image->get_format() >= Image::FORMAT_RH) && (p_image->get_format() <= Image::FORMAT_RGBE9995); - - if (!is_ldr && !is_hdr) { - return; // Not a usable source format - } - - cvtt::Options options; - uint32_t flags = cvtt::Flags::Fastest; - - if (p_lossy_quality > 0.85) { - flags = cvtt::Flags::Ultra; - } else if (p_lossy_quality > 0.75) { - flags = cvtt::Flags::Better; - } else if (p_lossy_quality > 0.55) { - flags = cvtt::Flags::Default; - } else if (p_lossy_quality > 0.35) { - flags = cvtt::Flags::Fast; - } else if (p_lossy_quality > 0.15) { - flags = cvtt::Flags::Faster; - } - - flags |= cvtt::Flags::BC7_RespectPunchThrough; - - if (p_source == Image::COMPRESS_SOURCE_NORMAL) { - flags |= cvtt::Flags::Uniform; - } - options.flags = flags; - - Image::Format target_format = Image::FORMAT_BPTC_RGBA; - - bool is_signed = false; - if (is_hdr) { - if (p_image->get_format() != Image::FORMAT_RGBH) { - p_image->convert(Image::FORMAT_RGBH); - } - - PoolVector::Read rb = p_image->get_data().read(); - - const uint16_t *source_data = reinterpret_cast(&rb[0]); - int pixel_element_count = w * h * 3; - for (int i = 0; i < pixel_element_count; i++) { - if ((source_data[i] & 0x8000) != 0 && (source_data[i] & 0x7fff) != 0) { - is_signed = true; - break; - } - } - - target_format = is_signed ? Image::FORMAT_BPTC_RGBF : Image::FORMAT_BPTC_RGBFU; - } else { - p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert - } - - PoolVector::Read rb = p_image->get_data().read(); - - PoolVector data; - int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps()); - int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; - data.resize(target_size); - int shift = Image::get_format_pixel_rshift(target_format); - - PoolVector::Write wb = data.write(); - - int dst_ofs = 0; - - CVTTCompressionJobQueue job_queue; - job_queue.job_params.is_hdr = is_hdr; - job_queue.job_params.is_signed = is_signed; - job_queue.job_params.options = options; - job_queue.job_params.bytes_per_pixel = is_hdr ? 6 : 4; - -#ifdef NO_THREADS - int num_job_threads = 0; -#else - int num_job_threads = OS::get_singleton()->can_use_threads() ? (OS::get_singleton()->get_processor_count() - 1) : 0; -#endif - - PoolVector tasks; - - for (int i = 0; i <= mm_count; i++) { - int bw = w % 4 != 0 ? w + (4 - w % 4) : w; - int bh = h % 4 != 0 ? h + (4 - h % 4) : h; - - int src_ofs = p_image->get_mipmap_offset(i); - - const uint8_t *in_bytes = &rb[src_ofs]; - uint8_t *out_bytes = &wb[dst_ofs]; - - for (int y_start = 0; y_start < h; y_start += 4) { - CVTTCompressionRowTask row_task; - row_task.width = w; - row_task.height = h; - row_task.y_start = y_start; - row_task.in_mm_bytes = in_bytes; - row_task.out_mm_bytes = out_bytes; - - if (num_job_threads > 0) { - tasks.push_back(row_task); - } else { - _digest_row_task(job_queue.job_params, row_task); - } - - out_bytes += 16 * (bw / 4); - } - - dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; - w = MAX(w / 2, 1); - h = MAX(h / 2, 1); - } - - if (num_job_threads > 0) { - PoolVector threads; - threads.resize(num_job_threads); - - PoolVector::Write threads_wb = threads.write(); - - PoolVector::Read tasks_rb = tasks.read(); - - job_queue.job_tasks = &tasks_rb[0]; - job_queue.current_task.set(0); - job_queue.num_tasks = static_cast(tasks.size()); - - for (int i = 0; i < num_job_threads; i++) { - threads_wb[i] = memnew(Thread); - threads_wb[i]->start(_digest_job_queue, &job_queue); - } - _digest_job_queue(&job_queue); - - for (int i = 0; i < num_job_threads; i++) { - threads_wb[i]->wait_to_finish(); - memdelete(threads_wb[i]); - } - } - - p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); -} - -void image_decompress_cvtt(Image *p_image) { - Image::Format target_format; - bool is_signed = false; - bool is_hdr = false; - - Image::Format input_format = p_image->get_format(); - - switch (input_format) { - case Image::FORMAT_BPTC_RGBA: - target_format = Image::FORMAT_RGBA8; - break; - case Image::FORMAT_BPTC_RGBF: - case Image::FORMAT_BPTC_RGBFU: - target_format = Image::FORMAT_RGBH; - is_signed = (input_format == Image::FORMAT_BPTC_RGBF); - is_hdr = true; - break; - default: - return; // Invalid input format - }; - - int w = p_image->get_width(); - int h = p_image->get_height(); - - PoolVector::Read rb = p_image->get_data().read(); - - PoolVector data; - int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps()); - int mm_count = p_image->get_mipmap_count(); - data.resize(target_size); - - PoolVector::Write wb = data.write(); - - int bytes_per_pixel = is_hdr ? 6 : 4; - - int dst_ofs = 0; - - for (int i = 0; i <= mm_count; i++) { - int src_ofs = p_image->get_mipmap_offset(i); - - const uint8_t *in_bytes = &rb[src_ofs]; - uint8_t *out_bytes = &wb[dst_ofs]; - - cvtt::PixelBlockU8 output_blocks_ldr[cvtt::NumParallelBlocks]; - cvtt::PixelBlockF16 output_blocks_hdr[cvtt::NumParallelBlocks]; - - for (int y_start = 0; y_start < h; y_start += 4) { - int y_end = y_start + 4; - - for (int x_start = 0; x_start < w; x_start += 4 * cvtt::NumParallelBlocks) { - int x_end = x_start + 4 * cvtt::NumParallelBlocks; - - uint8_t input_blocks[16 * cvtt::NumParallelBlocks]; - memset(input_blocks, 0, sizeof(input_blocks)); - - unsigned int num_real_blocks = ((w - x_start) + 3) / 4; - if (num_real_blocks > cvtt::NumParallelBlocks) { - num_real_blocks = cvtt::NumParallelBlocks; - } - - memcpy(input_blocks, in_bytes, 16 * num_real_blocks); - in_bytes += 16 * num_real_blocks; - - if (is_hdr) { - if (is_signed) { - cvtt::Kernels::DecodeBC6HS(output_blocks_hdr, input_blocks); - } else { - cvtt::Kernels::DecodeBC6HU(output_blocks_hdr, input_blocks); - } - } else { - cvtt::Kernels::DecodeBC7(output_blocks_ldr, input_blocks); - } - - for (int y = y_start; y < y_end; y++) { - int first_input_element = (y - y_start) * 4; - uint8_t *row_start; - if (y >= h) { - row_start = out_bytes + (h - 1) * (w * bytes_per_pixel); - } else { - row_start = out_bytes + y * (w * bytes_per_pixel); - } - - for (int x = x_start; x < x_end; x++) { - uint8_t *pixel_start; - if (x >= w) { - pixel_start = row_start + (w - 1) * bytes_per_pixel; - } else { - pixel_start = row_start + x * bytes_per_pixel; - } - - int block_index = (x - x_start) / 4; - int block_element = (x - x_start) % 4 + first_input_element; - if (is_hdr) { - memcpy(pixel_start, output_blocks_hdr[block_index].m_pixels[block_element], bytes_per_pixel); - } else { - memcpy(pixel_start, output_blocks_ldr[block_index].m_pixels[block_element], bytes_per_pixel); - } - } - } - } - } - - dst_ofs += w * h * bytes_per_pixel; - w >>= 1; - h >>= 1; - } - - rb.release(); - wb.release(); - - p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); -} diff --git a/editor_modules/cvtt/image_compress_cvtt.h b/editor_modules/cvtt/image_compress_cvtt.h deleted file mode 100644 index 5d637d2..0000000 --- a/editor_modules/cvtt/image_compress_cvtt.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef IMAGE_COMPRESS_CVTT_H -#define IMAGE_COMPRESS_CVTT_H -/*************************************************************************/ -/* image_compress_cvtt.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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/image.h" - -void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressSource p_source); -void image_decompress_cvtt(Image *p_image); - -#endif // IMAGE_COMPRESS_CVTT_H diff --git a/editor_modules/cvtt/register_types.cpp b/editor_modules/cvtt/register_types.cpp deleted file mode 100644 index c855465..0000000 --- a/editor_modules/cvtt/register_types.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "register_types.h" - -#ifdef TOOLS_ENABLED - -#include "image_compress_cvtt.h" - -void register_cvtt_types(ModuleRegistrationLevel p_level) { - if (p_level == MODULE_REGISTRATION_LEVEL_CORE) { - Image::set_compress_bptc_func(image_compress_cvtt); - Image::_image_decompress_bptc = image_decompress_cvtt; - } -} - -void unregister_cvtt_types(ModuleRegistrationLevel p_level) {} - -#endif diff --git a/editor_modules/cvtt/register_types.h b/editor_modules/cvtt/register_types.h deleted file mode 100644 index 844928c..0000000 --- a/editor_modules/cvtt/register_types.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CVTT_REGISTER_TYPES_H -#define CVTT_REGISTER_TYPES_H -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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. */ -/*************************************************************************/ - -#ifdef TOOLS_ENABLED - -#include "modules/register_module_types.h" - -void register_cvtt_types(ModuleRegistrationLevel p_level); -void unregister_cvtt_types(ModuleRegistrationLevel p_level); - -#endif // TOOLS_ENABLED - -#endif // CVTT_REGISTER_TYPES_H diff --git a/editor_modules/editor_code_editor/SCsub b/editor_modules/editor_code_editor/SCsub deleted file mode 100644 index 7c5a43c..0000000 --- a/editor_modules/editor_code_editor/SCsub +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -env_mlp = env.Clone() - -sources = [ - "register_types.cpp", - - "editor_code_text_editor.cpp", - "editor_script_text_editor.cpp", - "editor_text_editor.cpp", - "editor_script_editor_base.cpp", - "editor_connection_info_dialog.cpp", - "editor_goto_line_dialog.cpp", - "editor_find_replace_bar.cpp", - "editor_script_editor_quick_open.cpp", - "editor_syntax_highlighter.cpp", - - "script_editor_plugin.cpp", - "editor_script_editor.cpp", -] - -env_mlp.add_source_files(env.modules_sources, sources) diff --git a/editor_modules/editor_code_editor/config.py b/editor_modules/editor_code_editor/config.py deleted file mode 100644 index af86767..0000000 --- a/editor_modules/editor_code_editor/config.py +++ /dev/null @@ -1,23 +0,0 @@ - - -def can_build(env, platform): - if not env["tools"]: - return False - - env.module_add_dependencies("editor_code_editor", ["freetype"], True) - - return True - -def configure(env): - pass - - -def get_doc_classes(): - return [ - "EditorScriptEditor", - "EditorScriptEditorBase", - "EditorSyntaxHighlighter" - ] - -def get_doc_path(): - return "doc_classes" diff --git a/editor_modules/editor_code_editor/doc_classes/EditorScriptEditor.xml b/editor_modules/editor_code_editor/doc_classes/EditorScriptEditor.xml deleted file mode 100644 index 72f74cf..0000000 --- a/editor_modules/editor_code_editor/doc_classes/EditorScriptEditor.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - Godot editor's script editor. - - - [b]Note:[/b] This class shouldn't be instantiated directly. Instead, access the singleton using [method EditorInterface.get_script_editor]. - - - - - - - - - - - - - - - - - - - - - - - - Returns the underlying [Control] used for editing scripts. For text scripts, this is a [TextEdit]. - - - - - - Returns a [Script] that is currently active in editor. - - - - - - - - - - - - - Returns an array with all [Script] objects which are currently open in editor. - - - - - - - Goes to the specified line in the current script. - - - - - - - - Opens the script create dialog. The script will extend [code]base_name[/code]. The file extension can be omitted from [code]base_path[/code]. It will be added based on the selected scripting language. - - - - - - Reload all currently opened scripts from disk in case the file contents are newer. - - - - - - - - Emitted when user changed active script. Argument is a freshly activated [Script]. - - - - - - Emitted when editor is about to close the active script. Argument is a [Script] that is going to be closed. - - - - - - diff --git a/editor_modules/editor_code_editor/doc_classes/EditorScriptEditorBase.xml b/editor_modules/editor_code_editor/doc_classes/EditorScriptEditorBase.xml deleted file mode 100644 index fd5dd5a..0000000 --- a/editor_modules/editor_code_editor/doc_classes/EditorScriptEditorBase.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/editor_modules/editor_code_editor/doc_classes/EditorSyntaxHighlighter.xml b/editor_modules/editor_code_editor/doc_classes/EditorSyntaxHighlighter.xml deleted file mode 100644 index da0ad47..0000000 --- a/editor_modules/editor_code_editor/doc_classes/EditorSyntaxHighlighter.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/editor_modules/editor_code_editor/editor_code_text_editor.cpp b/editor_modules/editor_code_editor/editor_code_text_editor.cpp deleted file mode 100644 index fa31b89..0000000 --- a/editor_modules/editor_code_editor/editor_code_text_editor.cpp +++ /dev/null @@ -1,1163 +0,0 @@ -/*************************************************************************/ -/* code_editor.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "editor_code_text_editor.h" - -#include "core/containers/vector.h" -#include "core/input/input.h" -#include "core/input/input_event.h" -#include "core/input/shortcut.h" -#include "core/math/math_funcs.h" -#include "core/math/vector2.h" -#include "core/object/class_db.h" -#include "core/object/resource.h" -#include "core/object/script_language.h" -#include "core/os/keyboard.h" -#include "core/os/memory.h" -#include "core/string/string_builder.h" -#include "core/typedefs.h" -#include "core/variant/array.h" -#include "core/variant/dictionary.h" -#include "editor/editor_node.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" -#include "scene/main/canvas_item.h" -#include "scene/gui/button.h" -#include "scene/gui/check_box.h" -#include "scene/main/control.h" -#include "scene/gui/label.h" -#include "scene/gui/line_edit.h" -#include "scene/gui/scroll_container.h" -#include "scene/gui/text_edit.h" -#include "scene/gui/texture_button.h" -#include "scene/gui/tool_button.h" -#include "scene/main/node.h" -#include "scene/main/timer.h" -#include "scene/resources/font/dynamic_font.h" -#include "scene/resources/font/font.h" -#include "scene/resources/texture.h" - -#include "editor_find_replace_bar.h" -#include "editor_goto_line_dialog.h" - -#include "editor_script_editor.h" - -void EditorCodeTextEditor::_text_editor_gui_input(const Ref &p_event) { - Ref mb = p_event; - - if (mb.is_valid()) { - if (mb->is_pressed() && mb->get_command()) { - if (mb->get_button_index() == BUTTON_WHEEL_UP) { - _zoom_in(); - } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN) { - _zoom_out(); - } - } - } - - Ref magnify_gesture = p_event; - if (magnify_gesture.is_valid()) { - Ref font = text_editor->get_theme_font("font"); - - if (font.is_valid()) { - if (font->get_size() != (int)font_size) { - font_size = font->get_size(); - } - - font_size *= powf(magnify_gesture->get_factor(), 0.25); - - _add_font_size((int)font_size - font->get_size()); - } - return; - } - - Ref k = p_event; - - if (k.is_valid()) { - if (k->is_pressed()) { - if (ED_IS_SHORTCUT("script_editor/zoom_in", p_event)) { - _zoom_in(); - } - if (ED_IS_SHORTCUT("script_editor/zoom_out", p_event)) { - _zoom_out(); - } - if (ED_IS_SHORTCUT("script_editor/reset_zoom", p_event)) { - _reset_zoom(); - } - } - } -} - -void EditorCodeTextEditor::_zoom_in() { - font_resize_val += MAX(EDSCALE, 1.0f); - _zoom_changed(); -} - -void EditorCodeTextEditor::_zoom_out() { - font_resize_val -= MAX(EDSCALE, 1.0f); - _zoom_changed(); -} - -void EditorCodeTextEditor::_zoom_changed() { - if (font_resize_timer->get_time_left() == 0) { - font_resize_timer->start(); - } -} - -void EditorCodeTextEditor::_reset_zoom() { - Ref font = text_editor->get_theme_font("font"); // Reset source font size to default. - - if (font.is_valid()) { - EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); - font->set_size(14); - } -} - -void EditorCodeTextEditor::_line_col_changed() { - String line = text_editor->get_line(text_editor->cursor_get_line()); - - int positional_column = 0; - for (int i = 0; i < text_editor->cursor_get_column(); i++) { - if (line[i] == '\t') { - positional_column += text_editor->get_indent_size(); //tab size - } else { - positional_column += 1; - } - } - - StringBuilder sb; - sb.append(itos(text_editor->cursor_get_line() + 1).lpad(4)); - sb.append(" : "); - sb.append(itos(positional_column + 1).lpad(3)); - - line_and_col_txt->set_text(sb.as_string()); -} - -void EditorCodeTextEditor::_text_changed() { - if (text_editor->is_insert_text_operation()) { - code_complete_timer->start(); - } - - idle->start(); -} - -void EditorCodeTextEditor::_code_complete_timer_timeout() { - if (!is_visible_in_tree()) { - return; - } - text_editor->query_code_comple(); -} - -void EditorCodeTextEditor::_complete_request() { - List entries; - String ctext = text_editor->get_text_for_completion(); - _code_complete_script(ctext, &entries); - bool forced = false; - if (code_complete_func) { - code_complete_func(code_complete_ud, ctext, &entries, forced); - } - if (entries.size() == 0) { - return; - } - - for (List::Element *E = entries.front(); E; E = E->next()) { - ScriptCodeCompletionOption *e = &E->get(); - e->icon = _get_completion_icon(*e); - e->font_color = completion_font_color; - if (e->insert_text.begins_with("\"") || e->insert_text.begins_with("\'")) { - e->font_color = completion_string_color; - } else if (e->insert_text.begins_with("#") || e->insert_text.begins_with("//")) { - e->font_color = completion_comment_color; - } - } - - text_editor->code_complete(entries, forced); -} - -Ref EditorCodeTextEditor::_get_completion_icon(const ScriptCodeCompletionOption &p_option) { - Ref tex; - switch (p_option.kind) { - case ScriptCodeCompletionOption::KIND_CLASS: { - if (has_theme_icon(p_option.display, "EditorIcons")) { - tex = get_theme_icon(p_option.display, "EditorIcons"); - } else { - tex = get_theme_icon("Object", "EditorIcons"); - } - } break; - case ScriptCodeCompletionOption::KIND_ENUM: - tex = get_theme_icon("Enum", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_FILE_PATH: - tex = get_theme_icon("File", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_NODE_PATH: - tex = get_theme_icon("NodePath", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_VARIABLE: - tex = get_theme_icon("Variant", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_CONSTANT: - tex = get_theme_icon("MemberConstant", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_MEMBER: - tex = get_theme_icon("MemberProperty", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_SIGNAL: - tex = get_theme_icon("MemberSignal", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_FUNCTION: - tex = get_theme_icon("MemberMethod", "EditorIcons"); - break; - case ScriptCodeCompletionOption::KIND_PLAIN_TEXT: - tex = get_theme_icon("CubeMesh", "EditorIcons"); - break; - default: - tex = get_theme_icon("String", "EditorIcons"); - break; - } - return tex; -} - -void EditorCodeTextEditor::_font_resize_timeout() { - if (_add_font_size(font_resize_val)) { - font_resize_val = 0; - } -} - -bool EditorCodeTextEditor::_add_font_size(int p_delta) { - Ref font = text_editor->get_theme_font("font"); - - if (font.is_valid()) { - int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE); - - if (new_size != font->get_size()) { - EditorSettings::get_singleton()->set("interface/editor/code_font_size", new_size / EDSCALE); - font->set_size(new_size); - } - - return true; - } else { - return false; - } -} - -void EditorCodeTextEditor::update_editor_settings() { - completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color"); - completion_string_color = EDITOR_GET("text_editor/highlighting/string_color"); - completion_comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); - - text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); - text_editor->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line")); - text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); - text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); - text_editor->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); - text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); - text_editor->set_draw_spaces(EditorSettings::get_singleton()->get("text_editor/indent/draw_spaces")); - text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/smooth_scrolling")); - text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); - text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/navigation/show_minimap")); - text_editor->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width") * EDSCALE); - text_editor->set_drag_and_drop_selection_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/drag_and_drop_selection")); - text_editor->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers")); - text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/appearance/line_numbers_zero_padded")); - text_editor->set_bookmark_gutter_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter")); - text_editor->set_breakpoint_gutter_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/show_breakpoint_gutter")); - text_editor->set_draw_info_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_info_gutter")); - text_editor->set_hiding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); - text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); - text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap")); - text_editor->set_show_line_length_guidelines(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")); - text_editor->set_line_length_guideline_soft_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column")); - text_editor->set_line_length_guideline_hard_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column")); - text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); - text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); - text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->is_caret_blink_active()); - text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); - text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); -} - -void EditorCodeTextEditor::trim_trailing_whitespace() { - bool trimed_whitespace = false; - for (int i = 0; i < text_editor->get_line_count(); i++) { - String line = text_editor->get_line(i); - if (line.ends_with(" ") || line.ends_with("\t")) { - if (!trimed_whitespace) { - text_editor->begin_complex_operation(); - trimed_whitespace = true; - } - - int end = 0; - for (int j = line.length() - 1; j > -1; j--) { - if (line[j] != ' ' && line[j] != '\t') { - end = j + 1; - break; - } - } - text_editor->set_line(i, line.substr(0, end)); - } - } - - if (trimed_whitespace) { - text_editor->end_complex_operation(); - text_editor->update(); - } -} - -void EditorCodeTextEditor::insert_final_newline() { - int final_line = text_editor->get_line_count() - 1; - - String line = text_editor->get_line(final_line); - - //length 0 means it's already an empty line, - //no need to add a newline - if (line.length() > 0 && !line.ends_with("\n")) { - text_editor->begin_complex_operation(); - - line += "\n"; - text_editor->set_line(final_line, line); - - text_editor->end_complex_operation(); - text_editor->update(); - } -} - -void EditorCodeTextEditor::convert_indent_to_spaces() { - int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); - String indent = ""; - - for (int i = 0; i < indent_size; i++) { - indent += " "; - } - - int cursor_line = text_editor->cursor_get_line(); - int cursor_column = text_editor->cursor_get_column(); - - bool changed_indentation = false; - for (int i = 0; i < text_editor->get_line_count(); i++) { - String line = text_editor->get_line(i); - - if (line.length() <= 0) { - continue; - } - - int j = 0; - while (j < line.length() && (line[j] == ' ' || line[j] == '\t')) { - if (line[j] == '\t') { - if (!changed_indentation) { - text_editor->begin_complex_operation(); - changed_indentation = true; - } - if (cursor_line == i && cursor_column > j) { - cursor_column += indent_size - 1; - } - line = line.left(j) + indent + line.right(j + 1); - } - j++; - } - if (changed_indentation) { - text_editor->set_line(i, line); - } - } - if (changed_indentation) { - text_editor->cursor_set_column(cursor_column); - text_editor->end_complex_operation(); - text_editor->update(); - } -} - -void EditorCodeTextEditor::convert_indent_to_tabs() { - int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); - indent_size -= 1; - - int cursor_line = text_editor->cursor_get_line(); - int cursor_column = text_editor->cursor_get_column(); - - bool changed_indentation = false; - for (int i = 0; i < text_editor->get_line_count(); i++) { - String line = text_editor->get_line(i); - - if (line.length() <= 0) { - continue; - } - - int j = 0; - int space_count = -1; - while (j < line.length() && (line[j] == ' ' || line[j] == '\t')) { - if (line[j] != '\t') { - space_count++; - - if (space_count == indent_size) { - if (!changed_indentation) { - text_editor->begin_complex_operation(); - changed_indentation = true; - } - if (cursor_line == i && cursor_column > j) { - cursor_column -= indent_size; - } - line = line.left(j - indent_size) + "\t" + line.right(j + 1); - j = 0; - space_count = -1; - } - } else { - space_count = -1; - } - j++; - } - if (changed_indentation) { - text_editor->set_line(i, line); - } - } - if (changed_indentation) { - text_editor->cursor_set_column(cursor_column); - text_editor->end_complex_operation(); - text_editor->update(); - } -} - -void EditorCodeTextEditor::convert_case(CaseStyle p_case) { - if (!text_editor->is_selection_active()) { - return; - } - - text_editor->begin_complex_operation(); - - int begin = text_editor->get_selection_from_line(); - int end = text_editor->get_selection_to_line(); - int begin_col = text_editor->get_selection_from_column(); - int end_col = text_editor->get_selection_to_column(); - - for (int i = begin; i <= end; i++) { - int len = text_editor->get_line(i).length(); - if (i == end) { - len = end_col; - } - if (i == begin) { - len -= begin_col; - } - String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len); - - switch (p_case) { - case UPPER: { - new_line = new_line.to_upper(); - } break; - case LOWER: { - new_line = new_line.to_lower(); - } break; - case CAPITALIZE: { - new_line = new_line.capitalize(); - } break; - } - - if (i == begin) { - new_line = text_editor->get_line(i).left(begin_col) + new_line; - } - if (i == end) { - new_line = new_line + text_editor->get_line(i).right(end_col); - } - text_editor->set_line(i, new_line); - } - text_editor->end_complex_operation(); -} - -void EditorCodeTextEditor::move_lines_up() { - text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int from_line = text_editor->get_selection_from_line(); - int from_col = text_editor->get_selection_from_column(); - int to_line = text_editor->get_selection_to_line(); - int to_column = text_editor->get_selection_to_column(); - int cursor_line = text_editor->cursor_get_line(); - - for (int i = from_line; i <= to_line; i++) { - int line_id = i; - int next_id = i - 1; - - if (line_id == 0 || next_id < 0) { - return; - } - - text_editor->unfold_line(line_id); - text_editor->unfold_line(next_id); - - text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); - } - int from_line_up = from_line > 0 ? from_line - 1 : from_line; - int to_line_up = to_line > 0 ? to_line - 1 : to_line; - int cursor_line_up = cursor_line > 0 ? cursor_line - 1 : cursor_line; - text_editor->select(from_line_up, from_col, to_line_up, to_column); - text_editor->cursor_set_line(cursor_line_up); - } else { - int line_id = text_editor->cursor_get_line(); - int next_id = line_id - 1; - - if (line_id == 0 || next_id < 0) { - return; - } - - text_editor->unfold_line(line_id); - text_editor->unfold_line(next_id); - - text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); - } - text_editor->end_complex_operation(); - text_editor->update(); -} - -void EditorCodeTextEditor::move_lines_down() { - text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int from_line = text_editor->get_selection_from_line(); - int from_col = text_editor->get_selection_from_column(); - int to_line = text_editor->get_selection_to_line(); - int to_column = text_editor->get_selection_to_column(); - int cursor_line = text_editor->cursor_get_line(); - - for (int i = to_line; i >= from_line; i--) { - int line_id = i; - int next_id = i + 1; - - if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { - return; - } - - text_editor->unfold_line(line_id); - text_editor->unfold_line(next_id); - - text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); - } - int from_line_down = from_line < text_editor->get_line_count() ? from_line + 1 : from_line; - int to_line_down = to_line < text_editor->get_line_count() ? to_line + 1 : to_line; - int cursor_line_down = cursor_line < text_editor->get_line_count() ? cursor_line + 1 : cursor_line; - text_editor->select(from_line_down, from_col, to_line_down, to_column); - text_editor->cursor_set_line(cursor_line_down); - } else { - int line_id = text_editor->cursor_get_line(); - int next_id = line_id + 1; - - if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) { - return; - } - - text_editor->unfold_line(line_id); - text_editor->unfold_line(next_id); - - text_editor->swap_lines(line_id, next_id); - text_editor->cursor_set_line(next_id); - } - text_editor->end_complex_operation(); - text_editor->update(); -} - -void EditorCodeTextEditor::_delete_line(int p_line) { - // this is currently intended to be called within delete_lines() - // so `begin_complex_operation` is omitted here - text_editor->set_line(p_line, ""); - if (p_line == 0 && text_editor->get_line_count() > 1) { - text_editor->cursor_set_line(1); - text_editor->cursor_set_column(0); - } - text_editor->backspace_at_cursor(); - if (p_line < text_editor->get_line_count()) { - text_editor->unfold_line(p_line); - } - text_editor->cursor_set_line(p_line); -} - -void EditorCodeTextEditor::delete_lines() { - text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int to_line = text_editor->get_selection_to_line(); - int from_line = text_editor->get_selection_from_line(); - int count = Math::abs(to_line - from_line) + 1; - - text_editor->cursor_set_line(from_line, false); - for (int i = 0; i < count; i++) { - _delete_line(from_line); - } - text_editor->deselect(); - } else { - _delete_line(text_editor->cursor_get_line()); - } - text_editor->end_complex_operation(); -} - -void EditorCodeTextEditor::duplicate_selection() { - const int cursor_column = text_editor->cursor_get_column(); - int from_line = text_editor->cursor_get_line(); - int to_line = text_editor->cursor_get_line(); - int from_column = 0; - int to_column = 0; - int cursor_new_line = to_line + 1; - int cursor_new_column = text_editor->cursor_get_column(); - String new_text = "\n" + text_editor->get_line(from_line); - bool selection_active = false; - - text_editor->cursor_set_column(text_editor->get_line(from_line).length()); - if (text_editor->is_selection_active()) { - from_column = text_editor->get_selection_from_column(); - to_column = text_editor->get_selection_to_column(); - - from_line = text_editor->get_selection_from_line(); - to_line = text_editor->get_selection_to_line(); - cursor_new_line = to_line + text_editor->cursor_get_line() - from_line; - cursor_new_column = to_column == cursor_column ? 2 * to_column - from_column : to_column; - new_text = text_editor->get_selection_text(); - selection_active = true; - - text_editor->cursor_set_line(to_line); - text_editor->cursor_set_column(to_column); - } - - text_editor->begin_complex_operation(); - - for (int i = from_line; i <= to_line; i++) { - text_editor->unfold_line(i); - } - text_editor->deselect(); - text_editor->insert_text_at_cursor(new_text); - text_editor->cursor_set_line(cursor_new_line); - text_editor->cursor_set_column(cursor_new_column); - if (selection_active) { - text_editor->select(to_line, to_column, 2 * to_line - from_line, to_line == from_line ? 2 * to_column - from_column : to_column); - } - - text_editor->end_complex_operation(); - text_editor->update(); -} - -void EditorCodeTextEditor::toggle_inline_comment(const String &delimiter) { - text_editor->begin_complex_operation(); - if (text_editor->is_selection_active()) { - int begin = text_editor->get_selection_from_line(); - int end = text_editor->get_selection_to_line(); - - // End of selection ends on the first column of the last line, ignore it. - if (text_editor->get_selection_to_column() == 0) { - end -= 1; - } - - int col_to = text_editor->get_selection_to_column(); - int cursor_pos = text_editor->cursor_get_column(); - - // Check if all lines in the selected block are commented. - bool is_commented = true; - for (int i = begin; i <= end; i++) { - if (!text_editor->get_line(i).begins_with(delimiter)) { - is_commented = false; - break; - } - } - for (int i = begin; i <= end; i++) { - String line_text = text_editor->get_line(i); - - if (line_text.strip_edges().empty()) { - line_text = delimiter; - } else { - if (is_commented) { - line_text = line_text.substr(delimiter.length(), line_text.length()); - } else { - line_text = delimiter + line_text; - } - } - text_editor->set_line(i, line_text); - } - - // Adjust selection & cursor position. - int offset = (is_commented ? -1 : 1) * delimiter.length(); - int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0; - - if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) { - cursor_pos += 1; - } - - if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1) { - col_to += offset; - } - - if (text_editor->cursor_get_column() != 0) { - cursor_pos += offset; - } - - text_editor->select(begin, col_from, text_editor->get_selection_to_line(), col_to); - text_editor->cursor_set_column(cursor_pos); - - } else { - int begin = text_editor->cursor_get_line(); - String line_text = text_editor->get_line(begin); - int delimiter_length = delimiter.length(); - - int col = text_editor->cursor_get_column(); - if (line_text.begins_with(delimiter)) { - line_text = line_text.substr(delimiter_length, line_text.length()); - col -= delimiter_length; - } else { - line_text = delimiter + line_text; - col += delimiter_length; - } - - text_editor->set_line(begin, line_text); - text_editor->cursor_set_column(col); - } - text_editor->end_complex_operation(); - text_editor->update(); -} - -void EditorCodeTextEditor::goto_line(int p_line) { - text_editor->deselect(); - text_editor->unfold_line(p_line); - text_editor->call_deferred("cursor_set_line", p_line); -} - -void EditorCodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { - text_editor->unfold_line(p_line); - text_editor->call_deferred("cursor_set_line", p_line); - text_editor->call_deferred("cursor_set_column", p_begin); - text_editor->select(p_line, p_begin, p_line, p_end); -} - -void EditorCodeTextEditor::goto_line_centered(int p_line) { - goto_line(p_line); - text_editor->call_deferred("center_viewport_to_cursor"); -} - -void EditorCodeTextEditor::set_executing_line(int p_line) { - text_editor->set_executing_line(p_line); -} - -void EditorCodeTextEditor::clear_executing_line() { - text_editor->clear_executing_line(); -} - -Variant EditorCodeTextEditor::get_edit_state() { - Dictionary state; - - state["scroll_position"] = text_editor->get_v_scroll(); - state["h_scroll_position"] = text_editor->get_h_scroll(); - state["column"] = text_editor->cursor_get_column(); - state["row"] = text_editor->cursor_get_line(); - - state["selection"] = get_text_edit()->is_selection_active(); - if (get_text_edit()->is_selection_active()) { - state["selection_from_line"] = text_editor->get_selection_from_line(); - state["selection_from_column"] = text_editor->get_selection_from_column(); - state["selection_to_line"] = text_editor->get_selection_to_line(); - state["selection_to_column"] = text_editor->get_selection_to_column(); - } - - state["folded_lines"] = text_editor->get_folded_lines(); - state["breakpoints"] = text_editor->get_breakpoints_array(); - state["bookmarks"] = text_editor->get_bookmarks_array(); - - Ref syntax_highlighter = text_editor->get_syntax_highlighter(); - state["syntax_highlighter"] = syntax_highlighter->_get_name(); - - return state; -} - -void EditorCodeTextEditor::set_edit_state(const Variant &p_state) { - Dictionary state = p_state; - - /* update the row first as it sets the column to 0 */ - text_editor->cursor_set_line(state["row"]); - text_editor->cursor_set_column(state["column"]); - text_editor->set_v_scroll(state["scroll_position"]); - text_editor->set_h_scroll(state["h_scroll_position"]); - - if (state.has("selection")) { - text_editor->select(state["selection_from_line"], state["selection_from_column"], state["selection_to_line"], state["selection_to_column"]); - } - - if (state.has("folded_lines")) { - Vector folded_lines = state["folded_lines"]; - for (int i = 0; i < folded_lines.size(); i++) { - text_editor->fold_line(folded_lines[i]); - } - } - - if (state.has("breakpoints")) { - Array breakpoints = state["breakpoints"]; - for (int i = 0; i < breakpoints.size(); i++) { - text_editor->set_line_as_breakpoint(breakpoints[i], true); - } - } - - if (state.has("bookmarks")) { - Array bookmarks = state["bookmarks"]; - for (int i = 0; i < bookmarks.size(); i++) { - text_editor->set_line_as_bookmark(bookmarks[i], true); - } - } -} - -void EditorCodeTextEditor::set_error(const String &p_error) { - error->set_text(p_error); - if (p_error != "") { - error->set_default_cursor_shape(CURSOR_POINTING_HAND); - } else { - error->set_default_cursor_shape(CURSOR_ARROW); - } -} - -void EditorCodeTextEditor::set_error_pos(int p_line, int p_column) { - error_line = p_line; - error_column = p_column; -} - -void EditorCodeTextEditor::goto_error() { - if (error->get_text() != "") { - text_editor->cursor_set_line(error_line); - text_editor->cursor_set_column(error_column); - text_editor->center_viewport_to_cursor(); - } -} - -void EditorCodeTextEditor::_update_font() { - text_editor->add_theme_font_override("font", get_theme_font("source", "EditorFonts")); - - error->add_theme_font_override("font", get_theme_font("status_source", "EditorFonts")); - error->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); - - Ref status_bar_font = get_theme_font("status_source", "EditorFonts"); - error->add_theme_font_override("font", status_bar_font); - int count = status_bar->get_child_count(); - for (int i = 0; i < count; i++) { - Control *n = Object::cast_to(status_bar->get_child(i)); - if (n) { - n->add_theme_font_override("font", status_bar_font); - } - } -} - -void EditorCodeTextEditor::_on_settings_change() { - _update_font(); - - font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); - - // Auto brace completion. - text_editor->set_auto_brace_completion( - EDITOR_GET("text_editor/completion/auto_brace_complete")); - - code_complete_timer->set_wait_time( - EDITOR_GET("text_editor/completion/code_complete_delay")); - - // Call hint settings. - text_editor->set_callhint_settings( - EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"), - EDITOR_GET("text_editor/completion/callhint_tooltip_offset")); - - idle->set_wait_time(EDITOR_GET("text_editor/completion/idle_parse_delay")); -} - -void EditorCodeTextEditor::_text_changed_idle_timeout() { - _validate_script(); - emit_signal("validate_script"); -} - -void EditorCodeTextEditor::validate_script() { - idle->start(); -} - -void EditorCodeTextEditor::_warning_label_gui_input(const Ref &p_event) { - Ref mb = p_event; - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - _warning_button_pressed(); - } -} - -void EditorCodeTextEditor::_warning_button_pressed() { - _set_show_warnings_panel(!is_warnings_panel_opened); -} - -void EditorCodeTextEditor::_set_show_warnings_panel(bool p_show) { - is_warnings_panel_opened = p_show; - emit_signal("show_warnings_panel", p_show); -} - -void EditorCodeTextEditor::_toggle_scripts_pressed() { - toggle_scripts_button->set_icon(EditorScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); -} - -void EditorCodeTextEditor::_error_pressed(const Ref &p_event) { - Ref mb = p_event; - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - goto_error(); - } -} - -void EditorCodeTextEditor::_notification(int p_what) { - switch (p_what) { - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - _load_theme_settings(); - emit_signal("load_theme_settings"); - } break; - case NOTIFICATION_THEME_CHANGED: { - if (toggle_scripts_button->is_visible()) { - update_toggle_scripts_button(); - } - _update_font(); - } break; - case NOTIFICATION_ENTER_TREE: { - warning_button->set_icon(get_theme_icon("NodeWarning", "EditorIcons")); - add_theme_constant_override("separation", 4 * EDSCALE); - } break; - case NOTIFICATION_VISIBILITY_CHANGED: { - if (toggle_scripts_button->is_visible()) { - update_toggle_scripts_button(); - } - } break; - default: - break; - } -} - -void EditorCodeTextEditor::set_warning_nb(int p_warning_nb) { - warning_count_label->set_text(itos(p_warning_nb)); - warning_count_label->set_visible(p_warning_nb > 0); - warning_button->set_visible(p_warning_nb > 0); - if (!p_warning_nb) { - _set_show_warnings_panel(false); - } -} - -void EditorCodeTextEditor::toggle_bookmark() { - int line = text_editor->cursor_get_line(); - text_editor->set_line_as_bookmark(line, !text_editor->is_line_set_as_bookmark(line)); -} - -void EditorCodeTextEditor::goto_next_bookmark() { - List bmarks; - text_editor->get_bookmarks(&bmarks); - if (bmarks.size() <= 0) { - return; - } - - int line = text_editor->cursor_get_line(); - if (line >= bmarks[bmarks.size() - 1]) { - text_editor->unfold_line(bmarks[0]); - text_editor->cursor_set_line(bmarks[0]); - text_editor->center_viewport_to_cursor(); - } else { - for (List::Element *E = bmarks.front(); E; E = E->next()) { - int bline = E->get(); - if (bline > line) { - text_editor->unfold_line(bline); - text_editor->cursor_set_line(bline); - text_editor->center_viewport_to_cursor(); - return; - } - } - } -} - -void EditorCodeTextEditor::goto_prev_bookmark() { - List bmarks; - text_editor->get_bookmarks(&bmarks); - if (bmarks.size() <= 0) { - return; - } - - int line = text_editor->cursor_get_line(); - if (line <= bmarks[0]) { - text_editor->unfold_line(bmarks[bmarks.size() - 1]); - text_editor->cursor_set_line(bmarks[bmarks.size() - 1]); - text_editor->center_viewport_to_cursor(); - } else { - for (List::Element *E = bmarks.back(); E; E = E->prev()) { - int bline = E->get(); - if (bline < line) { - text_editor->unfold_line(bline); - text_editor->cursor_set_line(bline); - text_editor->center_viewport_to_cursor(); - return; - } - } - } -} - -void EditorCodeTextEditor::remove_all_bookmarks() { - List bmarks; - text_editor->get_bookmarks(&bmarks); - - for (List::Element *E = bmarks.front(); E; E = E->next()) { - text_editor->set_line_as_bookmark(E->get(), false); - } -} - -void EditorCodeTextEditor::_bind_methods() { - ClassDB::bind_method("_text_editor_gui_input", &EditorCodeTextEditor::_text_editor_gui_input); - ClassDB::bind_method("_line_col_changed", &EditorCodeTextEditor::_line_col_changed); - ClassDB::bind_method("_text_changed", &EditorCodeTextEditor::_text_changed); - ClassDB::bind_method("_on_settings_change", &EditorCodeTextEditor::_on_settings_change); - ClassDB::bind_method("_text_changed_idle_timeout", &EditorCodeTextEditor::_text_changed_idle_timeout); - ClassDB::bind_method("_code_complete_timer_timeout", &EditorCodeTextEditor::_code_complete_timer_timeout); - ClassDB::bind_method("_complete_request", &EditorCodeTextEditor::_complete_request); - ClassDB::bind_method("_font_resize_timeout", &EditorCodeTextEditor::_font_resize_timeout); - ClassDB::bind_method("_error_pressed", &EditorCodeTextEditor::_error_pressed); - ClassDB::bind_method("_toggle_scripts_pressed", &EditorCodeTextEditor::_toggle_scripts_pressed); - ClassDB::bind_method("_warning_button_pressed", &EditorCodeTextEditor::_warning_button_pressed); - ClassDB::bind_method("_warning_label_gui_input", &EditorCodeTextEditor::_warning_label_gui_input); - - ADD_SIGNAL(MethodInfo("validate_script")); - ADD_SIGNAL(MethodInfo("load_theme_settings")); - ADD_SIGNAL(MethodInfo("show_warnings_panel")); -} - -void EditorCodeTextEditor::set_code_complete_func(EditorCodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud) { - code_complete_func = p_code_complete_func; - code_complete_ud = p_ud; -} - -void EditorCodeTextEditor::show_toggle_scripts_button() { - toggle_scripts_button->show(); -} - -void EditorCodeTextEditor::update_toggle_scripts_button() { - toggle_scripts_button->set_icon(EditorScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); - toggle_scripts_button->set_tooltip(TTR("Toggle Scripts Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")"); -} - -EditorCodeTextEditor::EditorCodeTextEditor() { - code_complete_func = nullptr; - ED_SHORTCUT("script_editor/zoom_in", TTR("Zoom In"), KEY_MASK_CMD | KEY_EQUAL); - ED_SHORTCUT("script_editor/zoom_out", TTR("Zoom Out"), KEY_MASK_CMD | KEY_MINUS); - ED_SHORTCUT("script_editor/reset_zoom", TTR("Reset Zoom"), KEY_MASK_CMD | KEY_0); - - text_editor = memnew(TextEdit); - add_child(text_editor); - text_editor->set_v_size_flags(SIZE_EXPAND_FILL); - - // Added second so it opens at the bottom, so it won't shift the entire text editor when opening. - find_replace_bar = memnew(EditorFindReplaceBar); - add_child(find_replace_bar); - find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL); - find_replace_bar->hide(); - - find_replace_bar->set_text_edit(text_editor); - - text_editor->set_show_line_numbers(true); - text_editor->set_brace_matching(true); - text_editor->set_auto_indent(true); - text_editor->set_deselect_on_focus_loss_enabled(false); - - status_bar = memnew(HBoxContainer); - add_child(status_bar); - status_bar->set_h_size_flags(SIZE_EXPAND_FILL); - status_bar->set_custom_minimum_size(Size2(0, 24 * EDSCALE)); // Adjust for the height of the warning icon. - - idle = memnew(Timer); - add_child(idle); - idle->set_one_shot(true); - idle->set_wait_time(EDITOR_GET("text_editor/completion/idle_parse_delay")); - - code_complete_timer = memnew(Timer); - add_child(code_complete_timer); - code_complete_timer->set_one_shot(true); - code_complete_timer->set_wait_time(EDITOR_GET("text_editor/completion/code_complete_delay")); - - error_line = 0; - error_column = 0; - - toggle_scripts_button = memnew(ToolButton); - toggle_scripts_button->connect("pressed", this, "_toggle_scripts_pressed"); - status_bar->add_child(toggle_scripts_button); - toggle_scripts_button->hide(); - - // Error - ScrollContainer *scroll = memnew(ScrollContainer); - scroll->set_h_size_flags(SIZE_EXPAND_FILL); - scroll->set_v_size_flags(SIZE_EXPAND_FILL); - scroll->set_enable_v_scroll(false); - status_bar->add_child(scroll); - - error = memnew(Label); - scroll->add_child(error); - error->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - error->set_mouse_filter(MOUSE_FILTER_STOP); - error->connect("gui_input", this, "_error_pressed"); - find_replace_bar->connect("error", error, "set_text"); - - // Warnings - warning_button = memnew(ToolButton); - status_bar->add_child(warning_button); - warning_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - warning_button->set_default_cursor_shape(CURSOR_POINTING_HAND); - warning_button->connect("pressed", this, "_warning_button_pressed"); - warning_button->set_tooltip(TTR("Warnings")); - - warning_count_label = memnew(Label); - status_bar->add_child(warning_count_label); - warning_count_label->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - warning_count_label->set_align(Label::ALIGN_RIGHT); - warning_count_label->set_default_cursor_shape(CURSOR_POINTING_HAND); - warning_count_label->set_mouse_filter(MOUSE_FILTER_STOP); - warning_count_label->set_tooltip(TTR("Warnings")); - warning_count_label->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor")); - warning_count_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); - warning_count_label->connect("gui_input", this, "_warning_label_gui_input"); - - is_warnings_panel_opened = false; - set_warning_nb(0); - - // Line and column - line_and_col_txt = memnew(Label); - status_bar->add_child(line_and_col_txt); - line_and_col_txt->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - line_and_col_txt->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); - line_and_col_txt->set_tooltip(TTR("Line and column numbers.")); - line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP); - - text_editor->connect("gui_input", this, "_text_editor_gui_input"); - text_editor->connect("cursor_changed", this, "_line_col_changed"); - text_editor->connect("text_changed", this, "_text_changed"); - text_editor->connect("request_completion", this, "_complete_request"); - Vector cs; - cs.push_back("."); - cs.push_back(","); - cs.push_back("("); - cs.push_back("="); - cs.push_back("$"); - text_editor->set_completion(true, cs); - idle->connect("timeout", this, "_text_changed_idle_timeout"); - - code_complete_timer->connect("timeout", this, "_code_complete_timer_timeout"); - - font_resize_val = 0; - font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); - font_resize_timer = memnew(Timer); - add_child(font_resize_timer); - font_resize_timer->set_one_shot(true); - font_resize_timer->set_wait_time(0.07); - font_resize_timer->connect("timeout", this, "_font_resize_timeout"); - - EditorSettings::get_singleton()->connect("settings_changed", this, "_on_settings_change"); -} diff --git a/editor_modules/editor_code_editor/editor_code_text_editor.h b/editor_modules/editor_code_editor/editor_code_text_editor.h deleted file mode 100644 index 77d81a5..0000000 --- a/editor_modules/editor_code_editor/editor_code_text_editor.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef EDITOR_CODE_EDITOR_H -#define EDITOR_CODE_EDITOR_H - -/*************************************************************************/ -/* code_editor.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "scene/gui/box_container.h" -#include "scene/gui/dialogs.h" - -#include "core/containers/list.h" -#include "core/math/math_defs.h" -#include "core/object/object.h" -#include "core/object/reference.h" -#include "core/string/ustring.h" -#include "core/variant/variant.h" - -class Button; -class CheckBox; -class InputEvent; -class Label; -class LineEdit; -class TextEdit; -class Texture; -class TextureButton; -class Timer; -class ToolButton; -struct ScriptCodeCompletionOption; -class EditorGotoLineDialog; -class EditorFindReplaceBar; - -typedef void (*EditorCodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List *r_options, bool &r_forced); - -class EditorCodeTextEditor : public VBoxContainer { - GDCLASS(EditorCodeTextEditor, VBoxContainer); - - TextEdit *text_editor; - EditorFindReplaceBar *find_replace_bar; - HBoxContainer *status_bar; - - ToolButton *toggle_scripts_button; - ToolButton *warning_button; - Label *warning_count_label; - - Label *line_and_col_txt; - - Label *info; - Timer *idle; - Timer *code_complete_timer; - - Timer *font_resize_timer; - int font_resize_val; - real_t font_size; - - Label *error; - int error_line; - int error_column; - - void _on_settings_change(); - - void _update_font(); - void _complete_request(); - Ref _get_completion_icon(const ScriptCodeCompletionOption &p_option); - void _font_resize_timeout(); - bool _add_font_size(int p_delta); - - void _text_editor_gui_input(const Ref &p_event); - void _zoom_in(); - void _zoom_out(); - void _zoom_changed(); - void _reset_zoom(); - - Color completion_font_color; - Color completion_string_color; - Color completion_comment_color; - EditorCodeTextEditorCodeCompleteFunc code_complete_func; - void *code_complete_ud; - - void _warning_label_gui_input(const Ref &p_event); - void _warning_button_pressed(); - void _set_show_warnings_panel(bool p_show); - void _error_pressed(const Ref &p_event); - - void _delete_line(int p_line); - void _toggle_scripts_pressed(); - -protected: - virtual void _load_theme_settings() {} - virtual void _validate_script() {} - virtual void _code_complete_script(const String &p_code, List *r_options) {} - - void _text_changed_idle_timeout(); - void _code_complete_timer_timeout(); - void _text_changed(); - void _line_col_changed(); - void _notification(int); - static void _bind_methods(); - - bool is_warnings_panel_opened; - -public: - void trim_trailing_whitespace(); - void insert_final_newline(); - - void convert_indent_to_spaces(); - void convert_indent_to_tabs(); - - enum CaseStyle { - UPPER, - LOWER, - CAPITALIZE, - }; - void convert_case(CaseStyle p_case); - - void move_lines_up(); - void move_lines_down(); - void delete_lines(); - void duplicate_selection(); - - /// Toggle inline comment on currently selected lines, or on current line if nothing is selected, - /// by adding or removing comment delimiter - void toggle_inline_comment(const String &delimiter); - - void goto_line(int p_line); - void goto_line_selection(int p_line, int p_begin, int p_end); - void goto_line_centered(int p_line); - void set_executing_line(int p_line); - void clear_executing_line(); - - Variant get_edit_state(); - void set_edit_state(const Variant &p_state); - - void set_warning_nb(int p_warning_nb); - - void update_editor_settings(); - void set_error(const String &p_error); - void set_error_pos(int p_line, int p_column); - void update_line_and_column() { _line_col_changed(); } - TextEdit *get_text_edit() { return text_editor; } - EditorFindReplaceBar *get_find_replace_bar() { return find_replace_bar; } - virtual void apply_code() {} - void goto_error(); - - void toggle_bookmark(); - void goto_next_bookmark(); - void goto_prev_bookmark(); - void remove_all_bookmarks(); - - void set_code_complete_func(EditorCodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud); - - void validate_script(); - - void show_toggle_scripts_button(); - void update_toggle_scripts_button(); - - EditorCodeTextEditor(); -}; - -#endif // CODE_EDITOR_H diff --git a/editor_modules/editor_code_editor/editor_connection_info_dialog.cpp b/editor_modules/editor_code_editor/editor_connection_info_dialog.cpp deleted file mode 100644 index b2838da..0000000 --- a/editor_modules/editor_code_editor/editor_connection_info_dialog.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************/ -/* script_text_editor.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "editor_connection_info_dialog.h" - -#include "editor/editor_node.h" -#include "editor/editor_scale.h" -#include "scene/gui/box_container.h" -#include "scene/gui/label.h" -#include "scene/gui/tree.h" -#include "scene/main/node.h" - -void EditorConnectionInfoDialog::ok_pressed() { -} - -void EditorConnectionInfoDialog::popup_connections(String p_method, Vector p_nodes) { - method->set_text(p_method); - - tree->clear(); - TreeItem *root = tree->create_item(); - - for (int i = 0; i < p_nodes.size(); i++) { - List all_connections; - p_nodes[i]->get_signals_connected_to_this(&all_connections); - - for (List::Element *E = all_connections.front(); E; E = E->next()) { - Connection connection = E->get(); - - if (connection.method != p_method) { - continue; - } - - TreeItem *node_item = tree->create_item(root); - - node_item->set_text(0, Object::cast_to(connection.source)->get_name()); - node_item->set_icon(0, EditorNode::get_singleton()->get_object_icon(connection.source, "Node")); - node_item->set_selectable(0, false); - node_item->set_editable(0, false); - - node_item->set_text(1, connection.signal); - node_item->set_icon(1, get_parent_control()->get_theme_icon("Slot", "EditorIcons")); - node_item->set_selectable(1, false); - node_item->set_editable(1, false); - - node_item->set_text(2, Object::cast_to(connection.target)->get_name()); - node_item->set_icon(2, EditorNode::get_singleton()->get_object_icon(connection.target, "Node")); - node_item->set_selectable(2, false); - node_item->set_editable(2, false); - } - } - - popup_centered(Size2(600, 300) * EDSCALE); -} - -EditorConnectionInfoDialog::EditorConnectionInfoDialog() { - set_title(TTR("Connections to method:")); - - VBoxContainer *vbc = memnew(VBoxContainer); - vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE); - add_child(vbc); - - method = memnew(Label); - method->set_align(Label::ALIGN_CENTER); - vbc->add_child(method); - - tree = memnew(Tree); - tree->set_columns(3); - tree->set_hide_root(true); - tree->set_column_titles_visible(true); - tree->set_column_title(0, TTR("Source")); - tree->set_column_title(1, TTR("Signal")); - tree->set_column_title(2, TTR("Target")); - vbc->add_child(tree); - tree->set_v_size_flags(SIZE_EXPAND_FILL); - tree->set_allow_rmb_select(true); -} diff --git a/editor_modules/editor_code_editor/editor_connection_info_dialog.h b/editor_modules/editor_code_editor/editor_connection_info_dialog.h deleted file mode 100644 index c346870..0000000 --- a/editor_modules/editor_code_editor/editor_connection_info_dialog.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef EDITOR_CONNECTION_INFO_DIALOG_H -#define EDITOR_CONNECTION_INFO_DIALOG_H - -/*************************************************************************/ -/* script_text_editor.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "scene/gui/dialogs.h" - -class Label; -class Node; -class Tree; - -class EditorConnectionInfoDialog : public AcceptDialog { - GDCLASS(EditorConnectionInfoDialog, AcceptDialog); - - Label *method; - Tree *tree; - - virtual void ok_pressed(); - -public: - void popup_connections(String p_method, Vector p_nodes); - - EditorConnectionInfoDialog(); -}; - -#endif // SCRIPT_TEXT_EDITOR_H diff --git a/editor_modules/editor_code_editor/editor_find_replace_bar.cpp b/editor_modules/editor_code_editor/editor_find_replace_bar.cpp deleted file mode 100644 index 04e20f0..0000000 --- a/editor_modules/editor_code_editor/editor_find_replace_bar.cpp +++ /dev/null @@ -1,654 +0,0 @@ -/*************************************************************************/ -/* code_editor.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "editor_find_replace_bar.h" - -#include "core/input/input.h" -#include "core/input/input_event.h" -#include "core/input/shortcut.h" -#include "core/math/math_funcs.h" -#include "core/os/keyboard.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" -#include "scene/gui/button.h" -#include "scene/gui/check_box.h" -#include "scene/main/control.h" -#include "scene/gui/label.h" -#include "scene/gui/line_edit.h" -#include "scene/gui/scroll_container.h" -#include "scene/gui/text_edit.h" -#include "scene/gui/texture_button.h" -#include "scene/gui/tool_button.h" -#include "scene/resources/font/font.h" -#include "scene/resources/texture.h" - -void EditorFindReplaceBar::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - set_process_unhandled_input(is_visible_in_tree()); - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); - } -} - -void EditorFindReplaceBar::_unhandled_input(const Ref &p_event) { - Ref k = p_event; - if (!k.is_valid() || !k->is_pressed()) { - return; - } - - Control *focus_owner = get_focus_owner(); - if (text_edit->has_focus() || (focus_owner && vbc_lineedit->is_a_parent_of(focus_owner))) { - bool accepted = true; - - switch (k->get_scancode()) { - case KEY_ESCAPE: { - _hide_bar(); - } break; - default: { - accepted = false; - } break; - } - - if (accepted) { - accept_event(); - } - } -} - -bool EditorFindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) { - int line, col; - String text = get_search_text(); - - bool found = text_edit->search(text, p_flags, p_from_line, p_from_col, line, col); - - if (found) { - if (!preserve_cursor && !is_selection_only()) { - text_edit->unfold_line(line); - text_edit->cursor_set_line(line, false); - text_edit->cursor_set_column(col + text.length(), false); - text_edit->center_viewport_to_cursor(); - text_edit->select(line, col, line, col + text.length()); - } - - text_edit->set_search_text(text); - text_edit->set_search_flags(p_flags); - text_edit->set_current_search_result(line, col); - - result_line = line; - result_col = col; - - _update_results_count(); - } else { - results_count = 0; - result_line = -1; - result_col = -1; - text_edit->set_search_text(""); - text_edit->set_search_flags(p_flags); - text_edit->set_current_search_result(line, col); - } - - _update_matches_label(); - - return found; -} - -void EditorFindReplaceBar::_replace() { - bool selection_enabled = text_edit->is_selection_active(); - Point2i selection_begin, selection_end; - if (selection_enabled) { - selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); - selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); - } - - String replace_text = get_replace_text(); - int search_text_len = get_search_text().length(); - - text_edit->begin_complex_operation(); - if (selection_enabled && is_selection_only()) { // To restrict search_current() to selected region - text_edit->cursor_set_line(selection_begin.width); - text_edit->cursor_set_column(selection_begin.height); - } - - if (search_current()) { - text_edit->unfold_line(result_line); - text_edit->select(result_line, result_col, result_line, result_col + search_text_len); - - if (selection_enabled && is_selection_only()) { - Point2i match_from(result_line, result_col); - Point2i match_to(result_line, result_col + search_text_len); - if (!(match_from < selection_begin || match_to > selection_end)) { - text_edit->insert_text_at_cursor(replace_text); - if (match_to.x == selection_end.x) { // Adjust selection bounds if necessary - selection_end.y += replace_text.length() - search_text_len; - } - } - } else { - text_edit->insert_text_at_cursor(replace_text); - } - } - text_edit->end_complex_operation(); - results_count = -1; - - if (selection_enabled && is_selection_only()) { - // Reselect in order to keep 'Replace' restricted to selection - text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); - } else { - text_edit->deselect(); - } -} - -void EditorFindReplaceBar::_replace_all() { - text_edit->disconnect("text_changed", this, "_editor_text_changed"); - // Line as x so it gets priority in comparison, column as y. - Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); - Point2i prev_match = Point2(-1, -1); - - bool selection_enabled = text_edit->is_selection_active(); - Point2i selection_begin, selection_end; - if (selection_enabled) { - selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); - selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); - } - - int vsval = text_edit->get_v_scroll(); - - text_edit->cursor_set_line(0); - text_edit->cursor_set_column(0); - - String replace_text = get_replace_text(); - int search_text_len = get_search_text().length(); - - int rc = 0; - - replace_all_mode = true; - - text_edit->begin_complex_operation(); - - if (selection_enabled && is_selection_only()) { - text_edit->cursor_set_line(selection_begin.width); - text_edit->cursor_set_column(selection_begin.height); - } - if (search_current()) { - do { - // replace area - Point2i match_from(result_line, result_col); - Point2i match_to(result_line, result_col + search_text_len); - - if (match_from < prev_match) { - break; // Done. - } - - prev_match = Point2i(result_line, result_col + replace_text.length()); - - text_edit->unfold_line(result_line); - text_edit->select(result_line, result_col, result_line, match_to.y); - - if (selection_enabled && is_selection_only()) { - if (match_from < selection_begin || match_to > selection_end) { - break; // Done. - } - - // Replace but adjust selection bounds. - text_edit->insert_text_at_cursor(replace_text); - if (match_to.x == selection_end.x) { - selection_end.y += replace_text.length() - search_text_len; - } - - } else { - // Just replace. - text_edit->insert_text_at_cursor(replace_text); - } - - rc++; - } while (search_next()); - } - - text_edit->end_complex_operation(); - - replace_all_mode = false; - - // Restore editor state (selection, cursor, scroll). - text_edit->cursor_set_line(orig_cursor.x); - text_edit->cursor_set_column(orig_cursor.y); - - if (selection_enabled && is_selection_only()) { - // Reselect. - text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); - } else { - text_edit->deselect(); - } - - text_edit->set_v_scroll(vsval); - matches_label->add_theme_color_override("font_color", rc > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); - matches_label->set_text(vformat(TTR("%d replaced."), rc)); - - text_edit->call_deferred("connect", "text_changed", this, "_editor_text_changed"); - results_count = -1; -} - -void EditorFindReplaceBar::_get_search_from(int &r_line, int &r_col) { - r_line = text_edit->cursor_get_line(); - r_col = text_edit->cursor_get_column(); - - if (text_edit->is_selection_active() && is_selection_only()) { - return; - } - - if (r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { - r_col = result_col; - } -} - -void EditorFindReplaceBar::_update_results_count() { - if (results_count != -1) { - return; - } - - results_count = 0; - - String searched = get_search_text(); - if (searched.empty()) { - return; - } - - String full_text = text_edit->get_text(); - - int from_pos = 0; - - while (true) { - int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos); - if (pos == -1) { - break; - } - - int pos_subsequent = pos + searched.length(); - if (is_whole_words()) { - from_pos = pos + 1; // Making sure we won't hit the same match next time, if we get out via a continue. - if (pos > 0 && !(is_symbol(full_text[pos - 1]) || full_text[pos - 1] == '\n')) { - continue; - } - if (pos_subsequent < full_text.length() && !(is_symbol(full_text[pos_subsequent]) || full_text[pos_subsequent] == '\n')) { - continue; - } - } - - results_count++; - from_pos = pos_subsequent; - } -} - -void EditorFindReplaceBar::_update_matches_label() { - if (search_text->get_text().empty() || results_count == -1) { - matches_label->hide(); - } else { - matches_label->show(); - - matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); - matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count)); - } -} - -bool EditorFindReplaceBar::search_current() { - uint32_t flags = 0; - - if (is_whole_words()) { - flags |= TextEdit::SEARCH_WHOLE_WORDS; - } - if (is_case_sensitive()) { - flags |= TextEdit::SEARCH_MATCH_CASE; - } - - int line, col; - _get_search_from(line, col); - - return _search(flags, line, col); -} - -bool EditorFindReplaceBar::search_prev() { - if (!is_visible()) { - popup_search(true); - } - - uint32_t flags = 0; - String text = get_search_text(); - - if (is_whole_words()) { - flags |= TextEdit::SEARCH_WHOLE_WORDS; - } - if (is_case_sensitive()) { - flags |= TextEdit::SEARCH_MATCH_CASE; - } - - flags |= TextEdit::SEARCH_BACKWARDS; - - int line, col; - _get_search_from(line, col); - if (text_edit->is_selection_active()) { - col--; // Skip currently selected word. - } - - col -= text.length(); - if (col < 0) { - line -= 1; - if (line < 0) { - line = text_edit->get_line_count() - 1; - } - col = text_edit->get_line(line).length(); - } - - return _search(flags, line, col); -} - -bool EditorFindReplaceBar::search_next() { - if (!is_visible()) { - popup_search(true); - } - - uint32_t flags = 0; - String text; - if (replace_all_mode) { - text = get_replace_text(); - } else { - text = get_search_text(); - } - - if (is_whole_words()) { - flags |= TextEdit::SEARCH_WHOLE_WORDS; - } - if (is_case_sensitive()) { - flags |= TextEdit::SEARCH_MATCH_CASE; - } - - int line, col; - _get_search_from(line, col); - - if (line == result_line && col == result_col) { - col += text.length(); - if (col > text_edit->get_line(line).length()) { - line += 1; - if (line >= text_edit->get_line_count()) { - line = 0; - } - col = 0; - } - } - - return _search(flags, line, col); -} - -void EditorFindReplaceBar::_hide_bar() { - if (replace_text->has_focus() || search_text->has_focus()) { - text_edit->grab_focus(); - } - - text_edit->set_search_text(""); - result_line = -1; - result_col = -1; - hide(); -} - -void EditorFindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) { - show(); - if (p_show_only) { - return; - } - - if (p_focus_replace) { - search_text->deselect(); - replace_text->call_deferred("grab_focus"); - } else { - replace_text->deselect(); - search_text->call_deferred("grab_focus"); - } - - if (text_edit->is_selection_active() && !selection_only->is_pressed()) { - search_text->set_text(text_edit->get_selection_text()); - } - - if (!get_search_text().empty()) { - if (p_focus_replace) { - replace_text->select_all(); - replace_text->set_cursor_position(replace_text->get_text().length()); - } else { - search_text->select_all(); - search_text->set_cursor_position(search_text->get_text().length()); - } - - results_count = -1; - _update_results_count(); - _update_matches_label(); - } -} - -void EditorFindReplaceBar::popup_search(bool p_show_only) { - replace_text->hide(); - hbc_button_replace->hide(); - hbc_option_replace->hide(); - - _show_search(false, p_show_only); -} - -void EditorFindReplaceBar::popup_replace() { - if (!replace_text->is_visible_in_tree()) { - replace_text->show(); - hbc_button_replace->show(); - hbc_option_replace->show(); - } - - selection_only->set_pressed((text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line())); - - _show_search(is_visible() || text_edit->is_selection_active()); -} - -void EditorFindReplaceBar::_search_options_changed(bool p_pressed) { - results_count = -1; - search_current(); -} - -void EditorFindReplaceBar::_editor_text_changed() { - results_count = -1; - if (is_visible_in_tree()) { - preserve_cursor = true; - search_current(); - preserve_cursor = false; - } -} - -void EditorFindReplaceBar::_search_text_changed(const String &p_text) { - results_count = -1; - search_current(); -} - -void EditorFindReplaceBar::_search_text_entered(const String &p_text) { - if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { - search_prev(); - } else { - search_next(); - } -} - -void EditorFindReplaceBar::_replace_text_entered(const String &p_text) { - if (selection_only->is_pressed() && text_edit->is_selection_active()) { - _replace_all(); - _hide_bar(); - } -} - -String EditorFindReplaceBar::get_search_text() const { - return search_text->get_text(); -} - -String EditorFindReplaceBar::get_replace_text() const { - return replace_text->get_text(); -} - -bool EditorFindReplaceBar::is_case_sensitive() const { - return case_sensitive->is_pressed(); -} - -bool EditorFindReplaceBar::is_whole_words() const { - return whole_words->is_pressed(); -} - -bool EditorFindReplaceBar::is_selection_only() const { - return selection_only->is_pressed(); -} - -void EditorFindReplaceBar::set_error(const String &p_label) { - emit_signal("error", p_label); -} - -void EditorFindReplaceBar::set_text_edit(TextEdit *p_text_edit) { - results_count = -1; - text_edit = p_text_edit; - text_edit->connect("text_changed", this, "_editor_text_changed"); -} - -void EditorFindReplaceBar::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &EditorFindReplaceBar::_unhandled_input); - - ClassDB::bind_method("_editor_text_changed", &EditorFindReplaceBar::_editor_text_changed); - ClassDB::bind_method("_search_text_changed", &EditorFindReplaceBar::_search_text_changed); - ClassDB::bind_method("_search_text_entered", &EditorFindReplaceBar::_search_text_entered); - ClassDB::bind_method("_replace_text_entered", &EditorFindReplaceBar::_replace_text_entered); - ClassDB::bind_method("_search_current", &EditorFindReplaceBar::search_current); - ClassDB::bind_method("_search_next", &EditorFindReplaceBar::search_next); - ClassDB::bind_method("_search_prev", &EditorFindReplaceBar::search_prev); - ClassDB::bind_method("_replace_pressed", &EditorFindReplaceBar::_replace); - ClassDB::bind_method("_replace_all_pressed", &EditorFindReplaceBar::_replace_all); - ClassDB::bind_method("_search_options_changed", &EditorFindReplaceBar::_search_options_changed); - ClassDB::bind_method("_hide_pressed", &EditorFindReplaceBar::_hide_bar); - - ADD_SIGNAL(MethodInfo("search")); - ADD_SIGNAL(MethodInfo("error")); -} - -EditorFindReplaceBar::EditorFindReplaceBar() { - results_count = -1; - replace_all_mode = false; - preserve_cursor = false; - - vbc_lineedit = memnew(VBoxContainer); - add_child(vbc_lineedit); - vbc_lineedit->set_alignment(ALIGN_CENTER); - vbc_lineedit->set_h_size_flags(SIZE_EXPAND_FILL); - VBoxContainer *vbc_button = memnew(VBoxContainer); - add_child(vbc_button); - VBoxContainer *vbc_option = memnew(VBoxContainer); - add_child(vbc_option); - - HBoxContainer *hbc_button_search = memnew(HBoxContainer); - vbc_button->add_child(hbc_button_search); - hbc_button_search->set_alignment(ALIGN_END); - hbc_button_replace = memnew(HBoxContainer); - vbc_button->add_child(hbc_button_replace); - hbc_button_replace->set_alignment(ALIGN_END); - - HBoxContainer *hbc_option_search = memnew(HBoxContainer); - vbc_option->add_child(hbc_option_search); - hbc_option_replace = memnew(HBoxContainer); - vbc_option->add_child(hbc_option_replace); - - // search toolbar - search_text = memnew(LineEdit); - vbc_lineedit->add_child(search_text); - search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); - search_text->connect("text_changed", this, "_search_text_changed"); - search_text->connect("text_entered", this, "_search_text_entered"); - - matches_label = memnew(Label); - hbc_button_search->add_child(matches_label); - matches_label->hide(); - - find_prev = memnew(ToolButton); - hbc_button_search->add_child(find_prev); - find_prev->set_focus_mode(FOCUS_NONE); - find_prev->connect("pressed", this, "_search_prev"); - - find_next = memnew(ToolButton); - hbc_button_search->add_child(find_next); - find_next->set_focus_mode(FOCUS_NONE); - find_next->connect("pressed", this, "_search_next"); - - case_sensitive = memnew(CheckBox); - hbc_option_search->add_child(case_sensitive); - case_sensitive->set_text(TTR("Match Case")); - case_sensitive->set_focus_mode(FOCUS_NONE); - case_sensitive->set_pressed(true); - case_sensitive->connect("toggled", this, "_search_options_changed"); - - whole_words = memnew(CheckBox); - hbc_option_search->add_child(whole_words); - whole_words->set_text(TTR("Whole Words")); - whole_words->set_focus_mode(FOCUS_NONE); - whole_words->connect("toggled", this, "_search_options_changed"); - - // replace toolbar - replace_text = memnew(LineEdit); - vbc_lineedit->add_child(replace_text); - replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); - replace_text->connect("text_entered", this, "_replace_text_entered"); - - replace = memnew(Button); - hbc_button_replace->add_child(replace); - replace->set_text(TTR("Replace")); - replace->connect("pressed", this, "_replace_pressed"); - - replace_all = memnew(Button); - hbc_button_replace->add_child(replace_all); - replace_all->set_text(TTR("Replace All")); - replace_all->connect("pressed", this, "_replace_all_pressed"); - - selection_only = memnew(CheckBox); - hbc_option_replace->add_child(selection_only); - selection_only->set_text(TTR("Selection Only")); - selection_only->set_focus_mode(FOCUS_NONE); - selection_only->connect("toggled", this, "_search_options_changed"); - - hide_button = memnew(TextureButton); - add_child(hide_button); - hide_button->set_focus_mode(FOCUS_NONE); - hide_button->connect("pressed", this, "_hide_pressed"); - hide_button->set_v_size_flags(SIZE_SHRINK_CENTER); -} diff --git a/editor_modules/editor_code_editor/editor_find_replace_bar.h b/editor_modules/editor_code_editor/editor_find_replace_bar.h deleted file mode 100644 index 7119721..0000000 --- a/editor_modules/editor_code_editor/editor_find_replace_bar.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef EDITOR_FIND_REPLACE_BAR_H -#define EDITOR_FIND_REPLACE_BAR_H - -/*************************************************************************/ -/* code_editor.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "scene/gui/dialogs.h" -#include "scene/gui/box_container.h" - -#include "core/containers/list.h" -#include "core/math/math_defs.h" -#include "core/object/object.h" -#include "core/object/reference.h" -#include "core/string/ustring.h" -#include "core/variant/variant.h" - -class Button; -class CheckBox; -class InputEvent; -class Label; -class LineEdit; -class TextEdit; -class Texture; -class TextureButton; -class ToolButton; - -class EditorFindReplaceBar : public HBoxContainer { - GDCLASS(EditorFindReplaceBar, HBoxContainer); - - LineEdit *search_text; - Label *matches_label; - ToolButton *find_prev; - ToolButton *find_next; - CheckBox *case_sensitive; - CheckBox *whole_words; - TextureButton *hide_button; - - LineEdit *replace_text; - Button *replace; - Button *replace_all; - CheckBox *selection_only; - - VBoxContainer *vbc_lineedit; - HBoxContainer *hbc_button_replace; - HBoxContainer *hbc_option_replace; - - TextEdit *text_edit; - - int result_line; - int result_col; - int results_count; - - bool replace_all_mode; - bool preserve_cursor; - - void _get_search_from(int &r_line, int &r_col); - void _update_results_count(); - void _update_matches_label(); - - void _show_search(bool p_focus_replace = false, bool p_show_only = false); - void _hide_bar(); - - void _editor_text_changed(); - void _search_options_changed(bool p_pressed); - void _search_text_changed(const String &p_text); - void _search_text_entered(const String &p_text); - void _replace_text_entered(const String &p_text); - -protected: - void _notification(int p_what); - void _unhandled_input(const Ref &p_event); - - bool _search(uint32_t p_flags, int p_from_line, int p_from_col); - - void _replace(); - void _replace_all(); - - static void _bind_methods(); - -public: - String get_search_text() const; - String get_replace_text() const; - - bool is_case_sensitive() const; - bool is_whole_words() const; - bool is_selection_only() const; - void set_error(const String &p_label); - - void set_text_edit(TextEdit *p_text_edit); - - void popup_search(bool p_show_only = false); - void popup_replace(); - - bool search_current(); - bool search_prev(); - bool search_next(); - - EditorFindReplaceBar(); -}; - -#endif // CODE_EDITOR_H diff --git a/editor_modules/editor_code_editor/editor_goto_line_dialog.cpp b/editor_modules/editor_code_editor/editor_goto_line_dialog.cpp deleted file mode 100644 index e9f806a..0000000 --- a/editor_modules/editor_code_editor/editor_goto_line_dialog.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************/ -/* code_editor.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "editor_goto_line_dialog.h" - -#include "scene/gui/line_edit.h" -#include "scene/gui/text_edit.h" -#include "scene/gui/box_container.h" -#include "scene/gui/label.h" - -#include "editor/editor_scale.h" - -void EditorGotoLineDialog::popup_find_line(TextEdit *p_edit) { - text_editor = p_edit; - - line->set_text(itos(text_editor->cursor_get_line())); - line->select_all(); - popup_centered(Size2(180, 80) * EDSCALE); - line->grab_focus(); -} - -int EditorGotoLineDialog::get_line() const { - return line->get_text().to_int(); -} - -void EditorGotoLineDialog::ok_pressed() { - if (get_line() < 1 || get_line() > text_editor->get_line_count()) { - return; - } - text_editor->unfold_line(get_line() - 1); - text_editor->cursor_set_line(get_line() - 1); - hide(); -} - -EditorGotoLineDialog::EditorGotoLineDialog() { - set_title(TTR("Go to Line")); - - VBoxContainer *vbc = memnew(VBoxContainer); - vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE); - add_child(vbc); - - Label *l = memnew(Label); - l->set_text(TTR("Line Number:")); - vbc->add_child(l); - - line = memnew(LineEdit); - vbc->add_child(line); - register_text_enter(line); - text_editor = nullptr; - - set_hide_on_ok(false); -} diff --git a/editor_modules/editor_code_editor/editor_goto_line_dialog.h b/editor_modules/editor_code_editor/editor_goto_line_dialog.h deleted file mode 100644 index a3c88d0..0000000 --- a/editor_modules/editor_code_editor/editor_goto_line_dialog.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef EDITOR_GOTO_LINE_DIALOH_H -#define EDITOR_GOTO_LINE_DIALOH_H - -/*************************************************************************/ -/* code_editor.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "scene/gui/dialogs.h" - -class Label; -class LineEdit; -class TextEdit; - -class EditorGotoLineDialog : public ConfirmationDialog { - GDCLASS(EditorGotoLineDialog, ConfirmationDialog); - - Label *line_label; - LineEdit *line; - - TextEdit *text_editor; - - virtual void ok_pressed(); - -public: - void popup_find_line(TextEdit *p_edit); - int get_line() const; - - EditorGotoLineDialog(); -}; - -#endif // CODE_EDITOR_H diff --git a/editor_modules/editor_code_editor/editor_script_editor.cpp b/editor_modules/editor_code_editor/editor_script_editor.cpp deleted file mode 100644 index 065318e..0000000 --- a/editor_modules/editor_code_editor/editor_script_editor.cpp +++ /dev/null @@ -1,3532 +0,0 @@ - -/*************************************************************************/ -/* script_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "editor_script_editor.h" - -#include "core/config/project_settings.h" -#include "core/containers/pair.h" -#include "core/containers/rb_map.h" -#include "core/error/error_macros.h" -#include "core/input/input.h" -#include "core/input/input_event.h" -#include "core/io/config_file.h" -#include "core/io/resource_loader.h" -#include "core/io/resource_saver.h" -#include "core/math/color.h" -#include "core/math/math_funcs.h" -#include "core/math/transform_2d.h" -#include "core/object/class_db.h" -#include "core/object/undo_redo.h" -#include "core/os/file_access.h" -#include "core/os/keyboard.h" -#include "core/os/main_loop.h" -#include "core/os/memory.h" -#include "core/os/os.h" -#include "core/string/string_name.h" -#include "core/variant/dictionary.h" -#include "core/version_generated.gen.h" -#include "editor/editor_data.h" -#include "editor/editor_file_dialog.h" -#include "editor/editor_file_system.h" -#include "editor/editor_help.h" -#include "editor/editor_help_search.h" -#include "editor/editor_node.h" -#include "editor/editor_run_script.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" -#include "editor/filesystem_dock.h" -#include "editor/find_in_files.h" -#include "editor/inspector_dock.h" -#include "editor/node_dock.h" -#include "editor/script_create_dialog.h" -#include "editor/script_editor_debugger.h" -#include "scene/main/canvas_item.h" -#include "scene/gui/button.h" -#include "scene/main/control.h" -#include "scene/gui/item_list.h" -#include "scene/gui/label.h" -#include "scene/gui/line_edit.h" -#include "scene/gui/menu_button.h" -#include "scene/gui/popup_menu.h" -#include "scene/gui/separator.h" -#include "scene/gui/split_container.h" -#include "scene/gui/tab_container.h" -#include "scene/gui/text_edit.h" -#include "scene/gui/texture_rect.h" -#include "scene/gui/tool_button.h" -#include "scene/gui/tree.h" -#include "scene/main/node.h" -#include "scene/main/scene_tree.h" -#include "scene/main/timer.h" -#include "scene/main/viewport.h" -#include "scene/resources/text_file.h" -#include "scene/resources/texture.h" -#include "scene/main/scene_string_names.h" - -#include "editor_script_editor_quick_open.h" -#include "editor_script_text_editor.h" -#include "editor_text_editor.h" - -#include "modules/modules_enabled.gen.h" - -#ifdef MODULE_SHADER_EDITOR_ENABLED -#include "shader_editor/shader_editor_plugin.h" -#endif - -static bool _is_built_in_script(Script *p_script) { - String path = p_script->get_path(); - - return path.find("::") != -1; -} - -class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { - struct Cache { - uint64_t time_loaded; - RES cache; - - Cache() { - time_loaded = 0; - } - }; - - RBMap cached; - -public: - uint64_t max_time_cache; - int max_cache_size; - - void cleanup() { - List::Element *> to_clean; - - RBMap::Element *I = cached.front(); - while (I) { - if ((OS::get_singleton()->get_ticks_msec() - I->get().time_loaded) > max_time_cache) { - to_clean.push_back(I); - } - I = I->next(); - } - - while (to_clean.front()) { - cached.erase(to_clean.front()->get()); - to_clean.pop_front(); - } - } - - virtual RES get_cached_resource(const String &p_path) { - RBMap::Element *E = cached.find(p_path); - if (!E) { - Cache c; - c.cache = ResourceLoader::load(p_path); - E = cached.insert(p_path, c); - } - - E->get().time_loaded = OS::get_singleton()->get_ticks_msec(); - - if (cached.size() > max_cache_size) { - uint64_t older; - RBMap::Element *O = cached.front(); - older = O->get().time_loaded; - RBMap::Element *I = O; - while (I) { - if (I->get().time_loaded < older) { - older = I->get().time_loaded; - O = I; - } - I = I->next(); - } - - if (O != E) { //should never happen.. - cached.erase(O); - } - } - - return E->get().cache; - } - - EditorScriptCodeCompletionCache() { - max_cache_size = 128; - max_time_cache = 5 * 60 * 1000; //minutes, five - } - - virtual ~EditorScriptCodeCompletionCache() {} -}; - -///////////////////////////////// - -EditorScriptEditor *EditorScriptEditor::script_editor = nullptr; - -/*** SCRIPT EDITOR ******/ - -String EditorScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) { - String val = debugger->get_var_value(p_text); - if (val != String()) { - return p_text + ": " + val; - } else { - return String(); - } -} - -void EditorScriptEditor::_breaked(bool p_breaked, bool p_can_debug, const String &p_reason, bool p_has_stackdump) { - if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { - return; - } - - debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), !(p_breaked && p_can_debug)); - debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), !(p_breaked && p_can_debug)); - debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), p_breaked); - debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), !p_breaked); - - for (int i = 0; i < tab_container->get_child_count(); i++) { - EditorScriptEditorBase *se = Object::cast_to(tab_container->get_child(i)); - if (!se) { - continue; - } - - se->set_debugger_active(p_breaked); - } -} - -void EditorScriptEditor::_show_debugger(bool p_show) { -} - -void EditorScriptEditor::_script_created(Ref