Esempio n. 1
0
        private void HandleRefresh(object sender, ExecutedRoutedEventArgs e)
        {
            Cursor saveCursor = Mouse.OverrideCursor;

            Mouse.OverrideCursor = Cursors.Wait;
            try
            {
                object currentTarget = CurrentSelection != null ? CurrentSelection.Target : null;

                _visualTreeItems.Clear();

                Root = VisualTreeItem.Construct(_root, null);

                if (currentTarget != null)
                {
                    VisualTreeItem visualItem = FindItem(currentTarget);
                    if (visualItem != null)
                    {
                        CurrentSelection = visualItem;
                    }
                }

                SetFilter(_filter);
            }
            finally
            {
                Mouse.OverrideCursor = saveCursor;
            }
        }
Esempio n. 2
0
        public static void AddEditedProperty(Dispatcher dispatcher, VisualTreeItem propertyOwner, PropertyInformation propInfo)
        {
            lock (_lock)
            {
                List <PropertyValueInfo> propInfoList;
                Dictionary <VisualTreeItem, List <PropertyValueInfo> > dispatcherList;

                // first get the dictionary we're using for the given dispatcher
                if (!_itemsWithEditedProperties.TryGetValue(dispatcher, out dispatcherList))
                {
                    dispatcherList = new Dictionary <VisualTreeItem, List <PropertyValueInfo> >();
                    _itemsWithEditedProperties.Add(dispatcher, dispatcherList);
                }

                // now get the property info list for the owning object
                if (!dispatcherList.TryGetValue(propertyOwner, out propInfoList))
                {
                    propInfoList = new List <PropertyValueInfo>();
                    dispatcherList.Add(propertyOwner, propInfoList);
                }

                // if we already have a property of that name on this object, remove it
                var existingPropInfo = propInfoList.FirstOrDefault(l => l.PropertyName == propInfo.DisplayName);
                if (existingPropInfo.PropertyName != null)
                {
                    propInfoList.Remove(existingPropInfo);
                }

                // finally add the edited property info
                propInfoList.Add(new PropertyValueInfo(propInfo.DisplayName, propInfo.Value));
            }
        }
Esempio n. 3
0
        static List <VisualTreeItem> GetDescendants(VisualTreeItem vItem)
        {
            var descendants = new List <VisualTreeItem>();

            vItem.Iterate(x => x == vItem || x.IsExpanded, descendants.Add);
            descendants.Remove(vItem);
            return(descendants);
        }
Esempio n. 4
0
        private void HandleTreeSelectedItemChanged(object sender, EventArgs e)
        {
            VisualTreeItem item = Tree.SelectedItem as VisualTreeItem;

            if (item != null)
            {
                CurrentSelection = item;
            }
        }
Esempio n. 5
0
        public void NotifySelected(VisualTreeItem item)
        {
            if (this.autoExpandCheckBox.IsChecked == true)
            {
                item.IsExpanded = true;
            }

            this.Invoke(string.Format("cd {0}:\\{1}", ShellConstants.DriveName, item.NodePath()));
        }
Esempio n. 6
0
 /// <summary>
 /// Loop through the properties in the current PropertyGrid and save away any properties
 /// that have been changed by the user.
 /// </summary>
 /// <param name="owningObject">currently selected object that owns the properties in the grid (before changing selection to the new object)</param>
 private void SaveEditedProperties(VisualTreeItem owningObject)
 {
     foreach (PropertyInformation property in PropertyGrid.PropertyGrid.Properties)
     {
         if (property.IsValueChangedByUser)
         {
             EditedPropertiesHelper.AddEditedProperty(Dispatcher, owningObject, property);
         }
     }
 }
Esempio n. 7
0
 private void SelectItem(DependencyObject item)
 {
     if (item != null)
     {
         VisualTreeItem node = FindItem(item);
         if (node != null)
         {
             CurrentSelection = node;
         }
     }
 }
