ShareX/ShareX.UploadersLib/Forms/JiraUpload.cs

104 lines
3.1 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2024-01-03 12:57:14 +13:00
Copyright (c) 2007-2024 ShareX Team
2013-11-03 23:53:49 +13:00
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;
2014-12-11 12:19:28 +13:00
using ShareX.UploadersLib.Properties;
2013-11-03 23:53:49 +13:00
using System;
using System.Threading.Tasks;
2013-11-03 23:53:49 +13:00
using System.Windows.Forms;
namespace ShareX.UploadersLib
2013-11-03 23:53:49 +13:00
{
public partial class JiraUpload : Form
2013-11-03 23:53:49 +13:00
{
public delegate string GetSummaryHandler(string issueId);
2018-10-07 08:09:15 +13:00
private readonly string issuePrefix;
private readonly GetSummaryHandler getSummary;
2013-11-03 23:53:49 +13:00
public string IssueId
{
get
{
return txtIssueId.Text;
}
}
public JiraUpload()
{
InitializeComponent();
2023-06-05 10:17:51 +12:00
ShareXResources.ApplyTheme(this, true);
}
2016-04-07 04:02:48 +12:00
public JiraUpload(string issuePrefix, GetSummaryHandler getSummary) : this()
2013-11-03 23:53:49 +13:00
{
2018-10-07 08:09:15 +13:00
this.issuePrefix = issuePrefix;
2021-06-10 10:14:01 +12:00
this.getSummary = getSummary ?? throw new ArgumentNullException(nameof(getSummary));
2013-11-03 23:53:49 +13:00
}
private void JiraUpload_Load(object sender, EventArgs e)
{
UpdateSummary(null);
2018-10-07 08:09:15 +13:00
txtIssueId.Text = issuePrefix;
2013-11-03 23:53:49 +13:00
txtIssueId.SelectionStart = txtIssueId.Text.Length;
}
2023-06-05 10:17:51 +12:00
private void txtIssueId_TextChanged(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
2023-06-05 10:17:51 +12:00
ValidateIssueId(txtIssueId.Text);
2013-11-03 23:53:49 +13:00
}
private void ValidateIssueId(string issueId)
{
2018-10-07 08:09:15 +13:00
Task.Run(() => getSummary(issueId)).ContinueWith(UpdateSummaryAsync);
}
private void UpdateSummaryAsync(Task<string> task)
{
2020-04-12 02:00:14 +12:00
this.InvokeSafe(() => UpdateSummary(task.Result));
}
private void UpdateSummary(string summary)
{
2015-11-29 01:53:16 +13:00
btnUpload.Enabled = summary != null;
2013-11-03 23:53:49 +13:00
lblSummary.Text = summary ?? Resources.JiraUpload_ValidateIssueId_Issue_not_found;
lblSummary.Enabled = summary != null;
2013-11-03 23:53:49 +13:00
}
2023-06-05 10:17:51 +12:00
private void btnSend_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
2013-11-03 23:53:49 +13:00
private void btnCancel_Click(object sender, EventArgs e)
{
2023-06-05 10:17:51 +12:00
DialogResult = DialogResult.Cancel;
2013-11-03 23:53:49 +13:00
Close();
}
}
}