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]); }
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)); }
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)); }
void OnKeyBindingSchemeChanged(object sender, EventArgs e) { if (internalUpdate) { return; } if (schemeCombo.Active == schemes.Count + 1) { 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 = string.Join(" ", currentBindings.GetBindings(command)); keyStore.SetValue(citer, bindingCol, binding); } while (keyStore.IterNext(ref citer)); } while (keyStore.IterNext(ref iter)); UpdateConflictsWarning(); }