2013-11-03 23:53:49 +13:00
|
|
|
|
/*
|
|
|
|
|
* Greenshot - a free and open source screenshot tool
|
2016-03-14 05:07:53 +13:00
|
|
|
|
* Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom
|
2013-11-03 23:53:49 +13:00
|
|
|
|
*
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
namespace GreenshotPlugin.Controls
|
|
|
|
|
{
|
2014-09-26 14:43:13 +12:00
|
|
|
|
internal class GreenshotComboBox : ComboBox, IGreenshotConfigBindable
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-23 03:17:02 +12:00
|
|
|
|
private Type _enumType = null;
|
|
|
|
|
private Enum _selectedEnum = null;
|
2016-07-30 13:21:18 +12:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
[Category("Greenshot"), DefaultValue("Core"), Description("Specifies the Ini-Section to map this control with.")]
|
2016-05-23 03:17:02 +12:00
|
|
|
|
public string SectionName { get; set; } = "Core";
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
[Category("Greenshot"), DefaultValue(null), Description("Specifies the property name to map the configuration.")]
|
|
|
|
|
public string PropertyName
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GreenshotComboBox()
|
|
|
|
|
{
|
|
|
|
|
SelectedIndexChanged += delegate
|
|
|
|
|
{
|
|
|
|
|
StoreSelectedEnum();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetValue(Enum currentValue)
|
|
|
|
|
{
|
|
|
|
|
if (currentValue != null)
|
|
|
|
|
{
|
2016-05-23 03:17:02 +12:00
|
|
|
|
_selectedEnum = currentValue;
|
2014-09-20 06:41:13 +12:00
|
|
|
|
SelectedItem = currentValue;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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(Type enumType)
|
|
|
|
|
{
|
|
|
|
|
// Store the enum-type, so we can work with it
|
2016-05-23 03:17:02 +12:00
|
|
|
|
_enumType = enumType;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
var availableValues = Enum.GetValues(enumType);
|
|
|
|
|
Items.Clear();
|
|
|
|
|
foreach (var enumValue in availableValues)
|
|
|
|
|
{
|
2014-09-20 06:41:13 +12:00
|
|
|
|
Items.Add(enumValue);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Store the selected value internally
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void StoreSelectedEnum()
|
|
|
|
|
{
|
2016-05-23 03:17:02 +12:00
|
|
|
|
string enumTypeName = _enumType.Name;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
string selectedValue = SelectedItem as string;
|
2016-05-23 03:17:02 +12:00
|
|
|
|
var availableValues = Enum.GetValues(_enumType);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
object returnValue = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-05-23 03:17:02 +12:00
|
|
|
|
returnValue = Enum.Parse(_enumType, selectedValue);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 03:17:02 +12:00
|
|
|
|
_selectedEnum = (Enum)returnValue;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the selected enum value from the combobox, uses generics
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The enum value of the combobox</returns>
|
|
|
|
|
public Enum GetSelectedEnum()
|
|
|
|
|
{
|
2016-05-23 03:17:02 +12:00
|
|
|
|
return _selectedEnum;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|