Fix some nullables

This commit is contained in:
Peter Kirmeier 2022-12-05 01:27:57 +01:00
parent 22679392f4
commit 11bac5dd1e
9 changed files with 277 additions and 237 deletions

View file

@ -455,7 +455,7 @@ namespace SystemTrayMenu.Business
timerShowProcessStartedAsLoadingIcon.Tick += Tick;
timerShowProcessStartedAsLoadingIcon.Interval = TimeSpan.FromMilliseconds(5);
timerShowProcessStartedAsLoadingIcon.Start();
void Tick(object sender, EventArgs e)
void Tick(object? sender, EventArgs e)
{
timerShowProcessStartedAsLoadingIcon.Tick -= Tick;
timerShowProcessStartedAsLoadingIcon.Interval = TimeSpan.FromMilliseconds(Properties.Settings.Default.TimeUntilClosesAfterEnterPressed);
@ -488,12 +488,17 @@ namespace SystemTrayMenu.Business
private static void LoadMenu(object senderDoWork, DoWorkEventArgs eDoWork)
{
string path;
string? path;
int level = 0;
RowData rowData = eDoWork.Argument as RowData;
RowData? rowData = eDoWork.Argument as RowData;
if (rowData != null)
{
path = rowData.ResolvedPath;
if (path == null)
{
return;
}
level = rowData.Level + 1;
}
else
@ -521,32 +526,35 @@ namespace SystemTrayMenu.Business
foldersCount = 0;
filesCount = 0;
List<Menu.ListViewItemData> items = new();
ListView lv = menu.GetDataGridView();
foreach (RowData rowData in data)
ListView? lv = menu.GetDataGridView();
if (lv != null)
{
if (!(rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult))
List<Menu.ListViewItemData> items = new();
foreach (RowData rowData in data)
{
if (rowData.ContainsMenu)
if (!(rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult))
{
foldersCount++;
}
else
{
filesCount++;
if (rowData.ContainsMenu)
{
foldersCount++;
}
else
{
filesCount++;
}
}
rowData.RowIndex = items.Count; // Index
items.Add(new(
(rowData.HiddenEntry ? IconReader.AddIconOverlay(rowData.Icon, Properties.Resources.White50Percentage) : rowData.Icon)?.ToImageSource(),
rowData.Text ?? "?",
rowData,
rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult ? 99 : 0));
}
rowData.RowIndex = items.Count; // Index
items.Add(new(
(rowData.HiddenEntry ? IconReader.AddIconOverlay(rowData.Icon, Properties.Resources.White50Percentage) : rowData.Icon).ToImageSource(),
rowData.Text,
rowData,
rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult ? 99 : 0));
lv.ItemsSource = items;
}
lv.ItemsSource = items;
}
private bool IsActive()
@ -1135,7 +1143,7 @@ namespace SystemTrayMenu.Business
}
Menu menu;
Menu menuPredecessor = null;
Menu? menuPredecessor = null;
for (int i = 0; i < list.Count; i++)
{
menu = list[i];
@ -1219,16 +1227,15 @@ namespace SystemTrayMenu.Business
{
menus[0].Dispatcher.Invoke(() => RenameItem(renamedEventArgs));
}
else
else if (e is FileSystemEventArgs fileSystemEventArgs)
{
FileSystemEventArgs fileSystemEventArgs = (FileSystemEventArgs)e;
if (fileSystemEventArgs.ChangeType == WatcherChangeTypes.Deleted)
{
menus[0].Dispatcher.Invoke(() => DeleteItem(e as FileSystemEventArgs));
menus[0].Dispatcher.Invoke(() => DeleteItem(fileSystemEventArgs));
}
else if (fileSystemEventArgs.ChangeType == WatcherChangeTypes.Created)
{
menus[0].Dispatcher.Invoke(() => CreateItem(e as FileSystemEventArgs));
menus[0].Dispatcher.Invoke(() => CreateItem(fileSystemEventArgs));
}
}
}
@ -1238,33 +1245,36 @@ namespace SystemTrayMenu.Business
try
{
List<RowData> rowDatas = new();
ListView dgv = menus[0].GetDataGridView();
foreach (ListViewItemData item in dgv.Items)
ListView? dgv = menus[0].GetDataGridView();
if (dgv != null)
{
RowData rowData = item.data;
if (rowData.Path.StartsWith($"{e.OldFullPath}"))
foreach (ListViewItemData item in dgv.Items)
{
string path = rowData.Path.Replace(e.OldFullPath, e.FullPath);
FileAttributes attr = File.GetAttributes(path);
bool isFolder = (attr & FileAttributes.Directory) == FileAttributes.Directory;
if (isFolder)
RowData rowData = item.data;
if (rowData.Path.StartsWith($"{e.OldFullPath}"))
{
path = Path.GetDirectoryName(path);
}
string path = rowData.Path.Replace(e.OldFullPath, e.FullPath);
FileAttributes attr = File.GetAttributes(path);
bool isFolder = (attr & FileAttributes.Directory) == FileAttributes.Directory;
if (isFolder)
{
path = Path.GetDirectoryName(path);
}
RowData rowDataRenamed = new(isFolder, rowData.IsAddionalItem, false, 0, path);
if (FolderOptions.IsHidden(rowDataRenamed))
RowData rowDataRenamed = new(isFolder, rowData.IsAddionalItem, false, 0, path);
if (FolderOptions.IsHidden(rowDataRenamed))
{
continue;
}
IconReader.RemoveIconFromCache(rowData.Path);
rowDataRenamed.ReadIcon(true);
rowDatas.Add(rowDataRenamed);
}
else
{
continue;
rowDatas.Add(rowData);
}
IconReader.RemoveIconFromCache(rowData.Path);
rowDataRenamed.ReadIcon(true);
rowDatas.Add(rowDataRenamed);
}
else
{
rowDatas.Add(rowData);
}
}
@ -1288,22 +1298,26 @@ namespace SystemTrayMenu.Business
{
try
{
List<ListViewItemData> rowsToRemove = new();
ListView dgv = menus[0].GetDataGridView();
foreach (ListViewItemData item in dgv.Items)
ListView? dgv = menus[0].GetDataGridView();
if (dgv != null)
{
RowData rowData = item.data;
if (rowData.Path == e.FullPath ||
rowData.Path.StartsWith($"{e.FullPath}\\"))
{
IconReader.RemoveIconFromCache(rowData.Path);
rowsToRemove.Add(item);
}
}
List<ListViewItemData> rowsToRemove = new();
foreach (ListViewItemData rowToRemove in rowsToRemove)
{
dgv.Items.Remove(rowToRemove);
foreach (ListViewItemData item in dgv.Items)
{
RowData rowData = item.data;
if (rowData.Path == e.FullPath ||
rowData.Path.StartsWith($"{e.FullPath}\\"))
{
IconReader.RemoveIconFromCache(rowData.Path);
rowsToRemove.Add(item);
}
}
foreach (ListViewItemData rowToRemove in rowsToRemove)
{
dgv.Items.Remove(rowToRemove);
}
}
keyboardInput.ClearIsSelectedByKey();
@ -1339,10 +1353,13 @@ namespace SystemTrayMenu.Business
rowData,
};
ListView dgv = menus[0].GetDataGridView();
foreach (ListViewItemData item in dgv.Items)
ListView? dgv = menus[0].GetDataGridView();
if (dgv != null)
{
rowDatas.Add(item.data);
foreach (ListViewItemData item in dgv.Items)
{
rowDatas.Add(item.data);
}
}
rowDatas = MenusHelpers.SortItems(rowDatas);

View file

@ -1,12 +1,12 @@
// <copyright file="MenuData.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu.DataClasses
{
using System.Collections.Generic;
internal enum MenuDataDirectoryState
// <copyright file="MenuData.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu.DataClasses
{
using System.Collections.Generic;
internal enum MenuDataDirectoryState
{
/// <summary>
/// State not defined or data still loading
@ -15,39 +15,35 @@ namespace SystemTrayMenu.DataClasses
/// <summary>
/// Data is available
/// </summary>
/// </summary>
Valid,
/// <summary>
/// Loading finished but no data available
/// </summary>
/// </summary>
Empty,
/// <summary>
/// Loading failed, so no data available
/// </summary>
NoAccess,
}
internal struct MenuData
{
public MenuData(int level)
{
RowDatas = new List<RowData>();
DirectoryState = MenuDataDirectoryState.Undefined;
Level = level;
RowDataParent = null;
IsNetworkRoot = false;
}
internal List<RowData> RowDatas { get; set; }
internal MenuDataDirectoryState DirectoryState { get; set; }
internal int Level { get; }
internal RowData RowDataParent { get; set; }
internal bool IsNetworkRoot { get; set; }
}
/// </summary>
NoAccess,
}
internal struct MenuData
{
public MenuData(int level)
{
Level = level;
}
internal List<RowData> RowDatas { get; set; } = new ();
internal MenuDataDirectoryState DirectoryState { get; set; } = MenuDataDirectoryState.Undefined;
internal int Level { get; }
internal RowData? RowDataParent { get; set; } = null;
internal bool IsNetworkRoot { get; set; } = false;
}
}

View file

@ -5,7 +5,6 @@
namespace SystemTrayMenu.DataClasses
{
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows;
@ -99,11 +98,11 @@ namespace SystemTrayMenu.DataClasses
}
}
internal Icon Icon { get; private set; }
internal Icon? Icon { get; private set; }
internal FileInfo FileInfo { get; }
internal FileInfo? FileInfo { get; }
internal string Path { get; }
internal string? Path { get; }
internal bool IsFolder { get; }
@ -113,23 +112,23 @@ namespace SystemTrayMenu.DataClasses
internal int Level { get; set; }
internal string FileExtension { get; }
internal string? FileExtension { get; }
internal bool IsLink { get; }
internal string ResolvedPath { get; }
internal string? ResolvedPath { get; }
internal bool IsLinkToFolder { get; }
internal bool ShowOverlay { get; }
internal string Text { get; }
internal string? Text { get; }
internal bool ContainsMenu { get; }
internal bool IsMainMenu { get; }
internal Menu SubMenu { get; set; }
internal Menu? SubMenu { get; set; }
internal bool IsMenuOpen { get; set; }
@ -147,7 +146,7 @@ namespace SystemTrayMenu.DataClasses
internal bool ProcessStarted { get; set; }
internal Icon ReadIcon(bool updateIconInBackground)
internal void ReadIcon(bool updateIconInBackground)
{
if (IsFolder || IsLinkToFolder)
{
@ -171,8 +170,6 @@ namespace SystemTrayMenu.DataClasses
Icon = AddIconOverlay(Icon, Properties.Resources.White50Percentage);
}
}
return Icon;
}
internal void MouseDown(ListView dgv, MouseButtonEventArgs e)
@ -217,8 +214,10 @@ namespace SystemTrayMenu.DataClasses
{
try
{
string parentFolder = System.IO.Path.GetDirectoryName(Path);
Directory.GetFiles(parentFolder);
string? parentFolder = System.IO.Path.GetDirectoryName(Path);
// Assume folder is not null as failure will be catched any ways
Directory.GetFiles(parentFolder!);
}
catch (Exception ex)
{
@ -273,7 +272,7 @@ namespace SystemTrayMenu.DataClasses
(e == null || e.LeftButton == MouseButtonState.Pressed))
{
ProcessStarted = true;
string workingDirectory = System.IO.Path.GetDirectoryName(ResolvedPath);
string? workingDirectory = System.IO.Path.GetDirectoryName(ResolvedPath);
Log.ProcessStart(Path, string.Empty, false, workingDirectory, true, ResolvedPath);
if (!Properties.Settings.Default.StaysOpenWhenItemClicked)
{

View file

@ -6,8 +6,6 @@ namespace SystemTrayMenu.Helpers
{
using System;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.Reflection.Metadata;
using System.Threading;
using System.Windows.Input;
using SharpDX.DirectInput;
@ -17,7 +15,7 @@ namespace SystemTrayMenu.Helpers
{
private readonly System.Timers.Timer timerReadJoystick = new();
private readonly object lockRead = new();
private Joystick joystick;
private Joystick? joystick;
private Key pressingKey;
private int pressingKeyCounter;
private bool joystickHelperEnabled;
@ -38,7 +36,7 @@ namespace SystemTrayMenu.Helpers
Dispose(false);
}
public event Action<Key, ModifierKeys> KeyPressed;
public event Action<Key, ModifierKeys>? KeyPressed;
public void Enable()
{
@ -105,7 +103,7 @@ namespace SystemTrayMenu.Helpers
return keys;
}
private void ReadJoystickLoop(object sender, System.Timers.ElapsedEventArgs e)
private void ReadJoystickLoop(object? sender, System.Timers.ElapsedEventArgs e)
{
if (joystickHelperEnabled)
{
@ -129,45 +127,48 @@ namespace SystemTrayMenu.Helpers
private void ReadJoystick()
{
try
if (joystick != null)
{
joystick.Poll();
JoystickUpdate[] datas = joystick.GetBufferedData();
foreach (JoystickUpdate state in datas)
try
{
if (state.Value < 0)
joystick.Poll();
JoystickUpdate[] datas = joystick.GetBufferedData();
foreach (JoystickUpdate state in datas)
{
pressingKey = Key.None;
pressingKeyCounter = 0;
continue;
if (state.Value < 0)
{
pressingKey = Key.None;
pressingKeyCounter = 0;
continue;
}
Key key = ReadKeyFromState(state);
if (key != Key.None)
{
KeyPressed?.Invoke(key, ModifierKeys.None);
if (state.Offset == JoystickOffset.PointOfViewControllers0)
{
pressingKeyCounter = 0;
pressingKey = key;
}
}
}
Key key = ReadKeyFromState(state);
if (key != Key.None)
if (pressingKey != Key.None)
{
KeyPressed?.Invoke(key, ModifierKeys.None);
if (state.Offset == JoystickOffset.PointOfViewControllers0)
pressingKeyCounter += 1;
if (pressingKeyCounter > 1)
{
pressingKeyCounter = 0;
pressingKey = key;
KeyPressed?.Invoke(pressingKey, ModifierKeys.None);
}
}
}
if (pressingKey != Key.None)
catch
{
pressingKeyCounter += 1;
if (pressingKeyCounter > 1)
{
KeyPressed?.Invoke(pressingKey, ModifierKeys.None);
}
joystick?.Dispose();
joystick = null;
}
}
catch
{
joystick?.Dispose();
joystick = null;
}
}
private void InitializeJoystick()

View file

@ -6,7 +6,7 @@ namespace SystemTrayMenu.Properties
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
@ -43,9 +43,23 @@ namespace SystemTrayMenu.Properties
$"SystemTrayMenu"),
$"user-{Environment.MachineName}.config");
public static string ConfigPathAssembly => Path.Combine(
Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName,
$"user.config");
public static string? ConfigPathAssembly
{
get
{
Assembly? assembly = Assembly.GetEntryAssembly();
if (assembly != null)
{
string? location = Directory.GetParent(assembly.Location)?.FullName;
if (location != null)
{
return Path.Combine(location, $"user.config");
}
}
return null;
}
}
/// <summary>
/// Gets or sets override.
@ -81,7 +95,7 @@ namespace SystemTrayMenu.Properties
{
try
{
File.Delete(ConfigPathAssembly);
File.Delete(ConfigPathAssembly!);
}
catch (Exception ex)
{
@ -126,22 +140,28 @@ namespace SystemTrayMenu.Properties
IsDirty = false,
};
// need the type of the value for the strong typing
Type t = Type.GetType(setting.PropertyType.FullName);
if (SettingsDictionary.ContainsKey(setting.Name))
{
value.SerializedValue = SettingsDictionary[setting.Name].Value;
value.PropertyValue = Convert.ChangeType(SettingsDictionary[setting.Name].Value, t, CultureInfo.InvariantCulture);
// need the type of the value for the strong typing
string? typename = setting.PropertyType.FullName;
if (typename != null)
{
Type? t = Type.GetType(typename);
if (t != null)
{
if (SettingsDictionary.ContainsKey(setting.Name))
{
value.SerializedValue = SettingsDictionary[setting.Name].Value;
value.PropertyValue = Convert.ChangeType(SettingsDictionary[setting.Name].Value, t, CultureInfo.InvariantCulture);
}
else
{
// use defaults in the case where there are no settings yet
value.SerializedValue = setting.DefaultValue;
value.PropertyValue = Convert.ChangeType(setting.DefaultValue, t, CultureInfo.InvariantCulture);
}
values.Add(value);
}
}
else
{
// use defaults in the case where there are no settings yet
value.SerializedValue = setting.DefaultValue;
value.PropertyValue = Convert.ChangeType(setting.DefaultValue, t, CultureInfo.InvariantCulture);
}
values.Add(value);
}
return values;
@ -159,7 +179,7 @@ namespace SystemTrayMenu.Properties
{
SettingStruct setting = new()
{
Value = value.PropertyValue == null ? string.Empty : value.PropertyValue.ToString(),
Value = value.PropertyValue == null ? string.Empty : value.PropertyValue.ToString() ?? string.Empty,
Name = value.Name,
SerializeAs = value.Property.SerializeAs.ToString(),
};
@ -182,7 +202,7 @@ namespace SystemTrayMenu.Properties
/// Creates an empty user.config file...looks like the one MS creates.
/// This could be overkill a simple key/value pairing would probably do.
/// </summary>
private static void CreateEmptyConfigIfNotExists(string path)
private static void CreateEmptyConfigIfNotExists(string? path)
{
if (!File.Exists(path))
{
@ -205,7 +225,7 @@ namespace SystemTrayMenu.Properties
Log.Warn($"Failed to store config at assembly location {path}", ex);
}
}
}
}
private static bool IsConfigPathAssembly()
{
@ -222,9 +242,9 @@ namespace SystemTrayMenu.Properties
return isconfigPathAssembly;
}
private static XDocument LoadOrGetNew(string path)
private static XDocument? LoadOrGetNew(string path)
{
XDocument xDocument = null;
XDocument? xDocument = null;
try
{
xDocument = XDocument.Load(path);
@ -255,10 +275,10 @@ namespace SystemTrayMenu.Properties
CreateEmptyConfigIfNotExists(UserConfigPath);
// load the xml
XDocument configXml;
XDocument? configXml;
if (IsConfigPathAssembly())
{
configXml = LoadOrGetNew(ConfigPathAssembly);
configXml = LoadOrGetNew(ConfigPathAssembly!);
}
else
{
@ -268,19 +288,27 @@ namespace SystemTrayMenu.Properties
if (configXml != null)
{
// get all of the <setting name="..." serializeAs="..."> elements.
IEnumerable<XElement> settingElements = configXml.Element(Config).Element(UserSettings).Element(typeof(Settings).FullName).Elements(Setting);
IEnumerable<XElement>? settingElements = configXml.Element(Config)?.Element(UserSettings)?.Element(typeof(Settings).FullName)?.Elements(Setting);
// iterate through, adding them to the dictionary, (checking for nulls, xml no likey nulls)
// using "String" as default serializeAs...just in case, no real good reason.
foreach (XElement element in settingElements)
{
SettingStruct newSetting = new()
{
Name = element.Attribute(NameOf) == null ? string.Empty : element.Attribute(NameOf).Value,
SerializeAs = element.Attribute(SerializeAs) == null ? "String" : element.Attribute(SerializeAs).Value,
Value = element.Value ?? string.Empty,
};
SettingsDictionary.Add(element.Attribute(NameOf).Value, newSetting);
// using "String" as default serializeAs...just in case, no real good reason.
if (settingElements != null)
{
foreach (XElement element in settingElements)
{
string? name = element.Attribute(NameOf)?.Value;
if (name != null)
{
string? serializeAs = element.Attribute(SerializeAs)?.Value;
SettingStruct newSetting = new()
{
Name = element.Attribute(NameOf) == null ? string.Empty : name,
SerializeAs = serializeAs == null ? "String" : serializeAs,
Value = element.Value ?? string.Empty,
};
SettingsDictionary.Add(name, newSetting);
}
}
}
}
}
@ -291,10 +319,10 @@ namespace SystemTrayMenu.Properties
private void SaveValuesToFile()
{
// load the current xml from the file.
XDocument configXml;
XDocument? configXml;
if (IsConfigPathAssembly())
{
configXml = LoadOrGetNew(ConfigPathAssembly);
configXml = LoadOrGetNew(ConfigPathAssembly!);
}
else
{
@ -304,12 +332,12 @@ namespace SystemTrayMenu.Properties
if (configXml != null)
{
// get the settings group (e.g. <Company.Project.Desktop.Settings>)
XElement settingsSection = configXml.Element(Config).Element(UserSettings).Element(typeof(Settings).FullName);
XElement? settingsSection = configXml.Element(Config)?.Element(UserSettings)?.Element(typeof(Settings).FullName);
// iterate though the dictionary, either updating the value or adding the new setting.
foreach (KeyValuePair<string, SettingStruct> entry in SettingsDictionary)
{
XElement setting = settingsSection.Elements().FirstOrDefault(e => e.Attribute(NameOf).Value == entry.Key);
XElement? setting = settingsSection?.Elements().FirstOrDefault(e => e.Attribute(NameOf)?.Value == entry.Key);
if (setting == null)
{
// this can happen if a new setting is added via the .settings designer.
@ -317,7 +345,7 @@ namespace SystemTrayMenu.Properties
newSetting.Add(new XAttribute(NameOf, entry.Value.Name));
newSetting.Add(new XAttribute(SerializeAs, entry.Value.SerializeAs));
newSetting.Value = entry.Value.Value ?? string.Empty;
settingsSection.Add(newSetting);
settingsSection?.Add(newSetting);
}
else
{
@ -328,7 +356,7 @@ namespace SystemTrayMenu.Properties
if (IsConfigPathAssembly())
{
configXml.Save(ConfigPathAssembly);
configXml.Save(ConfigPathAssembly!);
}
configXml.Save(UserConfigPath);

View file

@ -6,7 +6,6 @@ namespace SystemTrayMenu.UserInterface
{
using System;
using System.Windows;
using System.Windows.Input;
using Hardcodet.Wpf.TaskbarNotification;
using SystemTrayMenu.Helper;
using SystemTrayMenu.Utilities;
@ -23,20 +22,16 @@ namespace SystemTrayMenu.UserInterface
AppContextMenu contextMenus = new();
contextMenus.ClickedOpenLog += ClickedOpenLog;
void ClickedOpenLog()
{
OpenLog?.Invoke();
}
contextMenus.ClickedOpenLog += () => OpenLog?.Invoke();
notifyIcon.ContextMenu = contextMenus.Create();
notifyIcon.LeftClickCommand = new ActionCommand((_) => Click?.Invoke());
notifyIcon.DoubleClickCommand = new ActionCommand((_) => Click?.Invoke());
}
public event Action Click;
public event Action? Click;
public event Action OpenLog;
public event Action? OpenLog;
public void Dispose()
{

View file

@ -166,8 +166,8 @@ namespace SystemTrayMenu.UserInterface
#endif
#if TODO // TOUCH
bool isTouchEnabled = NativeMethods.IsTouchEnabled();
if ((isTouchEnabled && Properties.Settings.Default.DragDropItemsEnabledTouch) ||
(!isTouchEnabled && Properties.Settings.Default.DragDropItemsEnabled))
if ((isTouchEnabled && Settings.Default.DragDropItemsEnabledTouch) ||
(!isTouchEnabled && Settings.Default.DragDropItemsEnabled))
{
AllowDrop = true;
DragEnter += DragDropHelper.DragEnter;
@ -492,7 +492,7 @@ namespace SystemTrayMenu.UserInterface
/// <param name="isCustomLocationOutsideOfScreen">isCustomLocationOutsideOfScreen.</param>
internal void AdjustSizeAndLocation(
Rect bounds,
Menu menuPredecessor,
Menu? menuPredecessor,
StartLocation startLocation,
bool isCustomLocationOutsideOfScreen)
{
@ -500,7 +500,7 @@ namespace SystemTrayMenu.UserInterface
AdjustDataGridViewHeight(menuPredecessor, bounds.Height);
AdjustDataGridViewWidth();
bool useCustomLocation = Properties.Settings.Default.UseCustomLocation || lastLocation.X > 0;
bool useCustomLocation = Settings.Default.UseCustomLocation || lastLocation.X > 0;
bool changeDirectionWhenOutOfBounds = true;
if (menuPredecessor != null)
@ -519,13 +519,13 @@ namespace SystemTrayMenu.UserInterface
// Use this menu as predecessor and overwrite location with CustomLocation
menuPredecessor = this;
Tag = new RowData();
Left = Properties.Settings.Default.CustomLocationX;
Top = Properties.Settings.Default.CustomLocationY;
Left = Settings.Default.CustomLocationX;
Top = Settings.Default.CustomLocationY;
directionToRight = true;
startLocation = StartLocation.Predecessor;
changeDirectionWhenOutOfBounds = false;
}
else if (Properties.Settings.Default.AppearAtMouseLocation)
else if (Settings.Default.AppearAtMouseLocation)
{
// Do not adjust location again because Cursor.Postion changed
if (Tag != null)
@ -635,16 +635,16 @@ namespace SystemTrayMenu.UserInterface
}
if (Level != 0 &&
!Properties.Settings.Default.AppearNextToPreviousMenu &&
menuPredecessor != null && menuPredecessor.Width > Properties.Settings.Default.OverlappingOffsetPixels)
!Settings.Default.AppearNextToPreviousMenu &&
menuPredecessor != null && menuPredecessor.Width > Settings.Default.OverlappingOffsetPixels)
{
if (directionToRight)
{
x = x - menuPredecessor.Width + Properties.Settings.Default.OverlappingOffsetPixels;
x = x - menuPredecessor.Width + Settings.Default.OverlappingOffsetPixels;
}
else
{
x = x + menuPredecessor.Width - Properties.Settings.Default.OverlappingOffsetPixels;
x = x + menuPredecessor.Width - Settings.Default.OverlappingOffsetPixels;
}
}
@ -749,7 +749,7 @@ namespace SystemTrayMenu.UserInterface
Left = x;
Top = y;
if (Properties.Settings.Default.RoundCorners)
if (Settings.Default.RoundCorners)
{
windowFrame.CornerRadius = new CornerRadius(CornerRadius);
}
@ -842,12 +842,12 @@ namespace SystemTrayMenu.UserInterface
e.Handled = true;
}
private void AdjustDataGridViewHeight(Menu menuPredecessor, double screenHeightMax)
private void AdjustDataGridViewHeight(Menu? menuPredecessor, double screenHeightMax)
{
double factor = Properties.Settings.Default.RowHeighteInPercentage / 100f;
double factor = Settings.Default.RowHeighteInPercentage / 100f;
if (NativeMethods.IsTouchEnabled())
{
factor = Properties.Settings.Default.RowHeighteInPercentageTouch / 100f;
factor = Settings.Default.RowHeighteInPercentageTouch / 100f;
}
if (menuPredecessor == null)
@ -876,7 +876,7 @@ namespace SystemTrayMenu.UserInterface
{
#endif
double heightMaxByOptions = Scaling.Factor * Scaling.FactorByDpi *
450f * (Properties.Settings.Default.HeightMaxInPercent / 100f);
450f * (Settings.Default.HeightMaxInPercent / 100f);
MaxHeight = Math.Min(screenHeightMax, heightMaxByOptions);
#if TODO // SEARCH
dgvHeightSet = true;
@ -901,7 +901,7 @@ namespace SystemTrayMenu.UserInterface
return;
}
double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f;
double factorIconSizeInPercent = Settings.Default.IconSizeInPercent / 100f;
// IcoWidth 100% = 21px, 175% is 33, +3+2 is padding from ColumnIcon
double icoWidth = (16 * Scaling.FactorByDpi) + 5;
@ -926,7 +926,7 @@ namespace SystemTrayMenu.UserInterface
Resources["ColumnTextWidth"] = Math.Min(
renderedMaxWidth,
(double)(Scaling.Factor * Scaling.FactorByDpi * 400f * (Properties.Settings.Default.WidthMaxInPercent / 100f)));
(double)(Scaling.Factor * Scaling.FactorByDpi * 400f * (Settings.Default.WidthMaxInPercent / 100f)));
}
private void HandleScrollChanged(object sender, ScrollChangedEventArgs e)
@ -981,7 +981,7 @@ namespace SystemTrayMenu.UserInterface
foreach (DataRow row in data.Rows)
{
RowData rowData = (RowData)row[2];
if (rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult)
if (rowData.IsAddionalItem && Settings.Default.ShowOnlyAsSearchResult)
{
row[columnSortIndex] = 99;
}
@ -1022,7 +1022,7 @@ namespace SystemTrayMenu.UserInterface
RowData rowData = (RowData)row.Cells[2].Value;
if (!string.IsNullOrEmpty(userPattern) ||
!(rowData.IsAddionalItem && Properties.Settings.Default.ShowOnlyAsSearchResult))
!(rowData.IsAddionalItem && Settings.Default.ShowOnlyAsSearchResult))
{
rowData.RowIndex = row.Index;
@ -1146,7 +1146,11 @@ namespace SystemTrayMenu.UserInterface
if (rowData.IconLoading)
{
iconsToUpdate++;
row.ColumnIcon = rowData.ReadIcon(false).ToImageSource();
rowData.ReadIcon(false);
if (rowData.Icon != null)
{
row.ColumnIcon = rowData.Icon.ToImageSource();
}
}
}
@ -1179,19 +1183,19 @@ namespace SystemTrayMenu.UserInterface
Top = Top + mousePos.Y - lastLocation.Y;
lastLocation = mousePos;
Properties.Settings.Default.CustomLocationX = (int)Left;
Properties.Settings.Default.CustomLocationY = (int)Top;
Settings.Default.CustomLocationX = (int)Left;
Settings.Default.CustomLocationY = (int)Top;
}
}
private void Menu_MouseUp(object sender, MouseButtonEventArgs e)
{
mouseDown = false;
if (Properties.Settings.Default.UseCustomLocation)
if (Settings.Default.UseCustomLocation)
{
if (!SettingsWindow.IsOpen())
{
Properties.Settings.Default.Save();
Settings.Default.Save();
}
}
}

View file

@ -69,7 +69,7 @@ namespace SystemTrayMenu.Utilities
public static void RemoveIconFromCache(string path)
{
if (DictIconCacheMainMenu.Remove(path, out Icon iconToRemove))
if (DictIconCacheMainMenu.Remove(path, out Icon? iconToRemove))
{
iconToRemove?.Dispose();
}
@ -105,7 +105,7 @@ namespace SystemTrayMenu.Utilities
key = extension + linkOverlay;
}
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon icon) &&
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon? icon) &&
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
{
icon = Resources.StaticResources.LoadingIcon;
@ -143,7 +143,7 @@ namespace SystemTrayMenu.Utilities
string key = path;
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon icon) &&
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon? icon) &&
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
{
icon = Resources.StaticResources.LoadingIcon;
@ -174,9 +174,9 @@ namespace SystemTrayMenu.Utilities
return icon;
}
public static Icon GetIconSTA(string path, string resolvedPath, bool linkOverlay, IconSize size, bool isFolder)
public static Icon? GetIconSTA(string path, string resolvedPath, bool linkOverlay, IconSize size, bool isFolder)
{
Icon icon = null;
Icon? icon = null;
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
{
icon = GetIcon(path, resolvedPath, linkOverlay, size, isFolder);
@ -184,7 +184,7 @@ namespace SystemTrayMenu.Utilities
else
{
Thread staThread = new(new ParameterizedThreadStart(StaThreadMethod));
void StaThreadMethod(object obj)
void StaThreadMethod(object? obj)
{
icon = GetIcon(path, resolvedPath, linkOverlay, size, isFolder);
}
@ -197,9 +197,9 @@ namespace SystemTrayMenu.Utilities
return icon;
}
public static Icon AddIconOverlay(Icon originalIcon, Icon overlay)
public static Icon? AddIconOverlay(Icon? originalIcon, Icon overlay)
{
Icon icon = null;
Icon? icon = originalIcon;
if (originalIcon != null)
{
using Bitmap target = new(originalIcon.Width, originalIcon.Height, PixelFormat.Format32bppArgb);
@ -239,9 +239,9 @@ namespace SystemTrayMenu.Utilities
return isExtensionWithSameIcon;
}
private static Icon GetIcon(string path, string resolvedPath, bool linkOverlay, IconSize size, bool isFolder)
private static Icon? GetIcon(string path, string resolvedPath, bool linkOverlay, IconSize size, bool isFolder)
{
Icon icon;
Icon? icon;
if (Path.GetExtension(path).Equals(".ico", StringComparison.InvariantCultureIgnoreCase))
{
icon = Icon.ExtractAssociatedIcon(path);
@ -288,10 +288,10 @@ namespace SystemTrayMenu.Utilities
return flags;
}
private static Icon GetIcon(
private static Icon? GetIcon(
string path, bool linkOverlay, NativeMethods.SHFILEINFO shFileInfo, IntPtr imageList)
{
Icon icon = null;
Icon? icon = null;
if (imageList != IntPtr.Zero)
{
IntPtr hIcon;

View file

@ -149,7 +149,7 @@ namespace SystemTrayMenu.Utilities
string fileName,
string arguments = "",
bool doubleQuoteArg = false,
string workingDirectory = "",
string? workingDirectory = null,
bool createNoWindow = false,
string resolvedPath = "")
{
@ -166,7 +166,7 @@ namespace SystemTrayMenu.Utilities
{
FileName = fileName,
Arguments = arguments,
WorkingDirectory = workingDirectory,
WorkingDirectory = workingDirectory ?? string.Empty,
CreateNoWindow = createNoWindow,
UseShellExecute = true,
},