static void UpdateGroup(NativeToolbarGroup group, IList <ToolbarItem> toolbarItems, double itemWidth, double itemSpacing) { int count = toolbarItems.Count; group.Items.Clear(); if (count > 0) { var subItems = new NSToolbarItem[count]; var view = new NSView(); nfloat totalWidth = 0; var currentX = 0.0; for (int i = 0; i < toolbarItems.Count; i++) { var element = toolbarItems[i]; var item = new NSToolbarItem(element.Text); item.Activated += (sender, e) => (element as IMenuItemController).Activate(); var button = new NSButton(); button.Title = element.Text; button.SizeToFit(); var buttonWidth = itemWidth; if (button.FittingSize.Width > itemWidth) { buttonWidth = button.FittingSize.Width + 10; } button.Frame = new CGRect(currentX + i * itemSpacing, 0, buttonWidth, ToolbarItemHeight); currentX += buttonWidth; totalWidth += button.Frame.Width; button.Activated += (sender, e) => (element as IMenuItemController).Activate(); button.BezelStyle = NSBezelStyle.TexturedRounded; if (!string.IsNullOrEmpty(element.Icon)) { button.Image = new NSImage(element.Icon); } button.SizeToFit(); view.AddSubview(button); item.Label = item.PaletteLabel = item.ToolTip = button.ToolTip = element.Text; subItems[i] = item; group.Items.Add(new NativeToolbarGroup.Item { ToolbarItem = item, Button = button }); } view.Frame = new CGRect(0, 0, totalWidth + (itemSpacing * (count - 1)), ToolbarItemHeight); group.Group.Subitems = subItems; group.Group.View = view; } else { group.Group.Subitems = new NSToolbarItem[] { }; group.Group.View = new NSView(); } }
public bool validateToolbarItem(NSToolbarItem toolbarItem) { //Console.WriteLine("validateToolbarItem: " + toolbarItem.Identifier); switch (toolbarItem.Tag) { // new case 0: return(true); // open case 1: return(true); // save case 2: return(dbNeedsTobeSaved); // edit case 3: return(true); // copy password case 4: bool entryIsSelected = EntriesTableView.SelectedRowCount == 1; return(entryIsSelected); default: break; } return(true); }
// Creates a toolbar item for each preferences tab. This method is called by Cocoa framework. // Notice that tab name is used as identifier. This identifier is used in PreferencesWindowController // to find a correct view to be displayed when toolbar item has been activated (clicked). public override NSToolbarItem WillInsertItem(NSToolbar toolbar, string itemIdentifier, bool willBeInserted) { var tab = tabs.Single(s => s.Name.Equals(itemIdentifier)); var item = new NSToolbarItem(tab.Name) { Image = tab.Icon, Label = tab.Name}; item.Activated += HandleActivated; return item; }
public PlayingProgressMonitor (NSToolbarItem progressItem, NSTextField label) { ProgressItem = progressItem; Progress = (NSProgressIndicator) progressItem.View; Label = label; ProgressChanged += (o, e) => UpdateLabels (e); }
NSToolbarItem CreateSelectorToolbarItem() { var selector = new SelectorView(); viewCache.Add(selector); var item = new NSToolbarItem(SelectorId) { View = selector, MinSize = new CGSize(150, 25), MaxSize = new CGSize(150, 25), }; selector.ResizeRequested += (o, e) => { item.MinSize = item.MaxSize = e.Size; centeringSpace.UpdateWidth(); }; var pathSelector = (SelectorView.PathSelectorView)selector.Subviews [0]; pathSelector.ConfigurationChanged += (sender, e) => { if (ConfigurationChanged != null) { ConfigurationChanged(sender, e); } }; pathSelector.RuntimeChanged += (sender, ea) => { if (RuntimeChanged != null) { RuntimeChanged(sender, ea); } }; return(item); }
NSToolbarItem CreateButtonBarToolbarItem() { var bar = new ButtonBar(barItems); buttonBarCache.Add(bar); // Note: We're leaving a 1 dead pixel size here because Apple bug // on Yosemite. Segmented controls have 3px padding on left and right // on Mavericks. nfloat size = 6 + 33 * bar.SegmentCount; // By default, Cocoa doesn't want to duplicate items in the toolbar. // Use different Ids to prevent this and not have to subclass. var item = new NSToolbarItem(ButtonBarId + buttonBarCount) { View = bar, MinSize = new CGSize(size, bar.FittingSize.Height), MaxSize = new CGSize(size, bar.FittingSize.Height), }; bar.ResizeRequested += (o, e) => { nfloat resize = 6 + 33 * bar.SegmentCount; item.MinSize = new CGSize(resize, bar.FittingSize.Height); item.MaxSize = new CGSize(resize, bar.FittingSize.Height); centeringSpace.UpdateWidth(); }; return(item); }
NSToolbarItem CreateStatusBarToolbarItem() { var bar = new StatusBar(); viewCache.Add(bar); var item = new NSToolbarItem(StatusBarId) { View = bar, // Place some temporary values in there. MinSize = new CGSize(360, 22), MaxSize = new CGSize(360, 22), }; NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, notif => DispatchService.GuiDispatch(() => { // Skip updates with a null Window. Only crashes on Mavericks. // The View gets updated once again when the window resize finishes. if (bar.Window == null) { return; } double maxSize = Math.Round(bar.Window.Frame.Width * 0.30f); double minSize = Math.Round(bar.Window.Frame.Width * 0.25f); item.MinSize = new CGSize((nfloat)Math.Max(280, minSize), 22); item.MaxSize = new CGSize((nfloat)Math.Min(700, maxSize), 22); bar.RepositionStatusLayers(); })); return(item); }
public bool ValidateToolbarItem(NSToolbarItem item) { if (item.Identifier == "AddPath") { return (Window.Map != null); } return true; }
NSToolbarItem CreateSearchBarToolbarItem() { var bar = new SearchBar(); // Remove the focus from the Gtk system when Cocoa has focus // Fixes BXC #29601 bar.GainedFocus += (o, e) => IdeApp.Workbench.RootWindow.Focus = null; viewCache.Add(bar); var menuBar = new SearchBar { Frame = new CGRect(0, 0, 180, bar.FittingSize.Height), }; var item = new NSToolbarItem(SearchBarId) { View = bar, MenuFormRepresentation = new NSMenuItem { View = menuBar, }, MinSize = new CGSize(180, bar.FittingSize.Height), MaxSize = new CGSize(270, bar.FittingSize.Height), }; AttachToolbarEvents(bar); return(item); }
public override NSToolbarItem WillInsertItem(NSToolbar toolbar, string itemIdentifier, bool willBeInserted) { var toolBarItem = new NSToolbarItem (itemIdentifier) {Label = itemIdentifier, ToolTip = itemIdentifier, PaletteLabel = itemIdentifier, Image = NSImage.ImageNamed ("hand_32x32.png")}; toolBarItemList.Add (toolBarItem); toolBarItem.Activated += Item_Activated; return toolBarItem; }
// Creates a toolbar item for each preferences tab. This method is called by Cocoa framework. // Notice that tab name is used as identifier. This identifier is used in PreferencesWindowController // to find a correct view to be displayed when toolbar item has been activated (clicked). public override NSToolbarItem WillInsertItem(NSToolbar toolbar, string itemIdentifier, bool willBeInserted) { var tab = tabs.Single(s => s.Name.Equals(itemIdentifier)); var item = new NSToolbarItem(tab.Name) { Image = tab.Icon, Label = tab.Name }; item.Activated += HandleActivated; return(item); }
void UpdateGroup(NativeToolbarGroup group, IList <ToolbarItem> toolbarItems) { int count = toolbarItems.Count; group.Items.Clear(); if (count > 0) { var subItems = new NSToolbarItem[count]; var view = new NSView(); for (int i = 0; i < toolbarItems.Count; i++) { var element = toolbarItems[i]; var item = new NSToolbarItem(element.Text ?? ""); item.Activated += (sender, e) => ((IMenuItemController)element).Activate(); var button = new NSButton(); // Padding for toolbar items with icon only is 9=44-25 (ToolbarItemWidth-ToolbarItemHeight) // 10 added here to match this padding for long items button.Activated += (sender, e) => ((IMenuItemController)element).Activate(); button.BezelStyle = NSBezelStyle.TexturedRounded; UpdateButtonContent(button, element, group); button.Enabled = item.Enabled = element.IsEnabled; element.PropertyChanged -= ToolBarItemPropertyChanged; element.PropertyChanged += ToolBarItemPropertyChanged; view.AddSubview(button); //item.Label = item.PaletteLabel = item.ToolTip = element.Text ?? ""; subItems[i] = item; SetAccessibility(button, element); group.Items.Add(new NativeToolbarGroup.Item { ToolbarItem = item, Button = button, Element = element }); } group.Group.Subitems = subItems; group.Group.View = view; UpdateGroupWidth(group); } else { group.Group.Subitems = new NSToolbarItem[] { }; group.Group.View = new NSView(); } }
public void InitTests() { const string TestLabel = "NSToolbarItemTests.Label"; NSToolbarItem item = new NSToolbarItem(); Assert.IsNotNull(item.Handle, "NSToolbarItem has handle"); item.Label = TestLabel; Assert.AreEqual(item.Label, TestLabel, "NSToolbarItem has non null Label"); NSToolbarItemGroup group = new NSToolbarItemGroup(); Assert.IsNotNull(group.Handle, "NSToolbarItemGroup has handle"); Assert.AreEqual(group.Subitems.Length, 0, "NSToolbarItemGroup has zero items"); group.Label = TestLabel; Assert.AreEqual(group.Label, TestLabel, "NSToolbarItemGroup has non null Label"); }
void PlayPauseButton (NSToolbarItem playPauseItem, NSButton playPauseButton) { const string resume = "Resume"; const string pause = "Pause"; playQueue.Paused += () => playPauseItem.Label = resume; playQueue.Stopped += () => playPauseItem.Label = pause; playQueue.Playing += () => playPauseItem.Label = pause; playQueue.Playing += () => playPauseItem.Enabled = true; playQueue.Stopped += () => playPauseButton.Enabled = false; playPauseItem.Label = pause; playPauseButton.Activated += (o, e) => { playQueue.IsPaused = !playQueue.IsPaused; }; }
static bool ValidateSystemToolbarAction(IntPtr sender, IntPtr sel, IntPtr item) { var toolbarItem = new NSToolbarItem(item); var control = Runtime.GetNSObject(sender); var handler = (MacView <T, W>)((IMacControl)control).Handler; BaseAction action; if (handler.systemActions != null && toolbarItem.Action != null && handler.systemActions.TryGetValue(toolbarItem.Action.Name, out action)) { if (action != null) { return(action.Enabled); } } return(false); }
NSToolbarItem CreateSearchBarToolbarItem() { var bar = new SearchBar(); var menuBar = new SearchBar { Frame = new CGRect(0, 0, 180, bar.FittingSize.Height), }; var item = new NSToolbarItem(SearchBarId) { View = bar, MenuFormRepresentation = new NSMenuItem { View = menuBar, }, MinSize = new CGSize(180, bar.FittingSize.Height), MaxSize = new CGSize(270, bar.FittingSize.Height), }; AttachToolbarEvents(bar); return(item); }
NSToolbarItem CreateButtonBarToolbarItem() { var bar = new ButtonBar(barItems); // By default, Cocoa doesn't want to duplicate items in the toolbar. // Use different Ids to prevent this and not have to subclass. var item = new NSToolbarItem(ButtonBarId + buttonBarCount) { View = bar, MinSize = new CGSize(bar.SegmentCount * 40, bar.FittingSize.Height), MaxSize = new CGSize(bar.SegmentCount * 40, bar.FittingSize.Height), }; bar.ResizeRequested += (o, e) => { item.MinSize = new CGSize(bar.SegmentCount * 40, bar.FittingSize.Height); item.MaxSize = new CGSize(bar.SegmentCount * 40, bar.FittingSize.Height); centeringSpace.UpdateWidth(); }; return(item); }
NSToolbarItem CreateStatusBarToolbarItem() { var bar = new StatusBar(); var item = new NSToolbarItem(StatusBarId) { View = bar, // Place some temporary values in there. MinSize = new CGSize(360, 22), MaxSize = new CGSize(360, 22), }; NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, notif => { double size = Math.Round(bar.Window.Frame.Width * 0.25f); item.MinSize = new CGSize((nfloat)Math.Max(300, size), 22); item.MaxSize = new CGSize((nfloat)Math.Min(600, size), 22); bar.RepositionStatusLayers(); }); return(item); }
NSToolbarItem CreateRunToolbarItem() { var button = new RunButton(); button.Activated += (o, e) => { if (RunButtonClicked != null) { RunButtonClicked(o, e); } }; var item = new NSToolbarItem(RunButtonId) { View = button, MinSize = new CGSize(button.FittingSize.Width + 12, button.FittingSize.Height), MaxSize = new CGSize(button.FittingSize.Width + 12, button.FittingSize.Height), }; return(item); }
static bool ValidateSystemToolbarAction(IntPtr sender, IntPtr sel, IntPtr item) { var toolbarItem = new NSToolbarItem(item); var control = Runtime.GetNSObject(sender); var handler = GetHandler(control) as MacView <TControl, TWidget>; if (handler != null) { Command command; if (handler.systemActions != null && toolbarItem.Action != null && handler.systemActions.TryGetValue(toolbarItem.Action.Handle, out command)) { if (command != null) { return(command.Enabled); } } } return(false); }
void UpdateTitle() { if (_toolbar == null || _navigation == null || _titleGroup == null) { return; } var title = GetCurrentPageTitle(); var item = new NSToolbarItem(title); var view = new NSView(); var titleField = new NSTextField { AllowsEditingTextAttributes = true, Bordered = false, DrawsBackground = false, Bezeled = false, Editable = false, Selectable = false, Cell = new VerticallyCenteredTextFieldCell(0f, NSFont.TitleBarFontOfSize(18)), StringValue = title }; titleField.Cell.TextColor = GetTitleColor(); titleField.SizeToFit(); _titleGroup.Group.MinSize = new CGSize(NavigationTitleMinSize, ToolbarHeight); _titleGroup.Group.Subitems = new NSToolbarItem[] { item }; view.AddSubview(titleField); _titleGroup.Group.View = view; //save a reference so we can paint this for the background _nsToolbarItemViewer = _titleGroup.Group.View.Superview; if (_nsToolbarItemViewer == null) { return; } //position is hard .. we manually set the title to be centered var totalWidth = _nsToolbarItemViewer.Superview.Frame.Width; var fieldWidth = titleField.Frame.Width; var x = ((totalWidth - fieldWidth) / 2) - _nsToolbarItemViewer.Frame.X; titleField.Frame = new CGRect(x, 0, fieldWidth, ToolbarHeight); }
private void UpdateItems(bool animated) { if (((NSToolbar)this.Control).Items != null) { for (int index = 0; index < ((NSToolbar)this.Control).Items.Length; ++index) { ((NSToolbar)this.Control).Items [index].Dispose(); } } NSToolbarItem[] items = new NSToolbarItem[((Toolbar)this.Element).Items.Count]; for (int index = 0; index < ((Toolbar)this.Element).Items.Count; ++index) { items [index] = ToolbarItemExtensions.ToNSToolbarItem(((Toolbar)this.Element).Items [index], false); } foreach (var item in items) { ((NSToolbar)this.Control).InsertItem(item, 0); } //((NSToolbar)this.Control).SetItems (items, animated); }
/// <summary> /// Adds an item to a toolbar. /// </summary> /// <param name="toolbar">The <see cref=">NSToolbar"/> to which an item is to be added.</param> /// <param name="toolbarItem">The <see cref="NSToolbarItem"/> to be added to the toolbar.</param> /// <param name="itemIdentifier">The item's unique identifier.</param> /// <param name="insertLocation">The location in the toolbar at which the item is to be inserted.</param> public static void AddToolbarItem(this NSToolbar toolbar, NSToolbarItem toolbarItem, string itemIdentifier, int insertLocation) { if (toolbar.DefaultItemIdentifiers == null) { toolbar.DefaultItemIdentifiers = NSToolbarIdentifiers; } if (toolbar.AllowedItemIdentifiers == null) { toolbar.AllowedItemIdentifiers = NSToolbarIdentifiers; } if (toolbar.SelectableItemIdentifiers == null) { // HACK WORKAROUND for bug https://bugzilla.xamarin.com/show_bug.cgi?id=21680 toolbar.SelectableItemIdentifiers = BugWorkaround; } var prevWillAdd = toolbar.WillInsertItem; toolbar.WillInsertItem = (t, i, b) => toolbarItem; toolbar.InsertItem(itemIdentifier, insertLocation); toolbar.WillInsertItem = prevWillAdd; }
void TabBtnClick(NSToolbarItem item) { Toolbar.SelectedItemIdentifier = item.Identifier; switch (item.Identifier) { case "Server": ContentView = serverViewController.View; ChangeHeight(221); break; case "Discovery": ContentView = discoveryViewController.View; ChangeHeight(246); break; case "Notifications": ContentView = notificationsViewController.View; ChangeHeight(74); break; } }
protected override void OnElementChanged(ElementChangedEventArgs <Editor> e) { this.OnElementChanged(e); if (this.Control == null) { this.SetNativeControl(new NSTextView(CGRect.Empty)); if (Device.Idiom == TargetIdiom.Phone) { accessoryView = new NSToolbar(this.ToString()); //accessoryView = new NSToolbar (new CGRect ((nfloat)0, (nfloat)0, NSScreen.MainScreen.Frame.Width, (nfloat)44)); //uiToolbar.BarStyle = UIBarStyle.Default; //int num = 1; //uiToolbar.Translucent = num != 0; var toolBarItem = new NSToolbarItem(""); toolBarItem.Activated += (sender, ev) => { this.Control.ResignFirstResponder(); this.Element.SendCompleted(); }; accessoryView.Items.Append(toolBarItem); // TODO: //this.Control.InputAccessoryView = accessoryView; } this.Control.TextDidChange += HandleChanged; this.Control.TextDidBeginEditing += OnStarted; this.Control.TextDidEndEditing += OnEnded; } if (e.NewElement == null) { return; } this.UpdateText(); this.UpdateFont(); this.UpdateTextColor(); //this.UpdateKeyboard (); this.UpdateEditable(); }
NSToolbarItem CreateStatusBarToolbarItem() { var bar = new StatusBar(); viewCache.Add(bar); var item = new NSToolbarItem(StatusBarId) { View = bar, // Place some temporary values in there. MinSize = new CGSize(360, 22), MaxSize = new CGSize(360, 22), }; Action <NSNotification> resizeAction = notif => DispatchService.GuiDispatch(() => { // Skip updates with a null Window. Only crashes on Mavericks. // The View gets updated once again when the window resize finishes. if (bar.Window == null) { return; } // We're getting notified about all windows in the application (for example, NSPopovers) that change size when really we only care about // the window the bar is in. if (notif.Object != bar.Window) { return; } double maxSize = Math.Round(bar.Window.Frame.Width * 0.30f); double minSize = Math.Round(bar.Window.Frame.Width * 0.25f); item.MinSize = new CGSize((nfloat)Math.Max(220, minSize), 22); item.MaxSize = new CGSize((nfloat)Math.Min(700, maxSize), 22); bar.RepositionStatusLayers(); }); NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, resizeAction); NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidEndLiveResizeNotification, resizeAction); return(item); }
void SetToolbarItemVisibility(NSToolbarItem item, bool value) { var currentIndex = mainToolbar.Items.IndexOf(x => x == item); if (value == currentIndex.HasValue) { return; } if (value) { var placeToInsert = mainToolbar.Items.IndexOf(x => x == shareToolbarItem); if (placeToInsert == null) { throw new InvalidOperationException("cannot modifty toolbar"); } mainToolbar.InsertItem(item.Identifier, placeToInsert.GetValueOrDefault()); } else { mainToolbar.RemoveItem(currentIndex.Value); } }
/// <summary> /// Mac-specific implementation /// </summary> /// <param name="pageName">Page name.</param> /// <param name="icon">The icon for the page.</param> /// <param name="page">Platform-specific page visual data.</param> partial void AddTab(string pageName, string icon, object page) { var pageController = page as NSViewController; PageControllers.Add(pageController); var tabViewItem = new NSTabViewItem(); tabViewItem.Label = pageName; tabViewItem.View = pageController.View; PropertyPages.Add(tabViewItem); NSToolbarItem item = null; if (!string.IsNullOrEmpty(icon)) { if (Toolbar.Items.Length < PropertyPages.Count) { var pageAsDependencyObject = page as IFakeDependencyObject; var id = pageAsDependencyObject.DataContext.GetType().FullName; item = new NSToolbarItem(id); item.Label = pageName.TrimEnd(new char[] { '.' }); item.Image = page.GetType().LoadImageResource(icon); var size = new CGSize(item.Image.Size.Width * 2, item.Image.Size.Height); item.MinSize = size; item.MaxSize = size; Toolbar.AddToolbarItem(item, id, Toolbar.Items.Length); } else { item = Toolbar.Items[PropertyPages.Count - 1]; } } else { item = Toolbar.Items[PropertyPages.Count - 1]; } SelectableItemIdentifiers.Add(item.Identifier); item.Activated += SettingsPageSelected; }
void UpdateTitle() { if (_toolbar == null || _navigation == null || _titleGroup == null) { return; } var title = GetCurrentPageTitle(); var item = new NSToolbarItem(title); var view = new NSView(); var titleField = new NSTextField { AllowsEditingTextAttributes = true, Bordered = false, DrawsBackground = false, Bezeled = false, Editable = false, Selectable = false, Cell = new VerticallyCenteredTextFieldCell(0f, NSFont.TitleBarFontOfSize(18)), StringValue = title }; titleField.Cell.TextColor = GetTitleColor(); titleField.SizeToFit(); _titleGroup.Group.MinSize = new CGSize(NavigationTitleMinSize, ToolbarHeight); _titleGroup.Group.Subitems = new NSToolbarItem[] { item }; view.AddSubview(titleField); titleField.CenterXAnchor.ConstraintEqualToAnchor(view.CenterXAnchor).Active = true; titleField.CenterYAnchor.ConstraintEqualToAnchor(view.CenterYAnchor).Active = true; titleField.TranslatesAutoresizingMaskIntoConstraints = false; view.TranslatesAutoresizingMaskIntoConstraints = false; _titleGroup.Group.View = view; //save a reference so we can paint this for the background _nsToolbarItemViewer = _titleGroup.Group.View.Superview; }
public id InitWithToolbarItem(NSToolbarItem toolbarItem) { id self = null; // Frame will be reset by the layout method //self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY, ItemBackViewDefaultWidth, ItemBackViewDefaultHeight)]; if (self != null) { _toolbarItem = toolbarItem; //this.TIt //[self setTitle: @""]; //[self setEnabled: NO]; //[_cell setBezeled: YES]; //[self setImagePosition: NSImageAbove]; //[self setHighlightsBy: // NSChangeGrayCellMask | NSChangeBackgroundCellMask]; //[self setFont: NormalFont]; } return self; }
NSToolbarItem CreateSelectorToolbarItem () { var selector = new SelectorView (); viewCache.Add (selector); var item = new NSToolbarItem (SelectorId) { View = selector, MinSize = new CGSize (150, 25), MaxSize = new CGSize (150, 25), }; selector.ResizeRequested += (o, e) => { item.MinSize = item.MaxSize = e.Size; centeringSpace.UpdateWidth (); }; selector.OverflowInfoRequested += (o, e) => { FillOverflowInfo (e); }; IDisposable resizeTimer = null; NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillStartLiveResizeNotification, notif => DispatchService.GuiDispatch (() => { if (!IsCorrectNotification (selector, notif.Object)) return; if (resizeTimer != null) resizeTimer.Dispose (); resizeTimer = Application.TimeoutInvoke (100, () => { if (widget.Items.Length != widget.VisibleItems.Length) selector.RequestResize (); return true; }); })); NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notif => DispatchService.GuiDispatch (() => { if (!IsCorrectNotification (selector, notif.Object)) return; // Don't check difference in overflow menus. This could cause issues since we're doing resizing of widgets and the views might go in front // or behind while we're doing the resize request. selector.RequestResize (); })); NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, notif => DispatchService.GuiDispatch (() => { if (!IsCorrectNotification (selector, notif.Object)) return; if (resizeTimer != null) resizeTimer.Dispose (); resizeTimer = Application.TimeoutInvoke (300, selector.RequestResize); })); var pathSelector = (SelectorView.PathSelectorView)selector.Subviews [0]; pathSelector.ConfigurationChanged += (sender, e) => { if (ConfigurationChanged != null) ConfigurationChanged (sender, e); }; pathSelector.RuntimeChanged += (sender, ea) => { if (RuntimeChanged != null) RuntimeChanged (sender, ea); }; return item; }
NSToolbarItem CreateButtonBarToolbarItem () { var bar = new ButtonBar (barItems); buttonBarCache.Add (bar); // Note: We're leaving a 1 dead pixel size here because Apple bug // on Yosemite. Segmented controls have 3px padding on left and right // on Mavericks. nfloat size = 6 + 33 * bar.SegmentCount; // By default, Cocoa doesn't want to duplicate items in the toolbar. // Use different Ids to prevent this and not have to subclass. var item = new NSToolbarItem (ButtonBarId + buttonBarCount) { View = bar, MinSize = new CGSize (size, bar.FittingSize.Height), MaxSize = new CGSize (size, bar.FittingSize.Height), }; bar.ResizeRequested += (o, e) => { nfloat resize = 6 + 33 * bar.SegmentCount; item.MinSize = new CGSize (resize, bar.FittingSize.Height); item.MaxSize = new CGSize (resize, bar.FittingSize.Height); selector.RequestResize (); centeringSpace.UpdateWidth (); }; return item; }
public bool ValidateToolbarItem(NSToolbarItem theItem) { // You could check [theItem itemIdentifier] here and take appropriate action if you wanted to return true; }
private static void AddToolbarItem(NSMutableDictionary theDict, NSString identifier, NSString label, NSString paletteLabel, NSString toolTip, Id target, IntPtr settingSelector, Id itemContent, IntPtr action, NSMenu menu) { NSMenuItem mItem; // here we create the NSToolbarItem and setup its attributes in line with the parameters NSToolbarItem item = new NSToolbarItem(identifier); item.Autorelease(); item.Label = label; item.PaletteLabel = paletteLabel; item.ToolTip = toolTip; // the settingSelector parameter can either be @selector(setView:) or @selector(setImage:). Pass in the right // one depending upon whether your NSToolbarItem will have a custom view or an image, respectively // (in the itemContent parameter). Then this next line will do the right thing automatically. item.PerformSelectorWithObject(settingSelector, itemContent); item.Target = target; item.Action = action; // If this NSToolbarItem is supposed to have a menu "form representation" associated with it (for text-only mode), // we set it up here. Actually, you have to hand an NSMenuItem (not a complete NSMenu) to the toolbar item, // so we create a dummy NSMenuItem that has our real menu as a submenu. if (menu != null) { // we actually need an NSMenuItem here, so we construct one mItem = new NSMenuItem(); mItem.Autorelease(); mItem.Submenu = menu; mItem.Title = menu.Title; item.MenuFormRepresentation = mItem; } // Now that we've setup all the settings for this new toolbar item, we add it to the dictionary. // The dictionary retains the toolbar item for us, which is why we could autorelease it when we created // it (above). theDict[identifier] = item; }
NSToolbarItem CreateRunToolbarItem () { var button = new RunButton (); viewCache.Add (button); button.Activated += (o, e) => { if (RunButtonClicked != null) RunButtonClicked (o, e); }; var item = new NSToolbarItem (RunButtonId) { View = button, MinSize = new CGSize (button.FittingSize.Width + 12, button.FittingSize.Height), MaxSize = new CGSize (button.FittingSize.Width + 12, button.FittingSize.Height), }; return item; }
public NSToolbarItem ToolbarItemForItemIdentifierWillBeInsertedIntoToolbar(NSToolbar toolbar, NSString itemIdentifier, bool flag) { // We create and autorelease a new NSToolbarItem, and then go through the process of setting up its // attributes from the master toolbar item matching that identifier in our dictionary of items. NSToolbarItem newItem = new NSToolbarItem(itemIdentifier); newItem.Autorelease(); NSToolbarItem item = this.toolbarItems[itemIdentifier].CastTo<NSToolbarItem>(); newItem.Label = item.Label; newItem.PaletteLabel = item.PaletteLabel; if (item.View != null) { newItem.View = item.View; } else { newItem.Image = item.Image; } newItem.ToolTip = item.ToolTip; newItem.Target = item.Target; newItem.Action = item.Action; newItem.MenuFormRepresentation = item.MenuFormRepresentation; // If we have a custom view, we *have* to set the min/max size - otherwise, it'll default to 0,0 and the custom // view won't show up at all! This doesn't affect toolbar items with images, however. if (newItem.View != null) { newItem.MinSize = item.View.Bounds.size; newItem.MaxSize = item.View.Bounds.size; } return newItem; }
public bool ValidateToolbarItem(NSToolbarItem item) { return item.Tag != this.currentViewTag; }
partial void AddText(NSToolbarItem sender) { imageCanvas.AddTextField(); }
NSToolbarItem CreateSearchBarToolbarItem () { var bar = new SearchBar (); // Remove the focus from the Gtk system when Cocoa has focus // Fixes BXC #29601 bar.GainedFocus += (o, e) => IdeApp.Workbench.RootWindow.Focus = null; viewCache.Add (bar); var item = new NSToolbarItem (SearchBarId) { View = bar, MinSize = new CGSize (150, bar.FittingSize.Height), MaxSize = new CGSize (270, bar.FittingSize.Height), }; AttachToolbarEvents (bar); return item; }
public bool ValidateToolbarItem(NSToolbarItem item) { return(Handler.Enabled); }
public virtual bool ValidateToolbarItem(NSToolbarItem theItem) { return true; }
public virtual NSToolbarItem ToolbarItemForItemIdentifierWillBeInsertedIntoToolbar(NSToolbar toolbar, NSString itemIdentifier, bool flag) { NSToolbarItem item = new NSToolbarItem(itemIdentifier); if (itemIdentifier.IsEqualToString(TOOLBAR_ITEM1)) { item.Image = NSImage.ImageNamed(NSImage.NSImageNameAdvanced); item.Label = "Toolbar Item 1"; item.Target = this; item.Action = ObjectiveCRuntime.Selector("doSomething1:"); } if (itemIdentifier.IsEqualToString(TOOLBAR_ITEM2)) { item.Image = NSImage.ImageNamed(NSImage.NSImageNameEveryone); item.Label = "Toolbar Item 2"; item.Target = this; item.Action = ObjectiveCRuntime.Selector("doSomething2:"); } if (itemIdentifier.IsEqualToString(TOOLBAR_ITEM3)) { item.Image = NSImage.ImageNamed(NSImage.NSImageNameDotMac); item.Label = "Toolbar Item 3"; item.Target = this; item.Action = ObjectiveCRuntime.Selector("doSomething3:"); } item.PaletteLabel = item.Label; return item; }
partial void SaveCheats(NSToolbarItem sender) { Controller.SaveCheats(this.Window); }
partial void LoadCheats(NSToolbarItem sender) { Controller.LoadCheats(this.Window); }
NSToolbarItem CreateSearchBarToolbarItem () { var bar = new SearchBar (); viewCache.Add (bar); var menuBar = new SearchBar { Frame = new CGRect (0, 0, 180, bar.FittingSize.Height), }; var item = new NSToolbarItem (SearchBarId) { View = bar, MenuFormRepresentation = new NSMenuItem { View = menuBar, }, MinSize = new CGSize (180, bar.FittingSize.Height), MaxSize = new CGSize (270, bar.FittingSize.Height), }; AttachToolbarEvents (bar); return item; }
NSToolbarItem CreateStatusBarToolbarItem () { var bar = new StatusBar (); viewCache.Add (bar); var item = new NSToolbarItem (StatusBarId) { View = bar, // Place some temporary values in there. MinSize = new CGSize (360, 22), MaxSize = new CGSize (360, 22), }; Action<NSNotification> resizeAction = notif => DispatchService.GuiDispatch (() => { // Skip updates with a null Window. Only crashes on Mavericks. // The View gets updated once again when the window resize finishes. if (bar.Window == null) return; // We're getting notified about all windows in the application (for example, NSPopovers) that change size when really we only care about // the window the bar is in. if (notif.Object != bar.Window) return; double maxSize = Math.Round (bar.Window.Frame.Width * 0.30f); double minSize = Math.Round (bar.Window.Frame.Width * 0.25f); item.MinSize = new CGSize ((nfloat)Math.Max (220, minSize), 22); item.MaxSize = new CGSize ((nfloat)Math.Min (700, maxSize), 22); bar.RepositionStatusLayers (); }); NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, resizeAction); NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, resizeAction); return item; }
NSToolbarItem CreateStatusBarToolbarItem () { var bar = new StatusBar (); viewCache.Add (bar); var item = new NSToolbarItem (StatusBarId) { View = bar, // Place some temporary values in there. MinSize = new CGSize (360, 22), MaxSize = new CGSize (360, 22), }; NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notif => DispatchService.GuiDispatch (() => { // Skip updates with a null Window. Only crashes on Mavericks. // The View gets updated once again when the window resize finishes. if (bar.Window == null) return; double maxSize = Math.Round (bar.Window.Frame.Width * 0.30f); double minSize = Math.Round (bar.Window.Frame.Width * 0.25f); item.MinSize = new CGSize ((nfloat)Math.Max (280, minSize), 22); item.MaxSize = new CGSize ((nfloat)Math.Min (700, maxSize), 22); bar.RepositionStatusLayers (); })); return item; }
partial void RemoveCheat(NSToolbarItem sender) { Controller.DeleteCheat(this.Window); }
partial void EditCheat(NSToolbarItem sender) { Controller.EditCheat(this.Window); }
NSToolbarItem CreateSelectorToolbarItem () { var selector = new SelectorView (); viewCache.Add (selector); var item = new NSToolbarItem (SelectorId) { View = selector, MinSize = new CGSize (150, 25), MaxSize = new CGSize (150, 25), }; selector.ResizeRequested += (o, e) => { item.MinSize = item.MaxSize = e.Size; centeringSpace.UpdateWidth (); }; var pathSelector = (SelectorView.PathSelectorView)selector.Subviews [0]; pathSelector.ConfigurationChanged += (sender, e) => { if (ConfigurationChanged != null) ConfigurationChanged (sender, e); }; pathSelector.RuntimeChanged += (sender, ea) => { if (RuntimeChanged != null) RuntimeChanged (sender, ea); }; return item; }
private NSToolbarItem ToolbarItemWithIdentifier( string identifier, string label, string paletteLabel, string toolTip, NSObject target, object imageOrView, Selector action, NSMenu menu) { NSToolbarItem item = new NSToolbarItem(identifier); item.Label = label; item.PaletteLabel = paletteLabel; item.ToolTip = toolTip; item.Target = target; item.Action = action; if (imageOrView is NSImage) { item.Image = (NSImage)imageOrView; } else if (imageOrView is NSView) { item.View = (NSView)imageOrView; } else // Invalid content Debug.Assert(false); if (menu != null) { // Create a sub-menu for the menu form representation. // What, you never clicked on the chevrons you see when you shrink the toolbar width? NSMenuItem menuItem = new NSMenuItem(label); menuItem.Submenu = menu; item.MenuFormRepresentation = menuItem; } return item; }