Advertisement
Guest User

Passive MVP -Cocoa/MonoMac Code Example

a guest
Jan 30th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. namespace MonoMac.Views.Bootstrap
  2. {
  3.     public class BootstrapView : NSWindow, IBootstrapView
  4.     {
  5.         public BootstrapView ()
  6.         {
  7.             Initialize ();
  8.         }
  9.  
  10.         #region Initialization
  11.         /// <summary>
  12.         /// Show this instance.
  13.         /// </summary>
  14.         public void Show()
  15.         {
  16.             MakeKeyAndOrderFront(this);
  17.             if (StartBootstrap != null) {
  18.                 StartBootstrap ();
  19.             }
  20.         }
  21.  
  22.         /// <summary>
  23.         /// Initializes the view and it's controls.
  24.         /// </summary>
  25.         private void Initialize()
  26.         {
  27.             // Initialize window.
  28.             InitializeWindow();
  29.  
  30.             // Initialize controls.
  31.             InitializeControls();
  32.  
  33.             // Centers the window.
  34.             Center();
  35.         }
  36.  
  37.         /// <summary>
  38.         /// Initializes the window.
  39.         /// </summary>
  40.         private void InitializeWindow ()
  41.         {
  42.             StyleMask = NSWindowStyle.Titled;
  43.             SetContentSize (new SizeF (505, 54));
  44.         }
  45.            
  46.  
  47.         /// <summary>
  48.         /// Initializes the controls.
  49.         /// </summary>
  50.         private void InitializeControls()
  51.         {
  52.             var padding = 10;
  53.  
  54.             // Progress Message
  55.             uxProgressMessage = Controls.CreateLabel ("%uxProgressMessage%", 16);
  56.             this.AddControl (uxProgressMessage, padding + 32, padding + 8);
  57.  
  58.             // Progress Spinner
  59.             uxProgress = Controls.CreateProgressSpinner (18, 18);
  60.             this.AddControl (uxProgress, padding + 8, padding + 8);
  61.  
  62.             // Quit Button
  63.             uxQuit = Controls.CreateButton ("Afsluiten");
  64.             uxQuit.Activated += uxQuit_Activated;
  65.             this.AddControl (uxQuit, (int)(ContentView.Frame.Width - padding - uxQuit.Frame.Width), padding + 5);
  66.         }
  67.         private NSTextField uxProgressMessage;
  68.         private NSProgressIndicator uxProgress;
  69.         private NSButton uxQuit;
  70.         #endregion
  71.  
  72.         #region IBootstrapView
  73.         public event QuitApplicationEventHandler QuitApplication;
  74.         private void uxQuit_Activated(object sender, EventArgs e)
  75.         {
  76.             if (QuitApplication != null) {
  77.                 QuitApplication (this, new ActionEventArgs(() => NSApplication.SharedApplication.Terminate(this)));
  78.             }
  79.         }
  80.         public event StartBootstrapEventHandler StartBootstrap;
  81.         public event ShowDebugInfoEventHandler ShowDebugInfo;
  82.         public ProgressInfo Progress {
  83.             set {
  84.                 uxProgressMessage.StringValue = value.Message;
  85.                 uxProgressMessage.SizeToFit ();
  86.  
  87.                 if (!value.IsIndeterminate) {
  88.                     uxProgress.Indeterminate = false;
  89.                     uxProgress.MinValue = value.Range.Minimum;
  90.                     uxProgress.MaxValue = value.Range.Maximum;
  91.                     uxProgress.DoubleValue = value.Progress;
  92.                 }
  93.             }
  94.         }
  95.         #endregion
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement