11using System ;
2+ using System . Linq ;
23using System . Collections . Generic ;
34using System . ComponentModel ;
45
@@ -43,13 +44,6 @@ public bool IsArrangeEnabled
4344 return ;
4445
4546 this . isArrangeEnabled = value ;
46- if ( value ) {
47- AddSubview ( this . propertyArrangeMode ) ;
48- AddSubview ( this . propertyArrangeModeLabel ) ;
49- } else {
50- this . propertyArrangeMode . RemoveFromSuperview ( ) ;
51- this . propertyArrangeModeLabel . RemoveFromSuperview ( ) ;
52- }
5347 }
5448 }
5549
@@ -77,6 +71,11 @@ public TargetPlatform TargetPlatform
7771 if ( this . viewModel != null ) {
7872 this . viewModel . ArrangedPropertiesChanged -= OnPropertiesChanged ;
7973 this . viewModel . PropertyChanged -= OnVmPropertyChanged ;
74+
75+ var views = this . tabStack . Views ;
76+ for ( int i = 0 ; i < views . Length ; i ++ ) {
77+ ( ( TabButton ) views [ i ] ) . Clicked -= OnArrangeModeChanged ;
78+ }
8079 }
8180
8281 this . targetPlatform = value ;
@@ -90,12 +89,18 @@ public TargetPlatform TargetPlatform
9089 this . viewModel . ArrangedPropertiesChanged += OnPropertiesChanged ;
9190 this . viewModel . PropertyChanged += OnVmPropertyChanged ;
9291
93- this . propertyArrangeMode . RemoveAll ( ) ;
94- foreach ( ArrangeModeViewModel item in this . viewModel . ArrangeModes ) {
95- var itemAsString = new NSString ( item . ArrangeMode . ToString ( ) ) ;
96- this . propertyArrangeMode . Add ( itemAsString ) ;
97- if ( item . IsChecked )
98- this . propertyArrangeMode . Select ( itemAsString ) ;
92+ for ( int i = 0 ; i < this . viewModel . ArrangeModes . Count ; i ++ ) {
93+ var item = this . viewModel . ArrangeModes [ i ] ;
94+ string imageName = GetIconName ( item . ArrangeMode ) ;
95+ TabButton arrangeMode = new TabButton ( this . hostResources , imageName ) {
96+ Bounds = new CGRect ( 0 , 0 , 32 , 30 ) ,
97+ Tag = i ,
98+ Selected = item . IsChecked
99+ } ;
100+
101+ arrangeMode . Clicked += OnArrangeModeChanged ;
102+
103+ this . tabStack . AddView ( arrangeMode , NSStackViewGravity . Top ) ;
99104 }
100105 }
101106 }
@@ -113,12 +118,9 @@ public void Select (IEnumerable<object> selectedItems)
113118
114119 public override void ViewDidChangeEffectiveAppearance ( )
115120 {
116- if ( this . propertyArrangeMode == null )
121+ if ( this . propertyTable == null )
117122 return ;
118123
119- this . propertyArrangeMode . Font = HostResourceProvider . GetNamedFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize ) ;
120- this . propertyFilter . Font = HostResourceProvider . GetNamedFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize ) ;
121-
122124 this . propertyTable . BackgroundColor = this . hostResources . GetNamedColor ( NamedResources . PadBackgroundColor ) ;
123125 }
124126
@@ -130,8 +132,7 @@ public override void ViewDidChangeEffectiveAppearance ()
130132 private PanelViewModel viewModel ;
131133
132134 private NSSearchField propertyFilter ;
133- private NSComboBox propertyArrangeMode ;
134- private NSTextField propertyArrangeModeLabel ;
135+ private NSStackView tabStack ;
135136
136137 // Shared initialization code
137138 private void Initialize ( )
@@ -140,79 +141,73 @@ private void Initialize ()
140141
141142 NSControlSize controlSize = NSControlSize . Small ;
142143
143- this . propertyArrangeModeLabel = new NSTextField {
144- ControlSize = controlSize ,
145- BackgroundColor = NSColor . Clear ,
146- Bezeled = false ,
147- Editable = false ,
148- StringValue = LocalizationResources . ArrangeByLabel ,
149- TranslatesAutoresizingMaskIntoConstraints = false ,
144+ var header = new DynamicFillBox ( HostResourceProvider , NamedResources . PanelTabBackground ) {
145+ ContentViewMargins = new CGSize ( 0 , 0 ) ,
146+ ContentView = new NSView ( )
150147 } ;
148+ AddSubview ( header ) ;
151149
152- this . propertyArrangeMode = new NSComboBox {
153- ControlSize = controlSize ,
154- Editable = false ,
155- TranslatesAutoresizingMaskIntoConstraints = false ,
150+ var border = new DynamicFillBox ( HostResourceProvider , NamedResources . TabBorderColor ) {
151+ Frame = new CGRect ( 0 , 0 , 1 , 1 )
156152 } ;
157-
158- if ( IsArrangeEnabled ) {
159- AddSubview ( this . propertyArrangeMode ) ;
160- AddSubview ( this . propertyArrangeModeLabel ) ;
161- }
153+ header . AddSubview ( border ) ;
162154
163155 this . propertyFilter = new NSSearchField {
164156 ControlSize = controlSize ,
165157 PlaceholderString = LocalizationResources . PropertyFilterLabel ,
166158 TranslatesAutoresizingMaskIntoConstraints = false ,
167159 } ;
168- AddSubview ( this . propertyFilter ) ;
160+ ( ( NSView ) header . ContentView ) . AddSubview ( this . propertyFilter ) ;
169161
170- // If either the Filter Mode or PropertySearchFilter Change Filter the Data
171- this . propertyArrangeMode . SelectionChanged += OnArrangeModeChanged ;
172162 this . propertyFilter . Changed += OnPropertyFilterChanged ;
173163
164+ this . tabStack = new NSStackView {
165+ Orientation = NSUserInterfaceLayoutOrientation . Horizontal ,
166+ TranslatesAutoresizingMaskIntoConstraints = false ,
167+ EdgeInsets = new NSEdgeInsets ( 0 , 0 , 0 , 0 )
168+ } ;
169+
170+ ( ( NSView ) header . ContentView ) . AddSubview ( this . tabStack ) ;
171+
174172 this . propertyTable = new FirstResponderOutlineView {
175173 RefusesFirstResponder = true ,
176- AutoresizingMask = NSViewResizingMask . WidthSizable ,
177174 SelectionHighlightStyle = NSTableViewSelectionHighlightStyle . None ,
178175 HeaderView = null ,
179176 } ;
180177
181- #if DESIGNER_DEBUG
182- propertyTable . GridStyleMask = NSTableViewGridStyle . SolidHorizontalLine | NSTableViewGridStyle . SolidVerticalLine ;
183- #endif
184-
185178 var propertyEditors = new NSTableColumn ( PropertyEditorColId ) ;
186179 this . propertyTable . AddColumn ( propertyEditors ) ;
187180
188181 // Set OutlineTableColumn or the arrows showing children/expansion will not be drawn
189182 this . propertyTable . OutlineTableColumn = propertyEditors ;
190183
191- // create a table view and a scroll view
192184 var tableContainer = new NSScrollView {
193185 TranslatesAutoresizingMaskIntoConstraints = false ,
194186 } ;
195187
196- // add the panel to the window
197188 tableContainer . DocumentView = this . propertyTable ;
198189 AddSubview ( tableContainer ) ;
199190
200191 this . AddConstraints ( new [ ] {
201- NSLayoutConstraint . Create ( this . propertyArrangeModeLabel , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 5f ) ,
202- NSLayoutConstraint . Create ( this . propertyArrangeModeLabel , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 10f ) ,
192+ NSLayoutConstraint . Create ( header , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1 , 0 ) ,
193+ NSLayoutConstraint . Create ( header , NSLayoutAttribute . Width , NSLayoutRelation . Equal , this , NSLayoutAttribute . Width , 1 , 0 ) ,
194+ NSLayoutConstraint . Create ( header , NSLayoutAttribute . Height , NSLayoutRelation . Equal , 1 , 30 ) ,
195+
196+ NSLayoutConstraint . Create ( this . tabStack , NSLayoutAttribute . Left , NSLayoutRelation . Equal , header , NSLayoutAttribute . Left , 1 , 0 ) ,
197+ NSLayoutConstraint . Create ( this . tabStack , NSLayoutAttribute . Top , NSLayoutRelation . Equal , header , NSLayoutAttribute . Top , 1 , 0 ) ,
198+ NSLayoutConstraint . Create ( this . tabStack , NSLayoutAttribute . Bottom , NSLayoutRelation . Equal , header , NSLayoutAttribute . Bottom , 1 , 0 ) ,
199+ NSLayoutConstraint . Create ( this . tabStack , NSLayoutAttribute . Right , NSLayoutRelation . LessThanOrEqual , this . propertyFilter , NSLayoutAttribute . Left , 1 , 0 ) ,
203200
204- NSLayoutConstraint . Create ( this . propertyArrangeMode , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 4f ) ,
205- NSLayoutConstraint . Create ( this . propertyArrangeMode , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 90f ) ,
206- NSLayoutConstraint . Create ( this . propertyArrangeMode , NSLayoutAttribute . Width , NSLayoutRelation . Equal , 1f , 130f ) ,
201+ NSLayoutConstraint . Create ( this . propertyFilter , NSLayoutAttribute . Right , NSLayoutRelation . Equal , header , NSLayoutAttribute . Right , 1 , - 15 ) ,
202+ NSLayoutConstraint . Create ( this . propertyFilter , NSLayoutAttribute . Width , NSLayoutRelation . Equal , 1 , 150 ) ,
203+ NSLayoutConstraint . Create ( this . propertyFilter , NSLayoutAttribute . CenterY , NSLayoutRelation . Equal , header , NSLayoutAttribute . CenterY , 1 , 0 ) ,
207204
208- NSLayoutConstraint . Create ( this . propertyFilter , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 3f ) ,
209- NSLayoutConstraint . Create ( this . propertyFilter , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 255f ) ,
210- NSLayoutConstraint . Create ( this . propertyFilter , NSLayoutAttribute . Width , NSLayoutRelation . Equal , this , NSLayoutAttribute . Width , 1f , - 265f ) ,
205+ NSLayoutConstraint . Create ( border , NSLayoutAttribute . Bottom , NSLayoutRelation . Equal , header , NSLayoutAttribute . Bottom , 1 , 0 ) ,
206+ NSLayoutConstraint . Create ( border , NSLayoutAttribute . Width , NSLayoutRelation . Equal , header , NSLayoutAttribute . Width , 1 , 0 ) ,
211207
212- NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 30f ) ,
213- NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 10f ) ,
214- NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Width , NSLayoutRelation . Equal , this , NSLayoutAttribute . Width , 1f , - 20f ) ,
215- NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Height , NSLayoutRelation . Equal , this , NSLayoutAttribute . Height , 1f , - 37f ) ,
208+ NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Top , NSLayoutRelation . Equal , border , NSLayoutAttribute . Bottom , 1 , 0 ) ,
209+ NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Bottom , NSLayoutRelation . Equal , this , NSLayoutAttribute . Bottom , 1 , 0 ) ,
210+ NSLayoutConstraint . Create ( tableContainer , NSLayoutAttribute . Width , NSLayoutRelation . Equal , this , NSLayoutAttribute . Width , 1 , 0 ) ,
216211 } ) ;
217212
218213 ViewDidChangeEffectiveAppearance ( ) ;
@@ -227,7 +222,7 @@ private void OnPropertiesChanged (object sender, EventArgs e)
227222
228223 private void OnArrangeModeChanged ( object sender , EventArgs e )
229224 {
230- this . viewModel . ArrangeMode = this . viewModel . ArrangeModes [ ( int ) this . propertyArrangeMode . SelectedIndex ] . ArrangeMode ;
225+ this . viewModel . ArrangeMode = this . viewModel . ArrangeModes [ ( int ) ( ( NSView ) sender ) . Tag ] . ArrangeMode ;
231226 }
232227
233228 private void OnPropertyFilterChanged ( object sender , EventArgs e )
@@ -239,8 +234,25 @@ private void OnPropertyFilterChanged (object sender, EventArgs e)
239234
240235 private void OnVmPropertyChanged ( object sender , PropertyChangedEventArgs e )
241236 {
242- if ( e . PropertyName == nameof ( PanelViewModel . ArrangeMode ) || String . IsNullOrEmpty ( e . PropertyName ) )
243- this . propertyArrangeMode . Select ( new NSString ( this . viewModel . ArrangeMode . ToString ( ) ) ) ;
237+ if ( e . PropertyName == nameof ( PanelViewModel . ArrangeMode ) || String . IsNullOrEmpty ( e . PropertyName ) ) {
238+ int selected = this . viewModel . ArrangeModes . Select ( vm => vm . ArrangeMode ) . IndexOf ( this . viewModel . ArrangeMode ) ;
239+ var views = this . tabStack . Views ;
240+ for ( int i = 0 ; i < views . Length ; i ++ ) {
241+ ( ( TabButton ) views [ i ] ) . Selected = ( i == selected ) ;
242+ }
243+ }
244+ }
245+
246+ private string GetIconName ( PropertyArrangeMode mode )
247+ {
248+ switch ( mode ) {
249+ case PropertyArrangeMode . Name :
250+ return "sort-alphabetically-16" ;
251+ case PropertyArrangeMode . Category :
252+ return "group-by-category-16" ;
253+ default :
254+ throw new ArgumentException ( ) ;
255+ }
244256 }
245257
246258 private class FirstResponderOutlineView : NSOutlineView
0 commit comments