@@ -23,6 +23,8 @@ public AdvancedTypePopupItem (Type type,string name) : base(name) {
2323 /// </summary>
2424 public class AdvancedTypePopup : AdvancedDropdown {
2525
26+ const int kMaxNamespaceNestCount = 16 ;
27+
2628 public static void AddTo ( AdvancedDropdownItem root , IEnumerable < Type > types ) {
2729 int itemCount = 0 ;
2830
@@ -32,8 +34,30 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
3234 } ;
3335 root . AddChild ( nullItem ) ;
3436
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+
3559 // Add type items.
36- foreach ( Type type in types . OrderByType ( ) ) {
60+ foreach ( Type type in typeArray ) {
3761 string [ ] splittedTypePath = TypeMenuUtility . GetSplittedTypePath ( type ) ;
3862 if ( splittedTypePath . Length == 0 ) {
3963 continue ;
@@ -42,16 +66,19 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
4266 AdvancedDropdownItem parent = root ;
4367
4468 // 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+ }
5582 }
5683 }
5784
0 commit comments