예제 #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));
        }
        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);
        }
예제 #4
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;
		}