@@ -23,6 +23,8 @@ public AdvancedTypePopupItem (Type type,string name) : base(name) {
23
23
/// </summary>
24
24
public class AdvancedTypePopup : AdvancedDropdown {
25
25
26
+ const int kMaxNamespaceNestCount = 16 ;
27
+
26
28
public static void AddTo ( AdvancedDropdownItem root , IEnumerable < Type > types ) {
27
29
int itemCount = 0 ;
28
30
@@ -32,8 +34,31 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
32
34
} ;
33
35
root . AddChild ( nullItem ) ;
34
36
37
+ Type [ ] typeArray = types . OrderByType ( ) . ToArray ( ) ;
38
+
39
+ // Single namespace if the root has one namespace and the nest is unbranched.
40
+ bool isSingleNamespace = true ;
41
+ string [ ] namespaces = new string [ kMaxNamespaceNestCount ] ;
42
+ foreach ( Type type in typeArray ) {
43
+ string [ ] splittedTypePath = TypeMenuUtility . GetSplittedTypePath ( type ) ;
44
+ if ( splittedTypePath . Length <= 1 ) {
45
+ continue ;
46
+ }
47
+ for ( int k = 0 ; ( splittedTypePath . Length - 1 ) > k ; k ++ ) {
48
+ string ns = namespaces [ k ] ;
49
+ if ( ns == null ) {
50
+ namespaces [ k ] = splittedTypePath [ k ] ;
51
+ }
52
+ else if ( ns != splittedTypePath [ k ] ) {
53
+
54
+ isSingleNamespace = false ;
55
+ break ;
56
+ }
57
+ }
58
+ }
59
+
35
60
// Add type items.
36
- foreach ( Type type in types . OrderByType ( ) ) {
61
+ foreach ( Type type in typeArray ) {
37
62
string [ ] splittedTypePath = TypeMenuUtility . GetSplittedTypePath ( type ) ;
38
63
if ( splittedTypePath . Length == 0 ) {
39
64
continue ;
@@ -42,16 +67,19 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
42
67
AdvancedDropdownItem parent = root ;
43
68
44
69
// Add namespace items.
45
- for ( int k = 0 ; ( splittedTypePath . Length - 1 ) > k ; k ++ ) {
46
- AdvancedDropdownItem foundItem = GetItem ( parent , splittedTypePath [ k ] ) ;
47
- if ( foundItem != null ) {
48
- parent = foundItem ;
49
- } else {
50
- var newItem = new AdvancedDropdownItem ( splittedTypePath [ k ] ) {
51
- id = itemCount ++ ,
52
- } ;
53
- parent . AddChild ( newItem ) ;
54
- parent = newItem ;
70
+ if ( ! isSingleNamespace ) {
71
+ for ( int k = 0 ; ( splittedTypePath . Length - 1 ) > k ; k ++ ) {
72
+ AdvancedDropdownItem foundItem = GetItem ( parent , splittedTypePath [ k ] ) ;
73
+ if ( foundItem != null ) {
74
+ parent = foundItem ;
75
+ }
76
+ else {
77
+ var newItem = new AdvancedDropdownItem ( splittedTypePath [ k ] ) {
78
+ id = itemCount ++ ,
79
+ } ;
80
+ parent . AddChild ( newItem ) ;
81
+ parent = newItem ;
82
+ }
55
83
}
56
84
}
57
85
0 commit comments