Esempio n. 8
0
        private void Load(object localRoot)
        {
            _root = localRoot;

            _visualTreeItems.Clear();

            Root             = VisualTreeItem.Construct(localRoot, null);
            CurrentSelection = _rootVisualTreeItem;

            SetFilter(_filter);

            OnPropertyChanged("Root");
        }
Esempio n. 9
0
 private void FilterBindings(VisualTreeItem node)
 {
     foreach (VisualTreeItem child in node.Children)
     {
         if (child.HasBindingError)
         {
             _visualTreeItems.Add(child);
         }
         else
         {
             FilterBindings(child);
         }
     }
 }
Esempio n. 10
0
 private void FilterTree(VisualTreeItem node, string localFilter)
 {
     foreach (VisualTreeItem child in node.Children)
     {
         if (child.Filter(localFilter))
         {
             _visualTreeItems.Add(child);
         }
         else
         {
             FilterTree(child, localFilter);
         }
     }
 }
Esempio n. 11
0
        public bool ApplyReduceDepthFilterIfNeeded(ProperTreeViewItem curNode)
        {
            if (_pendingRoot != null)
            {
                OnRootLoaded();
            }

            if (_maxDepth == 0)
            {
                return(false);
            }

            VisualTreeItem rootItem = (VisualTreeItem)_rootItem.Target;

            if (rootItem == null)
            {
                return(false);
            }

            if (_snoopUi == null)
            {
                _snoopUi = this.GetAncestor <SnoopUI>();
                if (_snoopUi == null)
                {
                    return(false);
                }
            }

            VisualTreeItem item         = (VisualTreeItem)curNode.DataContext;
            VisualTreeItem selectedItem = _snoopUi.CurrentSelection;

            if (selectedItem != null && item.Depth < selectedItem.Depth)
            {
                item = selectedItem;
            }

            if ((item.Depth - rootItem.Depth) <= _maxDepth)
            {
                return(false);
            }

            for (int i = 0; i < _maxDepth; ++i)
            {
                item = item.Parent;
            }

            _snoopUi.ApplyReduceDepthFilter(item);
            return(true);
        }
        public static string NodePath(this VisualTreeItem item)
        {
            var parts = new List <string>();

            var current = item;

            while (current.Parent != null)
            {
                var name = current.NodeName();
                parts.Insert(0, name);
                current = current.Parent;
            }

            return(string.Join("\\", parts.ToArray()));
        }
        public static string NodeName(this VisualTreeItem item)
        {
            var name = GetName(item);

            if (item.Parent != null)
            {
                var parent          = item.Parent;
                var similarChildren = parent.Children.Where(c => GetName(c).Equals(name)).ToList();
                if (similarChildren.Count > 1)
                {
                    name += (similarChildren.IndexOf(item) + 1);
                }
            }

            return(name);
        }
Esempio n. 14
0
 public void ApplyReduceDepthFilter(VisualTreeItem newRoot)
 {
     if (_reducedDepthRoot == newRoot)
     {
         return;
     }
     if (_reducedDepthRoot == null)
     {
         Dispatcher.InvokeAsync(() =>
         {
             VisualTreeItems.Clear();
             VisualTreeItems.Add(_reducedDepthRoot);
             _reducedDepthRoot = null;
         }, DispatcherPriority.Background);
     }
     _reducedDepthRoot = newRoot;
 }
Esempio n. 15
0
        private void HandleInspect(object sender, ExecutedRoutedEventArgs e)
        {
            Visual visual = e.Parameter as Visual;

            if (visual != null)
            {
                VisualTreeItem node = FindItem(visual);
                if (node != null)
                {
                    CurrentSelection = node;
                }
            }
            else if (e.Parameter != null)
            {
                PropertyGrid.SetTarget(e.Parameter);
            }
        }
