private void TreeViewItem_Expanded(object sender, RoutedEventArgs e)
        {
            try
            {
                TreeViewItem     item   = e.Source as TreeViewItem;
                TreeListView     tree   = null;
                FrameworkElement parent = item?.Parent as FrameworkElement;

                while (tree == null && parent != null)
                {
                    tree   = parent as TreeListView;
                    parent = parent.Parent as FrameworkElement;
                }

                if ((item.Items.Count == 1) && (item.Items[0].ToString() == ExpandingItemText))
                {
                    TreeViewItemTag tag = item.Tag as TreeViewItemTag;

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        IResultVisualizer resultTreeItem         = tag.ResultTreeItem as IResultVisualizer;
                        IEnumerable <IResultVisualizer> children = tag.ResultTreeItem as IEnumerable <IResultVisualizer>;

                        try
                        {
                            if (resultTreeItem != null)
                            {
                                List <Tuple <string, IEnumerable <IResultVisualizer> > > customChildren = new List <Tuple <string, IEnumerable <IResultVisualizer> > >();

                                foreach (Tuple <string, IEnumerable <IResultVisualizer> > customChild in resultTreeItem.Children)
                                {
                                    if (customChild.Item2.Any())
                                    {
                                        if (customChild.Item1 == "[Expanded]")
                                        {
                                            List <IResultVisualizer> cachedItems = customChild.Item2.ToList();

                                            customChildren.Add(Tuple.Create(customChild.Item1, (IEnumerable <IResultVisualizer>)cachedItems));
                                            foreach (IResultVisualizer child in cachedItems)
                                            {
                                                child.Initialize();
                                            }
                                        }
                                        else
                                        {
                                            customChildren.Add(customChild);
                                        }
                                    }
                                }

                                item.Dispatcher.InvokeAsync(() =>
                                {
                                    try
                                    {
                                        int level = tag.Level;

                                        item.Items.Clear();
                                        foreach (Tuple <string, IEnumerable <IResultVisualizer> > customChild in customChildren)
                                        {
                                            if (customChild.Item1 == "[Expanded]")
                                            {
                                                foreach (IResultVisualizer child in customChild.Item2)
                                                {
                                                    item.Items.Add(CreateTreeItem(tree, child, level + 1));
                                                }
                                            }
                                            else
                                            {
                                                TreeViewItem customItem = CreateTreeItem(tree, customChild.Item1, CompletionData.GetImage(CompletionDataType.Namespace), level + 1, nameItalic: true);

                                                customItem.Tag = new TreeViewItemTag()
                                                {
                                                    Level          = level + 1,
                                                    ResultTreeItem = customChild.Item2,
                                                };
                                                customItem.Items.Add(ExpandingItemText);
                                                customItem.Expanded += TreeViewItem_Expanded;
                                                item.Items.Add(customItem);
                                            }
                                        }
                                    }
                                    catch (Exception ex3)
                                    {
                                        MessageBox.Show(ex3.ToString());
                                    }
                                });
                            }
                            else if (children != null)
                            {
                                List <IResultVisualizer> cachedItems = children.ToList();

                                foreach (IResultVisualizer child in children)
                                {
                                    child.Initialize();
                                }

                                item.Dispatcher.InvokeAsync(() =>
                                {
                                    try
                                    {
                                        int level = tag.Level;

                                        item.Items.Clear();
                                        foreach (IResultVisualizer child in cachedItems)
                                        {
                                            item.Items.Add(CreateTreeItem(tree, child, level + 1));
                                        }
                                    }
                                    catch (Exception ex3)
                                    {
                                        MessageBox.Show(ex3.ToString());
                                    }
                                });
                            }
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.ToString());
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts fields of the object that will be visualized in [Expanded] group.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <IResultVisualizer> ExtractFields()
        {
            CodeType codeType = variable.GetCodeType();

            if (extractUsingClasses)
            {
                foreach (string baseClass in codeType.InheritedClasses.Keys)
                {
                    object   baseClassValue    = GetValue(() => variable.GetBaseClass(baseClass));
                    Variable baseClassVariable = baseClassValue as Variable;

                    if (baseClassVariable != null)
                    {
                        yield return(new VariableResultVisualizer(baseClassVariable, typeof(Variable), $"[{baseClass}]", CompletionData.GetImage(CompletionDataType.Class), interactiveResultVisualizer));
                    }
                    else
                    {
                        yield return(Create(baseClassValue, typeof(Variable), $"[{baseClass}]", CompletionData.GetImage(CompletionDataType.Class), interactiveResultVisualizer));
                    }
                }

                foreach (string fieldName in codeType.ClassFieldNames)
                {
                    yield return(Create(GetValue(() => variable.GetClassField(fieldName)), typeof(Variable), fieldName, CompletionData.GetImage(CompletionDataType.Variable), interactiveResultVisualizer));
                }
            }
            else
            {
                foreach (string fieldName in codeType.FieldNames)
                {
                    yield return(Create(GetValue(() => variable.GetField(fieldName)), typeof(Variable), fieldName, CompletionData.GetImage(CompletionDataType.Variable), interactiveResultVisualizer));
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Extracts entries that should be visualized.
 /// </summary>
 /// <returns>Entries that should be visualized as a group.</returns>
 private IEnumerable <IResultVisualizer> ExtractItems()
 {
     foreach (DictionaryEntry entry in dictionary)
     {
         yield return(Create(GetValue(() => entry.Value), resultType.GetElementType(), entry.Key.ToString(), CompletionData.GetImage(CompletionDataType.Variable), interactiveResultVisualizer));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Gets group of array elements to be visualized.
 /// </summary>
 /// <param name="start">Array index of the group start.</param>
 /// <param name="end">Array index of the group end (not included).</param>
 /// <returns>Group of array elements to be visualized.</returns>
 private IEnumerable <IResultVisualizer> GetArrayElements(int start, int end)
 {
     for (int i = start; i < end; i++)
     {
         yield return(Create(GetValue(() => variable.GetArrayElement(i)), typeof(Variable), $"[{i}]", CompletionData.GetImage(CompletionDataType.Variable), interactiveResultVisualizer));
     }
 }