partial void okButtonClicked(MonoMac.AppKit.NSButton sender)
        {
            spinner.Hidden = false;
            spinner.StartAnimation(this);

            NSError error;
            var     networkName   = nameTextField.StringValue;
            var     password      = passwordTextField.StringValue;
            var     channelNumber = UInt32.Parse(channelPicker.SelectedItem.Title);
            var     security      = string.IsNullOrEmpty(password) ? CWIbssModeSecurity.None : CWIbssModeSecurity.WEP40;

            CurrentInterface.StartIbssModeWithSsid(new NSData(), security, channelNumber, password, out error);

            spinner.StopAnimation(this);
            spinner.Hidden = true;

            if (error != null)
            {
                NSAlert.WithError(error).RunModal();
            }
            else
            {
                Window.Close();
            }
        }
        partial void NotifyMeAction(MonoMac.AppKit.NSButton sender)
        {
            // First we create our notification and customize as needed
            NSUserNotification not = new NSUserNotification();

            not.Title           = "Hello World";
            not.InformativeText = "This is an informative text";
            not.DeliveryDate    = DateTime.Now;
            not.SoundName       = NSUserNotification.NSUserNotificationDefaultSoundName;

            // We get the Default notification Center
            NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;

            center.DidDeliverNotification += (s, e) =>
            {
                Console.WriteLine("Notification Delivered");
                DeliveredColorWell.Color = NSColor.Green;
            };

            center.DidActivateNotification += (s, e) =>
            {
                Console.WriteLine("Notification Touched");
                TouchedColorWell.Color = NSColor.Green;
            };

            // If we return true here, Notification will show up even if your app is TopMost.
            center.ShouldPresentNotification = (c, n) => { return(true); };

            center.ScheduleNotification(not);
        }
		public override void ViewDidLoad ()
		{
			View = new NSView (new RectangleF (0, 0, 320, 400));
			base.ViewDidLoad ();

			var textEditFirst = new NSTextField(new System.Drawing.RectangleF(0,0,320,40));
			View.AddSubview (textEditFirst);
			var textEditSecond = new NSTextField(new System.Drawing.RectangleF(0,50,320,40));
			View.AddSubview(textEditSecond);
			var slider = new NSSlider(new System.Drawing.RectangleF(0,150,320,40));
			slider.MinValue = 0;
			slider.MaxValue = 100;
			slider.IntValue = 23;
			View.AddSubview(slider);
			var labelFull = new NSTextField(new System.Drawing.RectangleF(0,100,320,40));
			labelFull.Editable = false;
			labelFull.Bordered = false;
			labelFull.AllowsEditingTextAttributes = false;
			labelFull.DrawsBackground = false;
			View.AddSubview (labelFull);
			var sw = new NSButton(new RectangleF(0,200,320,40));
			sw.SetButtonType (NSButtonType.Switch);
			View.AddSubview (sw);
			//sw.AddObserver()

			var set = this.CreateBindingSet<SecondViewController, SecondViewModel> ();
			set.Bind (textEditFirst).For(v => v.StringValue).To (vm => vm.FirstName);
			set.Bind (textEditSecond).For(v => v.StringValue).To (vm => vm.LastName);
			set.Bind (labelFull).Described("SliderValue + ' ' + OnOffValue").For("StringValue");	
			set.Bind (slider).For("IntValue").To (vm => vm.SliderValue);
			set.Bind (sw).For(c => c.State).To (vm => vm.OnOffValue);


			set.Apply ();
		}
partial         void useNumbersPressed(NSButton sender)
        {
            if( sender.IntValue == 0 )
                useNumbers = false;
            else
                useNumbers = true;
        }
partial         void useLowerCaseLettersPressed(NSButton sender)
        {
            if( sender.IntValue == 0 )
                useLowercaseLetters = false;
            else
                useLowercaseLetters = true;
        }
Ejemplo n.º 6
0
 partial void BtnClicked(MonoMac.AppKit.NSButton sender)
 {
     if (null != CommandSelected)
     {
         CommandSelected(this, m_Cmds[sender.Title]);
     }
 }
Ejemplo n.º 7
0
		partial void lightPointalize (NSButton sender)
		{
			if (controls.ContentFilters == null || controls.ContentFilters.Count() == 0)
				Pointalize();	
			
			var path = string.Format ("contentFilters.pointalize.{0}", CIFilter.InputRadiusKey);
			controls.SetValueForKeyPath (NSNumber.FromFloat (1.0f), (NSString)path);
		}
        partial void exportFile(MonoMac.AppKit.NSButton sender)
        {
            var        scfExport = new ExportSCF(txt_input.StringValue, txt_output.StringValue);
            NSTextView txt       = (NSTextView)txt_fld_output.DocumentView;

            //txt.TextStorage.Append(new NSAttributedString(parser.GetParseOutput()));
            txt.TextStorage.Append(new NSAttributedString(scfExport.DebugOutput));
        }
		// Action for Remove pushbutton
		partial void removeLastBox (NSButton sender)
		{
			if (simpleView.Subviews.Length == 0)
				return;
			
			simpleView.Subviews.Last ().RemoveFromSuperview ();
			layout ();
		}
		partial void makeFast (NSButton sender)
		{
			CABasicAnimation frameOriginAnimation = new CABasicAnimation();
			frameOriginAnimation.Duration = 0.1f;
			NSDictionary animations = NSDictionary.FromObjectAndKey(frameOriginAnimation,
			                                                        (NSString)"frameOrigin");
			myView.Mover.Animations = animations;
		}
 public MvxNSButtonTitleTargetBinding(NSButton button)
     : base(button)
 {
     if (button == null)
     {
         MvxBindingTrace.Trace(MvxTraceLevel.Error, "Error - NSButton is null in MvxNSButtonTitleTargetBinding");
     }
 }
Ejemplo n.º 12
0
		partial void heavyPointalize (NSButton sender)
		{
			if (controls.ContentFilters == null || controls.ContentFilters.Count() == 0)
				Pointalize();	
			
			string path = string.Format ("contentFilters.pointalize.{0}", CIFilterInputKey.Radius);
			controls.SetValueForKeyPath (NSNumber.FromFloat (5), (NSString)path);
		}
Ejemplo n.º 13
0
partial         void generatePasswordClicked(NSButton sender)
        {
            gen = new Generator(Int32.Parse( passwordLengthText.StringValue ),
                                useUppercaseLetters,
                                useLowercaseLetters,
                                useNumbers,
                                useSpecialCharacters);
            generatedPasswordText.StringValue = gen.GeneratePassword();
        }
 partial void requestAction (NSButton sender)
 {
         myTimer = NSTimer.CreateScheduledTimer (3.0, delegate {
                 if (popupRequestType.Cell.SelectedItemIndex == 0)
                         NSApp.RequestUserAttention (NSRequestUserAttentionType.InformationalRequest);
                 else
                         NSApp.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
         });
 }
Ejemplo n.º 15
0
        // The user clicked the Set Title button, so we'll take whatever text is in
        // the titleText NSTextField and replace the current content of the 'contentTitle'
        // H1 tag in the HTML with the new text. This shows you how to replace some HTML
        // content with new content.
        partial void setTitle(MonoMac.AppKit.NSButton sender)
        {
            var     document = webView.MainFrame.DomDocument;
            DomText newText  = document.CreateTextNode(titleText.StringValue);

            var contentTitle = document.GetElementById("contentTitle");

            contentTitle.ReplaceChild(newText, contentTitle.FirstChild);
        }
Ejemplo n.º 16
0
		partial void openInDefaultBrowser (NSButton sender)
		{
			CLLocation currentLocation = locationManager.Location;
			
			var urlPath = String.Format("http://maps.google.com/maps?ll={0},{1}&amp;spn={2},{3}",
						    currentLocation.Coordinate.Latitude,currentLocation.Coordinate.Longitude,
						    latitudeRangeForLocation (currentLocation), longitudeRangeForLocation (currentLocation));

			var externalBrowserURL = new NSUrl (urlPath);
			NSWorkspace.SharedWorkspace.OpenUrl (externalBrowserURL);
		}
Ejemplo n.º 17
0
		partial void DeleteButtonClicked (NSButton sender)
		{
			if (bookmarkTableView.SelectedRowCount != 1)
				return;
			
			var index = bookmarkTableView.SelectedRow;
			if (index < 0 || index > bookmarkTableView.RowCount)
				return;
			var temp = BookmarkDeleted;
			if (temp != null)
				temp (index);
		}
