Example #1
0
        /// <summary>
        /// 通过这种方式设置路径的前提是有(初始化过)根节点
        /// </summary>
        /// <param name="path"></param>
        public void SetAddress(string path)
        {
            if (_rootNode == null)
            {
                return;
            }

            if (String.IsNullOrEmpty(path))
            {
                _currentNode = null;
                ResetBar();
                return;
            }

            //解释path找到当前节点,然后调用RestBar方法就可以了
            string[] pathArray = path.Split('/');
            _currentNode = _rootNode;
            for (int i = 0; i < pathArray.Length; i++)
            {
                foreach (IShengAddressNode node in _currentNode.Children)
                {
                    if (node.UniqueID == pathArray[i])
                    {
                        _currentNode = node;
                        break;
                    }
                }
            }
            ResetBar();
        }
Example #2
0
        /// <summary>
        /// Populates this node as a root node representing "My Computer"
        /// </summary>
        private void GenerateRootNode()
        {
            // if we have data, we can't become a root node.
            if (children != null)
            {
                return;
            }

            //get the display name of the first logical drive
            fullPath    = "";
            this.parent = null;

            //get our drives
            string[] drives = Environment.GetLogicalDrives();

            //create space for the children
            children = new ShengFileSystemNode[drives.Length];

            for (int i = 0; i < drives.Length; i++)
            {
                //create the child value
                children[i] = new ShengFileSystemNode(drives[i], this);
            }

            //get the icon
            GenerateNodeDisplayDetails();
        }
Example #3
0
        /// <summary>
        /// Creates a File System node with a given path
        /// </summary>
        /// <param name="path">Path that this node represents</param>
        /// <param name="depth">Integer represnting how deep in the hierarchy this node is</param>
        public ShengFileSystemNode(string path, ShengFileSystemNode parent)
        {
            //fill in the relevant details
            fullPath    = path;
            this.parent = parent;

            //get the icon
            GenerateNodeDisplayDetails();
        }
Example #4
0
        private ShengAddressBarDropDown GetButtonDropDown(IShengAddressNode addressNode)
        {
            ShengAddressBarDropDown dropDown = new ShengAddressBarDropDown();

            if (this.DropDownRenderer != null)
            {
                dropDown.Renderer = this.DropDownRenderer;
            }

            dropDown.LayoutStyle = ToolStripLayoutStyle.Table;
            dropDown.MaximumSize = new Size(1000, 400);
            dropDown.Opening    += new CancelEventHandler(DropDown_Opening);

            /*
             * This is the primary bottleneck for this app, creating all the necessary drop-down menu items.
             *
             * To optimize performance of this control, this is the main area that needs tuning.
             */

            IShengAddressNode curNode = null;

            for (int i = 0; i < addressNode.Children.Length; i++)
            {
                curNode = (IShengAddressNode)addressNode.Children.GetValue(i);

                ShengAddressBarDropDownItem tsb = null;

                tsb = new ShengAddressBarDropDownItem(curNode.DisplayName, curNode.Icon, NodeButtonClicked);

                tsb.AddressNode = curNode;

                tsb.Overflow = ToolStripItemOverflow.AsNeeded;

                dropDown.Items.Add(tsb); //THIS IS THE BIGGEST BOTTLENECK. LOTS OF TIME SPENT IN/CALLING THIS METHOD!
            }

            addressNode.DropDownMenu = dropDown;

            dropDown.LayoutStyle = ToolStripLayoutStyle.Table;
            dropDown.MaximumSize = new Size(1000, 400);

            dropDown.AddressNode = addressNode;

            //不起作用
            dropDown.MouseWheel += new MouseEventHandler(ScrollDropDownMenu);
            dropDown.MouseEnter += new EventHandler(GiveToolStripDropDownMenuFocus);

            return(dropDown);
        }
