More UI updates

This commit is contained in:
2023-04-16 12:57:17 -04:00
parent 5c0c84a068
commit d6a2fd5a46
47 changed files with 3695 additions and 3768 deletions

View File

@@ -7,167 +7,166 @@ using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
namespace FeedCenter
namespace FeedCenter;
public partial class MainWindow
{
public partial class MainWindow
private void LoadWindowSettings()
{
private void LoadWindowSettings()
// Get the last window location
var windowLocation = Settings.Default.WindowLocation;
// Set the window into position
Left = windowLocation.X;
Top = windowLocation.Y;
// Get the last window size
var windowSize = Settings.Default.WindowSize;
// Set the window into the previous size if it is valid
if (!windowSize.Width.Equals(0) && !windowSize.Height.Equals(0))
{
// Get the last window location
var windowLocation = Settings.Default.WindowLocation;
// Set the window into position
Left = windowLocation.X;
Top = windowLocation.Y;
// Get the last window size
var windowSize = Settings.Default.WindowSize;
// Set the window into the previous size if it is valid
if (!windowSize.Width.Equals(0) && !windowSize.Height.Equals(0))
{
Width = windowSize.Width;
Height = windowSize.Height;
}
// Set the location of the navigation tray
switch (Settings.Default.ToolbarLocation)
{
case Dock.Top:
NameBasedGrid.NameBasedGrid.SetRow(NavigationToolbarTray, "TopToolbarRow");
break;
case Dock.Bottom:
NameBasedGrid.NameBasedGrid.SetRow(NavigationToolbarTray, "BottomToolbarRow");
break;
}
// Load the lock state
HandleWindowLockState();
Width = windowSize.Width;
Height = windowSize.Height;
}
private void SaveWindowSettings()
// Set the location of the navigation tray
switch (Settings.Default.ToolbarLocation)
{
// Set the last window location
Settings.Default.WindowLocation = new Point(Left, Top);
// Set the last window size
Settings.Default.WindowSize = new Size(Width, Height);
// Save the dock on the navigation tray
Settings.Default.ToolbarLocation = NameBasedGrid.NameBasedGrid.GetRow(NavigationToolbarTray) == "TopToolbarRow" ? Dock.Top : Dock.Bottom;
// Save settings
Settings.Default.Save();
case Dock.Top:
NameBasedGrid.NameBasedGrid.SetRow(NavigationToolbarTray, "TopToolbarRow");
break;
case Dock.Bottom:
NameBasedGrid.NameBasedGrid.SetRow(NavigationToolbarTray, "BottomToolbarRow");
break;
}
private void HandleWindowLockState()
// Load the lock state
HandleWindowLockState();
}
private void SaveWindowSettings()
{
// Set the last window location
Settings.Default.WindowLocation = new Point(Left, Top);
// Set the last window size
Settings.Default.WindowSize = new Size(Width, Height);
// Save the dock on the navigation tray
Settings.Default.ToolbarLocation = NameBasedGrid.NameBasedGrid.GetRow(NavigationToolbarTray) == "TopToolbarRow" ? Dock.Top : Dock.Bottom;
// Save settings
Settings.Default.Save();
}
private void HandleWindowLockState()
{
// Set the resize mode for the window
ResizeMode = Settings.Default.WindowLocked ? ResizeMode.NoResize : ResizeMode.CanResize;
// Show or hide the border
WindowBorder.BorderBrush = Settings.Default.WindowLocked ? SystemColors.ActiveBorderBrush : Brushes.Transparent;
// Update the borders
UpdateBorder();
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
// Ditch the worker
if (_feedReadWorker != null)
{
// Set the resize mode for the window
ResizeMode = Settings.Default.WindowLocked ? ResizeMode.NoResize : ResizeMode.CanResize;
// Show or hide the border
WindowBorder.BorderBrush = Settings.Default.WindowLocked ? SystemColors.ActiveBorderBrush : Brushes.Transparent;
// Update the borders
UpdateBorder();
_feedReadWorker.CancelAsync();
_feedReadWorker.Dispose();
}
protected override void OnClosing(CancelEventArgs e)
// Get rid of the timer
TerminateTimer();
// Save current window settings
SaveWindowSettings();
// Save settings
_database.SaveChanges(Settings.Default.Save);
// Get rid of the notification icon
NotificationIcon.Dispose();
}
private readonly DebounceDispatcher _updateWindowSettingsDispatcher = new(500);
private void HandleWindowSizeChanged(object sender, SizeChangedEventArgs e)
{
_updateWindowSettingsDispatcher.Debounce(() => Dispatcher.Invoke(UpdateWindowSettings));
}
private void HandleWindowLocationChanged(object sender, EventArgs e)
{
_updateWindowSettingsDispatcher.Debounce(() => Dispatcher.Invoke(UpdateWindowSettings));
}
private void UpdateBorder()
{
var windowInteropHelper = new WindowInteropHelper(this);
var screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
var rectangle = new System.Drawing.Rectangle
{
base.OnClosing(e);
X = (int) Left,
Y = (int) Top,
Width = (int) Width,
Height = (int) Height
};
// Ditch the worker
if (_feedReadWorker != null)
{
_feedReadWorker.CancelAsync();
_feedReadWorker.Dispose();
}
var borderThickness = new Thickness();
// Get rid of the timer
TerminateTimer();
if (rectangle.Right != screen.WorkingArea.Right)
borderThickness.Right = 1;
// Save current window settings
SaveWindowSettings();
if (rectangle.Left != screen.WorkingArea.Left)
borderThickness.Left = 1;
// Save settings
_database.SaveChanges(Settings.Default.Save);
if (rectangle.Top != screen.WorkingArea.Top)
borderThickness.Top = 1;
// Get rid of the notification icon
NotificationIcon.Dispose();
}
if (rectangle.Bottom != screen.WorkingArea.Bottom)
borderThickness.Bottom = 1;
private readonly DebounceDispatcher _updateWindowSettingsDispatcher = new(500);
WindowBorder.BorderThickness = borderThickness;
}
private void HandleWindowSizeChanged(object sender, SizeChangedEventArgs e)
{
_updateWindowSettingsDispatcher.Debounce(() => Dispatcher.Invoke(UpdateWindowSettings));
}
private void UpdateWindowSettings()
{
// Save current window settings
SaveWindowSettings();
private void HandleWindowLocationChanged(object sender, EventArgs e)
{
_updateWindowSettingsDispatcher.Debounce(() => Dispatcher.Invoke(UpdateWindowSettings));
}
// Update the border
UpdateBorder();
}
private void UpdateBorder()
{
var windowInteropHelper = new WindowInteropHelper(this);
private bool _activated;
var screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
var rectangle = new System.Drawing.Rectangle
{
X = (int) Left,
Y = (int) Top,
Width = (int) Width,
Height = (int) Height
};
if (_activated)
return;
var borderThickness = new Thickness();
_activated = true;
if (rectangle.Right != screen.WorkingArea.Right)
borderThickness.Right = 1;
// Load the lock state
HandleWindowLockState();
if (rectangle.Left != screen.WorkingArea.Left)
borderThickness.Left = 1;
// Watch for size and location changes
SizeChanged += HandleWindowSizeChanged;
LocationChanged += HandleWindowLocationChanged;
if (rectangle.Top != screen.WorkingArea.Top)
borderThickness.Top = 1;
if (rectangle.Bottom != screen.WorkingArea.Bottom)
borderThickness.Bottom = 1;
WindowBorder.BorderThickness = borderThickness;
}
private void UpdateWindowSettings()
{
// Save current window settings
SaveWindowSettings();
// Update the border
UpdateBorder();
}
private bool _activated;
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
if (_activated)
return;
_activated = true;
// Load the lock state
HandleWindowLockState();
// Watch for size and location changes
SizeChanged += HandleWindowSizeChanged;
LocationChanged += HandleWindowLocationChanged;
// Watch for setting changes
Settings.Default.PropertyChanged += HandlePropertyChanged;
}
// Watch for setting changes
Settings.Default.PropertyChanged += HandlePropertyChanged;
}
}