Save simple actions form position, option to run it at startup

This commit is contained in:
Jaex 2017-01-01 02:07:58 +03:00
parent 66880fd71a
commit 6ff0d09957
4 changed files with 49 additions and 9 deletions

View file

@ -84,6 +84,11 @@ public static Rectangle GetActiveScreenBounds()
return Screen.FromPoint(GetCursorPosition()).Bounds;
}
public static Rectangle GetActiveScreenWorkingArea()
{
return Screen.FromPoint(GetCursorPosition()).WorkingArea;
}
public static Rectangle GetPrimaryScreenBounds()
{
return Screen.PrimaryScreen.Bounds;

View file

@ -272,10 +272,12 @@ public ApplicationConfig()
#region Simple actions form
public bool SimpleActionsFormRunAtStartup = true;
public List<HotkeyType> SimpleActionsList = new List<HotkeyType>() { HotkeyType.RectangleRegion, HotkeyType.PrintScreen, HotkeyType.LastRegion,
HotkeyType.None, HotkeyType.FileUpload, HotkeyType.ClipboardUploadWithContentViewer, HotkeyType.None, HotkeyType.ScreenColorPicker };
public Point SimpleActionsFormPosition;
public Point SimpleActionsFormPosition = Point.Empty;
public bool SimpleActionsFormLockPosition = false;

View file

@ -61,8 +61,10 @@ private void MainForm_HandleCreated(object sender, EventArgs e)
UseCommandLineArgs(Program.CLI.Commands);
// TODO: For testing
SimpleActionsForm.Instance.ForceActivate();
if (Program.Settings.SimpleActionsFormRunAtStartup)
{
SimpleActionsForm.Instance.ForceActivate();
}
}
private void InitializeControls()

View file

@ -71,10 +71,11 @@ private void InitializeComponent()
ClientSize = new Size(284, 261);
FormBorderStyle = FormBorderStyle.None;
Icon = ShareXResources.Icon;
StartPosition = FormStartPosition.CenterScreen;
StartPosition = FormStartPosition.Manual;
Text = "ShareX - Simple actions";
TopMost = Program.Settings.SimpleActionsFormStayTopMost;
LocationChanged += SimpleActionsForm_LocationChanged;
Shown += SimpleActionsForm_Shown;
tsMain = new ToolStripEx()
@ -150,6 +151,41 @@ private void InitializeComponent()
ResumeLayout(false);
PerformLayout();
UpdatePosition();
}
private void SimpleActionsForm_LocationChanged(object sender, EventArgs e)
{
Program.Settings.SimpleActionsFormPosition = Location;
}
private void SimpleActionsForm_Shown(object sender, EventArgs e)
{
this.ForceActivate();
}
private void UpdatePosition()
{
Rectangle rectScreen = CaptureHelpers.GetScreenWorkingArea();
if (!Program.Settings.SimpleActionsFormPosition.IsEmpty && rectScreen.Contains(Program.Settings.SimpleActionsFormPosition))
{
Location = Program.Settings.SimpleActionsFormPosition;
}
else
{
Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenWorkingArea();
if (Width < rectActiveScreen.Width)
{
Location = new Point(rectActiveScreen.X + rectActiveScreen.Width - Width, rectActiveScreen.Y + rectActiveScreen.Height - Height);
}
else
{
Location = rectActiveScreen.Location;
}
}
}
private void TsmiClose_Click(object sender, EventArgs e)
@ -282,11 +318,6 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}
private void SimpleActionsForm_Shown(object sender, EventArgs e)
{
this.ForceActivate();
}
private void tsMain_MouseLeave(object sender, EventArgs e)
{
ttMain.RemoveAll();