Skip to content

Commit

Permalink
Fixing Request mitchcapper#1. Now remembers latest position.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Persson authored and Alexander Persson committed Dec 29, 2017
1 parent 51e2b82 commit 4664b3e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ClassKPFloatingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 24 additions & 5 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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)
{

}
}

}
11 changes: 9 additions & 2 deletions OptionsClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4664b3e

Please sign in to comment.