Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix merge conflict

  • Loading branch information...
commit 978f0bc9807466f0d08d32c9f07efd3e964c904e 2 parents 7c91c80 + 41cf1db
Pavel Karasov authored
8 Client/Client.csproj
@@ -59,6 +59,8 @@
59 59 </Reference>
60 60 <Reference Include="System" />
61 61 <Reference Include="System.Data" />
  62 + <Reference Include="System.Drawing" />
  63 + <Reference Include="System.Windows.Forms" />
62 64 <Reference Include="System.Xml" />
63 65 <Reference Include="Microsoft.CSharp" />
64 66 <Reference Include="System.Core" />
@@ -79,6 +81,7 @@
79 81 <Compile Include="FilterDialog.xaml.cs">
80 82 <DependentUpon>FilterDialog.xaml</DependentUpon>
81 83 </Compile>
  84 + <Compile Include="HotKey.cs" />
82 85 <Compile Include="Options.xaml.cs">
83 86 <DependentUpon>Options.xaml</DependentUpon>
84 87 </Compile>
@@ -155,12 +158,15 @@
155 158 </BootstrapperPackage>
156 159 </ItemGroup>
157 160 <ItemGroup>
158   - <Resource Include="TodoTouch_512.ico" />
  161 + <Resource Include="TodoTouch_512.ico">
  162 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  163 + </Resource>
159 164 </ItemGroup>
160 165 <ItemGroup>
161 166 <EmbeddedResource Include="Resource.resx">
162 167 <Generator>ResXFileCodeGenerator</Generator>
163 168 <LastGenOutput>Resource.Designer.cs</LastGenOutput>
  169 + <SubType>Designer</SubType>
164 170 </EmbeddedResource>
165 171 </ItemGroup>
166 172 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106 Client/HotKey.cs
... ... @@ -0,0 +1,106 @@
  1 +using System;
  2 +using System.Diagnostics.Contracts;
  3 +using System.Runtime.InteropServices;
  4 +using System.Windows;
  5 +using System.Windows.Forms;
  6 +using System.Windows.Input;
  7 +using System.Windows.Interop;
  8 +
  9 +namespace Client
  10 +{
  11 + //Use code from http://www.assembla.com/code/outcoldman_p/subversion/nodes/BlogProjects/WpfApplicationHotKey
  12 + internal class HotKeyWinApi
  13 + {
  14 + public const int WmHotKey = 0x0312;
  15 +
  16 + [DllImport("user32.dll", SetLastError = true)]
  17 + public static extern bool RegisterHotKey(IntPtr hWnd, int id, ModifierKeys fsModifiers, Keys vk);
  18 +
  19 + [DllImport("user32.dll", SetLastError = true)]
  20 + public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  21 + }
  22 +
  23 + public sealed class HotKey : IDisposable
  24 + {
  25 + public event Action<HotKey> HotKeyPressed;
  26 +
  27 + private readonly int _id;
  28 + private bool _isKeyRegistered;
  29 + readonly IntPtr _handle;
  30 +
  31 + public HotKey(ModifierKeys modifierKeys, Keys key, Window window)
  32 + : this(modifierKeys, key, new WindowInteropHelper(window))
  33 + {
  34 + Contract.Requires(window != null);
  35 + }
  36 +
  37 + public HotKey(ModifierKeys modifierKeys, Keys key, WindowInteropHelper window)
  38 + : this(modifierKeys, key, window.Handle)
  39 + {
  40 + Contract.Requires(window != null);
  41 + }
  42 +
  43 + public HotKey(ModifierKeys modifierKeys, Keys key, IntPtr windowHandle)
  44 + {
  45 + Contract.Requires(modifierKeys != ModifierKeys.None || key != Keys.None);
  46 + Contract.Requires(windowHandle != IntPtr.Zero);
  47 +
  48 + Key = key;
  49 + KeyModifier = modifierKeys;
  50 + _id = GetHashCode();
  51 + _handle = windowHandle;
  52 + RegisterHotKey();
  53 + ComponentDispatcher.ThreadPreprocessMessage += ThreadPreprocessMessageMethod;
  54 + }
  55 +
  56 + ~HotKey()
  57 + {
  58 + Dispose();
  59 + }
  60 +
  61 + public Keys Key { get; private set; }
  62 +
  63 + public ModifierKeys KeyModifier { get; private set; }
  64 +
  65 + public void RegisterHotKey()
  66 + {
  67 + if (Key == Keys.None)
  68 + return;
  69 + if (_isKeyRegistered)
  70 + UnregisterHotKey();
  71 + _isKeyRegistered = HotKeyWinApi.RegisterHotKey(_handle, _id, KeyModifier, Key);
  72 + if (!_isKeyRegistered)
  73 + throw new ApplicationException("Hotkey already in use");
  74 + }
  75 +
  76 + public void UnregisterHotKey()
  77 + {
  78 + _isKeyRegistered = !HotKeyWinApi.UnregisterHotKey(_handle, _id);
  79 + }
  80 +
  81 + public void Dispose()
  82 + {
  83 + ComponentDispatcher.ThreadPreprocessMessage -= ThreadPreprocessMessageMethod;
  84 + UnregisterHotKey();
  85 + }
  86 +
  87 + private void ThreadPreprocessMessageMethod(ref MSG msg, ref bool handled)
  88 + {
  89 + if (!handled)
  90 + {
  91 + if (msg.message == HotKeyWinApi.WmHotKey
  92 + && (int)(msg.wParam) == _id)
  93 + {
  94 + OnHotKeyPressed();
  95 + handled = true;
  96 + }
  97 + }
  98 + }
  99 +
  100 + private void OnHotKeyPressed()
  101 + {
  102 + if (HotKeyPressed != null)
  103 + HotKeyPressed(this);
  104 + }
  105 + }
  106 +}
