@@ -3814,10 +3814,32 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38143814 return ;
38153815 }
38163816
3817+ bool section_started = false ;
3818+ bool section_ended = false ;
3819+
3820+ // Marks beginning of a new separated section. When used multiple times in a row, only first use has effect.
3821+ #define BEGIN_SECTION () \
3822+ { \
3823+ if (section_ended) { \
3824+ section_ended = false ; \
3825+ menu->add_separator (); \
3826+ } \
3827+ section_started = true ; \
3828+ }
3829+ // Marks end of a section.
3830+ #define END_SECTION () \
3831+ { \
3832+ if (section_started) { \
3833+ section_ended = true ; \
3834+ section_started = false ; \
3835+ } \
3836+ }
3837+
38173838 Ref<Script> existing_script;
38183839 bool existing_script_removable = true ;
38193840 bool allow_attach_new_script = true ;
38203841 if (selection.size () == 1 ) {
3842+ BEGIN_SECTION ()
38213843 Node *selected = selection.front ()->get ();
38223844
38233845 if (profile_allow_editing) {
@@ -3833,7 +3855,6 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38333855 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Instance" )), ED_GET_SHORTCUT (" scene_tree/instantiate_scene" ), TOOL_INSTANTIATE);
38343856 }
38353857 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Collapse" )), ED_GET_SHORTCUT (" scene_tree/expand_collapse_all" ), TOOL_EXPAND_COLLAPSE);
3836- menu->add_separator ();
38373858
38383859 existing_script = selected->get_script ();
38393860
@@ -3844,9 +3865,11 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38443865 if (selected->has_meta (SceneStringName (_custom_type_script))) {
38453866 allow_attach_new_script = false ;
38463867 }
3868+ END_SECTION ()
38473869 }
38483870
38493871 if (profile_allow_editing) {
3872+ BEGIN_SECTION ()
38503873 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ActionCut" )), ED_GET_SHORTCUT (" scene_tree/cut_node" ), TOOL_CUT);
38513874 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ActionCopy" )), ED_GET_SHORTCUT (" scene_tree/copy_node" ), TOOL_COPY);
38523875 if (selection.size () == 1 && !node_clipboard.is_empty ()) {
@@ -3856,14 +3879,12 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38563879 menu->set_item_disabled (-1 , true );
38573880 }
38583881 }
3859- menu-> add_separator ();
3882+ END_SECTION ()
38603883 }
38613884
38623885 if (profile_allow_script_editing) {
3863- bool add_separator = false ;
3864-
38653886 if (full_selection.size () == 1 ) {
3866- add_separator = true ;
3887+ BEGIN_SECTION ()
38673888 if (allow_attach_new_script) {
38683889 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ScriptCreate" )), ED_GET_SHORTCUT (" scene_tree/attach_script" ), TOOL_ATTACH_SCRIPT);
38693890 }
@@ -3873,7 +3894,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38733894 }
38743895 }
38753896 if (existing_script.is_valid () && existing_script_removable) {
3876- add_separator = true ;
3897+ BEGIN_SECTION ()
38773898 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ScriptRemove" )), ED_GET_SHORTCUT (" scene_tree/detach_script" ), TOOL_DETACH_SCRIPT);
38783899 } else if (full_selection.size () > 1 ) {
38793900 bool script_exists = false ;
@@ -3885,40 +3906,38 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
38853906 }
38863907
38873908 if (script_exists) {
3888- add_separator = true ;
3909+ BEGIN_SECTION ()
38893910 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ScriptRemove" )), ED_GET_SHORTCUT (" scene_tree/detach_script" ), TOOL_DETACH_SCRIPT);
38903911 }
38913912 }
3892-
3893- if (add_separator && profile_allow_editing) {
3894- menu->add_separator ();
3895- }
3913+ END_SECTION ()
38963914 }
38973915
38983916 if (profile_allow_editing) {
3899- menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Rename" )), ED_GET_SHORTCUT (" scene_tree/rename" ), TOOL_RENAME);
3900-
3901- bool can_replace = true ;
3917+ bool is_foreign = false ;
39023918 for (Node *E : selection) {
39033919 if (E != edited_scene && (E->get_owner () != edited_scene || E->is_instance ())) {
3904- can_replace = false ;
3920+ is_foreign = true ;
39053921 break ;
39063922 }
39073923
39083924 if (edited_scene->get_scene_inherited_state ().is_valid ()) {
39093925 if (E == edited_scene || edited_scene->get_scene_inherited_state ()->find_node_by_path (edited_scene->get_path_to (E)) >= 0 ) {
3910- can_replace = false ;
3926+ is_foreign = true ;
39113927 break ;
39123928 }
39133929 }
39143930 }
39153931
3916- if (can_replace) {
3932+ if (!is_foreign) {
3933+ BEGIN_SECTION ()
3934+ menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Rename" )), ED_GET_SHORTCUT (" scene_tree/rename" ), TOOL_RENAME);
39173935 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Reload" )), ED_GET_SHORTCUT (" scene_tree/change_node_type" ), TOOL_REPLACE);
3936+ END_SECTION ()
39183937 }
39193938
39203939 if (scene_tree->get_selected () != edited_scene) {
3921- menu-> add_separator ();
3940+ BEGIN_SECTION ()
39223941 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" MoveUp" )), ED_GET_SHORTCUT (" scene_tree/move_up" ), TOOL_MOVE_UP);
39233942 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" MoveDown" )), ED_GET_SHORTCUT (" scene_tree/move_down" ), TOOL_MOVE_DOWN);
39243943 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Duplicate" )), ED_GET_SHORTCUT (" scene_tree/duplicate" ), TOOL_DUPLICATE);
@@ -3927,17 +3946,20 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39273946 if (selection.size () == 1 ) {
39283947 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" NewRoot" )), ED_GET_SHORTCUT (" scene_tree/make_root" ), TOOL_MAKE_ROOT);
39293948 }
3949+ END_SECTION ()
39303950 }
39313951 }
39323952 if (selection.size () == 1 ) {
39333953 if (profile_allow_editing) {
3934- menu-> add_separator ();
3954+ BEGIN_SECTION ()
39353955 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" CreateNewSceneFrom" )), ED_GET_SHORTCUT (" scene_tree/save_branch_as_scene" ), TOOL_NEW_SCENE_FROM);
3956+ END_SECTION ()
39363957 }
39373958
39383959 if (full_selection.size () == 1 ) {
3939- menu-> add_separator ();
3960+ BEGIN_SECTION ()
39403961 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" CopyNodePath" )), ED_GET_SHORTCUT (" scene_tree/copy_node_path" ), TOOL_COPY_NODE_PATH);
3962+ END_SECTION ()
39413963 }
39423964 }
39433965
@@ -3953,13 +3975,14 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39533975 if (all_owned) {
39543976 // Group "toggle_unique_name" with "copy_node_path", if it is available.
39553977 if (menu->get_item_index (TOOL_COPY_NODE_PATH) == -1 ) {
3956- menu-> add_separator ();
3978+ BEGIN_SECTION ()
39573979 }
39583980 Node *node = full_selection.front ()->get ();
39593981 menu->add_icon_check_item (get_editor_theme_icon (SNAME (" SceneUniqueName" )), TTRC (" Access as Unique Name" ), TOOL_TOGGLE_SCENE_UNIQUE_NAME);
39603982 menu->set_item_shortcut (menu->get_item_index (TOOL_TOGGLE_SCENE_UNIQUE_NAME), ED_GET_SHORTCUT (" scene_tree/toggle_unique_name" ));
39613983 menu->set_item_checked (menu->get_item_index (TOOL_TOGGLE_SCENE_UNIQUE_NAME), node->is_unique_name_in_owner ());
39623984 }
3985+ END_SECTION ()
39633986 }
39643987
39653988 if (selection.size () == 1 ) {
@@ -3968,13 +3991,13 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39683991 bool is_inherited = selection.front ()->get ()->get_scene_inherited_state ().is_valid ();
39693992 bool is_top_level = selection.front ()->get ()->get_owner () == nullptr ;
39703993 if (is_inherited && is_top_level) {
3971- menu-> add_separator ();
3994+ BEGIN_SECTION ()
39723995 if (profile_allow_editing) {
39733996 menu->add_item (TTR (" Clear Inheritance" ), TOOL_SCENE_CLEAR_INHERITANCE);
39743997 }
39753998 menu->add_icon_item (get_editor_theme_icon (SNAME (" Load" )), TTR (" Open in Editor" ), TOOL_SCENE_OPEN_INHERITED);
39763999 } else if (!is_top_level) {
3977- menu-> add_separator ();
4000+ BEGIN_SECTION ()
39784001 bool editable = EditorNode::get_singleton ()->get_edited_scene ()->is_editable_instance (selection.front ()->get ());
39794002 bool placeholder = selection.front ()->get ()->get_scene_instance_load_placeholder ();
39804003 if (profile_allow_editing) {
@@ -3991,15 +4014,16 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
39914014 }
39924015 }
39934016 }
4017+ END_SECTION ()
39944018 }
39954019
39964020 if (profile_allow_editing && selection.size () > 1 ) {
39974021 // this is not a commonly used action, it makes no sense for it to be where it was nor always present.
3998- menu-> add_separator ();
4022+ BEGIN_SECTION ()
39994023 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Rename" )), ED_GET_SHORTCUT (" scene_tree/batch_rename" ), TOOL_BATCH_RENAME);
4024+ END_SECTION ()
40004025 }
4001- menu->add_separator ();
4002-
4026+ BEGIN_SECTION ()
40034027 if (full_selection.size () == 1 && selection.front ()->get ()->is_instance ()) {
40044028 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" ShowInFileSystem" )), ED_GET_SHORTCUT (" scene_tree/show_in_file_system" ), TOOL_SHOW_IN_FILE_SYSTEM);
40054029 }
@@ -4010,6 +4034,10 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
40104034 menu->add_separator ();
40114035 menu->add_icon_shortcut (get_editor_theme_icon (SNAME (" Remove" )), ED_GET_SHORTCUT (" scene_tree/delete" ), TOOL_ERASE);
40124036 }
4037+ END_SECTION ()
4038+
4039+ #undef BEGIN_SECTION
4040+ #undef END_SECTIOn
40134041
40144042 Vector<String> p_paths;
40154043 Node *root = EditorNode::get_singleton ()->get_edited_scene ();
0 commit comments