Skip to content

Commit

Permalink
(Un)register windows at the global windows manager of keepass
Browse files Browse the repository at this point in the history
  • Loading branch information
dannoe committed Apr 6, 2020
1 parent 813e54a commit 46b5f4c
Show file tree
Hide file tree
Showing 13 changed files with 813 additions and 768 deletions.
236 changes: 118 additions & 118 deletions KeeTrayTOTP.Tests/TrayContextMenuPositionTests.cs
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
using System.Collections.Generic;
using System.Drawing;
using KeeTrayTOTP.Libraries;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace KeeTrayTOTP.Tests
{
[TestClass]
public class TrayContextMenuPositionTests
{
[DataTestMethod]
[DynamicData(nameof(DropDownLocationTestData))]
public void CalculatedLocationForDropDown_Should_ReturnTheCorrectLocation(Size controlSize, Point mousePosition,
Rectangle screenRect, Point expectedPoint)
{
var dropDownLocationCalculator = new DropDownLocationCalculator(controlSize);
var sut = dropDownLocationCalculator.CalculateLocationForDropDown(mousePosition, screenRect);

Assert.AreEqual(expectedPoint, sut);
}

private static IEnumerable<object[]> DropDownLocationTestData
{
get
{
var controlSize = new Size(300, 300);
var screenRect = new Rectangle(0, 0, 1920, 1080);

// top-left
yield return new object[]
{
controlSize, new Point(400, 500), screenRect,
// expected
new Point(400 - controlSize.Width, 500 - controlSize.Height)
};

// top-right
yield return new object[]
{
controlSize, new Point(200, 500), screenRect,
// expected
new Point(200, 500 - controlSize.Height)
};

// bottom-right
yield return new object[]
{
controlSize, new Point(200, 200), screenRect,
// expected
new Point(200, 200)
};

// bottom-left
yield return new object[]
{
controlSize, new Point(400, 200), screenRect,
// expected
new Point(400 - controlSize.Width, 200)
};

// top-left
yield return new object[]
{
controlSize, new Point(300, 300), screenRect,
// expected
new Point(0, 0)
};

// top-left
yield return new object[]
{
controlSize, new Point(screenRect.Width, screenRect.Height), screenRect,
// expected
new Point(screenRect.Width - controlSize.Width, screenRect.Height - controlSize.Height)
};

// edge case control size bigger than screen size
yield return new object[]
{
controlSize, new Point(0, 0), new Rectangle(0, 0, 200, 200),
// expected
new Point(0, 200 - controlSize.Height)
};

// edge case control height bigger than screen height
yield return new object[]
{
controlSize, new Point(50, 0), new Rectangle(0, 0, 1920, 200),
// expected
new Point(50, 200 - controlSize.Height)
};

// edge case control width bigger than screen width
yield return new object[]
{
controlSize, new Point(0, 0), new Rectangle(0, 0, 200, 1080),
// expected
new Point(0, 0)
};

// multi monitor test
yield return new object[]
{
controlSize, new Point(2500, 500), screenRect,
// expected
new Point(2500 - controlSize.Width, 500 - controlSize.Height)
};

// multi monitor test control bigger than screen
yield return new object[]
{
controlSize, new Point(1200, 150), new Rectangle(1080, 0, 200, 200),
// expected
new Point(1080, 200 - controlSize.Height)
};
}
}
}
using System.Collections.Generic;
using System.Drawing;
using KeeTrayTOTP.Libraries;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace KeeTrayTOTP.Tests
{
[TestClass]
public class TrayContextMenuPositionTests
{
[DataTestMethod]
[DynamicData(nameof(DropDownLocationTestData))]
public void CalculatedLocationForDropDown_Should_ReturnTheCorrectLocation(Size controlSize, Point mousePosition,
Rectangle screenRect, Point expectedPoint)
{
var dropDownLocationCalculator = new DropDownLocationCalculator(controlSize);
var sut = dropDownLocationCalculator.CalculateLocationForDropDown(mousePosition, screenRect);

Assert.AreEqual(expectedPoint, sut);
}

private static IEnumerable<object[]> DropDownLocationTestData
{
get
{
var controlSize = new Size(300, 300);
var screenRect = new Rectangle(0, 0, 1920, 1080);

// top-left
yield return new object[]
{
controlSize, new Point(400, 500), screenRect,
// expected
new Point(400 - controlSize.Width, 500 - controlSize.Height)
};

// top-right
yield return new object[]
{
controlSize, new Point(200, 500), screenRect,
// expected
new Point(200, 500 - controlSize.Height)
};

// bottom-right
yield return new object[]
{
controlSize, new Point(200, 200), screenRect,
// expected
new Point(200, 200)
};

// bottom-left
yield return new object[]
{
controlSize, new Point(400, 200), screenRect,
// expected
new Point(400 - controlSize.Width, 200)
};

// top-left
yield return new object[]
{
controlSize, new Point(300, 300), screenRect,
// expected
new Point(0, 0)
};

// top-left
yield return new object[]
{
controlSize, new Point(screenRect.Width, screenRect.Height), screenRect,
// expected
new Point(screenRect.Width - controlSize.Width, screenRect.Height - controlSize.Height)
};

// edge case control size bigger than screen size
yield return new object[]
{
controlSize, new Point(0, 0), new Rectangle(0, 0, 200, 200),
// expected
new Point(0, 200 - controlSize.Height)
};

// edge case control height bigger than screen height
yield return new object[]
{
controlSize, new Point(50, 0), new Rectangle(0, 0, 1920, 200),
// expected
new Point(50, 200 - controlSize.Height)
};

// edge case control width bigger than screen width
yield return new object[]
{
controlSize, new Point(0, 0), new Rectangle(0, 0, 200, 1080),
// expected
new Point(0, 0)
};

// multi monitor test
yield return new object[]
{
controlSize, new Point(2500, 500), screenRect,
// expected
new Point(2500 - controlSize.Width, 500 - controlSize.Height)
};

// multi monitor test control bigger than screen
yield return new object[]
{
controlSize, new Point(1200, 150), new Rectangle(1080, 0, 200, 200),
// expected
new Point(1080, 200 - controlSize.Height)
};
}
}
}
}
1 change: 1 addition & 0 deletions KeeTrayTOTP/FormAbout.Designer.cs

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

8 changes: 8 additions & 0 deletions KeeTrayTOTP/FormAbout.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Windows.Forms;
using KeePass.UI;

namespace KeeTrayTOTP
{
Expand Down Expand Up @@ -32,6 +33,8 @@ internal FormAbout(KeeTrayTOTPExt plugin)
/// <param name="e"></param>
private void FormAbout_Load(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this);

Text = Localization.Strings.About + @" - " + Localization.Strings.TrayTOTPPlugin;
ListViewAbout.Items[0].SubItems.Add(AssemblyTitle);
ListViewAbout.Items[1].SubItems.Add(AssemblyCompany);
Expand Down Expand Up @@ -151,5 +154,10 @@ internal string AssemblyCompany
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}

private void FormAbout_FormClosed(object sender, FormClosedEventArgs e)
{
GlobalWindowManager.RemoveWindow(this);
}
}
}
1 change: 1 addition & 0 deletions KeeTrayTOTP/FormSettings.Designer.cs

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

