Skip to content

Commit

Permalink
Resolves #35 & #34
Browse files Browse the repository at this point in the history
  • Loading branch information
tiuub committed Nov 21, 2021
1 parent dd1c58c commit bf8739a
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 18 deletions.
110 changes: 102 additions & 8 deletions KeeOtp2/Forms/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions KeeOtp2/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ public void InitEx()
groupBoxMigration.Text = KeeOtp2Statics.Migration;
labelMigrateButton.Text = KeeOtp2Statics.OtpInformationMigrate + KeeOtp2Statics.InformationChar + KeeOtp2Statics.SelectorChar;
buttonMigrate.Text = KeeOtp2Statics.OK;

groupBoxHotkey.Text = KeeOtp2Statics.HotKey;
labelUseHotKey.Text = KeeOtp2Statics.SettingsTOTPGlobalAutoType + KeeOtp2Statics.SelectorChar;
checkBoxUseHotkey.Text = KeeOtp2Statics.SettingsUseGlobalHotkey;
labelHotKeySequence.Text = KeeOtp2Statics.SettingsHotKeySequence + KeeOtp2Statics.InformationChar + KeeOtp2Statics.SelectorChar;
labelGlobalHotkey.Text = KeeOtp2Statics.SettingsGlobalHotKey + KeeOtp2Statics.SelectorChar;

groupBoxContextMenu.Text = KeeOtp2Statics.SettingsContextMenu;
labelShowContextMenuItem.Text = KeeOtp2Statics.SettingsCopyTotpShortcut + KeeOtp2Statics.InformationChar + KeeOtp2Statics.SelectorChar;
checkBoxShowContextMenuItem.Text = KeeOtp2Statics.SettingsShowCopyTotp;
labelUseLocalHotkey.Text = KeeOtp2Statics.SettingsTotpToClipboard + KeeOtp2Statics.SelectorChar;
checkBoxUseLocalHotkey.Text = KeeOtp2Statics.SettingsUseLocalHotkey;
labelLocalHotkey.Text = KeeOtp2Statics.SettingsLocalHotKey + KeeOtp2Statics.SelectorChar;

groupBoxTime.Text = KeeOtp2Statics.GlobalTime + KeeOtp2Statics.InformationChar + KeeOtp2Statics.SelectorChar;
radioButtonSystemTime.Text = KeeOtp2Statics.SettingsUseSystemTime;
labelTime.Text = String.Format(KeeOtp2Statics.SettingsPreviewUtc, "00:00:00");
Expand Down Expand Up @@ -110,6 +119,10 @@ public void InitEx()
toolTip.SetToolTip(labelGlobalHotkey, toolTipHotKeyCombination);
toolTip.SetToolTip(hotKeyControlExGlobalHotkey, toolTipHotKeyCombination);

string toolTipContextMenuItem = KeeOtp2Statics.ToolTipContextMenuItem;
toolTip.SetToolTip(labelShowContextMenuItem, toolTipContextMenuItem);
toolTip.SetToolTip(checkBoxShowContextMenuItem, toolTipContextMenuItem);

string toolTipOverrideBuiltInTime = KeeOtp2Statics.ToolTipOverrideBuiltInTime;
toolTip.SetToolTip(labelOverrideBuiltInTime, toolTipOverrideBuiltInTime);
toolTip.SetToolTip(checkBoxOverrideBuiltInTime, toolTipOverrideBuiltInTime);
Expand Down Expand Up @@ -159,6 +172,31 @@ private void loadConfig()
hotKeyControlExGlobalHotkey.Enabled = false;
}

if (KeeOtp2Config.ShowContextMenuItem)
{
checkBoxShowContextMenuItem.Checked = true;
checkBoxUseLocalHotkey.Enabled = true;
hotKey = KeeOtp2Config.LocalHotKeyKeys;
hotKeyControlExLocalHotkey.HotKey = hotKey;
if (KeeOtp2Config.UseHotKey && hotKey != Keys.None)
{
checkBoxUseLocalHotkey.Checked = true;
hotKeyControlExLocalHotkey.Enabled = true;
}
else
{
checkBoxUseLocalHotkey.Checked = false;
hotKeyControlExLocalHotkey.Enabled = false;
}
}
else
{
checkBoxShowContextMenuItem.Checked = false;
checkBoxUseLocalHotkey.Enabled = false;
hotKeyControlExLocalHotkey.Enabled = false;
}


radioButtonSystemTime.Checked =
radioButtonFixedTimeOffset.Checked =
numericUpDownFixedTimeOffset.Enabled =
Expand Down Expand Up @@ -194,10 +232,19 @@ private void Settings_FormClosing(object sender, FormClosingEventArgs e)

