mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
UI - Implemented tray icon
UI - Moved dialog service to the shared UI project UI - Implemented autorun
This commit is contained in:
1 parent
b3f6aef101
commit
5710acb321
34 files changed
+344
-57
No files matched your search
@@ -2,7 +2,8 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:local="clr-namespace:Artemis.UI">
|
||||
xmlns:local="clr-namespace:Artemis.UI"
|
||||
ShutdownMode="OnExplicitShutdown">
|
||||
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<ProjectReference Include="..\Artemis.UI.Shared\Artemis.UI.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\logo-512.ico" />
|
||||
<Resource Include="Resources\logo-512.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -112,8 +113,10 @@
|
||||
<PackageReference Include="Castle.Core" Version="4.4.0" />
|
||||
<PackageReference Include="FluentValidation" Version="8.6.1" />
|
||||
<PackageReference Include="gong-wpf-dragdrop" Version="2.2.0" />
|
||||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf.NetCore" Version="1.0.10" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.7.9" />
|
||||
<PackageReference Include="MaterialDesignExtensions" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
||||
<PackageReference Include="Ninject" Version="3.3.4" />
|
||||
<PackageReference Include="Ninject.Extensions.Conventions" Version="3.3.0" />
|
||||
@@ -276,6 +279,9 @@
|
||||
<Compile Remove="obj\x64\Debug\Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKSizePropertyInputView.g.cs" />
|
||||
<Compile Remove="obj\x64\Debug\Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKSizePropertyInputView.g.i.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Resources\logo-512.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
@@ -14,9 +16,10 @@ using Stylet;
|
||||
|
||||
namespace Artemis.UI
|
||||
{
|
||||
public class Bootstrapper : NinjectBootstrapper<RootViewModel>
|
||||
public class Bootstrapper : NinjectBootstrapper<TrayViewModel>
|
||||
{
|
||||
private ICoreService _core;
|
||||
public static List<string> StartupArguments { get; private set; }
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
@@ -28,9 +31,10 @@ namespace Artemis.UI
|
||||
|
||||
protected override void Launch()
|
||||
{
|
||||
var windowManager = (IWindowManager) GetInstance(typeof(IWindowManager));
|
||||
var splashViewModel = new SplashViewModel(Kernel);
|
||||
windowManager.ShowWindow(splashViewModel);
|
||||
StartupArguments = Args.ToList();
|
||||
|
||||
var windowManager = Kernel.Get<IWindowManager>();
|
||||
windowManager.ShowWindow(RootViewModel);
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
@@ -38,10 +42,6 @@ namespace Artemis.UI
|
||||
{
|
||||
// Start the Artemis core
|
||||
_core = Kernel.Get<ICoreService>();
|
||||
// When the core is done, hide the splash and show the main window
|
||||
_core.Initialized += (sender, args) => ShowMainWindow(windowManager, splashViewModel);
|
||||
// While the core is instantiated, start listening for events on the splash
|
||||
splashViewModel.ListenToEvents();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -4,8 +4,8 @@ using Artemis.UI.Screens;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Dialog;
|
||||
using Artemis.UI.Stylet;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using FluentValidation;
|
||||
using Ninject.Extensions.Conventions;
|
||||
using Ninject.Modules;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Artemis.UI": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-autorun"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Dialogs.ConfirmDialogView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:dialogs="clr-namespace:Artemis.UI.Screens.Dialogs"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="163.274" d:DesignWidth="254.425"
|
||||
d:DataContext="{d:DesignInstance dialogs:ConfirmDialogViewModel}">
|
||||
<StackPanel Margin="16">
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" Text="{Binding Header}" TextWrapping="Wrap" />
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Margin="0 20 0 20" Text="{Binding Text}" TextWrapping="Wrap" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0"
|
||||
Command="{s:Action Cancel}" Content="{Binding CancelText}" />
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 0 0"
|
||||
Command="{s:Action Confirm}" Content="{Binding ConfirmText}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -1,30 +0,0 @@
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
|
||||
namespace Artemis.UI.Screens.Dialogs
|
||||
{
|
||||
public class ConfirmDialogViewModel : DialogViewModelBase
|
||||
{
|
||||
public ConfirmDialogViewModel(string header, string text, string confirmText, string cancelText)
|
||||
{
|
||||
Header = header;
|
||||
Text = text;
|
||||
ConfirmText = confirmText;
|
||||
CancelText = cancelText;
|
||||
}
|
||||
|
||||
public string Header { get; }
|
||||
public string Text { get; }
|
||||
public string ConfirmText { get; }
|
||||
public string CancelText { get; }
|
||||
|
||||
public void Confirm()
|
||||
{
|
||||
Session.Close(true);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Session.Close(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using Artemis.UI.Shared.Services.Dialog;
|
||||
using FluentValidation;
|
||||
using Stylet;
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using Artemis.UI.Shared.Services.Dialog;
|
||||
using FluentValidation;
|
||||
using Stylet;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:screens="clr-namespace:Artemis.UI.Screens"
|
||||
xmlns:mde="clr-namespace:MaterialDesignExtensions.Controls;assembly=MaterialDesignExtensions"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
mc:Ignorable="d"
|
||||
FadeContentIfInactive="False"
|
||||
Icon="/Artemis.UI;component/Resources/logo-512.png"
|
||||
@@ -50,15 +51,18 @@
|
||||
</Style>
|
||||
</mde:MaterialWindow.Resources>
|
||||
<materialDesign:DialogHost Identifier="RootDialog">
|
||||
<materialDesign:DrawerHost IsLeftDrawerOpen="{Binding IsSidebarVisible}">
|
||||
<materialDesign:DrawerHost.LeftDrawerContent>
|
||||
<ContentControl s:View.Model="{Binding SidebarViewModel}" Width="220" ClipToBounds="False" />
|
||||
</materialDesign:DrawerHost.LeftDrawerContent>
|
||||
<DockPanel>
|
||||
<mde:AppBar Type="Dense" IsNavigationDrawerOpen="{Binding IsSidebarVisible, Mode=TwoWay}" Title="{Binding ActiveItem.DisplayName}" ShowNavigationDrawerButton="True"
|
||||
DockPanel.Dock="Top" />
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" Style="{StaticResource InitializingFade}" />
|
||||
</DockPanel>
|
||||
</materialDesign:DrawerHost>
|
||||
</materialDesign:DialogHost>
|
||||
<materialDesign:DrawerHost IsLeftDrawerOpen="{Binding IsSidebarVisible}">
|
||||
<materialDesign:DrawerHost.LeftDrawerContent>
|
||||
<ContentControl s:View.Model="{Binding SidebarViewModel}" Width="220" ClipToBounds="False" />
|
||||
</materialDesign:DrawerHost.LeftDrawerContent>
|
||||
<DockPanel>
|
||||
<mde:AppBar Type="Dense"
|
||||
IsNavigationDrawerOpen="{Binding IsSidebarVisible, Mode=TwoWay}"
|
||||
Title="{Binding ActiveItem.DisplayName}"
|
||||
ShowNavigationDrawerButton="True"
|
||||
DockPanel.Dock="Top" />
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" Style="{StaticResource InitializingFade}" />
|
||||
</DockPanel>
|
||||
</materialDesign:DrawerHost>
|
||||
</materialDesign:DialogHost>
|
||||
</mde:MaterialWindow>
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Sidebar;
|
||||
using Artemis.UI.Utilities;
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Start up with Windows</TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
|
||||
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Default ToggleButton Style" />
|
||||
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding StartWithWindows}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
|
||||
@@ -57,7 +57,7 @@
|
||||
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Start up with Windows minimized</TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
|
||||
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Default ToggleButton Style" />
|
||||
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding StartMinimized}" IsEnabled="{Binding StartWithWindows}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services;
|
||||
@@ -12,8 +13,10 @@ using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Settings.Debug;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Devices;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Plugins;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
using Ninject;
|
||||
using Serilog.Events;
|
||||
using Stylet;
|
||||
@@ -23,6 +26,7 @@ namespace Artemis.UI.Screens.Settings
|
||||
public class SettingsViewModel : MainScreenViewModel
|
||||
{
|
||||
private readonly IDeviceSettingsVmFactory _deviceSettingsVmFactory;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
@@ -32,6 +36,7 @@ namespace Artemis.UI.Screens.Settings
|
||||
public SettingsViewModel(IKernel kernel,
|
||||
ISurfaceService surfaceService,
|
||||
IPluginService pluginService,
|
||||
IDialogService dialogService,
|
||||
IWindowManager windowManager,
|
||||
ISettingsService settingsService,
|
||||
IDeviceSettingsVmFactory deviceSettingsVmFactory)
|
||||
@@ -43,6 +48,7 @@ namespace Artemis.UI.Screens.Settings
|
||||
_kernel = kernel;
|
||||
_surfaceService = surfaceService;
|
||||
_pluginService = pluginService;
|
||||
_dialogService = dialogService;
|
||||
_windowManager = windowManager;
|
||||
_settingsService = settingsService;
|
||||
_deviceSettingsVmFactory = deviceSettingsVmFactory;
|
||||
@@ -65,12 +71,33 @@ namespace Artemis.UI.Screens.Settings
|
||||
|
||||
public List<Tuple<string, int>> TargetFrameRates { get; set; }
|
||||
public List<Tuple<string, double>> RenderScales { get; set; }
|
||||
public IEnumerable<ValueDescription> LogLevels { get; private set; }
|
||||
public IEnumerable<ValueDescription> LogLevels { get; }
|
||||
|
||||
public List<int> SampleSizes { get; set; }
|
||||
public BindableCollection<DeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
|
||||
public BindableCollection<PluginSettingsViewModel> Plugins { get; set; }
|
||||
|
||||
public bool StartWithWindows
|
||||
{
|
||||
get => _settingsService.GetSetting("UI.AutoRun", false).Value;
|
||||
set
|
||||
{
|
||||
_settingsService.GetSetting("UI.AutoRun", false).Value = value;
|
||||
_settingsService.GetSetting("UI.AutoRun", false).Save();
|
||||
Task.Run(ApplyAutorun);
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartMinimized
|
||||
{
|
||||
get => !_settingsService.GetSetting("UI.ShowOnStartup", true).Value;
|
||||
set
|
||||
{
|
||||
_settingsService.GetSetting("UI.ShowOnStartup", true).Value = !value;
|
||||
_settingsService.GetSetting("UI.ShowOnStartup", true).Save();
|
||||
}
|
||||
}
|
||||
|
||||
public Tuple<string, double> SelectedRenderScale
|
||||
{
|
||||
get => RenderScales.FirstOrDefault(s => Math.Abs(s.Item2 - RenderScale) < 0.01);
|
||||
@@ -138,8 +165,10 @@ namespace Artemis.UI.Screens.Settings
|
||||
Process.Start(Constants.DataFolder);
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
Task.Run(ApplyAutorun);
|
||||
|
||||
DeviceSettingsViewModels.Clear();
|
||||
foreach (var device in _surfaceService.ActiveSurface.Devices)
|
||||
DeviceSettingsViewModels.Add(_deviceSettingsVmFactory.Create(device));
|
||||
@@ -149,7 +178,34 @@ namespace Artemis.UI.Screens.Settings
|
||||
foreach (var plugin in _pluginService.GetPluginsOfType<Plugin>())
|
||||
Plugins.Add(new PluginSettingsViewModel(plugin));
|
||||
|
||||
base.OnActivate();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
DeviceSettingsViewModels.Clear();
|
||||
Plugins.Clear();
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private async Task ApplyAutorun()
|
||||
{
|
||||
try
|
||||
{
|
||||
var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||
if (key == null)
|
||||
key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
|
||||
|
||||
if (StartWithWindows)
|
||||
key.SetValue("Artemis", $"\"{Process.GetCurrentProcess().MainModule.FileName}\" -autorun");
|
||||
else
|
||||
key.DeleteValue("Artemis", false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _dialogService.ShowExceptionDialog("An exception occured while trying to apply the auto run setting", e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,26 @@ namespace Artemis.UI.Screens.Splash
|
||||
{
|
||||
public class SplashViewModel : Screen
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IPluginService _pluginService;
|
||||
|
||||
public SplashViewModel(IKernel kernel)
|
||||
public SplashViewModel(ICoreService coreService, IPluginService pluginService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_coreService = coreService;
|
||||
_pluginService = pluginService;
|
||||
Status = "Initializing Core";
|
||||
|
||||
ListenToEvents();
|
||||
}
|
||||
|
||||
public string Status { get; set; }
|
||||
|
||||
public void ListenToEvents()
|
||||
{
|
||||
var pluginService = _kernel.Get<IPluginService>();
|
||||
pluginService.CopyingBuildInPlugins += (sender, args) => Status = "Updating built-in plugins";
|
||||
pluginService.PluginLoading += (sender, args) => Status = "Loading plugin: " + args.PluginInfo.Name;
|
||||
pluginService.PluginLoaded += (sender, args) => Status = "Initializing UI";
|
||||
_coreService.Initialized += (sender, args) => Execute.OnUIThread(() => RequestClose());
|
||||
_pluginService.CopyingBuildInPlugins += (sender, args) => Status = "Updating built-in plugins";
|
||||
_pluginService.PluginLoading += (sender, args) => Status = "Loading plugin: " + args.PluginInfo.Name;
|
||||
_pluginService.PluginLoaded += (sender, args) => Status = "Initializing UI";
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called from view
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using Artemis.UI.Shared.Services.Dialog;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.SurfaceEditor.Visualization;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using Artemis.UI.Shared.Services.Dialog;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
|
||||
@@ -14,7 +14,7 @@ using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Screens.SurfaceEditor.Dialogs;
|
||||
using Artemis.UI.Screens.SurfaceEditor.Visualization;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<Window x:Class="Artemis.UI.Screens.TrayView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
Title="Artemis"
|
||||
Height="1"
|
||||
Width="1"
|
||||
Visibility="Hidden">
|
||||
<tb:TaskbarIcon x:Name="TrayIcon"
|
||||
IconSource="/Resources/logo-512.ico"
|
||||
MenuActivation="LeftOrRightClick"
|
||||
PopupActivation="DoubleClick"
|
||||
ToolTipText="Artemis"
|
||||
DoubleClickCommand="{s:Action TrayBringToForeground}">
|
||||
<tb:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Bring to foreground" Command="{s:Action TrayBringToForeground}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ArrangeBringToFront" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Exit" Command="{s:Action TrayExit}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Close" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</tb:TaskbarIcon.ContextMenu>
|
||||
</tb:TaskbarIcon>
|
||||
</Window>
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Windows;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.Screens.Splash;
|
||||
using Ninject;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens
|
||||
{
|
||||
public class TrayViewModel : Screen
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IWindowManager _windowManager;
|
||||
|
||||
public TrayViewModel(IKernel kernel, IWindowManager windowManager, ICoreService coreService, ISettingsService settingsService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_windowManager = windowManager;
|
||||
_coreService = coreService;
|
||||
CanShowRootViewModel = true;
|
||||
|
||||
var autoRunning = Bootstrapper.StartupArguments.Contains("-autorun");
|
||||
var showOnAutoRun = settingsService.GetSetting("UI.ShowOnStartup", true).Value;
|
||||
if (!autoRunning || showOnAutoRun)
|
||||
{
|
||||
ShowSplashScreen();
|
||||
_coreService.Initialized += (sender, args) => TrayBringToForeground();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanShowRootViewModel { get; set; }
|
||||
|
||||
public void TrayBringToForeground()
|
||||
{
|
||||
if (!CanShowRootViewModel)
|
||||
return;
|
||||
CanShowRootViewModel = false;
|
||||
|
||||
Execute.OnUIThread(() =>
|
||||
{
|
||||
var rootViewModel = _kernel.Get<RootViewModel>();
|
||||
rootViewModel.Closed += RootViewModelOnClosed;
|
||||
_windowManager.ShowWindow(rootViewModel);
|
||||
});
|
||||
}
|
||||
|
||||
public void TrayExit()
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
private void ShowSplashScreen()
|
||||
{
|
||||
Execute.OnUIThread(() =>
|
||||
{
|
||||
var splashViewModel = _kernel.Get<SplashViewModel>();
|
||||
_windowManager.ShowWindow(splashViewModel);
|
||||
});
|
||||
}
|
||||
|
||||
private void RootViewModelOnClosed(object sender, CloseEventArgs e)
|
||||
{
|
||||
CanShowRootViewModel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.Dialogs;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Services.Dialog
|
||||
{
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IViewManager _viewManager;
|
||||
|
||||
public DialogService(IKernel kernel, IViewManager viewManager)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_viewManager = viewManager;
|
||||
}
|
||||
|
||||
public async Task<bool> ShowConfirmDialog(string header, string text, string confirmText = "Confirm", string cancelText = "Cancel")
|
||||
{
|
||||
var arguments = new IParameter[]
|
||||
{
|
||||
new ConstructorArgument("header", header),
|
||||
new ConstructorArgument("text", text),
|
||||
new ConstructorArgument("confirmText", confirmText.ToUpper()),
|
||||
new ConstructorArgument("cancelText", cancelText.ToUpper())
|
||||
};
|
||||
var result = await ShowDialog<ConfirmDialogViewModel>(arguments);
|
||||
return (bool) result;
|
||||
}
|
||||
|
||||
public async Task<bool> ShowConfirmDialogAt(string identifier, string header, string text, string confirmText = "Confirm", string cancelText = "Cancel")
|
||||
{
|
||||
var arguments = new IParameter[]
|
||||
{
|
||||
new ConstructorArgument("header", header),
|
||||
new ConstructorArgument("text", text),
|
||||
new ConstructorArgument("confirmText", confirmText.ToUpper()),
|
||||
new ConstructorArgument("cancelText", cancelText.ToUpper())
|
||||
};
|
||||
var result = await ShowDialogAt<ConfirmDialogViewModel>(identifier, arguments);
|
||||
return (bool) result;
|
||||
}
|
||||
|
||||
public async Task<object> ShowDialog<T>() where T : DialogViewModelBase
|
||||
{
|
||||
return await ShowDialog("RootDialog", _kernel.Get<T>());
|
||||
}
|
||||
|
||||
public Task<object> ShowDialog<T>(Dictionary<string, object> parameters) where T : DialogViewModelBase
|
||||
{
|
||||
if (parameters == null)
|
||||
throw new ArgumentNullException(nameof(parameters));
|
||||
|
||||
var paramsArray = parameters.Select(kv => new ConstructorArgument(kv.Key, kv.Value)).Cast<IParameter>().ToArray();
|
||||
return ShowDialog<T>(paramsArray);
|
||||
}
|
||||
|
||||
public async Task<object> ShowDialog<T>(IParameter[] parameters) where T : DialogViewModelBase
|
||||
{
|
||||
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
|
||||
return await ShowDialog("RootDialog", _kernel.Get<T>(parameters));
|
||||
}
|
||||
|
||||
public async Task<object> ShowDialogAt<T>(string identifier) where T : DialogViewModelBase
|
||||
{
|
||||
return await ShowDialog(identifier, _kernel.Get<T>());
|
||||
}
|
||||
|
||||
public async Task<object> ShowDialogAt<T>(string identifier, Dictionary<string, object> parameters) where T : DialogViewModelBase
|
||||
{
|
||||
if (parameters == null)
|
||||
throw new ArgumentNullException(nameof(parameters));
|
||||
|
||||
var paramsArray = parameters.Select(kv => new ConstructorArgument(kv.Key, kv.Value)).Cast<IParameter>().ToArray();
|
||||
return await ShowDialogAt<T>(identifier, paramsArray);
|
||||
}
|
||||
|
||||
public async Task<object> ShowDialogAt<T>(string identifier, IParameter[] parameters) where T : DialogViewModelBase
|
||||
{
|
||||
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
|
||||
return await ShowDialog(identifier, _kernel.Get<T>(parameters));
|
||||
}
|
||||
|
||||
private async Task<object> ShowDialog(string identifier, DialogViewModelBase viewModel)
|
||||
{
|
||||
var view = _viewManager.CreateViewForModel(viewModel);
|
||||
_viewManager.BindViewToModel(view, viewModel);
|
||||
|
||||
if (identifier == null)
|
||||
return await DialogHost.Show(view, viewModel.OnDialogOpened, viewModel.OnDialogClosed);
|
||||
return await DialogHost.Show(view, identifier, viewModel.OnDialogOpened, viewModel.OnDialogClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Artemis.UI.ViewModels.Utilities;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Dialogs
|
||||
{
|
||||
public abstract class DialogViewModelBase : ValidatingModelBase
|
||||
{
|
||||
protected DialogViewModelBase(IModelValidator validator) : base(validator)
|
||||
{
|
||||
}
|
||||
|
||||
protected DialogViewModelBase()
|
||||
{
|
||||
}
|
||||
|
||||
public DialogViewModelHost DialogViewModelHost { get; set; }
|
||||
public DialogSession Session { get; private set; }
|
||||
|
||||
public void OnDialogOpened(object sender, DialogOpenedEventArgs e)
|
||||
{
|
||||
Session = e.Session;
|
||||
}
|
||||
|
||||
public virtual void OnDialogClosed(object sender, DialogClosingEventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Utilities
|
||||
{
|
||||
public class DialogViewModelHost : PropertyChangedBase
|
||||
{
|
||||
private readonly IViewManager _viewManager;
|
||||
|
||||
public DialogViewModelHost(IViewManager viewManager)
|
||||
{
|
||||
_viewManager = viewManager;
|
||||
}
|
||||
|
||||
public DialogViewModelBase ActiveDialogViewModel { get; set; }
|
||||
public bool IsOpen { get; set; }
|
||||
|
||||
public void OpenDialog(DialogViewModelBase viewModel, string dialogIdentifier)
|
||||
{
|
||||
var view = _viewManager.CreateViewForModel(viewModel);
|
||||
DialogHost.Show(view, dialogIdentifier, viewModel.OnDialogClosed);
|
||||
viewModel.DialogViewModelHost = this;
|
||||
|
||||
ActiveDialogViewModel = viewModel;
|
||||
IsOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject.Parameters;
|
||||
|
||||
namespace Artemis.UI.Services.Interfaces
|
||||
{
|
||||
public interface IDialogService : IArtemisUIService
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows a confirm dialog on the dialog host provided in <see cref="identifier" />.
|
||||
/// </summary>
|
||||
/// <param name="header">The title of the dialog</param>
|
||||
/// <param name="text">The body text of the dialog</param>
|
||||
/// <param name="confirmText">The text of the confirm button, defaults to "Confirm"</param>
|
||||
/// <param name="cancelText">The text of the cancel button, defaults to "Cancel"</param>
|
||||
/// <returns>A task that resolves to true if confirmed and false if cancelled</returns>
|
||||
Task<bool> ShowConfirmDialog(string header, string text, string confirmText = "Confirm", string cancelText = "Cancel");
|
||||
|
||||
/// <summary>
|
||||
/// Shows a confirm dialog on the dialog host provided in <see cref="identifier" />.
|
||||
/// </summary>
|
||||
/// <param name="identifier">
|
||||
/// The identifier of the <see cref="DialogHost" /> to use eg.
|
||||
/// <code><materialDesign:DialogHost Identifier="MyDialogHost"></code>
|
||||
/// </param>
|
||||
/// <param name="header">The title of the dialog</param>
|
||||
/// <param name="text">The body text of the dialog</param>
|
||||
/// <param name="confirmText">The text of the confirm button, defaults to "Confirm"</param>
|
||||
/// <param name="cancelText">The text of the cancel button, defaults to "Cancel"</param>
|
||||
/// <returns>A task that resolves to true if confirmed and false if cancelled</returns>
|
||||
Task<bool> ShowConfirmDialogAt(string identifier, string header, string text, string confirmText = "Confirm", string cancelText = "Cancel");
|
||||
|
||||
/// <summary>
|
||||
/// Shows a dialog by initializing a view model implementing <see cref="DialogViewModelBase" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the view model</typeparam>
|
||||
/// <returns>A task resolving to the result of the dialog's <see cref="DialogSession" /></returns>
|
||||
Task<object> ShowDialog<T>() where T : DialogViewModelBase;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a dialog by initializing a view model implementing <see cref="DialogViewModelBase" /> with arguments passed
|
||||
/// to the view models constructor
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the view model</typeparam>
|
||||
/// <param name="parameters">A dictionary of constructor arguments to pass to the view model</param>
|
||||
/// <returns>A task resolving to the result of the dialog's <see cref="DialogSession" /></returns>
|
||||
Task<object> ShowDialog<T>(Dictionary<string, object> parameters) where T : DialogViewModelBase;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a dialog by initializing a view model implementing <see cref="DialogViewModelBase" /> using an array of
|
||||
/// Ninject <see cref="IParameter" />, requires you to reference Ninject
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the view model</typeparam>
|
||||
/// <param name="parameters">An array of Ninject <see cref="IParameter" /> to pass to the view model during activation</param>
|
||||
/// <returns>A task resolving to the result of the dialog's <see cref="DialogSession" /></returns>
|
||||
Task<object> ShowDialog<T>(IParameter[] parameters) where T : DialogViewModelBase;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a dialog by initializing a view model implementing <see cref="DialogViewModelBase" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the view model</typeparam>
|
||||
/// <param name="identifier">
|
||||
/// The identifier of the <see cref="DialogHost" /> to use eg.
|
||||
/// <code><materialDesign:DialogHost Identifier="MyDialogHost"></code>
|
||||
/// </param>
|
||||
/// <returns>A task resolving to the result of the dialog's <see cref="DialogSession" /></returns>
|
||||
Task<object> ShowDialogAt<T>(string identifier) where T : DialogViewModelBase;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a dialog by initializing a view model implementing <see cref="DialogViewModelBase" /> with arguments passed
|
||||
/// to the view models constructor
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the view model</typeparam>
|
||||
/// <param name="identifier">
|
||||
/// The identifier of the <see cref="DialogHost" /> to use eg.
|
||||
/// <code><materialDesign:DialogHost Identifier="MyDialogHost"></code>
|
||||
/// </param>
|
||||
/// <param name="parameters">A dictionary of constructor arguments to pass to the view model</param>
|
||||
/// <returns>A task resolving to the result of the dialog's <see cref="DialogSession" /></returns>
|
||||
Task<object> ShowDialogAt<T>(string identifier, Dictionary<string, object> parameters) where T : DialogViewModelBase;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a dialog by initializing a view model implementing <see cref="DialogViewModelBase" /> using an array of
|
||||
/// Ninject <see cref="IParameter" />, requires you to reference Ninject
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the view model</typeparam>
|
||||
/// <param name="identifier">
|
||||
/// The identifier of the <see cref="DialogHost" /> to use eg.
|
||||
/// <code><materialDesign:DialogHost Identifier="MyDialogHost"></code>
|
||||
/// </param>
|
||||
/// <param name="parameters">An array of Ninject <see cref="IParameter" /> to pass to the view model during activation</param>
|
||||
/// <returns>A task resolving to the result of the dialog's <see cref="DialogSession" /></returns>
|
||||
Task<object> ShowDialogAt<T>(string identifier, IParameter[] parameters) where T : DialogViewModelBase;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user