예제 #1
0
        public void TestKeyBindingSetLoadXml()
        {
            var xml = "<schemes version=\"1.0\">" +
                      "<scheme name=\"Scheme1\">" +
                      "    <binding command=\"Command1\" shortcut=\"Ctrl+1\" />" +
                      "    <binding command=\"Command2\" shortcut=\"Ctrl+2 Alt+2\" />" +
                      "</scheme>" +
                      "</schemes>";

            var set1 = new KeyBindingSet();

            using (var str = new StringReader(xml))
                using (var reader = new XmlTextReader(str))
                    Assert.True(set1.LoadScheme(reader, "Scheme1"));

            var cmd1 = set1.GetBindings(new ActionCommand("Command1", "Test Command 1"));

            Assert.AreEqual(1, cmd1.Length);
            Assert.AreEqual("Ctrl+1", cmd1 [0]);

            var cmd2 = set1.GetBindings(new ActionCommand("Command2", "Test Command 2"));

            Assert.AreEqual(2, cmd2.Length);
            Assert.AreEqual("Ctrl+2", cmd2 [0]);
            Assert.AreEqual("Alt+2", cmd2 [1]);
        }
예제 #2
0
        public void TestKeyBindingSetLoadXmlWithParent()
        {
            var xml = "<schemes version=\"1.0\">" +
                      "<scheme name=\"Scheme1\">" +
                      "    <binding command=\"Command1\" shortcut=\"Alt+1\" />" +
                      "    <binding command=\"Command2\" shortcut=\"\" />" +
                      "</scheme>" +
                      "</schemes>";

            var cmd1   = new ActionCommand("Command1", "Test Command 1");
            var cmd2   = new ActionCommand("Command2", "Test Command 2");
            var cmd3   = new ActionCommand("Command3", "Test Command 2");
            var parent = new KeyBindingSet();

            parent.SetBinding(cmd1, "Ctrl+1");
            parent.SetBinding(cmd2, "Ctrl+2");
            parent.SetBinding(cmd3, "Ctrl+3");

            var set1 = new KeyBindingSet(parent);

            Assert.AreEqual(new string [] { "Ctrl+1" }, set1.GetBindings(cmd1));
            Assert.AreEqual(new string [] { "Ctrl+2" }, set1.GetBindings(cmd2));

            using (var str = new StringReader(xml))
                using (var reader = new XmlTextReader(str))
                    Assert.True(set1.LoadScheme(reader, "Scheme1"));

            // verify that the set overrides its parent
            Assert.AreEqual(new string [] { "Alt+1" }, set1.GetBindings(cmd1));
            Assert.AreEqual(new string [0], set1.GetBindings(cmd2));

            // cmd3 should be still there
            Assert.AreEqual(new string [] { "Ctrl+3" }, set1.GetBindings(cmd3));
        }
예제 #3
0
        public void TestKeyBindingSetWithParent()
        {
            var cmd1 = new ActionCommand("Command1", "Test Command 1");
            var cmd2 = new ActionCommand("Command2", "Test Command 2");
            var cmd3 = new ActionCommand("Command3", "Test Command 3");

            var set1 = new KeyBindingSet();

            set1.SetBinding(cmd1, "Ctrl+1");
            set1.SetBinding(cmd2, "Ctrl+2");

            var set2 = new KeyBindingSet(set1);

            set2.SetBinding(cmd2, "Alt+2");
            set2.SetBinding(cmd3, "Ctrl+3");

            // verify that set1 has only cmd1 and cmd2 bindings
            Assert.AreEqual(new string [] { "Ctrl+1" }, set1.GetBindings(cmd1));
            Assert.AreEqual(new string [] { "Ctrl+2" }, set1.GetBindings(cmd2));
            Assert.AreEqual(new string [0], set1.GetBindings(cmd3));

            // verify that set2 has cmd1 binding from set1
            Assert.AreEqual(set1.GetBindings(cmd1), set2.GetBindings(cmd1));

            // verify that set 2 overrides cmd2
            Assert.AreNotEqual(set1.GetBindings(cmd2), set2.GetBindings(cmd2));
            Assert.AreEqual(new string [] { "Alt+2" }, set2.GetBindings(cmd2));

            // verify that set2 has cmd3 binding
            Assert.AreEqual(new string [] { "Ctrl+3" }, set2.GetBindings(cmd3));
        }
