Beispiel #1
0
        VirtualizingStackPanelEx GetPanelForTreeViewItem(TreeViewItem container)
        {
            container.ApplyTemplate();
            ItemsPresenter itemsPresenter =
                (ItemsPresenter)container.Template.FindName("ItemsHost", container);

            if (itemsPresenter != null)
            {
                itemsPresenter.ApplyTemplate();
            }
            else
            {
                // The Tree template has not named the ItemsPresenter,
                // so walk the descendants and find the child.
                itemsPresenter = TreeViewHelper.FindVisualChild <ItemsPresenter>(container);
                if (itemsPresenter == null)
                {
                    container.UpdateLayout();

                    itemsPresenter = TreeViewHelper.FindVisualChild <ItemsPresenter>(container);
                }
            }

            Panel itemsHostPanel = (Panel)VisualTreeHelper.GetChild(itemsPresenter, 0);

            // Ensure that the generator for this panel has been created.
            UIElementCollection children = itemsHostPanel.Children;

            var virtualizingPanel = itemsHostPanel as VirtualizingStackPanelEx;

            Debug.Assert(virtualizingPanel != null);

            return(virtualizingPanel);
        }
        private void ApplyTemplate(CodeFile file, DataTemplate template)
        {
            TreeViewItem item = parent.ItemContainerGenerator.ContainerFromItem(file) as TreeViewItem;

            if (item != null)
            {
                item.HeaderTemplate = template;
                item.ApplyTemplate();
            }
        }
        // Обновляет выделения (текущий активный файл и открытые файлы)
        private void UpdateSelections()
        {
            if (Current == null)
            {
                return;
            }

            foreach (CodeFile file in Current.Files)
            {
                TreeViewItem item = parent.ItemContainerGenerator.ContainerFromItem(file) as TreeViewItem;
                if (item != null)
                {
                    if (_codeEditorView.CurrentCodeFile == file)
                    {
                        item.HeaderTemplate = CurrentEditorItemTemplate;
                    }
                    else if (_codeEditorView.OpenedFiles.Count(f => f == file) > 0)
                    {
                        item.HeaderTemplate = OpenInEditorItemTemplate;
                    }
                    else
                    {
                        item.HeaderTemplate = ItemTemplate;
                    }

                    item.ApplyTemplate();
                }
            }

            // Если нет ни одного активного файла, перетащить фокус на себя!
            if (_codeEditorView.OpenedFiles.Count() == 0)
            {
                if (treeView1.SelectedItem == null)
                {
                    parent.Focus(); // Если нету выбранного ранее объекта, то установим на сам проект
                }
                else
                {
                    treeView1.Focus(); // Иначе установим на сам тривь, а он уже сам выберет ранее выбранный
                }
            }
        }
Beispiel #4
0
        // Загрузить рабочие директории из проекта (если загружен)
        private void LoadWorkDirs()
        {
            if (CodeProjectManager.Instance.Current == null)
            {
                return;
            }

            // Load Work dirs from project
            workDirsItem = new TreeViewItem();

            workDirsItem.ItemTemplate = FavouriteItem.ItemTemplate;
            workDirsItem.ApplyTemplate();
            workDirsItem.Header     = LocalString.Get("WorkDirs");
            workDirsItem.IsExpanded = true;
            workDirsItem.SetBinding(TreeViewItem.ItemsSourceProperty,
                                    new Binding {
                Source = CodeProjectManager.Instance.Current.WorkDirs
            });

            treeView1.Items.Insert(0, workDirsItem);
        }
