#2144: Adding customizable simple actions window

This commit is contained in:
Jaex 2016-12-28 14:23:01 +03:00
parent a912197056
commit 8e645883a9
7 changed files with 352 additions and 7 deletions

View file

@ -24,6 +24,7 @@
#endregion License Information (GPL v3)
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace ShareX.HelpersLib
@ -33,6 +34,7 @@ public class ToolStripEx : ToolStrip
{
private bool clickThrough = false;
[DefaultValue(false)]
public bool ClickThrough
{
get

View file

@ -50,12 +50,12 @@ public class Uploader
public event Action<string> EarlyURLCopyRequested;
public bool IsUploading { get; protected set; }
public List<string> Errors { get; private set; }
public List<string> Errors { get; private set; } = new List<string>();
public bool IsError => !StopUploadRequested && Errors != null && Errors.Count > 0;
public int BufferSize { get; set; }
public int BufferSize { get; set; } = 8192;
protected bool StopUploadRequested { get; set; }
protected bool AllowReportProgress { get; set; }
protected bool AllowReportProgress { get; set; } = true;
protected bool WebExceptionReturnResponse { get; set; }
protected bool WebExceptionThrow { get; set; }
@ -63,10 +63,6 @@ public class Uploader
public Uploader()
{
Errors = new List<string>();
BufferSize = 8192;
AllowReportProgress = true;
ServicePointManager.DefaultConnectionLimit = 25;
ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;

View file

@ -0,0 +1,88 @@
namespace ShareX
{
partial class SimpleActionsForm
{
/// <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.tsMain = new ShareX.HelpersLib.ToolStripEx();
this.tslTitle = new System.Windows.Forms.ToolStripLabel();
this.tsMain.SuspendLayout();
this.SuspendLayout();
//
// tsMain
//
this.tsMain.CanOverflow = false;
this.tsMain.ClickThrough = true;
this.tsMain.Dock = System.Windows.Forms.DockStyle.None;
this.tsMain.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.tsMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tslTitle});
this.tsMain.Location = new System.Drawing.Point(0, 0);
this.tsMain.MinimumSize = new System.Drawing.Size(10, 30);
this.tsMain.Name = "tsMain";
this.tsMain.Padding = new System.Windows.Forms.Padding(2);
this.tsMain.Size = new System.Drawing.Size(86, 30);
this.tsMain.TabIndex = 0;
this.tsMain.Text = "toolStripEx1";
//
// tslTitle
//
this.tslTitle.Margin = new System.Windows.Forms.Padding(3, 1, 3, 2);
this.tslTitle.Name = "tslTitle";
this.tslTitle.Size = new System.Drawing.Size(43, 23);
this.tslTitle.Text = "ShareX";
this.tslTitle.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tslTitle_MouseDown);
this.tslTitle.MouseEnter += new System.EventHandler(this.tslTitle_MouseEnter);
this.tslTitle.MouseLeave += new System.EventHandler(this.tslTitle_MouseLeave);
this.tslTitle.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tslTitle_MouseUp);
//
// ToolMenuForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.tsMain);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ToolMenuForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX";
this.TopMost = true;
this.tsMain.ResumeLayout(false);
this.tsMain.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private HelpersLib.ToolStripEx tsMain;
private System.Windows.Forms.ToolStripLabel tslTitle;
}
}

View file

