Esempio n. 1
0
        private void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            // Store currently selected attribute, in case we just unselect + select the current item to refresh
            if (Tree.SelectedItem == null)
            {
                // We're unselcting, this is the old data we want to restore in future call of this event
                GuiTreeAttrib attrib = (TreeDetails.SelectedItem as GuiTreeAttrib);
                if (attrib == null)
                {
                    _oldSelectedAttrib         = null;
                    _alternativeSelectedAttrib = null;
                }
                else
                {
                    _oldSelectedAttrib = attrib.DataAttrib;
                    int i = TreeDetails.SelectedIndex;
                    if (i < TreeDetails.Items.Count - 1)
                    {
                        _alternativeSelectedAttrib = (TreeDetails.Items[i + 1] as GuiTreeAttrib).DataAttrib;
                    }
                    else if (i > 0)
                    {
                        _alternativeSelectedAttrib = (TreeDetails.Items[i - 1] as GuiTreeAttrib).DataAttrib;
                    }
                    else
                    {
                        _alternativeSelectedAttrib = null;
                    }
                }
            }

            TreeDetails.Items.Clear();
            if (Tree.SelectedItem != null)
            {
                GuiTreeNode Node = (GuiTreeNode)Tree.SelectedItem;
                TreeDetails.ContextMenu = Node.ContextMenu;
                foreach (KmlAttrib attrib in Node.DataNode.Attribs)
                {
                    TreeDetails.Items.Add(new GuiTreeAttrib(attrib));
                }
                _oldSelectedNode = Node.DataNode;

                // Restore attrib selection
                if (Node.DataNode == _oldSelectedNode && _oldSelectedAttrib != null)
                {
                    if (!Select(_oldSelectedAttrib))
                    {
                        Select(_alternativeSelectedAttrib);
                    }
                    if (TreeDetails.SelectedItem != null)
                    {
                        (TreeDetails.SelectedItem as ListViewItem).Focus();
                    }
                }
            }
            else
            {
                TreeDetails.ContextMenu = null;
            }
        }
