Skip to content

Commit

Permalink
implemented hotkey for cycling EVE clients
Browse files Browse the repository at this point in the history
  • Loading branch information
IwalkAlone committed Oct 11, 2020
1 parent bc06d9a commit 28b69da
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bin/
obj/
*.suo
*.user
*.DotSettings
*.DotSettings
packages/
30 changes: 30 additions & 0 deletions Eve-O-Preview/Services/Implementation/ThumbnailManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;
using EveOPreview.Configuration;
using EveOPreview.Mediator.Messages;
Expand Down Expand Up @@ -114,6 +116,7 @@ private async void UpdateThumbnailsList()
view.ThumbnailFocused = this.ThumbnailViewFocused;
view.ThumbnailLostFocus = this.ThumbnailViewLostFocus;
view.ThumbnailActivated = this.ThumbnailActivated;
view.NextThumbnailActivated = this.NextThumbnailActivated;
view.ThumbnailDeactivated = this.ThumbnailDeactivated;

view.RegisterHotkey(this._configuration.GetClientHotkey(view.Title));
Expand Down Expand Up @@ -410,6 +413,33 @@ private void ThumbnailActivated(IntPtr id)
}, TaskScheduler.FromCurrentSynchronizationContext());
}

private void NextThumbnailActivated()
{
if (this._activeClient.Handle == IntPtr.Zero || this._thumbnailViews.Count == 0)
{
return;
}

IThumbnailView currentView = this._thumbnailViews[this._activeClient.Handle];
var sortedViews = this._thumbnailViews.OrderBy(view => view.Key.ToInt32()).Select(view => view.Value).ToList();
var nextView = sortedViews.SkipWhile(view => view.Id != currentView.Id).Skip(1).DefaultIfEmpty(sortedViews[0]).FirstOrDefault();

if (nextView != null)
{
Task.Run(() =>
{
this._windowManager.ActivateWindow(nextView.Id);
})
.ContinueWith((task) =>
{
// This code should be executed on UI thread
this.SwitchActiveClient(nextView.Id, nextView.Title);
this.UpdateClientLayouts();
this.RefreshThumbnails();
}, TaskScheduler.FromCurrentSynchronizationContext());
}
}

private void ThumbnailDeactivated(IntPtr id, bool switchOut)
{
if (switchOut)
Expand Down
25 changes: 25 additions & 0 deletions Eve-O-Preview/View/Implementation/ThumbnailView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract partial class ThumbnailView : Form, IThumbnailView
private Size _baseZoomMaximumSize;

private HotkeyHandler _hotkeyHandler;
private HotkeyHandler _nextHotkeyHandler;
#endregion

protected ThumbnailView(IWindowManager windowManager)
Expand Down Expand Up @@ -115,6 +116,8 @@ public Size ThumbnailSize

public Action<IntPtr> ThumbnailActivated { get; set; }

public Action NextThumbnailActivated { get; set; }

public Action<IntPtr, bool> ThumbnailDeactivated { get; set; }

public new void Show()
Expand Down Expand Up @@ -317,6 +320,10 @@ public void RegisterHotkey(Keys hotkey)
this._hotkeyHandler = new HotkeyHandler(this.Handle, hotkey);
this._hotkeyHandler.Pressed += HotkeyPressed_Handler;
this._hotkeyHandler.Register();

this._nextHotkeyHandler = new HotkeyHandler(this.Handle, Keys.Tab);
this._nextHotkeyHandler.Pressed += NextHotkeyPressed_Handler;
this._nextHotkeyHandler.Register();
}

public void UnregisterHotkey()
Expand All @@ -330,6 +337,11 @@ public void UnregisterHotkey()
this._hotkeyHandler.Pressed -= HotkeyPressed_Handler;
this._hotkeyHandler.Dispose();
this._hotkeyHandler = null;

this._nextHotkeyHandler.Unregister();
this._nextHotkeyHandler.Pressed -= NextHotkeyPressed_Handler;
this._nextHotkeyHandler.Dispose();
this._nextHotkeyHandler = null;
}

public void Refresh(bool forceRefresh)
Expand Down Expand Up @@ -499,10 +511,23 @@ private void MouseUp_Handler(object sender, MouseEventArgs e)

private void HotkeyPressed_Handler(object sender, HandledEventArgs e)
{
Console.WriteLine("HotkeyPressedHandler");

this.ThumbnailActivated?.Invoke(this.Id);

e.Handled = true;
}

private void NextHotkeyPressed_Handler(object sender, HandledEventArgs e)
{
Console.WriteLine("NextHotkeyPressedHandler");
Console.WriteLine(this.Title);

this.NextThumbnailActivated?.Invoke();

e.Handled = true;
}

#endregion

#region Custom Mouse mode
Expand Down
1 change: 1 addition & 0 deletions Eve-O-Preview/View/Interface/IThumbnailView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface IThumbnailView : IView
Action<IntPtr> ThumbnailLostFocus { get; set; }

Action<IntPtr> ThumbnailActivated { get; set; }
Action NextThumbnailActivated { get; set; }
Action<IntPtr, bool> ThumbnailDeactivated { get; set; }
}
}

0 comments on commit 28b69da

Please sign in to comment.