2
using System.Collections.Generic;
4
using MonoMac.Foundation;
10
public partial class PreferencesWindowController : NSWindowController
14
// Called when created from unmanaged code
15
public PreferencesWindowController (IntPtr handle) : base (handle)
20
// Called when created directly from a XIB file
21
[Export ("initWithCoder:")]
22
public PreferencesWindowController (NSCoder coder) : base (coder)
27
// Call to load from the XIB/NIB file
28
public PreferencesWindowController () : base ("PreferencesWindow")
33
// Shared initialization code
40
List<IPreferencesTab> tabs = new List<IPreferencesTab>();
41
PreferencesToolbarDelegate toolbarDelegate;
43
// When Preference Window is loaded from a NIB we create a view controller
44
// for each tab in preferences window and initialize the toolbar.
45
public override void AwakeFromNib()
49
tabs.Add(new GeneralViewController());
50
tabs.Add(new FontsAndColorsViewController());
51
tabs.Add(new PrivacyViewController());
56
void InitializeToolbar()
58
toolbarDelegate = new PreferencesToolbarDelegate(tabs);
59
toolbarDelegate.SelectionChanged += HandleSelectionChanged;
61
Window.Toolbar = CreateToolbar ();
63
HandleSelectionChanged(this, null); // Called once when the window is created to make first tab visible
66
NSToolbar CreateToolbar ()
68
var tb = new NSToolbar ("PreferencesToolbar");
69
tb.AllowsUserCustomization = false;
70
tb.Delegate = toolbarDelegate;
71
tb.SelectedItemIdentifier = tabs.First().Name;
75
// Called when user clicks on toolbar item to change the preferences tab.
76
void HandleSelectionChanged (object sender, EventArgs e)
78
var selectedTab = tabs.Single(s => s.Name.Equals(Window.Toolbar.SelectedItemIdentifier));
79
Window.Title = selectedTab.Name;
80
ShowSelectedTab(selectedTab);
83
// Change preferences tab view to selected one. Animate resizing of the window if the selected
84
// tab is different size than the currently visible one.
85
void ShowSelectedTab(IPreferencesTab selectedTab)
87
float delta = Window.ContentView.Frame.Height - selectedTab.View.Frame.Height; // Delta must be calculated before currect tab view is removed
88
RemoveCurrentTabView();
89
Window.SetFrame(CalculateNewFrameForWindow (delta), true, true);
90
Window.ContentView.AddSubview(selectedTab.View);
93
void RemoveCurrentTabView()
95
if (Window.ContentView.Subviews.Any())
96
Window.ContentView.Subviews.Single().RemoveFromSuperview();
99
RectangleF CalculateNewFrameForWindow (float delta)
101
return new RectangleF (Window.Frame.X, Window.Frame.Y + delta, Window.Frame.Width, Window.Frame.Height - delta);