/// <summary>
 /// Event method auto-called when the "configure keys" box is double-clicked.
 /// </summary>
 public void ConfigureKeysGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (!KeysHelper.TryGetKey(ConfigureKeysGrid[0, e.RowIndex].Value.ToString(), out Keys key))
     {
         MessageBox.Show("Error: configure keys grid misconfigured, invalid key name!", "Keyboard Chatter Blocker", MessageBoxButtons.OK);
         return;
     }
     if (e.ColumnIndex == 1) // Value column
     {
         uint resultValue = Program.Blocker.KeysToChatterTime[key] ?? Program.Blocker.GlobalChatterTimeLimit;
         KeyConfigurationForm keyConfigForm = new KeyConfigurationForm()
         {
             Key       = key,
             SetResult = (i) =>
             {
                 resultValue = i;
             }
         };
         keyConfigForm.ShowDialog(this);
         Program.Blocker.KeysToChatterTime[key] = resultValue;
         Program.Blocker.SaveConfig();
         ConfigureKeysGrid[1, e.RowIndex].Value = resultValue.ToString();
     }
     else if (e.ColumnIndex == 2) // Remove column
     {
         Program.Blocker.KeysToChatterTime[key] = null;
         Program.Blocker.SaveConfig();
         ConfigureKeysGrid.Rows.RemoveAt(e.RowIndex);
     }
 }
示例#2
0
        /// <summary>
        /// Applies a setting line from a config file.
        /// </summary>
        /// <param name="setting">The setting line.</param>
        public void ApplyConfigSetting(string setting)
        {
            int colonIndex = setting.IndexOf(':');

            if (colonIndex == -1)
            {
                return;
            }
            string settingName  = setting.Substring(0, colonIndex).Trim();
            string settingValue = setting.Substring(colonIndex + 1).Trim();

            if (settingName.StartsWith("key."))
            {
                if (!KeysHelper.TryGetKey(settingName.Substring("key.".Length), out Keys key))
                {
                    MessageBox.Show("Config file contains setting '" + setting + "', which names an invalid key.", "KeyboardChatterBlocker Configuration Error", MessageBoxButtons.OK);
                    return;
                }
                KeysToChatterTime[key] = uint.Parse(settingValue);
                return;
            }
            switch (settingName)
            {
            case "is_enabled":
                IsEnabled = SettingAsBool(settingValue);
                break;

            case "global_chatter":
                GlobalChatterTimeLimit = uint.Parse(settingValue);
                break;

            case "hide_in_system_tray":
                Program.HideInSystemTray = SettingAsBool(settingValue);
                break;

            case "auto_disable_programs":
                AutoDisablePrograms.AddRange(settingValue.ToLowerInvariant().Split('/'));
                break;

            case "auto_disable_on_fullscreen":
                AutoDisableOnFullscreen = SettingAsBool(settingValue);
                break;
            }
        }