mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Added GreenshotComboBox, this binds to a ini configuration (enum) and fills the values depending on the type of the enum, including translations!
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1769 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
c3a1e18faa
commit
4e13e13f47
5 changed files with 129 additions and 18 deletions
12
Greenshot/Forms/SettingsForm.Designer.cs
generated
12
Greenshot/Forms/SettingsForm.Designer.cs
generated
|
@ -57,7 +57,7 @@ namespace Greenshot {
|
|||
this.textbox_screenshotname = new GreenshotPlugin.Controls.GreenshotTextBox();
|
||||
this.label_language = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||
this.combobox_language = new System.Windows.Forms.ComboBox();
|
||||
this.combobox_primaryimageformat = new System.Windows.Forms.ComboBox();
|
||||
this.combobox_primaryimageformat = new GreenshotPlugin.Controls.GreenshotComboBox();
|
||||
this.label_primaryimageformat = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||
this.groupbox_preferredfilesettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
|
||||
this.btnPatternHelp = new System.Windows.Forms.Button();
|
||||
|
@ -243,6 +243,7 @@ namespace Greenshot {
|
|||
this.combobox_primaryimageformat.FormattingEnabled = true;
|
||||
this.combobox_primaryimageformat.Location = new System.Drawing.Point(138, 64);
|
||||
this.combobox_primaryimageformat.Name = "combobox_primaryimageformat";
|
||||
this.combobox_primaryimageformat.PropertyName = "OutputFileFormat";
|
||||
this.combobox_primaryimageformat.Size = new System.Drawing.Size(268, 21);
|
||||
this.combobox_primaryimageformat.TabIndex = 4;
|
||||
//
|
||||
|
@ -313,7 +314,6 @@ namespace Greenshot {
|
|||
this.checkbox_autostartshortcut.LanguageKey = "settings_autostartshortcut";
|
||||
this.checkbox_autostartshortcut.Location = new System.Drawing.Point(8, 39);
|
||||
this.checkbox_autostartshortcut.Name = "checkbox_autostartshortcut";
|
||||
this.checkbox_autostartshortcut.PropertyName = null;
|
||||
this.checkbox_autostartshortcut.Size = new System.Drawing.Size(397, 25);
|
||||
this.checkbox_autostartshortcut.TabIndex = 15;
|
||||
this.checkbox_autostartshortcut.Text = "Launch Greenshot on startup";
|
||||
|
@ -955,7 +955,6 @@ namespace Greenshot {
|
|||
this.groupbox_plugins.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
|
||||
this.groupbox_plugins.Controls.Add(this.listview_plugins);
|
||||
this.groupbox_plugins.Controls.Add(this.button_pluginconfigure);
|
||||
this.groupbox_plugins.LanguageKey = null;
|
||||
this.groupbox_plugins.Location = new System.Drawing.Point(0, 0);
|
||||
this.groupbox_plugins.Name = "groupbox_plugins";
|
||||
this.groupbox_plugins.Size = new System.Drawing.Size(423, 314);
|
||||
|
@ -992,7 +991,6 @@ namespace Greenshot {
|
|||
// tab_expert
|
||||
//
|
||||
this.tab_expert.Controls.Add(this.groupbox_expert);
|
||||
this.tab_expert.LanguageKey = null;
|
||||
this.tab_expert.Location = new System.Drawing.Point(4, 22);
|
||||
this.tab_expert.Name = "tab_expert";
|
||||
this.tab_expert.Size = new System.Drawing.Size(423, 320);
|
||||
|
@ -1006,7 +1004,6 @@ namespace Greenshot {
|
|||
this.groupbox_expert.Controls.Add(this.label_clipboardformats);
|
||||
this.groupbox_expert.Controls.Add(this.checkbox_enableexpert);
|
||||
this.groupbox_expert.Controls.Add(this.listView1);
|
||||
this.groupbox_expert.LanguageKey = null;
|
||||
this.groupbox_expert.Location = new System.Drawing.Point(5, 5);
|
||||
this.groupbox_expert.Name = "groupbox_expert";
|
||||
this.groupbox_expert.Size = new System.Drawing.Size(412, 311);
|
||||
|
@ -1028,7 +1025,6 @@ namespace Greenshot {
|
|||
// label_clipboardformats
|
||||
//
|
||||
this.label_clipboardformats.AutoSize = true;
|
||||
this.label_clipboardformats.LanguageKey = null;
|
||||
this.label_clipboardformats.Location = new System.Drawing.Point(7, 45);
|
||||
this.label_clipboardformats.Name = "label_clipboardformats";
|
||||
this.label_clipboardformats.Size = new System.Drawing.Size(88, 13);
|
||||
|
@ -1037,10 +1033,8 @@ namespace Greenshot {
|
|||
//
|
||||
// checkbox_enableexpert
|
||||
//
|
||||
this.checkbox_enableexpert.LanguageKey = null;
|
||||
this.checkbox_enableexpert.Location = new System.Drawing.Point(6, 14);
|
||||
this.checkbox_enableexpert.Name = "checkbox_enableexpert";
|
||||
this.checkbox_enableexpert.PropertyName = null;
|
||||
this.checkbox_enableexpert.Size = new System.Drawing.Size(394, 24);
|
||||
this.checkbox_enableexpert.TabIndex = 19;
|
||||
this.checkbox_enableexpert.Text = "I know what I am doing!";
|
||||
|
@ -1178,7 +1172,7 @@ namespace Greenshot {
|
|||
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_preferredfilesettings;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_playsound;
|
||||
private GreenshotPlugin.Controls.GreenshotLabel label_primaryimageformat;
|
||||
private System.Windows.Forms.ComboBox combobox_primaryimageformat;
|
||||
private GreenshotPlugin.Controls.GreenshotComboBox combobox_primaryimageformat;
|
||||
private System.Windows.Forms.ComboBox combobox_language;
|
||||
private GreenshotPlugin.Controls.GreenshotLabel label_language;
|
||||
private GreenshotPlugin.Controls.GreenshotTextBox textbox_screenshotname;
|
||||
|
|
|
@ -66,7 +66,6 @@ namespace Greenshot {
|
|||
}
|
||||
|
||||
DisplayPluginTab();
|
||||
this.combobox_primaryimageformat.Items.AddRange(new object[] { OutputFormat.bmp, OutputFormat.gif, OutputFormat.jpg, OutputFormat.png, OutputFormat.tiff });
|
||||
UpdateUI();
|
||||
DisplaySettings();
|
||||
CheckSettings();
|
||||
|
@ -260,7 +259,6 @@ namespace Greenshot {
|
|||
combobox_language.SelectedValue = language.CurrentLanguage;
|
||||
}
|
||||
textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false);
|
||||
combobox_primaryimageformat.SelectedItem = coreConfiguration.OutputFileFormat;
|
||||
|
||||
SetWindowCaptureMode(coreConfiguration.WindowCaptureMode);
|
||||
|
||||
|
@ -297,12 +295,6 @@ namespace Greenshot {
|
|||
if (!FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false).Equals(textbox_storagelocation.Text)) {
|
||||
coreConfiguration.OutputFilePath = textbox_storagelocation.Text;
|
||||
}
|
||||
if (combobox_primaryimageformat.SelectedItem != null) {
|
||||
coreConfiguration.OutputFileFormat = (OutputFormat)combobox_primaryimageformat.SelectedItem;
|
||||
} else {
|
||||
coreConfiguration.OutputFileFormat = OutputFormat.png;
|
||||
}
|
||||
|
||||
coreConfiguration.OutputFileJpegQuality = trackBarJpegQuality.Value;
|
||||
|
||||
List<string> destinations = new List<string>();
|
||||
|
|
103
GreenshotPlugin/Controls/GreenshotComboBox.cs
Normal file
103
GreenshotPlugin/Controls/GreenshotComboBox.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace GreenshotPlugin.Controls {
|
||||
public class GreenshotComboBox : ComboBox, IGreenshotConfigBindable {
|
||||
private string sectionName = "Core";
|
||||
[Category("Greenshot"), DefaultValue("Core"), Description("Specifies the Ini-Section to map this control with.")]
|
||||
public string SectionName {
|
||||
get {
|
||||
return sectionName;
|
||||
}
|
||||
set {
|
||||
sectionName = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Greenshot"), DefaultValue(null), Description("Specifies the property name to map the configuration.")]
|
||||
public string PropertyName {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is a method to popululate the ComboBox
|
||||
/// with the items from the enumeration
|
||||
/// </summary>
|
||||
/// <param name="enumType">TEnum to populate with</param>
|
||||
public void Populate(ILanguage language, Type enumType, object currentValue) {
|
||||
var availableValues = Enum.GetValues(enumType);
|
||||
this.Items.Clear();
|
||||
string enumTypeName = enumType.Name;
|
||||
foreach (var enumValue in availableValues) {
|
||||
string enumKey = enumTypeName + "." + enumValue.ToString();
|
||||
if (language.hasKey(enumKey)) {
|
||||
string translation = language.GetString(enumKey);
|
||||
this.Items.Add(translation);
|
||||
} else {
|
||||
this.Items.Add(enumValue.ToString());
|
||||
}
|
||||
}
|
||||
if (currentValue != null) {
|
||||
string selectedEnumKey = enumTypeName + "." + currentValue.ToString();
|
||||
if (language.hasKey(selectedEnumKey)) {
|
||||
this.SelectedItem = language.GetString(selectedEnumKey);
|
||||
} else {
|
||||
this.SelectedItem = currentValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the selected enum value from the combobox, uses generics
|
||||
/// </summary>
|
||||
/// <param name="comboBox">Combobox to get the value from</param>
|
||||
/// <returns>The generics value of the combobox</returns>
|
||||
public object GetSelectedEnum(ILanguage language, Type enumType) {
|
||||
string enumTypeName = enumType.Name;
|
||||
string selectedValue = this.SelectedItem as string;
|
||||
var availableValues = Enum.GetValues(enumType);
|
||||
object returnValue = null;
|
||||
|
||||
try {
|
||||
returnValue = Enum.Parse(enumType, selectedValue);
|
||||
return returnValue;
|
||||
} catch (Exception) {
|
||||
}
|
||||
|
||||
foreach (Enum enumValue in availableValues) {
|
||||
string enumKey = enumTypeName + "." + enumValue.ToString();
|
||||
if (language.hasKey(enumKey)) {
|
||||
string translation = language.GetString(enumTypeName + "." + enumValue.ToString());
|
||||
if (translation.Equals(selectedValue)) {
|
||||
return enumValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@ namespace GreenshotPlugin.Controls {
|
|||
if (!string.IsNullOrEmpty(LanguageKey)) {
|
||||
this.Text = language.GetString(LanguageKey);
|
||||
}
|
||||
|
||||
// Reset the text values for all GreenshotControls
|
||||
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
|
||||
if (!field.FieldType.IsSubclassOf(typeof(Control))) {
|
||||
continue;
|
||||
|
@ -71,6 +71,21 @@ namespace GreenshotPlugin.Controls {
|
|||
LOG.WarnFormat("Greenshot control without language key: {0}", field.Name);
|
||||
}
|
||||
}
|
||||
// Repopulate the combox boxes
|
||||
if (typeof(IGreenshotConfigBindable).IsAssignableFrom(field.FieldType)) {
|
||||
if (typeof(GreenshotComboBox).IsAssignableFrom(field.FieldType)) {
|
||||
IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
|
||||
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
|
||||
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
|
||||
if (section != null) {
|
||||
GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
|
||||
// Only update the language, so get the actual value and than repopulate
|
||||
object currentValue = comboxBox.GetSelectedEnum(language, section.Values[configBindable.PropertyName].ValueType);
|
||||
comboxBox.Populate(language, section.Values[configBindable.PropertyName].ValueType, currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -99,6 +114,9 @@ namespace GreenshotPlugin.Controls {
|
|||
} else if (typeof(TextBox).IsAssignableFrom(field.FieldType)) {
|
||||
TextBox textBox = controlObject as TextBox;
|
||||
textBox.Text = (string)section.Values[configBindable.PropertyName].Value;
|
||||
} else if (typeof(GreenshotComboBox).IsAssignableFrom(field.FieldType)) {
|
||||
GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
|
||||
comboxBox.Populate(language, section.Values[configBindable.PropertyName].ValueType, (Enum)section.Values[configBindable.PropertyName].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +154,9 @@ namespace GreenshotPlugin.Controls {
|
|||
TextBox textBox = controlObject as TextBox;
|
||||
section.Values[configBindable.PropertyName].Value = textBox.Text;
|
||||
iniDirty = true;
|
||||
} else if (typeof(GreenshotComboBox).IsAssignableFrom(field.FieldType)) {
|
||||
GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
|
||||
section.Values[configBindable.PropertyName].Value = comboxBox.GetSelectedEnum(language, section.Values[configBindable.PropertyName].ValueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,6 +177,7 @@
|
|||
</Compile>
|
||||
<Compile Include="Controls\GreenshotButton.cs" />
|
||||
<Compile Include="Controls\GreenshotCheckBox.cs" />
|
||||
<Compile Include="Controls\GreenshotComboBox.cs" />
|
||||
<Compile Include="Controls\GreenshotForm.cs" />
|
||||
<Compile Include="Controls\GreenshotGroupBox.cs" />
|
||||
<Compile Include="Controls\GreenshotLabel.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue