/// <summary> /// Converts key enum constant into an internal key hash code. /// </summary> /// <param name="key"> The <see cref="Keys"/> enum constant to convert into an internal key hash code.</param> /// <returns> The internal key hash code corresponding to the <see cref="Keys"/> enum constant given.</returns> public static uint getKeyHashCode(ShortcutData.Keys key) { return getKeyHashCode((uint)key); }
/// \internal /// <summary> /// This function should be called when a new shortcut is read. /// </summary> /// <remarks>It just triggers the <see cref="NewShortcutEvent"/>.</remarks> /// <param name="shortcut">The new shortcut</param> protected void newShortcut(ShortcutData shortcut) { NewShortcutEvent(shortcut); }
/// <summary> /// Parses the parameter list. /// </summary> /// <param name="shortcut">The shortcut where to set parameters</param> /// <param name="line">The line of data from the config file</param> /// <param name="i">The current index</param> private void parseParameters(ShortcutData shortcut, string line, int i) { while (i < line.Length) { string param = nextParameterToken(line, ref i); if (param != String.Empty) shortcut.Params.Add(param); } }
/// <summary> /// Parses the configuration file. /// </summary> public override void parseConfig() { TextReader inStream = new StreamReader(new FileStream(mFileName, FileMode.Open, FileAccess.Read)); uint l = 0; while (true) { string line = inStream.ReadLine(); l++; if (line == null) break; // Ignores lines starting with another character than space. May be used for comments: if (!line.StartsWith(" ")) { log.DebugFormat("Ignored line \"{0}\"", line); continue; } ShortcutData shortcut = new ShortcutData(); try { parseModifiers(shortcut, line); int i = 8; string keyToken = nextToken(line, ref i); try { shortcut.setKey(keyToken); } catch (System.Reflection.ReflectionTypeLoadException e) { throw new BadConfigException("Invalid key name: " + keyToken, mFileName, l, (uint)i, e); } // Find class and method: shortcut.Class = nextToken(line, ref i); shortcut.Method = nextToken(line, ref i); // Parse parameters: parseParameters(shortcut, line, i); } catch (BadConfigException e) { e.Line = l; throw e; } newShortcut(shortcut); } inStream.Close(); }
/// <summary> /// Parse the modifiers for a shortcut. /// </summary> /// <param name="shortcut">The shortcut where to set modifiers</param> /// <param name="line">The line of data from the config file</param> private void parseModifiers(ShortcutData shortcut, string line) { Array modifiers = Enum.GetValues(typeof(ShortcutData.Modifiers)); // Line is too short to hold modifiers: if (line.Length < 8) throw new BadConfigException("Unexpected end of line", mFileName, 0, 8); for (int i = 0; i < modifiers.Length / 3; i++) { if (line[2 * i + 1] == 'X') shortcut.addModifier((ShortcutData.Modifiers)modifiers.GetValue(2 + 3 * i)); else if (line[2 * i + 1] == 'L') shortcut.addModifier((ShortcutData.Modifiers)modifiers.GetValue(1 + 3 * i)); else if (line[2 * i + 1] == 'R') shortcut.addModifier((ShortcutData.Modifiers)modifiers.GetValue(0 + 3 * i)); else if (line[2 * i + 1] == 'O') shortcut.removeModifier((ShortcutData.Modifiers)modifiers.GetValue(2 + 3 * i)); else throw new BadConfigException("Invalid setting for " + (ShortcutData.Modifiers)modifiers.GetValue(1 + 3 * i) + " modifier", mFileName, 0, (uint)(2 * i + 2)); } }