editor_scene_tabs.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /**************************************************************************/
  2. /* editor_scene_tabs.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_scene_tabs.h"
  31. #include "editor/editor_main_screen.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_resource_preview.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_string_names.h"
  36. #include "editor/editor_undo_redo_manager.h"
  37. #include "editor/gui/editor_run_bar.h"
  38. #include "editor/inspector_dock.h"
  39. #include "editor/plugins/editor_context_menu_plugin.h"
  40. #include "editor/themes/editor_scale.h"
  41. #include "scene/gui/box_container.h"
  42. #include "scene/gui/button.h"
  43. #include "scene/gui/panel.h"
  44. #include "scene/gui/panel_container.h"
  45. #include "scene/gui/popup_menu.h"
  46. #include "scene/gui/tab_bar.h"
  47. #include "scene/gui/texture_rect.h"
  48. void EditorSceneTabs::_notification(int p_what) {
  49. switch (p_what) {
  50. case NOTIFICATION_THEME_CHANGED: {
  51. tabbar_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("tabbar_background"), SNAME("TabContainer")));
  52. scene_tabs->add_theme_constant_override("icon_max_width", get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)));
  53. scene_tab_add->set_button_icon(get_editor_theme_icon(SNAME("Add")));
  54. scene_tab_add->add_theme_color_override("icon_normal_color", Color(0.6f, 0.6f, 0.6f, 0.8f));
  55. scene_tab_add_ph->set_custom_minimum_size(scene_tab_add->get_minimum_size());
  56. } break;
  57. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  58. if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/scene_tabs")) {
  59. scene_tabs->set_tab_close_display_policy((TabBar::CloseButtonDisplayPolicy)EDITOR_GET("interface/scene_tabs/display_close_button").operator int());
  60. scene_tabs->set_max_tab_width(int(EDITOR_GET("interface/scene_tabs/maximum_width")) * EDSCALE);
  61. _scene_tabs_resized();
  62. }
  63. } break;
  64. }
  65. }
  66. void EditorSceneTabs::_scene_tab_changed(int p_tab) {
  67. tab_preview_panel->hide();
  68. emit_signal("tab_changed", p_tab);
  69. }
  70. void EditorSceneTabs::_scene_tab_script_edited(int p_tab) {
  71. Ref<Script> scr = EditorNode::get_editor_data().get_scene_root_script(p_tab);
  72. if (scr.is_valid()) {
  73. InspectorDock::get_singleton()->edit_resource(scr);
  74. }
  75. }
  76. void EditorSceneTabs::_scene_tab_closed(int p_tab) {
  77. emit_signal("tab_closed", p_tab);
  78. }
  79. void EditorSceneTabs::_scene_tab_hovered(int p_tab) {
  80. if (!bool(EDITOR_GET("interface/scene_tabs/show_thumbnail_on_hover"))) {
  81. return;
  82. }
  83. // Currently the tab previews are displayed under the running game process when embed.
  84. // Right now, the easiest technique to fix that is to prevent displaying the tab preview
  85. // when the user is in the Game View.
  86. if (EditorNode::get_singleton()->get_editor_main_screen()->get_selected_index() == EditorMainScreen::EDITOR_GAME && EditorRunBar::get_singleton()->is_playing()) {
  87. return;
  88. }
  89. int current_tab = scene_tabs->get_current_tab();
  90. if (p_tab == current_tab || p_tab < 0) {
  91. tab_preview_panel->hide();
  92. } else {
  93. String path = EditorNode::get_editor_data().get_scene_path(p_tab);
  94. if (!path.is_empty()) {
  95. EditorResourcePreview::get_singleton()->queue_resource_preview(path, this, "_tab_preview_done", p_tab);
  96. }
  97. }
  98. }
  99. void EditorSceneTabs::_scene_tab_exit() {
  100. tab_preview_panel->hide();
  101. }
  102. void EditorSceneTabs::_scene_tab_input(const Ref<InputEvent> &p_input) {
  103. int tab_id = scene_tabs->get_hovered_tab();
  104. Ref<InputEventMouseButton> mb = p_input;
  105. if (mb.is_valid()) {
  106. if (tab_id >= 0) {
  107. if (mb->get_button_index() == MouseButton::MIDDLE && mb->is_pressed()) {
  108. _scene_tab_closed(tab_id);
  109. }
  110. } else if (mb->get_button_index() == MouseButton::LEFT && mb->is_double_click()) {
  111. int tab_buttons = 0;
  112. if (scene_tabs->get_offset_buttons_visible()) {
  113. tab_buttons = get_theme_icon(SNAME("increment"), SNAME("TabBar"))->get_width() + get_theme_icon(SNAME("decrement"), SNAME("TabBar"))->get_width();
  114. }
  115. if ((is_layout_rtl() && mb->get_position().x > tab_buttons) || (!is_layout_rtl() && mb->get_position().x < scene_tabs->get_size().width - tab_buttons)) {
  116. EditorNode::get_singleton()->trigger_menu_option(EditorNode::FILE_NEW_SCENE, true);
  117. }
  118. }
  119. if (mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
  120. // Context menu.
  121. _update_context_menu();
  122. scene_tabs_context_menu->set_position(scene_tabs->get_screen_position() + mb->get_position());
  123. scene_tabs_context_menu->reset_size();
  124. scene_tabs_context_menu->popup();
  125. }
  126. }
  127. }
  128. void EditorSceneTabs::unhandled_key_input(const Ref<InputEvent> &p_event) {
  129. if (!tab_preview_panel->is_visible()) {
  130. return;
  131. }
  132. Ref<InputEventKey> k = p_event;
  133. if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
  134. tab_preview_panel->hide();
  135. }
  136. }
  137. void EditorSceneTabs::_reposition_active_tab(int p_to_index) {
  138. EditorNode::get_editor_data().move_edited_scene_to_index(p_to_index);
  139. update_scene_tabs();
  140. }
  141. void EditorSceneTabs::_update_context_menu() {
  142. #define DISABLE_LAST_OPTION_IF(m_condition) \
  143. if (m_condition) { \
  144. scene_tabs_context_menu->set_item_disabled(-1, true); \
  145. }
  146. scene_tabs_context_menu->clear();
  147. scene_tabs_context_menu->reset_size();
  148. int tab_id = scene_tabs->get_hovered_tab();
  149. bool no_root_node = !EditorNode::get_editor_data().get_edited_scene_root(tab_id);
  150. scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/new_scene"), EditorNode::FILE_NEW_SCENE);
  151. if (tab_id >= 0) {
  152. scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/save_scene"), EditorNode::FILE_SAVE_SCENE);
  153. DISABLE_LAST_OPTION_IF(no_root_node);
  154. scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/save_scene_as"), EditorNode::FILE_SAVE_AS_SCENE);
  155. DISABLE_LAST_OPTION_IF(no_root_node);
  156. }
  157. bool can_save_all_scenes = false;
  158. for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
  159. if (!EditorNode::get_editor_data().get_scene_path(i).is_empty() && EditorNode::get_editor_data().get_edited_scene_root(i)) {
  160. can_save_all_scenes = true;
  161. break;
  162. }
  163. }
  164. scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/save_all_scenes"), EditorNode::FILE_SAVE_ALL_SCENES);
  165. DISABLE_LAST_OPTION_IF(!can_save_all_scenes);
  166. if (tab_id >= 0) {
  167. scene_tabs_context_menu->add_separator();
  168. scene_tabs_context_menu->add_item(TTR("Show in FileSystem"), SCENE_SHOW_IN_FILESYSTEM);
  169. DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(EditorNode::get_editor_data().get_scene_path(tab_id)));
  170. scene_tabs_context_menu->add_item(TTR("Play This Scene"), SCENE_RUN);
  171. DISABLE_LAST_OPTION_IF(no_root_node);
  172. scene_tabs_context_menu->add_separator();
  173. scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/close_scene"), EditorNode::FILE_CLOSE);
  174. scene_tabs_context_menu->set_item_text(-1, TTR("Close Tab"));
  175. scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/reopen_closed_scene"), EditorNode::FILE_OPEN_PREV);
  176. scene_tabs_context_menu->set_item_text(-1, TTR("Undo Close Tab"));
  177. DISABLE_LAST_OPTION_IF(!EditorNode::get_singleton()->has_previous_scenes());
  178. scene_tabs_context_menu->add_item(TTR("Close Other Tabs"), SCENE_CLOSE_OTHERS);
  179. DISABLE_LAST_OPTION_IF(EditorNode::get_editor_data().get_edited_scene_count() <= 1);
  180. scene_tabs_context_menu->add_item(TTR("Close Tabs to the Right"), SCENE_CLOSE_RIGHT);
  181. DISABLE_LAST_OPTION_IF(EditorNode::get_editor_data().get_edited_scene_count() == tab_id + 1);
  182. scene_tabs_context_menu->add_item(TTR("Close All Tabs"), SCENE_CLOSE_ALL);
  183. const PackedStringArray paths = { EditorNode::get_editor_data().get_scene_path(tab_id) };
  184. EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(scene_tabs_context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, paths);
  185. } else {
  186. EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(scene_tabs_context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, {});
  187. }
  188. #undef DISABLE_LAST_OPTION_IF
  189. last_hovered_tab = tab_id;
  190. }
  191. void EditorSceneTabs::_custom_menu_option(int p_option) {
  192. if (p_option >= EditorContextMenuPlugin::BASE_ID) {
  193. EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, p_option, last_hovered_tab >= 0 ? EditorNode::get_editor_data().get_scene_path(last_hovered_tab) : String());
  194. }
  195. }
  196. void EditorSceneTabs::update_scene_tabs() {
  197. static bool menu_initialized = false;
  198. tab_preview_panel->hide();
  199. if (menu_initialized && scene_tabs->get_tab_count() == EditorNode::get_editor_data().get_edited_scene_count()) {
  200. _update_tab_titles();
  201. return;
  202. }
  203. menu_initialized = true;
  204. if (NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
  205. RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
  206. NativeMenu::get_singleton()->clear(dock_rid);
  207. }
  208. scene_tabs->set_block_signals(true);
  209. scene_tabs->set_tab_count(EditorNode::get_editor_data().get_edited_scene_count());
  210. scene_tabs->set_block_signals(false);
  211. if (NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
  212. RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
  213. for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
  214. int global_menu_index = NativeMenu::get_singleton()->add_item(dock_rid, EditorNode::get_editor_data().get_scene_title(i), callable_mp(this, &EditorSceneTabs::_global_menu_scene), Callable(), i);
  215. scene_tabs->set_tab_metadata(i, global_menu_index);
  216. }
  217. NativeMenu::get_singleton()->add_separator(dock_rid);
  218. NativeMenu::get_singleton()->add_item(dock_rid, TTR("New Window"), callable_mp(this, &EditorSceneTabs::_global_menu_new_window));
  219. }
  220. _update_tab_titles();
  221. }
  222. void EditorSceneTabs::_update_tab_titles() {
  223. bool show_rb = EDITOR_GET("interface/scene_tabs/show_script_button");
  224. // Get all scene names, which may be ambiguous.
  225. Vector<String> disambiguated_scene_names;
  226. Vector<String> full_path_names;
  227. for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
  228. disambiguated_scene_names.append(EditorNode::get_editor_data().get_scene_title(i));
  229. full_path_names.append(EditorNode::get_editor_data().get_scene_path(i));
  230. }
  231. EditorNode::disambiguate_filenames(full_path_names, disambiguated_scene_names);
  232. Ref<Texture2D> script_icon = get_editor_theme_icon(SNAME("Script"));
  233. for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
  234. Node *type_node = EditorNode::get_editor_data().get_edited_scene_root(i);
  235. Ref<Texture2D> icon;
  236. if (type_node) {
  237. icon = EditorNode::get_singleton()->get_object_icon(type_node, "Node");
  238. }
  239. scene_tabs->set_tab_icon(i, icon);
  240. bool unsaved = EditorUndoRedoManager::get_singleton()->is_history_unsaved(EditorNode::get_editor_data().get_scene_history_id(i));
  241. scene_tabs->set_tab_title(i, disambiguated_scene_names[i] + (unsaved ? "(*)" : ""));
  242. if (NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
  243. RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
  244. int global_menu_index = scene_tabs->get_tab_metadata(i);
  245. NativeMenu::get_singleton()->set_item_text(dock_rid, global_menu_index, EditorNode::get_editor_data().get_scene_title(i) + (unsaved ? "(*)" : ""));
  246. NativeMenu::get_singleton()->set_item_tag(dock_rid, global_menu_index, i);
  247. }
  248. if (show_rb && EditorNode::get_editor_data().get_scene_root_script(i).is_valid()) {
  249. scene_tabs->set_tab_button_icon(i, script_icon);
  250. } else {
  251. scene_tabs->set_tab_button_icon(i, nullptr);
  252. }
  253. }
  254. int current_tab = EditorNode::get_editor_data().get_edited_scene();
  255. if (scene_tabs->get_tab_count() > 0 && scene_tabs->get_current_tab() != current_tab) {
  256. scene_tabs->set_block_signals(true);
  257. scene_tabs->set_current_tab(current_tab);
  258. scene_tabs->set_block_signals(false);
  259. }
  260. _scene_tabs_resized();
  261. }
  262. void EditorSceneTabs::_scene_tabs_resized() {
  263. const Size2 add_button_size = Size2(scene_tab_add->get_size().x, scene_tabs->get_size().y);
  264. if (scene_tabs->get_offset_buttons_visible()) {
  265. // Move the add button to a fixed position.
  266. if (scene_tab_add->get_parent() == scene_tabs) {
  267. scene_tabs->remove_child(scene_tab_add);
  268. scene_tab_add_ph->add_child(scene_tab_add);
  269. scene_tab_add->set_rect(Rect2(Point2(), add_button_size));
  270. }
  271. } else {
  272. // Move the add button to be after the last tab.
  273. if (scene_tab_add->get_parent() == scene_tab_add_ph) {
  274. scene_tab_add_ph->remove_child(scene_tab_add);
  275. scene_tabs->add_child(scene_tab_add);
  276. }
  277. if (scene_tabs->get_tab_count() == 0) {
  278. scene_tab_add->set_rect(Rect2(Point2(), add_button_size));
  279. return;
  280. }
  281. Rect2 last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1);
  282. int hsep = scene_tabs->get_theme_constant(SNAME("h_separation"));
  283. if (scene_tabs->is_layout_rtl()) {
  284. scene_tab_add->set_rect(Rect2(Point2(last_tab.position.x - add_button_size.x - hsep, last_tab.position.y), add_button_size));
  285. } else {
  286. scene_tab_add->set_rect(Rect2(Point2(last_tab.position.x + last_tab.size.width + hsep, last_tab.position.y), add_button_size));
  287. }
  288. }
  289. }
  290. void EditorSceneTabs::_tab_preview_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
  291. int p_tab = p_udata;
  292. if (p_preview.is_valid()) {
  293. tab_preview->set_texture(p_preview);
  294. Rect2 rect = scene_tabs->get_tab_rect(p_tab);
  295. rect.position += scene_tabs->get_global_position();
  296. tab_preview_panel->set_global_position(rect.position + Vector2(0, rect.size.height));
  297. tab_preview_panel->show();
  298. }
  299. }
  300. void EditorSceneTabs::_global_menu_scene(const Variant &p_tag) {
  301. int idx = (int)p_tag;
  302. scene_tabs->set_current_tab(idx);
  303. }
  304. void EditorSceneTabs::_global_menu_new_window(const Variant &p_tag) {
  305. if (OS::get_singleton()->get_main_loop()) {
  306. List<String> args;
  307. args.push_back("-p");
  308. OS::get_singleton()->create_instance(args);
  309. }
  310. }
  311. void EditorSceneTabs::shortcut_input(const Ref<InputEvent> &p_event) {
  312. ERR_FAIL_COND(p_event.is_null());
  313. Ref<InputEventKey> k = p_event;
  314. if ((k.is_valid() && k->is_pressed() && !k->is_echo()) || Object::cast_to<InputEventShortcut>(*p_event)) {
  315. if (ED_IS_SHORTCUT("editor/next_tab", p_event)) {
  316. int next_tab = EditorNode::get_editor_data().get_edited_scene() + 1;
  317. next_tab %= EditorNode::get_editor_data().get_edited_scene_count();
  318. _scene_tab_changed(next_tab);
  319. }
  320. if (ED_IS_SHORTCUT("editor/prev_tab", p_event)) {
  321. int next_tab = EditorNode::get_editor_data().get_edited_scene() - 1;
  322. next_tab = next_tab >= 0 ? next_tab : EditorNode::get_editor_data().get_edited_scene_count() - 1;
  323. _scene_tab_changed(next_tab);
  324. }
  325. }
  326. }
  327. void EditorSceneTabs::add_extra_button(Button *p_button) {
  328. tabbar_container->add_child(p_button);
  329. }
  330. void EditorSceneTabs::set_current_tab(int p_tab) {
  331. scene_tabs->set_current_tab(p_tab);
  332. }
  333. int EditorSceneTabs::get_current_tab() const {
  334. return scene_tabs->get_current_tab();
  335. }
  336. void EditorSceneTabs::_bind_methods() {
  337. ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab_index")));
  338. ADD_SIGNAL(MethodInfo("tab_closed", PropertyInfo(Variant::INT, "tab_index")));
  339. ClassDB::bind_method("_tab_preview_done", &EditorSceneTabs::_tab_preview_done);
  340. }
  341. EditorSceneTabs::EditorSceneTabs() {
  342. singleton = this;
  343. set_process_shortcut_input(true);
  344. set_process_unhandled_key_input(true);
  345. tabbar_panel = memnew(PanelContainer);
  346. add_child(tabbar_panel);
  347. tabbar_container = memnew(HBoxContainer);
  348. tabbar_panel->add_child(tabbar_container);
  349. scene_tabs = memnew(TabBar);
  350. scene_tabs->set_select_with_rmb(true);
  351. scene_tabs->add_tab("unsaved");
  352. scene_tabs->set_tab_close_display_policy((TabBar::CloseButtonDisplayPolicy)EDITOR_GET("interface/scene_tabs/display_close_button").operator int());
  353. scene_tabs->set_max_tab_width(int(EDITOR_GET("interface/scene_tabs/maximum_width")) * EDSCALE);
  354. scene_tabs->set_drag_to_rearrange_enabled(true);
  355. scene_tabs->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  356. scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  357. tabbar_container->add_child(scene_tabs);
  358. scene_tabs->connect("tab_changed", callable_mp(this, &EditorSceneTabs::_scene_tab_changed));
  359. scene_tabs->connect("tab_button_pressed", callable_mp(this, &EditorSceneTabs::_scene_tab_script_edited));
  360. scene_tabs->connect("tab_close_pressed", callable_mp(this, &EditorSceneTabs::_scene_tab_closed));
  361. scene_tabs->connect("tab_hovered", callable_mp(this, &EditorSceneTabs::_scene_tab_hovered));
  362. scene_tabs->connect(SceneStringName(mouse_exited), callable_mp(this, &EditorSceneTabs::_scene_tab_exit));
  363. scene_tabs->connect(SceneStringName(gui_input), callable_mp(this, &EditorSceneTabs::_scene_tab_input));
  364. scene_tabs->connect("active_tab_rearranged", callable_mp(this, &EditorSceneTabs::_reposition_active_tab));
  365. scene_tabs->connect(SceneStringName(resized), callable_mp(this, &EditorSceneTabs::_scene_tabs_resized), CONNECT_DEFERRED);
  366. scene_tabs_context_menu = memnew(PopupMenu);
  367. tabbar_container->add_child(scene_tabs_context_menu);
  368. scene_tabs_context_menu->connect(SceneStringName(id_pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::trigger_menu_option).bind(false));
  369. scene_tabs_context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorSceneTabs::_custom_menu_option));
  370. scene_tab_add = memnew(Button);
  371. scene_tab_add->set_flat(true);
  372. scene_tab_add->set_tooltip_text(TTR("Add a new scene."));
  373. scene_tabs->add_child(scene_tab_add);
  374. scene_tab_add->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::trigger_menu_option).bind(EditorNode::FILE_NEW_SCENE, false));
  375. scene_tab_add_ph = memnew(Control);
  376. scene_tab_add_ph->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  377. scene_tab_add_ph->set_custom_minimum_size(scene_tab_add->get_minimum_size());
  378. tabbar_container->add_child(scene_tab_add_ph);
  379. // On-hover tab preview.
  380. Control *tab_preview_anchor = memnew(Control);
  381. tab_preview_anchor->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  382. add_child(tab_preview_anchor);
  383. tab_preview_panel = memnew(Panel);
  384. tab_preview_panel->set_size(Size2(100, 100) * EDSCALE);
  385. tab_preview_panel->hide();
  386. tab_preview_panel->set_self_modulate(Color(1, 1, 1, 0.7));
  387. tab_preview_anchor->add_child(tab_preview_panel);
  388. tab_preview = memnew(TextureRect);
  389. tab_preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  390. tab_preview->set_size(Size2(96, 96) * EDSCALE);
  391. tab_preview->set_position(Point2(2, 2) * EDSCALE);
  392. tab_preview_panel->add_child(tab_preview);
  393. }