Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ClassKPFloatingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ internal sealed class KPFloatingPanelExt : Plugin {
private void InitForm() {
FForm = new MainForm();
FForm.Host = FHost;
FForm.ResetPosition();
FForm.RestorePosition();
FForm.Show();


}
public override string UpdateUrl {
get {
Expand All @@ -34,6 +36,7 @@ public override bool Initialize(IPluginHost AHost) {

InitForm();


FMenuItem = new ToolStripMenuItem();
FMenuItem.Text = "Show Floating Panel";
FMenuItem.ToolTipText = "Shows floating panel with passwords in the top-right corner of screen";
Expand Down Expand Up @@ -76,7 +79,7 @@ private void OnShowPanelClick(object sender, EventArgs e) {
FForm.TopMost = false;
FForm.Hide();
FForm.TopMost = true;
FForm.ResetPosition();
FForm.RestorePosition();
FForm.Show();
FForm.BringToFront();
if (FForm.Opacity < 0.2)
Expand Down
360 changes: 184 additions & 176 deletions MainForm.Designer.cs

Large diffs are not rendered by default.

83 changes: 71 additions & 12 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
using KeePassLib.Security;
using KeePassLib.Utility;

using System.Runtime.InteropServices; // for SetWindowsPos
using System.Runtime.InteropServices;
using System.Reflection; // for SetWindowsPos

namespace KPFloatingPanel {
internal partial class MainForm : Form {
Expand All @@ -25,7 +26,8 @@ internal partial class MainForm : Form {
private string FLastName;
private OptionsClass FOptions;
internal IPluginHost Host;

private MethodInfo mSelectEntriesMethod;

private const int SpaceForButtons = 300;
private HotKeyboardHook kb_shortcut;
private HotKeyboardHook kb_shortcut_quick;
Expand All @@ -49,8 +51,12 @@ public MainForm() {
tmClock_Tick(null, null);
ApplyOptions();



Program.Translation.ApplyTo(this);
Program.Translation.ApplyTo("KeePass.Forms.Plugins.PCFloatingPanel.MainForm.MainMenu", pmMainMenu.Items);


}


Expand Down Expand Up @@ -133,12 +139,23 @@ private void ApplyOptions() {
}
TopMost = true;
}
public void RestorePosition()
{
Rectangle R = Screen.GetWorkingArea(Host.MainWindow);
Top = R.Top;
Left = R.Left + R.Width - Width - SpaceForButtons;

public void ResetPosition() {
Rectangle R = Screen.GetWorkingArea(Host.MainWindow);
Top = R.Top;
Left = R.Left + R.Width - Width - SpaceForButtons;
}
if ((FOptions.lastPositionY > 0) && (FOptions.lastPositionY <= R.Height))
{
Top = FOptions.lastPositionY;
}

if ((FOptions.lastPositionX !=0) && (FOptions.lastPositionX <= (R.Left + R.Width - Width - SpaceForButtons)))
{
Left = FOptions.lastPositionX;
}
}

private bool last_show_clock;
private void tmClock_Tick(object sender, EventArgs e) {

Expand Down Expand Up @@ -203,9 +220,12 @@ private void miSetup_Click(object sender, EventArgs e) {
}

private void lbClock_MouseDown(object sender, MouseEventArgs e) {
FOldX = Cursor.Position.X;
FOldY = Cursor.Position.Y;
FMoving = e.Button == MouseButtons.Left ? 1 : 0;
if (FOptions.lockWindowPosition == false)
{
FOldX = Cursor.Position.X;
FOldY = Cursor.Position.Y;
FMoving = e.Button == MouseButtons.Left ? 1 : 0;
}
}


Expand All @@ -216,6 +236,9 @@ private void lbClock_MouseMove(object sender, MouseEventArgs e) {
Location = new Point(Location.X + Cursor.Position.X - FOldX, Location.Y + Cursor.Position.Y - FOldY);
FOldX = Cursor.Position.X;
FOldY = Cursor.Position.Y;
FOptions.lastPositionY = FOldY;
FOptions.lastPositionX = FOldX;
FOptions.Save();
}
}

Expand Down Expand Up @@ -622,6 +645,7 @@ private void miItem_AutoType(object sender, EventArgs e) {

try {
AutoType.PerformIntoPreviousWindow(this, Entry,Host.Database);
SelectEntries(new PwObjectList<PwEntry> { Entry }, true, true);
}
catch (Exception ex) {
MessageService.ShowWarning(ex);
Expand Down Expand Up @@ -671,11 +695,31 @@ private void miItem_OpenURL(object sender, EventArgs e) {
FieldAction(Item, PwDefs.UrlField, FIELD_ACTION.CLIPBOARD_COPY);
else
throw new Exception("Internal error in miItem_OpenURL (FOptions.URLAction)");
SelectEntries(new PwObjectList<PwEntry> { Entry }, true, true);
}

// Copied from AutoTypeShow plugin
private void SelectEntries(PwObjectList<PwEntry> lEntries, bool bDeselectOthers, bool bFocusFirst)
{
if (Host != null)
{
var mainWindowType = Host.MainWindow.GetType();
mSelectEntriesMethod = mainWindowType.GetMethod("SelectEntries", BindingFlags.Instance | BindingFlags.NonPublic);
if (mSelectEntriesMethod != null)
{
mSelectEntriesMethod.Invoke(Host.MainWindow, new object[] { lEntries, bDeselectOthers, bFocusFirst });
}
else
{
System.Diagnostics.Debug.Fail("Could not select the auto-typed entry, method not found");
}
}
}

void miItem_Click(object sender, EventArgs e) {
ToolStripMenuItem Item = (ToolStripMenuItem)sender;
FieldAction(Item, Item.Text, FIELD_ACTION.CLIPBOARD_COPY);

}
private enum FIELD_ACTION { CLIPBOARD_COPY, DRAG_DROP };
private void FieldAction(ToolStripMenuItem Item, string FieldName, FIELD_ACTION action) {
Expand All @@ -691,13 +735,15 @@ private void FieldAction(ToolStripMenuItem Item, string FieldName, FIELD_ACTION
Entry.Expires = true;
Host.MainWindow.RefreshEntriesList();
Host.MainWindow.UpdateUI(false, null, false, null, false, null, true);

}

if (action == FIELD_ACTION.CLIPBOARD_COPY) {
ClipboardUtil.CopyAndMinimize(Entry.Strings.GetSafe(FieldName),
true, Program.Config.MainWindow.MinimizeAfterClipboardCopy ?
Host.MainWindow : null, Entry, Host.MainWindow.DocumentManager.ActiveDatabase);
Host.MainWindow.StartClipboardCountdown();
SelectEntries(new PwObjectList<PwEntry> { Entry }, true, true);
}
else if (action == FIELD_ACTION.DRAG_DROP)
Item.DoDragDrop(Entry.Strings.ReadSafe(FieldName), DragDropEffects.Copy);
Expand All @@ -715,7 +761,9 @@ private void miItem_Edit(object sender, EventArgs e) {

if ((myForm.ShowDialog() == DialogResult.OK))
Host.MainWindow.UpdateUI(false, null, Host.MainWindow.DocumentManager.ActiveDatabase.UINeedsIconUpdate, null, true, null, true);
Host.MainWindow.RefreshEntriesList();
SelectEntries(new PwObjectList<PwEntry> { Entry }, true, true);
Host.MainWindow.RefreshEntriesList();

}


Expand Down Expand Up @@ -839,6 +887,17 @@ protected override CreateParams CreateParams//allow us to be borderless and not
return cp;
}
}

private void MainForm_Load(object sender, EventArgs e)
{

}

private void openKeepassToolStripMenuItem_Click(object sender, EventArgs e)
{
KeePass.Program.MainForm.EnsureVisibleForegroundWindow(true,true);

}
}

}
}
Loading