ShareX/ShareX.UploadersLib/Forms/JiraUpload.cs

111 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
2014-05-13 21:06:40 +12:00
Copyright (C) 2007-2014 ShareX Developers
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)
// gpailler
using System;
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
using ShareX.UploadersLib.Properties;
2013-11-03 23:53:49 +13:00
2014-12-11 09:25:20 +13:00
namespace ShareX.UploadersLib.GUI
2013-11-03 23:53:49 +13:00
{
using System.Threading.Tasks;
public partial class JiraUpload : Form
2013-11-03 23:53:49 +13:00
{
public delegate string GetSummaryHandler(string issueId);
private readonly string _issuePrefix;
private readonly GetSummaryHandler _getSummary;
public JiraUpload()
{
InitializeComponent();
}
public string IssueId
{
get
{
return txtIssueId.Text;
}
}
public JiraUpload(string issuePrefix, GetSummaryHandler getSummary)
: this()
{
if (getSummary == null)
{
throw new ArgumentNullException("getSummary");
}
_issuePrefix = issuePrefix;
_getSummary = getSummary;
}
private void JiraUpload_Load(object sender, EventArgs e)
{
UpdateSummary(null);
2013-11-03 23:53:49 +13:00
txtIssueId.Text = _issuePrefix;
txtIssueId.SelectionStart = txtIssueId.Text.Length;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
ValidateIssueId(((TextBox)sender).Text);
}
private void btnSend_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void ValidateIssueId(string issueId)
{
Task.Factory
.StartNew(() => _getSummary(issueId))
.ContinueWith(UpdateSummaryAsync);
}
private void UpdateSummaryAsync(Task<string> task)
{
this.Invoke((Action)(() => UpdateSummary(task.Result)));
}
private void UpdateSummary(string summary)
{
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
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
}
}