public override void WindowDidLoad() { MainThread.Ensure(); Session = SessionDocument.InstanceForWindowControllers?.Session; if (Session == null) { Log.Error(TAG, "Unable to get ClientSession from SessionDocument"); throw new InvalidOperationException(); } var viewControllers = new MacClientSessionViewControllers(this); Session.InitializeViewControllers(viewControllers); ShouldCascadeWindows = false; Window.FrameAutosaveName = "SessionWindow"; Window.TitleVisibility = NSWindowTitleVisibility.Hidden; var toolbar = new NSToolbar("xi-toolbar-main-toolbar-" + Guid.NewGuid()) { SizeMode = NSToolbarSizeMode.Regular, DisplayMode = NSToolbarDisplayMode.Icon, AllowsUserCustomization = false }; new SessionToolbarDelegate(Session, viewControllers, toolbar); Window.Toolbar = toolbar; base.WindowDidLoad(); }
public SessionToolbarDelegate( ClientSession clientSession, MacClientSessionViewControllers viewControllers, NSToolbar toolbar) { if (clientSession == null) { throw new ArgumentNullException(nameof(clientSession)); } if (viewControllers == null) { throw new ArgumentNullException(nameof(viewControllers)); } if (toolbar == null) { throw new ArgumentNullException(nameof(toolbar)); } allowedItemIdentifiers = clientSession.SessionKind == ClientSessionKind.LiveInspection ? Identifiers.InspectorDefault : Identifiers.WorkbooksDefault; this.toolbar = toolbar; toolbar.Delegate = this; runAllItem = CreateButton( Identifiers.RunAll, "runAllSubmissions:", Catalog.GetString("Run All"), Catalog.GetString("Run the whole workbook from top to bottom"), "ToolbarRunTemplate"); refreshItem = CreateButton( Identifiers.Refresh, "refreshVisualTree:", Catalog.GetString("Refresh"), Catalog.GetString("Refresh the application's visual tree in Inspector"), "ToolbarRefreshTemplate"); inspectItem = CreateButton( Identifiers.Inspect, "inspectView:", Catalog.GetString("Inspect"), Catalog.GetString("Select a UI element to inspect in the running application"), "ToolbarInspectTemplate"); var targetSelector = new WorkbookTargetSelector( clientSession.ViewControllers.WorkbookTargets) { Font = NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize) }; var targetSelectorItemMenu = new NSMenuItem(Catalog.GetString("Target")); targetSelectorItemMenu.Submenu = targetSelector.Menu; targetSelectorItem = new NSToolbarItem(Identifiers.TargetSelector) { View = targetSelector, MinSize = targetSelector.Frame.Size, MaxSize = targetSelector.Frame.Size, VisibilityPriority = -1000, MenuFormRepresentation = targetSelectorItemMenu }; targetSelector.Activated += (sender, e) => { var size = targetSelector.GetToolbarSize(); targetSelectorItem.MinSize = size; targetSelectorItem.MaxSize = size; centeringItem.UpdateWidth(); viewControllers.WindowTabs.SelectedTabViewItemIndex = 0; }; centeringItem = new CenteringToolbarItem(Identifiers.CenteringSpacer); statusItem = new StatusToolbarItem { View = viewControllers.Status.View }; tabViewItem = new NSToolbarItem(Identifiers.TabView) { PaletteLabel = Catalog.GetString("Views") }; tabViewItem.View = viewControllers.WindowTabs.ToolbarSegmentedControl; viewControllers.WindowTabs.ItemSelected += (sender, e) => { switch (viewControllers.WindowTabs.SelectedTabViewItemIndex) { case 0: RemoveItem(Identifiers.Inspect); RemoveItem(Identifiers.Refresh); if (clientSession.SessionKind != ClientSessionKind.LiveInspection) { toolbar.InsertItem(Identifiers.RunAll, 0); } ((XcbWorkbookPageView)clientSession.EvaluationService).DelayNewCodeCellFocus = false; break; case 1: RemoveItem(Identifiers.RunAll); toolbar.InsertItem(Identifiers.Inspect, 0); toolbar.InsertItem(Identifiers.Refresh, 0); ((XcbWorkbookPageView)clientSession.EvaluationService).DelayNewCodeCellFocus = true; break; } centeringItem.UpdateWidth(); }; NSWindow.Notifications.ObserveDidResize((sender, e) => { statusItem.UpdateSize(e.Notification.Object as NSWindow); centeringItem.UpdateWidth(); }); }