Lots of major improvements

This commit is contained in:
Peter Kirmeier 2022-12-03 02:14:15 +01:00
parent 1b24ef14d8
commit 9fffebafa2
20 changed files with 54 additions and 98 deletions

View file

@ -2,8 +2,6 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#nullable enable
namespace SystemTrayMenu
{
using System;

View file

@ -26,6 +26,7 @@ namespace SystemTrayMenu.Business
internal class Menus : IDisposable
{
private readonly Dispatcher dispatchter = Dispatcher.CurrentDispatcher;
private readonly Menu[] menus = new Menu[MenuDefines.MenusMax];
private readonly BackgroundWorker workerMainMenu = new();
private readonly List<BackgroundWorker> workersSubMenu = new();
@ -613,7 +614,7 @@ namespace SystemTrayMenu.Business
menu.AdjustControls(title, menuData.Validity);
menu.UserClickedOpenFolder += () => OpenFolder(path);
menu.Level = menuData.Level;
menu.Scrolled += AdjustMenusSizeAndLocation; // TODO: Only update vertical location while scrolling?
menu.MenuScrolled += AdjustMenusSizeAndLocation; // TODO: Only update vertical location while scrolling?
#if TODO // Misc MouseEvents
menu.MouseLeave += waitLeave.Start;
menu.MouseEnter += waitLeave.Stop;
@ -997,10 +998,13 @@ namespace SystemTrayMenu.Business
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
if (menus[0].IsUsable)
dispatchter.Invoke(() =>
{
menus[0].Tag = null;
}
if (menus[0].IsUsable)
{
menus[0].Tag = null;
}
});
}
private void ShowSubMenu(Menu menuToShow)

View file

