/// <summary> /// Get the orderered list of elements that make up the path that leads to the InsepctView with /// a Handle equal to viewHandle. The first element in the returned list is always the root, and the /// last element is the matching view. /// </summary> /// <param name="root"></param> /// <param name="viewHandle"></param> /// <returns>Null if no matching view is found. List as described, otherwise.</returns> static List <InspectView> GetInspectViewPath(InspectView root, long viewHandle) { if (root.Handle == viewHandle) { return new List <InspectView> { root } } ; if (root.Subviews == null) { return(null); } foreach (InspectView child in root.Subviews) { var path = GetInspectViewPath(child, viewHandle); if (path == null) { continue; } path.Insert(0, root); return(path); } return(null); }
public override nint GetChildrenCount(NSOutlineView outlineView, NSObject item) { if (Root == null) { return(0); // no tree exists } InspectView view = (InspectViewPeer)item; if (view == null) { return(1); // root node } var childCount = 0; if (view.Subviews != null) { childCount += view.Subviews.Count; // subviews } if (view.Layer != null) { childCount += 1; // layer } if (view.Sublayers != null) { childCount += view.Sublayers.Count; // sublayers } return(childCount); }
public static InspectViewMaterial Create(InspectView inspectView, bool renderImage = true) { if (inspectView == null) { throw new ArgumentNullException(nameof(inspectView)); } if (Math.Abs(inspectView.Width) < Single.Epsilon || Math.Abs(inspectView.Height) < Single.Epsilon) { return(null); } if (renderImage && inspectView.BestCapturedImage != null) { try { NativeExceptionHandler.Trap(); return(new InspectViewMaterial(inspectView.BestCapturedImage)); } catch (Exception e) { Log.Error(TAG, $"Exception creating NSImage from byte[] " + $"(length={inspectView.CapturedImage.Length})", e); } finally { NativeExceptionHandler.Release(); } } return(new InspectViewMaterial(inspectView.Width, inspectView.Height)); }
public override NSObject GetChild(NSOutlineView outlineView, nint childIndex, NSObject item) { InspectView view = (InspectViewPeer)item; if (view == null) { return((InspectViewPeer)Root.Peer); } var subviewCount = (view.Subviews?.Count ?? 0); if (childIndex >= subviewCount) { if (childIndex == subviewCount && view.Layer != null) { return((InspectViewPeer)view.Layer.Peer); } if (childIndex >= (view.Sublayers?.Count ?? 0)) { return(null); } return((InspectViewPeer)view.Sublayers [(int)childIndex].Peer); } return((InspectViewPeer)view.Subviews [(int)childIndex].Peer); }
void RebuildScene(InspectView view, bool recreateScene = true) { if (recreateScene) { Scene = new SCNScene(); } else { currentViewNode?.RemoveFromParentNode(); } currentViewNode = null; if (view != null) { currentViewNode = new InspectViewNode(view).Rebuild( new TreeState(DisplayMode, ShowHiddenViews)); Scene.Add(currentViewNode); Trackball.Target = Scene.RootNode; } Play(this); }
void TreeView_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { var value = e.NewValue as InspectView; var item = e.Source as TreeViewItem; Dispatcher.CurrentDispatcher.InvokeAsync(() => SelectedElement = value); e.Handled = true; }
InspectViewNode BuildChild(InspectView view, TreeState state) { var childNode = new InspectViewNode(view, state.AddChild(view)); Children.Add(childNode); childNode.Rebuild(state); return(childNode); }
/// <summary> /// Start Inspect Mode /// </summary> /// <param name="view"></param> /// <returns></returns> void StartInspectMode(InspectView view) { switch (view) { case InspectView.Live: StartLiveMode(); break; } }
public InspectViewNode(InspectView inspectView, int childIndex) { if (inspectView == null) { throw new ArgumentNullException(nameof(inspectView)); } InspectView = inspectView; this.childIndex = childIndex; }
public int AddChild(InspectView view) { var pos = ancestors.Count - 1; var count = ancestors [pos]; ancestors [pos] = count + 1; TotalCount = TotalCount + 1; return(count); }
void SelectView(InspectView view, bool withinExistingTree, bool setSelectedView) { if (!Session.Agent.IsConnected) { return; } if (setSelectedView && !string.IsNullOrEmpty(view?.PublicCSharpType) && Session.SessionKind == ClientSessionKind.LiveInspection) { var code = $"var selectedView = GetObject<{view.PublicCSharpType}> (0x{view.Handle:x})"; Session.WorkbookPageViewModel.EvaluateAsync(code).Forget(); } if (withinExistingTree && representedRootView != null && view != null) { view = representedRootView.FindSelfOrChild(v => v.Handle == view.Handle); } if (view != null && view.Root == view && view.IsFakeRoot) { view = view.Children.FirstOrDefault() ?? view; } var root = view?.Root; var current = view; // find the "window" to represent in the 3D view by either // using the root node of the tree for trees with real roots, // or by walking up to find the real root below the fake root if (root != null && root.IsFakeRoot && current != root) { while (current.Parent != null && current.Parent != root) { current = current.Parent; } } else { current = root; } representedRootView = root; ChildViewControllers.OfType <ViewInspectorViewController> ().ForEach(viewController => { viewController.RootView = root; viewController.RepresentedView = current; viewController.SelectedView = view; }); }
async Task HighlightView( Point screenPt, bool andSelect, string hierarchyKind, CancellationToken cancellationToken = default(CancellationToken)) { Point devicePt; InspectView view = null; if (coordinateMapper != null && coordinateMapper.TryGetLocalCoordinate(screenPt, out devicePt)) { view = await clientSession.Agent.Api.HighlightView <InspectView> ( devicePt.X, devicePt.Y, clear : true, hierarchyKind : hierarchyKind, cancellationToken : cancellationToken); } if (view == null) { highlightedView = null; overlayWindow.Clear(); return; } // Don't clear or redraw anything. We are over the same view. if (highlightedView != null && view.Handle == highlightedView.Handle && !andSelect) { return; } highlightedView = view; overlayWindow.Clear(); if (andSelect) { highlightedView = null; ViewSelected?.Invoke(this, new HighlightSelectionEventArgs { SelectedView = view }); } else { overlayWindow.HighlightRect(coordinateMapper.GetHostRect(new Rect { X = view.X, Y = view.Y, Width = view.Width, Height = view.Height, })); } }
public InspectTreeNode(InspectTreeNode parent, InspectView view) { Parent = parent; RepresentedObject = view ?? throw new ArgumentNullException(nameof(view)); Name = GetDisplayName(); Children = view.Children.Select(c => new InspectTreeNode(this, c)).ToList(); IsRenamable = false; IsEditing = false; IsSelectable = !view.IsFakeRoot; ToolTip = view.Description; IconName = view.Kind == ViewKind.Primary ? "view" : "layer"; IsExpanded = true; }
public override bool ItemExpandable(NSOutlineView outlineView, NSObject item) { InspectView inspectView = (InspectViewPeer)item; if (inspectView == null) { return(false); } var subviewsCount = inspectView.Subviews?.Count ?? 0; var layerCount = inspectView.Layer == null ? 0 : 1; var sublayerCount = inspectView.Sublayers?.Count ?? 0; return((subviewsCount + layerCount + sublayerCount) > 0); }
public override void SelectionDidChange(NSNotification notification) { if (InhibitSelectionDidChange) { return; } var row = viewController.outlineView.SelectedRow; if (row < 0) { row = 0; } InspectView view = viewController.outlineView.ItemAtRow(row) as InspectViewPeer; viewController.ParentViewController.SelectView(view); }
async Task RefreshVisualTreeAsync() { InspectView remoteView = null; string [] supportedHierarchies = null; isVisualTreeRefreshing = true; try { supportedHierarchies = Session.Agent?.Features?.SupportedViewInspectionHierarchies; if (supportedHierarchies != null && supportedHierarchies.Length > 0) { if (!supportedHierarchies.Contains(selectedHierarchy)) { selectedHierarchy = supportedHierarchies [0]; } remoteView = await Session.Agent.Api.GetVisualTreeAsync( selectedHierarchy, captureViews : true); } else { supportedHierarchies = null; selectedHierarchy = null; } } catch (Exception e) { e.ToUserPresentable(Catalog.GetString("Error trying to inspect remote view")) .Present(this); } SelectView(remoteView, withinExistingTree: false, setSelectedView: false); UpdateHierarchiesList(supportedHierarchies, selectedHierarchy); isVisualTreeRefreshing = false; View?.Window?.Toolbar?.ValidateVisibleItems(); }
async Task HighlightView( CGPoint screenPt, bool andSelect, CancellationToken cancellationToken = default(CancellationToken)) { CGPoint devicePt = CGPoint.Empty; InspectView view = null; var isValidLocalCoordinate = coordinateMapper != null && coordinateMapper.TryGetLocalCoordinate(screenPt, out devicePt); view = await clientSession.Agent.Api.HighlightView <InspectView> ( devicePt.X, devicePt.Y, clear : andSelect || !isValidLocalCoordinate, hierarchyKind : hierarchyKind, cancellationToken : cancellationToken); if (!isValidLocalCoordinate || view == null) { highlightedView = null; return; } // Don't clear or redraw anything. We are over the same view. if (highlightedView != null && view.Handle == highlightedView.Handle && !andSelect) { return; } highlightedView = view; if (andSelect) { highlightedView = null; ViewSelected?.Invoke(this, new HighlightSelectionEventArgs { SelectedView = view }); } }
public override NSObject GetObjectValue(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) { InspectView view = (InspectViewPeer)item; if (view == null) { return(null); } var text = (String.IsNullOrEmpty(view.DisplayName)) ? view.Type : view.DisplayName; if (text == null) { return(null); } var ofs = text.IndexOf('.'); if (ofs > 0) { switch (text.Substring(0, ofs)) { case "AppKit": case "SceneKit": case "WebKit": case "UIKit": text = text.Substring(ofs + 1); break; } } if (!String.IsNullOrEmpty(view.Description)) { text += String.Format(" — “{0}”", view.Description); } return(new NSString(text)); }
public void SelectView(InspectView view) => SelectView(view, false, true);
public void Load(InspectView view) { Root = view; }
void SelectView(InspectView view, bool withinExistingTree = false, bool setSelectedView = true) => model.SelectView(view, withinExistingTree, setSelectedView);
public void SelectView(InspectView target) { }
public InspectViewPeer(InspectView inspectView) => InspectView = inspectView;
public InspectViewNode(InspectView inspectView) : this(inspectView, 0) { }