Esempio n. 2
0
        private void BuildContextMenu()
        {
            // Copy that from a GuiTreeNode
            KmlNode node;

            if (DataMessage.Source is KmlNode)
            {
                node = (KmlNode)DataMessage.Source;
            }
            else
            {
                node = DataMessage.Source.Parent;
            }
            if (node == null)
            {
                return;
            }
            GuiTreeNode dummy = new GuiTreeNode(node, true, true, true, false, false, false);

            ContextMenu = dummy.ContextMenu;
            // To avoid follwing error output (uncritical), we need to have a parent for the TreeViewItem, so we also make a dummy
            // System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'GuiTreeNode' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
            // System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'GuiTreeNode' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
            TreeView dummyTree = new TreeView();

            dummyTree.Items.Add(dummy);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a GuiVesselsPartGraphNode containing the given KmlPart at the given PartGrid koordinates.
        /// Also needs a master GuiTabsManager to switch view on double click on this node.
        /// </summary>
        /// <param name="part">The KmlPart this node will represent</param>
        /// <param name="koordX">The X koord in parents PartGrid</param>
        /// <param name="koordY">The Y koord in parents PartGrid</param>
        /// <param name="master">The master GuiTabsManager</param>
        public GuiVesselsPartGraphNode(KmlPart part, int koordX, int koordY, GuiTabsManager master)
        {
            KoordX = koordX;
            KoordY = koordY;
            Master = master;
            Lines  = new List <Line>();

            if (part != null)
            {
                Orientation = System.Windows.Controls.Orientation.Horizontal;

                Icon         = new GuiTreeNode(part, true, false, true, false);
                Icon.ToolTip = part.ToString();
                Icon.Margin  = new System.Windows.Thickness(-16, 0, 0, 0);
                // GuiTreeNode gets selected and drawn highlighted after using its context menu
                // we don't want this in the part graph
                Icon.Selected += Icon_Selected;
                Children.Add(Icon);

                Text             = new Label();
                Text.DataContext = part;
                Text.Content     = "[" + (part.Parent as KmlVessel).Parts.IndexOf(part) + "]";
                Text.ToolTip     = part.ToString();
                // TODO GuiVesselsPartGraphNode.GuiVesselsPartGraphNode(): Label.ContextMenu does not really work
                Text.ContextMenu = Icon.ContextMenu;
                Text.Margin      = new System.Windows.Thickness(-6, -6, 0, 0);
                Children.Add(Text);

                MouseEnter            += Node_MouseEnter;
                MouseLeave            += Node_MouseLeave;
                Icon.MouseDoubleClick += Node_MouseDoubleClick;
                // TODO GuiVesselsPartGraphNode.GuiVesselsPartGraphNode(): Label.MouseDoubleClick does not really work
                Text.MouseDoubleClick += Node_MouseDoubleClick;
            }
        }
Esempio n. 4
0
        private void BuildContextMenu()
        {
            // Copy that from a GuiTreeNode
            GuiTreeNode dummy = new GuiTreeNode(DataKerbal);

            ContextMenu = dummy.ContextMenu;
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a GuiKerbalsNode containing the given DataKerbal.
        /// To have nice icons in the tree, a GuiIcons can be
        /// provided.
        /// </summary>
        /// <param name="dataKerbal">The KmlKerbal to contain</param>
        public GuiKerbalsNode(KmlKerbal dataKerbal)
        {
            DataKerbal  = dataKerbal;
            BaseGuiNode = new GuiTreeNode(DataKerbal, true, true, true, false, true, false);

            AssignTemplate();
            BuildContextMenu();

            // Get notified when KmlNode ToString() changes
            DataKerbal.ToStringChanged += DataKerbal_ToStringChanged;
            // Get notified when attributes are added / deleted
            DataKerbal.AttribChanged += DataKerbal_AttribChanged;
        }
Esempio n. 6
0
 private void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
 {
     TreeDetails.Items.Clear();
     if (Tree.SelectedItem != null)
     {
         GuiTreeNode Node = (GuiTreeNode)Tree.SelectedItem;
         TreeDetails.ContextMenu = Node.ContextMenu;
         foreach (KmlAttrib attrib in Node.DataNode.Attribs)
         {
             TreeDetails.Items.Add(new GuiTreeAttrib(attrib));
         }
     }
     else
     {
         TreeDetails.ContextMenu = null;
     }
 }
Esempio n. 7
0
        private void BuildContextMenu()
        {
            // Copy that from a GuiTreeNode
            KmlNode node;

            if (DataMessage.Source is KmlNode)
            {
                node = (KmlNode)DataMessage.Source;
            }
            else
            {
                node = DataMessage.Parent;
            }
            GuiTreeNode dummy = new GuiTreeNode(node);

            ContextMenu = dummy.ContextMenu;
        }
Esempio n. 8
0
        private void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (Tree.SelectedItem != null)
            {
                GuiTreeNode Node = (GuiTreeNode)Tree.SelectedItem;
                TreeDetails.Items.Clear();
                foreach (KmlAttrib attrib in Node.DataNode.Attribs)
                {
                    TreeDetails.Items.Add(attrib);
                }

                /*GridView gv = (NodeList.View as GridView);
                 * foreach (GridViewColumn col in gv.Columns)
                 * {
                 *  col.Width = NodeList.ActualWidth / 2 - 15;
                 * }*/
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a GuiWarningsNode containing the given Syntax.Message.
        /// </summary>
        /// <param name="dataMessage">The Syntax.Message to contain</param>
        public GuiWarningsNode(Syntax.Message dataMessage)
        {
            DataMessage = dataMessage;
            KmlNode node;

            if (DataMessage.Source is KmlNode)
            {
                node = (KmlNode)DataMessage.Source;
            }
            else
            {
                node = DataMessage.Source.Parent;
            }
            if (node != null)
            {
                BaseGuiNode = new GuiTreeNode(node, true, true, true, false, false, false);
            }

            AssignTemplate();
            BuildContextMenu();
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a GuiVesselsNode containing the given DataVessel.
        /// To have nice icons in the tree, a GuiIcons can be
        /// provided.
        /// </summary>
        /// <param name="dataVessel">The KmlVessel to contain</param>
        public GuiVesselsNode(KmlVessel dataVessel)
        {
            DataVessel  = dataVessel;
            BaseGuiNode = new GuiTreeNode(DataVessel, true, true, true, false, true, false);

            AssignTemplate();
            BuildContextMenu();

            // Get notified when KmlNode ToString() changes
            DataVessel.ToStringChanged += DataVessel_ToStringChanged;

            // Get notified when flag changes
            if (DataVessel.RootPart != null)
            {
                KmlAttrib flag = DataVessel.RootPart.GetAttrib("flag");
                if (flag != null)
                {
                    flag.AttribValueChanged += DataVessel_FlagChanged;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Select the given item in the tree view.
        /// </summary>
        /// <param name="item">The KmlItem to select</param>
        /// <returns>Whether item was found or not</returns>
        public bool Select(KmlItem item)
        {
            // Stack will contain items parent nodes
            Stack <KmlNode> stack = new Stack <KmlNode>();

            // Search in KML, root node goes first onto the stack
            foreach (KmlNode node in KmlRoots)
            {
                stack.Push(node);
                if (SelectSearch(stack, item))
                {
                    break;
                }
                else
                {
                    stack.Pop();
                }
            }

            // This reverses the stack, so root node comes out first
            stack = new Stack <KmlNode>(stack);

            // Master node will be selected later,
            // if item is KmlNode, master = GuiTreeNode for item
            // otherwise, master = GuiTreeNode for item.Parent
            GuiTreeNode masterNode = null;

            // Expand recursively all parent nodes from stack, root first
            // Seach root in the Tree.Items
            foreach (GuiTreeNode treeNode in Tree.Items)
            {
                if (stack.Count > 0)
                {
                    KmlNode peek = stack.Peek();
                    if (treeNode.DataNode == peek)
                    {
                        stack.Pop();
                        masterNode          = treeNode;
                        treeNode.IsExpanded = true;
                        break;
                    }
                }
                else if (treeNode.DataNode == item)
                {
                    masterNode = treeNode;
                    break;
                }
            }

            if (masterNode == null)
            {
                // Item found nowhere
                return(false);
            }

            // Seach following nodes recursive in parent treeNode
            foreach (KmlNode node in stack)
            {
                foreach (GuiTreeNode treeNode in masterNode.Items)
                {
                    if (treeNode.DataNode == node)
                    {
                        // No need to pop, this is handled by foreach loop
                        masterNode = treeNode;
                        if (!(item is KmlAttrib) || item.Parent != treeNode.DataNode)
                        {
                            treeNode.IsExpanded = true;
                        }
                        break;
                    }
                }
            }

            // And now we can select and focus the item if it is a node, its parent otherwise
            if (item is KmlNode && masterNode.DataNode != item)
            {
                foreach (GuiTreeNode sub in masterNode.Items)
                {
                    if (sub.DataNode == item)
                    {
                        sub.BringIntoView();
                        // Force a refreh, by causing SelectionChanged to invoke
                        sub.IsSelected = false;
                        sub.IsSelected = true;
                        Focus();
                        break;
                    }
                }
            }
            else
            {
                masterNode.BringIntoView();
                // Force a refreh, by causing SelectionChanged to invoke
                masterNode.IsSelected = false;
                masterNode.IsSelected = true;
                Focus();
                if (item is KmlAttrib)
                {
                    foreach (GuiTreeAttrib attrib in TreeDetails.Items)
                    {
                        if (attrib.DataAttrib == item)
                        {
                            attrib.IsSelected = true;
                            TreeDetails.Focus();
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 12
0
        private void Search(bool continued = false)
        {
            const int SEARCHLIMIT = 100;

            List <KmlItem> list;

            // TODO DlgSearch.Search(): loading the list on every continuation isn't the best choice
            // but it's ok, because that is fast, only loading items into tree is slow
            list = GuiTabsManager.GetCurrent().TreeManager.Search(TextBoxInput.Text,
                                                                  CheckNodeTag.IsChecked == true, CheckNodeText.IsChecked == true,
                                                                  CheckAttribName.IsChecked == true, CheckAttribValue.IsChecked == true);

            _searchResults.Clear();
            _searchResults.AddRange(list);

            int          maxItemCount = SEARCHLIMIT;
            KmlNode      parentNode   = null;
            TreeViewItem parentItem   = null;

            if (continued)
            {
                _searchContinued++;
                maxItemCount = SEARCHLIMIT * (_searchContinued + 1);
                parentItem   = (TreeViewItem)Tree.Items[Tree.Items.Count - 1];
                parentNode   = list[maxItemCount - SEARCHLIMIT - 1].Parent;
            }
            else
            {
                _searchContinued = 0;
                Tree.Items.Clear();
            }
            for (int i = maxItemCount - SEARCHLIMIT; i < list.Count; i++)
            {
                KmlItem item = list[i];
                // if (Tree.Items.Count >= maxParentCount)
                if (i >= maxItemCount)
                {
                    TreeViewItem dummy = new TreeViewItem();
                    dummy.Header = "...";
                    TreeViewItem toBeContinued = new TreeViewItem();
                    toBeContinued.Header    = "... " + (list.Count - maxItemCount) + " more items ...";
                    toBeContinued.Expanded += ToBeContinued_Expanded;
                    toBeContinued.Items.Add(dummy);
                    Tree.Items.Add(toBeContinued);
                    return;
                }
                if (item is KmlNode || item is KmlAttrib)
                {
                    if (item.Parent != null && item.Parent != parentNode)
                    {
                        parentNode        = item.Parent;
                        parentItem        = new TreeViewItem();
                        parentItem.Header = item.Parent.PathToString(@"\");
                        Tree.Items.Add(parentItem);
                        parentItem.IsExpanded = true;
                    }
                    TreeViewItem node;
                    if (item is KmlNode)
                    {
                        node = new GuiTreeNode((KmlNode)item, true, true, true, false, true, false);
                    }
                    else
                    {
                        node             = new TreeViewItem();
                        node.DataContext = item;
                        node.Header      = item.ToString();
                    }
                    node.Margin = new Thickness(-16, 0, 0, 0);
                    if (parentNode == null)
                    {
                        Tree.Items.Add(node);
                    }
                    else
                    {
                        parentItem.Items.Add(node);
                    }
                    node.IsSelected = Tree.SelectedItem == null;
                }
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Add a child GuiTreeNode to this node.
 /// </summary>
 /// <param name="child">The GuiTreeNode to add</param>
 public void Add(GuiTreeNode child)
 {
     Items.Add(child);
 }
Esempio n. 14
0
        /// <summary>
        /// Add a child KmlNode to this node.
        /// A GuiTreeNode will be built around.
        /// </summary>
        /// <param name="child">The KmlNode to add</param>
        public void Add(KmlNode child)
        {
            GuiTreeNode node = new GuiTreeNode(child);

            Add(node);
        }
Esempio n. 15
0
        /// <summary>
        /// Select the given item in the tree view.
        /// </summary>
        /// <param name="item">The KmlItem to select</param>
        public void Select(KmlItem item)
        {
            // Stack will contain items parent nodes
            Stack <KmlNode> stack = new Stack <KmlNode>();

            // Search in KML, root node goes first onto the stack
            foreach (KmlNode node in KmlRoots)
            {
                stack.Push(node);
                if (!SelectSearch(stack, item))
                {
                    stack.Pop();
                }
            }

            // This reverses the stack, so root node comes out first
            stack = new Stack <KmlNode>(stack);

            // Expand recursively all parent nodes from stack, root first
            GuiTreeNode masterNode = null;

            // Seach root in the Tree.Items
            foreach (GuiTreeNode treeNode in Tree.Items)
            {
                if (treeNode.DataNode == stack.Peek())
                {
                    stack.Pop();
                    masterNode          = treeNode;
                    treeNode.IsExpanded = true;
                    break;
                }
            }
            if (masterNode == null)
            {
                // Some bullshit went horribly wrong
                return;
            }
            // Seach following nodes recursive in parent treeNode
            foreach (KmlNode node in stack)
            {
                foreach (GuiTreeNode treeNode in masterNode.Items)
                {
                    if (treeNode.DataNode == node)
                    {
                        // No need to pop, this is handled by foreach loop
                        masterNode          = treeNode;
                        treeNode.IsExpanded = true;
                        break;
                    }
                }
            }
            // And now we can select and focus the item if it is a node, it's parent otherwise
            if (item is KmlNode)
            {
                foreach (GuiTreeNode sub in masterNode.Items)
                {
                    if (sub.DataNode == item)
                    {
                        sub.BringIntoView();
                        sub.IsSelected = true;
                        Focus();
                        break;
                    }
                }
            }
            else
            {
                masterNode.BringIntoView();
                masterNode.IsSelected = true;
                Focus();
            }
        }