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 MainWindow _mainWindow;
private readonly TaskbarIcon _taskbarIcon; private readonly TaskbarIcon _taskbarIcon;
private readonly MenuItem _lockMenuItem; private readonly MenuItem _lockMenuItem;
private readonly MenuItem _autoStartMenuItem;
private readonly IWindowSource _windowSource; private readonly IWindowSource _windowSource;
@@ -20,6 +22,21 @@ namespace FloatingStatusWindowLibrary
var contextMenu = new ContextMenu(); var contextMenu = new ContextMenu();
contextMenu.Opened += HandleContextMenuOpened; 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 var menuItem = new MenuItem
{ {
Name = "contextMenuChangeAppearance", Name = "contextMenuChangeAppearance",
@@ -81,6 +98,9 @@ namespace FloatingStatusWindowLibrary
private void HandleContextMenuOpened(object sender, RoutedEventArgs e) private void HandleContextMenuOpened(object sender, RoutedEventArgs e)
{ {
_lockMenuItem.IsChecked = _mainWindow.WindowSettings.Locked; _lockMenuItem.IsChecked = _mainWindow.WindowSettings.Locked;
if (_autoStartMenuItem != null)
_autoStartMenuItem.IsChecked = StartManager.AutoStartEnabled;
} }
public void SetText(string text) public void SetText(string text)

View File

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

View File

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

View File

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

View File

@@ -69,8 +69,6 @@ namespace FloatingStatusWindowLibrary
// Apply the stored settings // Apply the stored settings
_windowSettings.Apply(); _windowSettings.Apply();
HtmlLabel.Text = "Testing";
} }
protected override void OnLocationChanged(EventArgs e) 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> /// <summary>
/// Looks up a localized string similar to Change Appearance. /// Looks up a localized string similar to Change Appearance.
/// </summary> /// </summary>

View File

@@ -129,6 +129,9 @@
<data name="ChangeAppearanceWindow" xml:space="preserve"> <data name="ChangeAppearanceWindow" xml:space="preserve">
<value>Change Appearance</value> <value>Change Appearance</value>
</data> </data>
<data name="ContextMenuAutoStart" xml:space="preserve">
<value>Start with Windows</value>
</data>
<data name="ContextMenuChangeAppearance" xml:space="preserve"> <data name="ContextMenuChangeAppearance" xml:space="preserve">
<value>Change Appearance</value> <value>Change Appearance</value>
</data> </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 Common.Wpf.HtmlLabelControl;
using System; using System;
using System.Configuration;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Windows; using System.Windows;

View File

@@ -13,6 +13,9 @@
<setting name="WindowSettings" serializeAs="String"> <setting name="WindowSettings" serializeAs="String">
<value /> <value />
</setting> </setting>
<setting name="AutoStart" serializeAs="String">
<value>True</value>
</setting>
</TestWindow.Properties.Settings> </TestWindow.Properties.Settings>
</userSettings> </userSettings>
</configuration> </configuration>

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic; using FloatingStatusWindowLibrary;
using System.Collections.Generic;
using System.Windows; using System.Windows;
using Settings = TestWindow.Properties.Settings;
namespace TestWindow namespace TestWindow
{ {
@@ -11,7 +13,20 @@ namespace TestWindow
{ {
base.OnStartup(e); base.OnStartup(e);
_windowSourceList = new List<WindowSource> { new WindowSource(), new WindowSource(), new WindowSource() }; StartManager.ManageAutoStart = true;
StartManager.AutoStartEnabled = Settings.Default.AutoStart;
StartManager.AutoStartChanged += (value =>
{
Settings.Default.AutoStart = value;
Settings.Default.Save();
});
_windowSourceList = new List<WindowSource>
{
//new WindowSource(),
//new WindowSource(),
new WindowSource()
};
} }
protected override void OnExit(ExitEventArgs e) protected override void OnExit(ExitEventArgs e)

View File

@@ -34,5 +34,17 @@ namespace TestWindow.Properties {
this["WindowSettings"] = value; this["WindowSettings"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool AutoStart {
get {
return ((bool)(this["AutoStart"]));
}
set {
this["AutoStart"] = value;
}
}
} }
} }

View File

@@ -5,5 +5,8 @@
<Setting Name="WindowSettings" Type="System.String" Scope="User"> <Setting Name="WindowSettings" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="AutoStart" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>