68 Client/MainWindow.xaml.cs
... ... @@ -1,5 +1,6 @@
1 1 using System;
2 2 using System.Collections.Generic;
  3 +using System.Drawing;
3 4 using System.Linq;
4 5 using System.Text;
5 6 using System.Windows;
@@ -60,6 +61,8 @@ enum SortType
60 61 Task _updating;
61 62 int _intelliPos;
62 63 DispatcherTimer _dispatcherTimer;
  64 + System.Windows.Forms.NotifyIcon _notifyIcon;
  65 + HotKey _hotkey;
63 66
64 67 WindowLocation _previousWindowLocaiton;
65 68
@@ -68,6 +71,32 @@ public MainWindow()
68 71 try
69 72 {
70 73 InitializeComponent();
  74 + //add tray icon
  75 + try
  76 + {
  77 + _notifyIcon = new System.Windows.Forms.NotifyIcon();
  78 + _notifyIcon.Text = this.Title;
  79 + _notifyIcon.Icon = new System.Drawing.Icon("TodoTouch_512.ico");
  80 + _notifyIcon.Visible = true;
  81 + _notifyIcon.DoubleClick += (sender, args) => HideUnHideWindow();
  82 + }
  83 + catch (Exception ex)
  84 + {
  85 + var msg = "Error create tray icon";
  86 + Log.Error(msg, ex);
  87 + }
  88 + //add global key
  89 + try
  90 + {
  91 + _hotkey = new HotKey(ModifierKeys.Windows | ModifierKeys.Alt, System.Windows.Forms.Keys.T, this);
  92 + _hotkey.HotKeyPressed += (k) => HideUnHideWindow();
  93 + }
  94 + catch (Exception ex)
  95 + {
  96 + var msg = "Error Global HotKey Registered";
  97 + Log.Error(msg, ex);
  98 + MessageBox.Show(ex.Message, msg, MessageBoxButton.OK);
  99 + }
71 100
72 101 webBrowser1.Navigate("about:blank");
73 102
@@ -103,10 +132,45 @@ public MainWindow()
103 132 ThreadPool.QueueUserWorkItem(x => CheckForUpdates());
104 133 }
105 134
  135 + #region protected methods
106 136
107   - #region private methods
  137 + protected override void OnStateChanged(EventArgs e)
  138 + {
  139 + if (WindowState == WindowState.Minimized)
  140 + this.Hide();
108 141
109   - private void Reload()
  142 + base.OnStateChanged(e);
  143 + }
  144 +
  145 +
  146 +
  147 + #region private methods
  148 +
  149 + private void HideUnHideWindow()
  150 + {
  151 + if (this.WindowState == WindowState.Minimized)
  152 + {
  153 + this.Show();
  154 + this.Topmost = true;
  155 + this.Activate();
  156 + this.WindowState = WindowState.Normal;
  157 + }
  158 + else
  159 + {
  160 + this.WindowState = WindowState.Minimized;
  161 + this.Hide();
  162 + }
  163 + }
  164 +
  165 + private void OnClose(object sender, System.ComponentModel.CancelEventArgs args)
  166 + {
  167 + _notifyIcon.Dispose();
  168 + _notifyIcon = null;
  169 + }
  170 +
  171 + #endregion
  172 +
  173 + private void Reload()
110 174 {
111 175 try
112 176 {
1  ToDoTests/ToDoTests.csproj
@@ -66,6 +66,7 @@
66 66 <EmbeddedResource Include="Data.resx">
67 67 <Generator>ResXFileCodeGenerator</Generator>
68 68 <LastGenOutput>Data.Designer.cs</LastGenOutput>
  69 + <SubType>Designer</SubType>
69 70 </EmbeddedResource>
70 71 </ItemGroup>
71 72 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 comments on commit 978f0bc

Please sign in to comment.
Something went wrong with that request. Please try again.