예제 #4
0
        public void TestKeyBindingSetEqualsParent()
        {
            var cmd1   = new ActionCommand("Command1", "Test Command 1");
            var cmd2   = new ActionCommand("Command2", "Test Command 2");
            var cmd3   = new ActionCommand("Command3", "Test Command 3");
            var parent = new KeyBindingSet();

            parent.SetBinding(cmd1, "Ctrl+1");

            var set2 = new KeyBindingSet(parent);
            var set3 = new KeyBindingSet(parent);

            //UNDONE: this is not a full IEquatable<KeyBindingSet> implementation
            // an empty set must be equal to its parent
            Assert.IsTrue(set2.Equals(parent));

            set2.SetBinding(cmd2, "Ctrl+2");
            set3.SetBinding(cmd2, "Ctrl+2");

            // sets sharing the same parent and declaring same bindings are equal
            Assert.IsTrue(set3.Equals(set2));
            Assert.IsTrue(set2.Equals(set3));

            // set defines an additional binding, hence not equal to its parent
            Assert.IsFalse(set3.Equals(parent));

            // sets with different binding and same parent are not equal
            set3.SetBinding(cmd2, "Alt+2");
            Assert.IsFalse(set3.Equals(set2));
        }
예제 #5
0
        public void TestKeyBindingSetEquals1()
        {
            var cmd1 = new ActionCommand("Command1", "Test Command 1");
            var cmd2 = new ActionCommand("Command2", "Test Command 2");
            var cmd3 = new ActionCommand("Command3", "Test Command 3");

            var set1 = new KeyBindingSet();

            set1.SetBinding(cmd1, "Ctrl+1");
            set1.SetBinding(cmd2, "Ctrl+2");

            var set2 = new KeyBindingSet();

            set2.SetBinding(cmd1, "Ctrl+1");
            set2.SetBinding(cmd2, "Ctrl+2");

            Assert.IsTrue(set1.Equals(set2));
            Assert.IsTrue(set2.Equals(set1));

            set2.SetBinding(cmd3, "Ctrl+3");

            Assert.IsFalse(set2.Equals(set1));
            //UNDONE: a set equals an other set if its a subset, this may/shold change in the future
            Assert.IsTrue(set1.Equals(set2));
        }
        public KeyBindingSet GetKeyBindingSet()
        {
            if (cachedSet != null)
            {
                return(cachedSet);
            }

            XmlTextReader reader = null;
            Stream        stream = null;

            try {
                stream = GetKeyBindingsSchemeStream();
                if (stream != null)
                {
                    reader    = new XmlTextReader(stream);
                    cachedSet = new KeyBindingSet(KeyBindingService.DefaultKeyBindingSet);
                    cachedSet.LoadScheme(reader, Id);
                    return(cachedSet);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error reading keybindings definition '{0}' in addin '{1}'.\n {2}",
                                        file ?? resource, Addin.Id, e.ToString());
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return(null);
        }
예제 #7
0
        public void TestKeyBindingSetSaveXmlWithParent()
        {
            var cmd1   = new ActionCommand("Command1", "Test Command 1");
            var cmd2   = new ActionCommand("Command2", "Test Command 2");
            var cmd3   = new ActionCommand("Command3", "Test Command 3");
            var parent = new KeyBindingSet();

            parent.SetBinding(cmd1, "Ctrl+1");
            parent.SetBinding(cmd2, "Ctrl+2");
            var set1 = new KeyBindingSet(parent);

            set1.SetBinding(cmd3, "Ctrl+3");

            var sb = new StringBuilder();

            using (var str = new StringWriter(sb))
                using (var writer = new XmlTextWriter(str)
                {
                    Indentation = 0, Formatting = Formatting.None
                })
                    set1.Save(writer, "Scheme1");

            var xml = sb.ToString();

            // parent bindings should be ignored
            var expectedXml =
                "<scheme name=\"Scheme1\">" +
                "<binding command=\"Command3\" shortcut=\"Ctrl+3\" />" +
                "</scheme>";

            Assert.AreEqual(expectedXml, xml);

            // verify that parent overrides are stored, especially empty ones to disable bindings
            set1.SetBinding(cmd1, "Alt+1");
            set1.SetBinding(cmd2, string.Empty);

            sb.Clear();
            using (var str = new StringWriter(sb))
                using (var writer = new XmlTextWriter(str)
                {
                    Indentation = 0, Formatting = Formatting.None
                })
                    set1.Save(writer, "Scheme1");

            xml         = sb.ToString();
            expectedXml =
                "<scheme name=\"Scheme1\">" +
                "<binding command=\"Command3\" shortcut=\"Ctrl+3\" />" +
                "<binding command=\"Command1\" shortcut=\"Alt+1\" />" +
                "<binding command=\"Command2\" shortcut=\"\" />" +
                "</scheme>";

            Assert.AreEqual(expectedXml, xml);
        }
예제 #8
0
        internal ConsoleInputOperationResult ProcessKey(ConsoleKeyInfo key)
        {
            if (!KeyBindingSet.TryGetValue(key, out ConsoleInputOperation op))
            {
                op = ConsoleInputOperation.ProcessCharacter;
            }

            var result = Process(op, key);

            _lastOp = op;

            return(result);
        }
예제 #9
0
        public void TestKeyBindingSetSaveXml()
        {
            var cmd1 = new ActionCommand("Command1", "Test Command 1");
            var cmd2 = new ActionCommand("Command2", "Test Command 2");
            var cmd3 = new ActionCommand("Command3", "Test Command 3");
            var set1 = new KeyBindingSet();

            set1.SetBinding(cmd1, "Ctrl+1");
            set1.SetBinding(cmd2, "Ctrl+2");
            set1.SetBinding(cmd3, "Ctrl+3");

            var sb = new StringBuilder();

            using (var str = new StringWriter(sb))
                using (var writer = new XmlTextWriter(str)
                {
                    Indentation = 0, Formatting = Formatting.None
                })
                    set1.Save(writer, "Scheme1");

            var xml = sb.ToString();

            var expectedXml =
                "<scheme name=\"Scheme1\">" +
                "<binding command=\"Command1\" shortcut=\"Ctrl+1\" />" +
                "<binding command=\"Command2\" shortcut=\"Ctrl+2\" />" +
                "<binding command=\"Command3\" shortcut=\"Ctrl+3\" />" +
                "</scheme>";

            Assert.AreEqual(expectedXml, xml);

            // verify that empty bindings are not stored
            set1.SetBinding(cmd3, string.Empty);

            sb.Clear();
            using (var str = new StringWriter(sb))
                using (var writer = new XmlTextWriter(str)
                {
                    Indentation = 0, Formatting = Formatting.None
                })
                    set1.Save(writer, "Scheme1");

            xml         = sb.ToString();
            expectedXml =
                "<scheme name=\"Scheme1\">" +
                "<binding command=\"Command1\" shortcut=\"Ctrl+1\" />" +
                "<binding command=\"Command2\" shortcut=\"Ctrl+2\" />" +
                "</scheme>";

            Assert.AreEqual(expectedXml, xml);
        }
예제 #10
0
        public void TestKeyBindingSetEquals2()
        {
            var cmd1 = new ActionCommand("Command1", "Test Command 1");
            var cmd2 = new ActionCommand("Command2", "Test Command 2");

            var set1 = new KeyBindingSet();

            set1.SetBinding(cmd1, "Ctrl+1");

            var set2 = new KeyBindingSet();

            set2.SetBinding(cmd1, "Ctrl+1");

            // add an empty binding to set2 which shouldn't change equality (bug #57111)
            set2.SetBinding(cmd2, string.Empty);

            Assert.IsTrue(set2.Equals(set1));
            Assert.IsTrue(set1.Equals(set2));
        }
예제 #11
0
        public void TestKeyBindingSetEquals2()
        {
            var cmd1 = new ActionCommand("Command1", "Test Command 1");
            var cmd2 = new ActionCommand("Command2", "Test Command 2");

            var set1 = new KeyBindingSet();

            set1.SetBinding(cmd1, "Ctrl+1");

            var set2 = new KeyBindingSet();

            set2.SetBinding(cmd1, "Ctrl+1");

            // add an empty binding to set2 which shouldn't change equality (bug #57111)
            set2.SetBinding(cmd2, string.Empty);

            Assert.IsFalse(set2.Equals(set1));
            //UNDONE: a set equals an other set if its a subset, this may/shold change in the future
            Assert.IsTrue(set1.Equals(set2));
        }
예제 #12
0
        void OnKeyBindingSchemeChanged(object sender, EventArgs e)
        {
            if (internalUpdate)
            {
                return;
            }

            if (schemeCombo.Active == 0)
            {
                return;
            }

            Command  command;
            string   binding;
            TreeIter iter;

            if (!keyStore.GetIterFirst(out iter))
            {
                return;
            }

            // Load a key binding template
            KeyBindingScheme scheme = KeyBindingService.GetSchemeByName(schemeCombo.ActiveText);

            currentBindings = scheme.GetKeyBindingSet().Clone();

            do
            {
                TreeIter citer;
                keyStore.IterChildren(out citer, iter);
                do
                {
                    command = (Command)keyStore.GetValue(citer, commandCol);
                    binding = currentBindings.GetBinding(command);
                    keyStore.SetValue(citer, bindingCol, binding);
                } while (keyStore.IterNext(ref citer));
            } while (keyStore.IterNext(ref iter));

            UpdateGlobalWarningLabel();
        }
예제 #13
0
        public void TestKeyBindingSetEquals1()
        {
            var cmd1 = new ActionCommand("Command1", "Test Command 1");
            var cmd2 = new ActionCommand("Command2", "Test Command 2");
            var cmd3 = new ActionCommand("Command3", "Test Command 3");

            var set1 = new KeyBindingSet();

            set1.SetBinding(cmd1, "Ctrl+1");
            set1.SetBinding(cmd2, "Ctrl+2");

            var set2 = new KeyBindingSet();

            set2.SetBinding(cmd1, "Ctrl+1");
            set2.SetBinding(cmd2, "Ctrl+2");

            Assert.IsTrue(set1.Equals(set2));
            Assert.IsTrue(set2.Equals(set1));

            set2.SetBinding(cmd3, "Ctrl+3");

            Assert.IsFalse(set2.Equals(set1));
            Assert.IsFalse(set1.Equals(set2));
        }
예제 #14
0
        public KeyBindingsPanel()
        {
            this.Build();

            keyStore                  = new TreeStore(typeof(Command), typeof(string), typeof(string), typeof(string), typeof(int), typeof(string), typeof(bool), typeof(bool));
            keyTreeView.Model         = filterModel = new TreeModelFilter(keyStore, null);
            filterModel.VisibleColumn = visibleCol;

            TreeViewColumn col = new TreeViewColumn();

            col.Title   = GettextCatalog.GetString("Command");
            col.Spacing = 4;
            CellRendererImage crp = new CellRendererImage();

            col.PackStart(crp, false);
            col.AddAttribute(crp, "stock-id", iconCol);
            col.AddAttribute(crp, "visible", iconVisibleCol);
            CellRendererText crt = new CellRendererText();

            col.PackStart(crt, true);
            col.AddAttribute(crt, "text", labelCol);
            col.AddAttribute(crt, "weight", boldCol);
            keyTreeView.AppendColumn(col);

            TreeViewColumn bindingTVCol = new TreeViewColumn();

            bindingTVCol.Title = GettextCatalog.GetString("Key Binding");
            CellRendererText bindingRenderer = new CellRendererText();

            bindingTVCol.PackStart(bindingRenderer, false);
            bindingTVCol.SetCellDataFunc(bindingRenderer, BindingTVDataFunc);
            keyTreeView.AppendColumn(bindingTVCol);

            keyTreeView.AppendColumn(GettextCatalog.GetString("Description"), new CellRendererText(), "text", descCol);

            keyTreeView.Selection.Changed += OnKeysTreeViewSelectionChange;

            accelEntry.KeyPressEvent   += OnAccelEntryKeyPress;
            accelEntry.KeyReleaseEvent += OnAccelEntryKeyRelease;
            accelEntry.Changed         += delegate {
                UpdateWarningLabel();
            };
            updateButton.Clicked += OnUpdateButtonClick;

            currentBindings = KeyBindingService.CurrentKeyBindingSet.Clone();

            schemes = new List <KeyBindingScheme> (KeyBindingService.Schemes);
            schemeCombo.AppendText(GettextCatalog.GetString("Custom"));

            foreach (KeyBindingScheme s in schemes)
            {
                schemeCombo.AppendText(s.Name);
            }

            SelectCurrentScheme();
            schemeCombo.Changed += OnKeyBindingSchemeChanged;

            searchEntry.Ready    = true;
            searchEntry.Visible  = true;
            searchEntry.Changed += delegate {
                processedFilterTerms = searchEntry.Entry.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                       .Select(s => s.ToLower()).ToArray();;
                filterChanged = true;
                if (!filterTimeoutRunning)
                {
                    filterTimeoutRunning = true;
                    GLib.Timeout.Add(50, delegate {
                        if (!filterChanged)
                        {
                            if (filterTimeoutRunning)
                            {
                                Refilter();
                            }
                            filterTimeoutRunning = false;
                            return(false);
                        }
                        filterChanged = false;
                        return(true);
                    });
                }
                ;
            };

            //HACK: workaround for MD Bug 608021: Stetic loses values assigned to "new" properties of custom widget
            conflicButton.Label        = GettextCatalog.GetString("_View Conflicts");
            conflicButton.UseUnderline = true;
        }
예제 #15
0
		public KeyBindingSet GetKeyBindingSet ()
		{
			if (cachedSet != null)
				return cachedSet;
			
			XmlTextReader reader = null;
			Stream stream = null;
			
			try {
				stream = GetKeyBindingsSchemeStream ();
				if (stream != null) {
					reader = new XmlTextReader (stream);
					cachedSet = new KeyBindingSet (KeyBindingService.DefaultKeyBindingSet);
					cachedSet.LoadScheme (reader, Id);
					return cachedSet;
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error reading keybindings definition '{0}' in addin '{1}'.\n {2}",
				                         file ?? resource, Addin.Id,  e.ToString ());
			} finally {
				if (reader != null)
					reader.Close ();
				if (stream != null)
					stream.Close ();
			}
			return null;
		}