2
0

theme_editor_plugin.cpp 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799
  1. /*************************************************************************/
  2. /* theme_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "theme_editor_plugin.h"
  31. #include "core/os/keyboard.h"
  32. #include "editor/editor_file_dialog.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_resource_picker.h"
  35. #include "editor/editor_scale.h"
  36. #include "editor/editor_undo_redo_manager.h"
  37. #include "editor/progress_dialog.h"
  38. #include "scene/gui/color_picker.h"
  39. #include "scene/theme/theme_db.h"
  40. void ThemeItemImportTree::_update_items_tree() {
  41. import_items_tree->clear();
  42. TreeItem *root = import_items_tree->create_item();
  43. if (base_theme.is_null()) {
  44. return;
  45. }
  46. String filter_text = import_items_filter->get_text();
  47. List<StringName> types;
  48. List<StringName> names;
  49. List<StringName> filtered_names;
  50. base_theme->get_type_list(&types);
  51. types.sort_custom<StringName::AlphCompare>();
  52. int color_amount = 0;
  53. int constant_amount = 0;
  54. int font_amount = 0;
  55. int font_size_amount = 0;
  56. int icon_amount = 0;
  57. int stylebox_amount = 0;
  58. tree_color_items.clear();
  59. tree_constant_items.clear();
  60. tree_font_items.clear();
  61. tree_font_size_items.clear();
  62. tree_icon_items.clear();
  63. tree_stylebox_items.clear();
  64. for (const StringName &E : types) {
  65. String type_name = (String)E;
  66. Ref<Texture2D> type_icon;
  67. if (E == "") {
  68. type_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons"));
  69. } else {
  70. type_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled");
  71. }
  72. TreeItem *type_node = import_items_tree->create_item(root);
  73. type_node->set_meta("_can_be_imported", false);
  74. type_node->set_collapsed(true);
  75. type_node->set_icon(0, type_icon);
  76. type_node->set_text(0, type_name);
  77. type_node->set_cell_mode(IMPORT_ITEM, TreeItem::CELL_MODE_CHECK);
  78. type_node->set_checked(IMPORT_ITEM, false);
  79. type_node->set_editable(IMPORT_ITEM, true);
  80. type_node->set_cell_mode(IMPORT_ITEM_DATA, TreeItem::CELL_MODE_CHECK);
  81. type_node->set_checked(IMPORT_ITEM_DATA, false);
  82. type_node->set_editable(IMPORT_ITEM_DATA, true);
  83. bool is_matching_filter = (filter_text.is_empty() || type_name.findn(filter_text) > -1);
  84. bool has_filtered_items = false;
  85. for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
  86. Theme::DataType dt = (Theme::DataType)i;
  87. names.clear();
  88. filtered_names.clear();
  89. base_theme->get_theme_item_list(dt, E, &names);
  90. bool data_type_has_filtered_items = false;
  91. for (const StringName &F : names) {
  92. String item_name = (String)F;
  93. bool is_item_matching_filter = (item_name.findn(filter_text) > -1);
  94. if (!filter_text.is_empty() && !is_matching_filter && !is_item_matching_filter) {
  95. continue;
  96. }
  97. // Only mark this if actual items match the filter and not just the type group.
  98. if (!filter_text.is_empty() && is_item_matching_filter) {
  99. has_filtered_items = true;
  100. data_type_has_filtered_items = true;
  101. }
  102. filtered_names.push_back(F);
  103. }
  104. if (filtered_names.size() == 0) {
  105. continue;
  106. }
  107. TreeItem *data_type_node = import_items_tree->create_item(type_node);
  108. data_type_node->set_meta("_can_be_imported", false);
  109. data_type_node->set_metadata(0, i);
  110. data_type_node->set_collapsed(!data_type_has_filtered_items);
  111. data_type_node->set_cell_mode(IMPORT_ITEM, TreeItem::CELL_MODE_CHECK);
  112. data_type_node->set_checked(IMPORT_ITEM, false);
  113. data_type_node->set_editable(IMPORT_ITEM, true);
  114. data_type_node->set_cell_mode(IMPORT_ITEM_DATA, TreeItem::CELL_MODE_CHECK);
  115. data_type_node->set_checked(IMPORT_ITEM_DATA, false);
  116. data_type_node->set_editable(IMPORT_ITEM_DATA, true);
  117. List<TreeItem *> *item_list;
  118. switch (dt) {
  119. case Theme::DATA_TYPE_COLOR:
  120. data_type_node->set_icon(0, get_theme_icon(SNAME("Color"), SNAME("EditorIcons")));
  121. data_type_node->set_text(0, TTR("Colors"));
  122. item_list = &tree_color_items;
  123. color_amount += filtered_names.size();
  124. break;
  125. case Theme::DATA_TYPE_CONSTANT:
  126. data_type_node->set_icon(0, get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")));
  127. data_type_node->set_text(0, TTR("Constants"));
  128. item_list = &tree_constant_items;
  129. constant_amount += filtered_names.size();
  130. break;
  131. case Theme::DATA_TYPE_FONT:
  132. data_type_node->set_icon(0, get_theme_icon(SNAME("Font"), SNAME("EditorIcons")));
  133. data_type_node->set_text(0, TTR("Fonts"));
  134. item_list = &tree_font_items;
  135. font_amount += filtered_names.size();
  136. break;
  137. case Theme::DATA_TYPE_FONT_SIZE:
  138. data_type_node->set_icon(0, get_theme_icon(SNAME("FontSize"), SNAME("EditorIcons")));
  139. data_type_node->set_text(0, TTR("Font Sizes"));
  140. item_list = &tree_font_size_items;
  141. font_size_amount += filtered_names.size();
  142. break;
  143. case Theme::DATA_TYPE_ICON:
  144. data_type_node->set_icon(0, get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")));
  145. data_type_node->set_text(0, TTR("Icons"));
  146. item_list = &tree_icon_items;
  147. icon_amount += filtered_names.size();
  148. break;
  149. case Theme::DATA_TYPE_STYLEBOX:
  150. data_type_node->set_icon(0, get_theme_icon(SNAME("StyleBoxFlat"), SNAME("EditorIcons")));
  151. data_type_node->set_text(0, TTR("Styleboxes"));
  152. item_list = &tree_stylebox_items;
  153. stylebox_amount += filtered_names.size();
  154. break;
  155. case Theme::DATA_TYPE_MAX:
  156. break; // Can't happen, but silences warning.
  157. }
  158. filtered_names.sort_custom<StringName::AlphCompare>();
  159. for (const StringName &F : filtered_names) {
  160. TreeItem *item_node = import_items_tree->create_item(data_type_node);
  161. item_node->set_meta("_can_be_imported", true);
  162. item_node->set_text(0, F);
  163. item_node->set_cell_mode(IMPORT_ITEM, TreeItem::CELL_MODE_CHECK);
  164. item_node->set_checked(IMPORT_ITEM, false);
  165. item_node->set_editable(IMPORT_ITEM, true);
  166. item_node->set_cell_mode(IMPORT_ITEM_DATA, TreeItem::CELL_MODE_CHECK);
  167. item_node->set_checked(IMPORT_ITEM_DATA, false);
  168. item_node->set_editable(IMPORT_ITEM_DATA, true);
  169. _restore_selected_item(item_node);
  170. item_node->propagate_check(IMPORT_ITEM, false);
  171. item_node->propagate_check(IMPORT_ITEM_DATA, false);
  172. item_list->push_back(item_node);
  173. }
  174. }
  175. // Remove the item if it doesn't match the filter in any way.
  176. if (!is_matching_filter && !has_filtered_items) {
  177. root->remove_child(type_node);
  178. memdelete(type_node);
  179. continue;
  180. }
  181. // Show one level inside of a type group if there are matches in items.
  182. if (!filter_text.is_empty() && has_filtered_items) {
  183. type_node->set_collapsed(false);
  184. }
  185. }
  186. if (color_amount > 0) {
  187. Array arr;
  188. arr.push_back(color_amount);
  189. select_colors_label->set_text(TTRN("1 color", "{num} colors", color_amount).format(arr, "{num}"));
  190. select_all_colors_button->set_visible(true);
  191. select_full_colors_button->set_visible(true);
  192. deselect_all_colors_button->set_visible(true);
  193. } else {
  194. select_colors_label->set_text(TTR("No colors found."));
  195. select_all_colors_button->set_visible(false);
  196. select_full_colors_button->set_visible(false);
  197. deselect_all_colors_button->set_visible(false);
  198. }
  199. if (constant_amount > 0) {
  200. Array arr;
  201. arr.push_back(constant_amount);
  202. select_constants_label->set_text(TTRN("1 constant", "{num} constants", constant_amount).format(arr, "{num}"));
  203. select_all_constants_button->set_visible(true);
  204. select_full_constants_button->set_visible(true);
  205. deselect_all_constants_button->set_visible(true);
  206. } else {
  207. select_constants_label->set_text(TTR("No constants found."));
  208. select_all_constants_button->set_visible(false);
  209. select_full_constants_button->set_visible(false);
  210. deselect_all_constants_button->set_visible(false);
  211. }
  212. if (font_amount > 0) {
  213. Array arr;
  214. arr.push_back(font_amount);
  215. select_fonts_label->set_text(TTRN("1 font", "{num} fonts", font_amount).format(arr, "{num}"));
  216. select_all_fonts_button->set_visible(true);
  217. select_full_fonts_button->set_visible(true);
  218. deselect_all_fonts_button->set_visible(true);
  219. } else {
  220. select_fonts_label->set_text(TTR("No fonts found."));
  221. select_all_fonts_button->set_visible(false);
  222. select_full_fonts_button->set_visible(false);
  223. deselect_all_fonts_button->set_visible(false);
  224. }
  225. if (font_size_amount > 0) {
  226. Array arr;
  227. arr.push_back(font_size_amount);
  228. select_font_sizes_label->set_text(TTRN("1 font size", "{num} font sizes", font_size_amount).format(arr, "{num}"));
  229. select_all_font_sizes_button->set_visible(true);
  230. select_full_font_sizes_button->set_visible(true);
  231. deselect_all_font_sizes_button->set_visible(true);
  232. } else {
  233. select_font_sizes_label->set_text(TTR("No font sizes found."));
  234. select_all_font_sizes_button->set_visible(false);
  235. select_full_font_sizes_button->set_visible(false);
  236. deselect_all_font_sizes_button->set_visible(false);
  237. }
  238. if (icon_amount > 0) {
  239. Array arr;
  240. arr.push_back(icon_amount);
  241. select_icons_label->set_text(TTRN("1 icon", "{num} icons", icon_amount).format(arr, "{num}"));
  242. select_all_icons_button->set_visible(true);
  243. select_full_icons_button->set_visible(true);
  244. deselect_all_icons_button->set_visible(true);
  245. select_icons_warning_hb->set_visible(true);
  246. } else {
  247. select_icons_label->set_text(TTR("No icons found."));
  248. select_all_icons_button->set_visible(false);
  249. select_full_icons_button->set_visible(false);
  250. deselect_all_icons_button->set_visible(false);
  251. select_icons_warning_hb->set_visible(false);
  252. }
  253. if (stylebox_amount > 0) {
  254. Array arr;
  255. arr.push_back(stylebox_amount);
  256. select_styleboxes_label->set_text(TTRN("1 stylebox", "{num} styleboxes", stylebox_amount).format(arr, "{num}"));
  257. select_all_styleboxes_button->set_visible(true);
  258. select_full_styleboxes_button->set_visible(true);
  259. deselect_all_styleboxes_button->set_visible(true);
  260. } else {
  261. select_styleboxes_label->set_text(TTR("No styleboxes found."));
  262. select_all_styleboxes_button->set_visible(false);
  263. select_full_styleboxes_button->set_visible(false);
  264. deselect_all_styleboxes_button->set_visible(false);
  265. }
  266. }
  267. void ThemeItemImportTree::_toggle_type_items(bool p_collapse) {
  268. TreeItem *root = import_items_tree->get_root();
  269. if (!root) {
  270. return;
  271. }
  272. TreeItem *type_node = root->get_first_child();
  273. while (type_node) {
  274. type_node->set_collapsed(p_collapse);
  275. type_node = type_node->get_next();
  276. }
  277. }
  278. void ThemeItemImportTree::_filter_text_changed(const String &p_value) {
  279. _update_items_tree();
  280. }
  281. void ThemeItemImportTree::_store_selected_item(TreeItem *p_tree_item) {
  282. if (!p_tree_item->get_meta("_can_be_imported")) {
  283. return;
  284. }
  285. TreeItem *data_type_node = p_tree_item->get_parent();
  286. if (!data_type_node || data_type_node == import_items_tree->get_root()) {
  287. return;
  288. }
  289. TreeItem *type_node = data_type_node->get_parent();
  290. if (!type_node || type_node == import_items_tree->get_root()) {
  291. return;
  292. }
  293. ThemeItem ti;
  294. ti.item_name = p_tree_item->get_text(0);
  295. ti.data_type = (Theme::DataType)(int)data_type_node->get_metadata(0);
  296. ti.type_name = type_node->get_text(0);
  297. bool import = p_tree_item->is_checked(IMPORT_ITEM);
  298. bool with_data = p_tree_item->is_checked(IMPORT_ITEM_DATA);
  299. if (import && with_data) {
  300. selected_items[ti] = SELECT_IMPORT_FULL;
  301. } else if (import) {
  302. selected_items[ti] = SELECT_IMPORT_DEFINITION;
  303. } else {
  304. selected_items.erase(ti);
  305. }
  306. _update_total_selected(ti.data_type);
  307. }
  308. void ThemeItemImportTree::_restore_selected_item(TreeItem *p_tree_item) {
  309. if (!p_tree_item->get_meta("_can_be_imported")) {
  310. return;
  311. }
  312. TreeItem *data_type_node = p_tree_item->get_parent();
  313. if (!data_type_node || data_type_node == import_items_tree->get_root()) {
  314. return;
  315. }
  316. TreeItem *type_node = data_type_node->get_parent();
  317. if (!type_node || type_node == import_items_tree->get_root()) {
  318. return;
  319. }
  320. ThemeItem ti;
  321. ti.item_name = p_tree_item->get_text(0);
  322. ti.data_type = (Theme::DataType)(int)data_type_node->get_metadata(0);
  323. ti.type_name = type_node->get_text(0);
  324. if (!selected_items.has(ti)) {
  325. p_tree_item->set_checked(IMPORT_ITEM, false);
  326. p_tree_item->set_checked(IMPORT_ITEM_DATA, false);
  327. return;
  328. }
  329. if (selected_items[ti] == SELECT_IMPORT_FULL) {
  330. p_tree_item->set_checked(IMPORT_ITEM, true);
  331. p_tree_item->set_checked(IMPORT_ITEM_DATA, true);
  332. } else if (selected_items[ti] == SELECT_IMPORT_DEFINITION) {
  333. p_tree_item->set_checked(IMPORT_ITEM, true);
  334. p_tree_item->set_checked(IMPORT_ITEM_DATA, false);
  335. }
  336. }
  337. void ThemeItemImportTree::_update_total_selected(Theme::DataType p_data_type) {
  338. ERR_FAIL_INDEX_MSG(p_data_type, Theme::DATA_TYPE_MAX, "Theme item data type is out of bounds.");
  339. Label *total_selected_items_label;
  340. switch (p_data_type) {
  341. case Theme::DATA_TYPE_COLOR:
  342. total_selected_items_label = total_selected_colors_label;
  343. break;
  344. case Theme::DATA_TYPE_CONSTANT:
  345. total_selected_items_label = total_selected_constants_label;
  346. break;
  347. case Theme::DATA_TYPE_FONT:
  348. total_selected_items_label = total_selected_fonts_label;
  349. break;
  350. case Theme::DATA_TYPE_FONT_SIZE:
  351. total_selected_items_label = total_selected_font_sizes_label;
  352. break;
  353. case Theme::DATA_TYPE_ICON:
  354. total_selected_items_label = total_selected_icons_label;
  355. break;
  356. case Theme::DATA_TYPE_STYLEBOX:
  357. total_selected_items_label = total_selected_styleboxes_label;
  358. break;
  359. case Theme::DATA_TYPE_MAX:
  360. return; // Can't happen, but silences warning.
  361. }
  362. if (!total_selected_items_label) {
  363. return;
  364. }
  365. int count = 0;
  366. for (const KeyValue<ThemeItem, ItemCheckedState> &E : selected_items) {
  367. ThemeItem ti = E.key;
  368. if (ti.data_type == p_data_type) {
  369. count++;
  370. }
  371. }
  372. if (count == 0) {
  373. total_selected_items_label->hide();
  374. } else {
  375. Array arr;
  376. arr.push_back(count);
  377. total_selected_items_label->set_text(TTRN("{num} currently selected", "{num} currently selected", count).format(arr, "{num}"));
  378. total_selected_items_label->show();
  379. }
  380. }
  381. void ThemeItemImportTree::_tree_item_edited() {
  382. if (updating_tree) {
  383. return;
  384. }
  385. TreeItem *edited_item = import_items_tree->get_edited();
  386. if (!edited_item) {
  387. return;
  388. }
  389. updating_tree = true;
  390. int edited_column = import_items_tree->get_edited_column();
  391. bool is_checked = edited_item->is_checked(edited_column);
  392. if (is_checked) {
  393. if (edited_column == IMPORT_ITEM_DATA) {
  394. edited_item->set_checked(IMPORT_ITEM, true);
  395. edited_item->propagate_check(IMPORT_ITEM);
  396. }
  397. } else {
  398. if (edited_column == IMPORT_ITEM) {
  399. edited_item->set_checked(IMPORT_ITEM_DATA, false);
  400. edited_item->propagate_check(IMPORT_ITEM_DATA);
  401. }
  402. }
  403. edited_item->propagate_check(edited_column);
  404. updating_tree = false;
  405. }
  406. void ThemeItemImportTree::_check_propagated_to_tree_item(Object *p_obj, int p_column) {
  407. TreeItem *item = Object::cast_to<TreeItem>(p_obj);
  408. // Skip "category" tree items by checking for children.
  409. if (item && !item->get_first_child()) {
  410. _store_selected_item(item);
  411. }
  412. }
  413. void ThemeItemImportTree::_select_all_subitems(TreeItem *p_root_item, bool p_select_with_data) {
  414. TreeItem *child_item = p_root_item->get_first_child();
  415. while (child_item) {
  416. child_item->set_checked(IMPORT_ITEM, true);
  417. if (p_select_with_data) {
  418. child_item->set_checked(IMPORT_ITEM_DATA, true);
  419. }
  420. _store_selected_item(child_item);
  421. _select_all_subitems(child_item, p_select_with_data);
  422. child_item = child_item->get_next();
  423. }
  424. }
  425. void ThemeItemImportTree::_deselect_all_subitems(TreeItem *p_root_item, bool p_deselect_completely) {
  426. TreeItem *child_item = p_root_item->get_first_child();
  427. while (child_item) {
  428. child_item->set_checked(IMPORT_ITEM_DATA, false);
  429. if (p_deselect_completely) {
  430. child_item->set_checked(IMPORT_ITEM, false);
  431. }
  432. _store_selected_item(child_item);
  433. _deselect_all_subitems(child_item, p_deselect_completely);
  434. child_item = child_item->get_next();
  435. }
  436. }
  437. void ThemeItemImportTree::_select_all_items_pressed() {
  438. if (updating_tree) {
  439. return;
  440. }
  441. updating_tree = true;
  442. TreeItem *root = import_items_tree->get_root();
  443. _select_all_subitems(root, false);
  444. updating_tree = false;
  445. }
  446. void ThemeItemImportTree::_select_full_items_pressed() {
  447. if (updating_tree) {
  448. return;
  449. }
  450. updating_tree = true;
  451. TreeItem *root = import_items_tree->get_root();
  452. _select_all_subitems(root, true);
  453. updating_tree = false;
  454. }
  455. void ThemeItemImportTree::_deselect_all_items_pressed() {
  456. if (updating_tree) {
  457. return;
  458. }
  459. updating_tree = true;
  460. TreeItem *root = import_items_tree->get_root();
  461. _deselect_all_subitems(root, true);
  462. updating_tree = false;
  463. }
  464. void ThemeItemImportTree::_select_all_data_type_pressed(int p_data_type) {
  465. ERR_FAIL_INDEX_MSG(p_data_type, Theme::DATA_TYPE_MAX, "Theme item data type is out of bounds.");
  466. if (updating_tree) {
  467. return;
  468. }
  469. Theme::DataType data_type = (Theme::DataType)p_data_type;
  470. List<TreeItem *> *item_list;
  471. switch (data_type) {
  472. case Theme::DATA_TYPE_COLOR:
  473. item_list = &tree_color_items;
  474. break;
  475. case Theme::DATA_TYPE_CONSTANT:
  476. item_list = &tree_constant_items;
  477. break;
  478. case Theme::DATA_TYPE_FONT:
  479. item_list = &tree_font_items;
  480. break;
  481. case Theme::DATA_TYPE_FONT_SIZE:
  482. item_list = &tree_font_size_items;
  483. break;
  484. case Theme::DATA_TYPE_ICON:
  485. item_list = &tree_icon_items;
  486. break;
  487. case Theme::DATA_TYPE_STYLEBOX:
  488. item_list = &tree_stylebox_items;
  489. break;
  490. case Theme::DATA_TYPE_MAX:
  491. return; // Can't happen, but silences warning.
  492. }
  493. updating_tree = true;
  494. for (List<TreeItem *>::Element *E = item_list->front(); E; E = E->next()) {
  495. TreeItem *child_item = E->get();
  496. if (!child_item) {
  497. continue;
  498. }
  499. child_item->set_checked(IMPORT_ITEM, true);
  500. child_item->propagate_check(IMPORT_ITEM, false);
  501. _store_selected_item(child_item);
  502. }
  503. updating_tree = false;
  504. }
  505. void ThemeItemImportTree::_select_full_data_type_pressed(int p_data_type) {
  506. ERR_FAIL_INDEX_MSG(p_data_type, Theme::DATA_TYPE_MAX, "Theme item data type is out of bounds.");
  507. if (updating_tree) {
  508. return;
  509. }
  510. Theme::DataType data_type = (Theme::DataType)p_data_type;
  511. List<TreeItem *> *item_list;
  512. switch (data_type) {
  513. case Theme::DATA_TYPE_COLOR:
  514. item_list = &tree_color_items;
  515. break;
  516. case Theme::DATA_TYPE_CONSTANT:
  517. item_list = &tree_constant_items;
  518. break;
  519. case Theme::DATA_TYPE_FONT:
  520. item_list = &tree_font_items;
  521. break;
  522. case Theme::DATA_TYPE_FONT_SIZE:
  523. item_list = &tree_font_size_items;
  524. break;
  525. case Theme::DATA_TYPE_ICON:
  526. item_list = &tree_icon_items;
  527. break;
  528. case Theme::DATA_TYPE_STYLEBOX:
  529. item_list = &tree_stylebox_items;
  530. break;
  531. case Theme::DATA_TYPE_MAX:
  532. return; // Can't happen, but silences warning.
  533. }
  534. updating_tree = true;
  535. for (List<TreeItem *>::Element *E = item_list->front(); E; E = E->next()) {
  536. TreeItem *child_item = E->get();
  537. if (!child_item) {
  538. continue;
  539. }
  540. child_item->set_checked(IMPORT_ITEM, true);
  541. child_item->set_checked(IMPORT_ITEM_DATA, true);
  542. child_item->propagate_check(IMPORT_ITEM, false);
  543. child_item->propagate_check(IMPORT_ITEM_DATA, false);
  544. _store_selected_item(child_item);
  545. }
  546. updating_tree = false;
  547. }
  548. void ThemeItemImportTree::_deselect_all_data_type_pressed(int p_data_type) {
  549. ERR_FAIL_INDEX_MSG(p_data_type, Theme::DATA_TYPE_MAX, "Theme item data type is out of bounds.");
  550. if (updating_tree) {
  551. return;
  552. }
  553. Theme::DataType data_type = (Theme::DataType)p_data_type;
  554. List<TreeItem *> *item_list;
  555. switch (data_type) {
  556. case Theme::DATA_TYPE_COLOR:
  557. item_list = &tree_color_items;
  558. break;
  559. case Theme::DATA_TYPE_CONSTANT:
  560. item_list = &tree_constant_items;
  561. break;
  562. case Theme::DATA_TYPE_FONT:
  563. item_list = &tree_font_items;
  564. break;
  565. case Theme::DATA_TYPE_FONT_SIZE:
  566. item_list = &tree_font_size_items;
  567. break;
  568. case Theme::DATA_TYPE_ICON:
  569. item_list = &tree_icon_items;
  570. break;
  571. case Theme::DATA_TYPE_STYLEBOX:
  572. item_list = &tree_stylebox_items;
  573. break;
  574. case Theme::DATA_TYPE_MAX:
  575. return; // Can't happen, but silences warning.
  576. }
  577. updating_tree = true;
  578. for (List<TreeItem *>::Element *E = item_list->front(); E; E = E->next()) {
  579. TreeItem *child_item = E->get();
  580. if (!child_item) {
  581. continue;
  582. }
  583. child_item->set_checked(IMPORT_ITEM, false);
  584. child_item->set_checked(IMPORT_ITEM_DATA, false);
  585. child_item->propagate_check(IMPORT_ITEM, false);
  586. child_item->propagate_check(IMPORT_ITEM_DATA, false);
  587. _store_selected_item(child_item);
  588. }
  589. updating_tree = false;
  590. }
  591. void ThemeItemImportTree::_import_selected() {
  592. if (selected_items.size() == 0) {
  593. EditorNode::get_singleton()->show_accept(TTR("Nothing was selected for the import."), TTR("OK"));
  594. return;
  595. }
  596. Ref<Theme> old_snapshot = edited_theme->duplicate();
  597. Ref<Theme> new_snapshot = edited_theme->duplicate();
  598. ProgressDialog::get_singleton()->add_task("import_theme_items", TTR("Importing Theme Items"), selected_items.size() + 2);
  599. int idx = 0;
  600. for (KeyValue<ThemeItem, ItemCheckedState> &E : selected_items) {
  601. // Arbitrary number of items to skip from reporting.
  602. // Reduces the number of UI updates that this causes when copying large themes.
  603. if (idx % 10 == 0) {
  604. Array arr;
  605. arr.push_back(idx + 1);
  606. arr.push_back(selected_items.size());
  607. ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Importing items {n}/{n}").format(arr, "{n}"), idx);
  608. }
  609. ItemCheckedState cs = E.value;
  610. ThemeItem ti = E.key;
  611. if (cs == SELECT_IMPORT_DEFINITION || cs == SELECT_IMPORT_FULL) {
  612. Variant item_value = Variant();
  613. if (cs == SELECT_IMPORT_FULL) {
  614. item_value = base_theme->get_theme_item(ti.data_type, ti.item_name, ti.type_name);
  615. } else {
  616. switch (ti.data_type) {
  617. case Theme::DATA_TYPE_COLOR:
  618. item_value = Color();
  619. break;
  620. case Theme::DATA_TYPE_CONSTANT:
  621. item_value = 0;
  622. break;
  623. case Theme::DATA_TYPE_FONT:
  624. item_value = Ref<Font>();
  625. break;
  626. case Theme::DATA_TYPE_FONT_SIZE:
  627. item_value = -1;
  628. break;
  629. case Theme::DATA_TYPE_ICON:
  630. item_value = Ref<Texture2D>();
  631. break;
  632. case Theme::DATA_TYPE_STYLEBOX:
  633. item_value = Ref<StyleBox>();
  634. break;
  635. case Theme::DATA_TYPE_MAX:
  636. break; // Can't happen, but silences warning.
  637. }
  638. }
  639. new_snapshot->set_theme_item(ti.data_type, ti.item_name, ti.type_name, item_value);
  640. }
  641. idx++;
  642. }
  643. // Allow changes to be reported now that the operation is finished.
  644. ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Updating the editor"), idx++);
  645. // Make sure the task is not ended before the editor freezes to update the Inspector.
  646. ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Finalizing"), idx++);
  647. ProgressDialog::get_singleton()->end_task("import_theme_items");
  648. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  649. ur->create_action(TTR("Import Theme Items"));
  650. ur->add_do_method(*edited_theme, "clear");
  651. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  652. ur->add_undo_method(*edited_theme, "clear");
  653. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  654. ur->add_do_method(this, "emit_signal", SNAME("items_imported"));
  655. ur->add_undo_method(this, "emit_signal", SNAME("items_imported"));
  656. ur->commit_action();
  657. }
  658. void ThemeItemImportTree::set_edited_theme(const Ref<Theme> &p_theme) {
  659. edited_theme = p_theme;
  660. }
  661. void ThemeItemImportTree::set_base_theme(const Ref<Theme> &p_theme) {
  662. base_theme = p_theme;
  663. }
  664. void ThemeItemImportTree::reset_item_tree() {
  665. import_items_filter->clear();
  666. selected_items.clear();
  667. total_selected_colors_label->hide();
  668. total_selected_constants_label->hide();
  669. total_selected_fonts_label->hide();
  670. total_selected_font_sizes_label->hide();
  671. total_selected_icons_label->hide();
  672. total_selected_styleboxes_label->hide();
  673. _update_items_tree();
  674. }
  675. bool ThemeItemImportTree::has_selected_items() const {
  676. return (selected_items.size() > 0);
  677. }
  678. void ThemeItemImportTree::_notification(int p_what) {
  679. switch (p_what) {
  680. case NOTIFICATION_ENTER_TREE:
  681. case NOTIFICATION_THEME_CHANGED: {
  682. select_icons_warning_icon->set_texture(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
  683. select_icons_warning->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
  684. import_items_filter->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  685. // Bottom panel buttons.
  686. import_collapse_types_button->set_icon(get_theme_icon(SNAME("CollapseTree"), SNAME("EditorIcons")));
  687. import_expand_types_button->set_icon(get_theme_icon(SNAME("ExpandTree"), SNAME("EditorIcons")));
  688. import_select_all_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  689. import_select_full_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  690. import_deselect_all_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  691. // Side panel buttons.
  692. select_colors_icon->set_texture(get_theme_icon(SNAME("Color"), SNAME("EditorIcons")));
  693. deselect_all_colors_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  694. select_all_colors_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  695. select_full_colors_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  696. select_constants_icon->set_texture(get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")));
  697. deselect_all_constants_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  698. select_all_constants_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  699. select_full_constants_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  700. select_fonts_icon->set_texture(get_theme_icon(SNAME("Font"), SNAME("EditorIcons")));
  701. deselect_all_fonts_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  702. select_all_fonts_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  703. select_full_fonts_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  704. select_font_sizes_icon->set_texture(get_theme_icon(SNAME("FontSize"), SNAME("EditorIcons")));
  705. deselect_all_font_sizes_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  706. select_all_font_sizes_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  707. select_full_font_sizes_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  708. select_icons_icon->set_texture(get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")));
  709. deselect_all_icons_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  710. select_all_icons_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  711. select_full_icons_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  712. select_styleboxes_icon->set_texture(get_theme_icon(SNAME("StyleBoxFlat"), SNAME("EditorIcons")));
  713. deselect_all_styleboxes_button->set_icon(get_theme_icon(SNAME("ThemeDeselectAll"), SNAME("EditorIcons")));
  714. select_all_styleboxes_button->set_icon(get_theme_icon(SNAME("ThemeSelectAll"), SNAME("EditorIcons")));
  715. select_full_styleboxes_button->set_icon(get_theme_icon(SNAME("ThemeSelectFull"), SNAME("EditorIcons")));
  716. } break;
  717. }
  718. }
  719. void ThemeItemImportTree::_bind_methods() {
  720. ADD_SIGNAL(MethodInfo("items_imported"));
  721. }
  722. ThemeItemImportTree::ThemeItemImportTree() {
  723. import_items_filter = memnew(LineEdit);
  724. import_items_filter->set_placeholder(TTR("Filter Items"));
  725. import_items_filter->set_clear_button_enabled(true);
  726. add_child(import_items_filter);
  727. import_items_filter->connect("text_changed", callable_mp(this, &ThemeItemImportTree::_filter_text_changed));
  728. HBoxContainer *import_main_hb = memnew(HBoxContainer);
  729. import_main_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  730. add_child(import_main_hb);
  731. import_items_tree = memnew(Tree);
  732. import_items_tree->set_hide_root(true);
  733. import_items_tree->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  734. import_main_hb->add_child(import_items_tree);
  735. import_items_tree->connect("item_edited", callable_mp(this, &ThemeItemImportTree::_tree_item_edited));
  736. import_items_tree->connect("check_propagated_to_item", callable_mp(this, &ThemeItemImportTree::_check_propagated_to_tree_item));
  737. import_items_tree->set_columns(3);
  738. import_items_tree->set_column_titles_visible(true);
  739. import_items_tree->set_column_title(IMPORT_ITEM, TTR("Import"));
  740. import_items_tree->set_column_title(IMPORT_ITEM_DATA, TTR("With Data"));
  741. import_items_tree->set_column_expand(0, true);
  742. import_items_tree->set_column_clip_content(0, true);
  743. import_items_tree->set_column_expand(IMPORT_ITEM, false);
  744. import_items_tree->set_column_expand(IMPORT_ITEM_DATA, false);
  745. import_items_tree->set_column_custom_minimum_width(0, 160 * EDSCALE);
  746. import_items_tree->set_column_custom_minimum_width(IMPORT_ITEM, 80 * EDSCALE);
  747. import_items_tree->set_column_custom_minimum_width(IMPORT_ITEM_DATA, 80 * EDSCALE);
  748. import_items_tree->set_column_clip_content(1, true);
  749. import_items_tree->set_column_clip_content(2, true);
  750. ScrollContainer *import_bulk_sc = memnew(ScrollContainer);
  751. import_bulk_sc->set_custom_minimum_size(Size2(260.0, 0.0) * EDSCALE);
  752. import_bulk_sc->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  753. import_main_hb->add_child(import_bulk_sc);
  754. VBoxContainer *import_bulk_vb = memnew(VBoxContainer);
  755. import_bulk_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  756. import_bulk_sc->add_child(import_bulk_vb);
  757. Label *import_bulk_label = memnew(Label);
  758. import_bulk_label->set_text(TTR("Select by data type:"));
  759. import_bulk_vb->add_child(import_bulk_label);
  760. select_colors_icon = memnew(TextureRect);
  761. select_colors_label = memnew(Label);
  762. deselect_all_colors_button = memnew(Button);
  763. select_all_colors_button = memnew(Button);
  764. select_full_colors_button = memnew(Button);
  765. total_selected_colors_label = memnew(Label);
  766. select_constants_icon = memnew(TextureRect);
  767. select_constants_label = memnew(Label);
  768. deselect_all_constants_button = memnew(Button);
  769. select_all_constants_button = memnew(Button);
  770. select_full_constants_button = memnew(Button);
  771. total_selected_constants_label = memnew(Label);
  772. select_fonts_icon = memnew(TextureRect);
  773. select_fonts_label = memnew(Label);
  774. deselect_all_fonts_button = memnew(Button);
  775. select_all_fonts_button = memnew(Button);
  776. select_full_fonts_button = memnew(Button);
  777. total_selected_fonts_label = memnew(Label);
  778. select_font_sizes_icon = memnew(TextureRect);
  779. select_font_sizes_label = memnew(Label);
  780. deselect_all_font_sizes_button = memnew(Button);
  781. select_all_font_sizes_button = memnew(Button);
  782. select_full_font_sizes_button = memnew(Button);
  783. total_selected_font_sizes_label = memnew(Label);
  784. select_icons_icon = memnew(TextureRect);
  785. select_icons_label = memnew(Label);
  786. deselect_all_icons_button = memnew(Button);
  787. select_all_icons_button = memnew(Button);
  788. select_full_icons_button = memnew(Button);
  789. total_selected_icons_label = memnew(Label);
  790. select_styleboxes_icon = memnew(TextureRect);
  791. select_styleboxes_label = memnew(Label);
  792. deselect_all_styleboxes_button = memnew(Button);
  793. select_all_styleboxes_button = memnew(Button);
  794. select_full_styleboxes_button = memnew(Button);
  795. total_selected_styleboxes_label = memnew(Label);
  796. for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
  797. Theme::DataType dt = (Theme::DataType)i;
  798. TextureRect *select_items_icon;
  799. Label *select_items_label;
  800. Button *deselect_all_items_button;
  801. Button *select_all_items_button;
  802. Button *select_full_items_button;
  803. Label *total_selected_items_label;
  804. String items_title = "";
  805. String select_all_items_tooltip = "";
  806. String select_full_items_tooltip = "";
  807. String deselect_all_items_tooltip = "";
  808. switch (dt) {
  809. case Theme::DATA_TYPE_COLOR:
  810. select_items_icon = select_colors_icon;
  811. select_items_label = select_colors_label;
  812. deselect_all_items_button = deselect_all_colors_button;
  813. select_all_items_button = select_all_colors_button;
  814. select_full_items_button = select_full_colors_button;
  815. total_selected_items_label = total_selected_colors_label;
  816. items_title = TTR("Colors");
  817. select_all_items_tooltip = TTR("Select all visible color items.");
  818. select_full_items_tooltip = TTR("Select all visible color items and their data.");
  819. deselect_all_items_tooltip = TTR("Deselect all visible color items.");
  820. break;
  821. case Theme::DATA_TYPE_CONSTANT:
  822. select_items_icon = select_constants_icon;
  823. select_items_label = select_constants_label;
  824. deselect_all_items_button = deselect_all_constants_button;
  825. select_all_items_button = select_all_constants_button;
  826. select_full_items_button = select_full_constants_button;
  827. total_selected_items_label = total_selected_constants_label;
  828. items_title = TTR("Constants");
  829. select_all_items_tooltip = TTR("Select all visible constant items.");
  830. select_full_items_tooltip = TTR("Select all visible constant items and their data.");
  831. deselect_all_items_tooltip = TTR("Deselect all visible constant items.");
  832. break;
  833. case Theme::DATA_TYPE_FONT:
  834. select_items_icon = select_fonts_icon;
  835. select_items_label = select_fonts_label;
  836. deselect_all_items_button = deselect_all_fonts_button;
  837. select_all_items_button = select_all_fonts_button;
  838. select_full_items_button = select_full_fonts_button;
  839. total_selected_items_label = total_selected_fonts_label;
  840. items_title = TTR("Fonts");
  841. select_all_items_tooltip = TTR("Select all visible font items.");
  842. select_full_items_tooltip = TTR("Select all visible font items and their data.");
  843. deselect_all_items_tooltip = TTR("Deselect all visible font items.");
  844. break;
  845. case Theme::DATA_TYPE_FONT_SIZE:
  846. select_items_icon = select_font_sizes_icon;
  847. select_items_label = select_font_sizes_label;
  848. deselect_all_items_button = deselect_all_font_sizes_button;
  849. select_all_items_button = select_all_font_sizes_button;
  850. select_full_items_button = select_full_font_sizes_button;
  851. total_selected_items_label = total_selected_font_sizes_label;
  852. items_title = TTR("Font sizes");
  853. select_all_items_tooltip = TTR("Select all visible font size items.");
  854. select_full_items_tooltip = TTR("Select all visible font size items and their data.");
  855. deselect_all_items_tooltip = TTR("Deselect all visible font size items.");
  856. break;
  857. case Theme::DATA_TYPE_ICON:
  858. select_items_icon = select_icons_icon;
  859. select_items_label = select_icons_label;
  860. deselect_all_items_button = deselect_all_icons_button;
  861. select_all_items_button = select_all_icons_button;
  862. select_full_items_button = select_full_icons_button;
  863. total_selected_items_label = total_selected_icons_label;
  864. items_title = TTR("Icons");
  865. select_all_items_tooltip = TTR("Select all visible icon items.");
  866. select_full_items_tooltip = TTR("Select all visible icon items and their data.");
  867. deselect_all_items_tooltip = TTR("Deselect all visible icon items.");
  868. break;
  869. case Theme::DATA_TYPE_STYLEBOX:
  870. select_items_icon = select_styleboxes_icon;
  871. select_items_label = select_styleboxes_label;
  872. deselect_all_items_button = deselect_all_styleboxes_button;
  873. select_all_items_button = select_all_styleboxes_button;
  874. select_full_items_button = select_full_styleboxes_button;
  875. total_selected_items_label = total_selected_styleboxes_label;
  876. items_title = TTR("Styleboxes");
  877. select_all_items_tooltip = TTR("Select all visible stylebox items.");
  878. select_full_items_tooltip = TTR("Select all visible stylebox items and their data.");
  879. deselect_all_items_tooltip = TTR("Deselect all visible stylebox items.");
  880. break;
  881. case Theme::DATA_TYPE_MAX:
  882. continue; // Can't happen, but silences warning.
  883. }
  884. if (i > 0) {
  885. import_bulk_vb->add_child(memnew(HSeparator));
  886. }
  887. HBoxContainer *all_set = memnew(HBoxContainer);
  888. import_bulk_vb->add_child(all_set);
  889. HBoxContainer *label_set = memnew(HBoxContainer);
  890. label_set->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  891. all_set->add_child(label_set);
  892. select_items_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  893. label_set->add_child(select_items_icon);
  894. select_items_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  895. select_items_label->set_clip_text(true);
  896. select_items_label->set_text(items_title);
  897. label_set->add_child(select_items_label);
  898. HBoxContainer *button_set = memnew(HBoxContainer);
  899. button_set->set_alignment(BoxContainer::ALIGNMENT_END);
  900. all_set->add_child(button_set);
  901. select_all_items_button->set_flat(true);
  902. select_all_items_button->set_tooltip_text(select_all_items_tooltip);
  903. button_set->add_child(select_all_items_button);
  904. select_all_items_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_select_all_data_type_pressed).bind(i));
  905. select_full_items_button->set_flat(true);
  906. select_full_items_button->set_tooltip_text(select_full_items_tooltip);
  907. button_set->add_child(select_full_items_button);
  908. select_full_items_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_select_full_data_type_pressed).bind(i));
  909. deselect_all_items_button->set_flat(true);
  910. deselect_all_items_button->set_tooltip_text(deselect_all_items_tooltip);
  911. button_set->add_child(deselect_all_items_button);
  912. deselect_all_items_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_deselect_all_data_type_pressed).bind(i));
  913. total_selected_items_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
  914. total_selected_items_label->hide();
  915. import_bulk_vb->add_child(total_selected_items_label);
  916. if (dt == Theme::DATA_TYPE_ICON) {
  917. select_icons_warning_hb = memnew(HBoxContainer);
  918. import_bulk_vb->add_child(select_icons_warning_hb);
  919. select_icons_warning_icon = memnew(TextureRect);
  920. select_icons_warning_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  921. select_icons_warning_hb->add_child(select_icons_warning_icon);
  922. select_icons_warning = memnew(Label);
  923. select_icons_warning->set_text(TTR("Caution: Adding icon data may considerably increase the size of your Theme resource."));
  924. select_icons_warning->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  925. select_icons_warning->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  926. select_icons_warning_hb->add_child(select_icons_warning);
  927. }
  928. }
  929. add_child(memnew(HSeparator));
  930. HBoxContainer *import_buttons = memnew(HBoxContainer);
  931. add_child(import_buttons);
  932. import_collapse_types_button = memnew(Button);
  933. import_collapse_types_button->set_flat(true);
  934. import_collapse_types_button->set_tooltip_text(TTR("Collapse types."));
  935. import_buttons->add_child(import_collapse_types_button);
  936. import_collapse_types_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_toggle_type_items).bind(true));
  937. import_expand_types_button = memnew(Button);
  938. import_expand_types_button->set_flat(true);
  939. import_expand_types_button->set_tooltip_text(TTR("Expand types."));
  940. import_buttons->add_child(import_expand_types_button);
  941. import_expand_types_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_toggle_type_items).bind(false));
  942. import_buttons->add_child(memnew(VSeparator));
  943. import_select_all_button = memnew(Button);
  944. import_select_all_button->set_flat(true);
  945. import_select_all_button->set_text(TTR("Select All"));
  946. import_select_all_button->set_tooltip_text(TTR("Select all Theme items."));
  947. import_buttons->add_child(import_select_all_button);
  948. import_select_all_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_select_all_items_pressed));
  949. import_select_full_button = memnew(Button);
  950. import_select_full_button->set_flat(true);
  951. import_select_full_button->set_text(TTR("Select With Data"));
  952. import_select_full_button->set_tooltip_text(TTR("Select all Theme items with item data."));
  953. import_buttons->add_child(import_select_full_button);
  954. import_select_full_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_select_full_items_pressed));
  955. import_deselect_all_button = memnew(Button);
  956. import_deselect_all_button->set_flat(true);
  957. import_deselect_all_button->set_text(TTR("Deselect All"));
  958. import_deselect_all_button->set_tooltip_text(TTR("Deselect all Theme items."));
  959. import_buttons->add_child(import_deselect_all_button);
  960. import_deselect_all_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_deselect_all_items_pressed));
  961. import_buttons->add_spacer();
  962. Button *import_add_selected_button = memnew(Button);
  963. import_add_selected_button->set_text(TTR("Import Selected"));
  964. import_buttons->add_child(import_add_selected_button);
  965. import_add_selected_button->connect("pressed", callable_mp(this, &ThemeItemImportTree::_import_selected));
  966. }
  967. ///////////////////////
  968. void ThemeItemEditorDialog::ok_pressed() {
  969. if (import_default_theme_items->has_selected_items() || import_editor_theme_items->has_selected_items() || import_other_theme_items->has_selected_items()) {
  970. confirm_closing_dialog->set_text(TTR("Import Items tab has some items selected. Selection will be lost upon closing this window.\nClose anyway?"));
  971. confirm_closing_dialog->popup_centered(Size2i(380, 120) * EDSCALE);
  972. return;
  973. }
  974. hide();
  975. }
  976. void ThemeItemEditorDialog::_close_dialog() {
  977. hide();
  978. }
  979. void ThemeItemEditorDialog::_dialog_about_to_show() {
  980. ERR_FAIL_COND_MSG(edited_theme.is_null(), "Invalid state of the Theme Editor; the Theme resource is missing.");
  981. _update_edit_types();
  982. import_default_theme_items->set_edited_theme(edited_theme);
  983. import_default_theme_items->set_base_theme(ThemeDB::get_singleton()->get_default_theme());
  984. import_default_theme_items->reset_item_tree();
  985. import_editor_theme_items->set_edited_theme(edited_theme);
  986. import_editor_theme_items->set_base_theme(EditorNode::get_singleton()->get_theme_base()->get_theme());
  987. import_editor_theme_items->reset_item_tree();
  988. import_other_theme_items->set_edited_theme(edited_theme);
  989. import_other_theme_items->reset_item_tree();
  990. }
  991. void ThemeItemEditorDialog::_update_edit_types() {
  992. Ref<Theme> base_theme = ThemeDB::get_singleton()->get_default_theme();
  993. List<StringName> theme_types;
  994. edited_theme->get_type_list(&theme_types);
  995. theme_types.sort_custom<StringName::AlphCompare>();
  996. bool item_reselected = false;
  997. edit_type_list->clear();
  998. TreeItem *list_root = edit_type_list->create_item();
  999. for (const StringName &E : theme_types) {
  1000. Ref<Texture2D> item_icon;
  1001. if (E == "") {
  1002. item_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons"));
  1003. } else {
  1004. item_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled");
  1005. }
  1006. TreeItem *list_item = edit_type_list->create_item(list_root);
  1007. list_item->set_text(0, E);
  1008. list_item->set_icon(0, item_icon);
  1009. list_item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TYPES_TREE_REMOVE_ITEM, false, TTR("Remove Type"));
  1010. if (E == edited_item_type) {
  1011. list_item->select(0);
  1012. item_reselected = true;
  1013. }
  1014. }
  1015. if (!item_reselected) {
  1016. edited_item_type = "";
  1017. if (list_root->get_child_count() > 0) {
  1018. list_root->get_child(0)->select(0);
  1019. }
  1020. }
  1021. List<StringName> default_types;
  1022. base_theme->get_type_list(&default_types);
  1023. default_types.sort_custom<StringName::AlphCompare>();
  1024. String selected_type = "";
  1025. TreeItem *selected_item = edit_type_list->get_selected();
  1026. if (selected_item) {
  1027. selected_type = selected_item->get_text(0);
  1028. edit_items_add_color->set_disabled(false);
  1029. edit_items_add_constant->set_disabled(false);
  1030. edit_items_add_font->set_disabled(false);
  1031. edit_items_add_font_size->set_disabled(false);
  1032. edit_items_add_icon->set_disabled(false);
  1033. edit_items_add_stylebox->set_disabled(false);
  1034. edit_items_remove_class->set_disabled(false);
  1035. edit_items_remove_custom->set_disabled(false);
  1036. edit_items_remove_all->set_disabled(false);
  1037. edit_items_message->set_text("");
  1038. edit_items_message->hide();
  1039. } else {
  1040. edit_items_add_color->set_disabled(true);
  1041. edit_items_add_constant->set_disabled(true);
  1042. edit_items_add_font->set_disabled(true);
  1043. edit_items_add_font_size->set_disabled(true);
  1044. edit_items_add_icon->set_disabled(true);
  1045. edit_items_add_stylebox->set_disabled(true);
  1046. edit_items_remove_class->set_disabled(true);
  1047. edit_items_remove_custom->set_disabled(true);
  1048. edit_items_remove_all->set_disabled(true);
  1049. edit_items_message->set_text(TTR("Select a theme type from the list to edit its items.\nYou can add a custom type or import a type with its items from another theme."));
  1050. edit_items_message->show();
  1051. }
  1052. _update_edit_item_tree(selected_type);
  1053. }
  1054. void ThemeItemEditorDialog::_edited_type_selected() {
  1055. TreeItem *selected_item = edit_type_list->get_selected();
  1056. String selected_type = selected_item->get_text(0);
  1057. _update_edit_item_tree(selected_type);
  1058. }
  1059. void ThemeItemEditorDialog::_edited_type_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  1060. if (p_button != MouseButton::LEFT) {
  1061. return;
  1062. }
  1063. TreeItem *item = Object::cast_to<TreeItem>(p_item);
  1064. if (!item) {
  1065. return;
  1066. }
  1067. switch (p_id) {
  1068. case TYPES_TREE_REMOVE_ITEM: {
  1069. String type_name = item->get_text(0);
  1070. _remove_theme_type(type_name);
  1071. } break;
  1072. }
  1073. }
  1074. void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) {
  1075. edited_item_type = p_item_type;
  1076. edit_items_tree->clear();
  1077. TreeItem *root = edit_items_tree->create_item();
  1078. List<StringName> names;
  1079. bool has_any_items = false;
  1080. { // Colors.
  1081. names.clear();
  1082. edited_theme->get_color_list(p_item_type, &names);
  1083. if (names.size() > 0) {
  1084. TreeItem *color_root = edit_items_tree->create_item(root);
  1085. color_root->set_metadata(0, Theme::DATA_TYPE_COLOR);
  1086. color_root->set_icon(0, get_theme_icon(SNAME("Color"), SNAME("EditorIcons")));
  1087. color_root->set_text(0, TTR("Colors"));
  1088. color_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Color Items"));
  1089. names.sort_custom<StringName::AlphCompare>();
  1090. for (const StringName &E : names) {
  1091. TreeItem *item = edit_items_tree->create_item(color_root);
  1092. item->set_text(0, E);
  1093. item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item"));
  1094. item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item"));
  1095. }
  1096. has_any_items = true;
  1097. }
  1098. }
  1099. { // Constants.
  1100. names.clear();
  1101. edited_theme->get_constant_list(p_item_type, &names);
  1102. if (names.size() > 0) {
  1103. TreeItem *constant_root = edit_items_tree->create_item(root);
  1104. constant_root->set_metadata(0, Theme::DATA_TYPE_CONSTANT);
  1105. constant_root->set_icon(0, get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")));
  1106. constant_root->set_text(0, TTR("Constants"));
  1107. constant_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Constant Items"));
  1108. names.sort_custom<StringName::AlphCompare>();
  1109. for (const StringName &E : names) {
  1110. TreeItem *item = edit_items_tree->create_item(constant_root);
  1111. item->set_text(0, E);
  1112. item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item"));
  1113. item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item"));
  1114. }
  1115. has_any_items = true;
  1116. }
  1117. }
  1118. { // Fonts.
  1119. names.clear();
  1120. edited_theme->get_font_list(p_item_type, &names);
  1121. if (names.size() > 0) {
  1122. TreeItem *font_root = edit_items_tree->create_item(root);
  1123. font_root->set_metadata(0, Theme::DATA_TYPE_FONT);
  1124. font_root->set_icon(0, get_theme_icon(SNAME("Font"), SNAME("EditorIcons")));
  1125. font_root->set_text(0, TTR("Fonts"));
  1126. font_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Font Items"));
  1127. names.sort_custom<StringName::AlphCompare>();
  1128. for (const StringName &E : names) {
  1129. TreeItem *item = edit_items_tree->create_item(font_root);
  1130. item->set_text(0, E);
  1131. item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item"));
  1132. item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item"));
  1133. }
  1134. has_any_items = true;
  1135. }
  1136. }
  1137. { // Font sizes.
  1138. names.clear();
  1139. edited_theme->get_font_size_list(p_item_type, &names);
  1140. if (names.size() > 0) {
  1141. TreeItem *font_size_root = edit_items_tree->create_item(root);
  1142. font_size_root->set_metadata(0, Theme::DATA_TYPE_FONT_SIZE);
  1143. font_size_root->set_icon(0, get_theme_icon(SNAME("FontSize"), SNAME("EditorIcons")));
  1144. font_size_root->set_text(0, TTR("Font Sizes"));
  1145. font_size_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Font Size Items"));
  1146. names.sort_custom<StringName::AlphCompare>();
  1147. for (const StringName &E : names) {
  1148. TreeItem *item = edit_items_tree->create_item(font_size_root);
  1149. item->set_text(0, E);
  1150. item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item"));
  1151. item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item"));
  1152. }
  1153. has_any_items = true;
  1154. }
  1155. }
  1156. { // Icons.
  1157. names.clear();
  1158. edited_theme->get_icon_list(p_item_type, &names);
  1159. if (names.size() > 0) {
  1160. TreeItem *icon_root = edit_items_tree->create_item(root);
  1161. icon_root->set_metadata(0, Theme::DATA_TYPE_ICON);
  1162. icon_root->set_icon(0, get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")));
  1163. icon_root->set_text(0, TTR("Icons"));
  1164. icon_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Icon Items"));
  1165. names.sort_custom<StringName::AlphCompare>();
  1166. for (const StringName &E : names) {
  1167. TreeItem *item = edit_items_tree->create_item(icon_root);
  1168. item->set_text(0, E);
  1169. item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item"));
  1170. item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item"));
  1171. }
  1172. has_any_items = true;
  1173. }
  1174. }
  1175. { // Styleboxes.
  1176. names.clear();
  1177. edited_theme->get_stylebox_list(p_item_type, &names);
  1178. if (names.size() > 0) {
  1179. TreeItem *stylebox_root = edit_items_tree->create_item(root);
  1180. stylebox_root->set_metadata(0, Theme::DATA_TYPE_STYLEBOX);
  1181. stylebox_root->set_icon(0, get_theme_icon(SNAME("StyleBoxFlat"), SNAME("EditorIcons")));
  1182. stylebox_root->set_text(0, TTR("Styleboxes"));
  1183. stylebox_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All StyleBox Items"));
  1184. names.sort_custom<StringName::AlphCompare>();
  1185. for (const StringName &E : names) {
  1186. TreeItem *item = edit_items_tree->create_item(stylebox_root);
  1187. item->set_text(0, E);
  1188. item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item"));
  1189. item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item"));
  1190. }
  1191. has_any_items = true;
  1192. }
  1193. }
  1194. // If some type is selected, but it doesn't seem to have any items, show a guiding message.
  1195. TreeItem *selected_item = edit_type_list->get_selected();
  1196. if (selected_item) {
  1197. if (!has_any_items) {
  1198. edit_items_message->set_text(TTR("This theme type is empty.\nAdd more items to it manually or by importing from another theme."));
  1199. edit_items_message->show();
  1200. } else {
  1201. edit_items_message->set_text("");
  1202. edit_items_message->hide();
  1203. }
  1204. }
  1205. }
  1206. void ThemeItemEditorDialog::_item_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  1207. if (p_button != MouseButton::LEFT) {
  1208. return;
  1209. }
  1210. TreeItem *item = Object::cast_to<TreeItem>(p_item);
  1211. if (!item) {
  1212. return;
  1213. }
  1214. switch (p_id) {
  1215. case ITEMS_TREE_RENAME_ITEM: {
  1216. String item_name = item->get_text(0);
  1217. int data_type = item->get_parent()->get_metadata(0);
  1218. _open_rename_theme_item_dialog((Theme::DataType)data_type, item_name);
  1219. _update_edit_item_tree(edited_item_type);
  1220. } break;
  1221. case ITEMS_TREE_REMOVE_ITEM: {
  1222. String item_name = item->get_text(0);
  1223. int data_type = item->get_parent()->get_metadata(0);
  1224. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1225. ur->create_action(TTR("Remove Theme Item"));
  1226. ur->add_do_method(*edited_theme, "clear_theme_item", (Theme::DataType)data_type, item_name, edited_item_type);
  1227. ur->add_undo_method(*edited_theme, "set_theme_item", (Theme::DataType)data_type, item_name, edited_item_type, edited_theme->get_theme_item((Theme::DataType)data_type, item_name, edited_item_type));
  1228. ur->add_do_method(this, "_update_edit_item_tree", edited_item_type);
  1229. ur->add_undo_method(this, "_update_edit_item_tree", edited_item_type);
  1230. ur->commit_action();
  1231. } break;
  1232. case ITEMS_TREE_REMOVE_DATA_TYPE: {
  1233. int data_type = item->get_metadata(0);
  1234. _remove_data_type_items((Theme::DataType)data_type, edited_item_type);
  1235. } break;
  1236. }
  1237. }
  1238. void ThemeItemEditorDialog::_add_theme_type(const String &p_new_text) {
  1239. const String new_type = edit_add_type_value->get_text().strip_edges();
  1240. edit_add_type_value->clear();
  1241. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1242. ur->create_action(TTR("Add Theme Type"));
  1243. ur->add_do_method(*edited_theme, "add_type", new_type);
  1244. ur->add_undo_method(*edited_theme, "remove_type", new_type);
  1245. ur->add_do_method(this, "_update_edit_types");
  1246. ur->add_undo_method(this, "_update_edit_types");
  1247. ur->commit_action();
  1248. }
  1249. void ThemeItemEditorDialog::_add_theme_item(Theme::DataType p_data_type, String p_item_name, String p_item_type) {
  1250. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1251. ur->create_action(TTR("Create Theme Item"));
  1252. switch (p_data_type) {
  1253. case Theme::DATA_TYPE_ICON:
  1254. ur->add_do_method(*edited_theme, "set_icon", p_item_name, p_item_type, Ref<Texture2D>());
  1255. ur->add_undo_method(*edited_theme, "clear_icon", p_item_name, p_item_type);
  1256. break;
  1257. case Theme::DATA_TYPE_STYLEBOX:
  1258. ur->add_do_method(*edited_theme, "set_stylebox", p_item_name, p_item_type, Ref<StyleBox>());
  1259. ur->add_undo_method(*edited_theme, "clear_stylebox", p_item_name, p_item_type);
  1260. if (theme_type_editor->is_stylebox_pinned(edited_theme->get_stylebox(p_item_name, p_item_type))) {
  1261. ur->add_undo_method(theme_type_editor, "_unpin_leading_stylebox");
  1262. }
  1263. break;
  1264. case Theme::DATA_TYPE_FONT:
  1265. ur->add_do_method(*edited_theme, "set_font", p_item_name, p_item_type, Ref<Font>());
  1266. ur->add_undo_method(*edited_theme, "clear_font", p_item_name, p_item_type);
  1267. break;
  1268. case Theme::DATA_TYPE_FONT_SIZE:
  1269. ur->add_do_method(*edited_theme, "set_font_size", p_item_name, p_item_type, -1);
  1270. ur->add_undo_method(*edited_theme, "clear_font_size", p_item_name, p_item_type);
  1271. break;
  1272. case Theme::DATA_TYPE_COLOR:
  1273. ur->add_do_method(*edited_theme, "set_color", p_item_name, p_item_type, Color());
  1274. ur->add_undo_method(*edited_theme, "clear_color", p_item_name, p_item_type);
  1275. break;
  1276. case Theme::DATA_TYPE_CONSTANT:
  1277. ur->add_do_method(*edited_theme, "set_constant", p_item_name, p_item_type, 0);
  1278. ur->add_undo_method(*edited_theme, "clear_constant", p_item_name, p_item_type);
  1279. break;
  1280. case Theme::DATA_TYPE_MAX:
  1281. break; // Can't happen, but silences warning.
  1282. }
  1283. ur->add_do_method(this, "_update_edit_item_tree", edited_item_type);
  1284. ur->add_undo_method(this, "_update_edit_item_tree", edited_item_type);
  1285. ur->commit_action();
  1286. }
  1287. void ThemeItemEditorDialog::_remove_theme_type(const String &p_theme_type) {
  1288. Ref<Theme> old_snapshot = edited_theme->duplicate();
  1289. Ref<Theme> new_snapshot = edited_theme->duplicate();
  1290. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1291. ur->create_action(TTR("Remove Theme Type"));
  1292. new_snapshot->remove_type(p_theme_type);
  1293. ur->add_do_method(*edited_theme, "clear");
  1294. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  1295. // If the type was empty, it cannot be restored with merge, but thankfully we can fake it.
  1296. ur->add_undo_method(*edited_theme, "add_type", p_theme_type);
  1297. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  1298. ur->add_do_method(this, "_update_edit_types");
  1299. ur->add_undo_method(this, "_update_edit_types");
  1300. ur->commit_action();
  1301. }
  1302. void ThemeItemEditorDialog::_remove_data_type_items(Theme::DataType p_data_type, String p_item_type) {
  1303. List<StringName> names;
  1304. Ref<Theme> old_snapshot = edited_theme->duplicate();
  1305. Ref<Theme> new_snapshot = edited_theme->duplicate();
  1306. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1307. ur->create_action(TTR("Remove Data Type Items From Theme"));
  1308. new_snapshot->get_theme_item_list(p_data_type, p_item_type, &names);
  1309. for (const StringName &E : names) {
  1310. new_snapshot->clear_theme_item(p_data_type, E, edited_item_type);
  1311. if (p_data_type == Theme::DATA_TYPE_STYLEBOX && theme_type_editor->is_stylebox_pinned(edited_theme->get_stylebox(E, p_item_type))) {
  1312. ur->add_do_method(theme_type_editor, "_unpin_leading_stylebox");
  1313. ur->add_undo_method(theme_type_editor, "_pin_leading_stylebox", E, edited_theme->get_stylebox(E, p_item_type));
  1314. }
  1315. }
  1316. ur->add_do_method(*edited_theme, "clear");
  1317. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  1318. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  1319. ur->add_do_method(theme_type_editor, "_update_edit_item_tree", edited_item_type);
  1320. ur->add_undo_method(theme_type_editor, "_update_edit_item_tree", edited_item_type);
  1321. ur->commit_action();
  1322. }
  1323. void ThemeItemEditorDialog::_remove_class_items() {
  1324. List<StringName> names;
  1325. Ref<Theme> old_snapshot = edited_theme->duplicate();
  1326. Ref<Theme> new_snapshot = edited_theme->duplicate();
  1327. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1328. ur->create_action(TTR("Remove Class Items From Theme"));
  1329. for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) {
  1330. Theme::DataType data_type = (Theme::DataType)dt;
  1331. names.clear();
  1332. ThemeDB::get_singleton()->get_default_theme()->get_theme_item_list(data_type, edited_item_type, &names);
  1333. for (const StringName &E : names) {
  1334. if (new_snapshot->has_theme_item_nocheck(data_type, E, edited_item_type)) {
  1335. new_snapshot->clear_theme_item(data_type, E, edited_item_type);
  1336. if (dt == Theme::DATA_TYPE_STYLEBOX && theme_type_editor->is_stylebox_pinned(edited_theme->get_stylebox(E, edited_item_type))) {
  1337. ur->add_do_method(theme_type_editor, "_unpin_leading_stylebox");
  1338. ur->add_undo_method(theme_type_editor, "_pin_leading_stylebox", E, edited_theme->get_stylebox(E, edited_item_type));
  1339. }
  1340. }
  1341. }
  1342. }
  1343. ur->add_do_method(*edited_theme, "clear");
  1344. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  1345. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  1346. ur->add_do_method(this, "_update_edit_item_tree", edited_item_type);
  1347. ur->add_undo_method(this, "_update_edit_item_tree", edited_item_type);
  1348. ur->commit_action();
  1349. }
  1350. void ThemeItemEditorDialog::_remove_custom_items() {
  1351. List<StringName> names;
  1352. Ref<Theme> old_snapshot = edited_theme->duplicate();
  1353. Ref<Theme> new_snapshot = edited_theme->duplicate();
  1354. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1355. ur->create_action(TTR("Remove Custom Items From Theme"));
  1356. for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) {
  1357. Theme::DataType data_type = (Theme::DataType)dt;
  1358. names.clear();
  1359. new_snapshot->get_theme_item_list(data_type, edited_item_type, &names);
  1360. for (const StringName &E : names) {
  1361. if (!ThemeDB::get_singleton()->get_default_theme()->has_theme_item_nocheck(data_type, E, edited_item_type)) {
  1362. new_snapshot->clear_theme_item(data_type, E, edited_item_type);
  1363. if (dt == Theme::DATA_TYPE_STYLEBOX && theme_type_editor->is_stylebox_pinned(edited_theme->get_stylebox(E, edited_item_type))) {
  1364. ur->add_do_method(theme_type_editor, "_unpin_leading_stylebox");
  1365. ur->add_undo_method(theme_type_editor, "_pin_leading_stylebox", E, edited_theme->get_stylebox(E, edited_item_type));
  1366. }
  1367. }
  1368. }
  1369. }
  1370. ur->add_do_method(*edited_theme, "clear");
  1371. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  1372. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  1373. ur->add_do_method(this, "_update_edit_item_tree", edited_item_type);
  1374. ur->add_undo_method(this, "_update_edit_item_tree", edited_item_type);
  1375. ur->commit_action();
  1376. }
  1377. void ThemeItemEditorDialog::_remove_all_items() {
  1378. List<StringName> names;
  1379. Ref<Theme> old_snapshot = edited_theme->duplicate();
  1380. Ref<Theme> new_snapshot = edited_theme->duplicate();
  1381. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1382. ur->create_action(TTR("Remove All Items From Theme"));
  1383. for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) {
  1384. Theme::DataType data_type = (Theme::DataType)dt;
  1385. names.clear();
  1386. new_snapshot->get_theme_item_list(data_type, edited_item_type, &names);
  1387. for (const StringName &E : names) {
  1388. new_snapshot->clear_theme_item(data_type, E, edited_item_type);
  1389. if (dt == Theme::DATA_TYPE_STYLEBOX && theme_type_editor->is_stylebox_pinned(edited_theme->get_stylebox(E, edited_item_type))) {
  1390. ur->add_do_method(theme_type_editor, "_unpin_leading_stylebox");
  1391. ur->add_undo_method(theme_type_editor, "_pin_leading_stylebox", E, edited_theme->get_stylebox(E, edited_item_type));
  1392. }
  1393. }
  1394. }
  1395. ur->add_do_method(*edited_theme, "clear");
  1396. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  1397. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  1398. ur->add_do_method(this, "_update_edit_item_tree", edited_item_type);
  1399. ur->add_undo_method(this, "_update_edit_item_tree", edited_item_type);
  1400. ur->commit_action();
  1401. }
  1402. void ThemeItemEditorDialog::_open_add_theme_item_dialog(int p_data_type) {
  1403. ERR_FAIL_INDEX_MSG(p_data_type, Theme::DATA_TYPE_MAX, "Theme item data type is out of bounds.");
  1404. item_popup_mode = CREATE_THEME_ITEM;
  1405. edit_item_data_type = (Theme::DataType)p_data_type;
  1406. switch (edit_item_data_type) {
  1407. case Theme::DATA_TYPE_COLOR:
  1408. edit_theme_item_dialog->set_title(TTR("Add Color Item"));
  1409. break;
  1410. case Theme::DATA_TYPE_CONSTANT:
  1411. edit_theme_item_dialog->set_title(TTR("Add Constant Item"));
  1412. break;
  1413. case Theme::DATA_TYPE_FONT:
  1414. edit_theme_item_dialog->set_title(TTR("Add Font Item"));
  1415. break;
  1416. case Theme::DATA_TYPE_FONT_SIZE:
  1417. edit_theme_item_dialog->set_title(TTR("Add Font Size Item"));
  1418. break;
  1419. case Theme::DATA_TYPE_ICON:
  1420. edit_theme_item_dialog->set_title(TTR("Add Icon Item"));
  1421. break;
  1422. case Theme::DATA_TYPE_STYLEBOX:
  1423. edit_theme_item_dialog->set_title(TTR("Add Stylebox Item"));
  1424. break;
  1425. case Theme::DATA_TYPE_MAX:
  1426. break; // Can't happen, but silences warning.
  1427. }
  1428. edit_theme_item_old_vb->hide();
  1429. theme_item_name->clear();
  1430. edit_theme_item_dialog->popup_centered(Size2(380, 110) * EDSCALE);
  1431. theme_item_name->grab_focus();
  1432. }
  1433. void ThemeItemEditorDialog::_open_rename_theme_item_dialog(Theme::DataType p_data_type, String p_item_name) {
  1434. ERR_FAIL_INDEX_MSG(p_data_type, Theme::DATA_TYPE_MAX, "Theme item data type is out of bounds.");
  1435. item_popup_mode = RENAME_THEME_ITEM;
  1436. edit_item_data_type = p_data_type;
  1437. edit_item_old_name = p_item_name;
  1438. switch (edit_item_data_type) {
  1439. case Theme::DATA_TYPE_COLOR:
  1440. edit_theme_item_dialog->set_title(TTR("Rename Color Item"));
  1441. break;
  1442. case Theme::DATA_TYPE_CONSTANT:
  1443. edit_theme_item_dialog->set_title(TTR("Rename Constant Item"));
  1444. break;
  1445. case Theme::DATA_TYPE_FONT:
  1446. edit_theme_item_dialog->set_title(TTR("Rename Font Item"));
  1447. break;
  1448. case Theme::DATA_TYPE_FONT_SIZE:
  1449. edit_theme_item_dialog->set_title(TTR("Rename Font Size Item"));
  1450. break;
  1451. case Theme::DATA_TYPE_ICON:
  1452. edit_theme_item_dialog->set_title(TTR("Rename Icon Item"));
  1453. break;
  1454. case Theme::DATA_TYPE_STYLEBOX:
  1455. edit_theme_item_dialog->set_title(TTR("Rename Stylebox Item"));
  1456. break;
  1457. case Theme::DATA_TYPE_MAX:
  1458. break; // Can't happen, but silences warning.
  1459. }
  1460. edit_theme_item_old_vb->show();
  1461. theme_item_old_name->set_text(p_item_name);
  1462. theme_item_name->set_text(p_item_name);
  1463. edit_theme_item_dialog->popup_centered(Size2(380, 140) * EDSCALE);
  1464. theme_item_name->grab_focus();
  1465. }
  1466. void ThemeItemEditorDialog::_confirm_edit_theme_item() {
  1467. if (item_popup_mode == CREATE_THEME_ITEM) {
  1468. _add_theme_item(edit_item_data_type, theme_item_name->get_text(), edited_item_type);
  1469. } else if (item_popup_mode == RENAME_THEME_ITEM) {
  1470. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  1471. ur->create_action(TTR("Rename Theme Item"));
  1472. ur->add_do_method(*edited_theme, "rename_theme_item", edit_item_data_type, edit_item_old_name, theme_item_name->get_text(), edited_item_type);
  1473. ur->add_undo_method(*edited_theme, "rename_theme_item", edit_item_data_type, theme_item_name->get_text(), edit_item_old_name, edited_item_type);
  1474. ur->add_do_method(this, "_update_edit_item_tree", edited_item_type);
  1475. ur->add_undo_method(this, "_update_edit_item_tree", edited_item_type);
  1476. ur->commit_action();
  1477. }
  1478. item_popup_mode = ITEM_POPUP_MODE_MAX;
  1479. edit_item_data_type = Theme::DATA_TYPE_MAX;
  1480. edit_item_old_name = "";
  1481. }
  1482. void ThemeItemEditorDialog::_edit_theme_item_gui_input(const Ref<InputEvent> &p_event) {
  1483. Ref<InputEventKey> k = p_event;
  1484. if (k.is_valid()) {
  1485. if (!k->is_pressed()) {
  1486. return;
  1487. }
  1488. switch (k->get_keycode()) {
  1489. case Key::KP_ENTER:
  1490. case Key::ENTER: {
  1491. _confirm_edit_theme_item();
  1492. edit_theme_item_dialog->hide();
  1493. edit_theme_item_dialog->set_input_as_handled();
  1494. } break;
  1495. case Key::ESCAPE: {
  1496. edit_theme_item_dialog->hide();
  1497. edit_theme_item_dialog->set_input_as_handled();
  1498. } break;
  1499. default:
  1500. break;
  1501. }
  1502. }
  1503. }
  1504. void ThemeItemEditorDialog::_open_select_another_theme() {
  1505. import_another_theme_dialog->popup_file_dialog();
  1506. }
  1507. void ThemeItemEditorDialog::_select_another_theme_cbk(const String &p_path) {
  1508. Ref<Theme> loaded_theme = ResourceLoader::load(p_path);
  1509. if (loaded_theme.is_null()) {
  1510. EditorNode::get_singleton()->show_warning(TTR("Invalid file, not a Theme resource."));
  1511. return;
  1512. }
  1513. if (loaded_theme == edited_theme) {
  1514. EditorNode::get_singleton()->show_warning(TTR("Invalid file, same as the edited Theme resource."));
  1515. return;
  1516. }
  1517. import_another_theme_value->set_text(p_path);
  1518. import_other_theme_items->set_base_theme(loaded_theme);
  1519. import_other_theme_items->reset_item_tree();
  1520. }
  1521. void ThemeItemEditorDialog::_notification(int p_what) {
  1522. switch (p_what) {
  1523. case NOTIFICATION_ENTER_TREE: {
  1524. connect("about_to_popup", callable_mp(this, &ThemeItemEditorDialog::_dialog_about_to_show));
  1525. [[fallthrough]];
  1526. }
  1527. case NOTIFICATION_THEME_CHANGED: {
  1528. edit_items_add_color->set_icon(get_theme_icon(SNAME("Color"), SNAME("EditorIcons")));
  1529. edit_items_add_constant->set_icon(get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")));
  1530. edit_items_add_font->set_icon(get_theme_icon(SNAME("Font"), SNAME("EditorIcons")));
  1531. edit_items_add_font_size->set_icon(get_theme_icon(SNAME("FontSize"), SNAME("EditorIcons")));
  1532. edit_items_add_icon->set_icon(get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")));
  1533. edit_items_add_stylebox->set_icon(get_theme_icon(SNAME("StyleBoxFlat"), SNAME("EditorIcons")));
  1534. edit_items_remove_class->set_icon(get_theme_icon(SNAME("Control"), SNAME("EditorIcons")));
  1535. edit_items_remove_custom->set_icon(get_theme_icon(SNAME("ThemeRemoveCustomItems"), SNAME("EditorIcons")));
  1536. edit_items_remove_all->set_icon(get_theme_icon(SNAME("ThemeRemoveAllItems"), SNAME("EditorIcons")));
  1537. edit_add_type_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
  1538. import_another_theme_button->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
  1539. } break;
  1540. }
  1541. }
  1542. void ThemeItemEditorDialog::_bind_methods() {
  1543. ClassDB::bind_method(D_METHOD("_update_edit_types"), &ThemeItemEditorDialog::_update_edit_types);
  1544. ClassDB::bind_method(D_METHOD("_update_edit_item_tree"), &ThemeItemEditorDialog::_update_edit_item_tree);
  1545. }
  1546. void ThemeItemEditorDialog::set_edited_theme(const Ref<Theme> &p_theme) {
  1547. edited_theme = p_theme;
  1548. }
  1549. ThemeItemEditorDialog::ThemeItemEditorDialog(ThemeTypeEditor *p_theme_type_editor) {
  1550. set_title(TTR("Manage Theme Items"));
  1551. set_ok_button_text(TTR("Close"));
  1552. set_hide_on_ok(false); // Closing may require a confirmation in some cases.
  1553. theme_type_editor = p_theme_type_editor;
  1554. tc = memnew(TabContainer);
  1555. add_child(tc);
  1556. tc->set_theme_type_variation("TabContainerOdd");
  1557. // Edit Items tab.
  1558. HSplitContainer *edit_dialog_hs = memnew(HSplitContainer);
  1559. tc->add_child(edit_dialog_hs);
  1560. tc->set_tab_title(0, TTR("Edit Items"));
  1561. VBoxContainer *edit_dialog_side_vb = memnew(VBoxContainer);
  1562. edit_dialog_side_vb->set_custom_minimum_size(Size2(200.0, 0.0) * EDSCALE);
  1563. edit_dialog_hs->add_child(edit_dialog_side_vb);
  1564. Label *edit_type_label = memnew(Label);
  1565. edit_type_label->set_text(TTR("Types:"));
  1566. edit_dialog_side_vb->add_child(edit_type_label);
  1567. edit_type_list = memnew(Tree);
  1568. edit_type_list->set_hide_root(true);
  1569. edit_type_list->set_hide_folding(true);
  1570. edit_type_list->set_columns(1);
  1571. edit_type_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1572. edit_dialog_side_vb->add_child(edit_type_list);
  1573. edit_type_list->connect("item_selected", callable_mp(this, &ThemeItemEditorDialog::_edited_type_selected));
  1574. edit_type_list->connect("button_clicked", callable_mp(this, &ThemeItemEditorDialog::_edited_type_button_pressed));
  1575. Label *edit_add_type_label = memnew(Label);
  1576. edit_add_type_label->set_text(TTR("Add Type:"));
  1577. edit_dialog_side_vb->add_child(edit_add_type_label);
  1578. HBoxContainer *edit_add_type_hb = memnew(HBoxContainer);
  1579. edit_dialog_side_vb->add_child(edit_add_type_hb);
  1580. edit_add_type_value = memnew(LineEdit);
  1581. edit_add_type_value->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1582. edit_add_type_value->connect("text_submitted", callable_mp(this, &ThemeItemEditorDialog::_add_theme_type));
  1583. edit_add_type_hb->add_child(edit_add_type_value);
  1584. edit_add_type_button = memnew(Button);
  1585. edit_add_type_hb->add_child(edit_add_type_button);
  1586. edit_add_type_button->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_add_theme_type).bind(""));
  1587. VBoxContainer *edit_items_vb = memnew(VBoxContainer);
  1588. edit_items_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1589. edit_dialog_hs->add_child(edit_items_vb);
  1590. HBoxContainer *edit_items_toolbar = memnew(HBoxContainer);
  1591. edit_items_vb->add_child(edit_items_toolbar);
  1592. Label *edit_items_toolbar_add_label = memnew(Label);
  1593. edit_items_toolbar_add_label->set_text(TTR("Add Item:"));
  1594. edit_items_toolbar->add_child(edit_items_toolbar_add_label);
  1595. edit_items_add_color = memnew(Button);
  1596. edit_items_add_color->set_tooltip_text(TTR("Add Color Item"));
  1597. edit_items_add_color->set_flat(true);
  1598. edit_items_add_color->set_disabled(true);
  1599. edit_items_toolbar->add_child(edit_items_add_color);
  1600. edit_items_add_color->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_add_theme_item_dialog).bind(Theme::DATA_TYPE_COLOR));
  1601. edit_items_add_constant = memnew(Button);
  1602. edit_items_add_constant->set_tooltip_text(TTR("Add Constant Item"));
  1603. edit_items_add_constant->set_flat(true);
  1604. edit_items_add_constant->set_disabled(true);
  1605. edit_items_toolbar->add_child(edit_items_add_constant);
  1606. edit_items_add_constant->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_add_theme_item_dialog).bind(Theme::DATA_TYPE_CONSTANT));
  1607. edit_items_add_font = memnew(Button);
  1608. edit_items_add_font->set_tooltip_text(TTR("Add Font Item"));
  1609. edit_items_add_font->set_flat(true);
  1610. edit_items_add_font->set_disabled(true);
  1611. edit_items_toolbar->add_child(edit_items_add_font);
  1612. edit_items_add_font->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_add_theme_item_dialog).bind(Theme::DATA_TYPE_FONT));
  1613. edit_items_add_font_size = memnew(Button);
  1614. edit_items_add_font_size->set_tooltip_text(TTR("Add Font Size Item"));
  1615. edit_items_add_font_size->set_flat(true);
  1616. edit_items_add_font_size->set_disabled(true);
  1617. edit_items_toolbar->add_child(edit_items_add_font_size);
  1618. edit_items_add_font_size->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_add_theme_item_dialog).bind(Theme::DATA_TYPE_FONT_SIZE));
  1619. edit_items_add_icon = memnew(Button);
  1620. edit_items_add_icon->set_tooltip_text(TTR("Add Icon Item"));
  1621. edit_items_add_icon->set_flat(true);
  1622. edit_items_add_icon->set_disabled(true);
  1623. edit_items_toolbar->add_child(edit_items_add_icon);
  1624. edit_items_add_icon->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_add_theme_item_dialog).bind(Theme::DATA_TYPE_ICON));
  1625. edit_items_add_stylebox = memnew(Button);
  1626. edit_items_add_stylebox->set_tooltip_text(TTR("Add StyleBox Item"));
  1627. edit_items_add_stylebox->set_flat(true);
  1628. edit_items_add_stylebox->set_disabled(true);
  1629. edit_items_toolbar->add_child(edit_items_add_stylebox);
  1630. edit_items_add_stylebox->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_add_theme_item_dialog).bind(Theme::DATA_TYPE_STYLEBOX));
  1631. edit_items_toolbar->add_child(memnew(VSeparator));
  1632. Label *edit_items_toolbar_remove_label = memnew(Label);
  1633. edit_items_toolbar_remove_label->set_text(TTR("Remove Items:"));
  1634. edit_items_toolbar->add_child(edit_items_toolbar_remove_label);
  1635. edit_items_remove_class = memnew(Button);
  1636. edit_items_remove_class->set_tooltip_text(TTR("Remove Class Items"));
  1637. edit_items_remove_class->set_flat(true);
  1638. edit_items_remove_class->set_disabled(true);
  1639. edit_items_toolbar->add_child(edit_items_remove_class);
  1640. edit_items_remove_class->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_remove_class_items));
  1641. edit_items_remove_custom = memnew(Button);
  1642. edit_items_remove_custom->set_tooltip_text(TTR("Remove Custom Items"));
  1643. edit_items_remove_custom->set_flat(true);
  1644. edit_items_remove_custom->set_disabled(true);
  1645. edit_items_toolbar->add_child(edit_items_remove_custom);
  1646. edit_items_remove_custom->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_remove_custom_items));
  1647. edit_items_remove_all = memnew(Button);
  1648. edit_items_remove_all->set_tooltip_text(TTR("Remove All Items"));
  1649. edit_items_remove_all->set_flat(true);
  1650. edit_items_remove_all->set_disabled(true);
  1651. edit_items_toolbar->add_child(edit_items_remove_all);
  1652. edit_items_remove_all->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_remove_all_items));
  1653. edit_items_tree = memnew(Tree);
  1654. edit_items_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1655. edit_items_tree->set_hide_root(true);
  1656. edit_items_tree->set_columns(1);
  1657. edit_items_vb->add_child(edit_items_tree);
  1658. edit_items_tree->connect("button_clicked", callable_mp(this, &ThemeItemEditorDialog::_item_tree_button_pressed));
  1659. edit_items_message = memnew(Label);
  1660. edit_items_message->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  1661. edit_items_message->set_mouse_filter(Control::MOUSE_FILTER_STOP);
  1662. edit_items_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1663. edit_items_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  1664. edit_items_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  1665. edit_items_tree->add_child(edit_items_message);
  1666. edit_theme_item_dialog = memnew(ConfirmationDialog);
  1667. edit_theme_item_dialog->set_title(TTR("Add Theme Item"));
  1668. add_child(edit_theme_item_dialog);
  1669. VBoxContainer *edit_theme_item_vb = memnew(VBoxContainer);
  1670. edit_theme_item_dialog->add_child(edit_theme_item_vb);
  1671. edit_theme_item_old_vb = memnew(VBoxContainer);
  1672. edit_theme_item_vb->add_child(edit_theme_item_old_vb);
  1673. Label *edit_theme_item_old = memnew(Label);
  1674. edit_theme_item_old->set_text(TTR("Old Name:"));
  1675. edit_theme_item_old_vb->add_child(edit_theme_item_old);
  1676. theme_item_old_name = memnew(Label);
  1677. edit_theme_item_old_vb->add_child(theme_item_old_name);
  1678. Label *edit_theme_item_label = memnew(Label);
  1679. edit_theme_item_label->set_text(TTR("Name:"));
  1680. edit_theme_item_vb->add_child(edit_theme_item_label);
  1681. theme_item_name = memnew(LineEdit);
  1682. edit_theme_item_vb->add_child(theme_item_name);
  1683. theme_item_name->connect("gui_input", callable_mp(this, &ThemeItemEditorDialog::_edit_theme_item_gui_input));
  1684. edit_theme_item_dialog->connect("confirmed", callable_mp(this, &ThemeItemEditorDialog::_confirm_edit_theme_item));
  1685. // Import Items tab.
  1686. TabContainer *import_tc = memnew(TabContainer);
  1687. import_tc->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  1688. tc->add_child(import_tc);
  1689. tc->set_tab_title(1, TTR("Import Items"));
  1690. import_default_theme_items = memnew(ThemeItemImportTree);
  1691. import_tc->add_child(import_default_theme_items);
  1692. import_tc->set_tab_title(0, TTR("Default Theme"));
  1693. import_default_theme_items->connect("items_imported", callable_mp(this, &ThemeItemEditorDialog::_update_edit_types));
  1694. import_editor_theme_items = memnew(ThemeItemImportTree);
  1695. import_tc->add_child(import_editor_theme_items);
  1696. import_tc->set_tab_title(1, TTR("Editor Theme"));
  1697. import_editor_theme_items->connect("items_imported", callable_mp(this, &ThemeItemEditorDialog::_update_edit_types));
  1698. VBoxContainer *import_another_theme_vb = memnew(VBoxContainer);
  1699. HBoxContainer *import_another_file_hb = memnew(HBoxContainer);
  1700. import_another_theme_vb->add_child(import_another_file_hb);
  1701. import_another_theme_value = memnew(LineEdit);
  1702. import_another_theme_value->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1703. import_another_theme_value->set_editable(false);
  1704. import_another_file_hb->add_child(import_another_theme_value);
  1705. import_another_theme_button = memnew(Button);
  1706. import_another_file_hb->add_child(import_another_theme_button);
  1707. import_another_theme_button->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_open_select_another_theme));
  1708. import_another_theme_dialog = memnew(EditorFileDialog);
  1709. import_another_theme_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1710. import_another_theme_dialog->set_title(TTR("Select Another Theme Resource:"));
  1711. List<String> ext;
  1712. ResourceLoader::get_recognized_extensions_for_type("Theme", &ext);
  1713. for (const String &E : ext) {
  1714. import_another_theme_dialog->add_filter("*." + E, TTR("Theme Resource"));
  1715. }
  1716. import_another_file_hb->add_child(import_another_theme_dialog);
  1717. import_another_theme_dialog->connect("file_selected", callable_mp(this, &ThemeItemEditorDialog::_select_another_theme_cbk));
  1718. import_other_theme_items = memnew(ThemeItemImportTree);
  1719. import_other_theme_items->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1720. import_another_theme_vb->add_child(import_other_theme_items);
  1721. import_tc->add_child(import_another_theme_vb);
  1722. import_tc->set_tab_title(2, TTR("Another Theme"));
  1723. import_other_theme_items->connect("items_imported", callable_mp(this, &ThemeItemEditorDialog::_update_edit_types));
  1724. confirm_closing_dialog = memnew(ConfirmationDialog);
  1725. confirm_closing_dialog->set_autowrap(true);
  1726. add_child(confirm_closing_dialog);
  1727. confirm_closing_dialog->connect("confirmed", callable_mp(this, &ThemeItemEditorDialog::_close_dialog));
  1728. }
  1729. ///////////////////////
  1730. void ThemeTypeDialog::_dialog_about_to_show() {
  1731. add_type_filter->set_text("");
  1732. add_type_filter->grab_focus();
  1733. _update_add_type_options();
  1734. }
  1735. void ThemeTypeDialog::ok_pressed() {
  1736. _add_type_selected(add_type_filter->get_text().strip_edges());
  1737. }
  1738. void ThemeTypeDialog::_update_add_type_options(const String &p_filter) {
  1739. add_type_options->clear();
  1740. List<StringName> names;
  1741. ThemeDB::get_singleton()->get_default_theme()->get_type_list(&names);
  1742. if (include_own_types) {
  1743. edited_theme->get_type_list(&names);
  1744. }
  1745. names.sort_custom<StringName::AlphCompare>();
  1746. Vector<StringName> unique_names;
  1747. for (const StringName &E : names) {
  1748. // Filter out undesired values.
  1749. if (!p_filter.is_subsequence_ofn(String(E))) {
  1750. continue;
  1751. }
  1752. // Skip duplicate values.
  1753. if (unique_names.has(E)) {
  1754. continue;
  1755. }
  1756. unique_names.append(E);
  1757. Ref<Texture2D> item_icon;
  1758. if (E == "") {
  1759. item_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons"));
  1760. } else {
  1761. item_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled");
  1762. }
  1763. add_type_options->add_item(E, item_icon);
  1764. }
  1765. }
  1766. void ThemeTypeDialog::_add_type_filter_cbk(const String &p_value) {
  1767. _update_add_type_options(p_value);
  1768. }
  1769. void ThemeTypeDialog::_add_type_options_cbk(int p_index) {
  1770. add_type_filter->set_text(add_type_options->get_item_text(p_index));
  1771. }
  1772. void ThemeTypeDialog::_add_type_dialog_entered(const String &p_value) {
  1773. _add_type_selected(p_value.strip_edges());
  1774. }
  1775. void ThemeTypeDialog::_add_type_dialog_activated(int p_index) {
  1776. _add_type_selected(add_type_options->get_item_text(p_index));
  1777. }
  1778. void ThemeTypeDialog::_add_type_selected(const String &p_type_name) {
  1779. pre_submitted_value = p_type_name;
  1780. if (p_type_name.is_empty()) {
  1781. add_type_confirmation->popup_centered();
  1782. return;
  1783. }
  1784. _add_type_confirmed();
  1785. }
  1786. void ThemeTypeDialog::_add_type_confirmed() {
  1787. emit_signal(SNAME("type_selected"), pre_submitted_value);
  1788. hide();
  1789. }
  1790. void ThemeTypeDialog::_notification(int p_what) {
  1791. switch (p_what) {
  1792. case NOTIFICATION_ENTER_TREE: {
  1793. connect("about_to_popup", callable_mp(this, &ThemeTypeDialog::_dialog_about_to_show));
  1794. [[fallthrough]];
  1795. }
  1796. case NOTIFICATION_THEME_CHANGED: {
  1797. _update_add_type_options();
  1798. } break;
  1799. case NOTIFICATION_VISIBILITY_CHANGED: {
  1800. if (is_visible()) {
  1801. add_type_filter->grab_focus();
  1802. }
  1803. } break;
  1804. }
  1805. }
  1806. void ThemeTypeDialog::_bind_methods() {
  1807. ADD_SIGNAL(MethodInfo("type_selected", PropertyInfo(Variant::STRING, "type_name")));
  1808. }
  1809. void ThemeTypeDialog::set_edited_theme(const Ref<Theme> &p_theme) {
  1810. edited_theme = p_theme;
  1811. }
  1812. void ThemeTypeDialog::set_include_own_types(bool p_enable) {
  1813. include_own_types = p_enable;
  1814. }
  1815. ThemeTypeDialog::ThemeTypeDialog() {
  1816. set_hide_on_ok(false);
  1817. VBoxContainer *add_type_vb = memnew(VBoxContainer);
  1818. add_child(add_type_vb);
  1819. Label *add_type_filter_label = memnew(Label);
  1820. add_type_filter_label->set_text(TTR("Filter the list of types or create a new custom type:"));
  1821. add_type_vb->add_child(add_type_filter_label);
  1822. add_type_filter = memnew(LineEdit);
  1823. add_type_vb->add_child(add_type_filter);
  1824. add_type_filter->connect("text_changed", callable_mp(this, &ThemeTypeDialog::_add_type_filter_cbk));
  1825. add_type_filter->connect("text_submitted", callable_mp(this, &ThemeTypeDialog::_add_type_dialog_entered));
  1826. Label *add_type_options_label = memnew(Label);
  1827. add_type_options_label->set_text(TTR("Available Node-based types:"));
  1828. add_type_vb->add_child(add_type_options_label);
  1829. add_type_options = memnew(ItemList);
  1830. add_type_options->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1831. add_type_vb->add_child(add_type_options);
  1832. add_type_options->connect("item_selected", callable_mp(this, &ThemeTypeDialog::_add_type_options_cbk));
  1833. add_type_options->connect("item_activated", callable_mp(this, &ThemeTypeDialog::_add_type_dialog_activated));
  1834. add_type_confirmation = memnew(ConfirmationDialog);
  1835. add_type_confirmation->set_title(TTR("Type name is empty!"));
  1836. add_type_confirmation->set_text(TTR("Are you sure you want to create an empty type?"));
  1837. add_type_confirmation->connect("confirmed", callable_mp(this, &ThemeTypeDialog::_add_type_confirmed));
  1838. add_child(add_type_confirmation);
  1839. }
  1840. ///////////////////////
  1841. VBoxContainer *ThemeTypeEditor::_create_item_list(Theme::DataType p_data_type) {
  1842. VBoxContainer *items_tab = memnew(VBoxContainer);
  1843. items_tab->set_custom_minimum_size(Size2(0, 160) * EDSCALE);
  1844. data_type_tabs->add_child(items_tab);
  1845. data_type_tabs->set_tab_title(data_type_tabs->get_tab_count() - 1, "");
  1846. ScrollContainer *items_sc = memnew(ScrollContainer);
  1847. items_sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1848. items_sc->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  1849. items_tab->add_child(items_sc);
  1850. VBoxContainer *items_list = memnew(VBoxContainer);
  1851. items_list->set_h_size_flags(SIZE_EXPAND_FILL);
  1852. items_sc->add_child(items_list);
  1853. HBoxContainer *item_add_hb = memnew(HBoxContainer);
  1854. items_tab->add_child(item_add_hb);
  1855. LineEdit *item_add_edit = memnew(LineEdit);
  1856. item_add_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  1857. item_add_hb->add_child(item_add_edit);
  1858. item_add_edit->connect("text_submitted", callable_mp(this, &ThemeTypeEditor::_item_add_lineedit_cbk).bind(p_data_type, item_add_edit));
  1859. Button *item_add_button = memnew(Button);
  1860. item_add_button->set_text(TTR("Add"));
  1861. item_add_hb->add_child(item_add_button);
  1862. item_add_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_add_cbk).bind(p_data_type, item_add_edit));
  1863. return items_list;
  1864. }
  1865. void ThemeTypeEditor::_update_type_list() {
  1866. ERR_FAIL_COND(edited_theme.is_null());
  1867. if (updating) {
  1868. return;
  1869. }
  1870. updating = true;
  1871. Control *focused = get_viewport()->gui_get_focus_owner();
  1872. if (focused) {
  1873. if (focusables.has(focused)) {
  1874. // If focus is currently on one of the internal property editors, don't update.
  1875. updating = false;
  1876. return;
  1877. }
  1878. Node *focus_parent = focused->get_parent();
  1879. while (focus_parent) {
  1880. Control *c = Object::cast_to<Control>(focus_parent);
  1881. if (c && focusables.has(c)) {
  1882. // If focus is currently on one of the internal property editors, don't update.
  1883. updating = false;
  1884. return;
  1885. }
  1886. focus_parent = focus_parent->get_parent();
  1887. }
  1888. }
  1889. List<StringName> theme_types;
  1890. edited_theme->get_type_list(&theme_types);
  1891. theme_types.sort_custom<StringName::AlphCompare>();
  1892. theme_type_list->clear();
  1893. if (theme_types.size() > 0) {
  1894. theme_type_list->set_disabled(false);
  1895. bool item_reselected = false;
  1896. int e_idx = 0;
  1897. for (const StringName &E : theme_types) {
  1898. Ref<Texture2D> item_icon;
  1899. if (E == "") {
  1900. item_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons"));
  1901. } else {
  1902. item_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled");
  1903. }
  1904. theme_type_list->add_icon_item(item_icon, E);
  1905. if (E == edited_type) {
  1906. theme_type_list->select(e_idx);
  1907. item_reselected = true;
  1908. }
  1909. e_idx++;
  1910. }
  1911. if (!item_reselected) {
  1912. theme_type_list->select(0);
  1913. _list_type_selected(0);
  1914. } else {
  1915. _update_type_items();
  1916. }
  1917. } else {
  1918. theme_type_list->set_disabled(true);
  1919. theme_type_list->add_item(TTR("None"));
  1920. edited_type = "";
  1921. _update_type_items();
  1922. }
  1923. updating = false;
  1924. }
  1925. void ThemeTypeEditor::_update_type_list_debounced() {
  1926. update_debounce_timer->start();
  1927. }
  1928. HashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_name, void (Theme::*get_list_func)(StringName, List<StringName> *) const, bool include_default) {
  1929. HashMap<StringName, bool> items;
  1930. List<StringName> names;
  1931. if (include_default) {
  1932. names.clear();
  1933. String default_type = p_type_name;
  1934. if (edited_theme->get_type_variation_base(p_type_name) != StringName()) {
  1935. default_type = edited_theme->get_type_variation_base(p_type_name);
  1936. }
  1937. (ThemeDB::get_singleton()->get_default_theme().operator->()->*get_list_func)(default_type, &names);
  1938. names.sort_custom<StringName::AlphCompare>();
  1939. for (const StringName &E : names) {
  1940. items[E] = false;
  1941. }
  1942. }
  1943. {
  1944. names.clear();
  1945. (edited_theme.operator->()->*get_list_func)(p_type_name, &names);
  1946. names.sort_custom<StringName::AlphCompare>();
  1947. for (const StringName &E : names) {
  1948. items[E] = true;
  1949. }
  1950. }
  1951. List<StringName> keys;
  1952. for (const KeyValue<StringName, bool> &E : items) {
  1953. keys.push_back(E.key);
  1954. }
  1955. keys.sort_custom<StringName::AlphCompare>();
  1956. HashMap<StringName, bool> ordered_items;
  1957. for (const StringName &E : keys) {
  1958. ordered_items[E] = items[E];
  1959. }
  1960. return ordered_items;
  1961. }
  1962. HBoxContainer *ThemeTypeEditor::_create_property_control(Theme::DataType p_data_type, String p_item_name, bool p_editable) {
  1963. HBoxContainer *item_control = memnew(HBoxContainer);
  1964. HBoxContainer *item_name_container = memnew(HBoxContainer);
  1965. item_name_container->set_h_size_flags(SIZE_EXPAND_FILL);
  1966. item_name_container->set_stretch_ratio(2.0);
  1967. item_control->add_child(item_name_container);
  1968. Label *item_name = memnew(Label);
  1969. item_name->set_h_size_flags(SIZE_EXPAND_FILL);
  1970. item_name->set_clip_text(true);
  1971. item_name->set_text(p_item_name);
  1972. item_name->set_tooltip_text(p_item_name);
  1973. item_name_container->add_child(item_name);
  1974. if (p_editable) {
  1975. LineEdit *item_name_edit = memnew(LineEdit);
  1976. item_name_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  1977. item_name_edit->set_text(p_item_name);
  1978. item_name_container->add_child(item_name_edit);
  1979. item_name_edit->connect("text_submitted", callable_mp(this, &ThemeTypeEditor::_item_rename_entered).bind(p_data_type, p_item_name, item_name_container));
  1980. item_name_edit->hide();
  1981. Button *item_rename_button = memnew(Button);
  1982. item_rename_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
  1983. item_rename_button->set_tooltip_text(TTR("Rename Item"));
  1984. item_rename_button->set_flat(true);
  1985. item_name_container->add_child(item_rename_button);
  1986. item_rename_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_rename_cbk).bind(p_data_type, p_item_name, item_name_container));
  1987. Button *item_remove_button = memnew(Button);
  1988. item_remove_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
  1989. item_remove_button->set_tooltip_text(TTR("Remove Item"));
  1990. item_remove_button->set_flat(true);
  1991. item_name_container->add_child(item_remove_button);
  1992. item_remove_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_remove_cbk).bind(p_data_type, p_item_name));
  1993. Button *item_rename_confirm_button = memnew(Button);
  1994. item_rename_confirm_button->set_icon(get_theme_icon(SNAME("ImportCheck"), SNAME("EditorIcons")));
  1995. item_rename_confirm_button->set_tooltip_text(TTR("Confirm Item Rename"));
  1996. item_rename_confirm_button->set_flat(true);
  1997. item_name_container->add_child(item_rename_confirm_button);
  1998. item_rename_confirm_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_rename_confirmed).bind(p_data_type, p_item_name, item_name_container));
  1999. item_rename_confirm_button->hide();
  2000. Button *item_rename_cancel_button = memnew(Button);
  2001. item_rename_cancel_button->set_icon(get_theme_icon(SNAME("ImportFail"), SNAME("EditorIcons")));
  2002. item_rename_cancel_button->set_tooltip_text(TTR("Cancel Item Rename"));
  2003. item_rename_cancel_button->set_flat(true);
  2004. item_name_container->add_child(item_rename_cancel_button);
  2005. item_rename_cancel_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_rename_canceled).bind(p_data_type, p_item_name, item_name_container));
  2006. item_rename_cancel_button->hide();
  2007. } else {
  2008. item_name->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
  2009. Button *item_override_button = memnew(Button);
  2010. item_override_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
  2011. item_override_button->set_tooltip_text(TTR("Override Item"));
  2012. item_override_button->set_flat(true);
  2013. item_name_container->add_child(item_override_button);
  2014. item_override_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_override_cbk).bind(p_data_type, p_item_name));
  2015. }
  2016. return item_control;
  2017. }
  2018. void ThemeTypeEditor::_add_focusable(Control *p_control) {
  2019. focusables.append(p_control);
  2020. }
  2021. void ThemeTypeEditor::_update_type_items() {
  2022. bool show_default = show_default_items_button->is_pressed();
  2023. List<StringName> names;
  2024. focusables.clear();
  2025. // Colors.
  2026. {
  2027. for (int i = color_items_list->get_child_count() - 1; i >= 0; i--) {
  2028. Node *node = color_items_list->get_child(i);
  2029. node->queue_delete();
  2030. color_items_list->remove_child(node);
  2031. }
  2032. HashMap<StringName, bool> color_items = _get_type_items(edited_type, &Theme::get_color_list, show_default);
  2033. for (const KeyValue<StringName, bool> &E : color_items) {
  2034. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_COLOR, E.key, E.value);
  2035. ColorPickerButton *item_editor = memnew(ColorPickerButton);
  2036. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2037. item_control->add_child(item_editor);
  2038. if (E.value) {
  2039. item_editor->set_pick_color(edited_theme->get_color(E.key, edited_type));
  2040. item_editor->connect("color_changed", callable_mp(this, &ThemeTypeEditor::_color_item_changed).bind(E.key));
  2041. item_editor->get_popup()->connect("about_to_popup", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker).bind(item_editor->get_picker()));
  2042. } else {
  2043. item_editor->set_pick_color(ThemeDB::get_singleton()->get_default_theme()->get_color(E.key, edited_type));
  2044. item_editor->set_disabled(true);
  2045. }
  2046. _add_focusable(item_editor);
  2047. color_items_list->add_child(item_control);
  2048. }
  2049. }
  2050. // Constants.
  2051. {
  2052. for (int i = constant_items_list->get_child_count() - 1; i >= 0; i--) {
  2053. Node *node = constant_items_list->get_child(i);
  2054. node->queue_delete();
  2055. constant_items_list->remove_child(node);
  2056. }
  2057. HashMap<StringName, bool> constant_items = _get_type_items(edited_type, &Theme::get_constant_list, show_default);
  2058. for (const KeyValue<StringName, bool> &E : constant_items) {
  2059. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_CONSTANT, E.key, E.value);
  2060. SpinBox *item_editor = memnew(SpinBox);
  2061. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2062. item_editor->set_min(-100000);
  2063. item_editor->set_max(100000);
  2064. item_editor->set_step(1);
  2065. item_editor->set_allow_lesser(true);
  2066. item_editor->set_allow_greater(true);
  2067. item_control->add_child(item_editor);
  2068. if (E.value) {
  2069. item_editor->set_value(edited_theme->get_constant(E.key, edited_type));
  2070. item_editor->connect("value_changed", callable_mp(this, &ThemeTypeEditor::_constant_item_changed).bind(E.key));
  2071. } else {
  2072. item_editor->set_value(ThemeDB::get_singleton()->get_default_theme()->get_constant(E.key, edited_type));
  2073. item_editor->set_editable(false);
  2074. }
  2075. _add_focusable(item_editor);
  2076. constant_items_list->add_child(item_control);
  2077. }
  2078. }
  2079. // Fonts.
  2080. {
  2081. for (int i = font_items_list->get_child_count() - 1; i >= 0; i--) {
  2082. Node *node = font_items_list->get_child(i);
  2083. node->queue_delete();
  2084. font_items_list->remove_child(node);
  2085. }
  2086. HashMap<StringName, bool> font_items = _get_type_items(edited_type, &Theme::get_font_list, show_default);
  2087. for (const KeyValue<StringName, bool> &E : font_items) {
  2088. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_FONT, E.key, E.value);
  2089. EditorResourcePicker *item_editor = memnew(EditorResourcePicker);
  2090. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2091. item_editor->set_base_type("Font");
  2092. item_control->add_child(item_editor);
  2093. if (E.value) {
  2094. if (edited_theme->has_font(E.key, edited_type)) {
  2095. item_editor->set_edited_resource(edited_theme->get_font(E.key, edited_type));
  2096. } else {
  2097. item_editor->set_edited_resource(Ref<Resource>());
  2098. }
  2099. item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item));
  2100. item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_font_item_changed).bind(E.key));
  2101. } else {
  2102. if (ThemeDB::get_singleton()->get_default_theme()->has_font(E.key, edited_type)) {
  2103. item_editor->set_edited_resource(ThemeDB::get_singleton()->get_default_theme()->get_font(E.key, edited_type));
  2104. } else {
  2105. item_editor->set_edited_resource(Ref<Resource>());
  2106. }
  2107. item_editor->set_editable(false);
  2108. }
  2109. _add_focusable(item_editor);
  2110. font_items_list->add_child(item_control);
  2111. }
  2112. }
  2113. // Fonts sizes.
  2114. {
  2115. for (int i = font_size_items_list->get_child_count() - 1; i >= 0; i--) {
  2116. Node *node = font_size_items_list->get_child(i);
  2117. node->queue_delete();
  2118. font_size_items_list->remove_child(node);
  2119. }
  2120. HashMap<StringName, bool> font_size_items = _get_type_items(edited_type, &Theme::get_font_size_list, show_default);
  2121. for (const KeyValue<StringName, bool> &E : font_size_items) {
  2122. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_FONT_SIZE, E.key, E.value);
  2123. SpinBox *item_editor = memnew(SpinBox);
  2124. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2125. item_editor->set_min(-100000);
  2126. item_editor->set_max(100000);
  2127. item_editor->set_step(1);
  2128. item_editor->set_allow_lesser(true);
  2129. item_editor->set_allow_greater(true);
  2130. item_control->add_child(item_editor);
  2131. if (E.value) {
  2132. item_editor->set_value(edited_theme->get_font_size(E.key, edited_type));
  2133. item_editor->connect("value_changed", callable_mp(this, &ThemeTypeEditor::_font_size_item_changed).bind(E.key));
  2134. } else {
  2135. item_editor->set_value(ThemeDB::get_singleton()->get_default_theme()->get_font_size(E.key, edited_type));
  2136. item_editor->set_editable(false);
  2137. }
  2138. _add_focusable(item_editor);
  2139. font_size_items_list->add_child(item_control);
  2140. }
  2141. }
  2142. // Icons.
  2143. {
  2144. for (int i = icon_items_list->get_child_count() - 1; i >= 0; i--) {
  2145. Node *node = icon_items_list->get_child(i);
  2146. node->queue_delete();
  2147. icon_items_list->remove_child(node);
  2148. }
  2149. HashMap<StringName, bool> icon_items = _get_type_items(edited_type, &Theme::get_icon_list, show_default);
  2150. for (const KeyValue<StringName, bool> &E : icon_items) {
  2151. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_ICON, E.key, E.value);
  2152. EditorResourcePicker *item_editor = memnew(EditorResourcePicker);
  2153. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2154. item_editor->set_base_type("Texture2D");
  2155. item_control->add_child(item_editor);
  2156. if (E.value) {
  2157. if (edited_theme->has_icon(E.key, edited_type)) {
  2158. item_editor->set_edited_resource(edited_theme->get_icon(E.key, edited_type));
  2159. } else {
  2160. item_editor->set_edited_resource(Ref<Resource>());
  2161. }
  2162. item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item));
  2163. item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_icon_item_changed).bind(E.key));
  2164. } else {
  2165. if (ThemeDB::get_singleton()->get_default_theme()->has_icon(E.key, edited_type)) {
  2166. item_editor->set_edited_resource(ThemeDB::get_singleton()->get_default_theme()->get_icon(E.key, edited_type));
  2167. } else {
  2168. item_editor->set_edited_resource(Ref<Resource>());
  2169. }
  2170. item_editor->set_editable(false);
  2171. }
  2172. _add_focusable(item_editor);
  2173. icon_items_list->add_child(item_control);
  2174. }
  2175. }
  2176. // Styleboxes.
  2177. {
  2178. for (int i = stylebox_items_list->get_child_count() - 1; i >= 0; i--) {
  2179. Node *node = stylebox_items_list->get_child(i);
  2180. node->queue_delete();
  2181. stylebox_items_list->remove_child(node);
  2182. }
  2183. if (leading_stylebox.pinned) {
  2184. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_STYLEBOX, leading_stylebox.item_name, true);
  2185. EditorResourcePicker *item_editor = memnew(EditorResourcePicker);
  2186. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2187. item_editor->set_stretch_ratio(1.5);
  2188. item_editor->set_base_type("StyleBox");
  2189. Button *pin_leader_button = memnew(Button);
  2190. pin_leader_button->set_flat(true);
  2191. pin_leader_button->set_toggle_mode(true);
  2192. pin_leader_button->set_pressed(true);
  2193. pin_leader_button->set_icon(get_theme_icon(SNAME("Pin"), SNAME("EditorIcons")));
  2194. pin_leader_button->set_tooltip_text(TTR("Unpin this StyleBox as a main style."));
  2195. item_control->add_child(pin_leader_button);
  2196. pin_leader_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_on_unpin_leader_button_pressed));
  2197. item_control->add_child(item_editor);
  2198. if (edited_theme->has_stylebox(leading_stylebox.item_name, edited_type)) {
  2199. item_editor->set_edited_resource(leading_stylebox.stylebox);
  2200. } else {
  2201. item_editor->set_edited_resource(Ref<Resource>());
  2202. }
  2203. item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item));
  2204. item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_stylebox_item_changed).bind(leading_stylebox.item_name));
  2205. stylebox_items_list->add_child(item_control);
  2206. stylebox_items_list->add_child(memnew(HSeparator));
  2207. }
  2208. HashMap<StringName, bool> stylebox_items = _get_type_items(edited_type, &Theme::get_stylebox_list, show_default);
  2209. for (const KeyValue<StringName, bool> &E : stylebox_items) {
  2210. if (leading_stylebox.pinned && leading_stylebox.item_name == E.key) {
  2211. continue;
  2212. }
  2213. HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_STYLEBOX, E.key, E.value);
  2214. EditorResourcePicker *item_editor = memnew(EditorResourcePicker);
  2215. item_editor->set_h_size_flags(SIZE_EXPAND_FILL);
  2216. item_editor->set_stretch_ratio(1.5);
  2217. item_editor->set_base_type("StyleBox");
  2218. if (E.value) {
  2219. if (edited_theme->has_stylebox(E.key, edited_type)) {
  2220. item_editor->set_edited_resource(edited_theme->get_stylebox(E.key, edited_type));
  2221. } else {
  2222. item_editor->set_edited_resource(Ref<Resource>());
  2223. }
  2224. item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item));
  2225. item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_stylebox_item_changed).bind(E.key));
  2226. Button *pin_leader_button = memnew(Button);
  2227. pin_leader_button->set_flat(true);
  2228. pin_leader_button->set_toggle_mode(true);
  2229. pin_leader_button->set_icon(get_theme_icon(SNAME("Pin"), SNAME("EditorIcons")));
  2230. pin_leader_button->set_tooltip_text(TTR("Pin this StyleBox as a main style. Editing its properties will update the same properties in all other StyleBoxes of this type."));
  2231. item_control->add_child(pin_leader_button);
  2232. pin_leader_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_on_pin_leader_button_pressed).bind(item_editor, E.key));
  2233. } else {
  2234. if (ThemeDB::get_singleton()->get_default_theme()->has_stylebox(E.key, edited_type)) {
  2235. item_editor->set_edited_resource(ThemeDB::get_singleton()->get_default_theme()->get_stylebox(E.key, edited_type));
  2236. } else {
  2237. item_editor->set_edited_resource(Ref<Resource>());
  2238. }
  2239. item_editor->set_editable(false);
  2240. }
  2241. item_control->add_child(item_editor);
  2242. _add_focusable(item_editor);
  2243. stylebox_items_list->add_child(item_control);
  2244. }
  2245. }
  2246. // Various type settings.
  2247. if (edited_type.is_empty() || ClassDB::class_exists(edited_type)) {
  2248. type_variation_edit->set_editable(false);
  2249. type_variation_edit->set_text("");
  2250. type_variation_button->hide();
  2251. type_variation_locked->set_visible(!edited_type.is_empty());
  2252. } else {
  2253. type_variation_edit->set_editable(true);
  2254. type_variation_edit->set_text(edited_theme->get_type_variation_base(edited_type));
  2255. _add_focusable(type_variation_edit);
  2256. type_variation_button->show();
  2257. type_variation_locked->hide();
  2258. }
  2259. }
  2260. void ThemeTypeEditor::_list_type_selected(int p_index) {
  2261. edited_type = theme_type_list->get_item_text(p_index);
  2262. _update_type_items();
  2263. }
  2264. void ThemeTypeEditor::_add_type_button_cbk() {
  2265. add_type_mode = ADD_THEME_TYPE;
  2266. add_type_dialog->set_title(TTR("Add Item Type"));
  2267. add_type_dialog->set_ok_button_text(TTR("Add Type"));
  2268. add_type_dialog->set_include_own_types(false);
  2269. add_type_dialog->popup_centered(Size2(560, 420) * EDSCALE);
  2270. }
  2271. void ThemeTypeEditor::_add_default_type_items() {
  2272. List<StringName> names;
  2273. String default_type = edited_type;
  2274. if (edited_theme->get_type_variation_base(edited_type) != StringName()) {
  2275. default_type = edited_theme->get_type_variation_base(edited_type);
  2276. }
  2277. Ref<Theme> old_snapshot = edited_theme->duplicate();
  2278. Ref<Theme> new_snapshot = edited_theme->duplicate();
  2279. updating = true;
  2280. {
  2281. names.clear();
  2282. ThemeDB::get_singleton()->get_default_theme()->get_icon_list(default_type, &names);
  2283. for (const StringName &E : names) {
  2284. if (!new_snapshot->has_icon(E, edited_type)) {
  2285. new_snapshot->set_icon(E, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_icon(E, edited_type));
  2286. }
  2287. }
  2288. }
  2289. {
  2290. names.clear();
  2291. ThemeDB::get_singleton()->get_default_theme()->get_stylebox_list(default_type, &names);
  2292. for (const StringName &E : names) {
  2293. if (!new_snapshot->has_stylebox(E, edited_type)) {
  2294. new_snapshot->set_stylebox(E, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_stylebox(E, edited_type));
  2295. }
  2296. }
  2297. }
  2298. {
  2299. names.clear();
  2300. ThemeDB::get_singleton()->get_default_theme()->get_font_list(default_type, &names);
  2301. for (const StringName &E : names) {
  2302. if (!new_snapshot->has_font(E, edited_type)) {
  2303. new_snapshot->set_font(E, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_font(E, edited_type));
  2304. }
  2305. }
  2306. }
  2307. {
  2308. names.clear();
  2309. ThemeDB::get_singleton()->get_default_theme()->get_font_size_list(default_type, &names);
  2310. for (const StringName &E : names) {
  2311. if (!new_snapshot->has_font_size(E, edited_type)) {
  2312. new_snapshot->set_font_size(E, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_font_size(E, edited_type));
  2313. }
  2314. }
  2315. }
  2316. {
  2317. names.clear();
  2318. ThemeDB::get_singleton()->get_default_theme()->get_color_list(default_type, &names);
  2319. for (const StringName &E : names) {
  2320. if (!new_snapshot->has_color(E, edited_type)) {
  2321. new_snapshot->set_color(E, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_color(E, edited_type));
  2322. }
  2323. }
  2324. }
  2325. {
  2326. names.clear();
  2327. ThemeDB::get_singleton()->get_default_theme()->get_constant_list(default_type, &names);
  2328. for (const StringName &E : names) {
  2329. if (!new_snapshot->has_constant(E, edited_type)) {
  2330. new_snapshot->set_constant(E, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_constant(E, edited_type));
  2331. }
  2332. }
  2333. }
  2334. updating = false;
  2335. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2336. ur->create_action(TTR("Override All Default Theme Items"));
  2337. ur->add_do_method(*edited_theme, "merge_with", new_snapshot);
  2338. ur->add_undo_method(*edited_theme, "clear");
  2339. ur->add_undo_method(*edited_theme, "merge_with", old_snapshot);
  2340. ur->add_do_method(this, "_update_type_items");
  2341. ur->add_undo_method(this, "_update_type_items");
  2342. ur->commit_action();
  2343. }
  2344. void ThemeTypeEditor::_item_add_cbk(int p_data_type, Control *p_control) {
  2345. LineEdit *le = Object::cast_to<LineEdit>(p_control);
  2346. if (le->get_text().strip_edges().is_empty()) {
  2347. return;
  2348. }
  2349. String item_name = le->get_text().strip_edges();
  2350. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2351. ur->create_action(TTR("Add Theme Item"));
  2352. switch (p_data_type) {
  2353. case Theme::DATA_TYPE_COLOR: {
  2354. ur->add_do_method(*edited_theme, "set_color", item_name, edited_type, Color());
  2355. ur->add_undo_method(*edited_theme, "clear_color", item_name, edited_type);
  2356. } break;
  2357. case Theme::DATA_TYPE_CONSTANT: {
  2358. ur->add_do_method(*edited_theme, "set_constant", item_name, edited_type, 0);
  2359. ur->add_undo_method(*edited_theme, "clear_constant", item_name, edited_type);
  2360. } break;
  2361. case Theme::DATA_TYPE_FONT: {
  2362. ur->add_do_method(*edited_theme, "set_font", item_name, edited_type, Ref<Font>());
  2363. ur->add_undo_method(*edited_theme, "clear_font", item_name, edited_type);
  2364. } break;
  2365. case Theme::DATA_TYPE_FONT_SIZE: {
  2366. ur->add_do_method(*edited_theme, "set_font_size", item_name, edited_type, -1);
  2367. ur->add_undo_method(*edited_theme, "clear_font_size", item_name, edited_type);
  2368. } break;
  2369. case Theme::DATA_TYPE_ICON: {
  2370. ur->add_do_method(*edited_theme, "set_icon", item_name, edited_type, Ref<Texture2D>());
  2371. ur->add_undo_method(*edited_theme, "clear_icon", item_name, edited_type);
  2372. } break;
  2373. case Theme::DATA_TYPE_STYLEBOX: {
  2374. Ref<StyleBox> sb;
  2375. ur->add_do_method(*edited_theme, "set_stylebox", item_name, edited_type, sb);
  2376. ur->add_undo_method(*edited_theme, "clear_stylebox", item_name, edited_type);
  2377. if (is_stylebox_pinned(sb)) {
  2378. ur->add_undo_method(this, "_unpin_leading_stylebox");
  2379. }
  2380. } break;
  2381. }
  2382. ur->commit_action();
  2383. le->set_text("");
  2384. }
  2385. void ThemeTypeEditor::_item_add_lineedit_cbk(String p_value, int p_data_type, Control *p_control) {
  2386. _item_add_cbk(p_data_type, p_control);
  2387. }
  2388. void ThemeTypeEditor::_item_override_cbk(int p_data_type, String p_item_name) {
  2389. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2390. ur->create_action(TTR("Override Theme Item"));
  2391. switch (p_data_type) {
  2392. case Theme::DATA_TYPE_COLOR: {
  2393. ur->add_do_method(*edited_theme, "set_color", p_item_name, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_color(p_item_name, edited_type));
  2394. ur->add_undo_method(*edited_theme, "clear_color", p_item_name, edited_type);
  2395. } break;
  2396. case Theme::DATA_TYPE_CONSTANT: {
  2397. ur->add_do_method(*edited_theme, "set_constant", p_item_name, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_constant(p_item_name, edited_type));
  2398. ur->add_undo_method(*edited_theme, "clear_constant", p_item_name, edited_type);
  2399. } break;
  2400. case Theme::DATA_TYPE_FONT: {
  2401. ur->add_do_method(*edited_theme, "set_font", p_item_name, edited_type, Ref<Font>());
  2402. ur->add_undo_method(*edited_theme, "clear_font", p_item_name, edited_type);
  2403. } break;
  2404. case Theme::DATA_TYPE_FONT_SIZE: {
  2405. ur->add_do_method(*edited_theme, "set_font_size", p_item_name, edited_type, ThemeDB::get_singleton()->get_default_theme()->get_font_size(p_item_name, edited_type));
  2406. ur->add_undo_method(*edited_theme, "clear_font_size", p_item_name, edited_type);
  2407. } break;
  2408. case Theme::DATA_TYPE_ICON: {
  2409. ur->add_do_method(*edited_theme, "set_icon", p_item_name, edited_type, Ref<Texture2D>());
  2410. ur->add_undo_method(*edited_theme, "clear_icon", p_item_name, edited_type);
  2411. } break;
  2412. case Theme::DATA_TYPE_STYLEBOX: {
  2413. Ref<StyleBox> sb;
  2414. ur->add_do_method(*edited_theme, "set_stylebox", p_item_name, edited_type, sb);
  2415. ur->add_undo_method(*edited_theme, "clear_stylebox", p_item_name, edited_type);
  2416. if (is_stylebox_pinned(sb)) {
  2417. ur->add_undo_method(this, "_unpin_leading_stylebox");
  2418. }
  2419. } break;
  2420. }
  2421. ur->commit_action();
  2422. }
  2423. void ThemeTypeEditor::_item_remove_cbk(int p_data_type, String p_item_name) {
  2424. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2425. ur->create_action(TTR("Remove Theme Item"));
  2426. switch (p_data_type) {
  2427. case Theme::DATA_TYPE_COLOR: {
  2428. ur->add_do_method(*edited_theme, "clear_color", p_item_name, edited_type);
  2429. ur->add_undo_method(*edited_theme, "set_color", p_item_name, edited_type, edited_theme->get_color(p_item_name, edited_type));
  2430. } break;
  2431. case Theme::DATA_TYPE_CONSTANT: {
  2432. ur->add_do_method(*edited_theme, "clear_constant", p_item_name, edited_type);
  2433. ur->add_undo_method(*edited_theme, "set_constant", p_item_name, edited_type, edited_theme->get_constant(p_item_name, edited_type));
  2434. } break;
  2435. case Theme::DATA_TYPE_FONT: {
  2436. ur->add_do_method(*edited_theme, "clear_font", p_item_name, edited_type);
  2437. if (edited_theme->has_font(p_item_name, edited_type)) {
  2438. ur->add_undo_method(*edited_theme, "set_font", p_item_name, edited_type, edited_theme->get_font(p_item_name, edited_type));
  2439. } else {
  2440. ur->add_undo_method(*edited_theme, "set_font", p_item_name, edited_type, Ref<Font>());
  2441. }
  2442. } break;
  2443. case Theme::DATA_TYPE_ICON: {
  2444. ur->add_do_method(*edited_theme, "clear_icon", p_item_name, edited_type);
  2445. if (edited_theme->has_icon(p_item_name, edited_type)) {
  2446. ur->add_undo_method(*edited_theme, "set_icon", p_item_name, edited_type, edited_theme->get_icon(p_item_name, edited_type));
  2447. } else {
  2448. ur->add_undo_method(*edited_theme, "set_icon", p_item_name, edited_type, Ref<Texture2D>());
  2449. }
  2450. } break;
  2451. case Theme::DATA_TYPE_STYLEBOX: {
  2452. Ref<StyleBox> sb = edited_theme->get_stylebox(p_item_name, edited_type);
  2453. ur->add_do_method(*edited_theme, "clear_stylebox", p_item_name, edited_type);
  2454. if (edited_theme->has_stylebox(p_item_name, edited_type)) {
  2455. ur->add_undo_method(*edited_theme, "set_stylebox", p_item_name, edited_type, sb);
  2456. } else {
  2457. ur->add_undo_method(*edited_theme, "set_stylebox", p_item_name, edited_type, Ref<StyleBox>());
  2458. }
  2459. if (is_stylebox_pinned(sb)) {
  2460. ur->add_do_method(this, "_unpin_leading_stylebox");
  2461. ur->add_undo_method(this, "_pin_leading_stylebox", p_item_name, sb);
  2462. }
  2463. } break;
  2464. }
  2465. ur->commit_action();
  2466. }
  2467. void ThemeTypeEditor::_item_rename_cbk(int p_data_type, String p_item_name, Control *p_control) {
  2468. // Label
  2469. Object::cast_to<Label>(p_control->get_child(0))->hide();
  2470. // Label buttons
  2471. Object::cast_to<Button>(p_control->get_child(2))->hide();
  2472. Object::cast_to<Button>(p_control->get_child(3))->hide();
  2473. // LineEdit
  2474. Object::cast_to<LineEdit>(p_control->get_child(1))->set_text(p_item_name);
  2475. Object::cast_to<LineEdit>(p_control->get_child(1))->show();
  2476. // LineEdit buttons
  2477. Object::cast_to<Button>(p_control->get_child(4))->show();
  2478. Object::cast_to<Button>(p_control->get_child(5))->show();
  2479. }
  2480. void ThemeTypeEditor::_item_rename_confirmed(int p_data_type, String p_item_name, Control *p_control) {
  2481. LineEdit *le = Object::cast_to<LineEdit>(p_control->get_child(1));
  2482. if (le->get_text().strip_edges().is_empty()) {
  2483. return;
  2484. }
  2485. String new_name = le->get_text().strip_edges();
  2486. if (new_name == p_item_name) {
  2487. _item_rename_canceled(p_data_type, p_item_name, p_control);
  2488. return;
  2489. }
  2490. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2491. ur->create_action(TTR("Rename Theme Item"));
  2492. switch (p_data_type) {
  2493. case Theme::DATA_TYPE_COLOR: {
  2494. ur->add_do_method(*edited_theme, "rename_color", p_item_name, new_name, edited_type);
  2495. ur->add_undo_method(*edited_theme, "rename_color", new_name, p_item_name, edited_type);
  2496. } break;
  2497. case Theme::DATA_TYPE_CONSTANT: {
  2498. ur->add_do_method(*edited_theme, "rename_constant", p_item_name, new_name, edited_type);
  2499. ur->add_undo_method(*edited_theme, "rename_constant", new_name, p_item_name, edited_type);
  2500. } break;
  2501. case Theme::DATA_TYPE_FONT: {
  2502. ur->add_do_method(*edited_theme, "rename_font", p_item_name, new_name, edited_type);
  2503. ur->add_undo_method(*edited_theme, "rename_font", new_name, p_item_name, edited_type);
  2504. } break;
  2505. case Theme::DATA_TYPE_FONT_SIZE: {
  2506. ur->add_do_method(*edited_theme, "rename_font_size", p_item_name, new_name, edited_type);
  2507. ur->add_undo_method(*edited_theme, "rename_font_size", new_name, p_item_name, edited_type);
  2508. } break;
  2509. case Theme::DATA_TYPE_ICON: {
  2510. ur->add_do_method(*edited_theme, "rename_icon", p_item_name, new_name, edited_type);
  2511. ur->add_undo_method(*edited_theme, "rename_icon", new_name, p_item_name, edited_type);
  2512. } break;
  2513. case Theme::DATA_TYPE_STYLEBOX: {
  2514. ur->add_do_method(*edited_theme, "rename_stylebox", p_item_name, new_name, edited_type);
  2515. ur->add_undo_method(*edited_theme, "rename_stylebox", new_name, p_item_name, edited_type);
  2516. if (leading_stylebox.pinned && leading_stylebox.item_name == p_item_name) {
  2517. leading_stylebox.item_name = new_name;
  2518. }
  2519. } break;
  2520. }
  2521. ur->commit_action();
  2522. }
  2523. void ThemeTypeEditor::_item_rename_entered(String p_value, int p_data_type, String p_item_name, Control *p_control) {
  2524. _item_rename_confirmed(p_data_type, p_item_name, p_control);
  2525. }
  2526. void ThemeTypeEditor::_item_rename_canceled(int p_data_type, String p_item_name, Control *p_control) {
  2527. // LineEdit
  2528. Object::cast_to<LineEdit>(p_control->get_child(1))->hide();
  2529. // LineEdit buttons
  2530. Object::cast_to<Button>(p_control->get_child(4))->hide();
  2531. Object::cast_to<Button>(p_control->get_child(5))->hide();
  2532. // Label
  2533. Object::cast_to<Label>(p_control->get_child(0))->show();
  2534. // Label buttons
  2535. Object::cast_to<Button>(p_control->get_child(2))->show();
  2536. Object::cast_to<Button>(p_control->get_child(3))->show();
  2537. }
  2538. void ThemeTypeEditor::_color_item_changed(Color p_value, String p_item_name) {
  2539. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2540. ur->create_action(TTR("Set Color Item in Theme"), UndoRedo::MERGE_ENDS);
  2541. ur->add_do_method(*edited_theme, "set_color", p_item_name, edited_type, p_value);
  2542. ur->add_undo_method(*edited_theme, "set_color", p_item_name, edited_type, edited_theme->get_color(p_item_name, edited_type));
  2543. ur->commit_action();
  2544. }
  2545. void ThemeTypeEditor::_constant_item_changed(float p_value, String p_item_name) {
  2546. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2547. ur->create_action(TTR("Set Constant Item in Theme"));
  2548. ur->add_do_method(*edited_theme, "set_constant", p_item_name, edited_type, p_value);
  2549. ur->add_undo_method(*edited_theme, "set_constant", p_item_name, edited_type, edited_theme->get_constant(p_item_name, edited_type));
  2550. ur->commit_action();
  2551. }
  2552. void ThemeTypeEditor::_font_size_item_changed(float p_value, String p_item_name) {
  2553. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2554. ur->create_action(TTR("Set Font Size Item in Theme"));
  2555. ur->add_do_method(*edited_theme, "set_font_size", p_item_name, edited_type, p_value);
  2556. ur->add_undo_method(*edited_theme, "set_font_size", p_item_name, edited_type, edited_theme->get_font_size(p_item_name, edited_type));
  2557. ur->commit_action();
  2558. }
  2559. void ThemeTypeEditor::_edit_resource_item(Ref<Resource> p_resource, bool p_edit) {
  2560. EditorNode::get_singleton()->edit_resource(p_resource);
  2561. }
  2562. void ThemeTypeEditor::_font_item_changed(Ref<Font> p_value, String p_item_name) {
  2563. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2564. ur->create_action(TTR("Set Font Item in Theme"));
  2565. ur->add_do_method(*edited_theme, "set_font", p_item_name, edited_type, p_value.is_valid() ? p_value : Ref<Font>());
  2566. if (edited_theme->has_font(p_item_name, edited_type)) {
  2567. ur->add_undo_method(*edited_theme, "set_font", p_item_name, edited_type, edited_theme->get_font(p_item_name, edited_type));
  2568. } else {
  2569. ur->add_undo_method(*edited_theme, "set_font", p_item_name, edited_type, Ref<Font>());
  2570. }
  2571. ur->add_do_method(this, "call_deferred", "_update_type_items");
  2572. ur->add_undo_method(this, "call_deferred", "_update_type_items");
  2573. ur->commit_action();
  2574. }
  2575. void ThemeTypeEditor::_icon_item_changed(Ref<Texture2D> p_value, String p_item_name) {
  2576. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2577. ur->create_action(TTR("Set Icon Item in Theme"));
  2578. ur->add_do_method(*edited_theme, "set_icon", p_item_name, edited_type, p_value.is_valid() ? p_value : Ref<Texture2D>());
  2579. if (edited_theme->has_icon(p_item_name, edited_type)) {
  2580. ur->add_undo_method(*edited_theme, "set_icon", p_item_name, edited_type, edited_theme->get_icon(p_item_name, edited_type));
  2581. } else {
  2582. ur->add_undo_method(*edited_theme, "set_icon", p_item_name, edited_type, Ref<Texture2D>());
  2583. }
  2584. ur->add_do_method(this, "call_deferred", "_update_type_items");
  2585. ur->add_undo_method(this, "call_deferred", "_update_type_items");
  2586. ur->commit_action();
  2587. }
  2588. void ThemeTypeEditor::_stylebox_item_changed(Ref<StyleBox> p_value, String p_item_name) {
  2589. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2590. ur->create_action(TTR("Set Stylebox Item in Theme"));
  2591. ur->add_do_method(*edited_theme, "set_stylebox", p_item_name, edited_type, p_value.is_valid() ? p_value : Ref<StyleBox>());
  2592. if (edited_theme->has_stylebox(p_item_name, edited_type)) {
  2593. ur->add_undo_method(*edited_theme, "set_stylebox", p_item_name, edited_type, edited_theme->get_stylebox(p_item_name, edited_type));
  2594. } else {
  2595. ur->add_undo_method(*edited_theme, "set_stylebox", p_item_name, edited_type, Ref<StyleBox>());
  2596. }
  2597. ur->add_do_method(this, "_change_pinned_stylebox");
  2598. ur->add_undo_method(this, "_change_pinned_stylebox");
  2599. ur->add_do_method(this, "call_deferred", "_update_type_items");
  2600. ur->add_undo_method(this, "call_deferred", "_update_type_items");
  2601. ur->commit_action();
  2602. }
  2603. void ThemeTypeEditor::_change_pinned_stylebox() {
  2604. if (leading_stylebox.pinned) {
  2605. if (leading_stylebox.stylebox.is_valid()) {
  2606. leading_stylebox.stylebox->disconnect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading));
  2607. }
  2608. Ref<StyleBox> new_stylebox = edited_theme->get_stylebox(leading_stylebox.item_name, edited_type);
  2609. leading_stylebox.stylebox = new_stylebox;
  2610. leading_stylebox.ref_stylebox = (new_stylebox.is_valid() ? new_stylebox->duplicate() : Ref<Resource>());
  2611. if (leading_stylebox.stylebox.is_valid()) {
  2612. new_stylebox->connect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading));
  2613. }
  2614. } else if (leading_stylebox.stylebox.is_valid()) {
  2615. leading_stylebox.stylebox->disconnect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading));
  2616. }
  2617. }
  2618. void ThemeTypeEditor::_on_pin_leader_button_pressed(Control *p_editor, String p_item_name) {
  2619. Ref<StyleBox> stylebox;
  2620. if (Object::cast_to<EditorResourcePicker>(p_editor)) {
  2621. stylebox = Object::cast_to<EditorResourcePicker>(p_editor)->get_edited_resource();
  2622. }
  2623. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2624. ur->create_action(TTR("Pin Stylebox"));
  2625. ur->add_do_method(this, "_pin_leading_stylebox", p_item_name, stylebox);
  2626. if (leading_stylebox.pinned) {
  2627. ur->add_undo_method(this, "_pin_leading_stylebox", leading_stylebox.item_name, leading_stylebox.stylebox);
  2628. } else {
  2629. ur->add_undo_method(this, "_unpin_leading_stylebox");
  2630. }
  2631. ur->commit_action();
  2632. }
  2633. void ThemeTypeEditor::_pin_leading_stylebox(String p_item_name, Ref<StyleBox> p_stylebox) {
  2634. if (leading_stylebox.stylebox.is_valid()) {
  2635. leading_stylebox.stylebox->disconnect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading));
  2636. }
  2637. LeadingStylebox leader;
  2638. leader.pinned = true;
  2639. leader.item_name = p_item_name;
  2640. leader.stylebox = p_stylebox;
  2641. leader.ref_stylebox = (p_stylebox.is_valid() ? p_stylebox->duplicate() : Ref<Resource>());
  2642. leading_stylebox = leader;
  2643. if (p_stylebox.is_valid()) {
  2644. p_stylebox->connect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading));
  2645. }
  2646. _update_type_items();
  2647. }
  2648. void ThemeTypeEditor::_on_unpin_leader_button_pressed() {
  2649. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2650. ur->create_action(TTR("Unpin Stylebox"));
  2651. ur->add_do_method(this, "_unpin_leading_stylebox");
  2652. ur->add_undo_method(this, "_pin_leading_stylebox", leading_stylebox.item_name, leading_stylebox.stylebox);
  2653. ur->commit_action();
  2654. }
  2655. void ThemeTypeEditor::_unpin_leading_stylebox() {
  2656. if (leading_stylebox.stylebox.is_valid()) {
  2657. leading_stylebox.stylebox->disconnect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading));
  2658. }
  2659. LeadingStylebox leader;
  2660. leader.pinned = false;
  2661. leading_stylebox = leader;
  2662. _update_type_items();
  2663. }
  2664. void ThemeTypeEditor::_update_stylebox_from_leading() {
  2665. if (!leading_stylebox.pinned || leading_stylebox.stylebox.is_null()) {
  2666. return;
  2667. }
  2668. // Prevent changes from immediately being reported while the operation is still ongoing.
  2669. edited_theme->_freeze_change_propagation();
  2670. List<StringName> names;
  2671. edited_theme->get_stylebox_list(edited_type, &names);
  2672. List<Ref<StyleBox>> styleboxes;
  2673. for (const StringName &E : names) {
  2674. Ref<StyleBox> sb = edited_theme->get_stylebox(E, edited_type);
  2675. // Avoid itself, stylebox can be shared between items.
  2676. if (sb == leading_stylebox.stylebox) {
  2677. continue;
  2678. }
  2679. if (sb->get_class() == leading_stylebox.stylebox->get_class()) {
  2680. styleboxes.push_back(sb);
  2681. }
  2682. }
  2683. List<PropertyInfo> props;
  2684. leading_stylebox.stylebox->get_property_list(&props);
  2685. for (const PropertyInfo &E : props) {
  2686. if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
  2687. continue;
  2688. }
  2689. Variant value = leading_stylebox.stylebox->get(E.name);
  2690. Variant ref_value = leading_stylebox.ref_stylebox->get(E.name);
  2691. if (value == ref_value) {
  2692. continue;
  2693. }
  2694. for (const Ref<StyleBox> &F : styleboxes) {
  2695. Ref<StyleBox> sb = F;
  2696. sb->set(E.name, value);
  2697. }
  2698. }
  2699. leading_stylebox.ref_stylebox = leading_stylebox.stylebox->duplicate();
  2700. // Allow changes to be reported now that the operation is finished.
  2701. edited_theme->_unfreeze_and_propagate_changes();
  2702. }
  2703. void ThemeTypeEditor::_type_variation_changed(const String p_value) {
  2704. Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo();
  2705. ur->create_action(TTR("Set Theme Type Variation"));
  2706. if (p_value.is_empty()) {
  2707. ur->add_do_method(*edited_theme, "clear_type_variation", edited_type);
  2708. } else {
  2709. ur->add_do_method(*edited_theme, "set_type_variation", edited_type, StringName(p_value));
  2710. }
  2711. if (edited_theme->get_type_variation_base(edited_type) == "") {
  2712. ur->add_undo_method(*edited_theme, "clear_type_variation", edited_type);
  2713. } else {
  2714. ur->add_undo_method(*edited_theme, "set_type_variation", edited_type, edited_theme->get_type_variation_base(edited_type));
  2715. }
  2716. ur->commit_action();
  2717. }
  2718. void ThemeTypeEditor::_add_type_variation_cbk() {
  2719. add_type_mode = ADD_VARIATION_BASE;
  2720. add_type_dialog->set_title(TTR("Set Variation Base Type"));
  2721. add_type_dialog->set_ok_button_text(TTR("Set Base Type"));
  2722. add_type_dialog->set_include_own_types(true);
  2723. add_type_dialog->popup_centered(Size2(560, 420) * EDSCALE);
  2724. }
  2725. void ThemeTypeEditor::_add_type_dialog_selected(const String p_type_name) {
  2726. if (add_type_mode == ADD_THEME_TYPE) {
  2727. select_type(p_type_name);
  2728. } else if (add_type_mode == ADD_VARIATION_BASE) {
  2729. _type_variation_changed(p_type_name);
  2730. }
  2731. }
  2732. void ThemeTypeEditor::_notification(int p_what) {
  2733. switch (p_what) {
  2734. case NOTIFICATION_ENTER_TREE:
  2735. case NOTIFICATION_THEME_CHANGED: {
  2736. add_type_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
  2737. data_type_tabs->set_tab_icon(0, get_theme_icon(SNAME("Color"), SNAME("EditorIcons")));
  2738. data_type_tabs->set_tab_icon(1, get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")));
  2739. data_type_tabs->set_tab_icon(2, get_theme_icon(SNAME("Font"), SNAME("EditorIcons")));
  2740. data_type_tabs->set_tab_icon(3, get_theme_icon(SNAME("FontSize"), SNAME("EditorIcons")));
  2741. data_type_tabs->set_tab_icon(4, get_theme_icon(SNAME("ImageTexture"), SNAME("EditorIcons")));
  2742. data_type_tabs->set_tab_icon(5, get_theme_icon(SNAME("StyleBoxFlat"), SNAME("EditorIcons")));
  2743. data_type_tabs->set_tab_icon(6, get_theme_icon(SNAME("Tools"), SNAME("EditorIcons")));
  2744. type_variation_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
  2745. } break;
  2746. }
  2747. }
  2748. void ThemeTypeEditor::_bind_methods() {
  2749. ClassDB::bind_method(D_METHOD("_update_type_items"), &ThemeTypeEditor::_update_type_items);
  2750. ClassDB::bind_method(D_METHOD("_pin_leading_stylebox"), &ThemeTypeEditor::_pin_leading_stylebox);
  2751. ClassDB::bind_method(D_METHOD("_unpin_leading_stylebox"), &ThemeTypeEditor::_unpin_leading_stylebox);
  2752. ClassDB::bind_method(D_METHOD("_change_pinned_stylebox"), &ThemeTypeEditor::_change_pinned_stylebox);
  2753. }
  2754. void ThemeTypeEditor::set_edited_theme(const Ref<Theme> &p_theme) {
  2755. if (edited_theme.is_valid()) {
  2756. edited_theme->disconnect("changed", callable_mp(this, &ThemeTypeEditor::_update_type_list_debounced));
  2757. }
  2758. edited_theme = p_theme;
  2759. edited_theme->connect("changed", callable_mp(this, &ThemeTypeEditor::_update_type_list_debounced));
  2760. _update_type_list();
  2761. add_type_dialog->set_edited_theme(edited_theme);
  2762. }
  2763. void ThemeTypeEditor::select_type(String p_type_name) {
  2764. edited_type = p_type_name;
  2765. bool type_exists = false;
  2766. for (int i = 0; i < theme_type_list->get_item_count(); i++) {
  2767. String type_name = theme_type_list->get_item_text(i);
  2768. if (type_name == edited_type) {
  2769. theme_type_list->select(i);
  2770. type_exists = true;
  2771. break;
  2772. }
  2773. }
  2774. if (type_exists) {
  2775. _update_type_items();
  2776. } else {
  2777. edited_theme->add_icon_type(edited_type);
  2778. edited_theme->add_stylebox_type(edited_type);
  2779. edited_theme->add_font_type(edited_type);
  2780. edited_theme->add_font_size_type(edited_type);
  2781. edited_theme->add_color_type(edited_type);
  2782. edited_theme->add_constant_type(edited_type);
  2783. _update_type_list();
  2784. }
  2785. }
  2786. bool ThemeTypeEditor::is_stylebox_pinned(Ref<StyleBox> p_stylebox) {
  2787. return leading_stylebox.pinned && leading_stylebox.stylebox == p_stylebox;
  2788. }
  2789. ThemeTypeEditor::ThemeTypeEditor() {
  2790. VBoxContainer *main_vb = memnew(VBoxContainer);
  2791. add_child(main_vb);
  2792. HBoxContainer *type_list_hb = memnew(HBoxContainer);
  2793. main_vb->add_child(type_list_hb);
  2794. Label *type_list_label = memnew(Label);
  2795. type_list_label->set_text(TTR("Type:"));
  2796. type_list_hb->add_child(type_list_label);
  2797. theme_type_list = memnew(OptionButton);
  2798. theme_type_list->set_h_size_flags(SIZE_EXPAND_FILL);
  2799. theme_type_list->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  2800. type_list_hb->add_child(theme_type_list);
  2801. theme_type_list->connect("item_selected", callable_mp(this, &ThemeTypeEditor::_list_type_selected));
  2802. add_type_button = memnew(Button);
  2803. add_type_button->set_tooltip_text(TTR("Add a type from a list of available types or create a new one."));
  2804. type_list_hb->add_child(add_type_button);
  2805. add_type_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_add_type_button_cbk));
  2806. HBoxContainer *type_controls = memnew(HBoxContainer);
  2807. main_vb->add_child(type_controls);
  2808. show_default_items_button = memnew(CheckButton);
  2809. show_default_items_button->set_h_size_flags(SIZE_EXPAND_FILL);
  2810. show_default_items_button->set_text(TTR("Show Default"));
  2811. show_default_items_button->set_tooltip_text(TTR("Show default type items alongside items that have been overridden."));
  2812. show_default_items_button->set_pressed(true);
  2813. type_controls->add_child(show_default_items_button);
  2814. show_default_items_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_update_type_items));
  2815. Button *add_default_items_button = memnew(Button);
  2816. add_default_items_button->set_h_size_flags(SIZE_EXPAND_FILL);
  2817. add_default_items_button->set_text(TTR("Override All"));
  2818. add_default_items_button->set_tooltip_text(TTR("Override all default type items."));
  2819. type_controls->add_child(add_default_items_button);
  2820. add_default_items_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_add_default_type_items));
  2821. data_type_tabs = memnew(TabContainer);
  2822. data_type_tabs->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  2823. main_vb->add_child(data_type_tabs);
  2824. data_type_tabs->set_v_size_flags(SIZE_EXPAND_FILL);
  2825. data_type_tabs->set_use_hidden_tabs_for_min_size(true);
  2826. data_type_tabs->set_theme_type_variation("TabContainerOdd");
  2827. color_items_list = _create_item_list(Theme::DATA_TYPE_COLOR);
  2828. constant_items_list = _create_item_list(Theme::DATA_TYPE_CONSTANT);
  2829. font_items_list = _create_item_list(Theme::DATA_TYPE_FONT);
  2830. font_size_items_list = _create_item_list(Theme::DATA_TYPE_FONT_SIZE);
  2831. icon_items_list = _create_item_list(Theme::DATA_TYPE_ICON);
  2832. stylebox_items_list = _create_item_list(Theme::DATA_TYPE_STYLEBOX);
  2833. VBoxContainer *type_settings_tab = memnew(VBoxContainer);
  2834. type_settings_tab->set_custom_minimum_size(Size2(0, 160) * EDSCALE);
  2835. data_type_tabs->add_child(type_settings_tab);
  2836. data_type_tabs->set_tab_title(data_type_tabs->get_tab_count() - 1, "");
  2837. ScrollContainer *type_settings_sc = memnew(ScrollContainer);
  2838. type_settings_sc->set_v_size_flags(SIZE_EXPAND_FILL);
  2839. type_settings_sc->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  2840. type_settings_tab->add_child(type_settings_sc);
  2841. VBoxContainer *type_settings_list = memnew(VBoxContainer);
  2842. type_settings_list->set_h_size_flags(SIZE_EXPAND_FILL);
  2843. type_settings_sc->add_child(type_settings_list);
  2844. VBoxContainer *type_variation_vb = memnew(VBoxContainer);
  2845. type_settings_list->add_child(type_variation_vb);
  2846. HBoxContainer *type_variation_hb = memnew(HBoxContainer);
  2847. type_variation_vb->add_child(type_variation_hb);
  2848. Label *type_variation_label = memnew(Label);
  2849. type_variation_hb->add_child(type_variation_label);
  2850. type_variation_label->set_text(TTR("Base Type"));
  2851. type_variation_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2852. type_variation_edit = memnew(LineEdit);
  2853. type_variation_hb->add_child(type_variation_edit);
  2854. type_variation_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2855. type_variation_edit->connect("text_changed", callable_mp(this, &ThemeTypeEditor::_type_variation_changed));
  2856. type_variation_edit->connect("focus_exited", callable_mp(this, &ThemeTypeEditor::_update_type_items));
  2857. type_variation_button = memnew(Button);
  2858. type_variation_hb->add_child(type_variation_button);
  2859. type_variation_button->set_tooltip_text(TTR("Select the variation base type from a list of available types."));
  2860. type_variation_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_add_type_variation_cbk));
  2861. type_variation_locked = memnew(Label);
  2862. type_variation_vb->add_child(type_variation_locked);
  2863. type_variation_locked->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  2864. type_variation_locked->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  2865. type_variation_locked->set_text(TTR("A type associated with a built-in class cannot be marked as a variation of another type."));
  2866. type_variation_locked->hide();
  2867. add_type_dialog = memnew(ThemeTypeDialog);
  2868. add_child(add_type_dialog);
  2869. add_type_dialog->connect("type_selected", callable_mp(this, &ThemeTypeEditor::_add_type_dialog_selected));
  2870. update_debounce_timer = memnew(Timer);
  2871. update_debounce_timer->set_one_shot(true);
  2872. update_debounce_timer->set_wait_time(0.5);
  2873. update_debounce_timer->connect("timeout", callable_mp(this, &ThemeTypeEditor::_update_type_list));
  2874. add_child(update_debounce_timer);
  2875. }
  2876. ///////////////////////
  2877. void ThemeEditor::edit(const Ref<Theme> &p_theme) {
  2878. if (theme == p_theme) {
  2879. return;
  2880. }
  2881. theme = p_theme;
  2882. theme_type_editor->set_edited_theme(p_theme);
  2883. theme_edit_dialog->set_edited_theme(p_theme);
  2884. for (int i = 0; i < preview_tabs_content->get_child_count(); i++) {
  2885. ThemeEditorPreview *preview_tab = Object::cast_to<ThemeEditorPreview>(preview_tabs_content->get_child(i));
  2886. if (!preview_tab) {
  2887. continue;
  2888. }
  2889. preview_tab->set_preview_theme(p_theme);
  2890. }
  2891. theme_name->set_text(TTR("Theme:") + " " + theme->get_path().get_file());
  2892. }
  2893. Ref<Theme> ThemeEditor::get_edited_theme() {
  2894. return theme;
  2895. }
  2896. void ThemeEditor::_theme_save_button_cbk(bool p_save_as) {
  2897. ERR_FAIL_COND_MSG(theme.is_null(), "Invalid state of the Theme Editor; the Theme resource is missing.");
  2898. if (p_save_as) {
  2899. EditorNode::get_singleton()->save_resource_as(theme);
  2900. } else {
  2901. EditorNode::get_singleton()->save_resource(theme);
  2902. }
  2903. }
  2904. void ThemeEditor::_theme_edit_button_cbk() {
  2905. theme_edit_dialog->popup_centered(Size2(850, 700) * EDSCALE);
  2906. }
  2907. void ThemeEditor::_add_preview_button_cbk() {
  2908. preview_scene_dialog->popup_file_dialog();
  2909. }
  2910. void ThemeEditor::_preview_scene_dialog_cbk(const String &p_path) {
  2911. SceneThemeEditorPreview *preview_tab = memnew(SceneThemeEditorPreview);
  2912. if (!preview_tab->set_preview_scene(p_path)) {
  2913. return;
  2914. }
  2915. _add_preview_tab(preview_tab, p_path.get_file(), get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")));
  2916. preview_tab->connect("scene_invalidated", callable_mp(this, &ThemeEditor::_remove_preview_tab_invalid).bind(preview_tab));
  2917. preview_tab->connect("scene_reloaded", callable_mp(this, &ThemeEditor::_update_preview_tab).bind(preview_tab));
  2918. }
  2919. void ThemeEditor::_add_preview_tab(ThemeEditorPreview *p_preview_tab, const String &p_preview_name, const Ref<Texture2D> &p_icon) {
  2920. p_preview_tab->set_preview_theme(theme);
  2921. preview_tabs->add_tab(p_preview_name, p_icon);
  2922. preview_tabs_content->add_child(p_preview_tab);
  2923. preview_tabs->set_tab_button_icon(preview_tabs->get_tab_count() - 1, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("close"), SNAME("TabBar")));
  2924. p_preview_tab->connect("control_picked", callable_mp(this, &ThemeEditor::_preview_control_picked));
  2925. preview_tabs->set_current_tab(preview_tabs->get_tab_count() - 1);
  2926. }
  2927. void ThemeEditor::_change_preview_tab(int p_tab) {
  2928. ERR_FAIL_INDEX_MSG(p_tab, preview_tabs_content->get_child_count(), "Attempting to open a preview tab that doesn't exist.");
  2929. for (int i = 0; i < preview_tabs_content->get_child_count(); i++) {
  2930. Control *c = Object::cast_to<Control>(preview_tabs_content->get_child(i));
  2931. if (!c) {
  2932. continue;
  2933. }
  2934. c->set_visible(i == p_tab);
  2935. }
  2936. }
  2937. void ThemeEditor::_remove_preview_tab(int p_tab) {
  2938. ERR_FAIL_INDEX_MSG(p_tab, preview_tabs_content->get_child_count(), "Attempting to remove a preview tab that doesn't exist.");
  2939. ThemeEditorPreview *preview_tab = Object::cast_to<ThemeEditorPreview>(preview_tabs_content->get_child(p_tab));
  2940. ERR_FAIL_COND_MSG(Object::cast_to<DefaultThemeEditorPreview>(preview_tab), "Attemptying to remove the default preview tab.");
  2941. if (preview_tab) {
  2942. preview_tab->disconnect("control_picked", callable_mp(this, &ThemeEditor::_preview_control_picked));
  2943. if (preview_tab->is_connected("scene_invalidated", callable_mp(this, &ThemeEditor::_remove_preview_tab_invalid))) {
  2944. preview_tab->disconnect("scene_invalidated", callable_mp(this, &ThemeEditor::_remove_preview_tab_invalid));
  2945. }
  2946. if (preview_tab->is_connected("scene_reloaded", callable_mp(this, &ThemeEditor::_update_preview_tab))) {
  2947. preview_tab->disconnect("scene_reloaded", callable_mp(this, &ThemeEditor::_update_preview_tab));
  2948. }
  2949. preview_tabs_content->remove_child(preview_tab);
  2950. preview_tabs->remove_tab(p_tab);
  2951. _change_preview_tab(preview_tabs->get_current_tab());
  2952. }
  2953. }
  2954. void ThemeEditor::_remove_preview_tab_invalid(Node *p_tab_control) {
  2955. int tab_index = p_tab_control->get_index();
  2956. _remove_preview_tab(tab_index);
  2957. }
  2958. void ThemeEditor::_update_preview_tab(Node *p_tab_control) {
  2959. if (!Object::cast_to<SceneThemeEditorPreview>(p_tab_control)) {
  2960. return;
  2961. }
  2962. int tab_index = p_tab_control->get_index();
  2963. SceneThemeEditorPreview *scene_preview = Object::cast_to<SceneThemeEditorPreview>(p_tab_control);
  2964. preview_tabs->set_tab_title(tab_index, scene_preview->get_preview_scene_path().get_file());
  2965. }
  2966. void ThemeEditor::_preview_control_picked(String p_class_name) {
  2967. theme_type_editor->select_type(p_class_name);
  2968. }
  2969. void ThemeEditor::_notification(int p_what) {
  2970. switch (p_what) {
  2971. case NOTIFICATION_ENTER_TREE:
  2972. case NOTIFICATION_THEME_CHANGED: {
  2973. preview_tabs->add_theme_style_override("tab_selected", get_theme_stylebox(SNAME("ThemeEditorPreviewFG"), SNAME("EditorStyles")));
  2974. preview_tabs->add_theme_style_override("tab_unselected", get_theme_stylebox(SNAME("ThemeEditorPreviewBG"), SNAME("EditorStyles")));
  2975. preview_tabs_content->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("TabContainerOdd")));
  2976. add_preview_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
  2977. } break;
  2978. }
  2979. }
  2980. ThemeEditor::ThemeEditor() {
  2981. HBoxContainer *top_menu = memnew(HBoxContainer);
  2982. add_child(top_menu);
  2983. theme_name = memnew(Label);
  2984. theme_name->set_text(TTR("Theme:"));
  2985. theme_name->set_theme_type_variation("HeaderSmall");
  2986. top_menu->add_child(theme_name);
  2987. top_menu->add_spacer(false);
  2988. Button *theme_save_button = memnew(Button);
  2989. theme_save_button->set_text(TTR("Save"));
  2990. theme_save_button->set_flat(true);
  2991. theme_save_button->connect("pressed", callable_mp(this, &ThemeEditor::_theme_save_button_cbk).bind(false));
  2992. top_menu->add_child(theme_save_button);
  2993. Button *theme_save_as_button = memnew(Button);
  2994. theme_save_as_button->set_text(TTR("Save As..."));
  2995. theme_save_as_button->set_flat(true);
  2996. theme_save_as_button->connect("pressed", callable_mp(this, &ThemeEditor::_theme_save_button_cbk).bind(true));
  2997. top_menu->add_child(theme_save_as_button);
  2998. top_menu->add_child(memnew(VSeparator));
  2999. Button *theme_edit_button = memnew(Button);
  3000. theme_edit_button->set_text(TTR("Manage Items..."));
  3001. theme_edit_button->set_tooltip_text(TTR("Add, remove, organize and import Theme items."));
  3002. theme_edit_button->set_flat(true);
  3003. theme_edit_button->connect("pressed", callable_mp(this, &ThemeEditor::_theme_edit_button_cbk));
  3004. top_menu->add_child(theme_edit_button);
  3005. theme_type_editor = memnew(ThemeTypeEditor);
  3006. theme_edit_dialog = memnew(ThemeItemEditorDialog(theme_type_editor));
  3007. theme_edit_dialog->hide();
  3008. top_menu->add_child(theme_edit_dialog);
  3009. HSplitContainer *main_hs = memnew(HSplitContainer);
  3010. main_hs->set_v_size_flags(SIZE_EXPAND_FILL);
  3011. add_child(main_hs);
  3012. VBoxContainer *preview_tabs_vb = memnew(VBoxContainer);
  3013. preview_tabs_vb->set_h_size_flags(SIZE_EXPAND_FILL);
  3014. preview_tabs_vb->set_custom_minimum_size(Size2(520, 0) * EDSCALE);
  3015. preview_tabs_vb->add_theme_constant_override("separation", 2 * EDSCALE);
  3016. main_hs->add_child(preview_tabs_vb);
  3017. HBoxContainer *preview_tabbar_hb = memnew(HBoxContainer);
  3018. preview_tabs_vb->add_child(preview_tabbar_hb);
  3019. preview_tabs_content = memnew(PanelContainer);
  3020. preview_tabs_content->set_v_size_flags(SIZE_EXPAND_FILL);
  3021. preview_tabs_content->set_draw_behind_parent(true);
  3022. preview_tabs_vb->add_child(preview_tabs_content);
  3023. preview_tabs = memnew(TabBar);
  3024. preview_tabs->set_h_size_flags(SIZE_EXPAND_FILL);
  3025. preview_tabbar_hb->add_child(preview_tabs);
  3026. preview_tabs->connect("tab_changed", callable_mp(this, &ThemeEditor::_change_preview_tab));
  3027. preview_tabs->connect("tab_button_pressed", callable_mp(this, &ThemeEditor::_remove_preview_tab));
  3028. HBoxContainer *add_preview_button_hb = memnew(HBoxContainer);
  3029. preview_tabbar_hb->add_child(add_preview_button_hb);
  3030. add_preview_button = memnew(Button);
  3031. add_preview_button->set_text(TTR("Add Preview"));
  3032. add_preview_button_hb->add_child(add_preview_button);
  3033. add_preview_button->connect("pressed", callable_mp(this, &ThemeEditor::_add_preview_button_cbk));
  3034. DefaultThemeEditorPreview *default_preview_tab = memnew(DefaultThemeEditorPreview);
  3035. preview_tabs_content->add_child(default_preview_tab);
  3036. default_preview_tab->connect("control_picked", callable_mp(this, &ThemeEditor::_preview_control_picked));
  3037. preview_tabs->add_tab(TTR("Default Preview"));
  3038. preview_scene_dialog = memnew(EditorFileDialog);
  3039. preview_scene_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  3040. preview_scene_dialog->set_title(TTR("Select UI Scene:"));
  3041. List<String> ext;
  3042. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &ext);
  3043. for (const String &E : ext) {
  3044. preview_scene_dialog->add_filter("*." + E, TTR("Scene"));
  3045. }
  3046. main_hs->add_child(preview_scene_dialog);
  3047. preview_scene_dialog->connect("file_selected", callable_mp(this, &ThemeEditor::_preview_scene_dialog_cbk));
  3048. main_hs->add_child(theme_type_editor);
  3049. theme_type_editor->set_custom_minimum_size(Size2(280, 0) * EDSCALE);
  3050. }
  3051. ///////////////////////
  3052. void ThemeEditorPlugin::edit(Object *p_node) {
  3053. if (Object::cast_to<Theme>(p_node)) {
  3054. theme_editor->edit(Object::cast_to<Theme>(p_node));
  3055. } else if (Object::cast_to<Font>(p_node) || Object::cast_to<StyleBox>(p_node) || Object::cast_to<Texture2D>(p_node)) {
  3056. // Do nothing, keep editing the existing theme.
  3057. } else {
  3058. theme_editor->edit(Ref<Theme>());
  3059. }
  3060. }
  3061. bool ThemeEditorPlugin::handles(Object *p_node) const {
  3062. if (Object::cast_to<Theme>(p_node)) {
  3063. return true;
  3064. }
  3065. Ref<Theme> edited_theme = theme_editor->get_edited_theme();
  3066. if (edited_theme.is_null()) {
  3067. return false;
  3068. }
  3069. // If we are editing a theme already and this particular resource happens to belong to it,
  3070. // then we just keep editing it, despite not being able to directly handle it.
  3071. // This only goes one layer deep, but if required this can be extended to support, say, Font inside of Font.
  3072. bool belongs_to_theme = false;
  3073. if (Object::cast_to<Font>(p_node)) {
  3074. Ref<Font> font_item = Object::cast_to<Font>(p_node);
  3075. List<StringName> types;
  3076. List<StringName> names;
  3077. edited_theme->get_font_type_list(&types);
  3078. for (const StringName &E : types) {
  3079. names.clear();
  3080. edited_theme->get_font_list(E, &names);
  3081. for (const StringName &F : names) {
  3082. if (font_item == edited_theme->get_font(F, E)) {
  3083. belongs_to_theme = true;
  3084. break;
  3085. }
  3086. }
  3087. }
  3088. } else if (Object::cast_to<StyleBox>(p_node)) {
  3089. Ref<StyleBox> stylebox_item = Object::cast_to<StyleBox>(p_node);
  3090. List<StringName> types;
  3091. List<StringName> names;
  3092. edited_theme->get_stylebox_type_list(&types);
  3093. for (const StringName &E : types) {
  3094. names.clear();
  3095. edited_theme->get_stylebox_list(E, &names);
  3096. for (const StringName &F : names) {
  3097. if (stylebox_item == edited_theme->get_stylebox(F, E)) {
  3098. belongs_to_theme = true;
  3099. break;
  3100. }
  3101. }
  3102. }
  3103. } else if (Object::cast_to<Texture2D>(p_node)) {
  3104. Ref<Texture2D> icon_item = Object::cast_to<Texture2D>(p_node);
  3105. List<StringName> types;
  3106. List<StringName> names;
  3107. edited_theme->get_icon_type_list(&types);
  3108. for (const StringName &E : types) {
  3109. names.clear();
  3110. edited_theme->get_icon_list(E, &names);
  3111. for (const StringName &F : names) {
  3112. if (icon_item == edited_theme->get_icon(F, E)) {
  3113. belongs_to_theme = true;
  3114. break;
  3115. }
  3116. }
  3117. }
  3118. }
  3119. return belongs_to_theme;
  3120. }
  3121. void ThemeEditorPlugin::make_visible(bool p_visible) {
  3122. if (p_visible) {
  3123. button->show();
  3124. EditorNode::get_singleton()->make_bottom_panel_item_visible(theme_editor);
  3125. } else {
  3126. if (theme_editor->is_visible_in_tree()) {
  3127. EditorNode::get_singleton()->hide_bottom_panel();
  3128. }
  3129. button->hide();
  3130. }
  3131. }
  3132. ThemeEditorPlugin::ThemeEditorPlugin() {
  3133. theme_editor = memnew(ThemeEditor);
  3134. theme_editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
  3135. button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Theme"), theme_editor);
  3136. button->hide();
  3137. }