[Feature] Select root folder by windows context menu #195, version 1.0.18.1

This commit is contained in:
Markus Hofknecht 2021-09-23 12:00:50 +02:00
parent ee6e7b65f4
commit 7c77c235c4
20 changed files with 238 additions and 11 deletions

View file

@ -15,7 +15,7 @@ namespace SystemTrayMenu
private static bool isStartup = true;
[STAThread]
private static void Main()
private static void Main(string[] args)
{
try
{
@ -23,6 +23,7 @@ namespace SystemTrayMenu
SingleAppInstance.Initialize();
Translator.Initialize();
Config.Initialize();
Config.SetFolderByWindowsContextMenu(args);
if (Config.LoadOrSetByUser())
{
Application.EnableVisualStyles();

View file

@ -46,6 +46,17 @@ namespace SystemTrayMenu
AppColors.BitmapFilesCount.Dispose();
}
internal static void SetFolderByWindowsContextMenu(string[] args)
{
if (args != null && args.Length > 0)
{
string path = args[0];
Log.Info($"SetFolderByWindowsContextMenu() path: {path}");
Settings.Default.PathDirectory = path;
Settings.Default.Save();
}
}
public static bool LoadOrSetByUser()
{
bool pathOK = Directory.Exists(Path);

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.18.0")]
[assembly: AssemblyFileVersion("1.0.18.0")]
[assembly: AssemblyVersion("1.0.18.1")]
[assembly: AssemblyFileVersion("1.0.18.1")]

View file

@ -75,6 +75,22 @@ namespace SystemTrayMenu.Properties
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Configuration.SettingsProviderAttribute(typeof(CustomSettingsProvider))]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool PossibilityToSelectFolderByWindowsContextMenu
{
get
{
return ((bool)(this["PossibilityToSelectFolderByWindowsContextMenu"]));
}
set
{
this["PossibilityToSelectFolderByWindowsContextMenu"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Configuration.SettingsProviderAttribute(typeof(CustomSettingsProvider))]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

View file

@ -547,6 +547,24 @@ namespace SystemTrayMenu.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Set as SystemTrayMenu folder.
/// </summary>
internal static string Set_as_SystemTrayMenu_folder {
get {
return ResourceManager.GetString("Set as SystemTrayMenu folder", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Set by context menu .
/// </summary>
internal static string Set_by_context_menu_ {
get {
return ResourceManager.GetString("Set by context menu ", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Settings.
/// </summary>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Ikone</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Nastavljeno v kontekstnem meniju</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Nastavit jako složku SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Symbole</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Per Kontextmenü einstellen</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Als SystemTrayMenu-Ordner festlegen</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Iconos</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Establecido por menú contextual</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Establecer como carpeta SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Icônes</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Défini par menu contextuel</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Définir comme dossier SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Icone</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Imposta dal menu contestuale</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Imposta come cartella SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>アイコン</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>コンテキストメニューで設定</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>SystemTrayMenuフォルダーとして設定</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>아이콘</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>컨텍스트 메뉴로 설정</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>SystemTrayMenu 폴더로 설정</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>pictogrammen</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Ingesteld door contextmenu</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Instellen als SystemTrayMenu-map</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Ícones</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Definido por menu de contexto</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Definir como pasta SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Icons</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Set by context menu </value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Set as SystemTrayMenu folder</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Иконки</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Устанавливается в контекстном меню</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Установить как папку SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>Biểu tượng</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>Đặt theo menu ngữ cảnh</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>Đặt làm thư mục SystemTrayMenu</value>
</data>
</root>

View file

@ -330,4 +330,10 @@
<data name="Icons" xml:space="preserve">
<value>图标</value>
</data>
<data name="Set by context menu " xml:space="preserve">
<value>通过上下文菜单设置</value>
</data>
<data name="Set as SystemTrayMenu folder" xml:space="preserve">
<value>设置为 SystemTrayMenu 文件夹</value>
</data>
</root>

View file

@ -36,6 +36,7 @@ namespace SystemTrayMenu.UserInterface
this.tableLayoutPanelGeneral = new System.Windows.Forms.TableLayoutPanel();
this.groupBoxFolder = new System.Windows.Forms.GroupBox();
this.tableLayoutPanelFolder = new System.Windows.Forms.TableLayoutPanel();
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu = new System.Windows.Forms.CheckBox();
this.textBoxFolder = new System.Windows.Forms.TextBox();
this.tableLayoutPanelChangeFolder = new System.Windows.Forms.TableLayoutPanel();
this.buttonChangeFolder = new System.Windows.Forms.Button();
@ -458,7 +459,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxFolder.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxFolder.Name = "groupBoxFolder";
this.groupBoxFolder.Padding = new System.Windows.Forms.Padding(3, 6, 3, 6);
this.groupBoxFolder.Size = new System.Drawing.Size(400, 106);
this.groupBoxFolder.Size = new System.Drawing.Size(400, 131);
this.groupBoxFolder.TabIndex = 0;
this.groupBoxFolder.TabStop = false;
this.groupBoxFolder.Text = "groupBoxFolder";
@ -469,19 +470,31 @@ namespace SystemTrayMenu.UserInterface
this.tableLayoutPanelFolder.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableLayoutPanelFolder.ColumnCount = 1;
this.tableLayoutPanelFolder.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelFolder.Controls.Add(this.checkBoxPossibilityToSelectFolderByWindowsContextMenu, 0, 3);
this.tableLayoutPanelFolder.Controls.Add(this.textBoxFolder, 0, 0);
this.tableLayoutPanelFolder.Controls.Add(this.tableLayoutPanelChangeFolder, 0, 1);
this.tableLayoutPanelFolder.Controls.Add(this.checkBoxUseIconFromRootFolder, 0, 2);
this.tableLayoutPanelFolder.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanelFolder.Location = new System.Drawing.Point(3, 22);
this.tableLayoutPanelFolder.Name = "tableLayoutPanelFolder";
this.tableLayoutPanelFolder.RowCount = 3;
this.tableLayoutPanelFolder.RowCount = 4;
this.tableLayoutPanelFolder.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelFolder.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelFolder.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelFolder.Size = new System.Drawing.Size(394, 78);
this.tableLayoutPanelFolder.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelFolder.Size = new System.Drawing.Size(394, 103);
this.tableLayoutPanelFolder.TabIndex = 0;
//
// checkBoxPossibilityToSelectFolderByWindowsContextMenu
//
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.AutoSize = true;
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.Location = new System.Drawing.Point(3, 81);
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.Name = "checkBoxPossibilityToSelectFolderByWindowsContextMenu";
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.Size = new System.Drawing.Size(290, 19);
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.TabIndex = 2;
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.Text = "PossibilityToSelectFolderByWindowsContextMenu";
this.checkBoxPossibilityToSelectFolderByWindowsContextMenu.UseVisualStyleBackColor = true;
//
// textBoxFolder
//
this.textBoxFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
@ -543,7 +556,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxUSB.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBoxUSB.Controls.Add(this.tableLayoutPanelUSB);
this.groupBoxUSB.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBoxUSB.Location = new System.Drawing.Point(3, 115);
this.groupBoxUSB.Location = new System.Drawing.Point(3, 140);
this.groupBoxUSB.MaximumSize = new System.Drawing.Size(400, 0);
this.groupBoxUSB.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxUSB.Name = "groupBoxUSB";
@ -631,7 +644,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxAutostart.AutoSize = true;
this.groupBoxAutostart.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBoxAutostart.Controls.Add(this.tableLayoutPanelAutostart);
this.groupBoxAutostart.Location = new System.Drawing.Point(3, 205);
this.groupBoxAutostart.Location = new System.Drawing.Point(3, 230);
this.groupBoxAutostart.MaximumSize = new System.Drawing.Size(400, 0);
this.groupBoxAutostart.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxAutostart.Name = "groupBoxAutostart";
@ -672,7 +685,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxHotkey.AutoSize = true;
this.groupBoxHotkey.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBoxHotkey.Controls.Add(this.tableLayoutPanelHotkey);
this.groupBoxHotkey.Location = new System.Drawing.Point(3, 264);
this.groupBoxHotkey.Location = new System.Drawing.Point(3, 289);
this.groupBoxHotkey.MaximumSize = new System.Drawing.Size(400, 0);
this.groupBoxHotkey.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxHotkey.Name = "groupBoxHotkey";
@ -725,7 +738,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxLanguage.AutoSize = true;
this.groupBoxLanguage.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBoxLanguage.Controls.Add(this.tableLayoutPanelLanguage);
this.groupBoxLanguage.Location = new System.Drawing.Point(3, 329);
this.groupBoxLanguage.Location = new System.Drawing.Point(3, 354);
this.groupBoxLanguage.MaximumSize = new System.Drawing.Size(400, 0);
this.groupBoxLanguage.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxLanguage.Name = "groupBoxLanguage";
@ -4072,5 +4085,6 @@ namespace SystemTrayMenu.UserInterface
private System.Windows.Forms.PictureBox pictureBoxIconsDarkMode;
private System.Windows.Forms.Label labelIconsDarkMode;
private System.Windows.Forms.TextBox textBoxColorIconsDarkMode;
private System.Windows.Forms.CheckBox checkBoxPossibilityToSelectFolderByWindowsContextMenu;
}
}

View file

@ -18,6 +18,9 @@ namespace SystemTrayMenu.UserInterface
public partial class SettingsForm : Form
{
private const string MenuName = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder";
private const string Command = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder\command";
private static readonly Icon SystemTrayMenu = Resources.SystemTrayMenu;
private readonly string newHotKey = string.Empty;
private bool inHotkey;
@ -106,6 +109,8 @@ namespace SystemTrayMenu.UserInterface
groupBoxFolder.Text = Translator.GetText("Folder");
buttonChangeFolder.Text = Translator.GetText("Change folder");
checkBoxUseIconFromRootFolder.Text = Translator.GetText("Use icon from folder");
checkBoxPossibilityToSelectFolderByWindowsContextMenu.Text =
Translator.GetText("Set by context menu ");
groupBoxUSB.Text = Translator.GetText("USB");
buttonChangeRelativeFolder.Text = Translator.GetText("Change to relative folder");
checkBoxStoreConfigAtAssemblyLocation.Text = Translator.GetText("Store config at the assembly location");
@ -189,6 +194,8 @@ namespace SystemTrayMenu.UserInterface
textBoxFolder.Text = Config.Path;
checkBoxUseIconFromRootFolder.Checked =
Settings.Default.UseIconFromRootFolder;
checkBoxPossibilityToSelectFolderByWindowsContextMenu.Checked =
Settings.Default.PossibilityToSelectFolderByWindowsContextMenu;
}
InitializeAutostart();
@ -447,7 +454,7 @@ namespace SystemTrayMenu.UserInterface
tabControl.Size = new Size(
tabControl.Size.Width,
tableLayoutPanelAdvanced.Size.Height + 50);
tableLayoutPanelGeneral.Size.Height + 50);
}
private void AdjustControlMultilineIfNecessary(Control control)
@ -498,6 +505,20 @@ namespace SystemTrayMenu.UserInterface
{
Settings.Default.CurrentCultureInfoName =
comboBoxLanguage.SelectedValue.ToString();
Translator.Initialize();
}
PossibilityToSelectFolderByWindowsContextMenu();
void PossibilityToSelectFolderByWindowsContextMenu()
{
if (checkBoxPossibilityToSelectFolderByWindowsContextMenu.Checked)
{
AddPossibilityToSelectFolderByWindowsContextMenu();
}
else
{
RemovePossibilityToSelectFolderByWindowsContextMenu();
}
}
Settings.Default.OpenItemWithOneClick = checkBoxOpenItemWithOneClick.Checked;
@ -527,6 +548,74 @@ namespace SystemTrayMenu.UserInterface
Close();
}
private void AddPossibilityToSelectFolderByWindowsContextMenu()
{
RegistryKey registryKeyContextMenu = null;
RegistryKey registryKeyContextMenuCommand = null;
try
{
registryKeyContextMenu = Registry.CurrentUser.CreateSubKey(MenuName);
string binLocation = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
if (registryKeyContextMenu != null)
{
registryKeyContextMenu.SetValue(string.Empty, Translator.GetText("Set as SystemTrayMenu folder"));
registryKeyContextMenu.SetValue("Icon", binLocation);
}
registryKeyContextMenuCommand = Registry.CurrentUser.CreateSubKey(Command);
if (registryKeyContextMenuCommand != null)
{
registryKeyContextMenuCommand.SetValue(string.Empty, binLocation + " " + "\"" + "%1");
}
Settings.Default.PossibilityToSelectFolderByWindowsContextMenu = true;
}
catch (Exception ex)
{
Log.Warn("SavePossibilityToSelectFolderByWindowsContextMenu failed", ex);
}
finally
{
if (registryKeyContextMenu != null)
{
registryKeyContextMenu.Close();
}
if (registryKeyContextMenuCommand != null)
{
registryKeyContextMenuCommand.Close();
}
}
}
private void RemovePossibilityToSelectFolderByWindowsContextMenu()
{
try
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(Command);
if (registryKey != null)
{
registryKey.Close();
Registry.CurrentUser.DeleteSubKey(Command);
}
registryKey = Registry.CurrentUser.OpenSubKey(MenuName);
if (registryKey != null)
{
registryKey.Close();
Registry.CurrentUser.DeleteSubKey(MenuName);
}
Settings.Default.PossibilityToSelectFolderByWindowsContextMenu = false;
}
catch (Exception ex)
{
Log.Warn("DeletePossibilityToSelectFolderByWindowsContextMenu failed", ex);
}
}
private void ButtonHotkeyDefault_Click(object sender, EventArgs e)
{
textBoxHotkey.SetHotkey("Ctrl+LWin");