Beispiel #5
0
        private void SelectTreeviewItemByMatch(Func <AsfPacket, int> matchPacketMethod, Func <AsfPacket, int> matchPacketFollowupMethod = null, Func <List <PayloadInfo>, int> matchPayloadMethod = null)
        {
            AsfHierarchy.UpdateLayout();

            foreach (AsfHeaderItem item in AsfHierarchy.Items)
            {
                if (item.Name == "Data Object")
                {
                    AsfDataObjectItem asfDataObjectItem = item as AsfDataObjectItem;

                    TreeViewItem treeViewItem = AsfHierarchy.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
                    if (treeViewItem == null)
                    {
                        return;
                    }
                    treeViewItem.IsExpanded = true;
                    treeViewItem.ApplyTemplate();
                    ItemsPresenter itemsPresenter = (ItemsPresenter)treeViewItem.Template.FindName("ItemsHost", treeViewItem);
                    if (itemsPresenter != null)
                    {
                        itemsPresenter.ApplyTemplate();
                    }
                    else
                    {
                        // The Tree template has not named the ItemsPresenter,
                        // so walk the descendents and find the child.
                        itemsPresenter = FindVisualChild <ItemsPresenter>(treeViewItem);
                        if (itemsPresenter == null)
                        {
                            treeViewItem.UpdateLayout();

                            itemsPresenter = FindVisualChild <ItemsPresenter>(treeViewItem);
                        }
                    }
                    Panel itemsHostPanel = (Panel)VisualTreeHelper.GetChild(itemsPresenter, 0);
                    // Ensure that the generator for this panel has been created.
                    UIElementCollection children = itemsHostPanel.Children;

                    MyVirtualizingStackPanel msp = itemsHostPanel as MyVirtualizingStackPanel;

                    //binary search for right payload for the time offset requested with a 50 millisecond bucket size
                    int index = 0;

                    index = asfDataObjectItem.Packets.BinarySearchForMatch(matchPacketMethod);
                    if (matchPacketFollowupMethod != null)
                    {
                        index = asfDataObjectItem.Packets.LinearSearchForMatch(index, matchPacketFollowupMethod);
                    }

                    if (index >= 0 && index < asfDataObjectItem.Packets.Count)
                    {
                        msp.BringIntoView(index);
                        var  selectedPacket = treeViewItem.ItemContainerGenerator.ContainerFromIndex(index);
                        bool bBuilt         = false;

                        if (selectedPacket != null)
                        {
                            TreeViewItem packetTreeViewItem = selectedPacket as TreeViewItem;
                            //packetTreeViewItem.IsSelected = true;
                            packetTreeViewItem.IsExpanded = true;

                            //now expand to payload
                            bBuilt         = packetTreeViewItem.ApplyTemplate();
                            itemsPresenter = (ItemsPresenter)packetTreeViewItem.Template.FindName("ItemsHost", packetTreeViewItem);
                            if (itemsPresenter != null)
                            {
                                bBuilt = itemsPresenter.ApplyTemplate();
                            }
                            else
                            {
                                // The Tree template has not named the ItemsPresenter,
                                // so walk the descendents and find the child.
                                itemsPresenter = FindVisualChild <ItemsPresenter>(packetTreeViewItem);
                                if (itemsPresenter == null)
                                {
                                    packetTreeViewItem.UpdateLayout();
                                    itemsPresenter = FindVisualChild <ItemsPresenter>(packetTreeViewItem);
                                }
                            }
                            itemsHostPanel = (Panel)VisualTreeHelper.GetChild(itemsPresenter, 0);
                            // Ensure that the generator for this panel has been created.
                            children = itemsHostPanel.Children;
                            msp      = itemsHostPanel as MyVirtualizingStackPanel;

                            int payloadIndex = 0;

                            if (matchPayloadMethod != null)
                            {
                                payloadIndex = matchPayloadMethod(asfDataObjectItem.Packets[index].Payload);
                            }

                            if (payloadIndex < 0 || payloadIndex >= asfDataObjectItem.Packets[index].Payload.Count)
                            {
                                payloadIndex = 0;
                            }

                            msp.BringIntoView(payloadIndex);
                            var          selectedPayload     = packetTreeViewItem.ItemContainerGenerator.ContainerFromIndex(payloadIndex);
                            TreeViewItem payloadTreeViewItem = selectedPayload as TreeViewItem;
                            if (payloadTreeViewItem != null)
                            {
                                payloadTreeViewItem.BringIntoView();
                                payloadTreeViewItem.IsSelected = true;
                                payloadTreeViewItem.IsExpanded = true;
                                payloadTreeViewItem.Focus();
                            }
                        }
                    }
                }
            }
        }