public override void SetUp()
        {
            base.SetUp();

            _htmlHelper      = new HtmlHelper();
            _httpContextStub = MockRepository.GenerateStub <HttpContextBase> ();

            _control = MockRepository.GenerateStub <IListMenu>();
            _control.Stub(stub => stub.UniqueID).Return("MyListMenu");
            _control.Stub(stub => stub.ClientID).Return("MyListMenu");
            _control.Stub(stub => stub.MenuItems).Return(new WebMenuItemCollection(_control));

            _control.Stub(stub => stub.Enabled).Return(true);
            _control.Stub(stub => stub.HasClientScript).Return(true);
            _control.Stub(stub => stub.ResolveClientUrl(null)).IgnoreArguments().Do((Func <string, string>)(url => url.TrimStart('~')));
            _control.Stub(stub => stub.GetUpdateScriptReference("null")).Return("Update();");

            var pageStub = MockRepository.GenerateStub <IPage>();

            _clientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager>();
            pageStub.Stub(page => page.ClientScript).Return(_clientScriptManagerMock);

            _control.Stub(stub => stub.Page).Return(pageStub);

            _resourceUrlFactory = new FakeResourceUrlFactory();

            PopulateMenu();
        }
Beispiel #2
0
        protected override void BeginProcessing()
        {
            _menu = Create();

            if (IncrementalOptions == PatternOptions.None)
                _menu.IncrementalOptions = PatternOptions.Substring;
        }
Beispiel #3
0
        public UIWordMenu(List <string> words, string word, int column, int line)
        {
            // menu
            _menu           = Far.Api.CreateListMenu();
            _menu.Title     = word;
            _menu.NoInfo    = true;
            _menu.X         = column;
            _menu.Y         = line;
            _menu.HelpTopic = Far.Api.GetHelpTopic("correction-list");

            // menu keys
            _menu.AddKey(KeyCode.D1);
            _menu.AddKey(KeyCode.D2);
            _menu.AddKey(KeyCode.D3);

            // menu items
            foreach (var it in words)
            {
                _menu.Add(it);
            }

            // menu commands
            _menu.Add(string.Empty).IsSeparator = true;
            _itemIgnore          = _menu.Add(My.DoIgnore);
            _itemIgnoreAll       = _menu.Add(My.DoIgnoreAll);
            _itemAddToDictionary = _menu.Add(My.DoAddToDictionary);
        }
        public void SetUp()
        {
            _htmlHelper      = new HtmlHelper();
            _httpContextStub = MockRepository.GenerateStub <HttpContextBase>();

            _control = MockRepository.GenerateStub <IListMenu>();
            _control.Stub(stub => stub.UniqueID).Return("MyListMenu");
            _control.Stub(stub => stub.ClientID).Return("MyListMenu");
            _control.Stub(stub => stub.ControlType).Return("ListMenu");
            _control.Stub(stub => stub.MenuItems).Return(new WebMenuItemCollection(_control));

            _control.Stub(stub => stub.Enabled).Return(true);
            _control.Stub(stub => stub.HasClientScript).Return(true);
            _control.Stub(stub => stub.ResolveClientUrl(null)).IgnoreArguments().Do((Func <string, string>)(url => url.TrimStart('~')));
            _control.Stub(stub => stub.GetUpdateScriptReference("null")).Return("Update();");

            var pageStub = MockRepository.GenerateStub <IPage>();

            _clientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager>();
            pageStub.Stub(page => page.ClientScript).Return(_clientScriptManagerMock);

            _control.Stub(stub => stub.Page).Return(pageStub);

            PopulateMenu();

            var serviceLocator = DefaultServiceLocator.Create();

            serviceLocator.RegisterSingle <IRenderingFeatures> (() => RenderingFeatures.WithDiagnosticMetadata);
            _serviceLocatorScope = new ServiceLocatorScope(serviceLocator);
        }
