Пример #1
0
 public Window(Main _controller, Model.Buffer _model)
 {
     Controller = _controller;
     Model = new Bind<Model.Buffer>(_model);
     CurrentMode = new BindList<WindowMode>();
     CurrentMode.Event.Changed += (list) => { CurrentKeyMap = list.FoldLeft(EmptyKeyMap, (a, b) => a + b.KeyMap); };
     CurrentMode.Add(Controller.WindowModes[0]);
     CurrentMode.Add(Controller.WindowModes[2]);
     CurrentMode.Add(Controller.WindowModes[3]);
     Parser = new CommandParser();
 }
Пример #2
0
 public Window(Main _controller, Model.Buffer _model)
 {
     Controller = _controller;
     Model = new Bind<Model.Buffer>(_model);
     CurrentMode = new BindSet<WindowMode>();
     CurrentMode.Changed.Add(() =>
     {
         CurrentKeyMap = CurrentMode.ToList().FoldLeft(EmptyKeyMap, (a, b) => a + b.KeyMap);
     });
     DefaultMode.ForEach(CurrentMode.Add);
     Parser = new CommandParser();
 }
Пример #3
0
 static Window()
 {
     EmptyKeyMap = new KeyMap();
     IgnoreKeys = new HashSet<Gdk.Key>();
     IgnoreKeys.Add(Gdk.Key.Shift_L);
     IgnoreKeys.Add(Gdk.Key.Shift_R);
     IgnoreKeys.Add(Gdk.Key.Shift_Lock);
     IgnoreKeys.Add(Gdk.Key.Meta_L);
     IgnoreKeys.Add(Gdk.Key.Meta_R);
     IgnoreKeys.Add(Gdk.Key.Control_L);
     IgnoreKeys.Add(Gdk.Key.Control_R);
     IgnoreKeys.Add(Gdk.Key.Super_L);
     IgnoreKeys.Add(Gdk.Key.Super_R);
     IgnoreKeys.Add(Gdk.Key.Menu);
 }
Пример #4
0
 static Window()
 {
     EmptyKeyMap = new KeyMap { Priority = sbyte.MinValue };
     EmptyKeyMap.SetDefault(new Command.Ignore());
 }
Пример #5
0
 public static KeyMap operator +(KeyMap a, KeyMap b)
 {
     if (a.Priority < b.Priority)
     {
         var tmp = b;
         b = a;
         a = tmp;
     }
     KeyMap result = new KeyMap();
     result.Priority = a.Priority;
     result.Default = a.Default;
     a._map.ForEach(kv => result._map.Add(kv.Key, kv.Value));
     b._map.Where(kv => !a._map.ContainsKey(kv.Key)).ForEach(kv => result._map.Add(kv.Key, kv.Value));
     return result;
 }
Пример #6
0
 public static KeyMap operator +(KeyMap a, KeyMap b)
 {
     KeyMap result = new KeyMap();
     result.Default = a.Default + b.Default;
     a._map.Keys.Union(b._map.Keys).ForEach(k => result._map[k] = a._map.GetWithDefault(k, null) + b._map.GetWithDefault(k, null));
     return result;
 }
Пример #7
0
        public Main(Model.Main m)
        {
            Model = m;
            Idle = new IdleHandler(this);

            WindowModes = new Dictionary<string, IEnumerable<WindowMode>>();

            // Load command macros from config file
            foreach (var entry in Model.Config.GetSectionOrEmpty("macros"))
            {
                commandMacros[entry.Key] = ParseCommands(entry.Value);
            }

            // Load window modes from config file
            foreach (var section in Model.Config)
            {
                var match = ModeSectionName.Match(section.Key);
                if (match.Success)
                {
                    var modeKey = match.Groups["name"].Value;
                    var mode = new WindowMode();
                    mode.Key = modeKey;
                    mode.Name = section.Value.GetWithDefault<string, string>("display-name", modeKey);
                    mode.Hidden = section.Value.GetBoolWithDefault("hidden", false);
                    var map = new KeyMap();
                    sbyte prio = 0;
                    if (section.Value.ContainsKey("priority"))
                    {
                        prio = sbyte.Parse(section.Value["priority"]);
                        mode.Priority = prio;
                    }
                    if (section.Value.ContainsKey("default"))
                    {
                        map.SetDefault(prio, ParseCommands(section.Value["default"]));
                    }
                    foreach (var entry in section.Value)
                    {
                        if (string.IsNullOrEmpty(entry.Key) || entry.Key == "display-name" || entry.Key == "hidden" || entry.Key == "default")
                        {
                            continue;
                        }
                        var mod = Gdk.ModifierType.None;
                        var tokens = entry.Key.Tokenize().ToList();
                        var key = (Gdk.Key) (Gdk.Keyval.FromName(tokens.Last()));
                        tokens.RemoveAt(tokens.Count - 1);
                        foreach (var modName in tokens)
                        {
                            mod |= ModifierNames[modName];
                        }
                        map.Add(key, mod, prio, ParseCommands(entry.Value));
                    }
                    mode.KeyMap = map;
                    WindowModes.Add(modeKey, new WindowMode[] { mode });
                }
            }

            // Load mode sets from config file
            foreach (var entry in Model.Config.GetSectionOrEmpty("mode-sets"))
            {
                WindowModes[entry.Key] = entry.Value.Tokenize().Select(k => WindowModes[k]).Flatten();
            }

            // Load default window modes from config file
            Model.Config[""]["default-modes"].Tokenize().ForEach(k => WindowModes[k].ForEach(Window.DefaultMode.Add));

            Windows = new BindListWithCurrent<Window>();
            if (Model.Buffers.HasAny())
            {
                Windows.Add(new Window(this, Model.Buffers.Item(0)));
            }

            Action openFile = () =>
            {
                if (Windows.Count == 0)
                {
                    Command.FileCommand.OpenFile(this, Command.FileCommand.InNewWindow, false);
                }
            };

            // Open a file at startup (but it won't work until the view has attached itself to our events)
            Ready.Add(openFile);

            // Open a file whenever all other files have been closed
            Windows.Changed.Add(openFile);
        }
