Skip to content

Commit

Permalink
Fixes for #12, #13, #15, #16, #17, #18
Browse files Browse the repository at this point in the history
  • Loading branch information
brondavies committed Jul 29, 2024
1 parent d92c67a commit 482d6f1
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
/src/TrayToolbar/Properties/launchSettings.json
11 changes: 9 additions & 2 deletions src/TrayToolbar/Controls/FolderControl.Designer.cs

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

19 changes: 18 additions & 1 deletion src/TrayToolbar/Extensions/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.RegularExpressions;

namespace TrayToolbar.Extensions
{
Expand All @@ -12,7 +13,7 @@ public static string FileExtension(this string file)

public static Icon GetIcon(this string path)
{
return ShellIcons.FetchIcon(path, true);
return ShellIcons.FetchIcon(path, false);
}

public static Bitmap GetImage(this string file)
Expand Down Expand Up @@ -47,6 +48,12 @@ public static bool IsHttps(this string value)
return value.HasValue() && value.StartsWith("https://");
}

public static bool IsMatch(this string? value, string pattern)
{
if (value == null) return false;
return Regex.IsMatch(value, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
}

public static string Join(this string[] value, string separator = ", ")
{
return string.Join(separator, value);
Expand All @@ -67,5 +74,15 @@ public static void ShowContextMenu(this NotifyIcon notifyIcon)
MethodInfo? mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
mi?.Invoke(notifyIcon, null);
}

public static string[] SplitPaths(this string value, char[]? splitchars = null)
{
return value.Split(splitchars ?? [';', ','], StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
}

public static string ToMenuName(this string? value)
{
return value?.Replace("&", "&&") ?? "";
}
}
}
4 changes: 3 additions & 1 deletion src/TrayToolbar/Extensions/SystemTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ namespace TrayToolbar.Extensions
internal class SystemTheme
{
const string REGKEY_THEMES = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize";
static bool? DarkModeEnabled = null;
public unsafe static bool UseImmersiveDarkMode(IntPtr handle, bool enabled)
{
if (IsDarkModeSupported())
if (IsDarkModeSupported() && DarkModeEnabled != enabled)
{
DarkModeEnabled = enabled;
var form = Control.FromHandle(handle);
ThemeColors.Current = enabled ? ThemeColors.Dark : ThemeColors.Light;
SetThemeColors(form, enabled);
Expand Down
18 changes: 7 additions & 11 deletions src/TrayToolbar/Extensions/ThemeChangeMessageFilter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;

namespace TrayToolbar.Extensions
namespace TrayToolbar.Extensions
{
internal class ThemeChangeMessageFilter : IMessageFilter
{
Expand All @@ -16,13 +14,10 @@ public static void Enable(bool enable)
Application.AddMessageFilter(Instance);
}
}
else
else if (Instance != null)
{
if (Instance != null)
{
Application.RemoveMessageFilter(Instance);
Instance = null;
}
Application.RemoveMessageFilter(Instance);
Instance = null;
}
}

Expand All @@ -32,8 +27,9 @@ public static void Enable(bool enable)
public bool PreFilterMessage(ref Message m)
{
//Debug.WriteLine($"{m.HWnd}: {m.WParam}, {m.LParam}, {m.Msg}");
if (m.WParam == 0 && m.LParam == 0 && m.Msg == 49832 //not in the WM_* enum
&& (DateTime.Now - eventTrigger).TotalMilliseconds > 100)
//TODO: I was expecting to be able to check for WM_SETTINGCHANGE but this doesn't actually consistently happen between Win 10/11
// Look for updated documentation on how to get a message when the theme changes
if ((DateTime.Now - eventTrigger).TotalMilliseconds > 100)
{
ThemeChanged?.Invoke(null, EventArgs.Empty);
eventTrigger = DateTime.Now;
Expand Down
3 changes: 2 additions & 1 deletion src/TrayToolbar/Models/MenuItemCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using TrayToolbar.Extensions;

namespace TrayToolbar
{
Expand All @@ -13,7 +14,7 @@ public MenuItemCollection() { }
ToolStripMenuItem? parent = null;
foreach (var part in parts)
{
var added = AddFolder(parent, part, handler, out ToolStripMenuItem? menu);
var added = AddFolder(parent, part.ToMenuName(), handler, out ToolStripMenuItem? menu);
parent = menu;
if (!added && menu != null)
{
Expand Down
28 changes: 23 additions & 5 deletions src/TrayToolbar/Models/TrayToolbarConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,35 @@ namespace TrayToolbar
{
public class TrayToolbarConfiguration
{
public bool HideFileExtensions { get; set; }

public bool IgnoreAllDotFiles { get; set; }

public string[] IgnoreFiles { get; set; } = [".bak", ".config", ".dll", ".ico", ".ini"];

[Obsolete("IgnoreFileTypes is obsolete", true)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string[]? IgnoreFileTypes
{
get => null;
set
{
if (value != null)
IgnoreFiles = value;
}
}

public string[] IgnoreFolders { get; set; } = [".git", ".github"];

public int MaxRecursionDepth { get; set; } = 3;

public int Theme { get; set; } = 0;

[Obsolete]
[Obsolete("Folder is obsolete", true)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Folder
{
get => null;
public string? Folder
{
get => null;
set
{
if (value.HasValue())
Expand All @@ -31,7 +49,7 @@ public string? Folder
public class FolderConfig
{
public FolderConfig() { }
public FolderConfig(string name)
public FolderConfig(string name)
{
Name = name;
}
Expand Down
1 change: 1 addition & 0 deletions src/TrayToolbar/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ RegNotifyChangeKeyValue
RegOpenKeyEx
WM_MOUSE*
WM_PAINT
WM_SETTINGCHANGE
WINDOW_EX_STYLE
7 changes: 6 additions & 1 deletion src/TrayToolbar/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ static void Main()
ThemeChangeMessageFilter.Enable(true);
try
{
Application.Run(new SettingsForm());
var form = new SettingsForm();
if (Environment.GetCommandLineArgs().Contains("--show"))
{
form.Show();
}
Application.Run(form);
} catch (ObjectDisposedException) { }
}

Expand Down
11 changes: 10 additions & 1 deletion src/TrayToolbar/Resources/Resources.Designer.cs

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

5 changes: 4 additions & 1 deletion src/TrayToolbar/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
<value>Error</value>
</data>
<data name="Exclude files" xml:space="preserve">
<value>Exclude files</value>
<value>Exclude file types</value>
</data>
<data name="Exclude folders" xml:space="preserve">
<value>Exclude folders</value>
</data>
<data name="Exit" xml:space="preserve">
<value>Exit</value>
Expand Down
Loading

0 comments on commit 482d6f1

Please sign in to comment.