BUG-1653: Accessibility improvements, adding accept/cancel buttons to some of the forms. This way one can e.g. ESC out of a form.

This commit is contained in:
RKrom 2014-07-18 13:56:55 +02:00
commit 036aec55f5
25 changed files with 119 additions and 180 deletions

View file

@ -18,13 +18,14 @@
* 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 Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace ExternalCommand {
/// <summary>

View file

@ -63,10 +63,10 @@ namespace ExternalCommand {
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 11;
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
//
// buttonOk
//
this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOk.LanguageKey = "OK";
this.buttonOk.Location = new System.Drawing.Point(275, 173);
this.buttonOk.Name = "buttonOk";
@ -144,6 +144,7 @@ namespace ExternalCommand {
this.LanguageKey = "externalcommand.settings_title";
this.Name = "SettingsForm";
this.ResumeLayout(false);
}
private GreenshotPlugin.Controls.GreenshotButton button_edit;
private GreenshotPlugin.Controls.GreenshotButton button_delete;

View file

@ -18,12 +18,12 @@
* 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 Greenshot.IniFile;
using System;
using System.Drawing;
using System.Windows.Forms;
using Greenshot.IniFile;
namespace ExternalCommand {
/// <summary>
/// Description of SettingsForm.
@ -31,34 +31,31 @@ namespace ExternalCommand {
public partial class SettingsForm : ExternalCommandForm {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm));
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
public SettingsForm() {
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
AcceptButton = buttonOk;
CancelButton = buttonCancel;
UpdateView();
}
void ButtonOkClick(object sender, EventArgs e) {
IniConfig.Save();
DialogResult = DialogResult.OK;
}
void ButtonCancelClick(object sender, EventArgs e) {
DialogResult = DialogResult.Cancel;
}
void ButtonAddClick(object sender, EventArgs e) {
SettingsFormDetail form = new SettingsFormDetail(null);
form.ShowDialog();
UpdateView();
}
void ButtonDeleteClick(object sender, EventArgs e) {
foreach ( ListViewItem item in listView1.SelectedItems ) {
foreach(ListViewItem item in listView1.SelectedItems) {
string commando = item.Tag as string;
config.commands.Remove(commando);
config.commandlines.Remove(commando);
@ -69,15 +66,15 @@ namespace ExternalCommand {
void UpdateView() {
listView1.Items.Clear();
if (config.commands != null) {
if(config.commands != null) {
listView1.ListViewItemSorter = new ListviewComparer();
ImageList imageList = new ImageList();
listView1.SmallImageList = imageList;
int imageNr = 0;
foreach (string commando in config.commands) {
foreach(string commando in config.commands) {
ListViewItem item = null;
Image iconForExe = IconCache.IconForCommand(commando);
if (iconForExe != null) {
if(iconForExe != null) {
imageList.Images.Add(iconForExe);
item = new ListViewItem(commando, imageNr++);
} else {
@ -94,39 +91,39 @@ namespace ExternalCommand {
void ListView1ItemSelectionChanged(object sender, EventArgs e) {
button_edit.Enabled = listView1.SelectedItems.Count > 0;
}
void ButtonEditClick(object sender, EventArgs e) {
ListView1DoubleClick(sender, e);
}
void ListView1DoubleClick(object sender, EventArgs e) {
// Safety check for bug #1484
bool selectionActive = listView1.SelectedItems.Count > 0;
if (!selectionActive) {
if(!selectionActive) {
button_edit.Enabled = false;
return;
}
string commando = listView1.SelectedItems[0].Tag as string;
SettingsFormDetail form = new SettingsFormDetail(commando);
form.ShowDialog();
UpdateView();
}
}
public class ListviewComparer : System.Collections.IComparer {
public int Compare(object x, object y) {
if (!(x is ListViewItem)) {
if(!(x is ListViewItem)) {
return (0);
}
if (!(y is ListViewItem)) {
if(!(y is ListViewItem)) {
return (0);
}
ListViewItem l1 = (ListViewItem)x;
ListViewItem l2 = (ListViewItem)y;
if (l2 == null) {
if(l2 == null) {
return 1;
}
return l1.Text.CompareTo(l2.Text);

View file

@ -62,6 +62,7 @@ namespace ExternalCommand {
//
// buttonOk
//
this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOk.Enabled = false;
this.buttonOk.LanguageKey = "OK";
this.buttonOk.Location = new System.Drawing.Point(273, 140);
@ -80,7 +81,6 @@ namespace ExternalCommand {
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 11;
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
//
// groupBox1
//
@ -178,7 +178,6 @@ namespace ExternalCommand {
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.LanguageKey = "externalcommand.settings_detail_title";
this.Name = "SettingsFormDetail";
this.Text = "Configure command";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);

View file

@ -1,18 +1,30 @@
/*
* Created by SharpDevelop.
* User: 05018038
* Date: 04.04.2012
* Time: 10:50
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
* 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 Greenshot.IniFile;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Greenshot.IniFile;
namespace ExternalCommand {
/// <summary>
/// Description of SettingsFormDetail.
@ -20,17 +32,18 @@ namespace ExternalCommand {
public partial class SettingsFormDetail : ExternalCommandForm {
private string commando;
private int commandIndex;
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsFormDetail));
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
public SettingsFormDetail(string commando)
{
public SettingsFormDetail(string commando) {
InitializeComponent();
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
AcceptButton = buttonOk;
CancelButton = buttonCancel;
this.commando = commando;
if (commando != null) {
if(commando != null) {
textBox_name.Text = commando;
textBox_commandline.Text = config.commandlines[commando];
textBox_arguments.Text = config.arguments[commando];
@ -40,13 +53,12 @@ namespace ExternalCommand {
}
OKButtonState();
}
void ButtonOkClick(object sender, EventArgs e)
{
void ButtonOkClick(object sender, EventArgs e) {
string commandName = textBox_name.Text;
string commandLine = textBox_commandline.Text;
string arguments = textBox_arguments.Text;
if (commando != null) {
if(commando != null) {
config.commands[commandIndex] = commandName;
config.commandlines.Remove(commando);
config.commandlines.Add(commandName, commandLine);
@ -57,17 +69,9 @@ namespace ExternalCommand {
config.commandlines.Add(commandName, commandLine);
config.arguments.Add(commandName, arguments);
}
Close();
}
void ButtonCancelClick(object sender, EventArgs e)
{
Close();
}
void Button3Click(object sender, EventArgs e)
{
void Button3Click(object sender, EventArgs e) {
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Executables (*.exe, *.bat, *.com)|*.exe; *.bat; *.com|All files (*)|*";
openFileDialog.FilterIndex = 1;
@ -76,15 +80,15 @@ namespace ExternalCommand {
string initialPath = null;
try {
initialPath = Path.GetDirectoryName(textBox_commandline.Text);
} catch {}
if (initialPath != null && Directory.Exists(initialPath)) {
openFileDialog.InitialDirectory = initialPath;
} catch { }
if(initialPath != null && Directory.Exists(initialPath)) {
openFileDialog.InitialDirectory = initialPath;
} else {
initialPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
openFileDialog.InitialDirectory = initialPath;
}
LOG.DebugFormat("Starting OpenFileDialog at {0}", initialPath);
if (openFileDialog.ShowDialog() == DialogResult.OK) {
if(openFileDialog.ShowDialog() == DialogResult.OK) {
textBox_commandline.Text = openFileDialog.FileName;
}
}
@ -95,20 +99,20 @@ namespace ExternalCommand {
textBox_name.BackColor = Color.White;
textBox_commandline.BackColor = Color.White;
// Is there a text in the name field
if (string.IsNullOrEmpty(textBox_name.Text)) {
if(string.IsNullOrEmpty(textBox_name.Text)) {
buttonOk.Enabled = false;
}
// Check if commandname is unique
if (commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) {
if(commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) {
buttonOk.Enabled = false;
textBox_name.BackColor = Color.Red;
}
// Is there a text in the commandline field
if (string.IsNullOrEmpty(textBox_commandline.Text)) {
if(string.IsNullOrEmpty(textBox_commandline.Text)) {
buttonOk.Enabled = false;
}
// Is the command available?
if (!string.IsNullOrEmpty(textBox_commandline.Text) && !File.Exists(textBox_commandline.Text)) {
if(!string.IsNullOrEmpty(textBox_commandline.Text) && !File.Exists(textBox_commandline.Text)) {
buttonOk.Enabled = false;
textBox_commandline.BackColor = Color.Red;
}