internal static NSView CreateLabelledDropdown (string label, float popupWidth, out NSPopUpButton popup) { popup = new NSPopUpButton (new RectangleF (0, 6, popupWidth, 18), false) { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.MaxXMargin, }; return LabelControl (label, 200, popup); }
internal static NSPopUpButton CreateFileFilterPopup (SelectFileDialogData data, NSSavePanel panel) { var filters = data.Filters; //no filtering if (filters == null || filters.Count == 0) { return null; } //filter, but no choice if (filters.Count == 1) { panel.ShouldEnableUrl = GetFileFilter (filters[0]); return null; } var popup = new NSPopUpButton (new RectangleF (0, 6, 200, 18), false); popup.SizeToFit (); var rect = popup.Frame; popup.Frame = new RectangleF (rect.X, rect.Y, 200, rect.Height); foreach (var filter in filters) popup.AddItem (filter.Name); var defaultIndex = data.DefaultFilter == null? 0 : Math.Max (0, filters.IndexOf (data.DefaultFilter)); if (defaultIndex > 0) { popup.SelectItem (defaultIndex); } panel.ShouldEnableUrl = GetFileFilter (filters[defaultIndex]); popup.Activated += delegate { panel.ShouldEnableUrl = GetFileFilter (filters[popup.IndexOfSelectedItem]); panel.Display (); }; return popup; }
// The user just chose a theme in the NSPopUpButton, so we replace the HTML // document's CSS file using JavaScript. partial void changeTheme(MonoMac.AppKit.NSPopUpButton sender) { WebScriptObject scriptObject = webView.WindowScriptObject; NSString theme = (NSString)themeChooser.SelectedItem.RepresentedObject; scriptObject.EvaluateWebScript("document.getElementById('ss').href = '" + (string)theme + "'"); }
public bool Run (AddFileDialogData data) { using (var panel = new NSOpenPanel () { CanChooseDirectories = false, CanChooseFiles = true, }) { MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); var popup = new NSPopUpButton (new RectangleF (0, 0, 200, 28), false); var dropdownBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { new MDLabel (GettextCatalog.GetString ("Override build action:")), true }, { new MDAlignment (popup, true) { MinWidth = 200 } } }; var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); if (filterPopup != null) { dropdownBox.Layout (); var box = new MDBox (LayoutDirection.Vertical, 2, 2) { dropdownBox.View, filterPopup, }; box.Layout (); panel.AccessoryView = box.View; box.Layout (box.View.Superview.Frame.Size); } else { dropdownBox.Layout (); panel.AccessoryView = dropdownBox.View; } popup.AddItem (GettextCatalog.GetString ("(Default)")); popup.Menu.AddItem (NSMenuItem.SeparatorItem); foreach (var b in data.BuildActions) { if (b == "--") popup.Menu.AddItem (NSMenuItem.SeparatorItem); else popup.AddItem (b); } var action = MacSelectFileDialogHandler.RunPanel (data, panel); if (!action) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); var idx = popup.IndexOfSelectedItem - 2; if (idx >= 0) data.OverrideAction = data.BuildActions[idx]; GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } }
partial void changeChannel(MonoMac.AppKit.NSPopUpButton sender) { var previousChannel = CurrentInterface.WlanChannel; var selectedChannel = CurrentInterface.SupportedWlanChannels.Where(channel => string.Format("{0} {1}", channel.ChannelNumber, channel.ChannelBand) == channelPicker.SelectedItem.Title).First(); NSError error; CurrentInterface.SetWlanChannel(selectedChannel, out error); if (error != null) { Console.WriteLine("Error occurred while changing interface channel: {0}", error.LocalizedDescription); CurrentInterface.SetWlanChannel(previousChannel, out error); channelPicker.SelectItem(string.Format("{0} {1}", previousChannel.ChannelNumber, previousChannel.ChannelBand)); } }
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; }
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); }
public void UpdateChooser(string [] folders) { using (var a = new NSAutoreleasePool ()) { if (folders == null) folders = Controller.Folders; if (this.popup_button != null) this.popup_button.RemoveFromSuperview (); this.popup_button = new NSPopUpButton () { Frame = new RectangleF (480 - 156 - 8, 640 - 31 - 24, 156, 26), PullsDown = false }; this.popup_button.Cell.ControlSize = NSControlSize.Small; this.popup_button.Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize); this.popup_button.AddItem ("All Projects"); this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); int row = 2; foreach (string folder in folders) { this.popup_button.AddItem (folder); if (folder.Equals (Controller.SelectedFolder)) this.popup_button.SelectItem (row); row++; } this.popup_button.AddItems (folders); this.popup_button.Activated += delegate { using (var b = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { if (this.popup_button.IndexOfSelectedItem == 0) Controller.SelectedFolder = null; else Controller.SelectedFolder = this.popup_button.SelectedItem.Title; }); } }; ContentView.AddSubview (this.popup_button); } }
/// <summary> /// User chose a different picker style from the Picker Style popup. /// </summary> /// <param name="sender"> /// A <see cref="NSPopUpButton"/> /// </param> partial void setPickerStyle (NSPopUpButton sender) { int tag = sender.SelectedCell.Tag; if (datePickerControl.DatePickerStyle != (NSDatePickerStyle)tag) { RectangleF windowFrame = this.Window.Frame; RectangleF boxFrame = outerBox.Frame; datePickerControl.Hidden = true; if ((NSDatePickerStyle)tag == NSDatePickerStyle.ClockAndCalendar) { // for this picker style, we need to grow the window to make room for it. SizeF size = windowFrame.Size; size.Height += shrinkGrowFacter; windowFrame.Size = size; PointF origin = windowFrame.Location; origin.Y -= shrinkGrowFacter; windowFrame.Location = origin; size = boxFrame.Size; size.Height += shrinkGrowFacter; boxFrame.Size = size; outerBox.Frame = boxFrame; this.Window.SetFrame (windowFrame, true, true); datePickerControl.DatePickerStyle = NSDatePickerStyle.ClockAndCalendar; // shows these last dateResult1.Hidden = false; dateResult2.Hidden = false; dateResult3.Hidden = false; dateResult4.Hidden = false; } else { NSDatePickerStyle currentPickerStyle = datePickerControl.DatePickerStyle; // shrink the window only if the current style is "clock and calendar" if (currentPickerStyle == NSDatePickerStyle.ClockAndCalendar) { dateResult1.Hidden = true; dateResult2.Hidden = true; dateResult3.Hidden = true; dateResult4.Hidden = true; SizeF size = windowFrame.Size; size.Height -= shrinkGrowFacter; windowFrame.Size = size; PointF origin = windowFrame.Location; origin.Y += shrinkGrowFacter; windowFrame.Location = origin; size = boxFrame.Size; size.Height -= shrinkGrowFacter; boxFrame.Size = size; outerBox.Frame = boxFrame; this.Window.SetFrame (windowFrame, true, true); } // set our desired picker style setupDatePickerControl ((NSDatePickerStyle)tag); } datePickerControl.Hidden = false; updateControls (); // force update of all UI elements and the picker itself } }
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 (); } }
static void FillViewers (List<FileViewer> currentViewers, NSPopUpButton button, 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; if (IdeApp.Services.ProjectService.IsWorkspaceItemFile (filename) || IdeApp.Services.ProjectService.IsSolutionItemFile (filename)) { button.Menu.AddItem (new NSMenuItem () { Title = GettextCatalog.GetString ("Solution Workbench") }); currentViewers.Add (null); } foreach (var vw in DisplayBindingService.GetFileViewers (filename, null)) { if (!vw.IsExternal) { button.Menu.AddItem (new NSMenuItem () { Title = vw.Title }); currentViewers.Add (vw); } } button.Enabled = currentViewers.Count > 1; button.SelectItem (0); }
partial void interfaceSelected(MonoMac.AppKit.NSPopUpButton sender) { CurrentInterface = new CWInterface(interfacesPicker.SelectedItem.Title); UpdateInfoTab(); }
public static string GetSelected(NSPopUpButton control) { return control.SelectedItem.Title; }
public static void SetSelected(NSPopUpButton control, string value) { control.SelectItem (value); }
/// <summary> /// User chose a different control font size from the Font Size popup /// </summary> /// <param name="sender"> /// A <see cref="NSPopUpButton"/> /// </param> partial void setFontSize (NSPopUpButton sender) { int tag = sender.SelectedCell.Tag; switch ((NSControlSize)tag) { case NSControlSize.Mini: datePickerControl.Cell.ControlSize = NSControlSize.Mini; datePickerControl.Cell.Font = NSFont.SystemFontOfSize (9.0f); break; case NSControlSize.Small: datePickerControl.Cell.ControlSize = NSControlSize.Small; datePickerControl.Cell.Font = NSFont.SystemFontOfSize (11.0f); break; case NSControlSize.Regular: datePickerControl.Cell.ControlSize = NSControlSize.Regular; datePickerControl.Cell.Font = NSFont.SystemFontOfSize (13.0f); break; } }
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; }); } }; }
public void UpdateChooser(string [] folders) { if (folders == null) folders = this.controller.Folders; if (this.popup_button != null) this.popup_button.RemoveFromSuperview (); this.popup_button = new NSPopUpButton () { Frame = new RectangleF (480 - 156 - 8, 640 - 31 - 24, 156, 26), PullsDown = false }; this.popup_button.Cell.ControlSize = NSControlSize.Small; this.popup_button.Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize); this.popup_button.AddItem ("All Folders"); this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); this.popup_button.AddItems (folders); this.popup_button.Activated += delegate { if (this.popup_button.IndexOfSelectedItem == 0) this.controller.SelectedFolder = null; else this.controller.SelectedFolder = this.popup_button.SelectedItem.Title; }; ContentView.AddSubview (this.popup_button); }
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), "", "") { 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); (Delegate as SparkleEventsDelegate).WindowResized += Relayout; } // Hook up the controller events Controller.HideWindowEvent += delegate { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.progress_indicator.Hidden = true; PerformClose (this); }); } }; 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.UpdateChooserEnablementEvent += delegate (bool enabled) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.popup_button.Enabled = enabled; }); } }; Controller.UpdateContentEvent += delegate (string html) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.progress_indicator.Hidden = true; UpdateContent (html); }); } }; Controller.ContentLoadingEvent += delegate { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.web_view.RemoveFromSuperview (); this.progress_indicator.Hidden = false; this.progress_indicator.StartAnimation (this); }); } }; 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; }); } }; Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (() => { // TODO: Make this a sheet NSSavePanel panel = new NSSavePanel () { DirectoryUrl = new NSUrl (target_folder_path, true), NameFieldStringValue = file_name, ParentWindow = this, Title = "Restore from History", PreventsApplicationTerminationWhenModal = false }; if ((NSPanelButtonType) panel.RunModal ()== NSPanelButtonType.Ok) { string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath, panel.NameFieldStringValue); Controller.SaveDialogCompleted (target_file_path); } else { Controller.SaveDialogCancelled (); } }); } }; }
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 }
public void UpdateChooser() { if (this.popup_button != null) this.popup_button.RemoveFromSuperview (); this.popup_button = new NSPopUpButton () { Frame = new RectangleF (480 - 156 - 8, 640 - 31 - 26, 156, 26), PullsDown = false }; this.popup_button.AddItem ("All Folders"); this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); this.popup_button.AddItems (SparkleShare.Controller.Folders.ToArray ()); this.popup_button.Activated += delegate { if (popup_button.IndexOfSelectedItem == 0) this.selected_log = null; else this.selected_log = this.popup_button.SelectedItem.Title; UpdateEvents (false); }; ContentView.AddSubview (this.popup_button); }