Ejemplo n.º 18
0
		partial void startStopAction (NSButton sender) 
		{
			if (sender.Title == "Start") {
				counter.Start ();
				sender.Title = "Stop";
				GrowlApplicationBridge.Notify ("The two-minute rule is magic.", 
				                               "You now have two minutes to Get Your Things Done.", "Start", null, 0, false, null);
			} else {
				counter.Stop ();
				sender.Title = "Start";
				if (counter.TimerMark.Minutes > 0 && counter.TimerMark.Seconds > 0)
					GrowlApplicationBridge.Notify ("Action Completed", String.Format ("You still have {0} left.  Step back and breath.  " + "Take a second and contemplate what you have achieved.  " + "You'll be suprised how many two-minute actions you can " + "perform even on your most critical projects", counter.TimeLeft), "Stop", null, 0, true, null);
			}
		}
Ejemplo n.º 19
0
        public Canvas()
        {
            root = new RootNode ();
            renderers = new List<object> ();
            uisync = new UISyncInvoke ();
            Motion.Tweener.Sync = uisync;

            testButton = new NSButton (new System.Drawing.RectangleF (100, 100, 100, 50));
            testButton.BezelStyle = NSBezelStyle.Rounded;

            testButton.FrameCenterRotation = 40;

            AddSubview (testButton);
        }
		partial void goFullScreen (NSButton sender)
		{
			isInFullScreenMode = true;
			
			// Pause the non-fullscreen view
			openGLView.StopAnimation ();
			
			RectangleF mainDisplayRect;
			RectangleF viewRect;
			
			// Create a screen-sized window on the display you want to take over
			// Note, mainDisplayRect has a non-zero origin if the key window is on a secondary display
			mainDisplayRect = NSScreen.MainScreen.Frame;
			
			fullScreenWindow = new NSWindow (mainDisplayRect, NSWindowStyle.Borderless, NSBackingStore.Buffered, true);
			
			// Set the window level to be above the menu bar
			fullScreenWindow.Level = NSWindowLevel.MainMenu + 1;
			
			// Perform any other window configuration you desire
			fullScreenWindow.IsOpaque = true;
			fullScreenWindow.HidesOnDeactivate = true;
			
			// Create a view with a double-buffered OpenGL context and attach it to the window
			// By specifying the non-fullscreen context as the shareContext, we automatically inherit the 
			// OpenGL objects (textures, etc) it has defined
			viewRect = new RectangleF (0, 0, mainDisplayRect.Size.Width, mainDisplayRect.Size.Height);
			
			fullScreenView = new MyOpenGLView (viewRect, openGLView.OpenGLContext);
			fullScreenWindow.ContentView = fullScreenView;
			
			// Show the window
			fullScreenWindow.MakeKeyAndOrderFront (this);
			
			// Set the scene with the full-screen viewport and viewing transformation
			Scene.setViewportRect (viewRect);
			
			// Assign the view's MainController to self
			fullScreenView.MainController = this;
			
			if (!isAnimating) {
				// Mark the view as needing drawing to initalize its contents
				fullScreenView.NeedsDisplay = true;
			} else {
				// Start playing the animation
				fullScreenView.StartAnimation ();
				
			}
		}
		partial void AddButtonClicked (NSButton sender)
		{
			var panel = NSOpenPanel.OpenPanel;
			panel.FloatingPanel = true;
			panel.CanChooseDirectories = true;
			panel.CanChooseFiles = true;
			//FIXME - create enum for open/save panel return code
			int i = panel.RunModal ();
			if (i == 1 && panel.Urls != null) {
				foreach (NSUrl url in panel.Urls) {
					browseData.AddImages (url);
				}
				browserView.ReloadData ();
			}
		}
		partial void openInDefaultBrowser (NSButton sender)
		{
			CLLocation currentLocation = locationManager.Location;
			
			// it can take a few seconds before a location is returned
			if (currentLocation == null) {
				AppKitFramework.NSBeep ();
				return;
			}
			
			var urlPath = String.Format("http://maps.google.com/maps?ll={0},{1}&amp;spn={2},{3}",
						    currentLocation.Coordinate.Latitude,currentLocation.Coordinate.Longitude,
						    latitudeRangeForLocation (currentLocation), longitudeRangeForLocation (currentLocation));

			var externalBrowserURL = new NSUrl (urlPath);
			NSWorkspace.SharedWorkspace.OpenUrl (externalBrowserURL);
		}
Ejemplo n.º 23
0
        // The user just clicked the Add Content NSButton, so we'll add a new P tag
        // and a new I tag to the HTML, with some default content.
        // This shows you how to add content into an HTML document without reloading the page.
        partial void addContent(MonoMac.AppKit.NSButton sender)
        {
            var document  = webView.MainFrameDocument;
            var paraBlock = document.GetElementById("main_content");

            var newPara = document.CreateElement("p");
            var newItal = document.CreateElement("i");
            var newText = document.CreateTextNode("Some new italic content");

            newPara.AppendChild(newItal);
            newItal.AppendChild(newText);
            paraBlock.AppendChild(newPara);


            // This is a different way to change the whole text.
            // Useful for replacing the ".InnerText = some string" used by Internet Explorer engine
            //paraBlock.TextContent = "Text replaced from Mono";
        }
Ejemplo n.º 24
0
        public Note()
            : base()
        {
            SetFrame (new RectangleF (0, 0, 480, 240), true);
            Center ();

            Delegate    = new SparkleNoteDelegate ();
            StyleMask   = (NSWindowStyle.Closable | NSWindowStyle.Titled);
            Title       = "Add Note";
            MaxSize     = new SizeF (480, 240);
            MinSize     = new SizeF (480, 240);
            HasShadow   = true;
            IsOpaque    = false;
            BackingType = NSBackingStore.Buffered;
            Level       = NSWindowLevel.Floating;

            this.hidden_close_button = new NSButton () {
                Frame                     = new RectangleF (0, 0, 0, 0),
                KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                KeyEquivalent             = "w"
            };

            CreateNote ();

            this.hidden_close_button.Activated += delegate { Controller.WindowClosed (); };

            Controller.HideWindowEvent += delegate {
                SparkleShare.Controller.Invoke (() => PerformClose (this));
            };

            Controller.ShowWindowEvent += delegate {
                SparkleShare.Controller.Invoke (() => OrderFrontRegardless ());
                CreateNote ();
            };

            Controller.UpdateTitleEvent += delegate (string title) {
                SparkleShare.Controller.Invoke (() => { Title = title; });
            };

            ContentView.AddSubview (this.hidden_close_button);
        }
Ejemplo n.º 25
0
        partial void NotifyMeAction(MonoMac.AppKit.NSButton sender)
        {
            // First we create our notification and customize as needed
            NSUserNotification not = null;

            try {
                not = new NSUserNotification();
            } catch {
                new NSAlert {
                    MessageText     = "NSUserNotification Not Supported",
                    InformativeText = "This API was introduced in OS X Mountain Lion (10.8)."
                }.RunSheetModal(this);
                return;
            }

            not.Title           = "Hello World";
            not.InformativeText = "This is an informative text";
            not.DeliveryDate    = DateTime.Now;
            not.SoundName       = NSUserNotification.NSUserNotificationDefaultSoundName;

            // We get the Default notification Center
            NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;

            center.DidDeliverNotification += (s, e) =>
            {
                Console.WriteLine("Notification Delivered");
                DeliveredColorWell.Color = NSColor.Green;
            };

            center.DidActivateNotification += (s, e) =>
            {
                Console.WriteLine("Notification Touched");
                TouchedColorWell.Color = NSColor.Green;
            };

            // If we return true here, Notification will show up even if your app is TopMost.
            center.ShouldPresentNotification = (c, n) => { return(true); };

            center.ScheduleNotification(not);
        }
Ejemplo n.º 26
0
        public SparkleAbout () : base ()
        {
            SetFrame (new RectangleF (0, 0, 640, 281), true);
            Center ();

            Delegate    = new SparkleAboutDelegate ();
            StyleMask   = (NSWindowStyle.Closable | NSWindowStyle.Titled);
            Title       = "About SparkleShare";
            MaxSize     = new SizeF (640, 281);
            MinSize     = new SizeF (640, 281);
            HasShadow   = true;
            BackingType = NSBackingStore.Buffered;
            Level       = NSWindowLevel.Floating;

            this.hidden_close_button = new NSButton () {
                Frame                     = new RectangleF (0, 0, 0, 0),
                KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                KeyEquivalent             = "w"
            };

            CreateAbout ();


            this.hidden_close_button.Activated += delegate { Controller.WindowClosed (); };

            Controller.HideWindowEvent += delegate {
                Program.Controller.Invoke (() => PerformClose (this));
            };

            Controller.ShowWindowEvent += delegate {
                Program.Controller.Invoke (() => OrderFrontRegardless ());
            };

            Controller.UpdateLabelEvent += delegate (string text) {
                Program.Controller.Invoke (() => { this.updates_text_field.StringValue = text; });
            };


            ContentView.AddSubview (this.hidden_close_button);
        }