Example #5
0
        /// <summary>
        /// Method to handle when a mode is double clicked
        /// </summary>
        /// <param name="sender">Sender of this event</param>
        /// <param name="e">Event arguments</param>
        private void NodeDoubleClickHandler(Object sender, EventArgs e)
        {
            //check we are handlign the double click event
            if (NodeDoubleClick != null && sender.GetType() == typeof(ShengAddressBarButton))
            {
                //get the node from the tag
                _currentNode = ((ShengAddressBarDropDownItem)sender).AddressNode;

                //create the node changed event arguments
                NodeChangedArgs nca = new NodeChangedArgs(_currentNode.UniqueID);

                //fire the event
                NodeDoubleClick(this, nca);
            }
        }
Example #6
0
        /// <summary>
        /// Method to handle when a child has been selected from a node
        /// </summary>
        /// <param name="sender">Sender of this Event</param>
        /// <param name="e">Event Arguments</param>
        private void NodeButtonClicked(Object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(ShengAddressBarDropDownItem) || sender.GetType() == typeof(ShengAddressBarButton))
            {
                IShengAddressNode addressNode;

                if (sender.GetType() == typeof(ShengAddressBarDropDownItem))
                {
                    ShengAddressBarDropDownItem tsb = (ShengAddressBarDropDownItem)sender;
                    addressNode = tsb.AddressNode;
                }
                else
                {
                    ShengAddressBarButton tsb = (ShengAddressBarButton)sender;
                    addressNode = tsb.AddressNode;
                }

                //set the current node
                _currentNode = addressNode;

                //cxs
                //用不着整个都重新加载,在当前最后一个Item后面加上点的这个就行了
                //但是要额外考虑点击的是哪个下拉按钮,如果是中间的,还是要整个刷
                ResetBar();
                //if (sender.GetType().Equals(typeof(SEAddressBarButton)))
                //{
                //    UpdateBar();
                //}
                //else
                //{
                //    AddToolStripItemUpdate(ref _currentNode,ButtonPosition.Behind);
                //}

                //if the selection changed event is handled
                if (SelectionChange != null)
                {
                    NodeChangedArgs args = new NodeChangedArgs(_currentNode.UniqueID);
                    SelectionChange(this, args);
                }

                return;
            }
        }
Example #7
0
        /// <summary>
        /// 根据IAddressNode地址栏对象,创建并添加一个地址栏按钮
        /// </summary>
        /// <param name="node">The node to base the item on</param>
        /// <returns>Built SEAddressBarDropDownItem. Returns Null if method failed</returns>
        private void AddToolStripItemUpdate(IShengAddressNode node, ButtonPosition position)
        {
            ShengAddressBarButton tsButton = null;

            node.CreateChildNodes();

            tsButton = new ShengAddressBarButton(node.DisplayName, node.Icon, NodeButtonClicked);

            tsButton.AddressNode        = node;
            tsButton.ImageAlign         = ContentAlignment.MiddleCenter;
            tsButton.DoubleClickEnabled = true;
            tsButton.DoubleClick       += new EventHandler(NodeDoubleClickHandler);

            AddAddressBarButton(tsButton, position);

            if (IsManyNodes())
            {
                CreateOverflowDropDown();
            }
        }
Example #8
0
        private void DropDown_Opening(object sender, CancelEventArgs e)
        {
            ShengAddressBarDropDown dropDown = sender as ShengAddressBarDropDown;

            //dropDown.Left = dropDown.Left - 20;

            #region 把当前选中项加粗

            IShengAddressNode nextAddressNode = null;
            for (int i = 0; i < _buttonList.Count; i++)
            {
                //如果是当前点击的向下箭头
                if (_buttonList[i].DropDownButton != null && _buttonList[i].DropDownButton.DropDown == dropDown)
                {
                    //拿出当前点的地址栏按钮向下箭头的下一个地址栏项目
                    //如果为空,则表示当前点的是最右边的了,那就不去匹配了,也没得匹配
                    if ((i + 1) < _buttonList.Count)
                    {
                        nextAddressNode = _buttonList[i + 1].AddressNode;
                        break;
                    }
                }
            }

            if (nextAddressNode != null)
            {
                foreach (ShengAddressBarDropDownItem item in dropDown.Items)
                {
                    //在使用SetAddress逆向初始化节点时
                    //会出现item.AddressNode 和 nextAddressNode不是一个对象的情况
                    //所以需要UniqueID来判断
                    if (item.AddressNode.UniqueID.Equals(nextAddressNode.UniqueID))
                    {
                        item.Font = new Font(item.Font, this._selectedStyle);
                        break;
                    }
                }
            }

            #endregion
        }
