@@ -3810,10 +3810,32 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38103810 return ;
38113811 }
38123812
3813+ bool section_started = false ;
3814+ bool section_ended = false ;
3815+
3816+ // Marks beginning of a new separated section. When used multiple times in a row, only first use has effect.
3817+ #define BEGIN_SECTION () \
3818+ { \
3819+ if (section_ended) { \
3820+ section_ended = false ; \
3821+ menu->add_separator (); \
3822+ } \
3823+ section_started = true ; \
3824+ }
3825+ // Marks end of a section.
3826+ #define END_SECTION () \
3827+ { \
3828+ if (section_started) { \
3829+ section_ended = true ; \
3830+ section_started = false ; \
3831+ } \
3832+ }
3833+
38133834 Ref<Script> existing_script;
38143835 bool existing_script_removable = true ;
38153836 bool allow_attach_new_script = true ;
38163837 if (selection.size () == 1 ) {
3838+ BEGIN_SECTION ()
38173839 Node *selected = selection.front ()->get ();
38183840
38193841 if (profile_allow_editing) {
@@ -3829,7 +3851,6 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38293851 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Instance" )), ED_GET_SHORTCUT (" scene_tree/instantiate_scene" ), TOOL_INSTANTIATE);
38303852 }
38313853 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Collapse" )), ED_GET_SHORTCUT (" scene_tree/expand_collapse_all" ), TOOL_EXPAND_COLLAPSE);
3832- menu->add_separator ();
38333854
38343855 existing_script = selected->get_script ();
38353856
@@ -3840,9 +3861,11 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38403861 if (selected->has_meta (SceneStringName (_custom_type_script))) {
38413862 allow_attach_new_script = false ;
38423863 }
3864+ END_SECTION ()
38433865 }
38443866
38453867 if (profile_allow_editing) {
3868+ BEGIN_SECTION ()
38463869 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ActionCut" )), ED_GET_SHORTCUT (" scene_tree/cut_node" ), TOOL_CUT);
38473870 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ActionCopy" )), ED_GET_SHORTCUT (" scene_tree/copy_node" ), TOOL_COPY);
38483871 if (selection.size () == 1 && !node_clipboard.is_empty ()) {
@@ -3852,14 +3875,12 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38523875 menu->set_item_disabled (-1 , true );
38533876 }
38543877 }
3855- menu-> add_separator ();
3878+ END_SECTION ()
38563879 }
38573880
38583881 if (profile_allow_script_editing) {
3859- bool add_separator = false ;
3860-
38613882 if (full_selection.size () == 1 ) {
3862- add_separator = true ;
3883+ BEGIN_SECTION ()
38633884 if (allow_attach_new_script) {
38643885 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ScriptCreate" )), ED_GET_SHORTCUT (" scene_tree/attach_script" ), TOOL_ATTACH_SCRIPT);
38653886 }
@@ -3869,7 +3890,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38693890 }
38703891 }
38713892 if (existing_script.is_valid () && existing_script_removable) {
3872- add_separator = true ;
3893+ BEGIN_SECTION ()
38733894 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ScriptRemove" )), ED_GET_SHORTCUT (" scene_tree/detach_script" ), TOOL_DETACH_SCRIPT);
38743895 } else if (full_selection.size () > 1 ) {
38753896 bool script_exists = false ;
@@ -3881,40 +3902,38 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38813902 }
38823903
38833904 if (script_exists) {
3884- add_separator = true ;
3905+ BEGIN_SECTION ()
38853906 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ScriptRemove" )), ED_GET_SHORTCUT (" scene_tree/detach_script" ), TOOL_DETACH_SCRIPT);
38863907 }
38873908 }
3888-
3889- if (add_separator && profile_allow_editing) {
3890- menu->add_separator ();
3891- }
3909+ END_SECTION ()
38923910 }
38933911
38943912 if (profile_allow_editing) {
3895- menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Rename" )), ED_GET_SHORTCUT (" scene_tree/rename" ), TOOL_RENAME);
3896-
3897- bool can_replace = true ;
3913+ bool is_foreign = false ;
38983914 for (Node *E : selection) {
38993915 if (E != edited_scene && (E->get_owner () != edited_scene || E->is_instance ())) {
3900- can_replace = false ;
3916+ is_foreign = true ;
39013917 break ;
39023918 }
39033919
39043920 if (edited_scene->get_scene_inherited_state ().is_valid ()) {
39053921 if (E == edited_scene || edited_scene->get_scene_inherited_state ()->find_node_by_path (edited_scene->get_path_to (E)) >= 0 ) {
3906- can_replace = false ;
3922+ is_foreign = true ;
39073923 break ;
39083924 }
39093925 }
39103926 }
39113927
3912- if (can_replace) {
3928+ if (!is_foreign) {
3929+ BEGIN_SECTION ()
3930+ menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Rename" )), ED_GET_SHORTCUT (" scene_tree/rename" ), TOOL_RENAME);
39133931 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Reload" )), ED_GET_SHORTCUT (" scene_tree/change_node_type" ), TOOL_REPLACE);
3932+ END_SECTION ()
39143933 }
39153934
39163935 if (scene_tree->get_selected () != edited_scene) {
3917- menu-> add_separator ();
3936+ BEGIN_SECTION ()
39183937 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" MoveUp" )), ED_GET_SHORTCUT (" scene_tree/move_up" ), TOOL_MOVE_UP);
39193938 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" MoveDown" )), ED_GET_SHORTCUT (" scene_tree/move_down" ), TOOL_MOVE_DOWN);
39203939 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Duplicate" )), ED_GET_SHORTCUT (" scene_tree/duplicate" ), TOOL_DUPLICATE);
@@ -3923,17 +3942,20 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39233942 if (selection.size () == 1 ) {
39243943 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" NewRoot" )), ED_GET_SHORTCUT (" scene_tree/make_root" ), TOOL_MAKE_ROOT);
39253944 }
3945+ END_SECTION ()
39263946 }
39273947 }
39283948 if (selection.size () == 1 ) {
39293949 if (profile_allow_editing) {
3930- menu-> add_separator ();
3950+ BEGIN_SECTION ()
39313951 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" CreateNewSceneFrom" )), ED_GET_SHORTCUT (" scene_tree/save_branch_as_scene" ), TOOL_NEW_SCENE_FROM);
3952+ END_SECTION ()
39323953 }
39333954
39343955 if (full_selection.size () == 1 ) {
3935- menu-> add_separator ();
3956+ BEGIN_SECTION ()
39363957 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" CopyNodePath" )), ED_GET_SHORTCUT (" scene_tree/copy_node_path" ), TOOL_COPY_NODE_PATH);
3958+ END_SECTION ()
39373959 }
39383960 }
39393961
@@ -3949,13 +3971,14 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39493971 if (all_owned) {
39503972 // Group "toggle_unique_name" with "copy_node_path", if it is available.
39513973 if (menu->get_item_index (TOOL_COPY_NODE_PATH) == -1 ) {
3952- menu-> add_separator ();
3974+ BEGIN_SECTION ()
39533975 }
39543976 Node *node = full_selection.front ()->get ();
39553977 menu->add_icon_check_item (get_editor_theme_icon (SNAME (" SceneUniqueName" )), TTRC (" Access as Unique Name" ), TOOL_TOGGLE_SCENE_UNIQUE_NAME);
39563978 menu->set_item_shortcut (menu->get_item_index (TOOL_TOGGLE_SCENE_UNIQUE_NAME), ED_GET_SHORTCUT (" scene_tree/toggle_unique_name" ));
39573979 menu->set_item_checked (menu->get_item_index (TOOL_TOGGLE_SCENE_UNIQUE_NAME), node->is_unique_name_in_owner ());
39583980 }
3981+ END_SECTION ()
39593982 }
39603983
39613984 if (selection.size () == 1 ) {
@@ -3964,13 +3987,13 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39643987 bool is_inherited = selection.front ()->get ()->get_scene_inherited_state ().is_valid ();
39653988 bool is_top_level = selection.front ()->get ()->get_owner () == nullptr ;
39663989 if (is_inherited && is_top_level) {
3967- menu-> add_separator ();
3990+ BEGIN_SECTION ()
39683991 if (profile_allow_editing) {
39693992 menu->add_item (TTR (" Clear Inheritance" ), TOOL_SCENE_CLEAR_INHERITANCE);
39703993 }
39713994 menu->add_icon_item (get_editor_theme_icon (SNAME (" Load" )), TTR (" Open in Editor" ), TOOL_SCENE_OPEN_INHERITED);
39723995 } else if (!is_top_level) {
3973- menu-> add_separator ();
3996+ BEGIN_SECTION ()
39743997 bool editable = EditorNode::get_singleton ()->get_edited_scene ()->is_editable_instance (selection.front ()->get ());
39753998 bool placeholder = selection.front ()->get ()->get_scene_instance_load_placeholder ();
39763999 if (profile_allow_editing) {
@@ -3987,15 +4010,16 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39874010 }
39884011 }
39894012 }
4013+ END_SECTION ()
39904014 }
39914015
39924016 if (profile_allow_editing && selection.size () > 1 ) {
39934017 // this is not a commonly used action, it makes no sense for it to be where it was nor always present.
3994- menu-> add_separator ();
4018+ BEGIN_SECTION ()
39954019 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Rename" )), ED_GET_SHORTCUT (" scene_tree/batch_rename" ), TOOL_BATCH_RENAME);
4020+ END_SECTION ()
39964021 }
3997- menu->add_separator ();
3998-
4022+ BEGIN_SECTION ()
39994023 if (full_selection.size () == 1 && selection.front ()->get ()->is_instance ()) {
40004024 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ShowInFileSystem" )), ED_GET_SHORTCUT (" scene_tree/show_in_file_system" ), TOOL_SHOW_IN_FILE_SYSTEM);
40014025 }
@@ -4006,6 +4030,10 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
40064030 menu->add_separator ();
40074031 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Remove" )), ED_GET_SHORTCUT (" scene_tree/delete" ), TOOL_ERASE);
40084032 }
4033+ END_SECTION ()
4034+
4035+ #undef BEGIN_SECTION
4036+ #undef END_SECTIOn
40094037
40104038 Vector<String> p_paths;
40114039 Node *root = EditorNode::get_singleton ()->get_edited_scene ();
0 commit comments