Beispiel #5
0
        protected override void BeginProcessing()
        {
            _menu = Create();

            if (IncrementalOptions == PatternOptions.None)
            {
                _menu.IncrementalOptions = PatternOptions.Substring;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Sets the list menu template.
 /// </summary>
 /// <param name="menu">The menu with default properties.</param>
 public void ListMenu(IListMenu menu)
 {
     if (menu == null)
     {
         throw new ArgumentNullException("menu");
     }
     menu.ScreenMargin = _ListMenuScreenMargin;
     menu.UsualMargins = _ListMenuUsualMargins;
 }
Beispiel #7
0
 /// <summary>
 /// Sets the popup list menu template.
 /// </summary>
 /// <param name="menu">The menu with default properties.</param>
 public void PopupMenu(IListMenu menu)
 {
     if (menu == null)
     {
         throw new ArgumentNullException("menu");
     }
     menu.AutoSelect = _PopupAutoSelect;
     menu.MaxHeight  = _PopupMaxHeight;
     menu.NoShadow   = _PopupNoShadow;
 }
Beispiel #8
0
        public DebuggerMenu()
        {
            _menu = Far.Api.CreateListMenu();
            _menu.Title = "PowerShell debugger tools";
            _menu.HelpTopic = Far.Api.GetHelpTopic("MenuDebugger");
            _menu.NoInfo = true;
            _menu.ScreenMargin = Settings.Default.ListMenuScreenMargin;
            _menu.UsualMargins = Settings.Default.ListMenuUsualMargins;

            _menu.AddKey(KeyCode.Delete, ControlKeyStates.None, OnDelete);
            _menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed, OnDeleteAll);
            _menu.AddKey(KeyCode.F4, ControlKeyStates.None, OnEdit);
            _menu.AddKey(KeyCode.Backspace, ControlKeyStates.ShiftPressed, OnDisableAll);
            _menu.AddKey(KeyCode.Spacebar, ControlKeyStates.None, OnToggle);
        }
Beispiel #9
0
        public DebuggerMenu()
        {
            _menu              = Far.Api.CreateListMenu();
            _menu.Title        = "PowerShell debugger tools";
            _menu.HelpTopic    = Far.Api.GetHelpTopic(HelpTopic.DebuggerMenu);
            _menu.NoInfo       = true;
            _menu.ScreenMargin = Settings.Default.ListMenuScreenMargin;
            _menu.UsualMargins = Settings.Default.ListMenuUsualMargins;

            _menu.AddKey(KeyCode.Delete, ControlKeyStates.None, OnDelete);
            _menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed, OnDeleteAll);
            _menu.AddKey(KeyCode.F4, ControlKeyStates.None, OnEdit);
            _menu.AddKey(KeyCode.Backspace, ControlKeyStates.ShiftPressed, OnDisableAll);
            _menu.AddKey(KeyCode.Spacebar, ControlKeyStates.None, OnToggle);
        }
Beispiel #10
0
        public CommandHistoryMenu(string prefix)
        {
            _menu = Far.Api.CreateListMenu();
            Settings.Default.ListMenu(_menu);

            _menu.HelpTopic = Far.Api.GetHelpTopic("MenuCommandHistory");
            _menu.SelectLast = true;
            _menu.Title = "PowerShell history";

            _menu.Incremental = prefix;
            _menu.IncrementalOptions = PatternOptions.Substring;

            _menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed, OnDelete);
            _menu.AddKey(KeyCode.Delete, ControlKeyStates.None, OnDelete);
        }
Beispiel #11
0
        /// <summary>
        /// New history UI.
        /// </summary>
        /// <param name="history">The connected history log.</param>
        public HistoryMenu(HistoryLog history)
        {
            _history = history;

            Menu = Far.Api.CreateListMenu();

            Menu.IncrementalOptions = PatternOptions.Substring;
            Menu.ScreenMargin       = 2;
            Menu.SelectLast         = true;
            Menu.Title        = "History";
            Menu.UsualMargins = true;

            Menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed, OnDelete);
            Menu.AddKey(KeyCode.Delete, ControlKeyStates.None, OnDelete);
        }
Beispiel #12
0
        internal IListMenu Create()
        {
            IListMenu menu = Far.Api.CreateListMenu();

            Init(menu);

            if (Popup)
            {
                Settings.Default.PopupMenu(menu);
            }
            else
            {
                Settings.Default.ListMenu(menu);
            }

            if (_setAutoSelect)
            {
                menu.AutoSelect = _AutoSelect;
            }
            if (_setIncremental)
            {
                menu.Incremental = _Incremental;
            }
            if (_setIncrementalOptions)
            {
                menu.IncrementalOptions = _IncrementalOptions;
            }
            if (_setNoShadow)
            {
                menu.NoShadow = _NoShadow;
            }
            if (_setScreenMargin)
            {
                menu.ScreenMargin = _ScreenMargin;
            }
            if (_setUsualMargins)
            {
                menu.UsualMargins = _UsualMargins;
            }

            return(menu);
        }
