mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 20:46:30 +00:00
add badge with window switch on the top right
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user