From 4664b3e675ba74348bbc7baee9659ba6ddda092b Mon Sep 17 00:00:00 2001 From: Alexander Persson Date: Fri, 29 Dec 2017 11:19:47 +0100 Subject: [PATCH] Fixing Request #1. Now remembers latest position. --- ClassKPFloatingPanel.cs | 4 ++-- MainForm.cs | 29 ++++++++++++++++++++++++----- OptionsClass.cs | 11 +++++++++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/ClassKPFloatingPanel.cs b/ClassKPFloatingPanel.cs index 993af56..9bbec74 100644 --- a/ClassKPFloatingPanel.cs +++ b/ClassKPFloatingPanel.cs @@ -18,7 +18,7 @@ internal sealed class KPFloatingPanelExt : Plugin { private void InitForm() { FForm = new MainForm(); FForm.Host = FHost; - FForm.ResetPosition(); + FForm.RestorePosition(); FForm.Show(); } public override string UpdateUrl { @@ -76,7 +76,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) diff --git a/MainForm.cs b/MainForm.cs index 525dd02..59c828c 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -133,12 +133,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) { @@ -216,6 +227,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(); } } @@ -839,6 +853,11 @@ protected override CreateParams CreateParams//allow us to be borderless and not return cp; } } + + private void MainForm_Load(object sender, EventArgs e) + { + + } } } diff --git a/OptionsClass.cs b/OptionsClass.cs index e32e766..48c053a 100644 --- a/OptionsClass.cs +++ b/OptionsClass.cs @@ -14,7 +14,9 @@ public class OptionsClass { internal bool showSearch; internal bool showLastOne; internal bool foldersFirst; - internal string startGroupUUID; + internal int lastPositionX; + internal int lastPositionY; + internal string startGroupUUID; internal string shortcutKey; internal bool shortcutShift; internal bool shortcutAlt; @@ -46,6 +48,8 @@ public void Load() { showSearch = Convert.ToBoolean((string)Key.GetValue("ShowSearch")); showLastOne = Convert.ToBoolean((string)Key.GetValue("ShowLastOne")); foldersFirst = Convert.ToBoolean((string)Key.GetValue("foldersFirst")); + lastPositionX = (int)Key.GetValue("lastPositionX", (int)lastPositionX); + lastPositionY = (int)Key.GetValue("lastPositionY", (int)lastPositionY); shortcutShift = Convert.ToBoolean((string)Key.GetValue("shortcutShift")); shortcutAlt = Convert.ToBoolean((string)Key.GetValue("shortcutAlt")); @@ -80,7 +84,10 @@ public void Save() { Key.SetValue("ShowSearch", showSearch); //s² Key.SetValue("ShowLastOne", showLastOne); //s² Key.SetValue("foldersFirst", foldersFirst); //s² - Key.SetValue("startGroupUUID", startGroupUUID); + Key.SetValue("lastPositionX", (int)lastPositionX); + Key.SetValue("lastPositionY", (int)lastPositionY); + + Key.SetValue("startGroupUUID", startGroupUUID); Key.SetValue("shortcutKey", shortcutKey); Key.SetValue("shortcutAlt", shortcutAlt); Key.SetValue("shortcutShift", shortcutShift);