Skip to content

Commit

Permalink
Add Setting to remove options
Browse files Browse the repository at this point in the history
  • Loading branch information
bux committed Jul 3, 2015
1 parent d123b2d commit 97b33ae
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 123 deletions.
2 changes: 2 additions & 0 deletions tabler/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ namespace tabler.Classes {
public class Settings {
public IndentationSettings IndentationSettings { get; set; }
public int TabSize { get; set; }
public bool RemoveEmptyNodes { get; set; }

public Settings() {
// defaults
IndentationSettings = IndentationSettings.Spaces;
TabSize = 4;
RemoveEmptyNodes = true;
}

}
Expand Down
16 changes: 15 additions & 1 deletion tabler/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ConfigHelper {
private const string LASTPATHTODATAFILES_NAME = "LastPathToDataFiles";
private const string INDENTATION_NAME = "Indentation";
private const string TABSIZE_NAME = "TabSize";
private const string EMPTYNODES_NAME = "RemoveEmptyNodes";

private readonly FileInfo _fiConfig = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\config.xml"));
private XDocument _xDocConfig;
Expand All @@ -36,8 +37,9 @@ private XDocument CreateOrLoadConfig(bool forceCreation) {
var path = new XElement(LASTPATHTODATAFILES_NAME);
var indent = new XElement(INDENTATION_NAME, 0);
var tabsize = new XElement(TABSIZE_NAME, 4);
var removeEmptyNodes = new XElement(EMPTYNODES_NAME, true);

var lstElements = new List<XElement> { path, indent, tabsize };
var lstElements = new List<XElement> { path, indent, tabsize, removeEmptyNodes };

_xDocConfig = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
Expand Down Expand Up @@ -135,6 +137,11 @@ public Settings GetSettings() {
loadedSettings.TabSize = int.Parse(tabSizeElement.Value);
}

var removeEmptyNodes = _xDocConfig.Descendants().FirstOrDefault(d => d.Name == EMPTYNODES_NAME);
if (removeEmptyNodes != null) {
loadedSettings.RemoveEmptyNodes = bool.Parse(removeEmptyNodes.Value);
}

return loadedSettings;
}

Expand Down Expand Up @@ -168,6 +175,13 @@ public bool SaveSettings(Settings settingsToSave) {
CreateOrLoadConfig(true);
}

var removeEmptyNodes = _xDocConfig.Descendants().FirstOrDefault(d => d.Name == EMPTYNODES_NAME);
if (removeEmptyNodes != null) {
removeEmptyNodes.Value = settingsToSave.RemoveEmptyNodes.ToString();
} else {
CreateOrLoadConfig(true);
}

SaveConfigXml();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tabler/Helper/GridUiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private DataGridView CreateGridViewAndFillWithData(TranslationComponents tc, str
row.Cells[index].Style.BackColor = Color.FromKnownColor(COLOR_BASELANGUAGE);
}

if (!translationsWithKey.Value.ContainsKey(header)) {
if (!translationsWithKey.Value.ContainsKey(header) || String.IsNullOrWhiteSpace(translationsWithKey.Value[header])) {
row.Cells[index].Style.BackColor = Color.FromKnownColor(COLOR_EMPTYCELL);
AddMissingTranslationToStatistics(tc.Statistics, header, currentModule);
} else {
Expand Down
7 changes: 6 additions & 1 deletion tabler/Helper/XmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,14 @@ public void UpdateXmlFiles(List<FileInfo> filesByNameInDirectory, List<ModInfoCo
xmlSettings.IndentChars = "\t";
}



if (settings.RemoveEmptyNodes) {
xdoc.Descendants().Where(d => d.IsEmpty || String.IsNullOrWhiteSpace(d.Value)).Remove();
}

}


using (var writer = XmlWriter.Create(currentFileInfo.FullName, xmlSettings)) {
xdoc.Save(writer);
}
Expand Down
23 changes: 23 additions & 0 deletions tabler/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tabler/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ private void btnSaveSettings_Click(object sender, System.EventArgs e) {
}
}

newSettings.RemoveEmptyNodes = cbRemoveEmptyNodes.Checked;

configHelper.SaveSettings(newSettings);
Close();
}
Expand Down
24 changes: 18 additions & 6 deletions tabler/SettingsForm.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,20 @@
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="btnCancel.Location" type="System.Drawing.Point, System.Drawing">
<value>114, 116</value>
<value>114, 142</value>
</data>
<data name="btnCancel.Text" xml:space="preserve">
<value>Abbrechen</value>
</data>
<data name="btnSaveSettings.Text" xml:space="preserve">
<value>Speichern</value>
</data>
<data name="grpBIndentation.Size" type="System.Drawing.Size, System.Drawing">
<value>177, 72</value>
</data>
<data name="grpBIndentation.Text" xml:space="preserve">
<value>Einrückung</value>
</data>
<data name="rbIndentSpaces.Size" type="System.Drawing.Size, System.Drawing">
<value>83, 17</value>
</data>
Expand All @@ -145,14 +151,20 @@
<data name="rbIndentTabs.Text" xml:space="preserve">
<value>Tabulatoren</value>
</data>
<data name="grpBIndentation.Size" type="System.Drawing.Size, System.Drawing">
<value>177, 72</value>
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
<value>177, 46</value>
</data>
<data name="grpBIndentation.Text" xml:space="preserve">
<value>Einrückung</value>
<data name="groupBox1.Text" xml:space="preserve">
<value>Leere Nodes</value>
</data>
<data name="cbRemoveEmptyNodes.Size" type="System.Drawing.Size, System.Drawing">
<value>160, 17</value>
</data>
<data name="cbRemoveEmptyNodes.Text" xml:space="preserve">
<value>Leere XML-Nodes entfernen</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>201, 151</value>
<value>201, 179</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
Loading

0 comments on commit 97b33ae

Please sign in to comment.