Ejemplo n.º 1
0
 public static void MessageBox(string message, string title)
 {
     NSAlert alert = new NSAlert();
     alert.MessageText = title;
     alert.InformativeText = message;
     alert.RunModal();
 }
Ejemplo n.º 2
0
 public override void Alert(string message)
 {
     NSAlert alert = new NSAlert();
     alert.MessageText = message;
     alert.AddButton("Ok");
     alert.RunModal ();
 }
Ejemplo n.º 3
0
 protected void OnButtonClicked(object sender, EventArgs e)
 {
     if (sender == button1)
     {
         // native system calls messagebox demo
         // note: this is just a demo, you should always use GTK if you can!
         if (MainClass.platform == Platforms.Mac)
         {
             MonoMac.AppKit.NSAlert alert = new MonoMac.AppKit.NSAlert();
             alert.MessageText = "Hello";
             alert.AlertStyle  = MonoMac.AppKit.NSAlertStyle.Informational;
             alert.AddButton("Ok");
             alert.RunModal();
         }
         else if (MainClass.platform == Platforms.Windows)
         {
             CrossTemplate.Win32.user32.MessageBox(IntPtr.Zero, "Hello", "Caption", 0x40 /* MB_ICONINFORMATION */);
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     else if (sender == button2)
     {
         // Gtk
         Gtk.MessageDialog alert = new Gtk.MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello");
         alert.Title = "Caption";
         ResponseType result = (ResponseType)alert.Run();
         if (result == ResponseType.Ok)
         {
             alert.Destroy();
         }
     }
 }
Ejemplo n.º 4
0
 protected void OnButtonClicked(object sender, EventArgs e)
 {
     if (sender == button1)
     {
         // native system calls messagebox demo
         // note: this is just a demo, you should always use GTK if you can!
         if (MainClass.platform == Platforms.Mac)
         {
             MonoMac.AppKit.NSAlert alert = new MonoMac.AppKit.NSAlert ();
             alert.MessageText = "Hello";
             alert.AlertStyle = MonoMac.AppKit.NSAlertStyle.Informational;
             alert.AddButton ("Ok");
             alert.RunModal ();
         }
         else if (MainClass.platform == Platforms.Windows)
         {
             CrossTemplate.Win32.user32.MessageBox (IntPtr.Zero, "Hello", "Caption", 0x40 /* MB_ICONINFORMATION */);
         }
         else
         {
             throw new NotImplementedException ();
         }
     }
     else if (sender == button2)
     {
         // Gtk
         Gtk.MessageDialog alert = new Gtk.MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello");
         alert.Title = "Caption";
         ResponseType result = (ResponseType)alert.Run ();
         if (result == ResponseType.Ok)
         {
             alert.Destroy ();
         }
     }
 }
Ejemplo n.º 5
0
 public void ShowMessage(NSString message)
 {
     MonoMac.AppKit.NSAlert alert = new MonoMac.AppKit.NSAlert();
     alert.MessageText     = "Message from JavaScript";
     alert.InformativeText = (String)message;
     alert.RunModal();
 }
		// The user just clicked the Show Message NSButton, so we show him/her
		// a greeting. This code shows you how to execute C# code when a click is done in
		// and HTML button.
		public override void HandleEvent (DomEvent evt)
		{
			var alert = new NSAlert () {
				MessageText = "Hello there",
				InformativeText = "Saying hello from C# code. Event type: " + evt.Type
			};
			alert.RunModal();
		}
Ejemplo n.º 7
0
 /// <summary>
 /// Show message box with title and message.
 /// </summary>
 /// <param name="title">Title.</param>
 /// <param name="message">Message.</param>
 public void Show(string title, string message)
 {
     using (var alert = new NSAlert()) {
         alert.MessageText = title;
         alert.InformativeText = message;
         alert.AlertStyle = NSAlertStyle.Informational;
         alert.RunModal ();
     }
 }
Ejemplo n.º 8
0
 public static void ShowAlert(string title, string text, NSAlertStyle alertStyle)
 {
     using(NSAlert alert = new NSAlert())
     {
         alert.MessageText = title;
         alert.InformativeText = text;
         alert.AlertStyle = alertStyle;
         alert.RunModal();
     }
 }
Ejemplo n.º 9
0
		public static int Run (NSAlert view, Control parent)
		{
			int ret;
			if (parent != null) {
				var window = parent.ControlObject as NSWindow;
				if (window == null && parent.ControlObject is NSView)
					window = ((NSView)parent.ControlObject).Window;
				if (window == null || !view.RespondsToSelector (new Selector ("beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:")))
					ret = view.RunModal ();
				else {
					ret = 0;
					NSApplication.SharedApplication.InvokeOnMainThread (delegate {
						view.BeginSheet (window, new MacModal (), new Selector ("alertDidEnd:returnCode:contextInfo:"), IntPtr.Zero);
						ret = NSApplication.SharedApplication.RunModalForWindow (window);
					});
				}
			} else
				ret = view.RunModal ();
			return ret;
		}
Ejemplo n.º 10
0
        public override bool Confirm(string message)
        {
            NSAlert alert = new NSAlert();
            alert.MessageText = message;
            alert.AddButton("No");
            alert.AddButton("Yes");
            int ret = alert.RunModal ();
            if (ret == 1001) {
                return true;
            }

            return false;
        }
Ejemplo n.º 11
0
        public static bool MessageYesNo(string message, string title)
        {
            NSAlert alert = new NSAlert();
            alert.MessageText = title;
            alert.InformativeText = message;
            alert.AddButton ("Yes");
            alert.AddButton ("No");
            int r = alert.RunModal();

            if (r == 1000)
                return true;

            return false;
        }
Ejemplo n.º 12
0
        public override WindowResponse Show(object parent, string message, string title, MessageWindowType type, MessageWindowButtons bType)
        {
            NSAlert al = new NSAlert();
            al.AlertStyle = CocoaHelper.GetWinType(type);
            al.MessageText = title;
            al.InformativeText = message;

            switch (bType)
            {
                case MessageWindowButtons.AbortRetryIgnore:
                    al.AddButton(Message.GetString("Abort"));
                    al.AddButton(Message.GetString("Retry"));
                    al.AddButton(Message.GetString("Ignore"));
                    break;
                case MessageWindowButtons.Cancel:
                    al.AddButton(Message.GetString("Cancel"));
                    break;
                case MessageWindowButtons.Close:
                    al.AddButton(Message.GetString("Close"));
                    break;
                case  MessageWindowButtons.Ok:
                    al.AddButton(Message.GetString("Ok"));
                    break;
                case MessageWindowButtons.OkCancel:
                    al.AddButton(Message.GetString("Ok"));
                    al.AddButton(Message.GetString("Cancel"));
                    break;
                case MessageWindowButtons.RetryCancel:
                    al.AddButton(Message.GetString("Retry"));
                    al.AddButton(Message.GetString("Cancel"));
                    break;
                case MessageWindowButtons.YesNo:
                    al.AddButton(Message.GetString("Yes"));
                    al.AddButton(Message.GetString("No"));
                    break;
                case MessageWindowButtons.YesNoCancel:
                    al.AddButton(Message.GetString("Yes"));
                    al.AddButton(Message.GetString("No"));
                    al.AddButton(Message.GetString("Cancel"));
                    break;
            }

            WindowResponse resp = CocoaHelper.GetResponse(al.RunModal(), bType);
            al.Dispose();
            return resp;
        }
		public bool Run (ExceptionDialogData data)
		{
			using (var alert = new NSAlert ()) {
				alert.AlertStyle = NSAlertStyle.Critical;
				
				var pix = ImageService.GetPixbuf (Gtk.Stock.DialogError, Gtk.IconSize.Dialog);
				byte[] buf = pix.SaveToBuffer ("tiff");
				alert.Icon = new NSImage (NSData.FromArray (buf));
				
				alert.MessageText = data.Title ?? "Some Message";
				alert.InformativeText = data.Message ?? "Some Info";

				if (data.Exception != null) {

					var text = new NSTextView (new RectangleF (0, 0, float.MaxValue, float.MaxValue));
					text.HorizontallyResizable = true;
					text.TextContainer.ContainerSize = new SizeF (float.MaxValue, float.MaxValue);
					text.TextContainer.WidthTracksTextView = false;
					text.InsertText (new NSString (data.Exception.ToString ()));
					text.Editable = false;
					
					var scrollView = new NSScrollView (new RectangleF (0, 0, 450, 150)) {
						HasHorizontalScroller = true,
						DocumentView = text,
					};
;
					alert.AccessoryView = scrollView;
				}
				
				// Hack up a slightly wider than normal alert dialog. I don't know how to do this in a nicer way
				// as the min size constraints are apparently ignored.
				var frame = ((NSPanel) alert.Window).Frame;
				((NSPanel) alert.Window).SetFrame (new RectangleF (frame.X, frame.Y, Math.Max (frame.Width, 600), frame.Height), true);
				
				int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
		void ShowAlert (FinishState finishState)
		{
			InvokeOnMainThread (() => {
				var alert = new NSAlert ();
				switch (finishState) {
				case FinishState.NothingToDo:
					alert.MessageText = "Up-to-date";
					alert.InformativeText = "Your MonoTouch documentation is already based on the latest version of the Apple documentation";
					break;
				case FinishState.Processed:
					alert.MessageText = "Success";
					alert.InformativeText = "Your MonoTouch documentation was successfully updated";
					break;
				case FinishState.Canceled:
					alert.MessageText = "Canceled";
					alert.MessageText = "The update operation was canceled";
					break;
				}
				
				alert.RunModal ();
				NSApplication.SharedApplication.Terminate (this);
			});
		}
Ejemplo n.º 15
0
        void HandleWindowWillClose(object sender, EventArgs e)
        {
            if (!Platform.MacPreferences.ShouldAskToStartAtLogin) return;

            var alert = new NSAlert {
                AlertStyle = NSAlertStyle.Informational,
                MessageText = "Would you like Awareness to start at login?",
                InformativeText = "Unless Awareness starts automatically, you will likely forget to use it. What good would that do you?"
            };
            alert.AddButton ("Start Awareness at Login");
            alert.AddButton ("No Thanks");

            // TODO: Figure out why this freezes Awareness!
            // alert.BeginSheet (Window, this, new Selector ("alertDidEnd:returnCode:contextInfo:"), IntPtr.Zero);

            var pressed = (NSAlertButtonReturn) alert.RunModal ();
            if (pressed == NSAlertButtonReturn.First) {
                Log.Info ("User consented to starting Awareness automatically at login.");
                Platform.Preferences.StartAtLogin = true;
            }

            Platform.MacPreferences.HasAskedToStartAtLogin = true;
        }
Ejemplo n.º 16
0
		public bool Run (AlertDialogData data)
		{
			using (var alert = new NSAlert ()) {
				alert.Window.Title = data.Title ?? BrandingService.ApplicationName;

				if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
					alert.AlertStyle = NSAlertStyle.Critical;
				} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning) {
					alert.AlertStyle = NSAlertStyle.Warning;
				} else { //if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
					alert.AlertStyle = NSAlertStyle.Informational;
				}
				
				//FIXME: use correct size so we don't get horrible scaling?
				if (!string.IsNullOrEmpty (data.Message.Icon)) {
					var pix = ImageService.GetPixbuf (data.Message.Icon, Gtk.IconSize.Dialog);
					byte[] buf = pix.SaveToBuffer ("tiff");
					unsafe {
						fixed (byte* b = buf) {
							alert.Icon = new NSImage (NSData.FromBytes ((IntPtr)b, (uint)buf.Length));
						}
					}
				} else {
					//for some reason the NSAlert doesn't pick up the app icon by default
					alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
				}
				
				alert.MessageText = data.Message.Text;
				alert.InformativeText = data.Message.SecondaryText ?? "";
				
				var buttons = data.Buttons.Reverse ().ToList ();
				
				for (int i = 0; i < buttons.Count - 1; i++) {
					if (i == data.Message.DefaultButton) {
						var next = buttons[i];
						for (int j = buttons.Count - 1; j >= i; j--) {
							var tmp = buttons[j];
							buttons[j] = next;
							next = tmp;
						}
						break;
					}
				}
				
				foreach (var button in buttons) {
					var label = button.Label;
					if (button.IsStockButton)
						label = Gtk.Stock.Lookup (label).Label;
					label = label.Replace ("_", "");

					//this message seems to be a standard Mac message since alert handles it specially
					if (button == AlertButton.CloseWithoutSave)
						label = GettextCatalog.GetString ("Don't Save");

					alert.AddButton (label);
				}
				
				
				NSButton[] optionButtons = null;
				if (data.Options.Count > 0) {
					var box = new MDBox (LayoutDirection.Vertical, 2, 2);
					optionButtons = new NSButton[data.Options.Count];
					
					for (int i = data.Options.Count - 1; i >= 0; i--) {
						var option = data.Options[i];
						var button = new NSButton () {
							Title = option.Text,
							Tag = i,
							State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
						};
						button.SetButtonType (NSButtonType.Switch);
						optionButtons[i] = button;
						box.Add (new MDAlignment (button, true) { XAlign = LayoutAlign.Begin });
					}
					
					box.Layout ();
					alert.AccessoryView = box.View;
				}
				
				NSButton applyToAllCheck = null;
				if (data.Message.AllowApplyToAll) {
					alert.ShowsSuppressionButton = true;
					applyToAllCheck = alert.SuppressionButton;
					applyToAllCheck.Title = GettextCatalog.GetString ("Apply to all");
				}
				
				// Hack up a slightly wider than normal alert dialog. I don't know how to do this in a nicer way
				// as the min size constraints are apparently ignored.
				var frame = ((NSPanel) alert.Window).Frame;
				((NSPanel) alert.Window).SetFrame (new RectangleF (frame.X, frame.Y, Math.Max (frame.Width, 600), frame.Height), true);
				alert.Layout ();
				
				bool completed = false;
				if (data.Message.CancellationToken.CanBeCanceled) {
					data.Message.CancellationToken.Register (delegate {
						alert.InvokeOnMainThread (() => {
							if (!completed) {
								NSApplication.SharedApplication.AbortModal ();
							}
						});
					});
				}
				
				if (!data.Message.CancellationToken.IsCancellationRequested) {
					int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
					completed = true;
					if (result >= 0 && result < buttons.Count) {
						data.ResultButton = buttons [result];
					} else {
						data.ResultButton = null;
					}
				}
				
				if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested) {
					data.SetResultToCancelled ();
				}
				
				if (optionButtons != null) {
					foreach (var button in optionButtons) {
						var option = data.Options[button.Tag];
						data.Message.SetOptionValue (option.Id, button.State != 0);
					}
				}
				
				if (applyToAllCheck != null && applyToAllCheck.State != 0)
					data.ApplyToAll = true;
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
        public void ExportEveryGlyphsAsPNGTo(string path)
        {
            float scale = Window.BackingScaleFactor;
            var glyphInfos = _tableViewSource.GlyphInfos;
            //actvw.StartAnimating ();
            Task.Factory.StartNew (() => {
                Func<string, string> makeName = (rawName) => {
                    return String.Format ("{0}_{1}{2}.png", rawName, (int)this.unitFontSize
                                          , ((scale > 2f) ? "@4x" : (scale > 1f) ? "@2x" : ""));
                };
                //string documentDirPath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
                string documentDirPath = path;

                NSDictionary prop = new NSDictionary (); //
                int nSucceeded = 0;
                int nFailed = 0;
                glyphInfos.ForEach ((gi) => {
                    var url = new NSUrl (System.IO.Path.Combine (documentDirPath, makeName (gi.RawName)), false);
                    try {
                        CGImageDestination dest = CGImageDestination.FromUrl (url, "public.png", 1);
                        dest.AddImage (gi.GlyphImage, prop);
                        dest.Close ();
                    }
                    catch (Exception ex) {
                        Console.WriteLine (ex.ToString ());
                    }
                    if (System.IO.File.Exists (url.Path)) {
                        //Console.WriteLine ("Succeeded to write {0}", url);
                        ++ nSucceeded;
                    }
                    else {
                        Console.WriteLine ("Failed to write {0}", url);
                        ++ nFailed;
                    }
                    BeginInvokeOnMainThread (() => {
                        //ShowProgressionLabel (String.Format ("{0} of {1} processed", (nSucceeded + nFailed), glyphInfos.Count));
                    });
                });

                InvokeOnMainThread (() => {
                    //actvw.StopAnimating ();
                    //DismissProgressionLabel ();
                    var alert = new NSAlert ();
                    alert.MessageText = String.Format ("{0} succeeded, {1} failed", nSucceeded, nFailed);
                    alert.RunModal ();
                });
            });
        }
Ejemplo n.º 18
0
 private void HandleOnResetAudioSettingsButtonSelected(SessionsButton button)
 {
     if (OnCheckIfPlayerIsPlaying())
     {
         using(var alert = new NSAlert())
         {
             alert.MessageText = "Confirmation";
             alert.InformativeText = "Resetting the audio settings will stop the playback.\n\nIf you click OK, the playback will stop and changes will be applied immediately.\n\nIf you click Cancel, the changes will be applied the next time the player is reinitialized.";
             alert.AlertStyle = NSAlertStyle.Warning;
             var btnOK = alert.AddButton("OK");
             btnOK.Activated += (sender2, e2) => {
                 NSApplication.SharedApplication.StopModal();
                 OnResetAudioSettings();
             };
             var btnCancel = alert.AddButton("Cancel");
             btnCancel.Activated += (sender3, e3) => NSApplication.SharedApplication.StopModal();
             alert.RunModal();
         }
     }
 }
Ejemplo n.º 19
0
        private void SetOutputDeviceAndSampleRate()
        {
            if (popupOutputDevice.IndexOfSelectedItem == -1 || popupSampleRate.IndexOfSelectedItem == -1 || _isRefreshingComboBoxes)
                return;

            if (OnCheckIfPlayerIsPlaying())
            {
                using (var alert = new NSAlert())
                {
                    alert.MessageText = "Confirmation";
                    alert.InformativeText = "Resetting the audio settings will stop the playback.\n\nIf you click OK, the playback will stop and changes will be applied immediately.\n\nIf you click Cancel, the changes will be applied the next time the player is reinitialized.";
                    alert.AlertStyle = NSAlertStyle.Warning;
                    var btnOK = alert.AddButton("OK");
                    btnOK.Activated += (sender2, e2) =>
                    {
                        NSApplication.SharedApplication.StopModal();
                        SetOutputDeviceAndSampleRateInternal();
                    };
                    var btnCancel = alert.AddButton("Cancel");
                    btnCancel.Activated += (sender3, e3) => NSApplication.SharedApplication.StopModal();
                    alert.RunModal();
                }
            }
            else
            {
                SetOutputDeviceAndSampleRateInternal();
            }
        }
Ejemplo n.º 20
0
 private void HandleOnResetLibraryButtonSelected(SessionsButton button)
 {
     using(var alert = new NSAlert())
     {
         alert.MessageText = "Library will be reset";
         alert.InformativeText = "Are you sure you wish to reset your library? This won't delete any audio files from your hard disk.";
         alert.AlertStyle = NSAlertStyle.Warning;
         var btnOK = alert.AddButton("OK");
         btnOK.Activated += (sender2, e2) => {
             NSApplication.SharedApplication.StopModal();
             OnResetLibrary();
         };
         var btnCancel = alert.AddButton("Cancel");
         btnCancel.Activated += (sender3, e3) => NSApplication.SharedApplication.StopModal();
         alert.RunModal();
     }
 }
Ejemplo n.º 21
0
        private void HandleOnRemoveFolderButtonSelected(SessionsButton button)
        {
            using(var alert = new NSAlert())
            {
                alert.MessageText = "Folder will be removed from library";
                alert.InformativeText = "Are you sure you wish to remove this folder from your library? This won't delete any audio files from your hard disk.";
                alert.AlertStyle = NSAlertStyle.Warning;
                var btnOK = alert.AddButton("OK");
                btnOK.Activated += (sender2, e2) => {
                    NSApplication.SharedApplication.StopModal();

                    // Remove files from database
                    //OnRemoveFolder(_libraryAppConfig.Folders[tableFolders.SelectedRow]);

                    // Remove folder from list of configured folders
                    _libraryAppConfig.Folders.RemoveAt(tableFolders.SelectedRow);
                    OnSetLibraryPreferences(_libraryAppConfig);
                    tableFolders.ReloadData();
                };
                var btnCancel = alert.AddButton("Cancel");
                btnCancel.Activated += (sender3, e3) => NSApplication.SharedApplication.StopModal();
                alert.RunModal();
            }
        }
Ejemplo n.º 22
0
		void LaunchDocumentationUpdate (bool docOutdated, bool mergeOutdated)
		{
			var infoDialog = new NSAlert {
				AlertStyle = NSAlertStyle.Informational,
				MessageText = "Documentation update available",
				InformativeText = "We have detected your MonoTouch documentation can be upgraded with Apple documentation."
					+ Environment.NewLine
					+ Environment.NewLine
					+ "Would you like to update the documentation now? You can continue to browse the documentation while the update is performed."
			};
			
			infoDialog.AddButton ("Update now");
			infoDialog.AddButton ("Remind me later");
			var dialogResult = infoDialog.RunModal ();
			// If Cancel was clicked, just return
			if (dialogResult == (int)NSAlertButtonReturn.Second)
				return;
			
			// Launching AppleDocWizard as root
			// First get the directory
			try {
				RootLauncher.LaunchExternalTool (mergeToolPath, docOutdated ? new string[] { "--force-download" } : (string[])null);
			} catch (RootLauncherException ex) {
				var alertDialog = new NSAlert {
					AlertStyle = NSAlertStyle.Critical,
					MessageText = "Documentation updater error",
					InformativeText = string.Format ("There was an error launching the documentation updater: {0}{1}{2}", ex.ResultCode.ToString (), Environment.NewLine, ex.Message)
				};
				alertDialog.RunModal ();
			}
		}
Ejemplo n.º 23
0
 partial void actionRemovePreset(NSObject sender)
 {
     using(NSAlert alert = new NSAlert())
     {
         alert.MessageText = "Equalizer preset will be deleted";
         alert.InformativeText = "Are you sure you wish to delete this equalizer preset?";
         alert.AlertStyle = NSAlertStyle.Warning;
         var btnOK = alert.AddButton("OK");
         btnOK.Activated += (sender2, e2) => {
             NSApplication.SharedApplication.StopModal();
             OnDeletePreset(_preset.EQPresetId);
             EnableFaders(false);
             EnablePresetDetails(false);
             ResetFaderValuesAndPresetDetails();
             _preset = null;
         };
         var btnCancel = alert.AddButton("Cancel");
         btnCancel.Activated += (sender3, e3) => {
             NSApplication.SharedApplication.StopModal();
         };
         alert.RunModal();
     }
 }
Ejemplo n.º 24
0
 partial void actionReset(NSObject sender)
 {
     using(NSAlert alert = new NSAlert())
     {
         alert.MessageText = "Equalizer preset will be reset";
         alert.InformativeText = "Are you sure you wish to reset this equalizer preset?";
         alert.AlertStyle = NSAlertStyle.Warning;
         var btnOK = alert.AddButton("OK");
         btnOK.Activated += (sender2, e2) => {
             NSApplication.SharedApplication.StopModal();
             OnResetPreset();
         };
         var btnCancel = alert.AddButton("Cancel");
         btnCancel.Activated += (sender3, e3) => {
             NSApplication.SharedApplication.StopModal();
         };
         alert.RunModal();
     }
 }
Ejemplo n.º 25
0
		public bool Run (ExceptionDialogData data)
		{
			using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) {
				alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
				
				alert.MessageText = data.Title ?? GettextCatalog.GetString ("Error");
				
				if (!string.IsNullOrEmpty (data.Message)) {
					alert.InformativeText = data.Message;
				}

				List<AlertButton> buttons = null;
				if (data.Buttons != null && data.Buttons.Length > 0)
					buttons = data.Buttons.Reverse ().ToList ();

				if (buttons != null) {
					foreach (var button in buttons) {
						var label = button.Label;
						if (button.IsStockButton)
							label = Gtk.Stock.Lookup (label).Label;
						label = label.Replace ("_", "");

						//this message seems to be a standard Mac message since alert handles it specially
						if (button == AlertButton.CloseWithoutSave)
							label = GettextCatalog.GetString ("Don't Save");

						alert.AddButton (label);
					}
				}

				if (data.Exception != null) {
					var scrollSize = new SizeF (400, 130);
					float spacing = 4;
					
					string title = GettextCatalog.GetString ("View details");
					string altTitle = GettextCatalog.GetString ("Hide details");
					
					var buttonFrame = new RectangleF (0, 0, 0, 0);
					var button = new NSButton (buttonFrame) {
						BezelStyle = NSBezelStyle.Disclosure,
						Title = "",
						AlternateTitle = "",
					};
					button.SetButtonType (NSButtonType.OnOff);
					button.SizeToFit ();
					
					var label = new MDClickableLabel (title) {
						Alignment = NSTextAlignment.Left,
					};
					label.SizeToFit ();
					
					button.SetFrameSize (new SizeF (button.Frame.Width, Math.Max (button.Frame.Height, label.Frame.Height)));
					label.SetFrameOrigin (new PointF (button.Frame.Width + 5, button.Frame.Y));
					
					var text = new MyTextView (new RectangleF (0, 0, float.MaxValue, float.MaxValue)) {
						HorizontallyResizable = true,
					};
					text.TextContainer.ContainerSize = new SizeF (float.MaxValue, float.MaxValue);
					text.TextContainer.WidthTracksTextView = true;
					text.InsertText (new NSString (data.Exception.ToString ()));
					text.Editable = false;

					var scrollView = new NSScrollView (new RectangleF (PointF.Empty, SizeF.Empty)) {
						HasHorizontalScroller = true,
						HasVerticalScroller = true,
					};
					
					var accessory = new NSView (new RectangleF (0, 0, scrollSize.Width, button.Frame.Height));
					accessory.AddSubview (scrollView);
					accessory.AddSubview (button);
					accessory.AddSubview (label);
					
					alert.AccessoryView = accessory;
					
					button.Activated += delegate {
						float change;
						if (button.State == NSCellStateValue.On) {
							change = scrollSize.Height + spacing;
							label.StringValue = altTitle;
							scrollView.Hidden = false;
							scrollView.Frame = new RectangleF (PointF.Empty, scrollSize);
							scrollView.DocumentView = text;
						} else {
							change = -(scrollSize.Height + spacing);
							label.StringValue = title;
							scrollView.Hidden = true;
							scrollView.Frame = new RectangleF (PointF.Empty, SizeF.Empty);
						}
						var f = accessory.Frame;
						f.Height += change;
						accessory.Frame = f;
						var lf = label.Frame;
						lf.Y += change;
						label.Frame = lf;
						var bf = button.Frame;
						bf.Y += change;
						button.Frame = bf;
						label.SizeToFit ();
						var panel = (NSPanel) alert.Window;
						var pf = panel.Frame;
						pf.Height += change;
						pf.Y -= change;
						panel.SetFrame (pf, true, true);
						//unless we assign the icon again, it starts nesting old icon into the warning icon
						alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
						alert.Layout ();
					};
					label.OnMouseUp += (sender, e) => button.PerformClick (e.Event);
				}

				int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
				data.ResultButton = buttons != null ? buttons [result] : null;
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
        public void event_btnUpload_Activated(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty (txtUserName.StringValue) || string.IsNullOrEmpty (txtPassWord.StringValue)) {
                var alert = new NSAlert {
                    MessageText = "Username or password empty.",
                    AlertStyle = NSAlertStyle.Informational
                };

                alert.AddButton ("Ok");

                alert.RunModal();
                return;
            }

            FileInfo fInfo = new FileInfo(txtFullSceneName.StringValue);
            long numBytes = fInfo.Length;

            FileStream fStream = new FileStream(txtFullSceneName.StringValue, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fStream);

            FormUpload.FileParameter fp = new FormUpload.FileParameter (br.ReadBytes((int)numBytes),
                Path.GetFileName (txtFullSceneName.StringValue),
                "application/octet-stream");

            br.Close();
            fStream.Close();

            string releaseType = string.Empty;
            if (cmbType.StringValue == "App")
                releaseType = "1";
            if (cmbType.StringValue == "Game")
                releaseType = "2";

            var client = new WebClientEx ();
            var values = new NameValueCollection
            {
                { "username", txtUserName.StringValue },
                { "password", txtPassWord.StringValue },
            };

            // Authenticate
            client.UploadValues("https://mac-torrents.me/login.php", values);
            string tempResponse = client.DownloadString ("https://mac-torrents.me/upload.php");

            string searchFor = "<input type=\"hidden\" name=\"auth\" value=\"";
            int indexSearchFor = tempResponse.IndexOf (searchFor) + searchFor.Length;
            string authString = tempResponse.Substring (indexSearchFor, 32);

            // Upload torrent
            Dictionary<string, object> paramsDic = new Dictionary<string, object> ();
            paramsDic.Add ("submit", "true");
            paramsDic.Add ("auth", authString);
            paramsDic.Add ("type", releaseType);
            paramsDic.Add ("title", txtTitleCode.StringValue);
            paramsDic.Add ("tags", txtTagsCode.StringValue);
            paramsDic.Add ("image", txtImageCode.StringValue);
            paramsDic.Add ("desc", txtDescriptionCode.Value);
            paramsDic.Add ("file_input", fp);

            if (cmbComp.StringValue == "10.6") {
                paramsDic.Add ("macos[]", new string[] {"1", "2", "3", "4"});
            }
            if (cmbComp.StringValue == "10.7")
            {
                paramsDic.Add ("macos[]", new string[] {"2", "3", "4"});
            }
            if (cmbComp.StringValue == "10.8")
            {
                paramsDic.Add ("macos[]", new string[] {"3", "4"});
            }
            if (cmbComp.StringValue == "10.9")
            {
                paramsDic.Add ("macos[]", "4");
            }
            //Upload torrent
            FormUpload.MultipartFormDataPost (
                "https://mac-torrents.me/upload.php",
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) " +
                    "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36",
                paramsDic,
                client.CookieContainer);

            try
            {
                tempResponse = client.DownloadString ("https://mac-torrents.me/logout.php?auth=" + authString);
            } catch {
            }

            txtNfoFilename.StringValue = "";
            txtDescription.Value = "";
            txtDescriptionCode.Value = "";
            txtTagsCode.StringValue = "";
            txtImageCode.StringValue = "";

            var alertEnd = new NSAlert {
                MessageText = "Done!",
                AlertStyle = NSAlertStyle.Informational
            };

            alertEnd.AddButton ("Ok");

            alertEnd.RunModal();
        }
Ejemplo n.º 27
0
		public bool Run (AlertDialogData data)
		{
			using (var alert = new NSAlert ()) {
				
				if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
					alert.AlertStyle = NSAlertStyle.Critical;
				} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning) {
					alert.AlertStyle = NSAlertStyle.Warning;
				} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
					alert.AlertStyle = NSAlertStyle.Informational;
				}
				
				//FIXME: use correct size so we don't get horrible scaling?
				if (!string.IsNullOrEmpty (data.Message.Icon)) {
					var pix = ImageService.GetPixbuf (data.Message.Icon, Gtk.IconSize.Dialog);
					byte[] buf = pix.SaveToBuffer ("tiff");
					unsafe {
						fixed (byte* b = buf) {
							alert.Icon = new NSImage (NSData.FromBytes ((IntPtr)b, (uint)buf.Length));
						}
					}
				}
				
				alert.MessageText = data.Message.Text;
				alert.InformativeText = data.Message.SecondaryText ?? "";
				
				var buttons = data.Buttons.Reverse ().ToList ();
				
				for (int i = 0; i < buttons.Count - 1; i++) {
					if (i == data.Message.DefaultButton) {
						var next = buttons[i];
						for (int j = buttons.Count - 1; j >= i; j--) {
							var tmp = buttons[j];
							buttons[j] = next;
							next = tmp;
						}
						break;
					}
				}
				
				foreach (var button in buttons) {
					var label = button.Label;
					if (button.IsStockButton)
						label = Gtk.Stock.Lookup (label).Label;
					label = label.Replace ("_", "");
					
					//this message seems to be a standard Mac message since alert handles it specially
					if (button == AlertButton.CloseWithoutSave)
						label = GettextCatalog.GetString ("Don't Save");
					
					alert.AddButton (label);
				}
				
				
				NSButton[] optionButtons = null;
				if (data.Options.Count > 0) {
					var box = new MDBox (LayoutDirection.Vertical, 2, 2);
					optionButtons = new NSButton[data.Options.Count];
					
					for (int i = data.Options.Count - 1; i >= 0; i--) {
						var option = data.Options[i];
						var button = new NSButton () {
							Title = option.Text,
							Tag = i,
							State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
						};
						button.SetButtonType (NSButtonType.Switch);
						optionButtons[i] = button;
						box.Add (new MDAlignment (button, true) { XAlign = LayoutAlign.Begin });
					}
					
					box.Layout ();
					alert.AccessoryView = box.View;
				}
				
				NSButton applyToAllCheck = null;
				if (data.Message.AllowApplyToAll) {
					alert.ShowsSuppressionButton = true;
					applyToAllCheck = alert.SuppressionButton;
					applyToAllCheck.Title = GettextCatalog.GetString ("Apply to all");
				}
				
				alert.Layout ();
				
				int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
				
				data.ResultButton = buttons [result];
				
				if (optionButtons != null) {
					foreach (var button in optionButtons) {
						var option = data.Options[button.Tag];
						data.Message.SetOptionValue (option.Id, button.State != 0);
					}
				}
				
				if (applyToAllCheck != null && applyToAllCheck.State != 0)
					data.ApplyToAll = true;
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
Ejemplo n.º 28
0
		void LaunchDocumentationUpdate ()
		{
			var infoDialog = new NSAlert {
				AlertStyle = NSAlertStyle.Informational,
				MessageText = "Documentation update available",
				InformativeText = "We have detected your MonoTouch documentation can be upgraded with Apple documentation, would you like to launch the merge now (root password required)?"
			};
			
			infoDialog.AddButton ("Yes");
			infoDialog.AddButton ("Cancel");
			var dialogResult = infoDialog.RunModal ();
			// If Cancel was clicked, just return
			if (dialogResult == (int)NSAlertButtonReturn.Second)
				return;
			
			// Launching AppleDocWizard as root
			// First get the directory
			var updaterPath = Path.Combine (Path.GetDirectoryName (NSBundle.MainBundle.BuiltinPluginsPath), "MacOS");
			// Next get the executable
			updaterPath = Path.Combine (updaterPath, "AppleDocWizard.app", "Contents", "MacOS", "AppleDocWizard");
			try {
				RootLauncher.LaunchExternalTool (updaterPath);
			} catch (RootLauncherException ex) {
				var alertDialog = new NSAlert {
					AlertStyle = NSAlertStyle.Critical,
					MessageText = "Documentation updater error",
					InformativeText = string.Format ("There was an error launching the documentation updater: {0}{1}{2}", ex.ResultCode.ToString (), Environment.NewLine, ex.Message)
				};
				alertDialog.RunModal ();
			}
		}
Ejemplo n.º 29
0
        public SparkleUI()
        {
            NSApplication.Init ();

            SetSparkleIcon ();

            // TODO: Getting crashes when I remove this
            NSApplication.SharedApplication.ApplicationIconImage
                = NSImage.ImageNamed ("sparkleshare.icns");

            if (!SparkleShare.Controller.BackendIsPresent) {

                Alert = new SparkleAlert ();
                Alert.RunModal ();
                return;

            }

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

            OpenLogs   = new List <SparkleLog> ();
            StatusIcon = new SparkleStatusIcon ();

            SparkleShare.Controller.NotificationRaised += delegate {

                InvokeOnMainThread (delegate {

                    foreach (SparkleLog log in SparkleUI.OpenLogs)
                        log.UpdateEventLog ();

                    if (SparkleShare.Controller.NotificationsEnabled) {

                        if (NSApplication.SharedApplication.DockTile.BadgeLabel == null)
                            NSApplication.SharedApplication.DockTile.BadgeLabel = "1";
                        else
                            NSApplication.SharedApplication.DockTile.BadgeLabel =
                                (int.Parse (NSApplication.SharedApplication.DockTile.BadgeLabel) + 1).ToString ();

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.InformationalRequest);

                    }

                });

            };

            SparkleShare.Controller.AvatarFetched += delegate {

                InvokeOnMainThread (delegate {

                    foreach (SparkleLog log in SparkleUI.OpenLogs)
                        log.UpdateEventLog ();

                });

            };

            SparkleShare.Controller.OnIdle += delegate {

                InvokeOnMainThread (delegate {

                    foreach (SparkleLog log in SparkleUI.OpenLogs)
                        log.UpdateEventLog ();

                });

            };

            if (SparkleShare.Controller.FirstRun) {

                Intro = new SparkleIntro ();
                Intro.ShowAccountForm ();

            }
        }