@ -0,0 +1,97 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2016 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.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace ShareX
{
public partial class SimpleActionsForm : Form
{
public List<HotkeyType> Actions { get; set; }
public SimpleActionsForm()
{
InitializeComponent();
tsMain.Renderer = new CustomToolStripProfessionalRenderer();
// https://www.medo64.com/2014/01/scaling-toolstrip-with-dpi/
using (Graphics g = CreateGraphics())
{
double scale = Math.Max(g.DpiX, g.DpiY) / 96.0;
double newScale = ((int)Math.Floor(scale * 100) / 25 * 25) / 100.0;
if (newScale > 1)
{
int newWidth = (int)(tsMain.ImageScalingSize.Width * newScale);
int newHeight = (int)(tsMain.ImageScalingSize.Height * newScale);
tsMain.ImageScalingSize = new Size(newWidth, newHeight);
}
}
Actions = new List<HotkeyType>() { HotkeyType.RectangleRegion, HotkeyType.PrintScreen, HotkeyType.LastRegion, HotkeyType.FileUpload, HotkeyType.ClipboardUploadWithContentViewer };
foreach (HotkeyType action in Actions)
{
ToolStripButton tsb = new ToolStripButton();
tsb.Text = action.GetLocalizedDescription();
tsb.DisplayStyle = ToolStripItemDisplayStyle.Image;
tsb.Image = TaskHelpers.GetHotkeyTypeIcon(action);
tsMain.Items.Add(tsb);
}
}
private void tslTitle_MouseEnter(object sender, EventArgs e)
{
Cursor = Cursors.SizeAll;
}
private void tslTitle_MouseLeave(object sender, EventArgs e)
{
Cursor = Cursors.Default;
}
private void tslTitle_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
NativeMethods.ReleaseCapture();
NativeMethods.DefWindowProc(Handle, (uint)WindowsMessages.SYSCOMMAND, (UIntPtr)NativeConstants.MOUSE_MOVE, IntPtr.Zero);
}
}
private void tslTitle_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Close();
}
}
}
}

View file

@ -0,0 +1,123 @@
<?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>
<metadata name="tsMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -204,6 +204,12 @@
<Compile Include="Forms\FirstTimeConfigForm.Designer.cs">
<DependentUpon>FirstTimeConfigForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\SimpleActionsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\SimpleActionsForm.Designer.cs">
<DependentUpon>SimpleActionsForm.cs</DependentUpon>
</Compile>
<Compile Include="HotkeyTypeEnumConverter.cs" />
<Compile Include="ImageCombinerOptions.cs" />
<Compile Include="IntegrationHelpers.cs" />
@ -986,6 +992,9 @@
<EmbeddedResource Include="Forms\FirstTimeConfigForm.resx">
<DependentUpon>FirstTimeConfigForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\SimpleActionsForm.resx">
<DependentUpon>SimpleActionsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\TaskSettingsForm.de.resx">
<DependentUpon>TaskSettingsForm.cs</DependentUpon>
</EmbeddedResource>

View file

@ -1257,6 +1257,36 @@ public static Image FindMenuIcon<T>(int index)
return null;
}
public static Image GetHotkeyTypeIcon(HotkeyType hotkeyType)
{
switch (hotkeyType)
{
default: return null;
// Upload
case HotkeyType.FileUpload: return Resources.folder_open_document;
case HotkeyType.FolderUpload: return Resources.folder;
case HotkeyType.ClipboardUpload: return Resources.clipboard;
case HotkeyType.ClipboardUploadWithContentViewer: return Resources.clipboard; // TODO: Find better icon
case HotkeyType.UploadURL: return Resources.drive;
case HotkeyType.DragDropUpload: return Resources.inbox;
case HotkeyType.StopUploads: return Resources.cross_button; // TODO: Find better icon
// Screen capture
case HotkeyType.PrintScreen: return Resources.layer_fullscreen;
case HotkeyType.ActiveWindow: return Resources.application_blue;
case HotkeyType.ActiveMonitor: return Resources.monitor;
case HotkeyType.RectangleRegion: return Resources.layer_shape;
case HotkeyType.RectangleLight: return Resources.Rectangle;
case HotkeyType.RectangleTransparent: return Resources.layer_transparent;
case HotkeyType.CustomRegion: return Resources.layer_shape; // TODO: Find better icon
case HotkeyType.LastRegion: return Resources.layers;
case HotkeyType.ScrollingCapture: return Resources.ui_scroll_pane_image;
case HotkeyType.CaptureWebpage: return Resources.document_globe;
case HotkeyType.TextCapture: return Resources.edit_drop_cap;
case HotkeyType.AutoCapture: return Resources.clock;
case HotkeyType.StartAutoCapture: return Resources.clock; // TODO: Find better icon
}
}
public static Screenshot GetScreenshot(TaskSettings taskSettings = null)
{
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();