mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
"Merged" 0.8 with HEAD, so we can continue developing
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1282 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
174f653a5a
commit
f3b0878b02
539 changed files with 86855 additions and 0 deletions
219
GreenshotJiraPlugin/Forms/JiraForm.cs
Normal file
219
GreenshotJiraPlugin/Forms/JiraForm.cs
Normal file
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* 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 1 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GreenshotPlugin.Controls;
|
||||
using GreenshotPlugin.Core;
|
||||
using Jira;
|
||||
|
||||
namespace GreenshotJiraPlugin {
|
||||
public partial class JiraForm : Form {
|
||||
private JiraConnector jiraConnector;
|
||||
private JiraIssue selectedIssue;
|
||||
private ListViewColumnSorter columnSorter;
|
||||
private ILanguage language = Language.GetInstance();
|
||||
private JiraConfiguration config = IniConfig.GetIniSection<JiraConfiguration>();
|
||||
|
||||
public JiraForm(JiraConnector jiraConnector) {
|
||||
InitializeComponent();
|
||||
language.SynchronizeLanguageToCulture();
|
||||
initializeComponentText();
|
||||
|
||||
this.columnSorter = new ListViewColumnSorter();
|
||||
this.jiraListView.ListViewItemSorter = columnSorter;
|
||||
|
||||
this.jiraConnector = jiraConnector;
|
||||
|
||||
changeModus(false);
|
||||
try {
|
||||
if (!jiraConnector.isLoggedIn()) {
|
||||
jiraConnector.login();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MessageBox.Show(language.GetFormattedString(LangKey.login_error, e.Message));
|
||||
}
|
||||
updateForm();
|
||||
|
||||
uploadButton.Enabled = false;
|
||||
}
|
||||
|
||||
private void initializeComponentText() {
|
||||
this.label_jirafilter.Text = language.GetString(LangKey.label_jirafilter);
|
||||
this.label_comment.Text = language.GetString(LangKey.label_comment);
|
||||
this.label_filename.Text = language.GetString(LangKey.label_filename);
|
||||
}
|
||||
|
||||
private void updateForm() {
|
||||
if (jiraConnector.isLoggedIn()) {
|
||||
JiraFilter[] filters = jiraConnector.getFilters();
|
||||
if (filters.Length > 0) {
|
||||
foreach (JiraFilter filter in filters) {
|
||||
jiraFilterBox.Items.Add(filter);
|
||||
}
|
||||
jiraFilterBox.SelectedIndex = 0;
|
||||
}
|
||||
changeModus(true);
|
||||
jiraKey.Text = config.LastUsedJira;
|
||||
}
|
||||
}
|
||||
|
||||
private void changeModus(bool enabled) {
|
||||
jiraFilterBox.Enabled = enabled;
|
||||
jiraListView.Enabled = enabled;
|
||||
jiraFilenameBox.Enabled = enabled;
|
||||
jiraCommentBox.Enabled = enabled;
|
||||
}
|
||||
|
||||
public void setFilename(string filename) {
|
||||
jiraFilenameBox.Text = filename;
|
||||
}
|
||||
|
||||
public void setComment(string comment) {
|
||||
jiraCommentBox.Text = comment;
|
||||
}
|
||||
|
||||
public JiraIssue getJiraIssue() {
|
||||
return selectedIssue;
|
||||
}
|
||||
|
||||
public void upload(string text) {
|
||||
jiraConnector.addAttachment(selectedIssue.Key, jiraFilenameBox.Text, text);
|
||||
if (jiraCommentBox.Text != null && jiraCommentBox.Text.Length > 0) {
|
||||
jiraConnector.addComment(selectedIssue.Key, jiraCommentBox.Text);
|
||||
}
|
||||
}
|
||||
|
||||
public void upload(byte [] attachment) {
|
||||
config.LastUsedJira = selectedIssue.Key;
|
||||
jiraConnector.addAttachment(selectedIssue.Key, jiraFilenameBox.Text, attachment);
|
||||
if (jiraCommentBox.Text != null && jiraCommentBox.Text.Length > 0) {
|
||||
jiraConnector.addComment(selectedIssue.Key, jiraCommentBox.Text);
|
||||
}
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
jiraConnector.logout();
|
||||
}
|
||||
|
||||
private void selectJiraToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
|
||||
selectedIssue = (JiraIssue)clickedItem.Tag;
|
||||
jiraKey.Text = selectedIssue.Key;
|
||||
}
|
||||
|
||||
private void jiraFilterBox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
if (jiraConnector.isLoggedIn()) {
|
||||
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(JiraPlugin.JiraPluginAttributes.Name, language.GetString(LangKey.communication_wait));
|
||||
try {
|
||||
uploadButton.Enabled = false;
|
||||
JiraFilter filter = (JiraFilter)jiraFilterBox.SelectedItem;
|
||||
if (filter == null) {
|
||||
return;
|
||||
}
|
||||
JiraIssue[] issues = jiraConnector.getIssuesForFilter(filter.Id);
|
||||
jiraListView.BeginUpdate();
|
||||
jiraListView.Items.Clear();
|
||||
if (issues.Length > 0) {
|
||||
jiraListView.Columns.Clear();
|
||||
LangKey[] columns = { LangKey.column_id, LangKey.column_created, LangKey.column_assignee, LangKey.column_reporter, LangKey.column_summary };
|
||||
foreach (LangKey column in columns) {
|
||||
jiraListView.Columns.Add(language.GetString(column));
|
||||
}
|
||||
foreach (JiraIssue issue in issues) {
|
||||
ListViewItem item = new ListViewItem(issue.Key);
|
||||
item.Tag = issue;
|
||||
item.SubItems.Add(issue.Created.Value.ToString("d", DateTimeFormatInfo.InvariantInfo));
|
||||
item.SubItems.Add(issue.Assignee);
|
||||
item.SubItems.Add(issue.Reporter);
|
||||
item.SubItems.Add(issue.Summary);
|
||||
jiraListView.Items.Add(item);
|
||||
}
|
||||
for (int i = 0; i < columns.Length; i++) {
|
||||
jiraListView.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent);
|
||||
}
|
||||
}
|
||||
jiraListView.EndUpdate();
|
||||
jiraListView.Refresh();
|
||||
} finally {
|
||||
backgroundForm.CloseDialog();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void jiraListView_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
if (jiraListView.SelectedItems != null && jiraListView.SelectedItems.Count > 0) {
|
||||
selectedIssue = (JiraIssue)jiraListView.SelectedItems[0].Tag;
|
||||
jiraKey.Text = selectedIssue.Key;
|
||||
uploadButton.Enabled = true;
|
||||
} else {
|
||||
uploadButton.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadButton_Click(object sender, EventArgs e) {
|
||||
this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void cancelButton_Click(object sender, EventArgs e) {
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
|
||||
private void jiraListView_ColumnClick(object sender, ColumnClickEventArgs e) {
|
||||
// Determine if clicked column is already the column that is being sorted.
|
||||
if (e.Column == columnSorter.SortColumn) {
|
||||
// Reverse the current sort direction for this column.
|
||||
if (columnSorter.Order == SortOrder.Ascending) {
|
||||
columnSorter.Order = SortOrder.Descending;
|
||||
} else {
|
||||
columnSorter.Order = SortOrder.Ascending;
|
||||
}
|
||||
} else {
|
||||
// Set the column number that is to be sorted; default to ascending.
|
||||
columnSorter.SortColumn = e.Column;
|
||||
columnSorter.Order = SortOrder.Ascending;
|
||||
}
|
||||
|
||||
// Perform the sort with these new sort options.
|
||||
this.jiraListView.Sort();
|
||||
}
|
||||
|
||||
void JiraKeyTextChanged(object sender, EventArgs e) {
|
||||
string jiranumber = jiraKey.Text;
|
||||
uploadButton.Enabled = false;
|
||||
int dashIndex = jiranumber.IndexOf('-');
|
||||
if (dashIndex > 0 && jiranumber.Length > dashIndex+1) {
|
||||
selectedIssue = jiraConnector.getIssue(jiraKey.Text);
|
||||
if (selectedIssue != null) {
|
||||
uploadButton.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue