Bläddra i källkod

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

Johannes Hofmann 7 år sedan
förälder
incheckning
d0866730b3
1 ändrade filer med 27 tillägg och 11 borttagningar
  1. 27
    11
      gui_gtk/main.cpp

+ 27
- 11
gui_gtk/main.cpp Visa fil

@@ -1,5 +1,6 @@
1 1
 #include <math.h>
2 2
 #include <iostream>
3
+#include <clocale>
3 4
 using namespace std;
4 5
 
5 6
 #include <gtk/gtk.h>
@@ -168,20 +169,31 @@ void file_select_clicked(GtkButton *button, gpointer user_data) {
168 169
 
169 170
     bool ok = true;
170 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 199
     if (ok) {
@@ -258,6 +270,10 @@ int main(int argc, char *argv[])
258 270
 
259 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 277
     gtk_main ();
262 278
 
263 279
     return 0;