if (this.DialogResult == DialogResult.OK)
{
bool showRestartMessageBox = false;

KeeOtp2Config.UseHotKey = checkBoxUseHotkey.Checked;
KeeOtp2Config.HotKeySequence = textBoxHotKeySequence.Text;
KeeOtp2Config.HotKeyKeys = hotKeyControlExGlobalHotkey.HotKey;

showRestartMessageBox |= KeeOtp2Config.ShowContextMenuItem != checkBoxShowContextMenuItem.Checked;
KeeOtp2Config.ShowContextMenuItem = checkBoxShowContextMenuItem.Checked;
showRestartMessageBox |= KeeOtp2Config.UseLocalHotKey != checkBoxUseLocalHotkey.Checked;
KeeOtp2Config.UseLocalHotKey = checkBoxUseLocalHotkey.Checked;
showRestartMessageBox |= KeeOtp2Config.LocalHotKeyKeys != hotKeyControlExLocalHotkey.HotKey;
KeeOtp2Config.LocalHotKeyKeys = hotKeyControlExLocalHotkey.HotKey;

if (radioButtonSystemTime.Checked)
KeeOtp2Config.TimeType = OtpTimeType.SystemTime;
else if (radioButtonFixedTimeOffset.Checked)
Expand All @@ -212,6 +259,8 @@ private void Settings_FormClosing(object sender, FormClosingEventArgs e)
KeeOtp2Config.CustomNTPServer = textBoxCustomNTPServerAddress.Text;
KeeOtp2Config.OverrideBuiltInTime = checkBoxOverrideBuiltInTime.Checked;
}

MessageBox.Show(KeeOtp2Statics.MessageBoxSettingsRestartNotification, KeeOtp2Statics.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

Expand Down Expand Up @@ -261,6 +310,16 @@ private void checkBoxUseHotkey_CheckedChanged(object sender, EventArgs e)
textBoxHotKeySequence.Enabled = checkBoxUseHotkey.Checked;
}

private void checkBoxShowCopyTotp_CheckedChanged(object sender, EventArgs e)
{
checkBoxUseLocalHotkey.Enabled = checkBoxShowContextMenuItem.Checked;
}

private void checkBoxUseLocalHotkey_CheckedChanged(object sender, EventArgs e)
{
hotKeyControlExLocalHotkey.Enabled = (checkBoxShowContextMenuItem.Checked && checkBoxUseLocalHotkey.Checked);
}

private void radioButtonsTime_CheckedChanged(object sender, EventArgs e)
{
if (radioButtonFixedTimeOffset.Checked)
Expand Down
39 changes: 39 additions & 0 deletions KeeOtp2/KeeOtp2Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static void unregisterHotKey()
private const String PATH_USE_HOTKEY = PATH_PLUGINNAME + ".UseHotKey";
private const String PATH_HOTKEY_SEQUENCE = PATH_PLUGINNAME + ".HotKeySequence";
private const String PATH_HOTKEY_KEYS = PATH_PLUGINNAME + ".HotKeyKeys";
private const String PATH_SHOW_CONTEXT_MENU_ITEM = PATH_PLUGINNAME + ".ShowContextMenuItem";
private const String PATH_USE_LOCAL_HOTKEY = PATH_PLUGINNAME + ".UseLocalHotKey";
private const String PATH_LOCAL_HOTKEY_KEYS = PATH_PLUGINNAME + ".LocalHotKeyKeys";

private const String PATH_TIME_TYPE = PATH_PLUGINNAME + ".TimeType";
private const String PATH_FIXED_TIME_OFFSET = PATH_PLUGINNAME + ".FixedTimeOffset";
Expand Down Expand Up @@ -83,6 +86,42 @@ internal static Keys HotKeyKeys
}
}

internal static bool ShowContextMenuItem
{
get
{
return Program.Config.CustomConfig.GetBool(PATH_SHOW_CONTEXT_MENU_ITEM, true);
}
set
{
Program.Config.CustomConfig.SetBool(PATH_SHOW_CONTEXT_MENU_ITEM, value);
}
}

internal static bool UseLocalHotKey
{
get
{
return Program.Config.CustomConfig.GetBool(PATH_USE_LOCAL_HOTKEY, true);
}
set
{
Program.Config.CustomConfig.SetBool(PATH_USE_LOCAL_HOTKEY, value);
}
}

internal static Keys LocalHotKeyKeys
{
get
{
return (Keys)Enum.Parse(typeof(Keys), Program.Config.CustomConfig.GetString(PATH_LOCAL_HOTKEY_KEYS, (Keys.Control | Keys.T).ToString()));
}
set
{
Program.Config.CustomConfig.SetString(PATH_LOCAL_HOTKEY_KEYS, value.ToString());
}
}

internal static OtpTimeType TimeType
{
get
Expand Down
Loading

0 comments on commit bf8739a

Please sign in to comment.