Beispiel #13
0
        public UIWordMenu(List<string> words, string word, int column, int line)
        {
            // menu
            _menu = Far.Api.CreateListMenu();
            _menu.Title = word;
            _menu.NoInfo = true;
            _menu.X = column;
            _menu.Y = line;

            // menu keys
            _menu.AddKey(KeyCode.D1);
            _menu.AddKey(KeyCode.D2);
            _menu.AddKey(KeyCode.D3);

            // menu items
            foreach (var it in words)
                _menu.Add(it);

            // menu commands
            _menu.Add(string.Empty).IsSeparator = true;
            _itemIgnore = _menu.Add(My.DoIgnore);
            _itemIgnoreAll = _menu.Add(My.DoIgnoreAll);
            _itemAddToDictionary = _menu.Add(My.DoAddToDictionary);
        }
Beispiel #14
0
        static void ShowHistory()
        {
            var limit  = Settings.Default.Limit0;
            var factor = Settings.Default.Factor1;

            IListMenu menu = Far.Api.CreateListMenu();

            menu.HelpTopic    = HelpTopic + "FileHistory";
            menu.SelectLast   = true;
            menu.UsualMargins = true;
            menu.Title        = string.Format("File history ({0}/{1})", limit, factor);

            menu.IncrementalOptions = PatternOptions.Substring;

            menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.F3);
            menu.AddKey(KeyCode.F3, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.F4);
            menu.AddKey(KeyCode.F4, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed);

            for (; ; menu.Items.Clear())
            {
                var actor     = new Actor(0, null);
                int lastGroup = -1;
                foreach (var it in actor.GetHistory(DateTime.Now, factor))
                {
                    // separator
                    int nextGroup = it.Group(limit, factor);
                    if (lastGroup != nextGroup)
                    {
                        if (lastGroup > 0)
                        {
                            menu.Add("").IsSeparator = true;
                        }

                        lastGroup = nextGroup;
                    }

                    // item
                    var item = menu.Add(it.Path);
                    item.Data = it;
                    if (it.Evidence > 0)
                    {
                        item.Checked = true;
                    }
                }

show:

                //! show and check the result or after Esc index may be > 0
                //! e.g. ShiftDel the last record + Esc == index out of range
                if (!menu.Show() || menu.Selected < 0)
                {
                    return;
                }

                // update:
                if (menu.Key.IsCtrl(KeyCode.R))
                {
                    var algo = new Actor(0, VesselHost.LogPath[0], true);
                    algo.Update();
                    continue;
                }

                // the file
                int    indexSelected = menu.Selected;
                string path          = menu.Items[indexSelected].Text;

                // delete:
                if (menu.Key.IsShift(KeyCode.Delete))
                {
                    if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel))
                    {
                        Store.Remove(0, VesselHost.LogPath[0], path);
                        continue;
                    }

                    goto show;
                }

                // missing?
                if (!File.Exists(path))
                {
                    Far.Api.Message("File does not exist.");
                    goto show;
                }

                // if it is not logged yet, log the existing Far record(s)
                if (!actor.IsLoggedPath(path))
                {
                    var info = menu.Items[indexSelected].Data as Info;
                    Store.Append(VesselHost.LogPath[0], info.Head, Record.GOTO, path);
                    if (info.Head != info.Tail)
                    {
                        Store.Append(VesselHost.LogPath[0], info.Tail, Record.GOTO, path);
                    }
                }

                // go to:
                if (menu.Key.IsCtrl(KeyCode.Enter))
                {
                    Far.Api.Panel.GoToPath(path);
                    Store.Append(VesselHost.LogPath[0], DateTime.Now, Record.GOTO, path);
                }
                // view:
                else if (menu.Key.VirtualKeyCode == KeyCode.F3)
                {
                    IViewer viewer = Far.Api.CreateViewer();
                    viewer.FileName = path;

                    viewer.Closed += delegate
                    {
                        Store.Append(VesselHost.LogPath[0], DateTime.Now, Record.VIEW, path);
                    };

                    if (menu.Key.IsCtrl())
                    {
                        viewer.Open(OpenMode.Modal);
                        goto show;
                    }

                    viewer.Open();
                }
                // edit:
                else
                {
                    IEditor editor = Far.Api.CreateEditor();
                    editor.FileName = path;

                    editor.Closed += delegate
                    {
                        Store.Append(VesselHost.LogPath[0], DateTime.Now, Record.EDIT, path);
                    };

                    if (menu.Key.IsCtrl(KeyCode.F4))
                    {
                        editor.Open(OpenMode.Modal);
                        goto show;
                    }

                    editor.Open();

                    if (menu.Key.IsShift(KeyCode.Enter))
                    {
                        goto show;
                    }
                }

                UpdatePeriodically(0);
                return;
            }
        }
