Build issues & column alignment

This commit is contained in:
Crom (Thibaut CHARLES) 2015-03-06 12:15:52 +01:00
parent 50100c3ea5
commit aaefc184e8

42
source/app.d Normal file → Executable file
View File

@ -119,6 +119,7 @@ void main(string[] args)
tree.setProperty("headers-clickable", true); tree.setProperty("headers-clickable", true);
tree.addOnColumnsChanged((TreeView tree){ tree.addOnColumnsChanged((TreeView tree){
auto store = cast(ListStore)tree.getModel(); auto store = cast(ListStore)tree.getModel();
if(store is null) return;
int si = GetColumnStoreIndex(tree, 0); int si = GetColumnStoreIndex(tree, 0);
if(si>=0 && store.getColumnType(si) != GType.INT){ if(si>=0 && store.getColumnType(si) != GType.INT){
@ -201,6 +202,7 @@ void main(string[] args)
buttonNewCol.addOnClicked((Button){ buttonNewCol.addOnClicked((Button){
auto oldstore = cast(ListStore)tree.getModel(); auto oldstore = cast(ListStore)tree.getModel();
if(oldstore is null) return;
int newColIndex = oldstore.getNColumns(); int newColIndex = oldstore.getNColumns();
@ -318,18 +320,42 @@ void Save(ref TreeView tree, string newpath=""){
SetTitle(openedFile); SetTitle(openedFile);
} }
auto file = File(openedFile, "w"); //Detect column sizes
ulong colSize[];
colSize.length = tree.getNColumns;
foreach(i ; 0..tree.getNColumns) foreach(i ; 0..tree.getNColumns)
file.write(tree.getColumn(i).getTitle, "\t"); colSize[i] = tree.getColumn(i).getTitle.length +1;//+1 space
file.write("\n");
TreeIter it = new TreeIter(); TreeIter it = new TreeIter();
if(store.getIterFirst(it)){ if(store.getIterFirst(it)){
do{ do{
file.write(store.getValueInt(it, 0)); import std.math : log10;
int size0 = log10(store.getValueInt(it, 0)+1).to!int +1;//+1 space
if(size0>colSize[0])
colSize[0] = size0;
foreach(i ; 1..store.getNColumns()){ foreach(i ; 1..store.getNColumns()){
file.write("\t\"", store.getValueString(it, GetColumnStoreIndex(tree, i)), "\""); int size = store.getValueString(it, GetColumnStoreIndex(tree, i)).length.to!int +3;//+2 double quotes added, +1 space
if(size>colSize[i])
colSize[i] = size;
}
}while(store.iterNext(it));
}
//Write file
auto file = File(openedFile, "w");
foreach(i ; 0..tree.getNColumns)
file.write(leftJustify(tree.getColumn(i).getTitle, colSize[i]));
file.write("\n");
it = new TreeIter();
if(store.getIterFirst(it)){
do{
file.write(leftJustify(store.getValueInt(it, 0).to!string, colSize[0]));
foreach(i ; 1..store.getNColumns()){
file.write(leftJustify("\""~store.getValueString(it, GetColumnStoreIndex(tree, i))~"\"", colSize[i]));
} }
file.write("\n"); file.write("\n");
}while(store.iterNext(it)); }while(store.iterNext(it));
@ -466,7 +492,7 @@ auto ref SetupColumn(TreeView tree, string sName, size_t index){
auto renameentry = new Entry(col.getTitle); auto renameentry = new Entry(col.getTitle);
version(Windows) auto renamebutton = new Button(StockID.APPLY, true); version(Windows) auto renamebutton = new Button(StockID.APPLY, true);
else static assert(0, "TODO"); else auto renamebutton = new Button("object-select-symbolic", GtkIconSize.SMALL_TOOLBAR);
renamebutton.addOnClicked((Button){ renamebutton.addOnClicked((Button){
auto newname = renameentry.getText.strip; auto newname = renameentry.getText.strip;
if(newname.countchars(" \t\n\r")==0) if(newname.countchars(" \t\n\r")==0)
@ -482,7 +508,7 @@ auto ref SetupColumn(TreeView tree, string sName, size_t index){
dlg.getContentArea.packStart(deletebox, false, false, 0); dlg.getContentArea.packStart(deletebox, false, false, 0);
version(Windows) auto deletebutton = new Button(StockID.DELETE, true); version(Windows) auto deletebutton = new Button(StockID.DELETE, true);
else static assert(0, "TODO"); else auto deletebutton = new Button("user-trash-symbolic", GtkIconSize.SMALL_TOOLBAR);
deletebutton.addOnClicked((Button){ deletebutton.addOnClicked((Button){
tree.removeColumn(col); tree.removeColumn(col);
dlg.destroy(); dlg.destroy();