@@ -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,31 @@ 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+
54+ isSingleNamespace = false ;
55+ break ;
56+ }
57+ }
58+ }
59+
3560 // Add type items.
36- foreach ( Type type in types . OrderByType ( ) ) {
61+ foreach ( Type type in typeArray ) {
3762 string [ ] splittedTypePath = TypeMenuUtility . GetSplittedTypePath ( type ) ;
3863 if ( splittedTypePath . Length == 0 ) {
3964 continue ;
@@ -42,16 +67,19 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
4267 AdvancedDropdownItem parent = root ;
4368
4469 // 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+ }
5583 }
5684 }
5785
0 commit comments