Parse exceptions & open new window if the one used is full

master
Crom (Thibaut CHARLES) 8 years ago
parent b0d70f028f
commit 9926b68c26

@ -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]);

@ -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);

Loading…
Cancel
Save