mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
Improving the responsiveness of the editor and optimizing some general code.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1922 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
9d5e3e33be
commit
4f64dfe676
7 changed files with 192 additions and 158 deletions
|
@ -272,10 +272,9 @@ namespace Greenshot.IniFile {
|
|||
/// <param name="sectionName"></param>
|
||||
/// <returns></returns>
|
||||
public static IniSection GetIniSection(string sectionName) {
|
||||
if (sectionMap.ContainsKey(sectionName)) {
|
||||
return sectionMap[sectionName];
|
||||
}
|
||||
return null;
|
||||
IniSection returnValue = null;
|
||||
sectionMap.TryGetValue(sectionName, out returnValue);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -286,7 +285,7 @@ namespace Greenshot.IniFile {
|
|||
T section;
|
||||
|
||||
Type iniSectionType = typeof(T);
|
||||
string sectionName = getSectionName(iniSectionType);
|
||||
string sectionName = IniSection.GetIniSectionAttribute(iniSectionType).Name;
|
||||
if (sectionMap.ContainsKey(sectionName)) {
|
||||
//LOG.Debug("Returning pre-mapped section " + sectionName);
|
||||
section = (T)sectionMap[sectionName];
|
||||
|
@ -307,7 +306,7 @@ namespace Greenshot.IniFile {
|
|||
|
||||
public static Dictionary<string, string> PropertiesForSection(IniSection section) {
|
||||
Type iniSectionType = section.GetType();
|
||||
string sectionName = getSectionName(iniSectionType);
|
||||
string sectionName = section.IniSectionAttribute.Name;
|
||||
// Get the properties for the section
|
||||
Dictionary<string, string> properties = null;
|
||||
if (sections.ContainsKey(sectionName)) {
|
||||
|
@ -319,17 +318,6 @@ namespace Greenshot.IniFile {
|
|||
return properties;
|
||||
}
|
||||
|
||||
private static string getSectionName(Type iniSectionType) {
|
||||
Attribute[] classAttributes = Attribute.GetCustomAttributes(iniSectionType);
|
||||
foreach (Attribute attribute in classAttributes) {
|
||||
if (attribute is IniSectionAttribute) {
|
||||
IniSectionAttribute iniSectionAttribute = (IniSectionAttribute)attribute;
|
||||
return iniSectionAttribute.Name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Save() {
|
||||
string iniLocation = CreateIniLocation(configName + INI_EXTENSION);
|
||||
try {
|
||||
|
@ -340,7 +328,6 @@ namespace Greenshot.IniFile {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static void SaveInternally(string iniLocation) {
|
||||
WatchConfigFile(false);
|
||||
|
||||
|
|
|
@ -33,6 +33,16 @@ namespace Greenshot.IniFile {
|
|||
|
||||
[NonSerialized]
|
||||
private IDictionary<string, IniValue> values = new Dictionary<string, IniValue>();
|
||||
[NonSerialized]
|
||||
private IniSectionAttribute iniSectionAttribute = null;
|
||||
public IniSectionAttribute IniSectionAttribute {
|
||||
get {
|
||||
if (iniSectionAttribute == null) {
|
||||
iniSectionAttribute = GetIniSectionAttribute(this.GetType());
|
||||
}
|
||||
return iniSectionAttribute;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the dictionary with all the IniValues
|
||||
|
@ -86,6 +96,21 @@ namespace Greenshot.IniFile {
|
|||
public virtual void AfterSave() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to get the IniSectionAttribute of a type
|
||||
/// </summary>
|
||||
/// <param name="iniSectionType"></param>
|
||||
/// <returns></returns>
|
||||
public static IniSectionAttribute GetIniSectionAttribute(Type iniSectionType) {
|
||||
Attribute[] classAttributes = Attribute.GetCustomAttributes(iniSectionType);
|
||||
foreach (Attribute attribute in classAttributes) {
|
||||
if (attribute is IniSectionAttribute) {
|
||||
return (IniSectionAttribute)attribute;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill the section with the supplied properties
|
||||
/// </summary>
|
||||
|
@ -129,24 +154,16 @@ namespace Greenshot.IniFile {
|
|||
/// <param name="writer"></param>
|
||||
/// <param name="onlyProperties"></param>
|
||||
public void Write(TextWriter writer, bool onlyProperties) {
|
||||
if (IniSectionAttribute == null) {
|
||||
throw new ArgumentException("Section didn't implement the IniSectionAttribute");
|
||||
}
|
||||
BeforeSave();
|
||||
try {
|
||||
Attribute[] classAttributes = Attribute.GetCustomAttributes(this.GetType());
|
||||
IniSectionAttribute iniSectionAttribute = null;
|
||||
foreach (Attribute attribute in classAttributes) {
|
||||
if (attribute is IniSectionAttribute) {
|
||||
iniSectionAttribute = (IniSectionAttribute)attribute;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (iniSectionAttribute == null) {
|
||||
throw new ArgumentException("Section didn't implement the IniSectionAttribute");
|
||||
}
|
||||
|
||||
if (!onlyProperties) {
|
||||
writer.WriteLine("; {0}", iniSectionAttribute.Description);
|
||||
writer.WriteLine("; {0}", IniSectionAttribute.Description);
|
||||
}
|
||||
writer.WriteLine("[{0}]", iniSectionAttribute.Name);
|
||||
writer.WriteLine("[{0}]", IniSectionAttribute.Name);
|
||||
|
||||
foreach (IniValue value in Values.Values) {
|
||||
value.Write(writer, onlyProperties);
|
||||
|
|
|
@ -426,7 +426,5 @@ namespace Greenshot.IniFile {
|
|||
// All other types
|
||||
return valueObject.ToString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue