private void OnKeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Enter && cbChildrenList.Visible)
     {
         IDNodeBase selNode = cbChildrenList.Tag as IDNodeBase;
         if (cbChildrenList.SelectedItem == null)
         {
             // Literal
             IDNodeBase node = selNode.ListBase.TrimNodes(selNode);
             node.Text      = cbChildrenList.Text;
             node.IsLiteral = true;
             cbChildrenList.Hide();
             RepositionControls();
             StoreID();
         }
         else
         {
             cbChildrenList.DroppedDown = false;
         }
     }
     else if (e.KeyChar == (char)Keys.Escape)
     {
         _noSelect = true;
         cbChildrenList.Hide();
         BuildAllSections();
         RepositionControls();
     }
 }
        /// <summary>
        /// Just selected something new
        /// </summary>
        /// <param name="newText"></param>
        public IDNodeBase NewSelection(IDNodeBase node, string newText)
        {
            // Remove trailing nodes until we reach the last node
            // NEVER remove the last node
            node = TrimNodes(node);
            // Now we are targeted at last node (Will be Property (incl literal) or Method)
            int index = newText.IndexOfAny(new char[] { '(', ';' });

            if (index >= 0)
            {
                // Method or property (or literal)
                node.Text = newText.Substring(0, index);
                if (newText[index] == '(')
                {
                    if (!(this is IDMethodList))
                    {
                        U.LogPopup("Expected method to be in IDMethodList '{0}'", newText);
                    }
                    // We are method.  Let's resetup all args
                    _mpIDCtl.BuildMethodArgs(newText.Substring(index + 1));
                }
                return(null);
            }
            else
            {
                // Path , Insert as Path
                InsertPathNode(newText);
                node.Text = string.Empty;
                return(node);
            }
        }
        private void OnMouseClick(object sender, MouseEventArgs e)
        {
            IDNodeBase selNode = (sender as Control).Tag as IDNodeBase;

            _noSelect = false;
            DropList(selNode);
        }
        /// <summary>
        /// Fill the combo box and select the first entry
        /// </summary>
        /// <param name="pathElement"></param>
        private void DropList(IDNodeBase selNode)
        {
            if (selNode == null)
            {
                return;
            }
            //_editing = true;
            IDListBase listBase = selNode.ListBase;

            cbChildrenList.Location = selNode.Location;
            cbChildrenList.Tag      = selNode;
            cbChildrenList.Items.Clear();

            // Add choice to de-select if target is path
            //if (listBase is IDPathList)
            //{
            //    cbChildrenList.Items.Add("");
            //}

            // Add component children
            selNode.AddComponents(cbChildrenList);

            selNode.AddMethodsOrProperties(cbChildrenList);

            _noSelect = true;
            int sel = cbChildrenList.FindString(selNode.Text);

            if (sel >= 0)
            {
                cbChildrenList.SelectedIndex = sel;
            }

            cbChildrenList.BringToFront();
            cbChildrenList.Show();
            cbChildrenList.Select();
            if (selNode.IsLiteral)
            {
                cbChildrenList.DropDownStyle   = ComboBoxStyle.DropDown;
                cbChildrenList.Text            = selNode.Text;
                cbChildrenList.SelectionStart  = 0;
                cbChildrenList.SelectionLength = selNode.Text.Length;
            }
            else
            {
                if (selNode.ListBase is IDPropertyList && selNode.IsFirst)
                {
                    cbChildrenList.DropDownStyle = ComboBoxStyle.DropDown;
                    cbChildrenList.Text          = "";
                    //cbChildrenList.Items.Insert(0, "");
                }
                else
                {
                    cbChildrenList.DropDownStyle = ComboBoxStyle.DropDownList;
                }
                cbChildrenList.DroppedDown = true;
            }

            _noSelect = false;
        }
        public IDNodeBase TrimNodes(IDNodeBase node)
        {
            int index = _list.IndexOf(node);

            while (index >= 0 && index < _list.Count - 1)
            {
                _list.RemoveAt(index);
                node.Clear();
                node = _list[index];
            }
            return(node);
        }
        public string BuildID(IDNodeBase nodeStop)
        {
            string id = string.Empty;

            foreach (IDNodeBase node in _list)
            {
                id += node.StoreText;
                if (object.ReferenceEquals(node, nodeStop))
                {
                    break;
                }
            }
            return(id.TrimStart('>'));
        }
        /// <summary>
        /// We just closed drop down.
        /// Did we finish? or is there more to select?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDropDownClosed(object sender, EventArgs e)
        {
            if (_noSelect || cbChildrenList.SelectedItem == null)
            {
                return;
            }

            IDNodeBase selNode = cbChildrenList.Tag as IDNodeBase;

            string newText = cbChildrenList.SelectedItem.ToString();

            IDNodeBase dropNode = selNode.ListBase.NewSelection(selNode, newText);

            cbChildrenList.Hide();
            RepositionControls();
            StoreID();
            DropList(dropNode);
        }
 public CompBase ParentCompOf(IDNodeBase node)
 {
     if (_list.Count > 0)
     {
         int index = _list.IndexOf(node);
         if (index < 0)
         {
             foreach (IDNodeBase nd in _list)
             {
                 index = _list.IndexOf(nd);
                 if (index < 0)
                 {
                     U.LogPopup("Node not found '{0}'.", nd.Text);
                 }
             }
         }
         if (index > 0)
         {
             return((_list[index - 1] as IDPath).Comp);
         }
     }
     return(_mpIDCtl.RootNode);
 }
 public bool IsFirst(IDNodeBase node)
 {
     return(object.ReferenceEquals(_list.First(), node));
 }