@@ -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,30 @@ 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
+ isSingleNamespace = false ;
54
+ break ;
55
+ }
56
+ }
57
+ }
58
+
35
59
// Add type items.
36
- foreach ( Type type in types . OrderByType ( ) ) {
60
+ foreach ( Type type in typeArray ) {
37
61
string [ ] splittedTypePath = TypeMenuUtility . GetSplittedTypePath ( type ) ;
38
62
if ( splittedTypePath . Length == 0 ) {
39
63
continue ;
@@ -42,16 +66,19 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
42
66
AdvancedDropdownItem parent = root ;
43
67
44
68
// 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 ;
69
+ if ( ! isSingleNamespace ) {
70
+ for ( int k = 0 ; ( splittedTypePath . Length - 1 ) > k ; k ++ ) {
71
+ AdvancedDropdownItem foundItem = GetItem ( parent , splittedTypePath [ k ] ) ;
72
+ if ( foundItem != null ) {
73
+ parent = foundItem ;
74
+ }
75
+ else {
76
+ var newItem = new AdvancedDropdownItem ( splittedTypePath [ k ] ) {
77
+ id = itemCount ++ ,
78
+ } ;
79
+ parent . AddChild ( newItem ) ;
80
+ parent = newItem ;
81
+ }
55
82
}
56
83
}
57
84
0 commit comments