Esempio n. 1
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;
            }
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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;
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
 public bool Show()
 {
     return(_menu.Show());
 }