diff --git a/Artemis/Artemis/Dialogs/MarkdownDialog.xaml b/Artemis/Artemis/Dialogs/MarkdownDialog.xaml index 8a9587fe5..1147a616a 100644 --- a/Artemis/Artemis/Dialogs/MarkdownDialog.xaml +++ b/Artemis/Artemis/Dialogs/MarkdownDialog.xaml @@ -47,7 +47,7 @@ MinWidth="80" Margin="0 0 5 0" Content="Alrighty, let's go!" - Style="{DynamicResource AccentedDialogSquareButton}" /> + Style="{DynamicResource AccentedDialogSquareButton}" Click="PART_AffirmativeButton_Click" /> \ No newline at end of file diff --git a/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs b/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs index 8c31b6ec9..3d6b1d7e6 100644 --- a/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs +++ b/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs @@ -1,28 +1,45 @@ -using System.Windows; +using System.Threading.Tasks; +using System.Windows; using System.Windows.Input; +using MahApps.Metro.Controls; +using MahApps.Metro.Controls.Dialogs; namespace Artemis.Dialogs { /// /// Interaction logic for MarkdownDialog.xaml /// - public partial class MarkdownDialog + public partial class MarkdownDialog : CustomDialog { + public MetroWindow ParentWindow { get; set; } + public static readonly DependencyProperty MarkdownProperty = DependencyProperty.Register("Markdown", typeof(string), typeof(MarkdownDialog), new PropertyMetadata(default(string))); - public MarkdownDialog() + + + public MarkdownDialog(MetroWindow parentWindow) { + ParentWindow = parentWindow; InitializeComponent(); + Tcs = new TaskCompletionSource(); + CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, (sender, e) => System.Diagnostics.Process.Start((string) e.Parameter))); } + public TaskCompletionSource Tcs { get; set; } + public string Markdown { get { return (string) GetValue(MarkdownProperty); } set { SetValue(MarkdownProperty, value); } } + + private void PART_AffirmativeButton_Click(object sender, RoutedEventArgs e) + { + ParentWindow.HideMetroDialogAsync(this); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs index 02bb82ca5..400bfa441 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs @@ -13,6 +13,7 @@ namespace Artemis.Modules.Effects.WindowsProfile Cpu = new CpuDataModel(); Performance = new PerformanceDataModel(); CurrentTime = new CurrentTime(); + Keyboard = new KbDataModel(); } public CpuDataModel Cpu { get; set; } @@ -20,6 +21,7 @@ namespace Artemis.Modules.Effects.WindowsProfile public Spotify Spotify { get; set; } public GooglePlayMusic GooglePlayMusic { get; set; } public CurrentTime CurrentTime { get; set; } + public KbDataModel Keyboard { get; set; } } [MoonSharpUserData] @@ -94,10 +96,18 @@ namespace Artemis.Modules.Effects.WindowsProfile public bool disliked { get; set; } } + [MoonSharpUserData] public class Time { public int current { get; set; } public int total { get; set; } } + [MoonSharpUserData] + public class KbDataModel + { + public bool NumLock { get; set; } + public bool CapsLock { get; set; } + public bool ScrollLock { get; set; } + } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs index c428ea084..724535874 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Artemis.DAL; @@ -50,6 +51,7 @@ namespace Artemis.Modules.Effects.WindowsProfile UpdateCpu(dataModel); UpdateMusicPlayers(dataModel); UpdateDay(dataModel); + UpdateKeyStates(dataModel); } #region Current Time @@ -64,7 +66,7 @@ namespace Artemis.Modules.Effects.WindowsProfile } #endregion - + #region CPU private void SetupCpu() @@ -233,5 +235,20 @@ namespace Artemis.Modules.Effects.WindowsProfile } #endregion + + #region System + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, + CallingConvention = CallingConvention.Winapi)] + public static extern short GetKeyState(int keyCode); + + private void UpdateKeyStates(WindowsProfileDataModel dataModel) + { + dataModel.Keyboard.NumLock = ((ushort)GetKeyState(0x90) & 0xffff) != 0; + dataModel.Keyboard.CapsLock = ((ushort)GetKeyState(0x14) & 0xffff) != 0; + dataModel.Keyboard.ScrollLock = ((ushort)GetKeyState(0x91) & 0xffff) != 0; + } + + #endregion } } \ No newline at end of file diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs index c5d110a63..dfbd5b140 100644 --- a/Artemis/Artemis/Properties/AssemblyInfo.cs +++ b/Artemis/Artemis/Properties/AssemblyInfo.cs @@ -53,8 +53,8 @@ using System.Windows; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.0.2")] +[assembly: AssemblyFileVersion("1.5.0.2")] [assembly: InternalsVisibleTo("Artemis.Tests")] [assembly: InternalsVisibleTo("Artemis.Explorables")] diff --git a/Artemis/Artemis/Services/MetroDialogService.cs b/Artemis/Artemis/Services/MetroDialogService.cs index dc52e96dd..2591e7a0a 100644 --- a/Artemis/Artemis/Services/MetroDialogService.cs +++ b/Artemis/Artemis/Services/MetroDialogService.cs @@ -24,7 +24,6 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; using Artemis.Dialogs; -using Artemis.Styles; using Caliburn.Micro; using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; @@ -57,28 +56,30 @@ namespace Artemis.Services public void ShowMarkdownDialog(string title, string markdown) { - if (GetActiveWindow() == null) + var window = GetActiveWindow(); + if (window == null) return; - var dialog = new MarkdownDialog + var dialog = new MarkdownDialog(window) { Markdown = markdown, Title = title }; - Execute.OnUIThread(() => GetActiveWindow().ShowMetroDialogAsync(dialog)); + window.Dispatcher.Invoke(() => window.ShowMetroDialogAsync(dialog)); } public override async Task ShowQuestionMessageBox(string title, string message) { - if (GetActiveWindow() == null) + var window = GetActiveWindow(); + if (window == null) return null; var metroDialogSettings = new MetroDialogSettings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"}; - var result = - await - GetActiveWindow() - .ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, metroDialogSettings); + var result = await window.Dispatcher.Invoke(() => + window.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, + metroDialogSettings)); + switch (result) { case MessageDialogResult.Negative: @@ -92,10 +93,8 @@ namespace Artemis.Services public override Task ShowInputDialog(string title, string message, MetroDialogSettings settings = null) { - if (GetActiveWindow() == null) - return null; - - return GetActiveWindow().ShowInputAsync(title, message, settings); + var window = GetActiveWindow(); + return window?.Dispatcher.Invoke(() => window.ShowInputAsync(title, message, settings)); } public override bool ShowOpenDialog(out string path, string defaultExt, string filter, string initialDir = null) @@ -132,15 +131,14 @@ namespace Artemis.Services path = lPath; - return res.Value; + return res != null && res.Value; } public Task ShowProgressDialog(string title, string message, bool isCancelable = false, MetroDialogSettings settings = null) { - var activeWindow = GetActiveWindow(); - return activeWindow?.Dispatcher.Invoke( - () => activeWindow.ShowProgressAsync(title, message, isCancelable, settings)); + var window = GetActiveWindow(); + return window?.Dispatcher.Invoke(() => window.ShowProgressAsync(title, message, isCancelable, settings)); } } } \ No newline at end of file