Comments & save button

This commit is contained in:
Crom (Thibaut CHARLES) 2014-11-17 15:49:53 +01:00
parent 2018c0ef83
commit b384a661d4
1 changed files with 18 additions and 13 deletions

View File

@ -26,28 +26,34 @@ void[] Serialize(VT...)(VT data){
void main(string[] args) void main(string[] args)
{ {
//Parse 2da
auto twoda = new TwoDA(args[1]); auto twoda = new TwoDA(args[1]);
Main.init(args); Main.init(args);
//Window
auto window = new MainWindow("2DA-Edit"); auto window = new MainWindow("2DA-Edit");
//Header bar
auto header = new HeaderBar(); auto header = new HeaderBar();
window.setTitlebar(header); window.setTitlebar(header);
header.setTitle("2DAEdit"); header.setTitle("2DAEdit");
header.setSubtitle(args[1]); header.setSubtitle(args[1]);
header.setProperty("show-close-button", true); header.setProperty("show-close-button", true);
header.packEnd(new Button("coucou")); auto saveButton = new Button(StockID.SAVE);
header.packEnd(saveButton);
//Database for 2da GTK table
GType type[]; GType type[];
type~=GType.STRING; type~=GType.STRING;
foreach(i;1..twoda.header.length)type~=GType.STRING; foreach(i;1..twoda.header.length)type~=GType.STRING;
auto store = new ListStore(type); auto store = new ListStore(type);
saveButton.addOnClicked((Button){Save(store, twoda.header.length);});
//TreeView to display database
auto tree = new TreeView(store); auto tree = new TreeView(store);
window.add(tree); window.add(tree);
tree.setHeadersVisible(true); tree.setHeadersVisible(true);
tree.setEnableSearch(true); tree.setEnableSearch(true);
tree.setModel(store); tree.setModel(store);
@ -56,7 +62,7 @@ void main(string[] args)
tree.setProperty("reorderable", true); tree.setProperty("reorderable", true);
tree.setProperty("headers-clickable", true); tree.setProperty("headers-clickable", true);
//Setup TreeView columns
foreach(index, s ; twoda.header){ foreach(index, s ; twoda.header){
CellRendererText cr; CellRendererText cr;
@ -78,15 +84,14 @@ void main(string[] args)
} }
cr.setData("colnumber", cast(void*)cast(int)index); cr.setData("colnumber", cast(void*)cast(int)index);
//cr.setSensitive(true);
auto col = new TreeViewColumn(s, cr, "text", cast(int)index); auto col = new TreeViewColumn(s, cr, "text", cast(int)index);
col.setResizable(true); col.setResizable(true);
//if(index!=0) col.setReorderable(true); //col.setReorderable(true);
tree.appendColumn(col); tree.appendColumn(col);
} }
//Fill database
TreeIter iter = new TreeIter(); TreeIter iter = new TreeIter();
for(int i=0 ; i<=twoda.lastLine ; i++){ for(int i=0 ; i<=twoda.lastLine ; i++){
@ -103,26 +108,26 @@ void main(string[] args)
store.setValue(iter, cast(int)index+1, "_"); store.setValue(iter, cast(int)index+1, "_");
} }
} }
} }
//Autosize columns
tree.columnsAutosize(); tree.columnsAutosize();
window.showAll(); window.showAll();
Main.run();
}
//prints the tree model void Save(ref ListStore store, size_t columns){
TreeIter it = new TreeIter(); TreeIter it = new TreeIter();
store.getIterFirst(it);//TODO: fail if first is null store.getIterFirst(it);//TODO: fail if first is null
do{ do{
for(int i=0 ; i<twoda.header.length ; i++){ for(int i=0 ; i<columns ; i++){
write("\t",store.getValueString(it, i)); write("\t",store.getValueString(it, i));
} }
writeln(); writeln();
}while(store.iterNext(it)); }while(store.iterNext(it));
Main.run();
} }