8 changes: 8 additions & 0 deletions KeeTrayTOTP/FormSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
using KeePass.UI;

namespace KeeTrayTOTP
{
Expand Down Expand Up @@ -43,6 +44,8 @@ internal FormSettings(KeeTrayTOTPExt plugin)
/// <param name="e"></param>
private void FormSettings_Load(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this);

Text = Localization.Strings.Settings + @" - " + Localization.Strings.TrayTOTPPlugin; // Set form's name using constants.
Working(true, true); // Set controls depending on the state of action.
WorkerLoad.RunWorkerAsync(); // Load Settings in form controls.
Expand Down Expand Up @@ -479,5 +482,10 @@ private void WorkerReset_RunWorkerCompleted(object sender, RunWorkerCompletedEve
{
WorkerLoad.RunWorkerAsync("Reset");
}

private void FormSettings_FormClosed(object sender, FormClosedEventArgs e)
{
GlobalWindowManager.RemoveWindow(this);
}
}
}
1 change: 1 addition & 0 deletions KeeTrayTOTP/FormTimeCorrection.Designer.cs

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

8 changes: 8 additions & 0 deletions KeeTrayTOTP/FormTimeCorrection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
using KeePass.UI;
using KeeTrayTOTP.Libraries;

namespace KeeTrayTOTP
Expand Down Expand Up @@ -48,6 +49,8 @@ internal FormTimeCorrection(KeeTrayTOTPExt plugin, string url)
/// <param name="e"></param>
private void FormTimeCorrection_Load(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this);

Text = Localization.Strings.TimeCorrection + @" - " + Localization.Strings.TrayTOTPPlugin; //Sets the form's display text.
if (_plugin.PluginHost.MainWindow.ActiveDatabase.IsOpen)
{
Expand Down Expand Up @@ -200,5 +203,10 @@ private void ButtonCancel_Click(object sender, EventArgs e)
{
//Dialog Result = Cancel
}

private void FormTimeCorrection_FormClosed(object sender, FormClosedEventArgs e)
{
GlobalWindowManager.RemoveWindow(this);
}
}
}

0 comments on commit 46b5f4c

Please sign in to comment.