Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bux committed Jul 24, 2014
1 parent 4eb3e67 commit 6409c97
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 68 deletions.
2 changes: 1 addition & 1 deletion tabler/AddLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace tabler
{
public partial class AddLanguage : Form
{
private GridUI _myParent;
private readonly GridUI _myParent;

public AddLanguage(GridUI parent)
{
Expand Down
1 change: 0 additions & 1 deletion tabler/Classes/CellEditHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace tabler
{
public class CellEditHistory
{

public int CellColumnIndex { get; set; }

public int CellRowIndex { get; set; }
Expand Down
1 change: 0 additions & 1 deletion tabler/Classes/ModInfoContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ public class ModInfoContainer

public string Name { get; set; }
public FileInfo FileInfoStringTable { get; set; }

}
}
8 changes: 3 additions & 5 deletions tabler/Classes/TranslationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class TranslationManager

public TranslationManager()
{

}

public TranslationManager(FileInfo fiExcelFile)
Expand All @@ -37,9 +36,9 @@ private List<string> PrepareHeaders(List<string> headers, bool insertMod)
headers.Insert(0, COLUMN_IDNAME);
if (insertMod)
{
headers.Insert(0, COLUMN_MODNAME);
headers.Insert(0, COLUMN_MODNAME);
}


//remove duplicates
headers = headers.Distinct().ToList();
Expand All @@ -50,7 +49,7 @@ private List<string> PrepareHeaders(List<string> headers, bool insertMod)

public void ConvertXmlToExcel(DirectoryInfo lastPathToDataFiles, bool insertMod)
{
var transComp = GetTranslationComponents(lastPathToDataFiles, insertMod);
TranslationComponents transComp = GetTranslationComponents(lastPathToDataFiles, insertMod);

var eh = new ExcelHelper();
ExcelPackage pck = eh.CreateExcelDoc(_fiExcelFile);
Expand Down Expand Up @@ -112,6 +111,5 @@ public void SaveGridData(DirectoryInfo lastPathToDataFiles, List<ModInfoContaine
{
SaveModInfosToXml(lastPathToDataFiles, lstModInfos);
}

}
}
6 changes: 2 additions & 4 deletions tabler/GridUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace tabler
public partial class GridUI : Form
{
public readonly ConfigHelper ConfigHelper;
private readonly TranslationManager _tm;
private GridUiHelper _gridUiHelper;
private TranslationManager _tm;

public GridUI()
{
Expand Down Expand Up @@ -99,14 +99,13 @@ public void HandleAddLanguage(string newLanguage)

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{

if (_gridUiHelper == null)
{
Close();
return;
}

var canClose = _gridUiHelper.CanClose();
bool canClose = _gridUiHelper.CanClose();
if (canClose)
{
Close();
Expand All @@ -118,7 +117,6 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Close();
}
}

}
}
}
12 changes: 4 additions & 8 deletions tabler/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ namespace tabler
{
public class ConfigHelper
{

private XDocument _xDocConfig;

private Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

private readonly FileInfo _fiConfig = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\config.xml"));

private const string LASTPATHTODATAFILES = "LastPathToDataFiles";
private readonly FileInfo _fiConfig = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\config.xml"));
private Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

private DirectoryInfo _lastPathToDataFiles;
private XDocument _xDocConfig;

public ConfigHelper()
{
Expand All @@ -41,7 +37,7 @@ public void CreateOrLoadConfig()
}
else
{
var path = new XElement((XName) LASTPATHTODATAFILES);
var path = new XElement(LASTPATHTODATAFILES);

//XElement config = new XElement("config",
// new XElement("lastSavePath",
Expand Down
2 changes: 1 addition & 1 deletion tabler/Helper/ExcelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void CreateHeaderRow(ExcelPackage pck, List<string> lstLanguages)
// {
// return currentColumn;
// }

// }

// return -1;
Expand Down
50 changes: 25 additions & 25 deletions tabler/Helper/GridUiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,31 @@ public void Undo()
EditHistory.Remove(lastEdit);
}

public void AddLanguage(string newLanguage)
{
if (_tc.Headers.Any(l => l.ToLowerInvariant() == newLanguage.ToLowerInvariant()))
{
return;
}

foreach (TabPage tabPage in _gridUi.tabControl1.TabPages)
{
var grid = (DataGridView) tabPage.Controls[0];

var dgvc = new DataGridViewTextBoxColumn();
dgvc.HeaderText = newLanguage;
dgvc.SortMode = DataGridViewColumnSortMode.NotSortable;

grid.Columns.Add(dgvc);
}
_tc.Headers.Add(newLanguage);
}

public bool CanClose()
{
return !EditHistory.Any();
}

#region " Events "

private void gridView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
Expand Down Expand Up @@ -344,30 +369,5 @@ private void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs
}

#endregion

public void AddLanguage(string newLanguage)
{
if (_tc.Headers.Any(l => l.ToLowerInvariant() == newLanguage.ToLowerInvariant()))
{
return;
}

foreach (TabPage tabPage in _gridUi.tabControl1.TabPages)
{
var grid = (DataGridView)tabPage.Controls[0];

var dgvc = new DataGridViewTextBoxColumn();
dgvc.HeaderText = newLanguage;
dgvc.SortMode = DataGridViewColumnSortMode.NotSortable;

grid.Columns.Add(dgvc);
}
_tc.Headers.Add(newLanguage);
}

public bool CanClose()
{
return !EditHistory.Any();
}
}
}
16 changes: 6 additions & 10 deletions tabler/Helper/XmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public void UpdateXmlFiles(List<FileInfo> filesByNameInDirectory, List<ModInfoCo

// Now check if someone deleted a row
IEnumerable<XElement> keysInXml = xdoc.Descendants().Where(x => x.Name == KEY_NAME);
foreach (var currentKeyElement in keysInXml.ToList())
foreach (XElement currentKeyElement in keysInXml.ToList())
{
string currentKeyId = currentKeyElement.Attribute(ID_NAME).Value;
if (foundModInfo.Values.Keys.Contains(currentKeyId))
{
var a = true;
bool a = true;
}
else
{
Expand All @@ -121,12 +121,9 @@ public void UpdateXmlFiles(List<FileInfo> filesByNameInDirectory, List<ModInfoCo

if (changed)
{
XComment comment = (from node in xdoc.Nodes() where node.NodeType == XmlNodeType.Comment select node as XComment).FirstOrDefault();

var comment = (from node in xdoc.Nodes()
where node.NodeType == XmlNodeType.Comment
select node as XComment).FirstOrDefault();

var commentText = String.Format(" Edited with tabler - {0} ", DateTime.Now.ToShortDateString());
string commentText = String.Format(" Edited with tabler - {0} ", DateTime.Now.ToShortDateString());

if (comment == null)
{
Expand All @@ -136,7 +133,7 @@ public void UpdateXmlFiles(List<FileInfo> filesByNameInDirectory, List<ModInfoCo
{
comment.Value = commentText;
}

xdoc.Save(currentFileInfo.FullName);
}
}
Expand Down Expand Up @@ -195,14 +192,13 @@ private bool UpdateOrInsertValue(XDocument xdoc, string id, string language, str
//exist -> update (or delete)
if (xLanguage.Value != value)
{

if (string.IsNullOrEmpty(value))
{
xLanguage.Remove();
}
else
{
xLanguage.Value = value;
xLanguage.Value = value;
}

changed = true;
Expand Down
13 changes: 5 additions & 8 deletions tabler/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace tabler
{
static class Program
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
private static void Main(string[] args)
{
if (!args.Any())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new GridUI());
Application.Run(new GridUI());
}

}
}
}
}
4 changes: 2 additions & 2 deletions tabler/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: AssemblyVersion("0.2.0")]
[assembly: AssemblyFileVersion("0.2.0")]
4 changes: 2 additions & 2 deletions tabler/tabler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<AssemblyName>tabler</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -22,8 +23,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<ApplicationVersion>0.2.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down

0 comments on commit 6409c97

Please sign in to comment.