Auto start support

This commit is contained in:
2014-05-03 09:50:56 -04:00
parent 967af2834b
commit 5159468d80
13 changed files with 102 additions and 8 deletions

View File

@@ -9,7 +9,9 @@ namespace FloatingStatusWindowLibrary
{
private readonly MainWindow _mainWindow;
private readonly TaskbarIcon _taskbarIcon;
private readonly MenuItem _lockMenuItem;
private readonly MenuItem _autoStartMenuItem;
private readonly IWindowSource _windowSource;
@@ -20,6 +22,21 @@ namespace FloatingStatusWindowLibrary
var contextMenu = new ContextMenu();
contextMenu.Opened += HandleContextMenuOpened;
if (StartManager.ManageAutoStart)
{
_autoStartMenuItem = new MenuItem
{
Name = "contextMenuItemAutoStart",
IsChecked = StartManager.AutoStartEnabled,
Header = Properties.Resources.ContextMenuAutoStart
};
_autoStartMenuItem.Click += (sender, args) => StartManager.AutoStartEnabled = !StartManager.AutoStartEnabled;
contextMenu.Items.Add(_autoStartMenuItem);
contextMenu.Items.Add(new Separator());
}
var menuItem = new MenuItem
{
Name = "contextMenuChangeAppearance",
@@ -81,6 +98,9 @@ namespace FloatingStatusWindowLibrary
private void HandleContextMenuOpened(object sender, RoutedEventArgs e)
{
_lockMenuItem.IsChecked = _mainWindow.WindowSettings.Locked;
if (_autoStartMenuItem != null)
_autoStartMenuItem.IsChecked = StartManager.AutoStartEnabled;
}
public void SetText(string text)

View File

@@ -72,6 +72,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="StartManager.cs" />
<Compile Include="WindowSettings.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>

View File

@@ -6,7 +6,6 @@ namespace FloatingStatusWindowLibrary
{
string Name { get; }
string WindowSettings { get; set; }
Icon Icon { get; }
}
}

View File

@@ -1,7 +1,6 @@
<windows:SnappingWindow x:Class="FloatingStatusWindowLibrary.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:FloatingStatusWindowLibrary.Properties"
xmlns:htmlLabelControl="clr-namespace:Common.Wpf.HtmlLabelControl;assembly=Common.Wpf"
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
windows:ControlBox.HasMaximizeButton="False" windows:ControlBox.HasMinimizeButton="False" windows:ControlBox.HasSystemMenu="False"
@@ -13,7 +12,6 @@
<Border Name="HeaderBorder" Height="24" VerticalAlignment="Top">
<Grid>
<Label HorizontalAlignment="Stretch" Name="HeaderLabel" Margin="0,0,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0">
Testing
</Label>
</Grid>
</Border>

View File

@@ -69,8 +69,6 @@ namespace FloatingStatusWindowLibrary
// Apply the stored settings
_windowSettings.Apply();
HtmlLabel.Text = "Testing";
}
protected override void OnLocationChanged(EventArgs e)

View File

@@ -96,6 +96,15 @@ namespace FloatingStatusWindowLibrary.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Start with Windows.
/// </summary>
public static string ContextMenuAutoStart {
get {
return ResourceManager.GetString("ContextMenuAutoStart", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Change Appearance.
/// </summary>

View File

@@ -129,6 +129,9 @@
<data name="ChangeAppearanceWindow" xml:space="preserve">
<value>Change Appearance</value>
</data>
<data name="ContextMenuAutoStart" xml:space="preserve">
<value>Start with Windows</value>
</data>
<data name="ContextMenuChangeAppearance" xml:space="preserve">
<value>Change Appearance</value>
</data>

View File

@@ -0,0 +1,34 @@
using Common.Wpf.Extensions;
using System;
using System.Windows;
namespace FloatingStatusWindowLibrary
{
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
{
get
{
return ManageAutoStart && _autoStartEnabled;
}
set
{
if (!ManageAutoStart)
throw new InvalidOperationException("Cannot set AutoStartEnabled when ManageAutoStart is False");
_autoStartEnabled = value;
Application.Current.SetStartWithWindows(_autoStartEnabled);
AutoStartChanged(_autoStartEnabled);
}
}
}
}

View File

@@ -1,6 +1,5 @@
using Common.Wpf.HtmlLabelControl;
using System;
using System.Configuration;
using System.IO;
using System.Text;
using System.Windows;