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; }
public Command Run(WindowFrame transientFor, MessageDescription message) { this.MessageText = message.Text ?? String.Empty; this.InformativeText = message.SecondaryText ?? String.Empty; if (message.Icon != null) Icon = message.Icon.ToImageDescription (Context).ToNSImage (); var sortedButtons = new Command [message.Buttons.Count]; var j = 0; if (message.DefaultButton >= 0) { sortedButtons [0] = message.Buttons [message.DefaultButton]; this.AddButton (message.Buttons [message.DefaultButton].Label); j = 1; } for (var i = 0; i < message.Buttons.Count; i++) { if (i == message.DefaultButton) continue; sortedButtons [j++] = message.Buttons [i]; this.AddButton (message.Buttons [i].Label); } for (var i = 0; i < sortedButtons.Length; i++) { if (sortedButtons [i].Icon != null) { Buttons [i].Image = sortedButtons [i].Icon.WithSize (IconSize.Small).ToImageDescription (Context).ToNSImage (); Buttons [i].ImagePosition = NSCellImagePosition.ImageLeft; } } if (message.AllowApplyToAll) { ShowsSuppressionButton = true; SuppressionButton.State = NSCellStateValue.Off; SuppressionButton.Activated += (sender, e) => ApplyToAll = SuppressionButton.State == NSCellStateValue.On; } if (message.Options.Count > 0) { AccessoryView = new NSView (); var optionsSize = new CGSize (0, 3); foreach (var op in message.Options) { var chk = new NSButton (); chk.SetButtonType (NSButtonType.Switch); chk.Title = op.Text; chk.State = op.Value ? NSCellStateValue.On : NSCellStateValue.Off; chk.Activated += (sender, e) => message.SetOptionValue (op.Id, chk.State == NSCellStateValue.On); chk.SizeToFit (); chk.Frame = new CGRect (new CGPoint (0, optionsSize.Height), chk.FittingSize); optionsSize.Height += chk.FittingSize.Height + 6; optionsSize.Width = (float) Math.Max (optionsSize.Width, chk.FittingSize.Width); AccessoryView.AddSubview (chk); chk.NeedsDisplay = true; } AccessoryView.SetFrameSize (optionsSize); } var win = Toolkit.CurrentEngine.GetNativeWindow (transientFor) as NSWindow; if (win != null) return sortedButtons [(int)this.RunSheetModal (win) - 1000]; return sortedButtons [(int)this.RunModal () - 1000]; }
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 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); 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; 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; box.Layout (box.View.Superview.Frame.Size); } panel.SelectionDidChange += delegate(object sender, EventArgs e) { var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); bool slnViewerSelected = false; if (viewerSelector != null) { FillViewers (currentViewers, viewerSelector, 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 (box.View.Superview.Frame.Size); } if (encodingSelector != null) encodingSelector.Enabled = !slnViewerSelected; }; try { var action = MacSelectFileDialogHandler.RunPanel (data, panel); if (!action) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } } catch (Exception ex) { System.Console.WriteLine (ex); throw; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); if (encodingSelector != null) data.Encoding = encodingSelector.SelectedEncodingId; if (viewerSelector != null ) { if (closeSolutionButton != null) data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; data.SelectedViewer = currentViewers[viewerSelector.IndexOfSelectedItem]; } GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } finally { if (panel != null) panel.Dispose (); } }
private static NSButton CreateButton(string title, EventHandler handler) { var button = new NSButton { Title = title, }; button.Activated += handler; button.SizeToFit(); return button; }