First try at removing columns

This commit is contained in:
Crom (Thibaut CHARLES) 2014-11-20 09:08:14 +01:00
parent e27db91859
commit 50100c3ea5
1 changed files with 55 additions and 18 deletions

View File

@ -202,14 +202,27 @@ void main(string[] args)
buttonNewCol.addOnClicked((Button){ buttonNewCol.addOnClicked((Button){
auto oldstore = cast(ListStore)tree.getModel(); auto oldstore = cast(ListStore)tree.getModel();
int newColIndex = oldstore.getNColumns(); int newColIndex = oldstore.getNColumns();
foreach(i ; 0..tree.getNColumns){
auto col = tree.getColumn(i);
writeln("col",i,"=",col, "(", col is null? "" : col.getTitle, ")");
}
GType[] types; GType[] types;
string[] titles; string[] titles;
foreach(i ; 0..newColIndex){ int[] storeIndex;
foreach(i ; 0..tree.getNColumns){
writeln("Saving ",i);
if(i==0)types~= GType.INT; if(i==0)types~= GType.INT;
else types~= GType.STRING; else types~= GType.STRING;
titles~= tree.getColumn(0).getTitle;
storeIndex~= GetColumnStoreIndex(tree, 0)>=0?GetColumnStoreIndex(tree, 0):0;
auto col = tree.getColumn(0);
if(col !is null) titles~= tree.getColumn(0).getTitle;
else titles~= "ERR";
tree.removeColumn(tree.getColumn(0)); tree.removeColumn(tree.getColumn(0));
} }
types~=GType.STRING; types~=GType.STRING;
@ -227,9 +240,8 @@ void main(string[] args)
foreach(i ; 0..newColIndex+1){ foreach(i ; 0..newColIndex+1){
if(i<newColIndex){ if(i<newColIndex){
if(types[i]==GType.INT) store.setValue(newit, cast(int)i, oldstore.getValueInt(oldit, i)); if(types[i]==GType.INT) store.setValue(newit, i, oldstore.getValueInt(oldit, storeIndex[i]));
else store.setValue(newit, cast(int)i, oldstore.getValueString(oldit, i)); else store.setValue(newit, i, oldstore.getValueString(oldit, storeIndex[i]));
} }
else else
store.setValue(newit, cast(int)i, "_"); store.setValue(newit, cast(int)i, "_");
@ -443,21 +455,46 @@ auto ref SetupColumn(TreeView tree, string sName, size_t index){
col.setClickable(true); col.setClickable(true);
col.setReorderable(true); col.setReorderable(true);
col.addOnClicked((TreeViewColumn col){ col.addOnClicked((TreeViewColumn col){
import gtk.Dialog; import gtk.Dialog;
auto dlg = new Dialog("Rename column", window, GtkDialogFlags.MODAL, ["Cancel","Rename"], [ResponseType.CANCEL, ResponseType.OK]); auto dlg = new Dialog("Column options", window, GtkDialogFlags.MODAL, ["Close"], [ResponseType.CANCEL]);
auto entry = new Entry(col.getTitle);
dlg.getContentArea.packStart(entry, false, false, 5);
entry.show();
if(dlg.run()==ResponseType.OK){ //Rename
auto newname = entry.getText.strip; dlg.getContentArea.packStart(new Label("Rename:"), false, false, 0);
if(newname.countchars(" \t\n\r")==0)
col.setTitle(newname);
else
SaySomething("Spaces are forbidden in column name");
}
dlg.destroy(); auto renamebox = new HBox(false, 0);
dlg.getContentArea.packStart(renamebox, false, false, 0);
auto renameentry = new Entry(col.getTitle);
version(Windows) auto renamebutton = new Button(StockID.APPLY, true);
else static assert(0, "TODO");
renamebutton.addOnClicked((Button){
auto newname = renameentry.getText.strip;
if(newname.countchars(" \t\n\r")==0)
col.setTitle(newname);
else
SaySomething("Spaces are forbidden in column name");
});
renamebox.packStart(renameentry, true, true, 0);
renamebox.packEnd(renamebutton, false, false, 0);
//Delete
auto deletebox = new HBox(false, 0);
dlg.getContentArea.packStart(deletebox, false, false, 0);
version(Windows) auto deletebutton = new Button(StockID.DELETE, true);
else static assert(0, "TODO");
deletebutton.addOnClicked((Button){
tree.removeColumn(col);
dlg.destroy();
});
deletebox.packStart(new Label("Delete column"), true, true, 0);
deletebox.packEnd(deletebutton, false, false, 0);
dlg.showAll();
dlg.run();
dlg.destroy();
}); });