/SparkleShare/Mac/SparkleSetupWindow.cs

http://github.com/hbons/SparkleShare · C# · 156 lines · 100 code · 40 blank · 16 comment · 9 complexity · d7a7d41e52d6149498b929045ee8a5df MD5 · raw file

  1. // SparkleShare, an instant update workflow to Git.
  2. // Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Drawing;
  19. using System.IO;
  20. using MonoMac.Foundation;
  21. using MonoMac.AppKit;
  22. namespace SparkleShare {
  23. public class SparkleSetupWindow : NSWindow {
  24. public List <NSButton> Buttons = new List <NSButton> ();
  25. public string Header;
  26. new public string Description;
  27. private NSImage side_splash;
  28. private NSImageView side_splash_view;
  29. private NSTextField header_text_field, description_text_field;
  30. public SparkleSetupWindow (IntPtr handle) : base (handle) { }
  31. public SparkleSetupWindow () : base ()
  32. {
  33. SetFrame (new RectangleF (0, 0, 640, 420), true);
  34. StyleMask = NSWindowStyle.Titled;
  35. MaxSize = new SizeF (640, 420);
  36. MinSize = new SizeF (640, 420);
  37. HasShadow = true;
  38. BackingType = NSBackingStore.Buffered;
  39. Level = NSWindowLevel.Floating;
  40. Center ();
  41. this.side_splash = NSImage.ImageNamed ("side-splash");
  42. this.side_splash.Size = new SizeF (150, 482);
  43. this.side_splash_view = new NSImageView () {
  44. Image = this.side_splash,
  45. Frame = new RectangleF (0, 0, 150, 482)
  46. };
  47. this.header_text_field = new SparkleLabel ("", NSTextAlignment.Left) {
  48. Frame = new RectangleF (190, Frame.Height - 80, Frame.Width, 24),
  49. Font = NSFontManager.SharedFontManager.FontWithFamily (
  50. SparkleUI.FontName, NSFontTraitMask.Bold, 0, 16)
  51. };
  52. this.description_text_field = new SparkleLabel ("", NSTextAlignment.Left) {
  53. Frame = new RectangleF (190, Frame.Height - 130, 640 - 240, 44)
  54. };
  55. this.header_text_field.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
  56. if (Program.UI != null)
  57. Program.UI.UpdateDockIconVisibility ();
  58. }
  59. public void Reset ()
  60. {
  61. ContentView.Subviews = new NSView [0];
  62. Buttons = new List <NSButton> ();
  63. Header = "";
  64. Description = "";
  65. }
  66. public void ShowAll ()
  67. {
  68. this.header_text_field.StringValue = Header;
  69. this.description_text_field.StringValue = Description;
  70. ContentView.AddSubview (this.side_splash_view);
  71. ContentView.AddSubview (this.header_text_field);
  72. if (!string.IsNullOrEmpty (Description))
  73. ContentView.AddSubview (this.description_text_field);
  74. int i = 1;
  75. int x = 0;
  76. if (Buttons.Count > 0) {
  77. DefaultButtonCell = Buttons [0].Cell;
  78. foreach (NSButton button in Buttons) {
  79. button.BezelStyle = NSBezelStyle.Rounded;
  80. button.Frame = new RectangleF (Frame.Width - 15 - x - (105 * i), 12, 105, 32);
  81. // Make the button a bit wider if the text is likely to be longer
  82. if (button.Title.Contains (" ")) {
  83. button.SizeToFit ();
  84. button.Frame = new RectangleF (Frame.Width - 30 - 15 - (105 * (i - 1)) - button.Frame.Width,
  85. 12, button.Frame.Width + 30, 32);
  86. x += 22;
  87. }
  88. ContentView.AddSubview (button);
  89. i++;
  90. }
  91. }
  92. RecalculateKeyViewLoop ();
  93. }
  94. public override void OrderFrontRegardless ()
  95. {
  96. NSApplication.SharedApplication.AddWindowsItem (this, "SparkleShare Setup", false);
  97. NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
  98. MakeKeyAndOrderFront (this);
  99. if (Program.UI != null)
  100. Program.UI.UpdateDockIconVisibility ();
  101. base.OrderFrontRegardless ();
  102. }
  103. public override void PerformClose (NSObject sender)
  104. {
  105. base.OrderOut (this);
  106. NSApplication.SharedApplication.RemoveWindowsItem (this);
  107. if (Program.UI != null)
  108. Program.UI.UpdateDockIconVisibility ();
  109. return;
  110. }
  111. public override bool AcceptsFirstResponder ()
  112. {
  113. return true;
  114. }
  115. }
  116. }