Beispiel #15
0
        static void ShowCommands()
        {
            var mode  = 2;
            var store = VesselHost.LogPath[mode];
            var limit = Settings.Default.Limit0;

            IListMenu menu = Far.Api.CreateListMenu();

            menu.HelpTopic    = HelpTopic + "command-history";
            menu.SelectLast   = true;
            menu.UsualMargins = true;
            menu.Title        = $"Command history ({limit})";

            menu.IncrementalOptions = PatternOptions.Substring;

            menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed);

            for (; ; menu.Items.Clear())
            {
                var actor     = new Actor(mode, store);
                int lastGroup = -1;
                foreach (var it in actor.GetHistory(DateTime.Now))
                {
                    // separator
                    int nextGroup = it.Group(limit);
                    if (lastGroup != nextGroup)
                    {
                        if (lastGroup > 0)
                        {
                            menu.Add("").IsSeparator = true;
                        }
                        lastGroup = nextGroup;
                    }

                    // item
                    var item = menu.Add(it.Path);
                    item.Data = it;
                    if (it.Evidence > 0)
                    {
                        item.Checked = true;
                    }
                }

show:

                //! show and check the result or after Esc index may be > 0
                //! e.g. ShiftDel the last record + Esc == index out of range
                if (!menu.Show() || menu.Selected < 0)
                {
                    return;
                }

                // update:
                if (menu.Key.IsCtrl(KeyCode.R))
                {
                    var algo = new Actor(mode, store, true);
                    algo.Update();
                    continue;
                }

                // the command
                int    indexSelected = menu.Selected;
                string path          = menu.Items[indexSelected].Text;

                // delete:
                if (menu.Key.IsShift(KeyCode.Delete))
                {
                    if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel))
                    {
                        Store.Remove(store, path, StringComparison.Ordinal);
                        continue;
                    }
                    goto show;
                }

                // Enter | CtrlEnter:
                if (Far.Api.Window.Kind != WindowKind.Panels && !Far.Api.Window.IsModal)
                {
                    Far.Api.Window.SetCurrentAt(-1);
                }

                // put command
                Far.Api.CommandLine.Text = path;

                // invoke command
                if (!menu.Key.IsCtrl())
                {
                    Far.Api.PostMacro("Keys'Enter'");
                }

                // if it is not logged yet, log the existing Far record
                if (!actor.IsLoggedPath(path))
                {
                    var info = menu.Items[indexSelected].Data as Info;
                    Store.Append(store, info.Head, Record.OPEN, path);
                }
                // then log the current record
                Store.Append(store, DateTime.Now, Record.OPEN, path);

                UpdatePeriodically(mode);
                return;
            }
        }
