diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 33d9e2319..cd71cfbb4 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -900,39 +900,47 @@ namespace Greenshot { private void InitializeQuickSettingsMenu() { this.contextmenu_quicksettings.DropDownItems.Clear(); - if (conf.DisableQuickSettings) { - 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)); + if (conf.DisableQuickSettings) { + return; } - selectList.CheckedChanged += new EventHandler(this.QuickSettingDestinationChanged); - this.contextmenu_quicksettings.DropDownItems.Add(selectList); - // 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); + // Only add if the value is not fixed + if (!conf.Values["CaptureMousepointer"].Attributes.FixedValue) { + // 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); + } + 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 selectList = new ToolStripMenuSelectList("printoptions",true); @@ -942,24 +950,32 @@ namespace Greenshot { foreach(string propertyName in conf.Values.Keys) { if (propertyName.StartsWith("OutputPrint")) { 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.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); - this.contextmenu_quicksettings.DropDownItems.Add(selectList); + if (selectList.DropDownItems.Count > 0) { + selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); + this.contextmenu_quicksettings.DropDownItems.Add(selectList); + } // effects selectList = new ToolStripMenuSelectList("effects",true); selectList.Text = Language.GetString(LangKey.settings_visualization); 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"]; - selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); - selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); - this.contextmenu_quicksettings.DropDownItems.Add(selectList); + if (!iniValue.Attributes.FixedValue) { + selectList.AddItem(Language.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); + } + if (selectList.DropDownItems.Count > 0) { + selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); + this.contextmenu_quicksettings.DropDownItems.Add(selectList); + } } void QuickSettingCaptureModeChanged(object sender, EventArgs e) { diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index 34519f934..773191fb8 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -255,6 +255,10 @@ namespace Greenshot { /// Build the view with all the destinations /// private void DisplayDestinations() { + bool destinationsEnabled = true; + if (coreConfiguration.Values.ContainsKey("Destinations")) { + destinationsEnabled = !coreConfiguration.Values["Destinations"].Attributes.FixedValue; + } checkbox_picker.Checked = false; listview_destinations.Items.Clear(); @@ -289,6 +293,8 @@ namespace Greenshot { item.Checked = false; } } + checkbox_picker.Enabled = destinationsEnabled; + listview_destinations.Enabled = destinationsEnabled; } private void DisplaySettings() { @@ -304,9 +310,16 @@ namespace Greenshot { if (Language.CurrentLanguage != null) { 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); - + // Disable editing when the value is fixed + textbox_storagelocation.Enabled = !coreConfiguration.Values["OutputFilePath"].Attributes.FixedValue; + SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); + // Disable editing when the value is fixed + combobox_window_capture_mode.Enabled = !coreConfiguration.Values["WindowCaptureMode"].Attributes.FixedValue; trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality+"%"; @@ -477,7 +490,11 @@ namespace Greenshot { void CheckDestinationSettings() { bool clipboardDestinationChecked = false; 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) { ListViewItem item = listview_destinations.Items[index]; diff --git a/GreenshotPlugin/Controls/GreenshotForm.cs b/GreenshotPlugin/Controls/GreenshotForm.cs index e0852754a..70ab0e93c 100644 --- a/GreenshotPlugin/Controls/GreenshotForm.cs +++ b/GreenshotPlugin/Controls/GreenshotForm.cs @@ -389,20 +389,23 @@ namespace GreenshotPlugin.Controls { CheckBox checkBox = controlObject as CheckBox; if (checkBox != null) { checkBox.Checked = (bool)iniValue.Value; + checkBox.Enabled = !iniValue.Attributes.FixedValue; continue; } TextBox textBox = controlObject as TextBox; if (textBox != null) { - HotkeyControl hotkeyControl = controlObject as HotkeyControl; - if (hotkeyControl != null) { - string hotkeyValue = (string)iniValue.Value; - if (!string.IsNullOrEmpty(hotkeyValue)) { - hotkeyControl.SetHotkey(hotkeyValue); - } - continue; - } - textBox.Text = iniValue.ToString(); + HotkeyControl hotkeyControl = controlObject as HotkeyControl; + if (hotkeyControl != null) { + string hotkeyValue = (string)iniValue.Value; + if (!string.IsNullOrEmpty(hotkeyValue)) { + hotkeyControl.SetHotkey(hotkeyValue); + hotkeyControl.Enabled = !iniValue.Attributes.FixedValue; + } + continue; + } + textBox.Text = iniValue.ToString(); + textBox.Enabled = !iniValue.Attributes.FixedValue; continue; } @@ -410,9 +413,9 @@ namespace GreenshotPlugin.Controls { if (comboxBox != null) { comboxBox.Populate(iniValue.ValueType); comboxBox.SetValue((Enum)iniValue.Value); + comboxBox.Enabled = !iniValue.Attributes.FixedValue; continue; } - } } } diff --git a/GreenshotPlugin/IniFile/IniAttributes.cs b/GreenshotPlugin/IniFile/IniAttributes.cs index 2b8faa7cf..b106062b1 100644 --- a/GreenshotPlugin/IniFile/IniAttributes.cs +++ b/GreenshotPlugin/IniFile/IniAttributes.cs @@ -50,6 +50,7 @@ namespace Greenshot.IniFile { public string Separator = ","; public string DefaultValue; public string LanguageKey; + public bool FixedValue = false; public bool ExcludeIfNull=false; public string Name { diff --git a/GreenshotPlugin/IniFile/IniConfig.cs b/GreenshotPlugin/IniFile/IniConfig.cs index 65331c581..ba648bda3 100644 --- a/GreenshotPlugin/IniFile/IniConfig.cs +++ b/GreenshotPlugin/IniFile/IniConfig.cs @@ -39,6 +39,7 @@ namespace Greenshot.IniFile { private static Dictionary sectionMap = new Dictionary(); private static Dictionary> sections = new Dictionary>(); + private static Dictionary> fixedProperties = null; public static event FileSystemEventHandler IniChanged; private static bool portableCheckMade = false; @@ -224,10 +225,25 @@ namespace Greenshot.IniFile { // Load the normal Read(CreateIniLocation(configName + INI_EXTENSION)); // 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) { section.Fill(PropertiesForSection(section)); + FixProperties(section); + } + } + + private static void FixProperties(IniSection section) { + // Make properties unchangable + if (fixedProperties != null) { + Dictionary 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 /// /// Path & Filename of ini file - private static void Read(string iniLocation) { + private static Dictionary> Read(string iniLocation) { if (!File.Exists(iniLocation)) { - //LOG.Info("Can't find file: " + iniLocation); - return; + LOG.Info("Can't find file: " + iniLocation); + return null; } LOG.DebugFormat("Loading ini-file: {0}", iniLocation); //LOG.Info("Reading ini-properties from file: " + iniLocation); @@ -264,6 +280,7 @@ namespace Greenshot.IniFile { } } } + return newSections; } /// @@ -296,6 +313,7 @@ namespace Greenshot.IniFile { // Store for later save & retrieval sectionMap.Add(sectionName, section); section.Fill(PropertiesForSection(section)); + FixProperties(section); } if (section.IsDirty) { LOG.DebugFormat("Section {0} is marked dirty, saving!", sectionName); diff --git a/GreenshotPlugin/IniFile/IniSection.cs b/GreenshotPlugin/IniFile/IniSection.cs index f7ae8fa23..91082a578 100644 --- a/GreenshotPlugin/IniFile/IniSection.cs +++ b/GreenshotPlugin/IniFile/IniSection.cs @@ -123,7 +123,7 @@ namespace Greenshot.IniFile { if (Attribute.IsDefined(fieldInfo, typeof(IniPropertyAttribute))) { if (!Values.ContainsKey(fieldInfo.Name)) { 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 (!Values.ContainsKey(propertyInfo.Name)) { 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)); } } } diff --git a/GreenshotPlugin/IniFile/IniValue.cs b/GreenshotPlugin/IniFile/IniValue.cs index e2cbbf0e6..11a370572 100644 --- a/GreenshotPlugin/IniFile/IniValue.cs +++ b/GreenshotPlugin/IniFile/IniValue.cs @@ -57,18 +57,27 @@ namespace Greenshot.IniFile { } } + /// + /// Returns the IniSection this value is contained in + /// public IniSection ContainingIniSection { get { return containingIniSection; } } + /// + /// Get the in the ini file defined attributes + /// public IniPropertyAttribute Attributes { get { return attributes; } } + /// + /// Get the value for this IniValue + /// public object Value { get { if (propertyInfo == null) { @@ -86,6 +95,9 @@ namespace Greenshot.IniFile { } } + /// + /// Get the Type of the value + /// public Type ValueType { get { Type valueType = null;