Skip to content

Commit

Permalink
Settings window (hook alt+tab)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrondeau committed Jul 27, 2014
1 parent bfd4d54 commit 4836452
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 30 deletions.
12 changes: 12 additions & 0 deletions GoToWindow/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="GoToWindow.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<userSettings>
<GoToWindow.Properties.Settings>
<setting name="HookAltTab" serializeAs="String">
<value>True</value>
</setting>
</GoToWindow.Properties.Settings>
</userSettings>
</configuration>
3 changes: 2 additions & 1 deletion GoToWindow/App.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Application x:Class="GoToWindow.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:properties="clr-namespace:GoToWindow.Properties"
ShutdownMode="OnExplicitShutdown"
Startup="Application_Startup"
Exit="Application_Exit"
Deactivated="Application_Deactivated">
<Application.Resources>
<properties:Settings x:Key="Settings" />
</Application.Resources>
</Application>
26 changes: 18 additions & 8 deletions GoToWindow/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using GoToWindow.Api;
using GoToWindow.Commands;
using GoToWindow.Windows;
using Hardcodet.Wpf.TaskbarNotification;
using System;
using System.Collections.Generic;
Expand All @@ -13,9 +15,6 @@

namespace GoToWindow
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private readonly IGoToWindowContext _context = new GoToWindowContext();
Expand All @@ -31,21 +30,32 @@ private void Application_Startup(object sender, StartupEventArgs e)
Application.Current.Shutdown(1);
return;
}

TaskbarIcon trayIcon = new TaskbarIcon();
trayIcon.Icon = GoToWindow.Properties.Resources.AppIcon;
trayIcon.ToolTipText = "Go To Window";
trayIcon.DoubleClickCommand = new OpenMainWindowCommand(_context);

trayIcon.ContextMenu = CreateContextMenu();

if (GoToWindow.Properties.Settings.Default.HookAltTab)
_keyHandler = new InterceptAltTab(HandleAltTab);
}

private ContextMenu CreateContextMenu()
{
var contextMenu = new ContextMenu();
var showMenu = new MenuItem { Header = "Show", Command = new OpenMainWindowCommand(_context) };
contextMenu.Items.Add(showMenu);

var settingsMenu = new MenuItem { Header = "Settings", Command = new ShowSettingsCommand() };
contextMenu.Items.Add(settingsMenu);

contextMenu.Items.Add(new Separator());

var exitMenuItem = new MenuItem { Header = "Exit", Command = new ExitCommand() };
contextMenu.Items.Add(exitMenuItem);

trayIcon.ContextMenu = contextMenu;

_keyHandler = new InterceptAltTab(HandleAltTab);
return contextMenu;
}

delegate void CommandDelegate(object parameters);
Expand Down
25 changes: 25 additions & 0 deletions GoToWindow/BindingExtensions/SettingsBindingExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Windows.Data;

namespace GoToWindow.BindingExtensions
{
public class SettingBindingExtension : Binding
{
public SettingBindingExtension()
{
Initialize();
}

public SettingBindingExtension(string path)
: base(path)
{
Initialize();
}

private void Initialize()
{
Source = Properties.Settings.Default;
Mode = BindingMode.TwoWay;
}
}
}
2 changes: 1 addition & 1 deletion GoToWindow/Commands/ExitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows;
using System.Windows.Input;

namespace GoToWindow
namespace GoToWindow.Commands
{
public class ExitCommand : ICommand
{
Expand Down
2 changes: 1 addition & 1 deletion GoToWindow/Commands/OpenMainWindowCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows;
using System.Windows.Input;

namespace GoToWindow
namespace GoToWindow.Commands
{
public class OpenMainWindowCommand : ICommand
{
Expand Down
31 changes: 31 additions & 0 deletions GoToWindow/Commands/ShowSettingsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using GoToWindow.Windows;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace GoToWindow.Commands
{
public class ShowSettingsCommand : ICommand
{
public event EventHandler CanExecuteChanged;

public ShowSettingsCommand()
{
}

public bool CanExecute(object parameter)
{
return true;
}

public void Execute(object parameter)
{
if (Application.Current.Windows.OfType<SettingsWindow>().Count() > 0)
return;

new SettingsWindow().Show();
}
}
}
9 changes: 9 additions & 0 deletions GoToWindow/GoToWindow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="BindingExtensions\SettingsBindingExtension.cs" />
<Compile Include="Commands\ShowSettingsCommand.cs" />
<Compile Include="Converters\ExecutableToIconValueConverter.cs" />
<Compile Include="Commands\ExitCommand.cs" />
<Compile Include="GoToWindowContext.cs" />
<Compile Include="Commands\OpenMainWindowCommand.cs" />
<Compile Include="Controls\WindowListEntry.xaml.cs">
<DependentUpon>WindowListEntry.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\SettingsWindow.xaml.cs">
<DependentUpon>SettingsWindow.xaml</DependentUpon>
</Compile>
<Page Include="Windows\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -85,6 +90,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\SettingsWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
34 changes: 21 additions & 13 deletions GoToWindow/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions GoToWindow/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GoToWindow.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="HookAltTab" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion GoToWindow/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AllowsTransparency="True"
Background="Transparent"
WindowStyle="None"
Icon="..\Resources\AppIcon.ico"
Icon="/GoToWindow;component/Resources/AppIcon.ico"
Topmost="True"
ShowInTaskbar="False"
FocusManager.FocusedElement="{Binding ElementName=searchTextBox}"
Expand Down
14 changes: 14 additions & 0 deletions GoToWindow/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Window x:Class="GoToWindow.Windows.SettingsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gotowindowBindingExtensions="clr-namespace:GoToWindow.BindingExtensions"
Title="Go To Window Settings" Icon="/GoToWindow;component/Resources/AppIcon.ico" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
<Grid Height="140" Width="380">
<CheckBox Content="Hook Alt+Tab" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" IsChecked="{gotowindowBindingExtensions:SettingBinding Path=HookAltTab}"/>
<Button Name="okButton" IsDefault="True" Content="Apply" HorizontalAlignment="Left" Margin="295,110,0,0" VerticalAlignment="Top" Width="75" Click="okButton_Click"/>
<Button Name="cancelButton" IsCancel="True" Content="Cancel" HorizontalAlignment="Left" Margin="215,110,0,0" VerticalAlignment="Top" Width="75" Click="cancelButton_Click"/>
<Label Content="Settings will be applied after Go To Window is restarted" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<Label Content="© Christian Rondeau 2014" HorizontalAlignment="Left" Margin="10,104,0,0" VerticalAlignment="Top" FontStyle="Italic"/>

</Grid>
</Window>
41 changes: 41 additions & 0 deletions GoToWindow/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace GoToWindow.Windows
{
/// <summary>
/// Interaction logic for SettingsWindow.xaml
/// </summary>
public partial class SettingsWindow : Window
{
public SettingsWindow()
{
InitializeComponent();
}

private void okButton_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.Save();

MessageBox.Show("Settings will be applied on restart", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

Close();
}

private void cancelButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

0 comments on commit 4836452

Please sign in to comment.