Ejemplo n.º 27
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib ();

            CloseButton = new NSButton ();
            CloseButton.BezelStyle = NSBezelStyle.Circular;
            CloseButton.Bordered = false;

            NSButton windowCloseButton = StandardWindowButton (NSWindowButton.CloseButton);
            NSButton windowMinimizeButton = StandardWindowButton (NSWindowButton.MiniaturizeButton);
            NSButton windowZoomButton = StandardWindowButton (NSWindowButton.ZoomButton);

            windowZoomButton.Hidden = true;
            windowMinimizeButton.Hidden = true;
            windowCloseButton.Hidden = true;

            if (NSScreen.MainScreen.BackingScaleFactor > 1.0f) {
                AssignCloseImage ("*****@*****.**",
                              "*****@*****.**");
                AssignBackgroundImage ("*****@*****.**");
            } else {
                AssignCloseImage ("lightdialog.close.png",
                              "lightdialog.close_pressed.png");
                AssignBackgroundImage ("lightwindow.paper.png");
            }

            NSView themeFrame = ContentView.Superview;
            RectangleF containerFrame = themeFrame.Frame;
            RectangleF buttonFrame = CloseButton.Frame;

            CloseButton.Frame = new RectangleF (
                1.0f, containerFrame.Size.Height - buttonFrame.Size.Height - 2,
                buttonFrame.Size.Width, buttonFrame.Size.Height);;
            themeFrame.AddSubview (CloseButton);
            CloseButton.AutoresizingMask = NSViewResizingMask.MinXMargin | NSViewResizingMask.MinYMargin;
            CloseButton.Enabled = true;
            CloseButton.Target = this;
            CloseButton.Action = new Selector("performClose:");
        }
