Ejemplo n.º 1
0
        /// <summary>
        ///   Loads the keymap file and creates the mapping.
        /// </summary>
        /// <returns>True if the load was successfull, false if it failed.</returns>
        public bool LoadKeyMap()
        {
            mapWindows.Clear();
            string strFilename = String.Format(@"{0}\{1}", Options.ConfigDir, "keymap.xml");

            if (!File.Exists(strFilename))
            {
                strFilename = String.Format(@"{0}\bin\{1}", Application.StartupPath, "keymap.xml");
            }
            log.Info("Load key mapping from {0}", strFilename);
            try
            {
                // Load the XML file
                XmlDocument doc = new XmlDocument();
                doc.Load(strFilename);
                // Check if it is a keymap
                if (doc.DocumentElement == null)
                {
                    return(false);
                }
                string strRoot = doc.DocumentElement.Name;
                if (strRoot != "keymap")
                {
                    return(false);
                }

                // For each window
                XmlNodeList listWindows = doc.DocumentElement.SelectNodes("/keymap/window");
                foreach (XmlNode nodeWindow in listWindows)
                {
                    XmlNode nodeWindowId = nodeWindow.SelectSingleNode("id");
                    if (null != nodeWindowId)
                    {
                        WindowMap map = new WindowMap();
                        map.Window = Int32.Parse(nodeWindowId.InnerText);
                        XmlNodeList listNodes = nodeWindow.SelectNodes("action");
                        // Create a list of key/actiontype mappings
                        foreach (XmlNode node in listNodes)
                        {
                            XmlNode nodeId        = node.SelectSingleNode("id");
                            XmlNode nodeKey       = node.SelectSingleNode("key");
                            XmlNode nodeRibbonKey = node.SelectSingleNode("ribbon");
                            MapAction(ref map, nodeId, nodeKey, nodeRibbonKey);
                        }
                        if (map.Buttons.Count > 0)
                        {
                            mapWindows.Add(map);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("exception loading keymap {0} err:{1} stack:{2}", strFilename, ex.Message, ex.StackTrace);
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Map an action in a windowmap based on the id and key xml nodes.
        /// </summary>
        /// <param name = "map">The windowmap that needs to be filled in.</param>
        /// <param name = "nodeId">The id of the action</param>
        /// <param name = "nodeKey">The key corresponding to the mapping.</param>
        private void MapAction(ref WindowMap map, XmlNode nodeId, XmlNode nodeKey, XmlNode nodeRibbonKey)
        {
            if (null == nodeId)
            {
                return;
            }
            Button but = new Button();

            but.ActionType = (Action.ActionType)Int32.Parse(nodeId.InnerText);

            if (nodeRibbonKey != null)
            {
                but.RibbonKeyCode = nodeRibbonKey.InnerText;
            }

            if (nodeKey != null)
            {
                string[] buttons = nodeKey.InnerText.Split('-');
                for (int i = 0; i < buttons.Length - 1; i++)
                {
                    if (buttons[i] == "Alt")
                    {
                        but.Modifiers |= Keys.Alt;
                    }
                    else if (buttons[i] == "Ctrl")
                    {
                        but.Modifiers |= Keys.Control;
                    }
                    else if (buttons[i] == "Shift")
                    {
                        but.Modifiers |= Keys.Shift;
                    }
                }

                string strButton = buttons[buttons.Length - 1];

                try
                {
                    if (strButton != "")
                    {
                        but.KeyCode = (int)Enum.Parse(typeof(Keys), strButton);
                    }
                }
                catch (ArgumentException)
                {
                    log.Error("Invalid buttons for action {0}", nodeId.InnerText);
                }
            }

            map.Buttons.Add(but);
        }
        /// <summary>
        ///   Loads the keymap file and creates the mapping.
        /// </summary>
        /// <returns>True if the load was successfull, false if it failed.</returns>
        public bool LoadKeyMap()
        {
            mapWindows.Clear();
              string strFilename = String.Format(@"{0}\{1}", Options.ConfigDir, "keymap.xml");
              if (!File.Exists(strFilename))
            strFilename = String.Format(@"{0}\bin\{1}", Application.StartupPath, "keymap.xml");
              log.Info("Load key mapping from {0}", strFilename);
              try
              {
            // Load the XML file
            XmlDocument doc = new XmlDocument();
            doc.Load(strFilename);
            // Check if it is a keymap
            if (doc.DocumentElement == null) return false;
            string strRoot = doc.DocumentElement.Name;
            if (strRoot != "keymap") return false;

            // For each window
            XmlNodeList listWindows = doc.DocumentElement.SelectNodes("/keymap/window");
            foreach (XmlNode nodeWindow in listWindows)
            {
              XmlNode nodeWindowId = nodeWindow.SelectSingleNode("id");
              if (null != nodeWindowId)
              {
            WindowMap map = new WindowMap();
            map.Window = Int32.Parse(nodeWindowId.InnerText);
            XmlNodeList listNodes = nodeWindow.SelectNodes("action");
            // Create a list of key/actiontype mappings
            foreach (XmlNode node in listNodes)
            {
              XmlNode nodeId = node.SelectSingleNode("id");
              XmlNode nodeKey = node.SelectSingleNode("key");
              XmlNode nodeRibbonKey = node.SelectSingleNode("ribbon");
              MapAction(ref map, nodeId, nodeKey, nodeRibbonKey);
            }
            if (map.Buttons.Count > 0)
            {
              mapWindows.Add(map);
            }
              }
            }
              }
              catch (Exception ex)
              {
            log.Error("exception loading keymap {0} err:{1} stack:{2}", strFilename, ex.Message, ex.StackTrace);
              }
              return false;
        }
        /// <summary>
        ///   Map an action in a windowmap based on the id and key xml nodes.
        /// </summary>
        /// <param name = "map">The windowmap that needs to be filled in.</param>
        /// <param name = "nodeId">The id of the action</param>
        /// <param name = "nodeKey">The key corresponding to the mapping.</param>
        private void MapAction(ref WindowMap map, XmlNode nodeId, XmlNode nodeKey, XmlNode nodeRibbonKey)
        {
            if (null == nodeId) return;
              Button but = new Button();
              but.ActionType = (Action.ActionType)Int32.Parse(nodeId.InnerText);

              if (nodeRibbonKey != null)
              {
            but.RibbonKeyCode = nodeRibbonKey.InnerText;
              }

              if (nodeKey != null)
              {
            string[] buttons = nodeKey.InnerText.Split('-');
            for (int i = 0; i < buttons.Length - 1; i++)
            {
              if (buttons[i] == "Alt")
            but.Modifiers |= Keys.Alt;
              else if (buttons[i] == "Ctrl")
            but.Modifiers |= Keys.Control;
              else if (buttons[i] == "Shift")
            but.Modifiers |= Keys.Shift;
            }

            string strButton = buttons[buttons.Length - 1];

            try
            {
              if (strButton != "")
            but.KeyCode = (int)Enum.Parse(typeof (Keys), strButton);
            }
            catch (ArgumentException)
            {
              log.Error("Invalid buttons for action {0}", nodeId.InnerText);
            }
              }

              map.Buttons.Add(but);
        }