public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { NSCustomTouchBarItem item = new NSCustomTouchBarItem(identifier); switch (ParseId(identifier)) { case 0: { item.View = NSButton.CreateButton("1️⃣ Button", () => Console.WriteLine("Button")); return(item); } case 1: { item.View = NSSegmentedControl.FromLabels(new string [] { "Label1", "Label2" }, NSSegmentSwitchTracking.SelectAny, () => Console.WriteLine("Seg Label")); return(item); } case 2: { item.View = new NSImageView() { Image = NSImage.ImageNamed(NSImageName.TouchBarGetInfoTemplate), }; return(item); } case 3: { item.View = NSSegmentedControl.FromImages( new NSImage [] { NSImage.ImageNamed(NSImageName.TouchBarVolumeDownTemplate), NSImage.ImageNamed(NSImageName.TouchBarVolumeUpTemplate) }, NSSegmentSwitchTracking.SelectAny, () => Console.WriteLine("Seg Images")); return(item); } case 4: { item.View = NSSlider.FromValue(5, 0, 10, () => Console.WriteLine("Slider")); return(item); } } return(null); }
private void Initialize(PropertyViewModel propertyViewModel) { this.ShowPreview = true; TranslatesAutoresizingMaskIntoConstraints = false; var FrameWidthThird = Frame.Width / 3; var FrameWidthHalf = Frame.Width / 2; var FrameHeightHalf = Frame.Height / 2; NSControlSize controlSize = NSControlSize.Small; this.searchResources = new NSSearchField { ControlSize = controlSize, Font = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)), PlaceholderString = Properties.Resources.SearchResourcesTitle, TranslatesAutoresizingMaskIntoConstraints = false, }; this.searchResources.Changed += OnSearchResourcesChanged; AddSubview(this.searchResources); var vmType = propertyViewModel.GetType(); var valuePropertyInfo = vmType.GetProperty("Value"); var resourceValue = valuePropertyInfo.GetValue(propertyViewModel); this.resourceSelectorPanel = new RequestResourcePanel(HostResources, new ResourceSelectorViewModel(propertyViewModel.TargetPlatform.ResourceProvider, propertyViewModel.Editors.Select(ed => ed.Target), propertyViewModel.Property), resourceValue); this.resourceSelectorPanel.ResourceSelected += (sender, e) => { propertyViewModel.Resource = this.resourceSelectorPanel.SelectedResource; }; this.resourceSelectorPanel.DoubleClicked += (sender, e) => { PopOver.Close(); }; AddSubview(this.resourceSelectorPanel); segmentedControl = NSSegmentedControl.FromLabels(new string[] { Properties.Resources.AllResources, Properties.Resources.Local, Properties.Resources.Shared }, NSSegmentSwitchTracking.SelectOne, () => { //Switch Resource Types switch (this.segmentedControl.SelectedSegment) { case 0: this.resourceSelectorPanel.ViewModel.ShowBothResourceTypes = true; this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16"), 2); break; case 1: this.resourceSelectorPanel.ViewModel.ShowOnlyLocalResources = true; this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16"), 2); break; case 2: this.resourceSelectorPanel.ViewModel.ShowOnlySystemResources = true; this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16~sel"), 2); break; } this.resourceSelectorPanel.ReloadData(); }); this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16"), 2); this.segmentedControl.Frame = new CGRect((FrameWidthThird - (segmentedControl.Bounds.Width) / 2), 5, (Frame.Width - (FrameWidthThird)) - 10, 24); this.segmentedControl.Font = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)); this.segmentedControl.TranslatesAutoresizingMaskIntoConstraints = false; this.segmentedControl.SetSelected(true, 0); this.resourceSelectorPanel.ViewModel.ShowBothResourceTypes = true; AddSubview(this.segmentedControl); this.showPreviewImage = new NSButton { Bordered = false, ControlSize = controlSize, Image = NSImage.ImageNamed(NSImageName.QuickLookTemplate), Title = string.Empty, TranslatesAutoresizingMaskIntoConstraints = false, }; this.showPreviewImage.Activated += (o, e) => { ShowPreview = !ShowPreview; RepositionControls(); }; AddSubview(this.showPreviewImage); OnSearchResourcesChanged(null, null); RepositionControls(); }