Ejemplo n.º 28
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup) {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what's your name and email?\n(visible only to team members)";

                FullNameLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 234, 160, 17),
                    StringValue     = "Full Name:",
                    Font            = SparkleUI.Font
                };

                FullNameTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser ().RealName,
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                EmailLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                    StringValue     = "Email:",
                    Font            = SparkleUI.Font
                };

                EmailTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };

                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim ();
                    string email     = EmailTextField.StringValue.Trim ();

                    Controller.SetupPageCompleted (full_name, email);
                };

                CancelButton.Activated += delegate {
                    Controller.SetupPageCancelled ();
                };

                Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (delegate {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (FullNameLabel);
                ContentView.AddSubview (FullNameTextField);
                ContentView.AddSubview (EmailLabel);
                ContentView.AddSubview (EmailTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
            }

            if (type == PageType.Invite) {
                Header      = "You've received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 240, 160, 17),
                    StringValue     = "Address:",
                    Font            = SparkleUI.Font
                };

                PathLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.Font
                };

                AddressTextField = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (330, Frame.Height - 240, 260, 17),
                    StringValue     = Controller.PendingInvite.Address,
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (330, Frame.Height - 264, 260, 17),
                    StringValue     = Controller.PendingInvite.RemotePath,
                    Font            = SparkleUI.BoldFont
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                AddButton = new NSButton () {
                    Title = "Add"
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled ();
                };

                AddButton.Activated += delegate {
                    Controller.InvitePageCompleted ();
                };

                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (PathTextField);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Add) {
                Header      = "Where's your project hosted?";
                Description = "";

                AddressLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (190, Frame.Height - 308, 160, 17),
                    StringValue     = "Address:",
                    Font            = SparkleUI.BoldFont
                };

                AddressTextField = new NSTextField () {
                    Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                    Font        = SparkleUI.Font,
                    Enabled     = (Controller.SelectedPlugin.Address == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField () {
                    Frame       = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPlugin.Path == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new NSTextField () {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.PathExample
                };

                AddressHelpLabel = new NSTextField () {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF (190, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.AddressExample
                };

                TableView = new NSTableView () {
                    Frame            = new RectangleF (0, 0, 0, 0),
                    RowHeight        = 34,
                    IntercellSpacing = new SizeF (8, 12),
                    HeaderView       = null,
                    Delegate         = new SparkleTableViewDelegate ()
                };

                ScrollView = new NSScrollView () {
                    Frame               = new RectangleF (190, Frame.Height - 280, 408, 185),
                    DocumentView        = TableView,
                    HasVerticalScroller = true,
                    BorderType          = NSBorderType.BezelBorder
                };

                IconColumn = new NSTableColumn (new NSImage ()) {
                    Width = 36,
                    HeaderToolTip = "Icon",
                    DataCell = new NSImageCell () {
                        ImageAlignment = NSImageAlignment.Right
                    }
                };

                DescriptionColumn = new NSTableColumn () {
                    Width         = 350,
                    HeaderToolTip = "Description",
                    Editable      = false
                };

                DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                    NSFontTraitMask.Condensed, 0, 11);

                TableView.AddColumn (IconColumn);
                TableView.AddColumn (DescriptionColumn);

                DataSource = new SparkleDataSource (Controller.Plugins);

                TableView.DataSource = DataSource;
                TableView.ReloadData ();

                HistoryCheckButton = new NSButton () {
                    Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                    HistoryCheckButton.State = NSCellStateValue.On;

                HistoryCheckButton.SetButtonType (NSButtonType.Switch);

                AddButton = new NSButton () {
                    Title = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                Controller.ChangeAddressFieldEvent += delegate (string text,
                    string example_text, FieldState state) {

                    InvokeOnMainThread (delegate {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate (string text,
                    string example_text, FieldState state) {

                    InvokeOnMainThread (delegate {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };

                TableView.SelectRow (Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible (Controller.SelectedPluginIndex);

                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                 (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                    Controller.SelectedPluginChanged (TableView.SelectedRow);
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled ();
                };

                Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (delegate {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (ScrollView);
                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (AddressHelpLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (PathTextField);
                ContentView.AddSubview (PathHelpLabel);
                ContentView.AddSubview (HistoryCheckButton);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);

                Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing) {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while on big projects. Isn't it coffee-o'clock?";

                ProgressIndicator = new NSProgressIndicator () {
                    Frame         = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation (this);

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                FinishButton = new NSButton () {
                    Title = "Finish",
                    Enabled = false
                };

                Controller.UpdateProgressBarEvent += delegate (double percentage) {
                    InvokeOnMainThread (() => {
                        ProgressIndicator.DoubleValue = percentage;
                    });
                };

                CancelButton.Activated += delegate {
                    Controller.SyncingCancelled ();
                };

                ContentView.AddSubview (ProgressIndicator);

                Buttons.Add (FinishButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Error) {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView ();
                web_view.Frame   = new RectangleF (190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                    "* {" +
                    "  font-family: 'Lucida Grande';" +
                    "  font-size: 12px; cursor: default;" +
                    "}" +
                    "body {" +
                    "  -webkit-user-select: none;" +
                    "  margin: 0;" +
                    "  padding: 3px;" +
                    "}" +
                    "li {" +
                    "  margin-bottom: 16px;" +
                    "  margin-left: 0;" +
                    "  padding-left: 0;" +
                    "  line-height: 20px;" +
                    "}" +
                    "ul {" +
                    "  padding-left: 24px;" +
                    "}" +
                    "</style>" +
                    "<ul>" +
                    "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                    "  <li>Do you have access rights to this remote project?</li>" +
                    "</ul>";

                if (warnings.Length > 0) {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                        warnings_markup += "<br><b>" + warning + "</b>";

                    html = html.Replace ("</ul>", "<li>Here's the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                TryAgainButton = new NSButton () {
                    Title = "Try again…"
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled ();
                };

                TryAgainButton.Activated += delegate {
                    Controller.ErrorPageCompleted ();
                };

                ContentView.AddSubview (web_view);

                Buttons.Add (TryAgainButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.CryptoSetup) {
                Header      = "Set up file encryption";
                Description = "This project is supposed to be encrypted, but it doesn't yet have a password set. Please provide one below:";

                PasswordLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (155, Frame.Height - 204, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                WarningImage = NSImage.ImageNamed ("NSInfo");
                WarningImage.Size = new SizeF (24, 24);

                WarningImageView = new NSImageView () {
                    Image = WarningImage,
                    Frame = new RectangleF (200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new NSTextField () {
                    Frame           = new RectangleF (235, Frame.Height - 390, 325, 100),
                    StringValue     = "This password can't be changed later, and your files can't be recovered if it's forgotten.",
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Font            = SparkleUI.Font
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ContinueButton.Activated += delegate {
                   Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.CryptoPageCancelled ();
                };

                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);
                ContentView.AddSubview (WarningImageView);
                ContentView.AddSubview (WarningTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.CryptoPassword) {
                Header      = "This project contains encrypted files";
                Description = "Please enter the password to see their contents.";

                PasswordLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (155, Frame.Height - 224, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };

                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                   Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.CryptoPageCancelled ();
                };

                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Finished) {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0) {
                    WarningImage = NSImage.ImageNamed ("NSInfo");
                    WarningImage.Size = new SizeF (24, 24);

                    WarningImageView = new NSImageView () {
                        Image = WarningImage,
                        Frame = new RectangleF (200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new NSTextField () {
                        Frame           = new RectangleF (235, Frame.Height - 245, 325, 100),
                        StringValue     = warnings [0],
                        BackgroundColor = NSColor.WindowBackground,
                        Bordered        = false,
                        Editable        = false,
                        Font            = SparkleUI.Font
                    };

                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                OpenFolderButton = new NSButton () {
                    Title = string.Format ("Open {0}", Path.GetFileName (Controller.PreviousPath))
                };

                FinishButton = new NSButton () {
                    Title = "Finish"
                };

                OpenFolderButton.Activated += delegate {
                    Controller.OpenFolderClicked ();
                };

                FinishButton.Activated += delegate {
                    Controller.FinishPageCompleted ();
                };

                Buttons.Add (FinishButton);
                Buttons.Add (OpenFolderButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial) {
                string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                    "Pixmaps", "tutorial-slide-" + Controller.TutorialPageNumber + ".png");

                SlideImage = new NSImage (slide_image_path) {
                    Size = new SizeF (350, 200)
                };

                SlideImageView = new NSImageView () {
                    Image = SlideImage,
                    Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                };

                ContentView.AddSubview (SlideImageView);

                switch (Controller.TutorialPageNumber) {

                    case 1: {
                        Header      = "What's happening next?";
                        Description = "SparkleShare creates a special folder on your computer " +
                            "that will keep track of your projects.";

                        SkipTutorialButton = new NSButton () {
                            Title = "Skip Tutorial"
                        };

                        ContinueButton = new NSButton () {
                            Title = "Continue"
                        };

                        SkipTutorialButton.Activated += delegate {
                            Controller.TutorialSkipped ();
                        };

                        ContinueButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        ContentView.AddSubview (SlideImageView);

                        Buttons.Add (ContinueButton);
                        Buttons.Add (SkipTutorialButton);

                        break;
                    }

                    case 2: {
                        Header      = "Sharing files with others";
                        Description = "All files added to your project folders are synced automatically with " +
                            "the host and your team members.";

                        ContinueButton = new NSButton () {
                            Title = "Continue"
                        };

                        ContinueButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 3: {
                        Header      = "The status icon is here to help";
                        Description = "It shows the syncing progress, provides easy access to " +
                            "your projects and let's you view recent changes.";

                        ContinueButton = new NSButton () {
                            Title = "Continue"
                        };

                        ContinueButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 4: {
                        Header      = "Adding projects to SparkleShare";
                        Description = "You can do this through the status icon menu, or by clicking " +
                            "magic buttons on webpages that look like this:";

                        StartupCheckButton = new NSButton () {
                            Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                            Title = "Add SparkleShare to startup items",
                            State = NSCellStateValue.On
                        };

                        StartupCheckButton.SetButtonType (NSButtonType.Switch);

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        SlideImage.Size = new SizeF (350, 64);

                        StartupCheckButton.Activated += delegate {
                            Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On);
                        };

                        FinishButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        ContentView.AddSubview (StartupCheckButton);
                        Buttons.Add (FinishButton);

                        break;
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public SparkleEventLog()
            : base()
        {
            using (var a = new NSAutoreleasePool ())
            {
                Title    = "Recent Changes";
                Delegate = new SparkleEventsDelegate ();

                int min_width  = 480;
                int min_height = 640;
                float x    = (float) (NSScreen.MainScreen.Frame.Width * 0.61);
                float y    = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5));

                SetFrame (
                    new RectangleF (
                        new PointF (x, y),
                        new SizeF (min_width, (int) (NSScreen.MainScreen.Frame.Height * 0.85))),
                    true);

                StyleMask = (NSWindowStyle.Closable |
                             NSWindowStyle.Miniaturizable |
                             NSWindowStyle.Titled |
                             NSWindowStyle.Resizable);

                MinSize        = new SizeF (min_width, min_height);
                HasShadow      = true;
                BackingType    = NSBackingStore.Buffered;
                TitlebarHeight = Frame.Height - ContentView.Frame.Height;

                this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") {
                    PolicyDelegate = new SparkleWebPolicyDelegate (),
                    Frame = new RectangleF (new PointF (0, 0),
                        new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39))
                };

                this.hidden_close_button = new NSButton () {
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed ();
                };

                this.size_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (0, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "Size:",
                    Font            = SparkleUI.BoldFont
                };

                this.size_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (60, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };

                this.history_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (130, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "History:",
                    Font            = SparkleUI.BoldFont
                };

                this.history_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (190, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)
                    ),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };

                this.popup_button = new NSPopUpButton () {
                    Frame = new RectangleF (
                        new PointF (ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33),
                        new SizeF (156, 26)),
                    PullsDown = false
                };

                this.background = new NSBox () {
                    Frame = new RectangleF (
                        new PointF (-1, -1),
                        new SizeF (Frame.Width + 2, this.web_view.Frame.Height + 2)),
                    FillColor = NSColor.White,
                    BorderColor = NSColor.LightGray,
                    BoxType = NSBoxType.NSBoxCustom
                };

                this.progress_indicator = new NSProgressIndicator () {
                    Frame = new RectangleF (
                        new PointF (Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
                        new SizeF (20, 20)),
                    Style = NSProgressIndicatorStyle.Spinning
                };

                this.progress_indicator.StartAnimation (this);

                ContentView.AddSubview (this.size_label);
                ContentView.AddSubview (this.size_label_value);
                ContentView.AddSubview (this.history_label);
                ContentView.AddSubview (this.history_label_value);
                ContentView.AddSubview (this.popup_button);
                ContentView.AddSubview (this.progress_indicator);
                ContentView.AddSubview (this.background);
                ContentView.AddSubview (this.hidden_close_button);

                (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate (string href) {
                    Controller.LinkClicked (href);
                };

                (Delegate as SparkleEventsDelegate).WindowResized += Relayout;
            }

            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        PerformClose (this);

                        if (this.web_view.Superview == ContentView)
                            this.web_view.RemoveFromSuperview ();
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        OrderFrontRegardless ();
                    });
                }
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateChooser (folders);
                    });
                }
            };

            Controller.UpdateContentEvent += delegate (string html) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateContent (html);
                    });
                }
            };

            Controller.ContentLoadingEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        if (this.web_view.Superview == ContentView)
                            this.web_view.RemoveFromSuperview ();

                        ContentView.AddSubview (this.progress_indicator);
                    });
                }
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.size_label_value.StringValue    = size;
                        this.history_label_value.StringValue = history_size;
                    });
                }
            };
        }
Ejemplo n.º 30
0
        public void ShowPage (PageType type, string [] warnings)
        {
            if (type == PageType.Setup) {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                FullNameLabel       = new SparkleLabel ("Full Name:", NSTextAlignment.Right);
                FullNameLabel.Frame = new RectangleF (165, Frame.Height - 234, 160, 17);

                FullNameTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser ().RealName,
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                EmailLabel       = new SparkleLabel ("Email:", NSTextAlignment.Right);
                EmailLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17);
                    
                EmailTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                CancelButton = new NSButton () { Title = "Cancel" };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim ();
                    string email     = EmailTextField.StringValue.Trim ();

                    Controller.SetupPageCompleted (full_name, email);
                };

                CancelButton.Activated += delegate { Controller.SetupPageCancelled (); };

                Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview (FullNameLabel);
                ContentView.AddSubview (FullNameTextField);
                ContentView.AddSubview (EmailLabel);
                ContentView.AddSubview (EmailTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
            }

            if (type == PageType.Invite) {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel       = new SparkleLabel ("Address:", NSTextAlignment.Right);
                AddressLabel.Frame = new RectangleF (165, Frame.Height - 240, 160, 17);
     
                AddressTextField = new SparkleLabel (Controller.PendingInvite.Address, NSTextAlignment.Left) {
                    Frame = new RectangleF (330, Frame.Height - 240, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathLabel       = new SparkleLabel ("Remote Path:", NSTextAlignment.Right);
                PathLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17);

                PathTextField = new SparkleLabel (Controller.PendingInvite.RemotePath, NSTextAlignment.Left) {
                    Frame = new RectangleF (330, Frame.Height - 264, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                CancelButton = new NSButton () { Title = "Cancel" };
                AddButton = new NSButton () { Title = "Add" };


                CancelButton.Activated += delegate { Controller.PageCancelled (); };
                AddButton.Activated += delegate { Controller.InvitePageCompleted (); };


                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (PathTextField);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Add) {
                Header      = "Where’s your project hosted?";
                Description = "";

                AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Left) {
                    Frame = new RectangleF (190, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

                AddressTextField = new NSTextField () {
                    Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                    Font        = SparkleUI.Font,
                    Enabled     = (Controller.SelectedPlugin.Address == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Left) {
                    Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField () {
                    Frame       = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPlugin.Path == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new SparkleLabel (Controller.SelectedPlugin.PathExample, NSTextAlignment.Left) {
                    TextColor       = NSColor.DisabledControlText,
                    Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                };

                AddressHelpLabel = new SparkleLabel (Controller.SelectedPlugin.AddressExample, NSTextAlignment.Left) {
                    TextColor       = NSColor.DisabledControlText,
                    Frame           = new RectangleF (190, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                };

                if (TableView == null || TableView.RowCount != Controller.Plugins.Count) {
                    TableView = new NSTableView () {
                        Frame            = new RectangleF (0, 0, 0, 0),
                        RowHeight        = 34,
                        IntercellSpacing = new SizeF (8, 12),
                        HeaderView       = null,
                        Delegate         = new SparkleTableViewDelegate ()
                    };

                    ScrollView = new NSScrollView () {
                        Frame               = new RectangleF (190, Frame.Height - 280, 408, 185),
                        DocumentView        = TableView,
                        HasVerticalScroller = true,
                        BorderType          = NSBorderType.BezelBorder
                    };

                    IconColumn = new NSTableColumn () {
                        Width         = 36,
                        HeaderToolTip = "Icon",
                        DataCell      = new NSImageCell () { ImageAlignment = NSImageAlignment.Right }
                    };

                    DescriptionColumn = new NSTableColumn () {
                        Width         = 350,
                        HeaderToolTip = "Description",
                        Editable      = false
                    };

                    DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11);

                    TableView.AddColumn (IconColumn);
                    TableView.AddColumn (DescriptionColumn);

                    // Hi-res display support was added after Snow Leopard
                    if (Environment.OSVersion.Version.Major < 11)
                        DataSource = new SparkleDataSource (1, Controller.Plugins);
                    else
                        DataSource = new SparkleDataSource (BackingScaleFactor, Controller.Plugins);

                    TableView.DataSource = DataSource;
                    TableView.ReloadData ();
                    
                    (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                        Controller.SelectedPluginChanged (TableView.SelectedRow);
                        Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                    };
                }
                
                TableView.SelectRow (Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible (Controller.SelectedPluginIndex);

                HistoryCheckButton = new NSButton () {
                    Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                    HistoryCheckButton.State = NSCellStateValue.On;

                HistoryCheckButton.SetButtonType (NSButtonType.Switch);

                AddButton = new NSButton () {
                    Title = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton () { Title = "Cancel" };


                Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) {
                    Program.Controller.Invoke (() => {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) {
                    Program.Controller.Invoke (() => {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };


                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                 (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };


                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.PageCancelled (); };

                Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (ScrollView);
                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (AddressHelpLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (PathTextField);
                ContentView.AddSubview (PathHelpLabel);
                ContentView.AddSubview (HistoryCheckButton);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);

                Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing) {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressIndicator = new NSProgressIndicator () {
                    Frame         = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation (this);

                CancelButton = new NSButton () { Title = "Cancel" };

                FinishButton = new NSButton () {
                    Title = "Finish",
                    Enabled = false
                };


                Controller.UpdateProgressBarEvent += delegate (double percentage) {
                    Program.Controller.Invoke (() => {
                        ProgressIndicator.DoubleValue = percentage;
                    });
                };

                CancelButton.Activated += delegate { Controller.SyncingCancelled (); };


                ContentView.AddSubview (ProgressIndicator);

                Buttons.Add (FinishButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Error) {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView ();
                web_view.Frame   = new RectangleF (190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                    "* {" +
                    "  font-family: 'Lucida Grande';" +
                    "  font-size: 12px; cursor: default;" +
                    "}" +
                    "body {" +
                    "  -webkit-user-select: none;" +
                    "  margin: 0;" +
                    "  padding: 3px;" +
                    "}" +
                    "li {" +
                    "  margin-bottom: 16px;" +
                    "  margin-left: 0;" +
                    "  padding-left: 0;" +
                    "  line-height: 20px;" +
                    "  word-wrap: break-word;" +
                    "}" +
                    "ul {" +
                    "  padding-left: 24px;" +
                    "}" +
                    "</style>" +
                    "<ul>" +
                    "  <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" +
                    "  <li>Is this computer’s Client ID known by the host?</li>" +
                    "</ul>";

                if (warnings.Length > 0) {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                        warnings_markup += "<br><b>" + warning + "</b>";

                    html = html.Replace ("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton () { Title = "Cancel" };
                TryAgainButton = new NSButton () { Title = "Try Again…" };


                CancelButton.Activated += delegate { Controller.PageCancelled (); };
                TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted (); };


                ContentView.AddSubview (web_view);

                Buttons.Add (TryAgainButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) {
                if (type == PageType.CryptoSetup) {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                
                } else {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                int extra_pos_y = 0;

                if (type == PageType.CryptoPassword)
                    extra_pos_y = 20;
  
                PasswordLabel = new SparkleLabel ("Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                WarningImage = NSImage.ImageNamed ("NSInfo");
                WarningImage.Size = new SizeF (24, 24);

                WarningImageView = new NSImageView () {
                    Image = WarningImage,
                    Frame = new RectangleF (200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new SparkleLabel ("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) {
                    Frame = new RectangleF (235, Frame.Height - 390, 325, 100),
                };

                CancelButton = new NSButton () { Title = "Cancel" };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
                };
                
                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                        Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                    else
                        Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    
                    if (type == PageType.CryptoSetup)
                        Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                    else
                        Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    if (type == PageType.CryptoSetup)
                        Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue);
                    else
                        Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); };


                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);

                if (type == PageType.CryptoSetup) {
                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished) {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0) {
                    WarningImage = NSImage.ImageNamed ("NSInfo");
                    WarningImage.Size = new SizeF (24, 24);

                    WarningImageView = new NSImageView () {
                        Image = WarningImage,
                        Frame = new RectangleF (200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new SparkleLabel (warnings [0], NSTextAlignment.Left);
                    WarningTextField.Frame       = new RectangleF (235, Frame.Height - 245, 325, 100);

                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                ShowFilesButton = new NSButton () { Title = "Show Files…" };
                FinishButton    = new NSButton () { Title = "Finish" };


                ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked (); };
                FinishButton.Activated += delegate { Controller.FinishPageCompleted (); };


                Buttons.Add (FinishButton);
                Buttons.Add (ShowFilesButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial) {
                SlideImage = NSImage.ImageNamed ("tutorial-slide-" + Controller.TutorialPageNumber);
                if (SlideImage != null) {
                    SlideImage.Size = new SizeF (324, 200);

                    SlideImageView = new NSImageView () {
                        Image = SlideImage,
                        Frame = new RectangleF (228, Frame.Height - 350, 324, 200)
                    };

                    ContentView.AddSubview (SlideImageView);
                }

                switch (Controller.TutorialPageNumber) {
                    case 1: {
                        Header      = "What’s happening next?";
                        Description = "SparkleShare creates a special folder on your computer " +
                            "that will keep track of your projects.";

                        SkipTutorialButton = new NSButton () { Title = "Skip Tutorial" };
                        ContinueButton     = new NSButton () { Title = "Continue" };


                        SkipTutorialButton.Activated += delegate { Controller.TutorialSkipped (); };
                        ContinueButton.Activated     += delegate { Controller.TutorialPageCompleted (); };


                        ContentView.AddSubview (SlideImageView);

                        Buttons.Add (ContinueButton);
                        Buttons.Add (SkipTutorialButton);

                        break;
                    }

                    case 2: {
                        Header      = "Sharing files with others";
                        Description = "All files added to your project folders are synced automatically with " +
                            "the host and your team members.";

                        ContinueButton = new NSButton () { Title = "Continue" };
                        ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); };
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 3: {
                        Header      = "The status icon helps you";
                        Description = "It shows the syncing progress, provides easy access to " +
                            "your projects, and lets you view recent changes.";

                        ContinueButton = new NSButton () { Title = "Continue" };
                        ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); };
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 4: {
                        Header      = "Here’s your unique Client ID";
                        Description = "You’ll need it whenever you want to link this computer to a host. " +
                            "You can also find it in the status icon menu.";

                        LinkCodeTextField = new NSTextField () {
                            StringValue = Program.Controller.CurrentUser.PublicKey,
                            Enabled     = false,
                            Selectable  = false,
                            Frame       = new RectangleF (230, Frame.Height - 238, 246, 22)
                        };

                        LinkCodeTextField.Cell.UsesSingleLineMode = true;
                        LinkCodeTextField.Cell.LineBreakMode      = NSLineBreakMode.TruncatingTail;
                        
                        CopyButton = new NSButton () {
                            Title      = "Copy",
                            BezelStyle = NSBezelStyle.RoundRect,
                            Frame      = new RectangleF (480, Frame.Height - 238, 60, 22)
                        };
                        
                        StartupCheckButton = new NSButton () {
                            Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                            Title = "Add SparkleShare to startup items",
                            State = NSCellStateValue.On
                        };

                        StartupCheckButton.SetButtonType (NSButtonType.Switch);

                        FinishButton = new NSButton () { Title = "Finish" };


                        StartupCheckButton.Activated += delegate {
                            Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On);
                        };

                        CopyButton.Activated += delegate { Controller.CopyToClipboardClicked (); };
                        FinishButton.Activated += delegate { Controller.TutorialPageCompleted (); };


                        ContentView.AddSubview (LinkCodeTextField);
                        ContentView.AddSubview (CopyButton);
                        ContentView.AddSubview (StartupCheckButton);

                        Buttons.Add (FinishButton);

                        break;
                    }
                }
            }
        }
Ejemplo n.º 31
0
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup:

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64));

                        UserInfoForm.AddEntry ("Full Name:");
                        UserInfoForm.AddEntry ("Email Address:");

                        UserInfoForm.CellSize                = new SizeF (280, 22);
                        UserInfoForm.IntercellSpacing        = new SizeF (4, 4);
                        UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                        UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                        UserInfoForm.Cells [0].StringValue   = SparkleShare.Controller.UserName;
                        UserInfoForm.Cells [1].StringValue   = SparkleShare.Controller.UserEmail;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            timer.Stop ();
                            timer = null;

                            string full_name = UserInfoForm.Cells [0].StringValue.Trim ();
                            string email = UserInfoForm.Cells [1].StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                                bool email_is_valid = SparkleShare.Controller.IsValidEmail (
                                    UserInfoForm.Cells [1].StringValue.Trim ());

                                ContinueButton.Enabled = (name_is_valid && email_is_valid);
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (UserInfoForm);
                        Buttons.Add (ContinueButton);

                        break;

                    case PageType.Add:

                        Header       = "Where is your remote folder?";
                        Description  = "";

                        ServerTypeLabel  = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 139 , 160, 17),
                            StringValue     = "Server Type:",
                            Font            = SparkleUI.Font
                        };

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 237 , 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        FolderNameLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 264 , 160, 17),
                            StringValue     = "Folder Name:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (320, Frame.Height - 240 , 256, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousServer
                        };

                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameTextField = new NSTextField () {
                            Frame           = new RectangleF (320, Frame.Height - (240 + 22 + 4) , 256, 22),
                            StringValue     = Controller.PreviousFolder
                        };

                        FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (320, Frame.Height - 285 , 200, 17),
                            StringValue     = "e.g. ‘rupert/website-design’"
                        };

                        ServerType = 0;

                        ButtonCellProto = new NSButtonCell ();
                        ButtonCellProto.SetButtonType (NSButtonType.Radio) ;

                        Matrix = new NSMatrix (new RectangleF (315, 180, 256, 78),
                            NSMatrixMode.Radio, ButtonCellProto, 4, 1);

                        Matrix.CellSize = new SizeF (256, 18);

                        Matrix.Cells [0].Title = "My own server";
                        Matrix.Cells [1].Title = "Github";
                        Matrix.Cells [2].Title = "Gitorious";
                        Matrix.Cells [3].Title = "The GNOME Project";

                        foreach (NSCell cell in Matrix.Cells)
                            cell.Font = SparkleUI.Font;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                if (Matrix.SelectedRow != ServerType) {
                                    ServerType = Matrix.SelectedRow;

                                    AddressTextField.Enabled = (ServerType == 0);

                                    switch (ServerType) {
                                    case 0:
                                        AddressTextField.StringValue = "";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 1:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 2:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’";
                                        break;
                                    case 3:
                                        AddressTextField.StringValue = "ssh://[email protected]/git/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’";
                                        break;
                                    }
                                }

                                if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("")
                                    && !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else if (ServerType != 0 &&
                                           !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else {
                                    SyncButton.Enabled = false;
                                }
                            });

                        };

                        timer.Start ();

                        ContentView.AddSubview (ServerTypeLabel);
                        ContentView.AddSubview (Matrix);

                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);

                        ContentView.AddSubview (FolderNameLabel);
                        ContentView.AddSubview (FolderNameTextField);
                        ContentView.AddSubview (FolderNameHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Sync",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                timer.Stop ();
                                timer = null;

                                string folder_name    = FolderNameTextField.StringValue;
                                string server         = AddressTextField.StringValue;
                                Controller.AddPageCompleted (server, folder_name);
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            Buttons.Add (CancelButton);

                        break;

                    case PageType.Syncing:

                        Header      = "Syncing folder ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style = NSProgressIndicatorStyle.Bar
                        };

                        ProgressIndicator.StartAnimation (this);
                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        Buttons.Add (FinishButton);

                        break;

                    case PageType.Error:

                        Header      = "Something went wrong…";
                        Description = "";

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;

                    case PageType.Finished:

                        Header      = "Folder synced succesfully!";
                        Description = "Now you can access the synced files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            SparkleShare.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        break;
                    }

                    ShowAll ();
                });
            };
        }
Ejemplo n.º 32
0
		public bool Run (OpenFileDialogData data)
		{
			NSSavePanel panel = null;
			
			try {
				bool directoryMode = data.Action != Gtk.FileChooserAction.Open
						&& data.Action != Gtk.FileChooserAction.Save;
				
				if (data.Action == Gtk.FileChooserAction.Save) {
					panel = new NSSavePanel ();
				} else {
					panel = new NSOpenPanel () {
						CanChooseDirectories = directoryMode,
						CanChooseFiles = !directoryMode,
					};
				}
				
				MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel);
				
				SelectEncodingPopUpButton encodingSelector = null;
				NSPopUpButton viewerSelector = null;
				NSButton closeSolutionButton = null;
				
				var box = new MDBox (LayoutDirection.Vertical, 2, 2);
				
				List<FileViewer> currentViewers = null;
				List<MDAlignment> labels = new List<MDAlignment> ();
				
				if (!directoryMode) {
					var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel);

					if (filterPopup != null) {
						var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true);
						var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ filterLabel },
							{ new MDAlignment (filterPopup, true) { MinWidth = 200 } }
						};
						labels.Add (filterLabel);
						box.Add (filterBox);
					}

					if (data.ShowEncodingSelector) {
						encodingSelector = new SelectEncodingPopUpButton (data.Action != Gtk.FileChooserAction.Save);
						encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0;
						
						var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true);
						var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ encodingLabel },
							{ new MDAlignment (encodingSelector, true) { MinWidth = 200 }  }
						};
						labels.Add (encodingLabel);
						box.Add (encodingBox);
					}
					
					if (data.ShowViewerSelector && panel is NSOpenPanel) {
						currentViewers = new List<FileViewer> ();
						viewerSelector = new NSPopUpButton () {
							Enabled = false,
						};
						
						if (encodingSelector != null) {
							viewerSelector.Activated += delegate {
								var idx = viewerSelector.IndexOfSelectedItem;
								encodingSelector.Enabled = ! (idx == 0 && currentViewers [0] == null);
							};
						}
						
						var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:"));
						var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ viewSelLabel, true },
							{ new MDAlignment (viewerSelector, true) { MinWidth = 200 }  }
						};
						
						if (IdeApp.Workspace.IsOpen) {
							closeSolutionButton = new NSButton () {
								Title = GettextCatalog.GetString ("Close current workspace"),
								Hidden = true,
								State = NSCellStateValue.On,
							};
							
							closeSolutionButton.SetButtonType (NSButtonType.Switch);
							closeSolutionButton.SizeToFit ();
							
							viewSelBox.Add (closeSolutionButton, true);
						}
						
						box.Add (viewSelBox);
					}
				}
				
				if (labels.Count > 0) {
					float w = labels.Max (l => l.MinWidth);
					foreach (var l in labels) {
						l.MinWidth = w;
						l.XAlign = LayoutAlign.Begin;
					}
				}
				
				if (box.Count > 0) {
					box.Layout ();
					panel.AccessoryView = box.View;
				}
				
				panel.SelectionDidChange += delegate(object sender, EventArgs e) {
					var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel);
					bool slnViewerSelected = false;
					if (viewerSelector != null) {
						FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection);
						if (currentViewers.Count == 0 || currentViewers [0] != null) {
							if (closeSolutionButton != null)
								closeSolutionButton.Hidden = true;
							slnViewerSelected = false;
						} else {
							if (closeSolutionButton != null)
								closeSolutionButton.Hidden = false;
							slnViewerSelected = true;
						}
						box.Layout ();
						
						//re-center the accessory view in its parent, Cocoa does this for us initially and after
						//resizing the window, but we need to do it again after altering its layout
						var superFrame = box.View.Superview.Frame;
						var frame = box.View.Frame;
						//not sure why it's ceiling, but this matches the Cocoa layout
						frame.X = (float)Math.Ceiling ((superFrame.Width - frame.Width) / 2);
						frame.Y = (float)Math.Ceiling ((superFrame.Height - frame.Height) / 2);
						box.View.Frame = frame;
					} 
					if (encodingSelector != null)
						encodingSelector.Enabled = !slnViewerSelected;
				};

				var action = MacSelectFileDialogHandler.RunPanel (data, panel);
				if (!action) {
					GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
					return false;
				}

				data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel);
				
				if (encodingSelector != null)
					data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null;
				
				if (viewerSelector != null ) {
					if (closeSolutionButton != null)
						data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off;
					data.SelectedViewer = currentViewers[viewerSelector.IndexOfSelectedItem];
				}
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			} catch (Exception ex) {
				LoggingService.LogError ("Error in Open File dialog", ex);
				MessageService.ShowException (ex);
			} finally {
				if (panel != null)
					panel.Dispose ();
			}
			return true;
		}
		// Action for Add pushbutton
		partial void addABox (NSButton sender)
		{
			simpleView.AddSubview (viewToBeAdded ());
			layout ();
		}
