Beispiel #1
0
        /// <inheritdoc/>
        public override bool UIKeyPressed(KeyInfo key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            switch (key.VirtualKeyCode)
            {
            case KeyCode.LeftArrow:
            {
                if (!key.Is() && !key.IsAlt() || Far.Api.CommandLine.Length > 0)
                {
                    break;
                }

                FarFile file = CurrentFile;
                if (file == null)
                {
                    break;
                }

                TreeFile node = (TreeFile)file;
                if (node._State == 1)
                {
                    // reset
                    if (key.IsAlt())
                    {
                        node.ChildFiles.Clear();
                        node._State = 0;
                        UpdateRedraw(false);
                        return(true);
                    }

                    // collapse
                    OpenFile(file);
                }
                else if (node.Parent != null)
                {
                    PostFile(node.Parent);
                    Redraw();
                }

                return(true);
            }

            case KeyCode.RightArrow:
            {
                if (!key.Is() && !key.IsAlt() || Far.Api.CommandLine.Length > 0)
                {
                    break;
                }

                FarFile file = CurrentFile;
                if (file == null)
                {
                    break;
                }

                TreeFile node = (TreeFile)file;
                if (node != null && node._State != 1 && node.IsNode)
                {
                    // reset
                    if (key.IsAlt())
                    {
                        node.ChildFiles.Clear();
                        node._State = 0;
                    }

                    // open
                    OpenFile(file);
                }
                else
                {
                    // go to next
                    Redraw(CurrentIndex + 1, -1);
                }

                return(true);
            }
            }

            // base
            return(base.UIKeyPressed(key));
        }