add badge with window switch on the top right

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-28 18:04:34 +02:00
parent 7430b33b8e
commit 0290d8f5db
17 changed files with 160 additions and 96 deletions
+32 -10
View File
@@ -18,7 +18,7 @@ public partial class MainSuite
private readonly IConfigUpdater _configUpdater;
private readonly IEnumerable<IAzaionModule> _modules;
private readonly IServiceProvider _sp;
private readonly List<Window> _openedWindows = new();
private readonly Dictionary<WindowEnum, Window> _openedWindows = new();
public MainSuite(IOptions<AppConfig> appConfig, IConfigUpdater configUpdater, IEnumerable<IAzaionModule> modules, IServiceProvider sp )
{
@@ -33,7 +33,7 @@ public partial class MainSuite
SizeChanged += async (_, _) => await SaveUserSettings();
LocationChanged += async (_, _) => await SaveUserSettings();
StateChanged += async (_, _) => await SaveUserSettings();
Left = SystemParameters.WorkArea.Width - Width - 150;
Left = SystemParameters.WorkArea.Width - Width - 250;
}
private void OnLoaded(object sender, RoutedEventArgs e)
@@ -71,15 +71,35 @@ public partial class MainSuite
Cursor = Cursors.Hand,
Tag = azaionModule
};
lvItem.MouseUp += (sender, _) =>
{
var module = ((sender as ListViewItem)!.Tag as IAzaionModule)!;
var window = (_sp.GetRequiredService(module.MainWindowType) as Window)!;
_openedWindows.Add(window);
window.Show();
};
lvItem.MouseUp += (lv, _) => OpenWindow((lv as ListViewItem)!);
ListView.Items.Add(lvItem);
}
//by default show first
ListView.SelectedIndex = 0;
OpenWindow((ListView.Items[0] as ListViewItem)!);
}
private void OpenWindow(ListViewItem sender)
{
var module = (sender.Tag as IAzaionModule)!;
var window = (_sp.GetRequiredService(module.MainWindowType) as Window)!;
if (_openedWindows.ContainsKey(module.WindowEnum))
window.Activate();
else
{
_openedWindows[module.WindowEnum] = window;
window.Closed += (_, _) =>
{
_openedWindows.Remove(module.WindowEnum);
if (!_openedWindows.Any())
Close();
};
window.Show();
window.Activate();
}
}
private async Task SaveUserSettings()
@@ -95,7 +115,9 @@ public partial class MainSuite
{
_configUpdater.Save(_appConfig);
foreach (var window in _openedWindows)
window.Close();
window.Value.Close();
Application.Current.Shutdown();
}
private void CloseBtn_OnClick(object sender, RoutedEventArgs e) => Close();
}