File saving, default size

This commit is contained in:
Crom (Thibaut CHARLES) 2014-11-18 15:20:39 +01:00
parent 10eeb673e8
commit 1fa225471e

View File

@ -30,7 +30,7 @@ void main(string[] args)
auto cont = new VBox(false, 0); auto cont = new VBox(false, 0);
window.add(cont); window.add(cont);
cont.setSizeRequest(0, 100); cont.setSizeRequest(300, 200);
auto buttonSave = new Button("document-save-symbolic", GtkIconSize.MENU); auto buttonSave = new Button("document-save-symbolic", GtkIconSize.MENU);
buttonSave.setTooltipText("Save"); buttonSave.setTooltipText("Save");
@ -160,15 +160,26 @@ void main(string[] args)
void Save(ref TreeView tree){ void Save(ref TreeView tree){
auto store = cast(ListStore)tree.getModel(); auto store = cast(ListStore)tree.getModel();
if(store !is null){ if(store !is null){
auto file = File(openedFile, "w");
foreach(i ; 0..tree.getNColumns)
file.write(tree.getColumn(i).getTitle, "\t");
file.write("\n");
TreeIter it = new TreeIter(); TreeIter it = new TreeIter();
if(store.getIterFirst(it)){ if(store.getIterFirst(it)){
do{ do{
std.stdio.write("\t",store.getValueInt(it, 0)); file.write(store.getValueInt(it, 0));
foreach(i ; 1..store.getNColumns()){ foreach(i ; 1..store.getNColumns()){
std.stdio.write("\t",store.getValueString(it, i)); file.write("\t\"",store.getValueString(it, i),"\"");
} }
writeln(); file.write("\n");
}while(store.iterNext(it)); }while(store.iterNext(it));
file.flush();
file.close();
writeln("File written: ",openedFile);
} }
} }
else else
@ -176,10 +187,13 @@ void Save(ref TreeView tree){
} }
string openedFile;
void Open(string file, ref TreeView tree, Object header){ void Open(string file, ref TreeView tree, Object header){
auto twoda = new TwoDA(file); auto twoda = new TwoDA(file);
openedFile = file;
version(Windows) (cast(Window)header).setTitle(file); version(Windows) (cast(Window)header).setTitle(file);
else{ else{
import gtk.HeaderBar; import gtk.HeaderBar;