Beispiel #16
0
        static void ShowHistory(bool smart)
        {
            var Factor1 = Settings.Default.Factor1;
            var Factor2 = Settings.Default.Factor2;
            var Limit0  = Settings.Default.Limit0;

            // drop smart for the negative factor
            if (smart && Factor1 < 0)
            {
                smart = false;
            }

            IListMenu menu = Far.Api.CreateListMenu();

            menu.HelpTopic    = HelpTopic + "FileHistory";
            menu.SelectLast   = true;
            menu.UsualMargins = true;
            if (smart)
            {
                menu.Title = string.Format("File history ({0}/{1}/{2})", Limit0, Factor1, Factor2);
            }
            else
            {
                menu.Title = "File history (plain)";
            }

            menu.IncrementalOptions = PatternOptions.Substring;

            menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.F3);
            menu.AddKey(KeyCode.F3, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.F4);
            menu.AddKey(KeyCode.F4, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed);

            for (; ; menu.Items.Clear())
            {
                int group1      = -1;
                int indexLimit0 = int.MaxValue;
                foreach (var it in Record.GetHistory(null, DateTime.Now, (smart ? Factor1 : -1), Factor2))
                {
                    // separator
                    if (smart)
                    {
                        int group2 = it.Group(Limit0, Factor1, Factor2);
                        if (group1 != group2)
                        {
                            if (group1 >= 0)
                            {
                                menu.Add("").IsSeparator = true;
                                if (group2 == 0)
                                {
                                    indexLimit0 = menu.Items.Count;
                                }
                            }
                            group1 = group2;
                        }
                    }

                    // item
                    menu.Add(it.Path).Checked = it.Evidence > 0;
                }

show:

                //! show and check the result or after Esc index may be > 0
                //! e.g. ShiftDel the last record + Esc == index out of range
                if (!menu.Show() || menu.Selected < 0)
                {
                    return;
                }

                // update:
                if (menu.Key.IsCtrl(KeyCode.R))
                {
                    var algo = new Actor(VesselHost.LogPath);
                    algo.Update();
                    continue;
                }

                // the file
                int    indexSelected = menu.Selected;
                string path          = menu.Items[indexSelected].Text;

                // delete:
                if (menu.Key.IsShift(KeyCode.Delete))
                {
                    if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel))
                    {
                        Record.Remove(VesselHost.LogPath, path);
                        continue;
                    }

                    goto show;
                }

                // go to:
                if (menu.Key.IsCtrl(KeyCode.Enter))
                {
                    Far.Api.Panel.GoToPath(path);
                }
                // view:
                else if (menu.Key.VirtualKeyCode == KeyCode.F3)
                {
                    if (!File.Exists(path))
                    {
                        continue;
                    }

                    IViewer viewer = Far.Api.CreateViewer();
                    viewer.FileName = path;

                    if (menu.Key.IsCtrl())
                    {
                        viewer.DisableHistory = true;
                        viewer.Open(OpenMode.Modal);
                        goto show;
                    }

                    viewer.Open();

                    // post fast training
                    if (smart && indexSelected < indexLimit0)
                    {
                        VesselHost.PathToTrain = path;
                    }
                }
                // edit:
                else
                {
                    IEditor editor = Far.Api.CreateEditor();
                    editor.FileName = path;

                    if (menu.Key.IsCtrl(KeyCode.F4))
                    {
                        editor.DisableHistory = true;
                        editor.Open(OpenMode.Modal);
                        goto show;
                    }

                    editor.Open();

                    if (menu.Key.IsShift(KeyCode.Enter))
                    {
                        goto show;
                    }

                    // post fast training
                    if (smart && indexSelected < indexLimit0)
                    {
                        VesselHost.PathToTrain = path;
                    }
                }

                UpdateOnce();
                return;
            }
        }
Beispiel #17
0
        public static void CompleteText(ILine editLine, string tail, string line, string lastWord, IEnumerable words)
        {
            // menu
            IListMenu menu   = Far.Api.CreateListMenu();
            var       cursor = Far.Api.UI.WindowCursor;

            menu.X = cursor.X;
            menu.Y = cursor.Y;
            Settings.Default.PopupMenu(menu);
            menu.Incremental        = lastWord + "*";
            menu.IncrementalOptions = PatternOptions.Prefix;

            foreach (var it in words)
            {
                if (it == null)
                {
                    continue;
                }

                var candidate = it.ToString();
                if (candidate.Length == 0)
                {
                    menu.Add(string.Empty).IsSeparator = true;
                    continue;
                }

                if (lastWord.Length == 0 || candidate.StartsWith(lastWord, StringComparison.OrdinalIgnoreCase))
                {
                    menu.Add(candidate);
                }
            }

            if (menu.Items.Count == 0)
            {
                menu.Add(Res.Empty).Disabled = true;
                menu.NoInfo = true;
                menu.Show();
                return;
            }

            string word;

            if (menu.Items.Count == 1)
            {
                word = menu.Items[0].Text;
            }
            else
            {
                // show menu
                if (!menu.Show())
                {
                    return;
                }

                word = menu.Items[menu.Selected].Text;
            }

            // expand last word

            // head before the last word
            line = line.Substring(0, line.Length - lastWord.Length);

            // new caret
            int caret = line.Length + word.Length;

            // set new text = old head + expanded + old tail
            editLine.Text = line + word + tail;

            // set caret
            editLine.Caret = caret;
        }