Ejemplo n.º 34
0
        /// <summary>
        /// Create the UI
        /// </summary>
        private void CreateEdit()
        {
            RootFolder repo = new RootFolder()
            {
                Name = FolderName,
                Id = credentials.RepoId,
                Address = credentials.Address.ToString()
            };
            repo.Selected = true;
            IgnoredFolderLoader.AddIgnoredFolderToRootNode(repo, Ignores);
            LocalFolderLoader.AddLocalFolderToRootNode(repo, localPath);
            List<RootFolder> repos = new List<RootFolder>();
            repos.Add(repo);

            OutlineViewDelegate DataDelegate = new OutlineViewDelegate ();
            CmisTree.CmisTreeDataSource DataSource = new CmisTree.CmisTreeDataSource(repos);

            CmisOutlineController OutlineController = new CmisOutlineController (DataSource, DataDelegate);

            AsyncNodeLoader asyncLoader = new AsyncNodeLoader(repo, credentials, PredefinedNodeLoader.LoadSubFolderDelegate, PredefinedNodeLoader.CheckSubFolderDelegate);
            asyncLoader.UpdateNodeEvent += delegate {
                InvokeOnMainThread(delegate {
                    DataSource.UpdateCmisTree(repo);
                    NSOutlineView view = OutlineController.OutlineView();
                    for (int i = 0; i < view.RowCount; ++i) {
                        view.ReloadItem(view.ItemAtRow(i));
                    }
                });
            };
            asyncLoader.Load(repo);

            DataDelegate.ItemExpanded += delegate(NSNotification notification)
            {
                InvokeOnMainThread(delegate {
                    NSCmisTree cmis = notification.UserInfo["NSObject"] as NSCmisTree;
                    if (cmis == null) {
                        Console.WriteLine("ItemExpanded Error");
                        return;
                    }

                    NSCmisTree cmisRoot = cmis;
                    while (cmisRoot.Parent != null) {
                        cmisRoot = cmisRoot.Parent;
                    }
                    if (repo.Name != cmisRoot.Name) {
                        Console.WriteLine("ItemExpanded find root Error");
                        return;
                    }

                    Node node = cmis.GetNode(repo);
                    if (node == null) {
                        Console.WriteLine("ItemExpanded find node Error");
                        return;
                    }
                    asyncLoader.Load(node);
                });
            };
            DataSource.SelectedEvent += delegate (NSCmisTree cmis, int selected) {
                InvokeOnMainThread(delegate {
                    Node node = cmis.GetNode(repo);
                    if (node == null) {
                        Console.WriteLine("SelectedEvent find node Error");
                    }
                    node.Selected = (selected != 0);
                    DataSource.UpdateCmisTree(repo);

                    NSOutlineView view = OutlineController.OutlineView();
                    for (int i = 0; i < view.RowCount; ++i) {
                        try{
                            view.ReloadItem(view.ItemAtRow(i));
                        }catch(Exception e) {
                            Console.WriteLine(e);
                        }
                    }
                });
            };

            OutlineController.View.Frame = new RectangleF (190, 60, 400, 240);
            ContentView.AddSubview (OutlineController.View);

            Controller.CloseWindowEvent += delegate
            {
                asyncLoader.Cancel();
            };

            Controller.OpenWindowEvent += delegate
            {
                InvokeOnMainThread (delegate {
                    OrderFrontRegardless ();
                });
            };


            NSButton finish_button = new NSButton()
            {
                Title = Properties_Resources.SaveChanges,
            };

            NSButton cancel_button = new NSButton()
            {
                Title = Properties_Resources.DiscardChanges
            };

            Buttons.Add(finish_button);
            Buttons.Add(cancel_button);

            finish_button.Activated += delegate
            {
                Ignores = NodeModelUtils.GetIgnoredFolder(repo);
                Controller.SaveFolder();
                InvokeOnMainThread (delegate {
                    PerformClose (this);
                });
            };

            cancel_button.Activated += delegate
            {
                InvokeOnMainThread (delegate {
                    PerformClose (this);
                });
            };

            this.Header = Properties_Resources.EditTitle;
            this.Description = "";
            this.ShowAll();
        }
