shader_create_dialog.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /**************************************************************************/
  2. /* shader_create_dialog.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_create_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/dir_access.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/gui/editor_file_dialog.h"
  35. #include "editor/gui/editor_validation_panel.h"
  36. #include "editor/shader/editor_shader_language_plugin.h"
  37. #include "editor/themes/editor_scale.h"
  38. #include "scene/resources/shader_include.h"
  39. #include "servers/rendering/shader_types.h"
  40. void ShaderCreateDialog::_notification(int p_what) {
  41. switch (p_what) {
  42. case NOTIFICATION_ENTER_TREE: {
  43. current_mode = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_mode", 0);
  44. mode_menu->select(current_mode);
  45. } break;
  46. case NOTIFICATION_THEME_CHANGED: {
  47. path_button->set_button_icon(get_editor_theme_icon(SNAME("Folder")));
  48. // Note that some of the theme logic happens in `config()` when opening the dialog.
  49. } break;
  50. }
  51. }
  52. void ShaderCreateDialog::_refresh_type_icons() {
  53. for (int i = 0; i < type_menu->get_item_count(); i++) {
  54. const String item_name = type_menu->get_item_text(i);
  55. Ref<Texture2D> icon = get_editor_theme_icon(item_name);
  56. if (icon.is_valid()) {
  57. type_menu->set_item_icon(i, icon);
  58. } else {
  59. icon = get_editor_theme_icon("TextFile");
  60. if (icon.is_valid()) {
  61. type_menu->set_item_icon(i, icon);
  62. }
  63. }
  64. }
  65. }
  66. void ShaderCreateDialog::_update_language_info() {
  67. type_data.clear();
  68. for (int i = 0; i < EditorShaderLanguagePlugin::get_shader_language_variation_count(); i++) {
  69. ShaderTypeData shader_type_data;
  70. if (i == 0) {
  71. // HACK: The ShaderCreateDialog class currently only shows templates for text shaders. Generalize this later.
  72. shader_type_data.use_templates = true;
  73. }
  74. shader_type_data.default_extension = EditorShaderLanguagePlugin::get_file_extension_for_index(i);
  75. shader_type_data.extensions.push_back(shader_type_data.default_extension);
  76. if (shader_type_data.default_extension != "tres") {
  77. shader_type_data.extensions.push_back("tres");
  78. }
  79. shader_type_data.extensions.push_back("res");
  80. type_data.push_back(shader_type_data);
  81. }
  82. }
  83. void ShaderCreateDialog::_path_hbox_sorted() {
  84. if (is_visible()) {
  85. int filename_start_pos = initial_base_path.rfind_char('/') + 1;
  86. int filename_end_pos = initial_base_path.length();
  87. if (!is_built_in) {
  88. file_path->select(filename_start_pos, filename_end_pos);
  89. }
  90. file_path->set_caret_column(file_path->get_text().length());
  91. file_path->set_caret_column(filename_start_pos);
  92. file_path->grab_focus();
  93. }
  94. }
  95. void ShaderCreateDialog::_mode_changed(int p_mode) {
  96. current_mode = p_mode;
  97. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_mode", p_mode);
  98. }
  99. void ShaderCreateDialog::_template_changed(int p_template) {
  100. current_template = p_template;
  101. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_template", p_template);
  102. }
  103. void ShaderCreateDialog::ok_pressed() {
  104. if (is_new_shader_created) {
  105. _create_new();
  106. if (built_in_enabled) {
  107. // Only save state of built-in checkbox if it's enabled.
  108. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "create_built_in_shader", internal->is_pressed());
  109. }
  110. } else {
  111. _load_exist();
  112. }
  113. is_new_shader_created = true;
  114. validation_panel->update();
  115. }
  116. void ShaderCreateDialog::_create_new() {
  117. Ref<Resource> shader;
  118. Ref<Resource> shader_inc;
  119. const int type_index = type_menu->get_selected();
  120. Ref<EditorShaderLanguagePlugin> shader_lang = EditorShaderLanguagePlugin::get_shader_language_for_index(type_index);
  121. // A bit of an unfortunate hack because Shader and ShaderInclude do not share a common base class.
  122. // We need duplicate code paths for includes vs non-includes, so just check for the string "Include".
  123. if (type_menu->get_item_text(type_index).contains("Include")) {
  124. shader_inc = shader_lang->create_new_shader_include();
  125. } else {
  126. shader = shader_lang->create_new_shader(0, Shader::Mode(current_mode), current_template);
  127. }
  128. if (shader.is_null()) {
  129. String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
  130. shader_inc->set_path(lpath);
  131. Error error = ResourceSaver::save(shader_inc, lpath, ResourceSaver::FLAG_CHANGE_PATH);
  132. if (error != OK) {
  133. alert->set_text(TTR("Error - Could not create shader include in filesystem."));
  134. alert->popup_centered();
  135. return;
  136. }
  137. emit_signal(SNAME("shader_include_created"), shader_inc);
  138. } else {
  139. if (is_built_in) {
  140. Node *edited_scene = get_tree()->get_edited_scene_root();
  141. if (likely(edited_scene)) {
  142. shader->set_path(edited_scene->get_scene_file_path() + "::" + shader->generate_scene_unique_id());
  143. }
  144. } else {
  145. String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
  146. shader->set_path(lpath);
  147. Error error = ResourceSaver::save(shader, lpath, ResourceSaver::FLAG_CHANGE_PATH);
  148. if (error != OK) {
  149. alert->set_text(TTR("Error - Could not create shader in filesystem."));
  150. alert->popup_centered();
  151. return;
  152. }
  153. }
  154. emit_signal(SNAME("shader_created"), shader);
  155. }
  156. file_path->set_text(file_path->get_text().get_base_dir());
  157. hide();
  158. }
  159. void ShaderCreateDialog::_load_exist() {
  160. String path = file_path->get_text();
  161. Ref<Resource> p_shader = ResourceLoader::load(path, "Shader");
  162. if (p_shader.is_null()) {
  163. alert->set_text(vformat(TTR("Error loading shader from %s"), path));
  164. alert->popup_centered();
  165. return;
  166. }
  167. emit_signal(SNAME("shader_created"), p_shader);
  168. hide();
  169. }
  170. void ShaderCreateDialog::_type_changed(int p_language) {
  171. current_type = p_language;
  172. ShaderTypeData shader_type_data = type_data.get(p_language);
  173. String selected_ext = "." + shader_type_data.default_extension;
  174. String path = file_path->get_text();
  175. String extension = "";
  176. if (!path.is_empty()) {
  177. if (path.contains_char('.')) {
  178. extension = path.get_extension();
  179. }
  180. if (extension.length() == 0) {
  181. path += selected_ext;
  182. } else {
  183. path = path.get_basename() + selected_ext;
  184. }
  185. } else {
  186. path = "shader" + selected_ext;
  187. }
  188. _path_changed(path);
  189. file_path->set_text(path);
  190. mode_menu->set_disabled(false);
  191. for (int i = 0; i < type_menu->get_item_count(); i++) {
  192. const String item_name = type_menu->get_item_text(i);
  193. if (item_name.contains("Include")) {
  194. type_menu->set_item_disabled(i, load_enabled);
  195. if (i == p_language) {
  196. mode_menu->set_disabled(true);
  197. }
  198. } else {
  199. type_menu->set_item_disabled(i, false);
  200. }
  201. }
  202. template_menu->set_disabled(!shader_type_data.use_templates);
  203. template_menu->clear();
  204. if (shader_type_data.use_templates) {
  205. int last_template = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_template", 0);
  206. template_menu->add_item(TTRC("Default"));
  207. template_menu->add_item(TTRC("Empty"));
  208. template_menu->select(last_template);
  209. current_template = last_template;
  210. } else {
  211. template_menu->add_item(TTRC("N/A"));
  212. }
  213. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_language", type_menu->get_item_text(type_menu->get_selected()));
  214. validation_panel->update();
  215. }
  216. void ShaderCreateDialog::_built_in_toggled(bool p_enabled) {
  217. is_built_in = p_enabled;
  218. if (p_enabled) {
  219. is_new_shader_created = true;
  220. } else {
  221. _path_changed(file_path->get_text());
  222. }
  223. validation_panel->update();
  224. }
  225. void ShaderCreateDialog::_browse_path() {
  226. file_browse->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  227. file_browse->set_title(TTR("Open Shader / Choose Location"));
  228. file_browse->set_ok_button_text(TTR("Open"));
  229. file_browse->set_customization_flag_enabled(FileDialog::CUSTOMIZATION_OVERWRITE_WARNING, false);
  230. file_browse->clear_filters();
  231. List<String> extensions = type_data.get(type_menu->get_selected()).extensions;
  232. for (const String &E : extensions) {
  233. file_browse->add_filter("*." + E);
  234. }
  235. file_browse->set_current_path(file_path->get_text());
  236. file_browse->popup_file_dialog();
  237. }
  238. void ShaderCreateDialog::_file_selected(const String &p_file) {
  239. String p = ProjectSettings::get_singleton()->localize_path(p_file);
  240. file_path->set_text(p);
  241. _path_changed(p);
  242. String filename = p.get_file().get_basename();
  243. int select_start = p.rfind(filename);
  244. file_path->select(select_start, select_start + filename.length());
  245. file_path->set_caret_column(select_start + filename.length());
  246. file_path->grab_focus();
  247. }
  248. void ShaderCreateDialog::_path_changed(const String &p_path) {
  249. if (is_built_in) {
  250. return;
  251. }
  252. is_path_valid = false;
  253. is_new_shader_created = true;
  254. path_error = _validate_path(p_path);
  255. if (!path_error.is_empty()) {
  256. validation_panel->update();
  257. return;
  258. }
  259. Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  260. String p = ProjectSettings::get_singleton()->localize_path(p_path.strip_edges());
  261. if (f->file_exists(p)) {
  262. is_new_shader_created = false;
  263. }
  264. is_path_valid = true;
  265. validation_panel->update();
  266. }
  267. void ShaderCreateDialog::_path_submitted(const String &p_path) {
  268. if (!get_ok_button()->is_disabled()) {
  269. ok_pressed();
  270. }
  271. }
  272. void ShaderCreateDialog::config(const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled, const String &p_preferred_type, int p_preferred_mode) {
  273. _update_language_info();
  274. type_menu->clear();
  275. const Vector<Ref<EditorShaderLanguagePlugin>> shader_langs = EditorShaderLanguagePlugin::get_shader_languages_read_only();
  276. ERR_FAIL_COND_MSG(shader_langs.is_empty(), "ShaderCreateDialog: Unable to load any shader languages!");
  277. for (Ref<EditorShaderLanguagePlugin> shader_lang : shader_langs) {
  278. const PackedStringArray variations = shader_lang->get_language_variations();
  279. for (const String &variation : variations) {
  280. type_menu->add_item(variation);
  281. }
  282. }
  283. _refresh_type_icons();
  284. int preferred_type = -1;
  285. // Select preferred type if specified.
  286. for (int i = 0; i < type_menu->get_item_count(); i++) {
  287. if (type_menu->get_item_text(i) == p_preferred_type) {
  288. preferred_type = i;
  289. break;
  290. }
  291. }
  292. if (preferred_type < 0 || preferred_type >= type_menu->get_item_count()) {
  293. preferred_type = 0;
  294. // Select the last selected language if possible, otherwise default to the first language.
  295. String last_lang = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_language", "");
  296. if (!last_lang.is_empty()) {
  297. for (int i = 0; i < type_menu->get_item_count(); i++) {
  298. if (type_menu->get_item_text(i) == last_lang) {
  299. preferred_type = i;
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. type_menu->select(preferred_type);
  306. current_type = 0;
  307. if (!p_base_path.is_empty()) {
  308. initial_base_path = p_base_path.get_basename();
  309. file_path->set_text(initial_base_path + "." + type_data.get(type_menu->get_selected()).default_extension);
  310. current_type = type_menu->get_selected();
  311. } else {
  312. initial_base_path = "";
  313. file_path->set_text("");
  314. }
  315. file_path->deselect();
  316. built_in_enabled = p_built_in_enabled;
  317. load_enabled = p_load_enabled;
  318. if (built_in_enabled) {
  319. internal->set_pressed(EditorSettings::get_singleton()->get_project_metadata("shader_setup", "create_built_in_shader", false));
  320. }
  321. if (p_preferred_mode > -1) {
  322. mode_menu->select(p_preferred_mode);
  323. _mode_changed(p_preferred_mode);
  324. }
  325. _type_changed(current_type);
  326. _path_changed(file_path->get_text());
  327. }
  328. String ShaderCreateDialog::_validate_path(const String &p_path) {
  329. ERR_FAIL_COND_V(current_type >= type_data.size(), TTR("Invalid shader type selected."));
  330. String stripped_file_path = p_path.strip_edges();
  331. if (stripped_file_path.is_empty()) {
  332. return TTR("Path is empty.");
  333. }
  334. if (stripped_file_path.get_file().get_basename().is_empty()) {
  335. return TTR("Filename is empty.");
  336. }
  337. stripped_file_path = ProjectSettings::get_singleton()->localize_path(stripped_file_path);
  338. if (!stripped_file_path.begins_with("res://")) {
  339. return TTR("Path is not local.");
  340. }
  341. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  342. if (d->change_dir(stripped_file_path.get_base_dir()) != OK) {
  343. return TTR("Invalid base path.");
  344. }
  345. Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  346. if (f->dir_exists(stripped_file_path)) {
  347. return TTR("A directory with the same name exists.");
  348. }
  349. const ShaderCreateDialog::ShaderTypeData &current_type_data = type_data.get(current_type);
  350. const String file_extension = stripped_file_path.get_extension();
  351. for (const String &type_ext : current_type_data.extensions) {
  352. if (type_ext.nocasecmp_to(file_extension) == 0) {
  353. return "";
  354. }
  355. }
  356. return TTR("Invalid extension for selected shader type.");
  357. }
  358. void ShaderCreateDialog::_update_dialog() {
  359. if (!is_built_in && !is_path_valid) {
  360. validation_panel->set_message(MSG_ID_SHADER, TTR("Invalid path."), EditorValidationPanel::MSG_ERROR);
  361. }
  362. if (!is_built_in && !path_error.is_empty()) {
  363. validation_panel->set_message(MSG_ID_PATH, path_error, EditorValidationPanel::MSG_ERROR);
  364. } else if (validation_panel->is_valid() && !is_new_shader_created) {
  365. validation_panel->set_message(MSG_ID_SHADER, TTR("File exists, it will be reused."), EditorValidationPanel::MSG_OK);
  366. }
  367. if (!built_in_enabled) {
  368. internal->set_pressed(false);
  369. }
  370. if (is_built_in) {
  371. file_path->set_editable(false);
  372. path_button->set_disabled(true);
  373. re_check_path = true;
  374. } else {
  375. file_path->set_editable(true);
  376. path_button->set_disabled(false);
  377. if (re_check_path) {
  378. re_check_path = false;
  379. _path_changed(file_path->get_text());
  380. }
  381. }
  382. internal->set_disabled(!built_in_enabled);
  383. if (is_built_in) {
  384. validation_panel->set_message(MSG_ID_BUILT_IN, TTR("Note: Built-in shaders can't be edited using an external editor."), EditorValidationPanel::MSG_INFO, false);
  385. }
  386. if (is_built_in) {
  387. set_ok_button_text(TTR("Create"));
  388. validation_panel->set_message(MSG_ID_PATH, TTR("Built-in shader (into scene file)."), EditorValidationPanel::MSG_OK);
  389. } else if (is_new_shader_created) {
  390. set_ok_button_text(TTR("Create"));
  391. } else if (load_enabled) {
  392. set_ok_button_text(TTR("Load"));
  393. if (is_path_valid) {
  394. validation_panel->set_message(MSG_ID_PATH, TTR("Will load an existing shader file."), EditorValidationPanel::MSG_OK);
  395. }
  396. } else {
  397. set_ok_button_text(TTR("Create"));
  398. validation_panel->set_message(MSG_ID_PATH, TTR("Shader file already exists."), EditorValidationPanel::MSG_ERROR);
  399. }
  400. }
  401. void ShaderCreateDialog::_bind_methods() {
  402. ClassDB::bind_method(D_METHOD("config", "path", "built_in_enabled", "load_enabled"), &ShaderCreateDialog::config, DEFVAL(true), DEFVAL(true));
  403. ADD_SIGNAL(MethodInfo("shader_created", PropertyInfo(Variant::OBJECT, "shader", PROPERTY_HINT_RESOURCE_TYPE, "Shader")));
  404. ADD_SIGNAL(MethodInfo("shader_include_created", PropertyInfo(Variant::OBJECT, "shader_include", PROPERTY_HINT_RESOURCE_TYPE, "ShaderInclude")));
  405. }
  406. ShaderCreateDialog::ShaderCreateDialog() {
  407. _update_language_info();
  408. // Main Controls.
  409. gc = memnew(GridContainer);
  410. gc->set_columns(2);
  411. // Error Fields.
  412. validation_panel = memnew(EditorValidationPanel);
  413. validation_panel->add_line(MSG_ID_SHADER, TTR("Shader path/name is valid."));
  414. validation_panel->add_line(MSG_ID_PATH, TTR("Will create a new shader file."));
  415. validation_panel->add_line(MSG_ID_BUILT_IN);
  416. validation_panel->set_update_callback(callable_mp(this, &ShaderCreateDialog::_update_dialog));
  417. validation_panel->set_accept_button(get_ok_button());
  418. // Spacing.
  419. Control *spacing = memnew(Control);
  420. spacing->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
  421. VBoxContainer *vb = memnew(VBoxContainer);
  422. vb->add_child(gc);
  423. vb->add_child(spacing);
  424. vb->add_child(validation_panel);
  425. add_child(vb);
  426. // Type.
  427. type_menu = memnew(OptionButton);
  428. type_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  429. type_menu->set_accessibility_name(TTRC("Type:"));
  430. type_menu->set_custom_minimum_size(Size2(250, 0) * EDSCALE);
  431. type_menu->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  432. gc->add_child(memnew(Label(TTR("Type:"))));
  433. gc->add_child(type_menu);
  434. type_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_type_changed));
  435. // Modes.
  436. mode_menu = memnew(OptionButton);
  437. mode_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  438. mode_menu->set_accessibility_name(TTRC("Mode:"));
  439. for (const String &type_name : ShaderTypes::get_singleton()->get_types_list()) {
  440. mode_menu->add_item(type_name.capitalize());
  441. }
  442. gc->add_child(memnew(Label(TTR("Mode:"))));
  443. gc->add_child(mode_menu);
  444. mode_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_mode_changed));
  445. // Templates.
  446. template_menu = memnew(OptionButton);
  447. template_menu->set_accessibility_name(TTRC("Template:"));
  448. gc->add_child(memnew(Label(TTR("Template:"))));
  449. gc->add_child(template_menu);
  450. template_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_template_changed));
  451. // Built-in Shader.
  452. internal = memnew(CheckBox);
  453. internal->set_text(TTR("On"));
  454. internal->set_accessibility_name(TTRC("Built-in Shader:"));
  455. internal->connect(SceneStringName(toggled), callable_mp(this, &ShaderCreateDialog::_built_in_toggled));
  456. gc->add_child(memnew(Label(TTR("Built-in Shader:"))));
  457. gc->add_child(internal);
  458. // Path.
  459. HBoxContainer *hb = memnew(HBoxContainer);
  460. hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  461. hb->connect(SceneStringName(sort_children), callable_mp(this, &ShaderCreateDialog::_path_hbox_sorted));
  462. file_path = memnew(LineEdit);
  463. file_path->connect(SceneStringName(text_changed), callable_mp(this, &ShaderCreateDialog::_path_changed));
  464. file_path->set_accessibility_name(TTRC("Path:"));
  465. file_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  466. hb->add_child(file_path);
  467. register_text_enter(file_path);
  468. path_button = memnew(Button);
  469. path_button->set_accessibility_name(TTRC("Select"));
  470. path_button->connect(SceneStringName(pressed), callable_mp(this, &ShaderCreateDialog::_browse_path));
  471. hb->add_child(path_button);
  472. gc->add_child(memnew(Label(TTR("Path:"))));
  473. gc->add_child(hb);
  474. // Dialog Setup.
  475. file_browse = memnew(EditorFileDialog);
  476. file_browse->connect("file_selected", callable_mp(this, &ShaderCreateDialog::_file_selected));
  477. file_browse->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  478. add_child(file_browse);
  479. alert = memnew(AcceptDialog);
  480. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  481. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  482. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  483. alert->get_label()->set_custom_minimum_size(Size2(325, 60) * EDSCALE);
  484. add_child(alert);
  485. set_ok_button_text(TTR("Create"));
  486. set_hide_on_ok(false);
  487. set_title(TTR("Create Shader"));
  488. }