Ejemplo n.º 30
0
 private void HandleOnDeletePeakFilesButtonSelected(SessionsButton button)
 {
     using(var alert = new NSAlert())
     {
         alert.MessageText = "Peak files will be deleted";
         alert.InformativeText = "Are you sure you wish to delete the peak files folder? Peak files can always be generated later.";
         alert.AlertStyle = NSAlertStyle.Warning;
         var btnOK = alert.AddButton("OK");
         btnOK.Activated += (sender2, e2) => {
             NSApplication.SharedApplication.StopModal();
             OnDeletePeakFiles();
         };
         var btnCancel = alert.AddButton("Cancel");
         btnCancel.Activated += (sender3, e3) => NSApplication.SharedApplication.StopModal();
         alert.RunModal();
     }
 }
Ejemplo n.º 31
0
		void LaunchDocumentationUpdate (Dictionary<Product, Tuple<bool, bool>> toUpdate)
		{
			var informative = "We have detected your " + string.Join (" and ", toUpdate.Keys.Select (ProductUtils.GetFriendlyName)) +
				" documentation can be upgraded with Apple documentation.";
			// Check if we are going to be downloading stuff
			if (toUpdate.Any (kvp => kvp.Value.Item1))
				informative += Environment.NewLine + Environment.NewLine + "Warning: we are going to download documentation from Apple servers which can take a long time depending on your Internet connection.";
			informative += Environment.NewLine + Environment.NewLine + "Would you like to update the documentation now?";

			var infoDialog = new NSAlert {
				AlertStyle = NSAlertStyle.Informational,
				MessageText = "Documentation update available",
				InformativeText = informative
			};
			
			infoDialog.AddButton ("Update now");
			infoDialog.AddButton ("Remind me later");
			var dialogResult = infoDialog.RunModal ();
			// If Cancel was clicked, just return
			if (dialogResult == (int)NSAlertButtonReturn.Second)
				return;
			
			// Launching AppleDocWizard as root
			var mergerTasks = toUpdate
				.Where (kvp => kvp.Value.Item1 || kvp.Value.Item2)
				.Select (kvp => Task.Factory.StartNew (() => {
						var mergeToolPath = ProductUtils.GetMergeToolForProduct (kvp.Key);
						var docOutdated = kvp.Value.Item1;

						// If the script has its setuid bit on and user as root, then we launch it directly otherwise we first restore it
						if (!RootLauncher.IsRootEnabled (mergeToolPath)) {
							RootLauncher.LaunchExternalTool (mergeToolPath, new string[] { "--self-repair" });
							// No good way to know when the process will finish, so wait a bit. Not ideal but since this is an unlikely codepath, shouldn't matter.
							System.Threading.Thread.Sleep (1000);
						}
						var psi = new System.Diagnostics.ProcessStartInfo (mergeToolPath, docOutdated ? "--force-download" : null);
						return ProcessUtils.StartProcess (psi, null, null, CancellationToken.None);
					}).Unwrap ());
			// No Task.WhenAll yet
			var tcs = new TaskCompletionSource<int> ();
			Task.Factory.ContinueWhenAll (mergerTasks.ToArray (), ts => {
				var faulteds = ts.Where (t => t.IsFaulted);
				if (faulteds.Any ())
					tcs.SetException (faulteds.Select (t => t.Exception));
				else
					tcs.SetResult (ts.Select (t => t.Result).FirstOrDefault (r => r != 0));
			});

			var mergeController = new AppleDocMergeWindowController ();
			mergeController.TrackProcessTask (tcs.Task);
			mergeController.ShowWindow (this);
			mergeController.Window.Center ();
		}
		void ShowAlert (string title, string msg)
		{
			NSAlert alert = new NSAlert ();
			alert.MessageText = title;
			alert.InformativeText = msg;
			alert.AlertStyle = NSAlertStyle.Warning;
			alert.RunModal ();
		}