PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 17
 18using System;
 19using System.Collections.Generic;
 20using System.Drawing;
 21using System.IO;
 22
 23using MonoMac.Foundation;
 24using MonoMac.AppKit;
 25
 26namespace SparkleShare {
 27
 28    public class SparkleSetupWindow : NSWindow {
 29
 30        public List <NSButton> Buttons = new List <NSButton> ();
 31        public string Header;
 32        new public string Description;
 33
 34        private NSImage side_splash;
 35        private NSImageView side_splash_view;
 36        private NSTextField header_text_field, description_text_field;
 37
 38
 39        public SparkleSetupWindow (IntPtr handle) : base (handle) { }
 40
 41        public SparkleSetupWindow () : base ()
 42        {
 43            SetFrame (new RectangleF (0, 0, 640, 420), true);
 44
 45            StyleMask   = NSWindowStyle.Titled;
 46            MaxSize     = new SizeF (640, 420);
 47            MinSize     = new SizeF (640, 420);
 48            HasShadow   = true;
 49            BackingType = NSBackingStore.Buffered;
 50            Level       = NSWindowLevel.Floating;
 51
 52            Center ();
 53
 54            this.side_splash = NSImage.ImageNamed ("side-splash");
 55            this.side_splash.Size = new SizeF (150, 482);
 56
 57            this.side_splash_view = new NSImageView () {
 58                Image = this.side_splash,
 59                Frame = new RectangleF (0, 0, 150, 482)
 60            };
 61
 62            this.header_text_field = new SparkleLabel ("", NSTextAlignment.Left) {
 63                Frame = new RectangleF (190, Frame.Height - 80, Frame.Width, 24),
 64                Font  = NSFontManager.SharedFontManager.FontWithFamily (
 65                    SparkleUI.FontName, NSFontTraitMask.Bold, 0, 16)
 66            };
 67
 68            this.description_text_field = new SparkleLabel ("", NSTextAlignment.Left) {
 69                Frame = new RectangleF (190, Frame.Height - 130, 640 - 240, 44)
 70            };
 71
 72            this.header_text_field.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
 73
 74            if (Program.UI != null)
 75                Program.UI.UpdateDockIconVisibility ();
 76        }
 77
 78        
 79        public void Reset ()
 80        {
 81            ContentView.Subviews = new NSView [0];
 82            Buttons              = new List <NSButton> ();
 83            Header               = "";
 84            Description          = "";
 85        }
 86
 87
 88        public void ShowAll ()
 89        {
 90            this.header_text_field.StringValue      = Header;
 91            this.description_text_field.StringValue = Description;
 92            
 93            ContentView.AddSubview (this.side_splash_view);
 94            ContentView.AddSubview (this.header_text_field);
 95
 96            if (!string.IsNullOrEmpty (Description))
 97                ContentView.AddSubview (this.description_text_field);
 98
 99            int i = 1;
100            int x = 0;
101            if (Buttons.Count > 0) {
102                DefaultButtonCell = Buttons [0].Cell;
103                
104                foreach (NSButton button in Buttons) {
105                    button.BezelStyle = NSBezelStyle.Rounded;
106                    button.Frame      = new RectangleF (Frame.Width - 15 - x - (105 * i), 12, 105, 32);
107
108                    // Make the button a bit wider if the text is likely to be longer
109                    if (button.Title.Contains (" ")) {
110                        button.SizeToFit ();
111                        button.Frame = new RectangleF (Frame.Width - 30 - 15 - (105 * (i - 1)) - button.Frame.Width,
112                            12, button.Frame.Width + 30, 32);
113
114                        x += 22;
115                    }
116
117                    ContentView.AddSubview (button);
118                    i++;
119                }
120            }
121
122            RecalculateKeyViewLoop ();
123        }
124
125
126        public override void OrderFrontRegardless ()
127        {
128            NSApplication.SharedApplication.AddWindowsItem (this, "SparkleShare Setup", false);
129            NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
130            MakeKeyAndOrderFront (this);
131
132            if (Program.UI != null)
133                Program.UI.UpdateDockIconVisibility ();
134            
135            base.OrderFrontRegardless ();
136        }
137
138
139        public override void PerformClose (NSObject sender)
140        {
141            base.OrderOut (this);
142            NSApplication.SharedApplication.RemoveWindowsItem (this);
143
144            if (Program.UI != null)
145                Program.UI.UpdateDockIconVisibility ();
146
147            return;
148        }
149
150
151        public override bool AcceptsFirstResponder ()
152        {
153            return true;
154        }
155    }
156}