shader_editor_plugin.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /*************************************************************************/
  2. /* shader_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "shader_editor_plugin.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/io/resource_saver.h"
  33. #include "core/os/keyboard.h"
  34. #include "core/os/os.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_settings.h"
  37. #include "editor/property_editor.h"
  38. #include "scene/resources/shader_graph.h"
  39. #include "servers/visual/shader_types.h"
  40. /*** SHADER SCRIPT EDITOR ****/
  41. Ref<Shader> ShaderTextEditor::get_edited_shader() const {
  42. return shader;
  43. }
  44. void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) {
  45. shader = p_shader;
  46. _load_theme_settings();
  47. get_text_edit()->set_text(p_shader->get_code());
  48. _line_col_changed();
  49. }
  50. void ShaderTextEditor::_load_theme_settings() {
  51. get_text_edit()->clear_colors();
  52. Color background_color = EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0));
  53. Color completion_background_color = EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0));
  54. Color completion_selected_color = EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244"));
  55. Color completion_existing_color = EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf"));
  56. Color completion_scroll_color = EDITOR_DEF("text_editor/highlighting/completion_scroll_color", Color::html("ffffff"));
  57. Color completion_font_color = EDITOR_DEF("text_editor/highlighting/completion_font_color", Color::html("aaaaaa"));
  58. Color text_color = EDITOR_DEF("text_editor/highlighting/text_color", Color(0, 0, 0));
  59. Color line_number_color = EDITOR_DEF("text_editor/highlighting/line_number_color", Color(0, 0, 0));
  60. Color caret_color = EDITOR_DEF("text_editor/highlighting/caret_color", Color(0, 0, 0));
  61. Color caret_background_color = EDITOR_DEF("text_editor/highlighting/caret_background_color", Color(0, 0, 0));
  62. Color text_selected_color = EDITOR_DEF("text_editor/highlighting/text_selected_color", Color(1, 1, 1));
  63. Color selection_color = EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1));
  64. Color brace_mismatch_color = EDITOR_DEF("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
  65. Color current_line_color = EDITOR_DEF("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
  66. Color line_length_guideline_color = EDITOR_DEF("text_editor/highlighting/line_length_guideline_color", Color(0, 0, 0));
  67. Color word_highlighted_color = EDITOR_DEF("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
  68. Color number_color = EDITOR_DEF("text_editor/highlighting/number_color", Color(0.9, 0.6, 0.0, 2));
  69. Color function_color = EDITOR_DEF("text_editor/highlighting/function_color", Color(0.4, 0.6, 0.8));
  70. Color member_variable_color = EDITOR_DEF("text_editor/highlighting/member_variable_color", Color(0.9, 0.3, 0.3));
  71. Color mark_color = EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
  72. Color breakpoint_color = EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2));
  73. Color search_result_color = EDITOR_DEF("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  74. Color search_result_border_color = EDITOR_DEF("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1));
  75. Color symbol_color = EDITOR_DEF("text_editor/highlighting/symbol_color", Color::hex(0x005291ff));
  76. Color keyword_color = EDITOR_DEF("text_editor/highlighting/keyword_color", Color(0.5, 0.0, 0.2));
  77. Color basetype_color = EDITOR_DEF("text_editor/highlighting/base_type_color", Color(0.3, 0.3, 0.0));
  78. Color type_color = EDITOR_DEF("text_editor/highlighting/engine_type_color", Color(0.0, 0.2, 0.4));
  79. Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color", Color::hex(0x797e7eff));
  80. Color string_color = EDITOR_DEF("text_editor/highlighting/string_color", Color::hex(0x6b6f00ff));
  81. // Adapt
  82. if (EditorSettings::get_singleton()->get("text_editor/theme/color_theme") == "Adaptive") {
  83. Ref<Theme> tm = EditorNode::get_singleton()->get_theme_base()->get_theme();
  84. symbol_color = tm->get_color("text_editor/theme/symbol_color", "Editor");
  85. keyword_color = tm->get_color("text_editor/theme/keyword_color", "Editor");
  86. basetype_color = tm->get_color("text_editor/theme/basetype_color", "Editor");
  87. type_color = tm->get_color("text_editor/theme/type_color", "Editor");
  88. comment_color = tm->get_color("text_editor/theme/comment_color", "Editor");
  89. string_color = tm->get_color("text_editor/theme/string_color", "Editor");
  90. background_color = tm->get_color("text_editor/theme/background_color", "Editor");
  91. completion_background_color = tm->get_color("text_editor/theme/completion_background_color", "Editor");
  92. completion_selected_color = tm->get_color("text_editor/theme/completion_selected_color", "Editor");
  93. completion_existing_color = tm->get_color("text_editor/theme/completion_existing_color", "Editor");
  94. completion_scroll_color = tm->get_color("text_editor/theme/completion_scroll_color", "Editor");
  95. completion_font_color = tm->get_color("text_editor/theme/completion_font_color", "Editor");
  96. text_color = tm->get_color("text_editor/theme/text_color", "Editor");
  97. line_number_color = tm->get_color("text_editor/theme/line_number_color", "Editor");
  98. caret_color = tm->get_color("text_editor/theme/caret_color", "Editor");
  99. caret_background_color = tm->get_color("text_editor/theme/caret_background_color", "Editor");
  100. text_selected_color = tm->get_color("text_editor/theme/text_selected_color", "Editor");
  101. selection_color = tm->get_color("text_editor/theme/selection_color", "Editor");
  102. brace_mismatch_color = tm->get_color("text_editor/theme/brace_mismatch_color", "Editor");
  103. current_line_color = tm->get_color("text_editor/theme/current_line_color", "Editor");
  104. line_length_guideline_color = tm->get_color("text_editor/theme/line_length_guideline_color", "Editor");
  105. word_highlighted_color = tm->get_color("text_editor/theme/word_highlighted_color", "Editor");
  106. number_color = tm->get_color("text_editor/theme/number_color", "Editor");
  107. function_color = tm->get_color("text_editor/theme/function_color", "Editor");
  108. member_variable_color = tm->get_color("text_editor/theme/member_variable_color", "Editor");
  109. mark_color = tm->get_color("text_editor/theme/mark_color", "Editor");
  110. breakpoint_color = tm->get_color("text_editor/theme/breakpoint_color", "Editor");
  111. search_result_color = tm->get_color("text_editor/theme/search_result_color", "Editor");
  112. search_result_border_color = tm->get_color("text_editor/theme/search_result_border_color", "Editor");
  113. }
  114. get_text_edit()->add_color_override("background_color", background_color);
  115. get_text_edit()->add_color_override("completion_background_color", completion_background_color);
  116. get_text_edit()->add_color_override("completion_selected_color", completion_selected_color);
  117. get_text_edit()->add_color_override("completion_existing_color", completion_existing_color);
  118. get_text_edit()->add_color_override("completion_scroll_color", completion_scroll_color);
  119. get_text_edit()->add_color_override("completion_font_color", completion_font_color);
  120. get_text_edit()->add_color_override("font_color", text_color);
  121. get_text_edit()->add_color_override("line_number_color", line_number_color);
  122. get_text_edit()->add_color_override("caret_color", caret_color);
  123. get_text_edit()->add_color_override("caret_background_color", caret_background_color);
  124. get_text_edit()->add_color_override("font_selected_color", text_selected_color);
  125. get_text_edit()->add_color_override("selection_color", selection_color);
  126. get_text_edit()->add_color_override("brace_mismatch_color", brace_mismatch_color);
  127. get_text_edit()->add_color_override("current_line_color", current_line_color);
  128. get_text_edit()->add_color_override("line_length_guideline_color", line_length_guideline_color);
  129. get_text_edit()->add_color_override("word_highlighted_color", word_highlighted_color);
  130. get_text_edit()->add_color_override("number_color", number_color);
  131. get_text_edit()->add_color_override("function_color", function_color);
  132. get_text_edit()->add_color_override("member_variable_color", member_variable_color);
  133. get_text_edit()->add_color_override("mark_color", mark_color);
  134. get_text_edit()->add_color_override("breakpoint_color", breakpoint_color);
  135. get_text_edit()->add_color_override("search_result_color", search_result_color);
  136. get_text_edit()->add_color_override("search_result_border_color", search_result_border_color);
  137. get_text_edit()->add_color_override("symbol_color", symbol_color);
  138. List<String> keywords;
  139. ShaderLanguage::get_keyword_list(&keywords);
  140. if (shader.is_valid()) {
  141. for (const Map<StringName, ShaderLanguage::FunctionInfo>::Element *E = ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
  142. for (const Map<StringName, ShaderLanguage::DataType>::Element *F = E->get().built_ins.front(); F; F = F->next()) {
  143. keywords.push_back(F->key());
  144. }
  145. }
  146. for (const Set<String>::Element *E = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
  147. keywords.push_back(E->get());
  148. }
  149. }
  150. for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
  151. get_text_edit()->add_keyword_color(E->get(), keyword_color);
  152. }
  153. //colorize core types
  154. //Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));
  155. //colorize comments
  156. get_text_edit()->add_color_region("/*", "*/", comment_color, false);
  157. get_text_edit()->add_color_region("//", "", comment_color, false);
  158. /*//colorize strings
  159. Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
  160. List<String> strings;
  161. shader->get_shader_mode()->get_string_delimiters(&strings);
  162. for (List<String>::Element *E=strings.front();E;E=E->next()) {
  163. String string = E->get();
  164. String beg = string.get_slice(" ",0);
  165. String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String();
  166. get_text_edit()->add_color_region(beg,end,string_color,end=="");
  167. }*/
  168. }
  169. void ShaderTextEditor::_check_shader_mode() {
  170. String type = ShaderLanguage::get_shader_type(get_text_edit()->get_text());
  171. print_line("type is: " + type);
  172. Shader::Mode mode;
  173. if (type == "canvas_item") {
  174. mode = Shader::MODE_CANVAS_ITEM;
  175. } else if (type == "particles") {
  176. mode = Shader::MODE_PARTICLES;
  177. } else {
  178. mode = Shader::MODE_SPATIAL;
  179. }
  180. if (shader->get_mode() != mode) {
  181. shader->set_code(get_text_edit()->get_text());
  182. _load_theme_settings();
  183. }
  184. }
  185. void ShaderTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) {
  186. _check_shader_mode();
  187. ShaderLanguage sl;
  188. String calltip;
  189. Error err = sl.complete(p_code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_types(), r_options, calltip);
  190. if (err != OK)
  191. ERR_PRINT("Shaderlang complete failed");
  192. if (calltip != "") {
  193. get_text_edit()->set_code_hint(calltip);
  194. }
  195. }
  196. void ShaderTextEditor::_validate_script() {
  197. _check_shader_mode();
  198. String code = get_text_edit()->get_text();
  199. //List<StringName> params;
  200. //shader->get_param_list(&params);
  201. ShaderLanguage sl;
  202. Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_types());
  203. if (err != OK) {
  204. String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
  205. set_error(error_text);
  206. get_text_edit()->set_line_as_marked(sl.get_error_line() - 1, true);
  207. } else {
  208. for (int i = 0; i < get_text_edit()->get_line_count(); i++)
  209. get_text_edit()->set_line_as_marked(i, false);
  210. set_error("");
  211. }
  212. emit_signal("script_changed");
  213. }
  214. void ShaderTextEditor::_bind_methods() {
  215. }
  216. ShaderTextEditor::ShaderTextEditor() {
  217. }
  218. /*** SCRIPT EDITOR ******/
  219. void ShaderEditor::_menu_option(int p_option) {
  220. ShaderTextEditor *current = shader_editor;
  221. switch (p_option) {
  222. case EDIT_UNDO: {
  223. current->get_text_edit()->undo();
  224. } break;
  225. case EDIT_REDO: {
  226. current->get_text_edit()->redo();
  227. } break;
  228. case EDIT_CUT: {
  229. current->get_text_edit()->cut();
  230. } break;
  231. case EDIT_COPY: {
  232. current->get_text_edit()->copy();
  233. } break;
  234. case EDIT_PASTE: {
  235. current->get_text_edit()->paste();
  236. } break;
  237. case EDIT_SELECT_ALL: {
  238. current->get_text_edit()->select_all();
  239. } break;
  240. case SEARCH_FIND: {
  241. current->get_find_replace_bar()->popup_search();
  242. } break;
  243. case SEARCH_FIND_NEXT: {
  244. current->get_find_replace_bar()->search_next();
  245. } break;
  246. case SEARCH_FIND_PREV: {
  247. current->get_find_replace_bar()->search_prev();
  248. } break;
  249. case SEARCH_REPLACE: {
  250. current->get_find_replace_bar()->popup_replace();
  251. } break;
  252. case SEARCH_GOTO_LINE: {
  253. goto_line_dialog->popup_find_line(current->get_text_edit());
  254. } break;
  255. }
  256. }
  257. void ShaderEditor::_notification(int p_what) {
  258. if (p_what == NOTIFICATION_ENTER_TREE) {
  259. }
  260. if (p_what == NOTIFICATION_DRAW) {
  261. RID ci = get_canvas_item();
  262. Ref<StyleBox> style = get_stylebox("panel", "Panel");
  263. style->draw(ci, Rect2(Point2(), get_size()));
  264. }
  265. }
  266. void ShaderEditor::_params_changed() {
  267. shader_editor->_validate_script();
  268. }
  269. void ShaderEditor::_editor_settings_changed() {
  270. shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
  271. shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
  272. shader_editor->get_text_edit()->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size"));
  273. shader_editor->get_text_edit()->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type"));
  274. shader_editor->get_text_edit()->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent"));
  275. shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs"));
  276. shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers"));
  277. shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
  278. shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences"));
  279. shader_editor->get_text_edit()->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line"));
  280. shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
  281. shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
  282. shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing"));
  283. shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
  284. shader_editor->get_text_edit()->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/open_scripts/smooth_scrolling"));
  285. shader_editor->get_text_edit()->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/open_scripts/v_scroll_speed"));
  286. }
  287. void ShaderEditor::_bind_methods() {
  288. ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed);
  289. ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option);
  290. ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed);
  291. ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders);
  292. //ClassDB::bind_method("_close_current_tab",&ShaderEditor::_close_current_tab);
  293. }
  294. void ShaderEditor::ensure_select_current() {
  295. /*
  296. if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) {
  297. ShaderTextEditor *ste = Object::cast_to<ShaderTextEditor>(tab_container->get_child(tab_container->get_current_tab()));
  298. if (!ste)
  299. return;
  300. Ref<Shader> shader = ste->get_edited_shader();
  301. get_scene()->get_root_node()->call("_resource_selected",shader);
  302. }*/
  303. }
  304. void ShaderEditor::edit(const Ref<Shader> &p_shader) {
  305. if (p_shader.is_null())
  306. return;
  307. shader = p_shader;
  308. shader_editor->set_edited_shader(p_shader);
  309. //vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
  310. // see if already has it
  311. }
  312. void ShaderEditor::save_external_data() {
  313. if (shader.is_null())
  314. return;
  315. apply_shaders();
  316. if (shader->get_path() != "" && shader->get_path().find("local://") == -1 && shader->get_path().find("::") == -1) {
  317. //external shader, save it
  318. ResourceSaver::save(shader->get_path(), shader);
  319. }
  320. }
  321. void ShaderEditor::apply_shaders() {
  322. if (shader.is_valid()) {
  323. shader->set_code(shader_editor->get_text_edit()->get_text());
  324. shader->set_edited(true);
  325. }
  326. }
  327. ShaderEditor::ShaderEditor() {
  328. HBoxContainer *hbc = memnew(HBoxContainer);
  329. add_child(hbc);
  330. edit_menu = memnew(MenuButton);
  331. hbc->add_child(edit_menu);
  332. edit_menu->set_position(Point2(5, -1));
  333. edit_menu->set_text(TTR("Edit"));
  334. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z), EDIT_UNDO);
  335. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y), EDIT_REDO);
  336. edit_menu->get_popup()->add_separator();
  337. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X), EDIT_CUT);
  338. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C), EDIT_COPY);
  339. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V), EDIT_PASTE);
  340. edit_menu->get_popup()->add_separator();
  341. edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A), EDIT_SELECT_ALL);
  342. edit_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  343. search_menu = memnew(MenuButton);
  344. hbc->add_child(search_menu);
  345. search_menu->set_position(Point2(38, -1));
  346. search_menu->set_text(TTR("Search"));
  347. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), SEARCH_FIND);
  348. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT);
  349. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), SEARCH_FIND_PREV);
  350. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R), SEARCH_REPLACE);
  351. search_menu->get_popup()->add_separator();
  352. //search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K);
  353. search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L), SEARCH_GOTO_LINE);
  354. search_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  355. goto_line_dialog = memnew(GotoLineDialog);
  356. add_child(goto_line_dialog);
  357. shader_editor = memnew(ShaderTextEditor);
  358. add_child(shader_editor);
  359. shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  360. shader_editor->connect("script_changed", this, "apply_shaders");
  361. EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
  362. _editor_settings_changed();
  363. }
  364. void ShaderEditorPlugin::edit(Object *p_object) {
  365. Shader *s = Object::cast_to<Shader>(p_object);
  366. shader_editor->edit(s);
  367. }
  368. bool ShaderEditorPlugin::handles(Object *p_object) const {
  369. Shader *shader = Object::cast_to<Shader>(p_object);
  370. return shader != NULL;
  371. }
  372. void ShaderEditorPlugin::make_visible(bool p_visible) {
  373. if (p_visible) {
  374. button->show();
  375. editor->make_bottom_panel_item_visible(shader_editor);
  376. } else {
  377. button->hide();
  378. if (shader_editor->is_visible_in_tree())
  379. editor->hide_bottom_panel();
  380. shader_editor->apply_shaders();
  381. }
  382. }
  383. void ShaderEditorPlugin::selected_notify() {
  384. shader_editor->ensure_select_current();
  385. }
  386. void ShaderEditorPlugin::save_external_data() {
  387. shader_editor->save_external_data();
  388. }
  389. void ShaderEditorPlugin::apply_changes() {
  390. shader_editor->apply_shaders();
  391. }
  392. ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
  393. editor = p_node;
  394. shader_editor = memnew(ShaderEditor);
  395. shader_editor->set_custom_minimum_size(Size2(0, 300));
  396. button = editor->add_bottom_panel_item(TTR("Shader"), shader_editor);
  397. button->hide();
  398. }
  399. ShaderEditorPlugin::~ShaderEditorPlugin() {
  400. }