Skip to content

Commit

Permalink
Bugfix: changing the delimiter didn't set: changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Aug 22, 2015
1 parent 7cbc626 commit 39e2ded
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 38 deletions.
12 changes: 9 additions & 3 deletions Core/CsvDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ public bool SurroundText {
set { surroundText = value; Changed = true; }
}

public Delimiter Delimiter {
get { return delimiter; }
}
public string DelimiterValue {
get {
return this.delimiter.ToString();
}
set {
this.delimiter.Name = value;
this.Changed = true;
}
}

public DecimalMark.DecimalSeparator DecimalSeparator {
get {
Expand Down
14 changes: 7 additions & 7 deletions Core/CsvDocumentPersistence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void Load(string fileName, char delimiter = '\0', bool firstRowForHeaders
if ( delimiter == '\0' ) {
this.DetermineDelimiter( headers );
} else {
this.Document.Delimiter.Name = delimiter.ToString();
this.Document.DelimiterValue = delimiter.ToString();
}

// Check for the existence of a single line, and proceed
Expand Down Expand Up @@ -208,7 +208,7 @@ protected void DetermineDelimiter(string line)
if ( delimiterIndex < 0 ) {
throw new ApplicationException( "Unable to determine delimiter in file." );
} else {
Document.Delimiter.Name = Delimiter.PredefinedDelimiterNames[(int) delimiterIndex];
Document.DelimiterValue = Delimiter.PredefinedDelimiterNames[(int) delimiterIndex];
}

return;
Expand Down Expand Up @@ -240,7 +240,7 @@ private string[] SplitLine(string line)

// Delimiter found, add cell
if ( !inQuoted
&& line[ i ] == Document.Delimiter.Raw )
&& line[ i ] == Document.DelimiterValue[ 0 ] )
{
row.Add( PrepareValue( line.Substring( pos, i - pos ) ) );
pos = i + 1;
Expand All @@ -258,7 +258,7 @@ private string[] SplitLine(string line)
row.Add( PrepareValue( line.Substring( pos, line.Length - pos ) ) );
}
else
if ( line[ line.Length -1 ] == Document.Delimiter.Raw ) {
if ( line[ line.Length -1 ] == Document.DelimiterValue[ 0 ] ) {
row.Add( "" );
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ protected string QuoteValueForSaving(string cell)
delimitersAndSpace.Add( ' ' );

// ...and the current delimiter of the document (could be repeated)
delimitersAndSpace.Add( Document.Delimiter.Raw );
delimitersAndSpace.Add( Document.DelimiterValue[ 0 ] );

foreach(char ch in cell) {
if ( delimitersAndSpace.Contains( ch ) ) {
Expand Down Expand Up @@ -358,7 +358,7 @@ public void SaveCsvData(ExportOptions options)

// Write headers
if ( options.IncludeRowNumbers ) {
file.Write( "#" + Document.Delimiter );
file.Write( "#" + Document.DelimiterValue );
}

for(int col = 0; col < options.ColumnsIncluded.Length; ++col) {
Expand All @@ -374,7 +374,7 @@ public void SaveCsvData(ExportOptions options)
// Write each row
for(int row = 0; row < Document.Data.NumRows; ++row) {
if ( options.IncludeRowNumbers ) {
file.Write( Convert.ToString( row +1 ) + Document.Delimiter );
file.Write( Convert.ToString( row +1 ) + Document.DelimiterValue );
}

for(int col = 0; col < options.ColumnsIncluded.Length; ++col) {
Expand Down
39 changes: 24 additions & 15 deletions Core/Delimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Delimiter(char c)
/// <param name="d">The delimiter to use, as a string (can be special).</param>
public Delimiter(string d)
{
Name = d;
this.Name = d;
}

/// <summary>
Expand All @@ -46,21 +46,15 @@ public Delimiter(string d)
/// <seealso cref="TabDelimiterName"/>
public string Name {
get {
var toret = Raw.ToString();

if ( toret == "\t" ) {
toret = TabDelimiterName;
}

return toret;
return GetName( this.Raw );
}
set {
if ( !string.IsNullOrWhiteSpace( value ) ) {
if ( !string.IsNullOrEmpty( value ) ) {
if ( value == TabDelimiterName ) {
value = "\t";
}

this.raw = value[ 0 ];
this.Raw = value[ 0 ];
}

return;
Expand All @@ -83,13 +77,28 @@ public override string ToString()
/// </summary>
/// <value>The raw.</value>
public char Raw {
get {
return this.raw;
}
get; private set;
}

/// <summary>The raw value of the delimiter</summary>
private char raw;
public static string GetName(string delimiter) {
var toret = TabDelimiterName;

if ( !string.IsNullOrWhiteSpace( delimiter ) ) {
toret = GetName( delimiter[ 0 ] );
}

return toret;
}

public static string GetName(char delimiter) {
var toret = delimiter.ToString();

if ( toret == "\t" ) {
toret = TabDelimiterName;
}

return toret;
}
}
}

2 changes: 1 addition & 1 deletion Core/ExportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ExportOptions(String name, CsvDocument doc) {
this.name = name;
this.includeRowNumbers = false;
this.includeTableBorder = false;
this.delimiter = new Delimiter( doc.Delimiter.Raw );
this.delimiter = new Delimiter( doc.DelimiterValue );
this.QuotedText = doc.SurroundText;
this.Format = SelectionType.Html;

Expand Down
8 changes: 2 additions & 6 deletions Gui/DlgExportLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ public bool SurroundWithDoubleQuotes {
/// Gets the delimiter.
/// </summary>
/// <value>The delimiter, as a string of one position.</value>
public string Delimiter {
public string DelimiterValue {
get {
string delimiter = cmbDelimiter.Entry.Text.Trim();

if ( delimiter.Length > 0 )
return this.cmbDelimiter.Entry.Text;
else return Core.Delimiter.TabDelimiterName;
return Delimiter.GetName( cmbDelimiter.Entry.Text.Trim() );
}
}

Expand Down
2 changes: 1 addition & 1 deletion Gui/DlgExportView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void BuildCsvOptions() {
this.chkQuotes = new Gtk.CheckButton( "Enclose text with quotes" );

// Set options honoring current document
this.cmbDelimiter.Entry.Text = this.document.Delimiter.Name;
this.cmbDelimiter.Entry.Text = Delimiter.GetName( this.document.DelimiterValue );
chkQuotes.Active = this.document.SurroundText;

// Layout
Expand Down
2 changes: 1 addition & 1 deletion Gui/DlgPropertiesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void BuildPropertiesFrame() {
foreach(string delimiter in Delimiter.PredefinedDelimiterNames) {
cmbDelimiter.AppendText( delimiter );
}
cmbDelimiter.Entry.Text = document.Delimiter.Name;
cmbDelimiter.Entry.Text = Delimiter.GetName( this.document.DelimiterValue );

// Add decimal separators to its combo
foreach (char separator in DecimalMark.DecimalSeparatorChar) {
Expand Down
8 changes: 4 additions & 4 deletions Gui/MainWindowLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void SetTitle()
protected void ShowProjectInfo()
{
if ( this.document != null ) {
string delimiter = this.Document.Delimiter.Name;
string delimiter = Delimiter.GetName( this.Document.DelimiterValue );
string text = "field";
string number = "4";

Expand Down Expand Up @@ -532,7 +532,7 @@ private void OnExport()
options.IncludeRowNumbers = dlg.IncludeRowNumbers;
options.IncludeTableBorder = dlg.IncludeTableBorder;
options.ColumnsIncluded = dlg.ColumnsIncluded;
options.Delimiter.Name = dlg.Delimiter;
options.Delimiter.Name = dlg.DelimiterValue;
options.QuotedText = dlg.SurroundWithDoubleQuotes;

new CsvDocumentPersistence( Document ).Save( options );
Expand Down Expand Up @@ -603,7 +603,7 @@ private void ApplyPreferences(DlgProperties dlg)
this.document.DecimalSeparator = dlg.DecimalMarkValue;
}

this.document.Delimiter.Name = dlg.DelimiterValue;
this.document.DelimiterValue = dlg.DelimiterValue;
this.document.SurroundText = dlg.SurroundText;

// Check rows and headers size
Expand Down Expand Up @@ -933,7 +933,7 @@ private void OnRevert()
// Store the parameters and reload
var fileName = document.FileName;
var firstRowForHeaders = document.Data.FirstRowForHeaders;
char delimiter = document.Delimiter.Raw;
char delimiter = document.DelimiterValue[ 0 ];
this.document = null;

try {
Expand Down

0 comments on commit 39e2ded

Please sign in to comment.