Example #9
0
        /// <summary>
        /// 初始化根节点
        /// </summary>
        /// <param name="rootNode"></param>
        public void InitializeRoot(IShengAddressNode rootNode)
        {
            //remove all items
            this.Items.Clear();
            this._rootNode = null;

            if (rootNode != null)
            {
                //create the root node
                this._rootNode = rootNode.Clone();

                //force update the node
                this._rootNode.CreateChildNodes();

                //set the current node to be the root
                this._currentNode = this._rootNode;

                //update the address bar
                ResetBar();
            }
        }
Example #10
0
        /// <summary>
        /// 创建指定地址栏项的子级(如果需要)
        /// </summary>
        /// <param name="button"></param>
        private void BuildChildItem(ShengAddressBarButton button)
        {
            IShengAddressNode addressNode = button.AddressNode;

            ShengAddressBarDropDownButton dropDownButton = null;

            //SEAddressBarDropDown dropDown = null;

            if (addressNode.Children != null && addressNode.Children.Length > 0)
            {
                dropDownButton        = new ShengAddressBarDropDownButton(String.Empty);
                button.DropDownButton = dropDownButton;

                //check if we have any tag data (we cache already built drop down items in the node TAG data.
                if (addressNode.DropDownMenu == null)
                {
                    addressNode.DropDownMenu = GetButtonDropDown(addressNode);
                }
                else
                {
                    if (addressNode.DropDownMenu.GetType() == typeof(ShengAddressBarDropDown))
                    {
                        //dropDown = (SEAddressBarDropDown)addressNode.DropDownMenu;

                        foreach (ShengAddressBarDropDownItem tsmi in addressNode.DropDownMenu.Items)
                        {
                            if (tsmi.Font.Style != _baseFont.Style)
                            {
                                tsmi.Font = _baseFont;
                            }
                        }
                    }
                }

                dropDownButton.DropDown     = addressNode.DropDownMenu;
                dropDownButton.DisplayStyle = ToolStripItemDisplayStyle.None;
                dropDownButton.ImageAlign   = ContentAlignment.MiddleCenter;
            }
        }
Example #11
0
        /// <summary>
        /// 刷新(重新加载)整个地址栏
        /// </summary>
        private void ResetBar()
        {
            _buttonList.Clear();

            this.Items.Clear();

            //check we have a valid root
            if (_currentNode == null && _rootNode == null)
            {
                return;
            }

            //update the current node, if it doesn't exist
            if (_currentNode == null)
            {
                _currentNode = _rootNode;
            }

            IShengAddressNode tempNode = _currentNode;

            //从当前节点向上逐级添加
            //while (tempNode.Parent != null)
            while (tempNode != null)
            {
                AddToolStripItemUpdate(tempNode, ButtonPosition.Front);

                if (tempNode.Parent == null)
                {
                    _rootNode = tempNode;
                }

                tempNode = tempNode.Parent;
            }

            //添加根节点
            //if (_rootNode != null && _rootNode.UniqueID != tempNode.UniqueID)
            //    AddToolStripItemUpdate(_rootNode, ButtonPosition.Front);
        }
Example #12
0
 public void SetAddress(IShengAddressNode addressNode)
 {
     _currentNode = addressNode;
     ResetBar();
 }
 public void SetAddress(IShengAddressNode addressNode)
 {
     addressBarStrip.SetAddress(addressNode);
 }
 public void InitializeRoot(IShengAddressNode rootNode)
 {
     addressBarStrip.InitializeRoot(rootNode);
 }