public OptionEnumeratedMonobjc(NSRect aRect, Option aOption) : base(aOption) { iPopUpButton = new NSPopUpButton(); iPopUpButton.SizeToFit(); iPopUpButton.Frame = new NSRect(aRect.MinX, aRect.MinY - iPopUpButton.Frame.Height, aRect.Width, iPopUpButton.Frame.Height); OptionAllowedChanged(this, EventArgs.Empty); iPopUpButton.ActionEvent += ActionEvent; }
void CreateFilters(FileFilter [] filters) { if (filters.Any()) { var label = new NSTextField(); var fileTypes = new NSPopUpButton(); fileTypes.AddItems(filters.Select(f => f.Label).ToArray()); var fileTypeView = new NSView(); fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; const int padding = 15; label.StringValue = "Show Files"; label.DrawsBackground = false; label.Bordered = false; label.Bezeled = false; label.Editable = false; label.Selectable = false; label.SizeToFit(); fileTypeView.AddSubview(label); fileTypes.SizeToFit(); fileTypes.Activated += (sender, e) => { var currentFilter = filters.FirstOrDefault(f => f.Label == fileTypes.TitleOfSelectedItem); SetCurrentItem(currentFilter); // THIS DOES NOT WORK ON MAC OS FROM MAVERICS TO YOSEMITE // There exists hacks, however they are dependent on OS X version // I have filed bug as many others, but I guess this will never be fixed _panel.ValidateVisibleColumns(); _panel.Update(); }; fileTypeView.AddSubview(fileTypes); fileTypes.SetFrameOrigin(new CGPoint(label.Frame.Width + 10, padding)); label.SetFrameOrigin(new CGPoint(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2)); fileTypeView.Frame = new CGRect(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2); _panel.AccessoryView = fileTypeView; if (filters.Any()) { SetCurrentItem(filters.First()); } } else { _panel.AccessoryView = null; } }
void Create() { if (Control.AccessoryView != null) { return; } var fileTypeView = new NSView(); fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; const int padding = 15; if (Widget.Filters.Count > 0) { var label = new NSTextField(); label.StringValue = "Format"; label.DrawsBackground = false; label.Bordered = false; label.Bezeled = false; label.Editable = false; label.Selectable = false; label.SizeToFit(); fileTypeView.AddSubview(label); fileTypes.SizeToFit(); fileTypes.Activated += (sender, e) => { SetCurrentItem(); Control.ValidateVisibleColumns(); Control.Update(); }; fileTypeView.AddSubview(fileTypes); fileTypes.SetFrameOrigin(new CGPoint((nfloat)label.Frame.Width + 10, padding)); label.SetFrameOrigin(new CGPoint(0, (nfloat)(padding + (fileTypes.Frame.Height - label.Frame.Height) / 2))); fileTypeView.Frame = new CGRect(0, 0, (nfloat)(fileTypes.Frame.Width + label.Frame.Width + 10), (nfloat)(fileTypes.Frame.Height + padding * 2)); Control.AccessoryView = fileTypeView; SetCurrentItem(); } else { Control.AccessoryView = null; } }
void Create() { if (Control.AccessoryView != null) { return; } var fileTypeView = new NSView(); fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; int padding = 15; if (macfilters != null && macfilters.Count > 0) { var label = new NSTextField(); label.StringValue = "Format"; label.DrawsBackground = false; label.Bordered = false; label.Bezeled = false; label.Editable = false; label.Selectable = false; label.SizeToFit(); fileTypeView.AddSubview(label); fileTypes.SizeToFit(); fileTypes.Activated += (sender, e) => { SetFilters(); Control.ValidateVisibleColumns(); // SetFilters (); Control.Update(); }; fileTypeView.AddSubview(fileTypes); fileTypes.SetFrameOrigin(new System.Drawing.PointF(label.Frame.Width + 10, padding)); label.SetFrameOrigin(new System.Drawing.PointF(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2)); fileTypeView.Frame = new System.Drawing.RectangleF(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2); Control.AccessoryView = fileTypeView; } else { Control.AccessoryView = null; } }
private static NSPopUpButton CreateFileFilterPopup(IList <FileChooserFilter> filters, NSSavePanel panel) { //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); } NSPopUpButton popup = new NSPopUpButton(new RectangleF(0, 6, 200, 18), false); popup.SizeToFit(); RectangleF rect = popup.Frame; popup.Frame = new RectangleF(rect.X, rect.Y, 200, rect.Height); foreach (var filter in filters) { popup.AddItem(filter.Name); } panel.ShouldEnableUrl = GetFileFilter(filters [0]); popup.Activated += delegate { panel.ShouldEnableUrl = GetFileFilter(filters [popup.IndexOfSelectedItem]); panel.Display(); }; return(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 CGRect (0, 6, 200, 18), false); popup.SizeToFit (); var rect = popup.Frame; popup.Frame = new CGRect (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[(int)popup.IndexOfSelectedItem]); panel.Display (); }; return popup; }