Beispiel #18
0
        static void ShowFolders()
        {
            var limit  = Settings.Default.Limit0;
            var factor = Settings.Default.Factor2;

            IListMenu menu = Far.Api.CreateListMenu();

            menu.HelpTopic    = HelpTopic + "FolderHistory";
            menu.SelectLast   = true;
            menu.UsualMargins = true;
            menu.Title        = string.Format("Folder history ({0}/{1})", limit, factor);

            menu.IncrementalOptions = PatternOptions.Substring;

            menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed);

            for (; ; menu.Items.Clear())
            {
                int lastGroup = -1;
                foreach (var it in Store.GetHistory(1, null, DateTime.Now, factor))
                {
                    // separator
                    int nextGroup = it.Group(limit, factor);
                    if (lastGroup != nextGroup)
                    {
                        if (lastGroup > 0)
                        {
                            menu.Add("").IsSeparator = true;
                        }
                        lastGroup = nextGroup;
                    }

                    // item
                    menu.Add(it.Path).Checked = it.Evidence > 0;
                }

show:

                //! show and check the result or after Esc index may be > 0
                //! e.g. ShiftDel the last record + Esc == index out of range
                if (!menu.Show() || menu.Selected < 0)
                {
                    return;
                }

                // update:
                if (menu.Key.IsCtrl(KeyCode.R))
                {
                    var algo = new Actor(1, VesselHost.LogPath[1], true);
                    algo.Update();
                    continue;
                }

                // the folder
                int    indexSelected = menu.Selected;
                string path          = menu.Items[indexSelected].Text;

                // delete:
                if (menu.Key.IsShift(KeyCode.Delete))
                {
                    if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel))
                    {
                        Store.Remove(1, VesselHost.LogPath[1], path);
                        continue;
                    }
                    goto show;
                }

                // Enter:
                if (Far.Api.Window.Kind != WindowKind.Panels && !Far.Api.Window.IsModal)
                {
                    Far.Api.Window.SetCurrentAt(-1);
                }

                Far.Api.Panel.CurrentDirectory = path;
                Store.Append(VesselHost.LogPath[1], DateTime.Now, Record.OPEN, path);

                UpdatePeriodically(1);
                return;
            }
        }
Beispiel #19
0
        static void ShowHistory()
        {
            var factor0 = Settings.Default.Limit0;
            var factor1 = Settings.Default.Factor1;

            IListMenu menu = Far.Api.CreateListMenu();

            menu.HelpTopic    = HelpTopic + "FileHistory";
            menu.SelectLast   = true;
            menu.UsualMargins = true;
            menu.Title        = string.Format("File history ({0}/{1})", factor0, factor1);

            menu.IncrementalOptions = PatternOptions.Substring;

            menu.AddKey(KeyCode.Delete, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.Enter, ControlKeyStates.ShiftPressed);
            menu.AddKey(KeyCode.F3);
            menu.AddKey(KeyCode.F3, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.F4);
            menu.AddKey(KeyCode.F4, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.R, ControlKeyStates.LeftCtrlPressed);

            for (; ; menu.Items.Clear())
            {
                int lastGroup = -1;
                foreach (var it in Store.GetHistory(0, null, DateTime.Now, factor1))
                {
                    // separator
                    int nextGroup = it.Group(factor0, factor1);
                    if (lastGroup != nextGroup)
                    {
                        if (lastGroup > 0)
                        {
                            menu.Add("").IsSeparator = true;
                        }

                        lastGroup = nextGroup;
                    }

                    // item
                    menu.Add(it.Path).Checked = it.Evidence > 0;
                }

show:

                //! show and check the result or after Esc index may be > 0
                //! e.g. ShiftDel the last record + Esc == index out of range
                if (!menu.Show() || menu.Selected < 0)
                {
                    return;
                }

                // update:
                if (menu.Key.IsCtrl(KeyCode.R))
                {
                    var algo = new Actor(0, VesselHost.LogPath[0]);
                    algo.Update();
                    continue;
                }

                // the file
                int    indexSelected = menu.Selected;
                string path          = menu.Items[indexSelected].Text;

                // delete:
                if (menu.Key.IsShift(KeyCode.Delete))
                {
                    if (0 == Far.Api.Message("Discard " + path, "Confirm", MessageOptions.OkCancel))
                    {
                        Store.Remove(0, VesselHost.LogPath[0], path);
                        continue;
                    }

                    goto show;
                }

                // go to:
                if (menu.Key.IsCtrl(KeyCode.Enter))
                {
                    Far.Api.Panel.GoToPath(path);
                }
                // view:
                else if (menu.Key.VirtualKeyCode == KeyCode.F3)
                {
                    if (!File.Exists(path))
                    {
                        continue;
                    }

                    IViewer viewer = Far.Api.CreateViewer();
                    viewer.FileName = path;

                    if (menu.Key.IsCtrl())
                    {
                        viewer.DisableHistory = true;
                        viewer.Open(OpenMode.Modal);
                        goto show;
                    }

                    viewer.Open();
                }
                // edit:
                else
                {
                    IEditor editor = Far.Api.CreateEditor();
                    editor.FileName = path;

                    if (menu.Key.IsCtrl(KeyCode.F4))
                    {
                        editor.DisableHistory = true;
                        editor.Open(OpenMode.Modal);
                        goto show;
                    }

                    editor.Open();

                    if (menu.Key.IsShift(KeyCode.Enter))
                    {
                        goto show;
                    }
                }

                UpdatePeriodically(0);
                return;
            }
        }