Ejemplo n.º 35
0
 partial void NewNoteButton_Clicked(MonoMac.AppKit.NSButton sender)
 {
     NewNote();
 }
Ejemplo n.º 36
0
        public void ShowAccountForm()
        {
            Reset ();

                Header       = "Welcome to SparkleShare!";
                Description  = "Before we can create a SparkleShare folder on this " +
                               "computer, we need some information from you.";

                UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64));
                UserInfoForm.AddEntry ("Full Name:");
                UserInfoForm.AddEntry ("Email Address:");
                UserInfoForm.CellSize = new SizeF (280, 22);
                UserInfoForm.IntercellSpacing = new SizeF (4, 4);
                UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                UserInfoForm.Cells [0].StringValue = SparkleShare.Controller.UserName;
                UserInfoForm.Cells [1].StringValue = SparkleShare.Controller.UserEmail;

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled = false
                };

                ContinueButton.Activated += delegate {
                    SparkleShare.Controller.UserName  = UserInfoForm.Cells [0].StringValue.Trim ();
                    SparkleShare.Controller.UserEmail = UserInfoForm.Cells [1].StringValue.Trim ();
                    SparkleShare.Controller.GenerateKeyPair ();
                    SparkleUI.StatusIcon.CreateMenu ();

                    InvokeOnMainThread (delegate {
                        ShowServerForm ();
                    });
                };

                // TODO: Ugly hack, do properly with events
                Timer timer = new Timer () {
                    Interval = 50
                };

                timer.Elapsed += delegate {
                    InvokeOnMainThread (delegate {
                        bool name_is_correct =
                            !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                        bool email_is_correct = SparkleShare.Controller.IsValidEmail (
                            UserInfoForm.Cells [1].StringValue.Trim ());

                        ContinueButton.Enabled = (name_is_correct && email_is_correct);
                    });
                };

                timer.Start ();

                ContentView.AddSubview (UserInfoForm);
                Buttons.Add (ContinueButton);

            ShowAll ();
        }
