mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-16 18:32:40 +12:00
[Feature] Do not block menu when settings form open (#280), 1.2.0.5
This commit is contained in:
parent
db46db002d
commit
8394704fec
|
@ -64,57 +64,55 @@ namespace SystemTrayMenu.Helper
|
|||
{
|
||||
string pathToStoreIcons = Path.Combine(pathToStoreFile, "ico");
|
||||
|
||||
using (WebClient client = new())
|
||||
using WebClient client = new();
|
||||
if (!Directory.Exists(pathToStoreIcons))
|
||||
{
|
||||
if (!Directory.Exists(pathToStoreIcons))
|
||||
{
|
||||
Directory.CreateDirectory(pathToStoreIcons);
|
||||
}
|
||||
|
||||
Uri uri = new(url);
|
||||
string hostname = uri.Host.ToString();
|
||||
|
||||
string pathIconPng = Path.Combine(pathToStoreIcons, $"{hostname}.png");
|
||||
client.DownloadFile(
|
||||
@"http://www.google.com/s2/favicons?sz=32&domain=" + url,
|
||||
pathIconPng);
|
||||
string pathIcon = Path.Combine(pathToStoreIcons, $"{hostname}.ico");
|
||||
ImagingHelper.ConvertToIcon(pathIconPng, pathIcon, 32);
|
||||
File.Delete(pathIconPng);
|
||||
|
||||
string title = url;
|
||||
|
||||
title = title.Replace("/", " ").
|
||||
Replace("https", string.Empty).
|
||||
Replace("http", string.Empty);
|
||||
|
||||
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
|
||||
foreach (char c in invalid)
|
||||
{
|
||||
title = title.Replace(c.ToString(), string.Empty);
|
||||
}
|
||||
|
||||
title = Truncate(title, 128); // max 255
|
||||
static string Truncate(string value, int maxLength)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value) &&
|
||||
value.Length > maxLength)
|
||||
{
|
||||
value = value.Substring(0, maxLength);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
using StreamWriter writer = new(pathToStoreFile + "\\" + title.Trim() + ".url");
|
||||
writer.WriteLine("[InternetShortcut]");
|
||||
writer.WriteLine($"URL={url.TrimEnd('\0')}");
|
||||
writer.WriteLine("IconIndex=0");
|
||||
writer.WriteLine($"HotKey=0");
|
||||
writer.WriteLine($"IDList=");
|
||||
writer.WriteLine($"IconFile={pathIcon}");
|
||||
writer.Flush();
|
||||
Directory.CreateDirectory(pathToStoreIcons);
|
||||
}
|
||||
|
||||
Uri uri = new(url);
|
||||
string hostname = uri.Host.ToString();
|
||||
|
||||
string pathIconPng = Path.Combine(pathToStoreIcons, $"{hostname}.png");
|
||||
client.DownloadFile(
|
||||
@"http://www.google.com/s2/favicons?sz=32&domain=" + url,
|
||||
pathIconPng);
|
||||
string pathIcon = Path.Combine(pathToStoreIcons, $"{hostname}.ico");
|
||||
ImagingHelper.ConvertToIcon(pathIconPng, pathIcon, 32);
|
||||
File.Delete(pathIconPng);
|
||||
|
||||
string title = url;
|
||||
|
||||
title = title.Replace("/", " ").
|
||||
Replace("https", string.Empty).
|
||||
Replace("http", string.Empty);
|
||||
|
||||
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
|
||||
foreach (char c in invalid)
|
||||
{
|
||||
title = title.Replace(c.ToString(), string.Empty);
|
||||
}
|
||||
|
||||
title = Truncate(title, 128); // max 255
|
||||
static string Truncate(string value, int maxLength)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value) &&
|
||||
value.Length > maxLength)
|
||||
{
|
||||
value = value[..maxLength];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
using StreamWriter writer = new(pathToStoreFile + "\\" + title.Trim() + ".url");
|
||||
writer.WriteLine("[InternetShortcut]");
|
||||
writer.WriteLine($"URL={url.TrimEnd('\0')}");
|
||||
writer.WriteLine("IconIndex=0");
|
||||
writer.WriteLine($"HotKey=0");
|
||||
writer.WriteLine($"IDList=");
|
||||
writer.WriteLine($"IconFile={pathIcon}");
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -893,7 +893,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
SettingsForm.ShowSingleInstance();
|
||||
SettingsForm.ShowSingleInstance(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
5
UserInterface/SettingsForm.Designer.cs
generated
5
UserInterface/SettingsForm.Designer.cs
generated
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue