From c752fecef6971c85d3f4b44413bc55f246f729b1 Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 16 Sep 2021 03:17:07 +0300 Subject: [PATCH] Added remember window title and auto close window settings --- ShareX/BorderlessWindowSettings.cs | 34 +++++ ShareX/Forms/BorderlessWindowForm.Designer.cs | 16 ++- ShareX/Forms/BorderlessWindowForm.cs | 48 +++++-- .../BorderlessWindowSettingsForm.Designer.cs | 81 ++++++++++++ ShareX/Forms/BorderlessWindowSettingsForm.cs | 56 ++++++++ .../Forms/BorderlessWindowSettingsForm.resx | 120 ++++++++++++++++++ ShareX/ShareX.csproj | 10 ++ ShareX/TaskHelpers.cs | 7 +- ShareX/TaskSettings.cs | 1 + 9 files changed, 361 insertions(+), 12 deletions(-) create mode 100644 ShareX/BorderlessWindowSettings.cs create mode 100644 ShareX/Forms/BorderlessWindowSettingsForm.Designer.cs create mode 100644 ShareX/Forms/BorderlessWindowSettingsForm.cs create mode 100644 ShareX/Forms/BorderlessWindowSettingsForm.resx diff --git a/ShareX/BorderlessWindowSettings.cs b/ShareX/BorderlessWindowSettings.cs new file mode 100644 index 000000000..1938cd080 --- /dev/null +++ b/ShareX/BorderlessWindowSettings.cs @@ -0,0 +1,34 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2021 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +namespace ShareX +{ + public class BorderlessWindowSettings + { + public bool RememberWindowTitle { get; set; } = true; + public string WindowTitle { get; set; } + public bool AutoCloseWindow { get; set; } + } +} \ No newline at end of file diff --git a/ShareX/Forms/BorderlessWindowForm.Designer.cs b/ShareX/Forms/BorderlessWindowForm.Designer.cs index 5a908cd99..44555e2ee 100644 --- a/ShareX/Forms/BorderlessWindowForm.Designer.cs +++ b/ShareX/Forms/BorderlessWindowForm.Designer.cs @@ -32,6 +32,7 @@ private void InitializeComponent() this.lblWindowTitle = new System.Windows.Forms.Label(); this.txtWindowTitle = new System.Windows.Forms.TextBox(); this.btnMakeWindowBorderless = new System.Windows.Forms.Button(); + this.btnSettings = new System.Windows.Forms.Button(); this.SuspendLayout(); // // lblWindowTitle @@ -59,17 +60,29 @@ private void InitializeComponent() this.btnMakeWindowBorderless.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnMakeWindowBorderless.Location = new System.Drawing.Point(16, 72); this.btnMakeWindowBorderless.Name = "btnMakeWindowBorderless"; - this.btnMakeWindowBorderless.Size = new System.Drawing.Size(296, 32); + this.btnMakeWindowBorderless.Size = new System.Drawing.Size(256, 32); this.btnMakeWindowBorderless.TabIndex = 2; this.btnMakeWindowBorderless.Text = "Make window borderless"; this.btnMakeWindowBorderless.UseVisualStyleBackColor = true; this.btnMakeWindowBorderless.Click += new System.EventHandler(this.btnMakeWindowBorderless_Click); // + // btnSettings + // + this.btnSettings.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnSettings.Image = global::ShareX.Properties.Resources.gear; + this.btnSettings.Location = new System.Drawing.Point(280, 72); + this.btnSettings.Name = "btnSettings"; + this.btnSettings.Size = new System.Drawing.Size(32, 32); + this.btnSettings.TabIndex = 3; + this.btnSettings.UseVisualStyleBackColor = true; + this.btnSettings.Click += new System.EventHandler(this.btnSettings_Click); + // // BorderlessWindowForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(328, 122); + this.Controls.Add(this.btnSettings); this.Controls.Add(this.btnMakeWindowBorderless); this.Controls.Add(this.txtWindowTitle); this.Controls.Add(this.lblWindowTitle); @@ -90,5 +103,6 @@ private void InitializeComponent() private System.Windows.Forms.Label lblWindowTitle; private System.Windows.Forms.TextBox txtWindowTitle; private System.Windows.Forms.Button btnMakeWindowBorderless; + private System.Windows.Forms.Button btnSettings; } } \ No newline at end of file diff --git a/ShareX/Forms/BorderlessWindowForm.cs b/ShareX/Forms/BorderlessWindowForm.cs index 847b31cdb..d7fcc4cf9 100644 --- a/ShareX/Forms/BorderlessWindowForm.cs +++ b/ShareX/Forms/BorderlessWindowForm.cs @@ -33,15 +33,17 @@ namespace ShareX { public partial class BorderlessWindowForm : Form { - public string DefaultWindowTitle { get; set; } = "minecraft"; + public BorderlessWindowSettings Settings { get; private set; } - public BorderlessWindowForm() + public BorderlessWindowForm(BorderlessWindowSettings settings) { InitializeComponent(); ShareXResources.ApplyTheme(this); + + Settings = settings; } - private void MakeWindowBorderless(string windowTitle) + private bool MakeWindowBorderless(string windowTitle) { if (!string.IsNullOrEmpty(windowTitle)) { @@ -51,11 +53,15 @@ private void MakeWindowBorderless(string windowTitle) { // TODO: Translate MessageBox.Show("Unable to find a window with specified window title.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); - return; } - - MakeWindowBorderless(hWnd); + else + { + MakeWindowBorderless(hWnd); + return true; + } } + + return false; } private void MakeWindowBorderless(IntPtr hWnd) @@ -109,9 +115,9 @@ private IntPtr SearchWindow(string windowTitle) private void BorderlessWindowForm_Shown(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(DefaultWindowTitle)) + if (Settings.RememberWindowTitle && !string.IsNullOrEmpty(Settings.WindowTitle)) { - txtWindowTitle.Text = DefaultWindowTitle; + txtWindowTitle.Text = Settings.WindowTitle; btnMakeWindowBorderless.Focus(); } } @@ -125,7 +131,23 @@ private void btnMakeWindowBorderless_Click(object sender, EventArgs e) { try { - MakeWindowBorderless(txtWindowTitle.Text); + string windowTitle = txtWindowTitle.Text; + + if (Settings.RememberWindowTitle) + { + Settings.WindowTitle = windowTitle; + } + else + { + Settings.WindowTitle = ""; + } + + bool result = MakeWindowBorderless(windowTitle); + + if (result && Settings.AutoCloseWindow) + { + Close(); + } } catch (Exception ex) { @@ -133,6 +155,14 @@ private void btnMakeWindowBorderless_Click(object sender, EventArgs e) } } + private void btnSettings_Click(object sender, EventArgs e) + { + using (BorderlessWindowSettingsForm form = new BorderlessWindowSettingsForm(Settings)) + { + form.ShowDialog(); + } + } + #endregion } } \ No newline at end of file diff --git a/ShareX/Forms/BorderlessWindowSettingsForm.Designer.cs b/ShareX/Forms/BorderlessWindowSettingsForm.Designer.cs new file mode 100644 index 000000000..85e3eb50b --- /dev/null +++ b/ShareX/Forms/BorderlessWindowSettingsForm.Designer.cs @@ -0,0 +1,81 @@ + +namespace ShareX +{ + partial class BorderlessWindowSettingsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.cbRememberWindowTitle = new System.Windows.Forms.CheckBox(); + this.cbAutoCloseWindow = new System.Windows.Forms.CheckBox(); + this.SuspendLayout(); + // + // cbRememberWindowTitle + // + this.cbRememberWindowTitle.AutoSize = true; + this.cbRememberWindowTitle.Location = new System.Drawing.Point(16, 16); + this.cbRememberWindowTitle.Name = "cbRememberWindowTitle"; + this.cbRememberWindowTitle.Size = new System.Drawing.Size(135, 17); + this.cbRememberWindowTitle.TabIndex = 0; + this.cbRememberWindowTitle.Text = "Remember window title"; + this.cbRememberWindowTitle.UseVisualStyleBackColor = true; + this.cbRememberWindowTitle.CheckedChanged += new System.EventHandler(this.cbRememberWindowTitle_CheckedChanged); + // + // cbAutoCloseWindow + // + this.cbAutoCloseWindow.AutoSize = true; + this.cbAutoCloseWindow.Location = new System.Drawing.Point(16, 40); + this.cbAutoCloseWindow.Name = "cbAutoCloseWindow"; + this.cbAutoCloseWindow.Size = new System.Drawing.Size(155, 17); + this.cbAutoCloseWindow.TabIndex = 1; + this.cbAutoCloseWindow.Text = "Automatically close window"; + this.cbAutoCloseWindow.UseVisualStyleBackColor = true; + this.cbAutoCloseWindow.CheckedChanged += new System.EventHandler(this.cbAutoCloseWindow_CheckedChanged); + // + // BorderlessWindowSettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(328, 148); + this.Controls.Add(this.cbAutoCloseWindow); + this.Controls.Add(this.cbRememberWindowTitle); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "BorderlessWindowSettingsForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "ShareX - Borderless window settings"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.CheckBox cbRememberWindowTitle; + private System.Windows.Forms.CheckBox cbAutoCloseWindow; + } +} \ No newline at end of file diff --git a/ShareX/Forms/BorderlessWindowSettingsForm.cs b/ShareX/Forms/BorderlessWindowSettingsForm.cs new file mode 100644 index 000000000..dad4381cd --- /dev/null +++ b/ShareX/Forms/BorderlessWindowSettingsForm.cs @@ -0,0 +1,56 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2021 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using System; +using System.Windows.Forms; + +namespace ShareX +{ + public partial class BorderlessWindowSettingsForm : Form + { + public BorderlessWindowSettings Settings { get; private set; } + + public BorderlessWindowSettingsForm(BorderlessWindowSettings settings) + { + InitializeComponent(); + ShareXResources.ApplyTheme(this); + + Settings = settings; + cbRememberWindowTitle.Checked = Settings.RememberWindowTitle; + cbAutoCloseWindow.Checked = Settings.AutoCloseWindow; + } + + private void cbRememberWindowTitle_CheckedChanged(object sender, EventArgs e) + { + Settings.RememberWindowTitle = cbRememberWindowTitle.Checked; + } + + private void cbAutoCloseWindow_CheckedChanged(object sender, EventArgs e) + { + Settings.AutoCloseWindow = cbAutoCloseWindow.Checked; + } + } +} \ No newline at end of file diff --git a/ShareX/Forms/BorderlessWindowSettingsForm.resx b/ShareX/Forms/BorderlessWindowSettingsForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ShareX/Forms/BorderlessWindowSettingsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index dc1868770..9dd2a50a9 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -140,6 +140,7 @@ + @@ -187,6 +188,12 @@ BorderlessWindowForm.cs + + Form + + + BorderlessWindowSettingsForm.cs + Form @@ -925,6 +932,9 @@ BorderlessWindowForm.cs + + BorderlessWindowSettingsForm.cs + ClipboardFormatForm.cs diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 2101b200d..5dd14762a 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -807,9 +807,12 @@ public static void OpenVideoThumbnailer(TaskSettings taskSettings = null) thumbnailerForm.Show(); } - public static void OpenBorderlessWindow() + public static void OpenBorderlessWindow(TaskSettings taskSettings = null) { - BorderlessWindowForm borderlessWindowForm = new BorderlessWindowForm(); + if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); + + BorderlessWindowSettings settings = taskSettings.ToolsSettingsReference.BorderlessWindowSettings; + BorderlessWindowForm borderlessWindowForm = new BorderlessWindowForm(settings); borderlessWindowForm.Show(); } diff --git a/ShareX/TaskSettings.cs b/ShareX/TaskSettings.cs index d7bbefe20..fbd3e53ed 100644 --- a/ShareX/TaskSettings.cs +++ b/ShareX/TaskSettings.cs @@ -429,6 +429,7 @@ public class TaskSettingsTools public ImageCombinerOptions ImageCombinerOptions = new ImageCombinerOptions(); public VideoConverterOptions VideoConverterOptions = new VideoConverterOptions(); public VideoThumbnailOptions VideoThumbnailOptions = new VideoThumbnailOptions(); + public BorderlessWindowSettings BorderlessWindowSettings = new BorderlessWindowSettings(); } public class TaskSettingsAdvanced