Ejemplo n.º 37
0
 partial void CancelClicked(MonoMac.AppKit.NSButton sender)
 {
     CancellationSource.Cancel();
 }
 // This will only reset colors to red
 partial void ResetAction(MonoMac.AppKit.NSButton sender)
 {
     DeliveredColorWell.Color = NSColor.Red;
     TouchedColorWell.Color   = NSColor.Red;
 }
 partial void disconnectButtonClicked(MonoMac.AppKit.NSButton sender)
 {
     CurrentInterface.Disassociate();
     UpdateInfoTab();
 }
Ejemplo n.º 40
0
 partial void BtnCancel(MonoMac.AppKit.NSButton sender)
 {
     Close();
     NSApplication.SharedApplication.StopModalWithCode(0);
 }
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();
			
			#region first two buttons 
			
			// add the image menu item back to the first menu item
			NSMenuItem menuItem = new NSMenuItem ("", new Selector (""), "");
			
			menuItem.Image = NSImage.ImageNamed ("moof.png");
			buttonMenu.InsertItematIndex (menuItem, 0);
			
			nibBasedPopUpDown.Menu = buttonMenu;
			nibBasedPopUpRight.Menu = buttonMenu;
		
			// create the pull down button pointing DOWN
			RectangleF buttonFrame = placeHolder1.Frame;
			codeBasedPopUpDown = new NSPopUpButton (buttonFrame, true);
			
			((NSPopUpButtonCell)codeBasedPopUpDown.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
			((NSPopUpButtonCell)codeBasedPopUpDown.Cell).BezelStyle = NSBezelStyle.ThickSquare;
			codeBasedPopUpDown.Menu = buttonMenu;
			popupBox.AddSubview (codeBasedPopUpDown);
			placeHolder1.RemoveFromSuperview ();
		
			// create the pull down button pointing RIGHT
			buttonFrame = placeHolder2.Frame;
			codeBasedPopUpRight = new NSPopUpButton (buttonFrame, true);
			
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).PreferredEdge = NSRectEdge.MaxXEdge;
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).BezelStyle = NSBezelStyle.Circular;
			codeBasedPopUpRight.Menu = buttonMenu;
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).HighlightsBy = (int)NSCellMask.ChangeGrayCell;
			popupBox.AddSubview (codeBasedPopUpRight);
			placeHolder2.RemoveFromSuperview ();
			
			#endregion
			
			#region second two buttons
			
			// create the rounded button
			buttonFrame = placeHolder3.Frame;
			// note: this button we want alternate title and image, so we need to call this:
			codeBasedButtonRound = new NSButton (buttonFrame) {
				Title = "NSButton",
				AlternateTitle = "(pressed)",
				Image = NSImage.ImageNamed ("moof.png"),
				AlternateImage = NSImage.ImageNamed ("moof2.png"),
				BezelStyle = NSBezelStyle.RegularSquare,
				ImagePosition = NSCellImagePosition.ImageLeft,
				Font = NSFont.SystemFontOfSize (NSFont.SmallSystemFontSize),
				Sound = NSSound.FromName ("Pop"),
			};
			// Two choices, either use the .NET event system:
			//    foo.Activated += delegate {..} or += SomeMethod
			//
			// Or you can use the Target = this Action = new Selector ("buttonAction:")
			// pattern
			codeBasedButtonRound.Activated += delegate {
				buttonAction (null);
			};
			codeBasedButtonRound.SetButtonType (NSButtonType.MomentaryChange);
			codeBasedButtonRound.Cell.Alignment = NSTextAlignment.Left;
			buttonBox.AddSubview (codeBasedButtonRound);
			placeHolder3.RemoveFromSuperview (); 			// we are done with the place holder, remove it from the window
			
			// create the square button
			buttonFrame = placeHolder4.Frame;
			codeBasedButtonSquare = new NSButton (buttonFrame){
				Title = "NSButton",
				BezelStyle = NSBezelStyle.ShadowlessSquare,
				ImagePosition = NSCellImagePosition.ImageLeft,
				Image = NSImage.ImageNamed ("moof.png"),
				Font = NSFont.SystemFontOfSize (NSFont.SmallSystemFontSize),
				Sound = NSSound.FromName ("Pop"),
			};
			codeBasedButtonSquare.Activated += delegate { buttonAction (null); };
			codeBasedButtonSquare.Cell.Alignment = NSTextAlignment.Left;
			buttonBox.AddSubview (codeBasedButtonSquare);
			placeHolder4.RemoveFromSuperview (); 			// we are done with the place holder, remove it from the window
			
			#endregion
			
			#region segmented control
			
			buttonFrame = placeHolder5.Frame;
			codeBasedSegmentControl = new NSSegmentedControl(buttonFrame) {
				SegmentCount = 3,
				Target = this,
				Action = new Selector("segmentAction:")
			};
					
			codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth(0), 0);
			codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth (1), 1);
			codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth (2), 2);
			codeBasedSegmentControl.SetLabel ("One", 0);
			codeBasedSegmentControl.SetLabel ("Two", 1);
			codeBasedSegmentControl.SetLabel ("Three", 2);
			segmentBox.AddSubview (codeBasedSegmentControl);
			placeHolder5.RemoveFromSuperview ();
	
			// use a menu to the first segment (applied to both nib-based and code-based)
			codeBasedSegmentControl.SetMenu (buttonMenu, 0);
			nibBasedSegControl.SetMenu (buttonMenu, 0);
			
			// add icons to each segment (applied to both nib-based and code-based)
			NSImage segmentIcon1 = NSWorkspace.SharedWorkspace.IconForFileType(NSFileTypeForHFSTypeCode.ComputerIcon);
			segmentIcon1.Size = new SizeF(16, 16);
			nibBasedSegControl.SetImage (segmentIcon1, 0);
			codeBasedSegmentControl.SetImage (segmentIcon1, 0);
			
			NSImage segmentIcon2 = NSWorkspace.SharedWorkspace.IconForFileType (NSFileTypeForHFSTypeCode.DesktopIcon);
			segmentIcon2.Size = new SizeF (16, 16);
			nibBasedSegControl.SetImage (segmentIcon2, 1);
			codeBasedSegmentControl.SetImage (segmentIcon2, 1);
			
			NSImage segmentIcon3 = NSWorkspace.SharedWorkspace.IconForFileType (NSFileTypeForHFSTypeCode.FinderIcon);
			segmentIcon3.Size = new SizeF (16, 16);
			nibBasedSegControl.SetImage (segmentIcon3, 2);
			codeBasedSegmentControl.SetImage (segmentIcon3, 2);
		
			#endregion
			
			#region level indicator
			
			buttonFrame = placeHolder8.Frame;
			codeBasedIndicator = new NSLevelIndicator(buttonFrame) {
				MaxValue = 10,
				MajorTickMarkCount = 4,
				TickMarkCount = 7,
				WarningValue = 5,
				CriticalValue = 8,
				Action = new Selector("levelAction:")
			};
			codeBasedIndicator.Cell.LevelIndicatorStyle = NSLevelIndicatorStyle.DiscreteCapacity;
			indicatorBox.AddSubview(codeBasedIndicator);
			placeHolder8.RemoveFromSuperview();
			
			
			#endregion
		}
 partial void cancelButtonClicked(MonoMac.AppKit.NSButton sender)
 {
     Window.Close();
 }
