[chronojump] Import multiple persons csv col delimiter depending on preferences



commit e1f0d0821fa73cc04014157222827b8bd24be312
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Sep 18 12:25:38 2018 +0200

    Import multiple persons csv col delimiter depending on preferences

 glade/preferences_win.glade |  2 +-
 src/gui/chronojump.cs       |  6 +++++-
 src/gui/person.cs           | 10 +++++++---
 src/utilCSV.cs              |  9 +++++++++
 4 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index bf2bac47..1da9b1d6 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -3610,7 +3610,7 @@ Other</property>
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Export to spreadsheet</property>
+                        <property name="label" translatable="yes">Spreadsheet import and export 
format</property>
                       </widget>
                       <packing>
                         <property name="expand">False</property>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index ee977134..fe97594e 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2775,7 +2775,11 @@ public partial class ChronoJumpWindow
 
        private void person_add_multiple ()
        {
-               personAddMultipleWin = PersonAddMultipleWindow.Show(app1, currentSession);
+               char columnDelimiter = ',';
+               if(preferences.CSVExportDecimalSeparator == "COMMA")
+                       columnDelimiter = ';';
+
+               personAddMultipleWin = PersonAddMultipleWindow.Show(app1, currentSession, columnDelimiter);
                personAddMultipleWin.Button_accept.Clicked -= new 
EventHandler(on_person_add_multiple_accepted);
                personAddMultipleWin.Button_accept.Clicked += new 
EventHandler(on_person_add_multiple_accepted);
        }
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 84113912..69bf1d79 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -2048,13 +2048,15 @@ public class PersonAddMultipleWindow {
 
        private Person currentPerson;
        Session currentSession;
+       char columnDelimiter;
        int personsCreatedCount;
        string errorExistsString;
        string errorWeightString;
        string errorRepeatedEntryString;
 
        
-       PersonAddMultipleWindow (Gtk.Window parent, Session currentSession) {
+       PersonAddMultipleWindow (Gtk.Window parent, Session currentSession, char columnDelimiter)
+       {
                Glade.XML gladeXML;
                gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "person_multiple_infinite.glade", 
"person_multiple_infinite", null);
                gladeXML.Autoconnect(this);
@@ -2064,12 +2066,13 @@ public class PersonAddMultipleWindow {
        
                person_multiple_infinite.Parent = parent;
                this.currentSession = currentSession;
+               this.columnDelimiter = columnDelimiter;
        }
        
-       static public PersonAddMultipleWindow Show (Gtk.Window parent, Session currentSession)
+       static public PersonAddMultipleWindow Show (Gtk.Window parent, Session currentSession, char 
columnDelimiter)
        {
                if (PersonAddMultipleWindowBox == null) {
-                       PersonAddMultipleWindowBox = new PersonAddMultipleWindow (parent, currentSession);
+                       PersonAddMultipleWindowBox = new PersonAddMultipleWindow (parent, currentSession, 
columnDelimiter);
                }
                
                PersonAddMultipleWindowBox.putNonStandardIcons ();
@@ -2215,6 +2218,7 @@ public class PersonAddMultipleWindow {
                        List<string> columns = new List<string>();
                        using (var reader = new CsvFileReader(fc.Filename))
                        {
+                               reader.ChangeDelimiter(columnDelimiter);
                                bool headersActive = check_headers.Active;
                                bool name1Column = check_name_1_column.Active;
                                int row = 0;
diff --git a/src/utilCSV.cs b/src/utilCSV.cs
index 6a0d4ee9..c7b4fc30 100644
--- a/src/utilCSV.cs
+++ b/src/utilCSV.cs
@@ -81,6 +81,10 @@ public abstract class CsvFileCommon
     /// These are special characters in CSV files. If a column contains any
     /// of these characters, the entire column is wrapped in double quotes.
     /// </summary>
+    ///
+    /// First char has to be , or ; depending on preferences latin or not
+    /// see method ChangeDelimiter()
+    ///
     protected char[] SpecialChars = new char[] { ',', '"', '\r', '\n' };
 
     // Indexes into SpecialChars for characters with specific meaning
@@ -143,6 +147,11 @@ public class CsvFileReader : CsvFileCommon, IDisposable
         EmptyLineBehavior = emptyLineBehavior;
     }
 
+    public void ChangeDelimiter(char delimiter)
+    {
+           Delimiter = delimiter;
+    }
+
     /// <summary>
     /// Reads a row of columns from the current CSV file. Returns false if no
     /// more data could be read because the end of the file was reached.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]