@ -111,7 +111,7 @@ namespace SystemTrayMenu
}
}
public static void SetFolderByUser(Window owner = null, bool save = true)
public static void SetFolderByUser(Window? owner = null, bool save = true)
{
using FolderDialog dialog = new();
dialog.InitialFolder = Path;

View file

@ -2,8 +2,6 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#nullable enable
namespace SystemTrayMenu.Helper
{
using System;

View file

@ -53,14 +53,7 @@ namespace SystemTrayMenu.Helper.Updater
{
if (newVersionForm != null)
{
if (newVersionForm!.CheckAccess())
{
newVersionForm.Dispatcher.Invoke(() => newVersionForm?.Activate());
}
else
{
newVersionForm.Activate();
}
newVersionForm!.HandleInvoke(() => newVersionForm?.Activate());
}
else
{

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.DllImports
{
using System;

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.DllImports
{
using System;

View file

@ -19,6 +19,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>true</UseApplicationTrust>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Nullable>enable</Nullable>
<Platforms>x64;x86;AnyCPU</Platforms>
<Configurations>Debug;Release;ReleasePackage</Configurations>
</PropertyGroup>

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System;

View file

@ -2,8 +2,6 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System;

View file

@ -42,7 +42,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
/// <param name="owner">The window the dialog is assigned to.</param>
/// <returns>True is returned on successful user interaction and when not cancelled by the user otherwise false is returned.</returns>
[SupportedOSPlatform("windows")]
public bool ShowDialog(Window owner)
public bool ShowDialog(Window? owner)
{
NativeMethods.IFileDialog frm = (NativeMethods.IFileDialog)new NativeMethods.FileOpenDialogRCW();
frm.GetOptions(out uint options);

View file

@ -101,10 +101,10 @@
<TextBlock x:Name="txtTitle" TextTrimming="CharacterEllipsis" Margin="14,0"><Run Text="title"/></TextBlock>
</Label>
<DockPanel x:Name="searchPanel" DockPanel.Dock="Top" Margin="6,0">
<Separator x:Name="panelLine" Height="1" Margin="0,1" DockPanel.Dock="Bottom"/>
<Image x:Name="pictureBoxSearch" Width="16" Height="16" Margin="1" DockPanel.Dock="Left" Source="{StaticResource ic_fluent_search_48_regularDrawingImage}"/>
<TextBox x:Name="textBoxSearch" BorderBrush="{x:Null}" TextInput="textBoxSearch_TextInput" Background="{x:Null}" />
<TextBox x:Name="textBoxSearch" BorderBrush="{x:Null}" TextInput="textBoxSearch_TextInput" Background="{x:Null}" SelectionTextBrush="Red" SelectionBrush="#FFDAFF00" />
</DockPanel>
<Separator x:Name="panelLine" Height="1" Margin="6,1" DockPanel.Dock="Top"/>
<DockPanel x:Name="tableLayoutPanelBottom" DockPanel.Dock="Bottom" Margin="12,4">
<Label x:Name="labelItems" Content="0 items" Padding="0" DockPanel.Dock="Left" FontWeight="Bold" VerticalAlignment="Center" Margin="0,0,10,0"/>

View file

@ -2,8 +2,6 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System;
@ -222,7 +220,7 @@ namespace SystemTrayMenu.UserInterface
};
}
internal new event Action Scrolled;
internal new event Action MenuScrolled;
#if TODO // Misc MouseEvents
internal new event Action MouseEnter;
@ -463,7 +461,6 @@ namespace SystemTrayMenu.UserInterface
if (!Config.ShowSearchBar)
{
searchPanel.Visibility = Visibility.Collapsed;
panelLine.Visibility = Visibility.Collapsed;
}
if (!Config.ShowCountOfElementsBelow &&
@ -711,35 +708,6 @@ namespace SystemTrayMenu.UserInterface
// It also makes sure all height and location information is up to date
menuPredecessor.UpdateLayout();
#if TODO // SCROLL: bounds within list using scrollviewer index while calculating size once
// When scrolled, we have to reduce the index number as we calculate based on visual tree
int index = trigger.RowIndex;
ScrollViewer? scrollViewer = (VisualTreeHelper.GetChild(dgv, 0) as Decorator)?.Child as ScrollViewer;
if (scrollViewer != null)
{
// Show mid height or at bottom
if (scrollViewer.VerticalOffset <= index)
{
if ((int)(scrollViewer.VerticalOffset + scrollViewer.ViewportHeight) < index)
{
// Outside of visible list while index is even further below: place at bottom (last entry)
index = (int)scrollViewer.ViewportHeight;
}
else
{
// Remove skipped entries from index when scrolled down
index -= (int)scrollViewer.VerticalOffset;
}
}
else
{
// Outside of visible list while index is even further above: place at top (first entry)
index = 0;
}
}
y += menuPredecessor.GetRelativeChildPositionTo(dgv.FindVisualChildOfType<ListViewItem>(index)).Y;
#else // TODO: SCROLL: Sum up offsets by calculating final offset based on each items' height
// When scrolled, we have to reduce the index number as we calculate based on visual tree
int startIndex = 0;
double offset = 0D;
@ -774,32 +742,39 @@ namespace SystemTrayMenu.UserInterface
}
}
y += menuPredecessor.GetRelativeChildPositionTo(dgv).Y + (int)offset;
#endif
if (offset < 0)
{
// Do not allow to show window higher than previous window
offset = 0;
}
else
{
double offsetList = menuPredecessor.GetRelativeChildPositionTo(dgv).Y;
offsetList += dgv.ActualHeight;
if (offsetList < offset)
{
// Do not allow to show window below last entry position of list
offset = offsetList;
}
}
y += (int)offset;
}
#if TODO // SCROLL: Do we want this - Move upwards when there is no content? (Feels odd to me, topeterk)
// Maybe always move it up only the height of labelTitle?
// when warning is shown, the title should appear at same height as selected row
if (searchPanel.Visibility != Visibility.Visible)
if (searchPanel.Visibility == Visibility.Collapsed)
{
// TODO: This seems to fail in version 1 as search bar is always visible, so no adjustement is made
// And even when adjustment is made, it moves the menu even further down rather up?
y -= this.GetRelativeChildPositionTo(labelItems).Y;
y += menuPredecessor.searchPanel.ActualHeight;
}
#endif
// Move vertically when out of bounds
if (bounds.Y + bounds.Height < y + Height)
{
y = bounds.Y + bounds.Height - Height;
}
#if !TODO // SCROLL: Upper screen bounds
else if (y < bounds.Y)
{
y = bounds.Y;
}
#endif
break;
case StartLocation.TopRight:
@ -849,6 +824,8 @@ namespace SystemTrayMenu.UserInterface
private void HandlePreviewKeyDown(object sender, KeyEventArgs e)
{
searchPanel.Visibility= Visibility.Visible;
ModifierKeys modifiers = Keyboard.Modifiers;
switch (e.Key)
{
@ -986,7 +963,7 @@ namespace SystemTrayMenu.UserInterface
{
if (IsLoaded)
{
Scrolled?.Invoke();
MenuScrolled?.Invoke();
}
}

View file

@ -2,8 +2,6 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System;

View file

@ -2,8 +2,6 @@
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System;
@ -306,6 +304,8 @@ namespace SystemTrayMenu.UserInterface
Log.Warn("PathsAddToMainMenu", ex);
}
EnableButtonAddStartMenu();
checkBoxGenerateShortcutsToDrives.IsChecked = Settings.Default.GenerateShortcutsToDrives;
checkBoxStayOpenWhenItemClicked.IsChecked = Settings.Default.StaysOpenWhenItemClicked;
@ -395,14 +395,7 @@ namespace SystemTrayMenu.UserInterface
{
if (IsOpen())
{
if (settingsForm!.CheckAccess())
{
settingsForm.Dispatcher.Invoke(() => settingsForm?.Activate());
}
else
{
settingsForm.Activate();
}
settingsForm!.HandleInvoke(() => settingsForm?.Activate());
}
else
{
@ -943,7 +936,6 @@ namespace SystemTrayMenu.UserInterface
private void ButtonAddSampleStartMenuFolder_Click(object sender, RoutedEventArgs e)
{
// dataGridViewFolders.Rows.Clear(); // TODO: This line must be removed in version 1, right?
string folderPathCommonStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
dataGridViewFolders.Items.Add(new ListViewItemData(folderPathCommonStartMenu, true, true));
EnableButtonAddStartMenu();

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System;

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.UserInterface
{
using System.IO;

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.Utilities
{
using System;

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.Utilities
{
using System;

View file

@ -4,8 +4,6 @@
//
// Copyright (c) 2022-2022 Peter Kirmeier
#nullable enable
namespace SystemTrayMenu.Utilities
{
using System;
@ -14,10 +12,23 @@ namespace SystemTrayMenu.Utilities
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using Point = System.Windows.Point;
internal static class WPFExtensions
{
internal static void HandleInvoke(this DispatcherObject instance, Action action)
{
if (instance!.CheckAccess())
{
action();
}
else
{
instance.Dispatcher.Invoke(action);
}
}
internal static Window GetParentWindow(this ListView listView)
{
var parent = VisualTreeHelper.GetParent(listView);
@ -92,7 +103,7 @@ namespace SystemTrayMenu.Utilities
return (ImageSource)new IconToImageSourceConverter().Convert(
icon,
typeof(ImageSource),
null,
null!,
CultureInfo.InvariantCulture);
}
}