From 9926b68c26244bb7e4d4a4c0aba4e8272c985e87 Mon Sep 17 00:00:00 2001 From: "Crom (Thibaut CHARLES)" Date: Fri, 13 Mar 2015 09:57:10 +0100 Subject: [PATCH] Parse exceptions & open new window if the one used is full --- source/twoda.d | 8 +++++--- source/window.d | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/twoda.d b/source/twoda.d index 1da78af..29a014b 100644 --- a/source/twoda.d +++ b/source/twoda.d @@ -20,8 +20,8 @@ class TwoDA{ string data[]; auto results = matchAll(line, rgxField); - if(results.hit is null) - throw new ParseException(filepath~":"~index.to!string~" Incorrect 2da line (not parseable)"); + if(results.empty) + throw new ParseException("Could not parse fields in line: "~filepath~":"~index.to!string); foreach(res ; results){ string s; @@ -31,9 +31,11 @@ class TwoDA{ if(index==0){ header = data; - //writeln(header); } else{ + if(data.length != header.length) + throw new ParseException("Incorrect number of fields: "~filepath~":"~index.to!string); + int nLine = data[0].to!int; values[nLine] = data[1..$]; //writeln(values[nLine]); diff --git a/source/window.d b/source/window.d index 8a6457a..8e94ffd 100644 --- a/source/window.d +++ b/source/window.d @@ -340,9 +340,26 @@ class Window : MainWindow{ void open(string file, ref TreeView tree){ + writeln("Opening ",file); + TwoDA twoda; + try{ + twoda = new TwoDA(file); + } + catch(Exception e){ + import gtk.MessageDialog; + auto md = new MessageDialog(this, GtkDialogFlags.MODAL, GtkMessageType.ERROR, GtkButtonsType.CLOSE, "Could not open 2da:\n"~e.msg, null); + md.run(); + md.destroy(); + return; + } - auto twoda = new TwoDA(file); + //Open in new window + if(openedFile!=null){ + new Window(file); + return; + } + //Open in same window openedFile = file; header.setSubtitle(openedFile);