Skip to content

Commit

Permalink
Fixed missing shortcut keys on mono (#158)
Browse files Browse the repository at this point in the history
This was done cause of a bug in mono:
The constructor which takes an shortcut key, doesn't probably handle
this parameter. see https://github.com/mono/mono/blob/169a842f4e913608b17a1e5f38bcb635063b8dc8/mcs/class/System.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs#L83
  • Loading branch information
dannoe committed May 11, 2020
1 parent 40c11fb commit 5e7b904
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
44 changes: 44 additions & 0 deletions KeeTrayTOTP.Tests/Menu/EntryMenuItemProviderTests.cs
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FluentAssertions;
using KeePass.UI;
using KeePass.Util;
using KeeTrayTOTP.Menu;
using KeeTrayTOTP.Tests.Extensions;
using KeeTrayTOTP.Tests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace KeeTrayTOTP.Tests.Menu
{
[TestClass]
public class EntryMenuItemProviderTests
{
private EntryMenuItemProvider _entryMenuItemProvider;

[TestInitialize]
public void Initialize()
{
var (plugin, host) = PluginHostHelper.CreateAndInitialize();

_entryMenuItemProvider = new EntryMenuItemProvider(plugin, host.Object);
}

[TestMethod]
public void EntryMenuItemProvider_Should_ProvideAllMenuItemsWithCorrectShortcutKeys()
{
var sut = _entryMenuItemProvider.ProvideMenuItem();

sut.DropDownItems.Count.Should().Be(3,
"because, there are exactly three menu items for an entry.");

sut.DropDownItems
.Cast<ToolStripMenuItem>()
.All(menuItem => menuItem.ShortcutKeys != Keys.None)
.Should().BeTrue("because, all entries should have a shortcut key assigned.");
}
}
}
21 changes: 17 additions & 4 deletions KeeTrayTOTP/Menu/EntryMenuItemProvider.cs
Expand Up @@ -23,10 +23,23 @@ public ToolStripMenuItem ProvideMenuItem()
{
var rootEntryMenuItem = new ToolStripMenuItem(Localization.Strings.TrayTOTPPlugin, Properties.Resources.TOTP);

var entryMenuCopyTotp = new ToolStripMenuItem(Localization.Strings.CopyTOTP, Properties.Resources.TOTP, OnEntryMenuTOTPClick, (Keys)Shortcut.CtrlT);
var entryMenuSetupTotp = new ToolStripMenuItem(Localization.Strings.SetupTOTP, Properties.Resources.TOTP_Setup, OnEntryMenuSetupClick, (Keys)Shortcut.CtrlShiftI);
var entryMenuShowQrCode = new ToolStripMenuItem(Localization.Strings.ShowQR, Properties.Resources.TOTP_Setup, OnEntryMenuShowQRClick, (Keys)Shortcut.CtrlShiftJ);

// The ShortCutKeys assignments are required in this form and
// can not be setup as constructor parameters, because an implementation
// in the mono framework is missing.
// see https://github.com/mono/mono/issues/19755
var entryMenuCopyTotp = new ToolStripMenuItem(Localization.Strings.CopyTOTP, Properties.Resources.TOTP, OnEntryMenuTOTPClick)
{
ShortcutKeys = (Keys)Shortcut.CtrlT
};
var entryMenuSetupTotp = new ToolStripMenuItem(Localization.Strings.SetupTOTP, Properties.Resources.TOTP_Setup, OnEntryMenuSetupClick)
{
ShortcutKeys = (Keys)Shortcut.CtrlShiftI
};
var entryMenuShowQrCode = new ToolStripMenuItem(Localization.Strings.ShowQR, Properties.Resources.TOTP_Setup, OnEntryMenuShowQRClick)
{
ShortcutKeys = (Keys)Shortcut.CtrlShiftJ
};

rootEntryMenuItem.DropDownItems.Add(entryMenuCopyTotp);
rootEntryMenuItem.DropDownItems.Add(entryMenuSetupTotp);
rootEntryMenuItem.DropDownItems.Add(entryMenuShowQrCode);
Expand Down

0 comments on commit 5e7b904

Please sign in to comment.