Added "output" custom uploader syntax

This commit is contained in:
Jaex 2023-04-14 02:53:35 +03:00
parent b3907c918e
commit 6344565630
6 changed files with 94 additions and 36 deletions

View file

@ -28,24 +28,21 @@ protected override void Dispose(bool disposing)
/// </summary>
private void InitializeComponent()
{
this.txtText = new System.Windows.Forms.TextBox();
this.rtbText = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// txtText
// rtbText
//
this.txtText.BackColor = System.Drawing.Color.Black;
this.txtText.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtText.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtText.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
this.txtText.ForeColor = System.Drawing.Color.White;
this.txtText.Location = new System.Drawing.Point(0, 0);
this.txtText.Multiline = true;
this.txtText.Name = "txtText";
this.txtText.ReadOnly = true;
this.txtText.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtText.Size = new System.Drawing.Size(984, 761);
this.txtText.TabIndex = 0;
this.txtText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtText_KeyUp);
this.rtbText.BackColor = System.Drawing.Color.Black;
this.rtbText.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.rtbText.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtbText.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.rtbText.Location = new System.Drawing.Point(8, 8);
this.rtbText.Name = "rtbText";
this.rtbText.Size = new System.Drawing.Size(968, 745);
this.rtbText.TabIndex = 1;
this.rtbText.Text = "";
this.rtbText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.rtbText_KeyUp);
//
// OutputBox
//
@ -53,18 +50,18 @@ private void InitializeComponent()
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(984, 761);
this.Controls.Add(this.txtText);
this.Controls.Add(this.rtbText);
this.Name = "OutputBox";
this.Padding = new System.Windows.Forms.Padding(8);
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "OutputBox";
this.Shown += new System.EventHandler(this.OutputBox_Shown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtText;
private System.Windows.Forms.RichTextBox rtbText;
}
}

View file

@ -30,16 +30,16 @@ namespace ShareX.HelpersLib
{
public partial class OutputBox : Form
{
private bool scrollToEnd;
public bool ScrollToEnd { get; private set; }
public OutputBox(string text, string title, bool scrollToEnd = false)
private OutputBox(string text, string title, bool scrollToEnd = false)
{
InitializeComponent();
ShareXResources.ApplyTheme(this);
Text = "ShareX - " + title;
txtText.Text = text;
this.scrollToEnd = scrollToEnd;
rtbText.Text = text;
ScrollToEnd = scrollToEnd;
}
public static void Show(string text, string title, bool scrollToEnd = false)
@ -54,18 +54,15 @@ private void OutputBox_Shown(object sender, EventArgs e)
{
this.ForceActivate();
if (scrollToEnd)
rtbText.SelectionStart = rtbText.TextLength;
if (ScrollToEnd)
{
txtText.SelectionStart = txtText.TextLength;
txtText.ScrollToCaret();
}
else
{
txtText.Select(0, 0);
NativeMethods.SendMessage(rtbText.Handle, (int)WindowsMessages.VSCROLL, (int)ScrollBarCommands.SB_BOTTOM, 0);
}
}
private void txtText_KeyUp(object sender, KeyEventArgs e)
private void rtbText_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{

View file

@ -295,6 +295,11 @@ public void ParseResponse(UploadResult result, ResponseInfo responseInfo, Upload
if (!string.IsNullOrEmpty(URL))
{
url = parser.Parse(URL);
if (string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(URL) && URL.Contains("{output:"))
{
result.IsURLExpected = false;
}
}
else
{

View file

@ -0,0 +1,58 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2023 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;
namespace ShareX.UploadersLib
{
// Example: {output:text}
// Example: {output:title|text}
internal class CustomUploaderFunctionOutput : CustomUploaderFunction
{
public override string Name { get; } = "output";
public override int MinParameterCount { get; } = 1;
public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
{
string text, title;
if (parameters.Length > 1)
{
text = parameters[1];
title = parameters[0];
}
else
{
text = parameters[0];
title = "ShareX - Output";
}
OutputBox.Show(text, title);
return null;
}
}
}

View file

@ -30,7 +30,7 @@ namespace ShareX.UploadersLib
{
// Example: {prompt}
// Example: {prompt:title}
// Example: {prompt:title|default value}
// Example: {prompt:title|default text}
internal class CustomUploaderFunctionPrompt : CustomUploaderFunction
{
public override string Name { get; } = "prompt";
@ -38,7 +38,7 @@ internal class CustomUploaderFunctionPrompt : CustomUploaderFunction
public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
{
string title = "ShareX - Prompt";
string defaultValue = "";
string defaultText = "";
if (parameters.Length > 0)
{
@ -46,11 +46,11 @@ public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] pa
if (parameters.Length > 1)
{
defaultValue = parameters[1];
defaultText = parameters[1];
}
}
using (InputBox inputBox = new InputBox(title, defaultValue))
using (InputBox inputBox = new InputBox(title, defaultText))
{
if (inputBox.ShowDialog() == DialogResult.OK)
{
@ -58,7 +58,7 @@ public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] pa
}
}
return defaultValue;
return defaultText;
}
}
}

View file

@ -133,6 +133,7 @@
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionBase64.cs" />
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionFileName.cs" />
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionInput.cs" />
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionOutput.cs" />
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionResponseURL.cs" />
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionResponse.cs" />
<Compile Include="CustomUploader\Functions\CustomUploaderFunctionPrompt.cs" />