diff --git a/.gitmodules b/.gitmodules index 6599cee..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "Library/Common.Wpf"] - path = Library/Common.Wpf - url = https://github.com/ckaczor/Common.Wpf.git diff --git a/FloatingStatusWindow.sln b/FloatingStatusWindow.sln index 781e0b9..14f3e6f 100644 --- a/FloatingStatusWindow.sln +++ b/FloatingStatusWindow.sln @@ -1,25 +1,18 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2036 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33530.505 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloatingStatusWindow", "Library\FloatingStatusWindow.csproj", "{F023A16C-2F13-4A87-A8B7-22C43C4A58A4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FloatingStatusWindow", "Library\FloatingStatusWindow.csproj", "{F023A16C-2F13-4A87-A8B7-22C43C4A58A4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWindow", "TestWindow\TestWindow.csproj", "{0C541788-8FFD-47B6-8E6B-653A884CFA55}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestWindow", "TestWindow\TestWindow.csproj", "{0C541788-8FFD-47B6-8E6B-653A884CFA55}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{C4E7C6BF-86B2-433B-B842-31B82811FAC9}" ProjectSection(SolutionItems) = preProject - .gitignore = .gitignore - appveyor.yml = appveyor.yml - Library\FloatingStatusWindow.nuspec = Library\FloatingStatusWindow.nuspec + azure-pipelines.yml = azure-pipelines.yml LICENSE.md = LICENSE.md README.md = README.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Wpf", "Library\Common.Wpf\Common.Wpf.csproj", "{0074C983-550E-4094-9E8C-F566FB669297}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Native", "Library\Common.Wpf\Common.Native\Common.Native.csproj", "{ED1C07A1-54F5-4796-8B06-2A0BB1960D84}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -46,30 +39,6 @@ Global {0C541788-8FFD-47B6-8E6B-653A884CFA55}.Release|Any CPU.Build.0 = Release|Any CPU {0C541788-8FFD-47B6-8E6B-653A884CFA55}.Release|x64.ActiveCfg = Release|Any CPU {0C541788-8FFD-47B6-8E6B-653A884CFA55}.Release|x86.ActiveCfg = Release|Any CPU - {0074C983-550E-4094-9E8C-F566FB669297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0074C983-550E-4094-9E8C-F566FB669297}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0074C983-550E-4094-9E8C-F566FB669297}.Debug|x64.ActiveCfg = Debug|x64 - {0074C983-550E-4094-9E8C-F566FB669297}.Debug|x64.Build.0 = Debug|x64 - {0074C983-550E-4094-9E8C-F566FB669297}.Debug|x86.ActiveCfg = Debug|x86 - {0074C983-550E-4094-9E8C-F566FB669297}.Debug|x86.Build.0 = Debug|x86 - {0074C983-550E-4094-9E8C-F566FB669297}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0074C983-550E-4094-9E8C-F566FB669297}.Release|Any CPU.Build.0 = Release|Any CPU - {0074C983-550E-4094-9E8C-F566FB669297}.Release|x64.ActiveCfg = Release|x64 - {0074C983-550E-4094-9E8C-F566FB669297}.Release|x64.Build.0 = Release|x64 - {0074C983-550E-4094-9E8C-F566FB669297}.Release|x86.ActiveCfg = Release|x86 - {0074C983-550E-4094-9E8C-F566FB669297}.Release|x86.Build.0 = Release|x86 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Debug|x64.ActiveCfg = Debug|x64 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Debug|x64.Build.0 = Debug|x64 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Debug|x86.ActiveCfg = Debug|x86 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Debug|x86.Build.0 = Debug|x86 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Release|Any CPU.Build.0 = Release|Any CPU - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Release|x64.ActiveCfg = Release|x64 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Release|x64.Build.0 = Release|x64 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Release|x86.ActiveCfg = Release|x86 - {ED1C07A1-54F5-4796-8B06-2A0BB1960D84}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Library/App.config b/Library/App.config deleted file mode 100644 index bc3672d..0000000 --- a/Library/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Library/AppearanceWindow.xaml b/Library/AppearanceWindow.xaml index fdfc405..f40917e 100644 --- a/Library/AppearanceWindow.xaml +++ b/Library/AppearanceWindow.xaml @@ -1,17 +1,27 @@  + Closing="HandleWindowClosing" + x:ClassModifier="internal" + windows:ControlBox.HasMaximizeButton="False" + windows:ControlBox.HasMinimizeButton="False" + windows:ControlBox.HasSystemMenu="False" + WindowStyle="ToolWindow"> @@ -26,15 +36,16 @@ - - - + \ No newline at end of file diff --git a/Library/MainWindow.xaml.cs b/Library/MainWindow.xaml.cs index 005f533..47840c8 100644 --- a/Library/MainWindow.xaml.cs +++ b/Library/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using Common.Wpf.Windows; +using ChrisKaczor.Wpf.Windows; using System; using System.Collections.Generic; using System.Windows; @@ -7,132 +7,125 @@ using System.Windows.Media; using System.Windows.Shell; using System.Windows.Threading; -namespace FloatingStatusWindowLibrary +namespace ChrisKaczor.Wpf.FloatingStatusWindow; + +internal partial class MainWindow { - internal partial class MainWindow + public event EventHandler LockStateChanged = delegate { }; + + private const int WindowCaptionHeight = 24; + + private readonly WindowChrome _windowChrome; + private readonly Dispatcher _dispatcher; + + public WindowSettings WindowSettings { get; set; } + + private bool _locked; + + public bool Locked { - public event EventHandler LockStateChanged = delegate { }; - - private const int WindowCaptionHeight = 24; - - private readonly WindowChrome _windowChrome; - private readonly Dispatcher _dispatcher; - - private WindowSettings _windowSettings; - public WindowSettings WindowSettings + get => _locked; + set { - get { return _windowSettings; } - set { _windowSettings = value; } - } + _locked = value; - private bool _locked; - public bool Locked - { - get { return _locked; } - set - { - _locked = value; + _windowChrome.CaptionHeight = (_locked ? 0 : WindowCaptionHeight); - _windowChrome.CaptionHeight = (_locked ? 0 : WindowCaptionHeight); + HtmlLabel.Margin = new Thickness(0, (_locked ? 0 : WindowCaptionHeight), 0, 0); - HtmlLabel.Margin = new Thickness(0, (_locked ? 0 : WindowCaptionHeight), 0, 0); + // Show the header border if the window is unlocked + HeaderBorder.Visibility = (_locked ? Visibility.Collapsed : Visibility.Visible); - // Show the header border if the window is unlocked - HeaderBorder.Visibility = (_locked ? Visibility.Collapsed : Visibility.Visible); + // Show and enable the window border if the window is unlocked + BorderFull.BorderBrush = (_locked ? Brushes.Transparent : SystemColors.ActiveCaptionBrush); + BorderFull.IsEnabled = !_locked; - // Show and enable the window border if the window is unlocked - BorderFull.BorderBrush = (_locked ? Brushes.Transparent : SystemColors.ActiveCaptionBrush); - BorderFull.IsEnabled = !_locked; - - LockStateChanged(null, new EventArgs()); - } - } - - public MainWindow(IWindowSource windowSource) - { - InitializeComponent(); - - _dispatcher = Dispatcher.CurrentDispatcher; - - // Create and set the window chrome - _windowChrome = new WindowChrome { CaptionHeight = WindowCaptionHeight }; - WindowChrome.SetWindowChrome(this, _windowChrome); - - // Load the window settings - _windowSettings = WindowSettings.Load(windowSource.WindowSettings); - _windowSettings.Name = windowSource.Name; - _windowSettings.SetWindow(this); - - // Set the background of the border - HeaderBorder.Background = SystemColors.ActiveCaptionBrush; - - // Configure the header label - HeaderLabel.Foreground = SystemColors.InactiveCaptionTextBrush; - HeaderLabel.Content = _windowSettings.Name; - - // Get the thickness so we can size the visual border - var resizeThickness = _windowChrome.ResizeBorderThickness; - - // Set the color of the border - BorderFull.BorderBrush = SystemColors.ActiveCaptionBrush; - BorderFull.BorderThickness = new Thickness(resizeThickness.Left, 0, resizeThickness.Right, resizeThickness.Bottom); - - // Apply the stored settings - _windowSettings.Apply(); - } - - protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) - { - if (msg == WindowManager.SetLockMessage) - { - var lockState = (wParam == (IntPtr) 1); - - _dispatcher.InvokeAsync(() => - { - WindowSettings.Locked = lockState; - Locked = lockState; - }); - - return IntPtr.Zero; - } - - if (msg == WindowManager.CloseMessage) - { - _dispatcher.InvokeAsync(Close); - return IntPtr.Zero; - } - - return base.WndProc(hwnd, msg, wParam, lParam, ref handled); - } - - protected override void OnLocationChanged(EventArgs e) - { - base.OnLocationChanged(e); - - _windowSettings.Location = new Point(Left, Top); - } - - protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) - { - base.OnRenderSizeChanged(sizeInfo); - - _windowSettings.Size = new Size(Width, Height); - } - - protected override List OtherWindows - { - get - { - var windowHandle = new WindowInteropHelper(this).Handle; - - return WindowManager.GetWindowList(windowHandle); - } - } - - private void HandleChangeAppearanceClick(object sender, RoutedEventArgs e) - { - var appearanceWindow = new AppearanceWindow(WindowSettings); - appearanceWindow.ShowDialog(); + LockStateChanged(null, EventArgs.Empty); } } -} + + public MainWindow(IWindowSource windowSource) + { + InitializeComponent(); + + _dispatcher = Dispatcher.CurrentDispatcher; + + // Create and set the window chrome + _windowChrome = new WindowChrome { CaptionHeight = WindowCaptionHeight }; + WindowChrome.SetWindowChrome(this, _windowChrome); + + // Load the window settings + WindowSettings = WindowSettings.Load(windowSource.WindowSettings); + WindowSettings.Name = windowSource.Name; + WindowSettings.SetWindow(this); + + // Set the background of the border + HeaderBorder.Background = SystemColors.ActiveCaptionBrush; + + // Configure the header label + HeaderLabel.Foreground = SystemColors.InactiveCaptionTextBrush; + HeaderLabel.Content = WindowSettings.Name; + + // Get the thickness so we can size the visual border + var resizeThickness = _windowChrome.ResizeBorderThickness; + + // Set the color of the border + BorderFull.BorderBrush = SystemColors.ActiveCaptionBrush; + BorderFull.BorderThickness = new Thickness(resizeThickness.Left, 0, resizeThickness.Right, resizeThickness.Bottom); + + // Apply the stored settings + WindowSettings.Apply(); + } + + protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (msg == WindowManager.SetLockMessage) + { + var lockState = (wParam == 1); + + _dispatcher.InvokeAsync(() => + { + WindowSettings.Locked = lockState; + Locked = lockState; + }); + + return IntPtr.Zero; + } + + if (msg != WindowManager.CloseMessage) + return base.WndProc(hwnd, msg, wParam, lParam, ref handled); + + _dispatcher.InvokeAsync(Close); + return IntPtr.Zero; + } + + protected override void OnLocationChanged(EventArgs e) + { + base.OnLocationChanged(e); + + WindowSettings.Location = new Point(Left, Top); + } + + protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) + { + base.OnRenderSizeChanged(sizeInfo); + + WindowSettings.Size = new Size(Width, Height); + } + + protected override List OtherWindows + { + get + { + var windowHandle = new WindowInteropHelper(this).Handle; + + return WindowManager.GetWindowList(windowHandle); + } + } + + private void HandleChangeAppearanceClick(object sender, RoutedEventArgs e) + { + var appearanceWindow = new AppearanceWindow(WindowSettings); + appearanceWindow.ShowDialog(); + } +} \ No newline at end of file diff --git a/Library/Properties/AssemblyInfo.cs b/Library/Properties/AssemblyInfo.cs index d237a2f..3411910 100644 --- a/Library/Properties/AssemblyInfo.cs +++ b/Library/Properties/AssemblyInfo.cs @@ -1,19 +1,13 @@ using System.Reflection; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Windows; -[assembly: AssemblyTitle("FloatingStatusWindowLibrary")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Chris Kaczor")] -[assembly: AssemblyProduct("FloatingStatusWindowLibrary")] -[assembly: AssemblyCopyright("Copyright © Chris Kaczor 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - [assembly: ComVisible(false)] +[assembly: SupportedOSPlatform("windows")] + [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] -[assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] diff --git a/Library/Properties/Resources.Designer.cs b/Library/Properties/Resources.Designer.cs index b3f436e..963fa9f 100644 --- a/Library/Properties/Resources.Designer.cs +++ b/Library/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace FloatingStatusWindowLibrary.Properties { +namespace ChrisKaczor.Wpf.FloatingStatusWindow.Properties { using System; @@ -19,7 +19,7 @@ namespace FloatingStatusWindowLibrary.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Resources { @@ -39,7 +39,7 @@ namespace FloatingStatusWindowLibrary.Properties { public static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FloatingStatusWindowLibrary.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ChrisKaczor.Wpf.FloatingStatusWindow.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Library/StartManager.cs b/Library/StartManager.cs index 1e01afc..ee305f0 100644 --- a/Library/StartManager.cs +++ b/Library/StartManager.cs @@ -1,34 +1,31 @@ -using Common.Wpf.Extensions; +using ChrisKaczor.Wpf.Application; using System; using System.Windows; -namespace FloatingStatusWindowLibrary +namespace ChrisKaczor.Wpf.FloatingStatusWindow; + +public static class StartManager { - public static class StartManager + public delegate void AutoStartChangedEventHandler(bool autoStart); + + public static event AutoStartChangedEventHandler AutoStartChanged = delegate { }; + + public static bool ManageAutoStart { get; set; } + + private static bool _autoStartEnabled; + + public static bool AutoStartEnabled { - public delegate void AutoStartChangedEventHandler(bool autoStart); - - public static event AutoStartChangedEventHandler AutoStartChanged = delegate { }; - - public static bool ManageAutoStart { get; set; } - - private static bool _autoStartEnabled; - public static bool AutoStartEnabled + get => ManageAutoStart && _autoStartEnabled; + set { - get - { - return ManageAutoStart && _autoStartEnabled; - } - set - { - if (!ManageAutoStart) - throw new InvalidOperationException("Cannot set AutoStartEnabled when ManageAutoStart is False"); + if (!ManageAutoStart) + throw new InvalidOperationException("Cannot set AutoStartEnabled when ManageAutoStart is False"); - _autoStartEnabled = value; + _autoStartEnabled = value; - Application.Current.SetStartWithWindows(_autoStartEnabled); - AutoStartChanged(_autoStartEnabled); - } + System.Windows.Application.Current.SetStartWithWindows(_autoStartEnabled); + AutoStartChanged(_autoStartEnabled); } } -} +} \ No newline at end of file diff --git a/Library/WindowManager.cs b/Library/WindowManager.cs index 97a30a3..c85354e 100644 --- a/Library/WindowManager.cs +++ b/Library/WindowManager.cs @@ -1,77 +1,104 @@ -using Common.Native; -using Common.Wpf.Windows; +using ChrisKaczor.Wpf.Windows; using System; using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; -namespace FloatingStatusWindowLibrary +namespace ChrisKaczor.Wpf.FloatingStatusWindow; + +public static partial class WindowManager { - public static class WindowManager + private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); + + [LibraryImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial void EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam); + + [LibraryImport("user32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16, EntryPoint = "RegisterWindowMessageW")] + private static partial uint RegisterWindowMessage(string lpString); + + [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); + + [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowTextLengthW")] + private static partial int GetWindowTextLength(IntPtr hWnd); + + [LibraryImport("user32.dll", EntryPoint = "SendMessageW")] + private static partial void SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); + + private const string WindowMessageSetLock = "FloatingStatusWindowLibrary_SetLock"; + private const string WindowMessageClose = "FloatingStatusWindowLibrary_Close"; + + public static uint SetLockMessage { get; set; } + public static uint CloseMessage { get; set; } + + static WindowManager() { - private const string WindowMessageSetLock = "FloatingStatusWindowLibrary_SetLock"; - private const string WindowMessageClose = "FloatingStatusWindowLibrary_Close"; + SetLockMessage = RegisterWindowMessage(WindowMessageSetLock); + CloseMessage = RegisterWindowMessage(WindowMessageClose); + } - public static uint SetLockMessage { get; set; } - public static uint CloseMessage { get; set; } + private static readonly object WindowLocker = new(); - static WindowManager() + private static List _windowList; + private static IntPtr _excludeHandle; + + public static List GetWindowList() + { + lock (WindowLocker) { - SetLockMessage = Functions.User32.RegisterWindowMessage(WindowMessageSetLock); - CloseMessage = Functions.User32.RegisterWindowMessage(WindowMessageClose); - } + _windowList = new List(); + _excludeHandle = IntPtr.Zero; - private static readonly object WindowLocker = new object(); + EnumWindows(EnumWindowProc, IntPtr.Zero); - private static List _windowList; - private static IntPtr _excludeHandle; - - public static List GetWindowList() - { - lock (WindowLocker) - { - _windowList = new List(); - _excludeHandle = IntPtr.Zero; - - Functions.User32.EnumWindows(EnumWindowProc, IntPtr.Zero); - - return _windowList; - } - } - - public static List GetWindowList(IntPtr excludeHandle) - { - lock (WindowLocker) - { - _windowList = new List(); - _excludeHandle = excludeHandle; - - Functions.User32.EnumWindows(EnumWindowProc, IntPtr.Zero); - - return _windowList; - } - } - - private static bool EnumWindowProc(IntPtr hWnd, IntPtr lParam) - { - var windowText = Functions.Window.GetText(hWnd); - - if (windowText == "FloatingStatusWindow" && hWnd != _excludeHandle) - _windowList.Add(new WindowInformation(hWnd)); - - return true; - } - - public static void SetLockOnAll(bool locked) - { - var lockState = locked ? (IntPtr) 1 : (IntPtr) 0; - - foreach (var w in GetWindowList()) - Functions.User32.SendMessage(w.Handle, SetLockMessage, lockState, IntPtr.Zero); - } - - public static void CloseAll() - { - foreach (var w in GetWindowList()) - Functions.User32.SendMessage(w.Handle, CloseMessage, IntPtr.Zero, IntPtr.Zero); + return _windowList; } } -} + + public static List GetWindowList(IntPtr excludeHandle) + { + lock (WindowLocker) + { + _windowList = new List(); + _excludeHandle = excludeHandle; + + EnumWindows(EnumWindowProc, IntPtr.Zero); + + return _windowList; + } + } + + private static string GetText(IntPtr hWnd) + { + // Allocate correct string length first + var length = GetWindowTextLength(hWnd); + var sb = new StringBuilder(length + 1); + _ = GetWindowText(hWnd, sb, sb.Capacity); + return sb.ToString(); + } + + private static bool EnumWindowProc(IntPtr hWnd, IntPtr lParam) + { + var windowText = GetText(hWnd); + + if (windowText == "FloatingStatusWindow" && hWnd != _excludeHandle) + _windowList.Add(new WindowInformation(hWnd)); + + return true; + } + + public static void SetLockOnAll(bool locked) + { + var lockState = locked ? 1 : 0; + + foreach (var w in GetWindowList()) + SendMessage(w.Handle, SetLockMessage, lockState, IntPtr.Zero); + } + + public static void CloseAll() + { + foreach (var w in GetWindowList()) + SendMessage(w.Handle, CloseMessage, IntPtr.Zero, IntPtr.Zero); + } +} \ No newline at end of file diff --git a/Library/WindowSettings.cs b/Library/WindowSettings.cs index 8e8c8c5..29f94af 100644 --- a/Library/WindowSettings.cs +++ b/Library/WindowSettings.cs @@ -1,122 +1,119 @@ -using System.Drawing; -using System.Drawing.Text; -using System.Linq; -using Common.Wpf.HtmlLabelControl; +using ChrisKaczor.Wpf.Controls; +using JetBrains.Annotations; using System; using System.IO; +using System.Linq; using System.Text; using System.Windows; +using System.Windows.Controls; using System.Windows.Media; using System.Xml.Serialization; -using Color = System.Windows.Media.Color; -using FontFamily = System.Windows.Media.FontFamily; -using Point = System.Windows.Point; -using Size = System.Windows.Size; -using SystemFonts = System.Windows.SystemFonts; -namespace FloatingStatusWindowLibrary +namespace ChrisKaczor.Wpf.FloatingStatusWindow; + +[PublicAPI] +public class WindowSettings : ICloneable { - public class WindowSettings : ICloneable + private const string DefaultFontName = "Consolas"; + private const int DefaultFontSize = 14; + + public string Name { get; set; } + public bool Visible { get; set; } + public Point Location { get; set; } + public Size Size { get; set; } + public int Padding { get; set; } + public HorizontalAlignment HorizontalAlignment { get; set; } + public VerticalAlignment VerticalAlignment { get; set; } + public bool Locked { get; set; } + public string FontName { get; set; } + public double FontSize { get; set; } + public Color FontColor { get; set; } + + [XmlIgnore] + private MainWindow Window { get; set; } + + [XmlIgnore] + private HtmlTextBlock HtmlLabel { get; set; } + + [XmlIgnore] + private Grid ContentGrid { get; set; } + + [XmlIgnore] + public System.Drawing.Font Font => new(FontName, (float)FontSize); + + internal void SetWindow(MainWindow floatingWindow) { - private const string DefaultFontName = "Consolas"; - private const int DefaultFontSize = 14; - - public string Name { get; set; } - public bool Visible { get; set; } - public Point Location { get; set; } - public Size Size { get; set; } - public int Padding { get; set; } - public HorizontalAlignment HorizontalAlignment { get; set; } - public VerticalAlignment VerticalAlignment { get; set; } - public bool Locked { get; set; } - public string FontName { get; set; } - public double FontSize { get; set; } - public Color FontColor { get; set; } - - [XmlIgnore] - private MainWindow Window { get; set; } - - [XmlIgnore] - private HtmlLabel HtmlLabel { get; set; } - - [XmlIgnore] - public Font Font - { - get { return new Font(FontName, (float) FontSize); } - } - - internal void SetWindow(MainWindow floatingWindow) - { - Window = floatingWindow; - HtmlLabel = floatingWindow.HtmlLabel; - } - - private WindowSettings() - { - var allFonts = new InstalledFontCollection(); - var fontExists = allFonts.Families.Any(f => f.Name == DefaultFontName); - - FontName = fontExists ? DefaultFontName : SystemFonts.MessageFontFamily.Source; - FontColor = (System.Drawing.SystemColors.Desktop.GetBrightness() < 0.5 ? Colors.Silver : Colors.Black); - FontSize = fontExists ? DefaultFontSize : SystemFonts.MessageFontSize; - Padding = 5; - HorizontalAlignment = HorizontalAlignment.Left; - VerticalAlignment = VerticalAlignment.Bottom; - Locked = false; - } - - internal void Apply() - { - // Configure the text label - HtmlLabel.FontFamily = new FontFamily(FontName); - HtmlLabel.FontSize = FontSize; - HtmlLabel.Foreground = new SolidColorBrush(FontColor); - HtmlLabel.Padding = new Thickness(Padding); - HtmlLabel.HorizontalContentAlignment = HorizontalAlignment; - HtmlLabel.VerticalContentAlignment = VerticalAlignment; - - // Put the window in its last position - Window.Left = Location.X; - Window.Top = Location.Y; - - // Set the last size if we have a valid size - if (!Size.Width.Equals(0) && !Size.Height.Equals(0)) - { - Window.Width = Size.Width; - Window.Height = Size.Height; - } - - Window.Locked = Locked; - } - - public object Clone() - { - return MemberwiseClone(); - } - - internal static WindowSettings Load(string settings) - { - if (string.IsNullOrEmpty(settings)) - return new WindowSettings(); - - var serializer = new XmlSerializer(typeof(WindowSettings)); - TextReader textReader = new StringReader(settings); - var windowSettings = (WindowSettings) serializer.Deserialize(textReader); - textReader.Close(); - - return windowSettings; - } - - internal string Save() - { - var builder = new StringBuilder(); - - var serializer = new XmlSerializer(typeof(WindowSettings)); - TextWriter textWriter = new StringWriter(builder); - serializer.Serialize(textWriter, this); - textWriter.Close(); - - return builder.ToString(); - } + Window = floatingWindow; + HtmlLabel = floatingWindow.HtmlLabel; + ContentGrid = floatingWindow.ContentGrid; } -} + + private WindowSettings() + { + var allFonts = new System.Drawing.Text.InstalledFontCollection(); + var fontExists = allFonts.Families.Any(f => f.Name == DefaultFontName); + + FontName = fontExists ? DefaultFontName : SystemFonts.MessageFontFamily.Source; + FontColor = (System.Drawing.SystemColors.Desktop.GetBrightness() < 0.5 ? Colors.Silver : Colors.Black); + FontSize = fontExists ? DefaultFontSize : SystemFonts.MessageFontSize; + Padding = 5; + HorizontalAlignment = HorizontalAlignment.Left; + VerticalAlignment = VerticalAlignment.Bottom; + Locked = false; + } + + internal void Apply() + { + // Configure the text label + HtmlLabel.FontFamily = new FontFamily(FontName); + HtmlLabel.FontSize = FontSize; + HtmlLabel.Foreground = new SolidColorBrush(FontColor); + HtmlLabel.Padding = new Thickness(Padding); + + ContentGrid.HorizontalAlignment = HorizontalAlignment; + ContentGrid.VerticalAlignment = VerticalAlignment; + + // Put the window in its last position + Window.Left = Location.X; + Window.Top = Location.Y; + + // Set the last size if we have a valid size + if (!Size.Width.Equals(0) && !Size.Height.Equals(0)) + { + Window.Width = Size.Width; + Window.Height = Size.Height; + } + + Window.Locked = Locked; + } + + public object Clone() + { + return MemberwiseClone(); + } + + internal static WindowSettings Load(string settings) + { + if (string.IsNullOrEmpty(settings)) + return new WindowSettings(); + + var serializer = new XmlSerializer(typeof(WindowSettings)); + TextReader textReader = new StringReader(settings); + var windowSettings = (WindowSettings)serializer.Deserialize(textReader); + textReader.Close(); + + return windowSettings; + } + + internal string Save() + { + var builder = new StringBuilder(); + + var serializer = new XmlSerializer(typeof(WindowSettings)); + TextWriter textWriter = new StringWriter(builder); + serializer.Serialize(textWriter, this); + textWriter.Close(); + + return builder.ToString(); + } +} \ No newline at end of file diff --git a/TestWindow/App.xaml.cs b/TestWindow/App.xaml.cs index eee8df3..ca9c8d9 100644 --- a/TestWindow/App.xaml.cs +++ b/TestWindow/App.xaml.cs @@ -1,42 +1,41 @@ -using FloatingStatusWindowLibrary; +using ChrisKaczor.Wpf.FloatingStatusWindow; using System; using System.Collections.Generic; using System.Diagnostics; using System.Windows; using Settings = TestWindow.Properties.Settings; -namespace TestWindow +namespace TestWindow; + +public partial class App { - public partial class App + private List _windowSourceList; + + protected override void OnStartup(StartupEventArgs e) { - private List _windowSourceList; + base.OnStartup(e); - protected override void OnStartup(StartupEventArgs e) + StartManager.ManageAutoStart = true; + StartManager.AutoStartEnabled = !Debugger.IsAttached && Settings.Default.AutoStart; + StartManager.AutoStartChanged += (value => { - base.OnStartup(e); + Settings.Default.AutoStart = value; + Settings.Default.Save(); + }); - StartManager.ManageAutoStart = true; - StartManager.AutoStartEnabled = !Debugger.IsAttached && Settings.Default.AutoStart; - StartManager.AutoStartChanged += (value => - { - Settings.Default.AutoStart = value; - Settings.Default.Save(); - }); - - _windowSourceList = new List - { - new WindowSource1(), - new WindowSource2(), - new WindowSource3(), - new WindowSource4() - }; - } - - protected override void OnExit(ExitEventArgs e) + _windowSourceList = new List { - _windowSourceList.ForEach(ws => ws.Dispose()); - - base.OnExit(e); - } + new WindowSource1(), + new WindowSource2(), + new WindowSource3(), + new WindowSource4() + }; } -} + + protected override void OnExit(ExitEventArgs e) + { + _windowSourceList.ForEach(ws => ws.Dispose()); + + base.OnExit(e); + } +} \ No newline at end of file diff --git a/TestWindow/Properties/AssemblyInfo.cs b/TestWindow/Properties/AssemblyInfo.cs index 92d4a6d..08b0ee7 100644 --- a/TestWindow/Properties/AssemblyInfo.cs +++ b/TestWindow/Properties/AssemblyInfo.cs @@ -2,6 +2,7 @@ using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Windows; // General Information about an assembly is controlled through the following @@ -16,6 +17,9 @@ using System.Windows; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +[assembly: SupportedOSPlatform("windows7.0")] +[assembly: NeutralResourcesLanguage("en-US")] + // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. diff --git a/TestWindow/Settings.cs b/TestWindow/Settings.cs deleted file mode 100644 index c6a7a03..0000000 --- a/TestWindow/Settings.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace TestWindow.Properties { - - - // This class allows you to handle specific events on the settings class: - // The SettingChanging event is raised before a setting's value is changed. - // The PropertyChanged event is raised after a setting's value is changed. - // The SettingsLoaded event is raised after the setting values are loaded. - // The SettingsSaving event is raised before the setting values are saved. - internal sealed partial class Settings { - - public Settings() { - // // To add event handlers for saving and changing settings, uncomment the lines below: - // - // this.SettingChanging += this.SettingChangingEventHandler; - // - // this.SettingsSaving += this.SettingsSavingEventHandler; - // - } - - private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { - // Add code to handle the SettingChangingEvent event here. - } - - private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { - // Add code to handle the SettingsSaving event here. - } - } -} diff --git a/TestWindow/TestWindow.csproj b/TestWindow/TestWindow.csproj index 02f6565..5bf4185 100644 --- a/TestWindow/TestWindow.csproj +++ b/TestWindow/TestWindow.csproj @@ -1,111 +1,20 @@ - - - + - Debug - AnyCPU - {0C541788-8FFD-47B6-8E6B-653A884CFA55} + net70-windows WinExe - Properties - TestWindow - TestWindow - v4.5 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + false + true + true - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - - - - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - SettingsSingleFileGenerator - Settings.Designer.cs - - + - - {f023a16c-2f13-4a87-a8b7-22c43c4a58a4} - FloatingStatusWindowLibrary - + + + - - - - - \ No newline at end of file diff --git a/TestWindow/WindowSource1.cs b/TestWindow/WindowSource1.cs index 8092ae8..fea595c 100644 --- a/TestWindow/WindowSource1.cs +++ b/TestWindow/WindowSource1.cs @@ -1,92 +1,88 @@ -using FloatingStatusWindowLibrary; +using ChrisKaczor.Wpf.FloatingStatusWindow; using System; using System.Globalization; using System.Reflection; using System.Timers; using System.Windows.Threading; -namespace TestWindow +namespace TestWindow; + +internal class WindowSource1 : IWindowSource, IDisposable { - internal class WindowSource1 : IWindowSource, IDisposable + private readonly FloatingStatusWindow _floatingStatusWindow; + private readonly Timer _timer; + private readonly Dispatcher _dispatcher; + + internal WindowSource1() { - private readonly FloatingStatusWindow _floatingStatusWindow; - private readonly Timer _timer; - private readonly Dispatcher _dispatcher; + _floatingStatusWindow = new FloatingStatusWindow(this); + _floatingStatusWindow.SetText("Loading..."); - internal WindowSource1() + _dispatcher = Dispatcher.CurrentDispatcher; + + _timer = new Timer(1000); + _timer.Elapsed += HandleTimerElapsed; + _timer.Enabled = true; + } + + private void HandleTimerElapsed(object sender, ElapsedEventArgs e) + { + _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); + } + + public void Dispose() + { + _timer.Enabled = false; + _timer.Dispose(); + + _floatingStatusWindow.Save(); + _floatingStatusWindow.Dispose(); + } + + public Guid Id => Guid.Parse("0329D04D-B89B-4FEC-AFD0-4CB972E47FC8"); + + public string Name + { + get { return "Test Window 1"; } + } + + public System.Drawing.Icon Icon + { + get { return Properties.Resources.ApplicationIcon; } + } + + public bool HasSettingsMenu + { + get { return true; } + } + + public bool HasAboutMenu => true; + + public void ShowAbout() + { + _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); + } + + public void ShowSettings() + { + } + + public bool HasRefreshMenu + { + get { return true; } + } + + public void Refresh() + { + } + + public string WindowSettings + { + get { return Properties.Settings.Default.WindowSettings1; } + set { - _floatingStatusWindow = new FloatingStatusWindow(this); - _floatingStatusWindow.SetText("Loading..."); - - _dispatcher = Dispatcher.CurrentDispatcher; - - _timer = new Timer(1000); - _timer.Elapsed += HandleTimerElapsed; - _timer.Enabled = true; - } - - private void HandleTimerElapsed(object sender, ElapsedEventArgs e) - { - _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); - } - - public void Dispose() - { - _timer.Enabled = false; - _timer.Dispose(); - - _floatingStatusWindow.Save(); - _floatingStatusWindow.Dispose(); - } - - public string Name - { - get { return "Test Window 1"; } - } - - public System.Drawing.Icon Icon - { - get { return Properties.Resources.ApplicationIcon; } - } - - public bool HasSettingsMenu - { - get { return true; } - } - - public bool HasAboutMenu => true; - - public void ShowAbout() - { - _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); - } - - public void ShowSettings() - { - - } - - public bool HasRefreshMenu - { - get { return true; } - } - - public void Refresh() - { - - } - - public string WindowSettings - { - get - { - return Properties.Settings.Default.WindowSettings1; - } - set - { - Properties.Settings.Default.WindowSettings1 = value; - Properties.Settings.Default.Save(); - } + Properties.Settings.Default.WindowSettings1 = value; + Properties.Settings.Default.Save(); } } -} +} \ No newline at end of file diff --git a/TestWindow/WindowSource2.cs b/TestWindow/WindowSource2.cs index b7b0a68..b95ecff 100644 --- a/TestWindow/WindowSource2.cs +++ b/TestWindow/WindowSource2.cs @@ -1,92 +1,88 @@ -using FloatingStatusWindowLibrary; +using ChrisKaczor.Wpf.FloatingStatusWindow; using System; using System.Globalization; using System.Reflection; using System.Timers; using System.Windows.Threading; -namespace TestWindow +namespace TestWindow; + +internal class WindowSource2 : IWindowSource, IDisposable { - internal class WindowSource2 : IWindowSource, IDisposable + private readonly FloatingStatusWindow _floatingStatusWindow; + private readonly Timer _timer; + private readonly Dispatcher _dispatcher; + + internal WindowSource2() { - private readonly FloatingStatusWindow _floatingStatusWindow; - private readonly Timer _timer; - private readonly Dispatcher _dispatcher; + _floatingStatusWindow = new FloatingStatusWindow(this); + _floatingStatusWindow.SetText("Loading..."); - internal WindowSource2() + _dispatcher = Dispatcher.CurrentDispatcher; + + _timer = new Timer(1000); + _timer.Elapsed += HandleTimerElapsed; + _timer.Enabled = true; + } + + private void HandleTimerElapsed(object sender, ElapsedEventArgs e) + { + _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); + } + + public void Dispose() + { + _timer.Enabled = false; + _timer.Dispose(); + + _floatingStatusWindow.Save(); + _floatingStatusWindow.Dispose(); + } + + public Guid Id => Guid.Parse("F42F92BC-D397-497A-8E01-E71D084BEDB6"); + + public string Name + { + get { return "Test Window 2"; } + } + + public System.Drawing.Icon Icon + { + get { return Properties.Resources.ApplicationIcon; } + } + + public bool HasSettingsMenu + { + get { return true; } + } + + public bool HasAboutMenu => true; + + public void ShowAbout() + { + _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); + } + + public void ShowSettings() + { + } + + public bool HasRefreshMenu + { + get { return true; } + } + + public void Refresh() + { + } + + public string WindowSettings + { + get { return Properties.Settings.Default.WindowSettings2; } + set { - _floatingStatusWindow = new FloatingStatusWindow(this); - _floatingStatusWindow.SetText("Loading..."); - - _dispatcher = Dispatcher.CurrentDispatcher; - - _timer = new Timer(1000); - _timer.Elapsed += HandleTimerElapsed; - _timer.Enabled = true; - } - - private void HandleTimerElapsed(object sender, ElapsedEventArgs e) - { - _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); - } - - public void Dispose() - { - _timer.Enabled = false; - _timer.Dispose(); - - _floatingStatusWindow.Save(); - _floatingStatusWindow.Dispose(); - } - - public string Name - { - get { return "Test Window 2"; } - } - - public System.Drawing.Icon Icon - { - get { return Properties.Resources.ApplicationIcon; } - } - - public bool HasSettingsMenu - { - get { return true; } - } - - public bool HasAboutMenu => true; - - public void ShowAbout() - { - _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); - } - - public void ShowSettings() - { - - } - - public bool HasRefreshMenu - { - get { return true; } - } - - public void Refresh() - { - - } - - public string WindowSettings - { - get - { - return Properties.Settings.Default.WindowSettings2; - } - set - { - Properties.Settings.Default.WindowSettings2 = value; - Properties.Settings.Default.Save(); - } + Properties.Settings.Default.WindowSettings2 = value; + Properties.Settings.Default.Save(); } } -} +} \ No newline at end of file diff --git a/TestWindow/WindowSource3.cs b/TestWindow/WindowSource3.cs index 95a9d41..dca0d2d 100644 --- a/TestWindow/WindowSource3.cs +++ b/TestWindow/WindowSource3.cs @@ -1,92 +1,88 @@ -using FloatingStatusWindowLibrary; +using ChrisKaczor.Wpf.FloatingStatusWindow; using System; using System.Globalization; using System.Reflection; using System.Timers; using System.Windows.Threading; -namespace TestWindow +namespace TestWindow; + +internal class WindowSource3 : IWindowSource, IDisposable { - internal class WindowSource3 : IWindowSource, IDisposable + private readonly FloatingStatusWindow _floatingStatusWindow; + private readonly Timer _timer; + private readonly Dispatcher _dispatcher; + + internal WindowSource3() { - private readonly FloatingStatusWindow _floatingStatusWindow; - private readonly Timer _timer; - private readonly Dispatcher _dispatcher; + _floatingStatusWindow = new FloatingStatusWindow(this); + _floatingStatusWindow.SetText("Loading..."); - internal WindowSource3() + _dispatcher = Dispatcher.CurrentDispatcher; + + _timer = new Timer(1000); + _timer.Elapsed += HandleTimerElapsed; + _timer.Enabled = true; + } + + private void HandleTimerElapsed(object sender, ElapsedEventArgs e) + { + _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); + } + + public void Dispose() + { + _timer.Enabled = false; + _timer.Dispose(); + + _floatingStatusWindow.Save(); + _floatingStatusWindow.Dispose(); + } + + public Guid Id => Guid.Parse("CF7466DF-8980-452B-B2FA-290B26204BF2"); + + public string Name + { + get { return "Test Window 3"; } + } + + public System.Drawing.Icon Icon + { + get { return Properties.Resources.ApplicationIcon; } + } + + public bool HasSettingsMenu + { + get { return true; } + } + + public bool HasAboutMenu => true; + + public void ShowAbout() + { + _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); + } + + public void ShowSettings() + { + } + + public bool HasRefreshMenu + { + get { return true; } + } + + public void Refresh() + { + } + + public string WindowSettings + { + get { return Properties.Settings.Default.WindowSettings3; } + set { - _floatingStatusWindow = new FloatingStatusWindow(this); - _floatingStatusWindow.SetText("Loading..."); - - _dispatcher = Dispatcher.CurrentDispatcher; - - _timer = new Timer(1000); - _timer.Elapsed += HandleTimerElapsed; - _timer.Enabled = true; - } - - private void HandleTimerElapsed(object sender, ElapsedEventArgs e) - { - _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); - } - - public void Dispose() - { - _timer.Enabled = false; - _timer.Dispose(); - - _floatingStatusWindow.Save(); - _floatingStatusWindow.Dispose(); - } - - public string Name - { - get { return "Test Window 3"; } - } - - public System.Drawing.Icon Icon - { - get { return Properties.Resources.ApplicationIcon; } - } - - public bool HasSettingsMenu - { - get { return true; } - } - - public bool HasAboutMenu => true; - - public void ShowAbout() - { - _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); - } - - public void ShowSettings() - { - - } - - public bool HasRefreshMenu - { - get { return true; } - } - - public void Refresh() - { - - } - - public string WindowSettings - { - get - { - return Properties.Settings.Default.WindowSettings3; - } - set - { - Properties.Settings.Default.WindowSettings3 = value; - Properties.Settings.Default.Save(); - } + Properties.Settings.Default.WindowSettings3 = value; + Properties.Settings.Default.Save(); } } -} +} \ No newline at end of file diff --git a/TestWindow/WindowSource4.cs b/TestWindow/WindowSource4.cs index 585dfc9..adc5d5e 100644 --- a/TestWindow/WindowSource4.cs +++ b/TestWindow/WindowSource4.cs @@ -1,92 +1,88 @@ -using FloatingStatusWindowLibrary; +using ChrisKaczor.Wpf.FloatingStatusWindow; using System; using System.Globalization; using System.Reflection; using System.Timers; using System.Windows.Threading; -namespace TestWindow +namespace TestWindow; + +internal class WindowSource4 : IWindowSource, IDisposable { - internal class WindowSource4 : IWindowSource, IDisposable + private readonly FloatingStatusWindow _floatingStatusWindow; + private readonly Timer _timer; + private readonly Dispatcher _dispatcher; + + internal WindowSource4() { - private readonly FloatingStatusWindow _floatingStatusWindow; - private readonly Timer _timer; - private readonly Dispatcher _dispatcher; + _floatingStatusWindow = new FloatingStatusWindow(this); + _floatingStatusWindow.SetText("Loading..."); - internal WindowSource4() + _dispatcher = Dispatcher.CurrentDispatcher; + + _timer = new Timer(1000); + _timer.Elapsed += HandleTimerElapsed; + _timer.Enabled = true; + } + + private void HandleTimerElapsed(object sender, ElapsedEventArgs e) + { + _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); + } + + public void Dispose() + { + _timer.Enabled = false; + _timer.Dispose(); + + _floatingStatusWindow.Save(); + _floatingStatusWindow.Dispose(); + } + + public Guid Id => Guid.Parse("0DD89F7E-3AD4-4226-8CBD-B75C8EBEEF32"); + + public string Name + { + get { return "Test Window 4"; } + } + + public System.Drawing.Icon Icon + { + get { return Properties.Resources.ApplicationIcon; } + } + + public bool HasSettingsMenu + { + get { return true; } + } + + public bool HasAboutMenu => true; + + public void ShowAbout() + { + _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); + } + + public void ShowSettings() + { + } + + public bool HasRefreshMenu + { + get { return true; } + } + + public void Refresh() + { + } + + public string WindowSettings + { + get { return Properties.Settings.Default.WindowSettings4; } + set { - _floatingStatusWindow = new FloatingStatusWindow(this); - _floatingStatusWindow.SetText("Loading..."); - - _dispatcher = Dispatcher.CurrentDispatcher; - - _timer = new Timer(1000); - _timer.Elapsed += HandleTimerElapsed; - _timer.Enabled = true; - } - - private void HandleTimerElapsed(object sender, ElapsedEventArgs e) - { - _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(DateTime.Now.ToString(CultureInfo.InvariantCulture))); - } - - public void Dispose() - { - _timer.Enabled = false; - _timer.Dispose(); - - _floatingStatusWindow.Save(); - _floatingStatusWindow.Dispose(); - } - - public string Name - { - get { return "Test Window 4"; } - } - - public System.Drawing.Icon Icon - { - get { return Properties.Resources.ApplicationIcon; } - } - - public bool HasSettingsMenu - { - get { return true; } - } - - public bool HasAboutMenu => true; - - public void ShowAbout() - { - _floatingStatusWindow.SetText(Assembly.GetEntryAssembly().GetName().Version.ToString()); - } - - public void ShowSettings() - { - - } - - public bool HasRefreshMenu - { - get { return true; } - } - - public void Refresh() - { - - } - - public string WindowSettings - { - get - { - return Properties.Settings.Default.WindowSettings4; - } - set - { - Properties.Settings.Default.WindowSettings4 = value; - Properties.Settings.Default.Save(); - } + Properties.Settings.Default.WindowSettings4 = value; + Properties.Settings.Default.Save(); } } -} +} \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 311f8bd..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: 1.0.0.{build} -pull_requests: - do_not_increment_build_number: true -skip_tags: true -image: Visual Studio 2017 -configuration: Release -assembly_info: - patch: true - file: 'Library\Properties\AssemblyInfo.cs' - assembly_version: '{version}' - assembly_file_version: '{version}' -build: - project: FloatingStatusWindow.sln - verbosity: minimal -after_build: -- cmd: nuget pack Library\FloatingStatusWindow.nuspec -Version %appveyor_build_version% -Properties Configuration=Release -OutputDirectory Library\bin\Release\ -artifacts: -- path: Library\bin\$(configuration)\FloatingStatusWindow.*.nupkg - name: NuGet -deploy: -- provider: Environment - name: GitHub -- provider: Environment - name: NuGet -install: -- cmd: git submodule update --init --recursive -before_build: -- cmd: msbuild /t:restore \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..9a1959b --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,63 @@ +name: 2.0.0.$(Rev:r) + +pr: none + +trigger: + batch: 'true' + branches: + include: + - main + +pool: + vmImage: 'windows-latest' + +variables: + buildConfiguration: 'Release' + +steps: +- task: GetRevision@1 + displayName: 'Get Revision' + inputs: + VariableName: Revision + +- task: Assembly-Info-NetCore@3 + displayName: 'Set Assembly Info' + inputs: + Path: '$(Build.SourcesDirectory)' + FileNames: 'Library/*.csproj' + InsertAttributes: true + FileEncoding: 'utf-8' + WriteBOM: true + FailOnWarning: true + Authors: 'Chris Kaczor' + Copyright: 'Copyright $(date:YYYY) Chris Kaczor' + FileVersion: '2.0.0.$(Revision)' + PackageVersion: '2.0.0.$(Revision)' + +- task: DotNetCoreCLI@2 + displayName: 'dotnet build' + inputs: + command: 'build' + arguments: '--configuration $(buildConfiguration)' + projects: 'FloatingStatusWindow.csproj' + +- task: DotNetCoreCLI@2 + displayName: "dotnet pack" + inputs: + command: 'pack' + arguments: '--configuration $(buildConfiguration)' + packagesToPack: 'FloatingStatusWindow.csproj' + nobuild: true + versioningScheme: 'byBuildNumber' + +- task: NuGetCommand@2 + displayName: 'nuget push' + inputs: + command: 'push' + feedsToUse: 'select' + packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' + nuGetFeedType: external + publishFeedCredentials: 'NuGet' + publishVstsFeed: 'Packages' + versioningScheme: 'byBuildNumber' + allowPackageConflicts: true \ No newline at end of file