Beispiel #20
0
        public static void ExpandText(ILine editLine, int replacementIndex, int replacementLength, IList words)
        {
            bool isEmpty = words.Count == 0;
            var  text    = editLine.Text;
            var  last    = replacementIndex + replacementLength - 1;
            bool custom  = last > 0 && last < text.Length && text[last] == '=';            //_140112_150217 last can be out of range

            // select a word
            string word;

            if (words.Count == 1)
            {
                // 1 word
                if (words[0] == null)
                {
                    return;
                }

                word = TECompletionText(words[0]);
            }
            else
            {
                // make menu
                IListMenu menu   = Far.Api.CreateListMenu();
                var       cursor = Far.Api.UI.WindowCursor;
                menu.X = cursor.X;
                menu.Y = cursor.Y;
                Settings.Default.PopupMenu(menu);
                if (isEmpty)
                {
                    menu.Add(Res.Empty).Disabled = true;
                    menu.NoInfo = true;
                    menu.Show();
                    return;
                }

                menu.Incremental        = "*";
                menu.IncrementalOptions = PatternOptions.Substring;

                foreach (var it in words)
                {
                    if (it == null)
                    {
                        continue;
                    }
                    var item = new SetItem();
                    item.Text = TEListItemText(it);
                    item.Data = it;
                    menu.Items.Add(item);
                }

                if (menu.Items.Count == 0)
                {
                    return;
                }

                if (menu.Items.Count == 1)
                {
                    word = TECompletionText(menu.Items[0].Data);
                }
                else
                {
                    // show menu
                    if (!menu.Show())
                    {
                        return;
                    }
                    word = TECompletionText(menu.Items[menu.Selected].Data);
                }
            }

            // replace

            // head before replaced part
            string head = text.Substring(0, replacementIndex);

            // custom pattern
            int index, caret;

            if (custom && (index = word.IndexOf('#')) >= 0)
            {
                word  = word.Substring(0, index) + word.Substring(index + 1);
                caret = head.Length + index;
            }
            // standard
            else
            {
                caret = head.Length + word.Length;
            }

            // set new text = old head + expanded + old tail
            editLine.Text = head + word + text.Substring(replacementIndex + replacementLength);

            // set caret
            editLine.Caret = caret;
        }
Beispiel #21
0
        protected override void BeginProcessing()
        {
            IListMenu menu = Create();

            WriteObject(menu);
        }
Beispiel #22
0
 /// <summary>
 /// Sets the list menu template.
 /// </summary>
 /// <param name="menu">The menu with default properties.</param>
 public void ListMenu(IListMenu menu)
 {
     if (menu == null) throw new ArgumentNullException("menu");
     menu.ScreenMargin = _ListMenuScreenMargin;
     menu.UsualMargins = _ListMenuUsualMargins;
 }
Beispiel #23
0
 /// <summary>
 /// Sets the popup list menu template.
 /// </summary>
 /// <param name="menu">The menu with default properties.</param>
 public void PopupMenu(IListMenu menu)
 {
     if (menu == null) throw new ArgumentNullException("menu");
     menu.AutoSelect = _PopupAutoSelect;
     menu.MaxHeight = _PopupMaxHeight;
     menu.NoShadow = _PopupNoShadow;
 }