diff --git a/ShareX.HelpersLib/Automate/AutomateForm.Designer.cs b/ShareX.HelpersLib/Automate/AutomateForm.Designer.cs index 747f68ed2..363945c0e 100644 --- a/ShareX.HelpersLib/Automate/AutomateForm.Designer.cs +++ b/ShareX.HelpersLib/Automate/AutomateForm.Designer.cs @@ -50,6 +50,7 @@ private void InitializeComponent() // // btnRun // + this.btnRun.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); this.btnRun.Location = new System.Drawing.Point(9, 9); this.btnRun.Name = "btnRun"; this.btnRun.Size = new System.Drawing.Size(120, 63); diff --git a/ShareX.HelpersLib/Automate/AutomateForm.cs b/ShareX.HelpersLib/Automate/AutomateForm.cs index 1b39d9f08..5a29f9b78 100644 --- a/ShareX.HelpersLib/Automate/AutomateForm.cs +++ b/ShareX.HelpersLib/Automate/AutomateForm.cs @@ -36,13 +36,16 @@ namespace ShareX.HelpersLib { public partial class AutomateForm : Form { + private static AutomateForm instance; + + public static bool IsRunning { get; private set; } + public List Scripts { get; private set; } - public bool IsWorking { get; private set; } private FunctionManager functionManager = new FunctionManager(); private Tokenizer tokenizer = new Tokenizer(); - public AutomateForm(List scripts) + private AutomateForm(List scripts) { InitializeComponent(); Icon = ShareXResources.Icon; @@ -64,6 +67,16 @@ public AutomateForm(List scripts) } } + public static AutomateForm GetInstance(List scripts) + { + if (instance == null || instance.IsDisposed) + { + instance = new AutomateForm(scripts); + } + + return instance; + } + private void AddScript(ScriptInfo scriptInfo) { lvScripts.Items.Add(scriptInfo.Name).Tag = scriptInfo; @@ -126,9 +139,9 @@ private void SyntaxHighlighting(List tokens) private void Start() { - if (!IsWorking) + if (!IsRunning) { - IsWorking = true; + IsRunning = true; btnRun.Text = Resources.Stop; string[] lines = rtbInput.Lines; functionManager.LineDelay = (int)nudLineDelay.Value; @@ -139,13 +152,13 @@ private void Start() } } - private void Stop() + public void Stop() { - if (IsWorking) + if (IsRunning) { functionManager.Stop(); btnRun.Text = Resources.Start; - IsWorking = false; + IsRunning = false; } } @@ -153,7 +166,7 @@ private void btnRun_Click(object sender, EventArgs e) { lock (this) { - if (IsWorking) + if (IsRunning) { Stop(); } @@ -171,7 +184,7 @@ private void bw_DoWork(object sender, DoWorkEventArgs e) try { functionManager.Compile(lines); - functionManager.Run(); + functionManager.Start(); } catch (Exception ex) { @@ -273,7 +286,7 @@ private void btnAddMouseMove_Click(object sender, EventArgs e) { Thread thread = new Thread(() => { - Thread.Sleep(1000); + Thread.Sleep(2000); Point position = Cursor.Position; this.InvokeSafe(() => { diff --git a/ShareX.HelpersLib/Automate/FunctionManager.cs b/ShareX.HelpersLib/Automate/FunctionManager.cs index 252c3bbb8..626ae9695 100644 --- a/ShareX.HelpersLib/Automate/FunctionManager.cs +++ b/ShareX.HelpersLib/Automate/FunctionManager.cs @@ -133,12 +133,21 @@ public bool Compile(string[] lines) return true; } - public void Run(int startIndex = 0) + public void Start() + { + stopRequest = false; + Run(0); + } + + public void Stop() + { + stopRequest = true; + } + + public void Run(int startIndex) { if (FunctionList != null) { - stopRequest = false; - Function function; for (int i = startIndex; i < FunctionList.Count && !stopRequest; i++) @@ -159,10 +168,5 @@ public void Run(int startIndex = 0) } } } - - public void Stop() - { - stopRequest = true; - } } } \ No newline at end of file diff --git a/ShareX.HelpersLib/Properties/Resources.Designer.cs b/ShareX.HelpersLib/Properties/Resources.Designer.cs index bc16e5632..4962a3742 100644 --- a/ShareX.HelpersLib/Properties/Resources.Designer.cs +++ b/ShareX.HelpersLib/Properties/Resources.Designer.cs @@ -708,6 +708,15 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to Open/Stop Automate tool. + /// + internal static string HotkeyType_Automate { + get { + return ResourceManager.GetString("HotkeyType_Automate", resourceCulture); + } + } + /// /// Looks up a localized string similar to Upload from clipboard. /// diff --git a/ShareX.HelpersLib/Properties/Resources.resx b/ShareX.HelpersLib/Properties/Resources.resx index f8ca46ec4..f9cff0f1e 100644 --- a/ShareX.HelpersLib/Properties/Resources.resx +++ b/ShareX.HelpersLib/Properties/Resources.resx @@ -628,4 +628,7 @@ Would you like to download and install it? Start screen recording (GIF) using last region + + Open/Stop Automate tool + \ No newline at end of file diff --git a/ShareX/Enums.cs b/ShareX/Enums.cs index fdfd4a18e..38787e06e 100644 --- a/ShareX/Enums.cs +++ b/ShareX/Enums.cs @@ -162,7 +162,8 @@ public enum HotkeyType // Localized IndexFolder, ImageEffects, QRCode, - TweetMessage + TweetMessage, + Automate } public enum HotkeyStatus diff --git a/ShareX/Forms/AutoCaptureForm.cs b/ShareX/Forms/AutoCaptureForm.cs index 8647b29ce..ebd7a42c5 100644 --- a/ShareX/Forms/AutoCaptureForm.cs +++ b/ShareX/Forms/AutoCaptureForm.cs @@ -35,8 +35,6 @@ namespace ShareX { public partial class AutoCaptureForm : Form { - public static bool IsRunning { get; private set; } - private static AutoCaptureForm instance; public static AutoCaptureForm Instance @@ -52,6 +50,8 @@ public static AutoCaptureForm Instance } } + public static bool IsRunning { get; private set; } + private bool isLoaded; private Timer statusTimer; private System.Timers.Timer screenshotTimer; diff --git a/ShareX/Forms/MainForm.Designer.cs b/ShareX/Forms/MainForm.Designer.cs index af591b3dc..1a3e217cd 100644 --- a/ShareX/Forms/MainForm.Designer.cs +++ b/ShareX/Forms/MainForm.Designer.cs @@ -77,11 +77,11 @@ private void InitializeComponent() this.tsmiDNSChanger = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiQRCode = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiRuler = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiAutomate = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiIndexFolder = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiFTPClient = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTweetMessage = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiMonitorTest = new System.Windows.Forms.ToolStripMenuItem(); - this.tsmiAutomate = new System.Windows.Forms.ToolStripMenuItem(); this.tssMain1 = new System.Windows.Forms.ToolStripSeparator(); this.tsddbAfterCaptureTasks = new System.Windows.Forms.ToolStripDropDownButton(); this.tsddbAfterUploadTasks = new System.Windows.Forms.ToolStripDropDownButton(); @@ -224,6 +224,7 @@ private void InitializeComponent() this.tssTray3 = new System.Windows.Forms.ToolStripSeparator(); this.tsmiTrayShow = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayExit = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiTrayAutomate = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit(); this.scMain.Panel1.SuspendLayout(); this.scMain.Panel2.SuspendLayout(); @@ -628,6 +629,13 @@ private void InitializeComponent() resources.ApplyResources(this.tsmiRuler, "tsmiRuler"); this.tsmiRuler.Click += new System.EventHandler(this.tsmiRuler_Click); // + // tsmiAutomate + // + this.tsmiAutomate.Image = global::ShareX.Properties.Resources.robot; + this.tsmiAutomate.Name = "tsmiAutomate"; + resources.ApplyResources(this.tsmiAutomate, "tsmiAutomate"); + this.tsmiAutomate.Click += new System.EventHandler(this.tsmiAutomate_Click); + // // tsmiIndexFolder // this.tsmiIndexFolder.Image = global::ShareX.Properties.Resources.folder_tree; @@ -656,13 +664,6 @@ private void InitializeComponent() resources.ApplyResources(this.tsmiMonitorTest, "tsmiMonitorTest"); this.tsmiMonitorTest.Click += new System.EventHandler(this.tsmiMonitorTest_Click); // - // tsmiAutomate - // - this.tsmiAutomate.Image = global::ShareX.Properties.Resources.robot; - this.tsmiAutomate.Name = "tsmiAutomate"; - resources.ApplyResources(this.tsmiAutomate, "tsmiAutomate"); - this.tsmiAutomate.Click += new System.EventHandler(this.tsmiAutomate_Click); - // // tssMain1 // this.tssMain1.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); @@ -1460,6 +1461,7 @@ private void InitializeComponent() this.tsmiTrayDNSChanger, this.tsmiTrayQRCode, this.tsmiTrayRuler, + this.tsmiTrayAutomate, this.tsmiTrayIndexFolder, this.tsmiTrayFTPClient, this.tsmiTrayTweetMessage, @@ -1712,6 +1714,13 @@ private void InitializeComponent() resources.ApplyResources(this.tsmiTrayExit, "tsmiTrayExit"); this.tsmiTrayExit.Click += new System.EventHandler(this.tsmiTrayExit_Click); // + // tsmiTrayAutomate + // + this.tsmiTrayAutomate.Image = global::ShareX.Properties.Resources.robot; + this.tsmiTrayAutomate.Name = "tsmiTrayAutomate"; + resources.ApplyResources(this.tsmiTrayAutomate, "tsmiTrayAutomate"); + this.tsmiTrayAutomate.Click += new System.EventHandler(this.tsmiAutomate_Click); + // // MainForm // this.AllowDrop = true; @@ -1937,5 +1946,6 @@ private void InitializeComponent() public System.Windows.Forms.ToolStripMenuItem tsmiTrayRecentItems; private System.Windows.Forms.ContextMenuStrip cmsTray; private System.Windows.Forms.ToolStripMenuItem tsmiAutomate; + private System.Windows.Forms.ToolStripMenuItem tsmiTrayAutomate; } } \ No newline at end of file diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 41b170836..01d87489e 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -902,7 +902,7 @@ private void tsmiRuler_Click(object sender, EventArgs e) private void tsmiAutomate_Click(object sender, EventArgs e) { - TaskHelpers.OpenAutomate(); + TaskHelpers.OpenStopAutomate(); } private void tsmiIndexFolder_Click(object sender, EventArgs e) @@ -1583,6 +1583,9 @@ private void ExecuteJob(TaskSettings taskSettings, HotkeyType job) case HotkeyType.TweetMessage: TaskHelpers.TweetMessage(); break; + case HotkeyType.Automate: + TaskHelpers.OpenStopAutomate(); + break; } } diff --git a/ShareX/Forms/MainForm.resx b/ShareX/Forms/MainForm.resx index 01be02d2d..1b6b31e10 100644 --- a/ShareX/Forms/MainForm.resx +++ b/ShareX/Forms/MainForm.resx @@ -180,6 +180,45 @@ 1 + + Filename + + + 150 + + + Status + + + Progress + + + 125 + + + Speed + + + 75 + + + Elapsed + + + 45 + + + Remaining + + + 45 + + + URL + + + 145 + Fill @@ -276,45 +315,6 @@ 2 - - Filename - - - 150 - - - Status - - - Progress - - - 125 - - - Speed - - - 75 - - - Elapsed - - - 45 - - - Remaining - - - 45 - - - URL - - - 145 - 17, 17 @@ -324,6 +324,108 @@ Left + + 217, 22 + + + Fullscreen + + + 217, 22 + + + Window + + + 217, 22 + + + Monitor + + + 217, 22 + + + Rectangle + + + 217, 22 + + + Rectangle (Objects) + + + 217, 22 + + + Rectangle (Annotate) + + + 217, 22 + + + Rectangle (Light) + + + 217, 22 + + + Rounded rectangle + + + 217, 22 + + + Ellipse + + + 217, 22 + + + Triangle + + + 217, 22 + + + Diamond + + + 217, 22 + + + Polygon + + + 217, 22 + + + Freehand + + + 217, 22 + + + Last region + + + 217, 22 + + + Screen recording (FFmpeg) + + + 217, 22 + + + Screen recording (GIF) + + + 217, 22 + + + Auto capture... + MiddleLeft @@ -336,6 +438,36 @@ Capture + + 203, 22 + + + Upload file... + + + 203, 22 + + + Upload folder... + + + 203, 22 + + + Upload from clipboard... + + + 203, 22 + + + Upload from URL... + + + 203, 22 + + + Drag and drop upload... + MiddleLeft @@ -477,6 +609,45 @@ After upload tasks + + 187, 22 + + + Image uploaders + + + 187, 22 + + + Text uploaders + + + 187, 22 + + + File uploaders + + + 187, 22 + + + URL shorteners + + + 187, 22 + + + URL sharing services + + + 184, 6 + + + 187, 22 + + + Destination settings... + MiddleLeft @@ -564,6 +735,42 @@ Image history... + + 173, 22 + + + Debug log... + + + 173, 22 + + + Test image upload + + + 173, 22 + + + Test text upload + + + 173, 22 + + + Test file upload + + + 173, 22 + + + Test URL shortener + + + 173, 22 + + + Test URL sharing + MiddleLeft @@ -624,225 +831,9 @@ 3 - - 217, 22 - - - Fullscreen - - - 217, 22 - - - Window - - - 217, 22 - - - Monitor - - - 217, 22 - - - Rectangle - - - 217, 22 - - - Rectangle (Objects) - - - 217, 22 - - - Rectangle (Annotate) - - - 217, 22 - - - Rectangle (Light) - - - 217, 22 - - - Rounded rectangle - - - 217, 22 - - - Ellipse - - - 217, 22 - - - Triangle - - - 217, 22 - - - Diamond - - - 217, 22 - - - Polygon - - - 217, 22 - - - Freehand - - - 217, 22 - - - Last region - - - 217, 22 - - - Screen recording (FFmpeg) - - - 217, 22 - - - Screen recording (GIF) - - - 217, 22 - - - Auto capture... - - - 203, 22 - - - Upload file... - - - 203, 22 - - - Upload folder... - - - 203, 22 - - - Upload from clipboard... - - - 203, 22 - - - Upload from URL... - - - 203, 22 - - - Drag and drop upload... - - - 187, 22 - - - Image uploaders - - - 187, 22 - - - Text uploaders - - - 187, 22 - - - File uploaders - - - 187, 22 - - - URL shorteners - - - 187, 22 - - - URL sharing services - - - 184, 6 - - - 187, 22 - - - Destination settings... - - - 173, 22 - - - Debug log... - - - 173, 22 - - - Test image upload - - - 173, 22 - - - Test text upload - - - 173, 22 - - - Test file upload - - - 173, 22 - - - Test URL shortener - - - 173, 22 - - - Test URL sharing - 286, 17 - - 173, 318 - - - cmsTaskInfo - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 172, 22 @@ -855,12 +846,6 @@ Stop upload - - 172, 22 - - - Open - 156, 22 @@ -906,11 +891,11 @@ Thumbnail file - + 172, 22 - - Copy + + Open 233, 22 @@ -1044,6 +1029,12 @@ False + + 172, 22 + + + Copy + 172, 22 @@ -1101,12 +1092,6 @@ Hide menu - - 172, 22 - - - Image preview - 130, 22 @@ -1125,30 +1110,27 @@ Automatic + + 172, 22 + + + Image preview + + + 173, 318 + + + cmsTaskInfo + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 105, 17 190, 17 - - 189, 418 - - - cmsTray - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ShareX - - - 188, 22 - - - Capture - 217, 22 @@ -1251,11 +1233,11 @@ Auto capture... - + 188, 22 - - Upload + + Capture 203, 22 @@ -1287,18 +1269,18 @@ Drag and drop upload... + + 188, 22 + + + Upload + 188, 22 Workflows - - 188, 22 - - - Tools - 183, 22 @@ -1347,6 +1329,12 @@ Ruler... + + 183, 22 + + + Automate... + 183, 22 @@ -1371,6 +1359,12 @@ Monitor test... + + 188, 22 + + + Tools + 185, 6 @@ -1386,12 +1380,6 @@ After upload - - 188, 22 - - - Destinations - 187, 22 @@ -1431,6 +1419,12 @@ Destination settings... + + 188, 22 + + + Destinations + 188, 22 @@ -1506,6 +1500,18 @@ Exit + + 189, 418 + + + cmsTray + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ShareX + True @@ -1773,6 +1779,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsmiAutomate + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + tsmiIndexFolder @@ -1797,12 +1809,6 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsmiAutomate - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tssMain1 @@ -2643,6 +2649,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsmiTrayAutomate + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainForm diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 6a968f647..8e1a716fa 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -546,14 +546,20 @@ public static void OpenRuler() } } - public static void OpenAutomate() + public static void OpenStopAutomate() { if (Program.Settings.AutomateScripts == null) { Program.Settings.AutomateScripts = new List(); } - new AutomateForm(Program.Settings.AutomateScripts).Show(); + AutomateForm form = AutomateForm.GetInstance(Program.Settings.AutomateScripts); + form.ShowActivate(); + + if (AutomateForm.IsRunning) + { + form.Stop(); + } } public static void OpenHashCheck()