Fix: segfault on column add

This commit is contained in:
Crom (Thibaut CHARLES) 2014-11-19 15:15:59 +01:00
parent 61885f57aa
commit 24a4fc9500
1 changed files with 13 additions and 9 deletions

View File

@ -104,10 +104,11 @@ void main(string[] args)
tree.addOnColumnsChanged((TreeView tree){ tree.addOnColumnsChanged((TreeView tree){
auto store = cast(ListStore)tree.getModel(); auto store = cast(ListStore)tree.getModel();
if(store.getColumnType(GetColumnStoreIndex(tree, 0)) != GType.INT){ int si = GetColumnStoreIndex(tree, 0);
writeln("Position 0 is forbidden"); if(si>=0 && store.getColumnType(si) != GType.INT){
foreach(i ; 0..store.getNColumns()){ foreach(i ; 0..store.getNColumns()){
if(store.getColumnType(GetColumnStoreIndex(tree, i))==GType.INT){ si = GetColumnStoreIndex(tree, i);
if(si>=0 && store.getColumnType(si)==GType.INT){
tree.moveColumnAfter(tree.getColumn(i), null); tree.moveColumnAfter(tree.getColumn(i), null);
break; break;
} }
@ -192,11 +193,6 @@ void main(string[] args)
auto store = new ListStore(types); auto store = new ListStore(types);
tree.setModel(store); tree.setModel(store);
//setup cols
foreach(i ; 0..newColIndex+1){
tree.appendColumn(SetupColumn(tree, titles[i], i));
}
//Fill them //Fill them
TreeIter oldit = new TreeIter(); TreeIter oldit = new TreeIter();
TreeIter newit = new TreeIter(); TreeIter newit = new TreeIter();
@ -217,6 +213,11 @@ void main(string[] args)
}while(oldstore.iterNext(oldit)); }while(oldstore.iterNext(oldit));
} }
//setup cols
foreach(i ; 0..newColIndex+1){
tree.appendColumn(SetupColumn(tree, titles[i], i));
}
oldstore.destroy(); oldstore.destroy();
}); });
@ -235,7 +236,10 @@ void main(string[] args)
} }
int GetColumnStoreIndex(TreeView tree, int colindex){ int GetColumnStoreIndex(TreeView tree, int colindex){
return cast(int)(tree.getColumn(colindex).getData("colnumber")); auto col = tree.getColumn(colindex);
if(col !is null)
return cast(int)(col.getData("colnumber"));
return -1;
} }
void Save(ref TreeView tree){ void Save(ref TreeView tree){