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

This commit is contained in:
Crom (Thibaut CHARLES) 2015-03-13 09:57:10 +01:00
parent b0d70f028f
commit 9926b68c26
2 changed files with 23 additions and 4 deletions

View File

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

View File

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