Added remember window title and auto close window settings

This commit is contained in:
Jaex 2021-09-16 03:17:07 +03:00
parent 58d8337648
commit c752fecef6
9 changed files with 361 additions and 12 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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; }
}
}

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -0,0 +1,81 @@

namespace ShareX
{
partial class BorderlessWindowSettingsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -140,6 +140,7 @@
</Choose>
<ItemGroup>
<Compile Include="BalloonTipAction.cs" />
<Compile Include="BorderlessWindowSettings.cs" />
<Compile Include="CaptureHelpers\CaptureActiveMonitor.cs" />
<Compile Include="CaptureHelpers\CaptureActiveWindow.cs" />
<Compile Include="CaptureHelpers\CaptureBase.cs" />
@ -187,6 +188,12 @@
<Compile Include="Forms\BorderlessWindowForm.Designer.cs">
<DependentUpon>BorderlessWindowForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\BorderlessWindowSettingsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\BorderlessWindowSettingsForm.Designer.cs">
<DependentUpon>BorderlessWindowSettingsForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\ClipboardUploadForm.cs">
<SubType>Form</SubType>
</Compile>
@ -925,6 +932,9 @@
<EmbeddedResource Include="Forms\BorderlessWindowForm.resx">
<DependentUpon>BorderlessWindowForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\BorderlessWindowSettingsForm.resx">
<DependentUpon>BorderlessWindowSettingsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\ClipboardFormatForm.ja-JP.resx">
<DependentUpon>ClipboardFormatForm.cs</DependentUpon>
</EmbeddedResource>

View file

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

View file

@ -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