Browse Source

GUI: Open from CSV file, if one file is chosen

Johannes Hofmann 7 years ago
parent
commit
d0866730b3
1 changed files with 27 additions and 11 deletions
  1. 27
    11
      gui_gtk/main.cpp

+ 27
- 11
gui_gtk/main.cpp View File

1
 #include <math.h>
1
 #include <math.h>
2
 #include <iostream>
2
 #include <iostream>
3
+#include <clocale>
3
 using namespace std;
4
 using namespace std;
4
 
5
 
5
 #include <gtk/gtk.h>
6
 #include <gtk/gtk.h>
168
 
169
 
169
     bool ok = true;
170
     bool ok = true;
170
     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
171
     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
171
-        GSList *list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
172
-        vector<string> new_list;
173
-
174
-        GSList *element = list;
175
-        while (element != NULL) {
176
-            ok = ok && gui->stack.add_from_file_path((const char*)(element->data));
177
-            g_free(element->data);
178
-            element = g_slist_next(element);
179
-            if (!ok) {
180
-                break;
172
+        vector<string> path_list;
173
+
174
+        {
175
+            GSList *list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
176
+
177
+            GSList *element = list;
178
+            while (element != NULL) {
179
+                path_list.push_back(string((const char*)(element->data)));
180
+                g_free(element->data);
181
+                element = g_slist_next(element);
182
+                if (!ok) {
183
+                    break;
184
+                }
181
             }
185
             }
186
+
187
+            g_slist_free(list);
182
         }
188
         }
183
 
189
 
184
-        g_slist_free(list);
190
+        if (path_list.size() == 1) {
191
+            ok = gui->stack.read_from_csv_file(path_list[0].c_str());
192
+        } else {
193
+            for (unsigned int i = 0; i < path_list.size(); i++) {
194
+                ok = ok && gui->stack.add_from_file_path(path_list[i].c_str());
195
+            }
196
+        }
185
     }
197
     }
186
 
198
 
187
     if (ok) {
199
     if (ok) {
258
 
270
 
259
     gtk_widget_show_all(gui.window);
271
     gtk_widget_show_all(gui.window);
260
 
272
 
273
+    // Set C-locale number format.
274
+    // Make strtod work with strings like "0.1" (instead of "0,1")
275
+    std::setlocale(LC_NUMERIC, "C");
276
+
261
     gtk_main ();
277
     gtk_main ();
262
 
278
 
263
     return 0;
279
     return 0;