Пример #8
0
Файл: Main.cs Проект: cpdean/di
        public Main(Model.Main m)
        {
            Model = m;

            var windowModes = new List<WindowMode>();
            WindowModes = new ReadOnlyCollection<WindowMode>(windowModes);

            // Command mode bindings (0)
            var commandMode = new KeyMap() { Priority = 5 };
            commandMode.Add(Key.i, new Command.ClearWindowMode(), new Command.AddWindowMode(1));
            commandMode.Add(Key.h, new Command.Down());
            commandMode.Add(Key.t, new Command.Up());
            commandMode.Add(Key.d, new Command.Left());
            commandMode.Add(Key.n, new Command.Right());
            commandMode.Add(Key.Down, new Command.Down());
            commandMode.Add(Key.Up, new Command.Up());
            commandMode.Add(Key.Left, new Command.Left());
            commandMode.Add(Key.Right, new Command.Right());
            commandMode.Add(Key.o, new Command.OpenFile());
            commandMode.Add(Key.w, new Command.ClearWindowMode(), new Command.AddWindowMode(4), new Command.AddWindowMode(3));
            windowModes.Add(new WindowMode { Name = "Command", KeyMap = commandMode });

            // Insert mode bindings (1)
            var insertMode = new KeyMap();
            insertMode.SetDefault(new Command.InsertKey());
            insertMode.Add(Key.Return, new Command.InsertChar('\n'));
            insertMode.Add(Key.Escape,
                           new Command.DiscardInput(),
                           new Command.ClearWindowMode(),
                           new Command.AddWindowMode(0),
                           new Command.AddWindowMode(2),
                           new Command.AddWindowMode(3));
            insertMode.Add(Key.BackSpace, new Command.Delete(), new Command.Backspace());
            insertMode.Add(Key.Tab, new Command.Tab());
            insertMode.Add(Key.Down, new Command.Down());
            insertMode.Add(Key.Up, new Command.Up());
            insertMode.Add(Key.Left, new Command.Left());
            insertMode.Add(Key.Right, new Command.Right());
            insertMode.Add(Key.Delete, new Command.Delete(), new Command.Right());
            windowModes.Add(new WindowMode { Name = "Insert", KeyMap = insertMode });

            // Number mode bindings (2)
            var numberMode = new KeyMap();
            numberMode.Add(Key.Key_0, new NumCommand());
            numberMode.Add(Key.Key_1, new NumCommand());
            numberMode.Add(Key.Key_2, new NumCommand());
            numberMode.Add(Key.Key_3, new NumCommand());
            numberMode.Add(Key.Key_4, new NumCommand());
            numberMode.Add(Key.Key_5, new NumCommand());
            numberMode.Add(Key.Key_6, new NumCommand());
            numberMode.Add(Key.Key_7, new NumCommand());
            numberMode.Add(Key.Key_8, new NumCommand());
            numberMode.Add(Key.Key_9, new NumCommand());
            windowModes.Add(new WindowMode { Name = "Number", Hidden = true, KeyMap = numberMode });

            // Common bindings (3)
            var commonMode = new KeyMap();
            commonMode.Add(Key.Escape, new Command.DiscardInput());
            windowModes.Add(new WindowMode { Name = "Common", Hidden = true, KeyMap = commonMode });

            // Window mode bindings (4)
            var windowMode = new KeyMap();
            windowMode.Add(Key.a,
                           new Command.OpenFileInNewWindow(),
                           new Command.ClearWindowMode(),
                           new Command.AddWindowMode(0),
                           new Command.AddWindowMode(2),
                           new Command.AddWindowMode(3));
            windowMode.Add(Key.c,
                           new Command.CloseWindow(),
                           new Command.ClearWindowMode(),
                           new Command.AddWindowMode(0),
                           new Command.AddWindowMode(2),
                           new Command.AddWindowMode(3));
            windowModes.Add(new WindowMode { Name = "Window", KeyMap = windowMode });

            Windows = new BindList<Window>();
            if (Model.Buffers.HasAny())
            {
                var window = new Window(this, Model.Buffers.Item(0));
                Windows.Add(window);
                FocusedWindow.Value = window;
            }
            WindowsEvents = Windows.Event;
        }