[Feature] Do not block menu when settings form open (#280), 1.2.0.5

This commit is contained in:
Markus Hofknecht 2021-12-27 07:35:39 +01:00
parent db46db002d
commit 8394704fec
5 changed files with 87 additions and 81 deletions

View file

@ -64,8 +64,7 @@ namespace SystemTrayMenu.Helper
{
string pathToStoreIcons = Path.Combine(pathToStoreFile, "ico");
using (WebClient client = new())
{
using WebClient client = new();
if (!Directory.Exists(pathToStoreIcons))
{
Directory.CreateDirectory(pathToStoreIcons);
@ -100,7 +99,7 @@ namespace SystemTrayMenu.Helper
if (!string.IsNullOrEmpty(value) &&
value.Length > maxLength)
{
value = value.Substring(0, maxLength);
value = value[..maxLength];
}
return value;
@ -116,5 +115,4 @@ namespace SystemTrayMenu.Helper
writer.Flush();
}
}
}
}

View file

@ -893,7 +893,7 @@ namespace SystemTrayMenu.UserInterface
{
if (e.Button == MouseButtons.Left)
{
SettingsForm.ShowSingleInstance();
SettingsForm.ShowSingleInstance(this);
}
}

View file

@ -1497,7 +1497,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxCache.TabStop = false;
this.groupBoxCache.Text = "groupBoxCache";
//
// tableLayoutPanel1
// tableLayoutPanelCache
//
this.tableLayoutPanelCache.AutoSize = true;
this.tableLayoutPanelCache.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
@ -1507,7 +1507,7 @@ namespace SystemTrayMenu.UserInterface
this.tableLayoutPanelCache.Controls.Add(this.tableLayoutPanelClearCacheIfMoreThanThisNumberOfItems, 0, 1);
this.tableLayoutPanelCache.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanelCache.Location = new System.Drawing.Point(3, 19);
this.tableLayoutPanelCache.Name = "tableLayoutPanel1";
this.tableLayoutPanelCache.Name = "tableLayoutPanelCache";
this.tableLayoutPanelCache.RowCount = 2;
this.tableLayoutPanelCache.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelCache.RowStyles.Add(new System.Windows.Forms.RowStyle());
@ -4086,6 +4086,7 @@ namespace SystemTrayMenu.UserInterface
this.Name = "SettingsForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Settings";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.SettingsForm_FormClosed);
this.Load += new System.EventHandler(this.SettingsForm_Load);
this.tableLayoutPanelMain.ResumeLayout(false);
this.tableLayoutPanelMain.PerformLayout();

View file

@ -442,31 +442,6 @@ namespace SystemTrayMenu.UserInterface
textBoxColorArrowHoverBackgroundDarkMode.Text = Settings.Default.ColorArrowHoverBackgroundDarkMode;
}
internal static void ShowSingleInstance()
{
if (IsOpen())
{
settingsForm.Activate();
}
else
{
using (settingsForm = new())
{
if (settingsForm.ShowDialog() == DialogResult.OK)
{
AppRestart.ByConfigChange();
}
}
settingsForm = null;
}
}
internal static bool IsOpen()
{
return settingsForm != null;
}
/// <summary>
/// Gets NewHotKey.
/// </summary>
@ -481,6 +456,31 @@ namespace SystemTrayMenu.UserInterface
return RegisterHotkeys(false);
}
public static void ShowSingleInstance(IWin32Window owner = null)
{
if (IsOpen())
{
settingsForm.Activate();
}
else
{
settingsForm = new();
if (owner == null)
{
settingsForm.ShowDialog();
}
else
{
settingsForm.Show(owner);
}
}
}
public static bool IsOpen()
{
return settingsForm != null;
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
@ -614,7 +614,7 @@ namespace SystemTrayMenu.UserInterface
try
{
registryKeyContextMenu = Registry.CurrentUser.CreateSubKey(MenuName);
string binLocation = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
string binLocation = Environment.ProcessPath;
if (registryKeyContextMenu != null)
{
registryKeyContextMenu.SetValue(string.Empty, Translator.GetText("Set as SystemTrayMenu folder"));
@ -810,6 +810,7 @@ namespace SystemTrayMenu.UserInterface
}
DialogResult = DialogResult.OK;
AppRestart.ByConfigChange();
Close();
}
@ -821,7 +822,7 @@ namespace SystemTrayMenu.UserInterface
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue(
Assembly.GetExecutingAssembly().GetName().Name,
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Environment.ProcessPath);
Settings.Default.IsAutostartActivated = true;
}
@ -1214,5 +1215,11 @@ namespace SystemTrayMenu.UserInterface
DialogResult = DialogResult.Cancel;
Close();
}
private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
settingsForm.Dispose();
settingsForm = null;
}
}
}

View file

@ -20,7 +20,7 @@ namespace SystemTrayMenu.Utilities
foreach (DriveInfo driveInfo in driveInfos)
{
driveNamesToRemove.Remove(driveInfo.Name[0]);
string linkPath = GetLinkPathFromDriveName(driveInfo.Name.Substring(0, 1));
string linkPath = GetLinkPathFromDriveName(driveInfo.Name[..1]);
if (!System.IO.File.Exists(linkPath))
{
CreateShortcut(linkPath, driveInfo.Name);
@ -36,7 +36,7 @@ namespace SystemTrayMenu.Utilities
private static void CreateShortcut(string linkPath, string targetPath)
{
WshShell shell = new WshShell();
WshShell shell = new();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(linkPath);
shortcut.Description = "Generated by SystemTrayMenu";
shortcut.TargetPath = targetPath;