This changes enables the settings (most of them) which are supplied in the greenshot-fixed.ini to be unchangeable in the settings.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1969 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-07-30 18:09:19 +00:00
commit 48159a99b0
7 changed files with 122 additions and 55 deletions

View file

@ -900,39 +900,47 @@ namespace Greenshot {
private void InitializeQuickSettingsMenu() { private void InitializeQuickSettingsMenu() {
this.contextmenu_quicksettings.DropDownItems.Clear(); this.contextmenu_quicksettings.DropDownItems.Clear();
if (conf.DisableQuickSettings) { if (conf.DisableQuickSettings) {
return; return;
}
// For the capture mousecursor option
ToolStripMenuSelectListItem captureMouseItem = new ToolStripMenuSelectListItem();
captureMouseItem.Text = Language.GetString("settings_capture_mousepointer");
captureMouseItem.Checked = conf.CaptureMousepointer;
captureMouseItem.CheckOnClick = true;
captureMouseItem.CheckStateChanged += delegate {
conf.CaptureMousepointer = captureMouseItem.Checked;
};
this.contextmenu_quicksettings.DropDownItems.Add(captureMouseItem);
// screenshot destination
ToolStripMenuSelectList selectList = new ToolStripMenuSelectList("destinations",true);
selectList.Text = Language.GetString(LangKey.settings_destination);
// Working with IDestination:
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
selectList.AddItem(destination.Description, destination, conf.OutputDestinations.Contains(destination.Designation));
} }
selectList.CheckedChanged += new EventHandler(this.QuickSettingDestinationChanged);
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
// Capture Modes // Only add if the value is not fixed
selectList = new ToolStripMenuSelectList("capturemodes", false); if (!conf.Values["CaptureMousepointer"].Attributes.FixedValue) {
selectList.Text = Language.GetString(LangKey.settings_window_capture_mode); // For the capture mousecursor option
string enumTypeName = typeof(WindowCaptureMode).Name; ToolStripMenuSelectListItem captureMouseItem = new ToolStripMenuSelectListItem();
foreach(WindowCaptureMode captureMode in Enum.GetValues(typeof(WindowCaptureMode))) { captureMouseItem.Text = Language.GetString("settings_capture_mousepointer");
selectList.AddItem(Language.GetString(enumTypeName + "." + captureMode.ToString()), captureMode, conf.WindowCaptureMode == captureMode); captureMouseItem.Checked = conf.CaptureMousepointer;
captureMouseItem.CheckOnClick = true;
captureMouseItem.CheckStateChanged += delegate {
conf.CaptureMousepointer = captureMouseItem.Checked;
};
this.contextmenu_quicksettings.DropDownItems.Add(captureMouseItem);
}
ToolStripMenuSelectList selectList = null;
if (!conf.Values["Destinations"].Attributes.FixedValue) {
// screenshot destination
selectList = new ToolStripMenuSelectList("destinations", true);
selectList.Text = Language.GetString(LangKey.settings_destination);
// Working with IDestination:
foreach (IDestination destination in DestinationHelper.GetAllDestinations()) {
selectList.AddItem(destination.Description, destination, conf.OutputDestinations.Contains(destination.Designation));
}
selectList.CheckedChanged += new EventHandler(this.QuickSettingDestinationChanged);
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
}
if (!conf.Values["WindowCaptureMode"].Attributes.FixedValue) {
// Capture Modes
selectList = new ToolStripMenuSelectList("capturemodes", false);
selectList.Text = Language.GetString(LangKey.settings_window_capture_mode);
string enumTypeName = typeof(WindowCaptureMode).Name;
foreach (WindowCaptureMode captureMode in Enum.GetValues(typeof(WindowCaptureMode))) {
selectList.AddItem(Language.GetString(enumTypeName + "." + captureMode.ToString()), captureMode, conf.WindowCaptureMode == captureMode);
}
selectList.CheckedChanged += new EventHandler(this.QuickSettingCaptureModeChanged);
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
} }
selectList.CheckedChanged += new EventHandler(this.QuickSettingCaptureModeChanged);
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
// print options // print options
selectList = new ToolStripMenuSelectList("printoptions",true); selectList = new ToolStripMenuSelectList("printoptions",true);
@ -942,24 +950,32 @@ namespace Greenshot {
foreach(string propertyName in conf.Values.Keys) { foreach(string propertyName in conf.Values.Keys) {
if (propertyName.StartsWith("OutputPrint")) { if (propertyName.StartsWith("OutputPrint")) {
iniValue = conf.Values[propertyName]; iniValue = conf.Values[propertyName];
if (iniValue.Attributes.LanguageKey != null) { if (iniValue.Attributes.LanguageKey != null && !iniValue.Attributes.FixedValue) {
selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value);
} }
} }
} }
selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); if (selectList.DropDownItems.Count > 0) {
this.contextmenu_quicksettings.DropDownItems.Add(selectList); selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged);
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
}
// effects // effects
selectList = new ToolStripMenuSelectList("effects",true); selectList = new ToolStripMenuSelectList("effects",true);
selectList.Text = Language.GetString(LangKey.settings_visualization); selectList.Text = Language.GetString(LangKey.settings_visualization);
iniValue = conf.Values["PlayCameraSound"]; iniValue = conf.Values["PlayCameraSound"];
selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); if (!iniValue.Attributes.FixedValue) {
selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value);
}
iniValue = conf.Values["ShowTrayNotification"]; iniValue = conf.Values["ShowTrayNotification"];
selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); if (!iniValue.Attributes.FixedValue) {
selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value);
this.contextmenu_quicksettings.DropDownItems.Add(selectList); }
if (selectList.DropDownItems.Count > 0) {
selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged);
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
}
} }
void QuickSettingCaptureModeChanged(object sender, EventArgs e) { void QuickSettingCaptureModeChanged(object sender, EventArgs e) {

View file

@ -255,6 +255,10 @@ namespace Greenshot {
/// Build the view with all the destinations /// Build the view with all the destinations
/// </summary> /// </summary>
private void DisplayDestinations() { private void DisplayDestinations() {
bool destinationsEnabled = true;
if (coreConfiguration.Values.ContainsKey("Destinations")) {
destinationsEnabled = !coreConfiguration.Values["Destinations"].Attributes.FixedValue;
}
checkbox_picker.Checked = false; checkbox_picker.Checked = false;
listview_destinations.Items.Clear(); listview_destinations.Items.Clear();
@ -289,6 +293,8 @@ namespace Greenshot {
item.Checked = false; item.Checked = false;
} }
} }
checkbox_picker.Enabled = destinationsEnabled;
listview_destinations.Enabled = destinationsEnabled;
} }
private void DisplaySettings() { private void DisplaySettings() {
@ -304,9 +310,16 @@ namespace Greenshot {
if (Language.CurrentLanguage != null) { if (Language.CurrentLanguage != null) {
combobox_language.SelectedValue = Language.CurrentLanguage; combobox_language.SelectedValue = Language.CurrentLanguage;
} }
// Disable editing when the value is fixed
combobox_language.Enabled = !coreConfiguration.Values["Language"].Attributes.FixedValue;
textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false); textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false);
// Disable editing when the value is fixed
textbox_storagelocation.Enabled = !coreConfiguration.Values["OutputFilePath"].Attributes.FixedValue;
SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); SetWindowCaptureMode(coreConfiguration.WindowCaptureMode);
// Disable editing when the value is fixed
combobox_window_capture_mode.Enabled = !coreConfiguration.Values["WindowCaptureMode"].Attributes.FixedValue;
trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality;
textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality+"%"; textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality+"%";
@ -477,7 +490,11 @@ namespace Greenshot {
void CheckDestinationSettings() { void CheckDestinationSettings() {
bool clipboardDestinationChecked = false; bool clipboardDestinationChecked = false;
bool pickerSelected = checkbox_picker.Checked; bool pickerSelected = checkbox_picker.Checked;
listview_destinations.Enabled = true; bool destinationsEnabled = true;
if (coreConfiguration.Values.ContainsKey("Destinations")) {
destinationsEnabled = !coreConfiguration.Values["Destinations"].Attributes.FixedValue;
}
listview_destinations.Enabled = destinationsEnabled;
foreach(int index in listview_destinations.CheckedIndices) { foreach(int index in listview_destinations.CheckedIndices) {
ListViewItem item = listview_destinations.Items[index]; ListViewItem item = listview_destinations.Items[index];

View file

@ -389,20 +389,23 @@ namespace GreenshotPlugin.Controls {
CheckBox checkBox = controlObject as CheckBox; CheckBox checkBox = controlObject as CheckBox;
if (checkBox != null) { if (checkBox != null) {
checkBox.Checked = (bool)iniValue.Value; checkBox.Checked = (bool)iniValue.Value;
checkBox.Enabled = !iniValue.Attributes.FixedValue;
continue; continue;
} }
TextBox textBox = controlObject as TextBox; TextBox textBox = controlObject as TextBox;
if (textBox != null) { if (textBox != null) {
HotkeyControl hotkeyControl = controlObject as HotkeyControl; HotkeyControl hotkeyControl = controlObject as HotkeyControl;
if (hotkeyControl != null) { if (hotkeyControl != null) {
string hotkeyValue = (string)iniValue.Value; string hotkeyValue = (string)iniValue.Value;
if (!string.IsNullOrEmpty(hotkeyValue)) { if (!string.IsNullOrEmpty(hotkeyValue)) {
hotkeyControl.SetHotkey(hotkeyValue); hotkeyControl.SetHotkey(hotkeyValue);
} hotkeyControl.Enabled = !iniValue.Attributes.FixedValue;
continue; }
} continue;
textBox.Text = iniValue.ToString(); }
textBox.Text = iniValue.ToString();
textBox.Enabled = !iniValue.Attributes.FixedValue;
continue; continue;
} }
@ -410,9 +413,9 @@ namespace GreenshotPlugin.Controls {
if (comboxBox != null) { if (comboxBox != null) {
comboxBox.Populate(iniValue.ValueType); comboxBox.Populate(iniValue.ValueType);
comboxBox.SetValue((Enum)iniValue.Value); comboxBox.SetValue((Enum)iniValue.Value);
comboxBox.Enabled = !iniValue.Attributes.FixedValue;
continue; continue;
} }
} }
} }
} }

View file

@ -50,6 +50,7 @@ namespace Greenshot.IniFile {
public string Separator = ","; public string Separator = ",";
public string DefaultValue; public string DefaultValue;
public string LanguageKey; public string LanguageKey;
public bool FixedValue = false;
public bool ExcludeIfNull=false; public bool ExcludeIfNull=false;
public string Name { public string Name {

View file

@ -39,6 +39,7 @@ namespace Greenshot.IniFile {
private static Dictionary<string, IniSection> sectionMap = new Dictionary<string, IniSection>(); private static Dictionary<string, IniSection> sectionMap = new Dictionary<string, IniSection>();
private static Dictionary<string, Dictionary<string, string>> sections = new Dictionary<string, Dictionary<string, string>>(); private static Dictionary<string, Dictionary<string, string>> sections = new Dictionary<string, Dictionary<string, string>>();
private static Dictionary<string, Dictionary<string, string>> fixedProperties = null;
public static event FileSystemEventHandler IniChanged; public static event FileSystemEventHandler IniChanged;
private static bool portableCheckMade = false; private static bool portableCheckMade = false;
@ -224,10 +225,25 @@ namespace Greenshot.IniFile {
// Load the normal // Load the normal
Read(CreateIniLocation(configName + INI_EXTENSION)); Read(CreateIniLocation(configName + INI_EXTENSION));
// Load the fixed settings // Load the fixed settings
Read(CreateIniLocation(configName + FIXED_POSTFIX + INI_EXTENSION)); fixedProperties = Read(CreateIniLocation(configName + FIXED_POSTFIX + INI_EXTENSION));
foreach (IniSection section in sectionMap.Values) { foreach (IniSection section in sectionMap.Values) {
section.Fill(PropertiesForSection(section)); section.Fill(PropertiesForSection(section));
FixProperties(section);
}
}
private static void FixProperties(IniSection section) {
// Make properties unchangable
if (fixedProperties != null) {
Dictionary<string, string> fixedPropertiesForSection = null;
if (fixedProperties.TryGetValue(section.IniSectionAttribute.Name, out fixedPropertiesForSection)) {
foreach (string fixedPropertyKey in fixedPropertiesForSection.Keys) {
if (section.Values.ContainsKey(fixedPropertyKey)) {
section.Values[fixedPropertyKey].Attributes.FixedValue = true;
}
}
}
} }
} }
@ -235,10 +251,10 @@ namespace Greenshot.IniFile {
/// Read the ini file into the Dictionary /// Read the ini file into the Dictionary
/// </summary> /// </summary>
/// <param name="iniLocation">Path & Filename of ini file</param> /// <param name="iniLocation">Path & Filename of ini file</param>
private static void Read(string iniLocation) { private static Dictionary<string, Dictionary<string, string>> Read(string iniLocation) {
if (!File.Exists(iniLocation)) { if (!File.Exists(iniLocation)) {
//LOG.Info("Can't find file: " + iniLocation); LOG.Info("Can't find file: " + iniLocation);
return; return null;
} }
LOG.DebugFormat("Loading ini-file: {0}", iniLocation); LOG.DebugFormat("Loading ini-file: {0}", iniLocation);
//LOG.Info("Reading ini-properties from file: " + iniLocation); //LOG.Info("Reading ini-properties from file: " + iniLocation);
@ -264,6 +280,7 @@ namespace Greenshot.IniFile {
} }
} }
} }
return newSections;
} }
/// <summary> /// <summary>
@ -296,6 +313,7 @@ namespace Greenshot.IniFile {
// Store for later save & retrieval // Store for later save & retrieval
sectionMap.Add(sectionName, section); sectionMap.Add(sectionName, section);
section.Fill(PropertiesForSection(section)); section.Fill(PropertiesForSection(section));
FixProperties(section);
} }
if (section.IsDirty) { if (section.IsDirty) {
LOG.DebugFormat("Section {0} is marked dirty, saving!", sectionName); LOG.DebugFormat("Section {0} is marked dirty, saving!", sectionName);

View file

@ -123,7 +123,7 @@ namespace Greenshot.IniFile {
if (Attribute.IsDefined(fieldInfo, typeof(IniPropertyAttribute))) { if (Attribute.IsDefined(fieldInfo, typeof(IniPropertyAttribute))) {
if (!Values.ContainsKey(fieldInfo.Name)) { if (!Values.ContainsKey(fieldInfo.Name)) {
IniPropertyAttribute iniPropertyAttribute = (IniPropertyAttribute)fieldInfo.GetCustomAttributes(typeof(IniPropertyAttribute), false)[0]; IniPropertyAttribute iniPropertyAttribute = (IniPropertyAttribute)fieldInfo.GetCustomAttributes(typeof(IniPropertyAttribute), false)[0];
Values.Add(fieldInfo.Name, new IniValue(this, fieldInfo, iniPropertyAttribute)); Values.Add(iniPropertyAttribute.Name, new IniValue(this, fieldInfo, iniPropertyAttribute));
} }
} }
} }
@ -132,7 +132,7 @@ namespace Greenshot.IniFile {
if (Attribute.IsDefined(propertyInfo, typeof(IniPropertyAttribute))) { if (Attribute.IsDefined(propertyInfo, typeof(IniPropertyAttribute))) {
if (!Values.ContainsKey(propertyInfo.Name)) { if (!Values.ContainsKey(propertyInfo.Name)) {
IniPropertyAttribute iniPropertyAttribute = (IniPropertyAttribute)propertyInfo.GetCustomAttributes(typeof(IniPropertyAttribute), false)[0]; IniPropertyAttribute iniPropertyAttribute = (IniPropertyAttribute)propertyInfo.GetCustomAttributes(typeof(IniPropertyAttribute), false)[0];
Values.Add(propertyInfo.Name, new IniValue(this, propertyInfo, iniPropertyAttribute)); Values.Add(iniPropertyAttribute.Name, new IniValue(this, propertyInfo, iniPropertyAttribute));
} }
} }
} }

View file

@ -57,18 +57,27 @@ namespace Greenshot.IniFile {
} }
} }
/// <summary>
/// Returns the IniSection this value is contained in
/// </summary>
public IniSection ContainingIniSection { public IniSection ContainingIniSection {
get { get {
return containingIniSection; return containingIniSection;
} }
} }
/// <summary>
/// Get the in the ini file defined attributes
/// </summary>
public IniPropertyAttribute Attributes { public IniPropertyAttribute Attributes {
get { get {
return attributes; return attributes;
} }
} }
/// <summary>
/// Get the value for this IniValue
/// </summary>
public object Value { public object Value {
get { get {
if (propertyInfo == null) { if (propertyInfo == null) {
@ -86,6 +95,9 @@ namespace Greenshot.IniFile {
} }
} }
/// <summary>
/// Get the Type of the value
/// </summary>
public Type ValueType { public Type ValueType {
get { get {
Type valueType = null; Type valueType = null;