Ejemplo n.º 43
0
		static void FillViewers (List<FileViewer> currentViewers, NSPopUpButton button, NSButton closeSolutionButton, FilePath[] filenames)
		{
			button.Menu.RemoveAllItems ();
			currentViewers.Clear ();
			
			if (filenames == null || filenames.Length == 0) {
				button.Enabled = false;
				return;
			}
			
			var filename = filenames[0];
			if (System.IO.Directory.Exists (filename))
				return;
			
			int selected = -1;
			int i = 0;
			
			if (IdeApp.Services.ProjectService.IsWorkspaceItemFile (filename) || IdeApp.Services.ProjectService.IsSolutionItemFile (filename)) {
				button.Menu.AddItem (new NSMenuItem () { Title = GettextCatalog.GetString ("Solution Workbench") });
				currentViewers.Add (null);
				
				if (closeSolutionButton != null)
					closeSolutionButton.State = NSCellStateValue.On;
				
				selected = 0;
				i++;
			}
			
			foreach (var vw in DisplayBindingService.GetFileViewers (filename, null)) {
				if (!vw.IsExternal) {
					button.Menu.AddItem (new NSMenuItem () { Title = vw.Title });
					currentViewers.Add (vw);
					
					if (vw.CanUseAsDefault && selected == -1)
						selected = i;
					
					i++;
				}
			}
			
			if (selected == -1)
				selected = 0;
			
			button.Enabled = currentViewers.Count > 1;
			button.SelectItem (selected);
		}
 partial void refreshButtonClicked(MonoMac.AppKit.NSButton sender)
 {
     UpdateInfo();
 }