Esempio n. 16
0
 public void ApplyReduceDepthFilter(VisualTreeItem newRoot)
 {
     if (_reducedDepthRoot != newRoot)
     {
         if (_reducedDepthRoot == null)
         {
             Dispatcher.BeginInvoke
             (
                 DispatcherPriority.Background,
                 (Action)
                 delegate
             {
                 this._visualTreeItems.Clear();
                 this._visualTreeItems.Add(_reducedDepthRoot);
                 _reducedDepthRoot = null;
             }
             );
         }
         _reducedDepthRoot = newRoot;
     }
 }
Esempio n. 17
0
 void OnUIPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Root")
     {
         if (root != null)
         {
             root.ChildExpandedChanged -= OnChildExpandedChanged;
             root.BeginUpdate          -= OnRootBeginUpdateChild;
             root.EndUpdate            -= OnRootEndUpdateChild;
         }
         root = ui.Root;
         if (root != null)
         {
             root.ChildExpandedChanged += OnChildExpandedChanged;
             root.BeginUpdate          += OnRootBeginUpdateChild;
             root.EndUpdate            += OnRootEndUpdateChild;
         }
         visibleItems.Clear();
         visibleItems.Add(root);
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Find the VisualTreeItem for the specified visual.
        /// If the item is not found and is not part of the Snoop UI,
        /// the tree will be adjusted to include the window the item is in.
        /// </summary>
        private VisualTreeItem FindItem(object target)
        {
            VisualTreeItem node       = _rootVisualTreeItem.FindNode(target);
            Visual         rootVisual = _rootVisualTreeItem.MainVisual;

            if (node == null)
            {
                Visual visual = target as Visual;
                if (visual != null && rootVisual != null)
                {
                    // If target is a part of the SnoopUI, let's get out of here.
                    if (visual.IsDescendantOf(this))
                    {
                        return(null);
                    }

                    // If not in the root tree, make the root be the tree the visual is in.
                    if (!visual.IsDescendantOf(rootVisual))
                    {
                        var presentationSource = PresentationSource.FromVisual(visual);
                        if (presentationSource == null)
                        {
                            return(null); // Something went wrong. At least we will not crash with null ref here.
                        }

                        Root = new VisualItem(presentationSource.RootVisual, null);
                    }
                }

                _rootVisualTreeItem.Reload();

                node = _rootVisualTreeItem.FindNode(target);

                SetFilter(_filter);
            }
            return(node);
        }
Esempio n. 19
0
        private void HandlePreProcessInput(object sender, PreProcessInputEventArgs e)
        {
            OnPropertyChanged("CurrentFocus");

            if (!_stickyInputTimer.IsRunning)
            {
                ModifierKeys currentModifiers = InputManager.Current.PrimaryKeyboardDevice.Modifiers;
                if (!((currentModifiers & ModifierKeys.Control) != 0 && (currentModifiers & ModifierKeys.Shift) != 0))
                {
                    return;
                }
                if ((currentModifiers & ModifierKeys.Alt) != 0)
                {
                    _stickyInputTimer.Reset();
                    _stickyInputTimer.Start();
                }
            }
            else if (_stickyInputTimer.ElapsedMilliseconds > 5000)
            {
                _stickyInputTimer.Stop();
            }

            Visual directlyOver = Mouse.PrimaryDevice.DirectlyOver as Visual;

            if ((directlyOver == null) || directlyOver.IsDescendantOf(this))
            {
                return;
            }

            VisualTreeItem node = FindItem(directlyOver);

            if (node != null)
            {
                CurrentSelection = node;
            }
        }
Esempio n. 20
0
 private static string GetName(VisualTreeItem item)
 {
     return item.Target.GetType().Name;
 }
 private static string GetName(VisualTreeItem item)
 {
     return(item.Target.GetType().Name);
 }
Esempio n. 22
0
        public void NotifySelected(VisualTreeItem item)
        {
            if (this.autoExpandCheckBox.IsChecked == true)
            {
                item.IsExpanded = true;
            }

            this.Invoke(string.Format("cd {0}:\\{1}", ShellConstants.DriveName, item.NodePath()));
        }
Esempio n. 23
0
 public void Select(VisualTreeItem item)
 {
     TreeListSource.MoveCurrentTo(item);
 }