First try at removing columns

master
Crom (Thibaut CHARLES) 8 years ago
parent e27db91859
commit 50100c3ea5

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

Loading…
Cancel
Save