underscore handling in column names

This commit is contained in:
Crom (Thibaut CHARLES) 2015-03-13 00:11:05 +01:00
parent 6ac4dc3468
commit b0d70f028f

View File

@ -4,6 +4,7 @@ import std.path;
import std.stdio; import std.stdio;
import std.string; import std.string;
import std.conv : to; import std.conv : to;
import std.array : replace;
import gtk.MainWindow; import gtk.MainWindow;
import gtk.HeaderBar; import gtk.HeaderBar;
@ -291,7 +292,7 @@ class Window : MainWindow{
size_t colSize[]; size_t colSize[];
colSize.length = tree.getNColumns; colSize.length = tree.getNColumns;
foreach(i ; 0..tree.getNColumns) foreach(i ; 0..tree.getNColumns)
colSize[i] = tree.getColumn(i).getTitle.length +1;//+1 space colSize[i] = tree.getColumn(i).getTitle.replace("__", "_").length +1;//+1 space
TreeIter it = new TreeIter(); TreeIter it = new TreeIter();
if(store.getIterFirst(it)){ if(store.getIterFirst(it)){
@ -314,7 +315,7 @@ class Window : MainWindow{
auto file = File(openedFile, "w"); auto file = File(openedFile, "w");
foreach(i ; 0..tree.getNColumns) foreach(i ; 0..tree.getNColumns)
file.write(leftJustify(tree.getColumn(i).getTitle, colSize[i])); file.write(leftJustify(tree.getColumn(i).getTitle.replace("__", "_"), colSize[i]));
file.write("\n"); file.write("\n");
it = new TreeIter(); it = new TreeIter();
@ -454,7 +455,7 @@ private:
cr.setData("colnumber", cast(void*)cast(int)index); cr.setData("colnumber", cast(void*)cast(int)index);
auto col = new TreeViewColumn(sName, cr, "text", cast(int)index); auto col = new TreeViewColumn(sName.replace("_", "__"), cr, "text", cast(int)index);
col.setData("colnumber", cast(void*)cast(int)index); col.setData("colnumber", cast(void*)cast(int)index);
col.setResizable(true); col.setResizable(true);
col.setMinWidth(10); col.setMinWidth(10);
@ -470,12 +471,12 @@ private:
auto renamebox = new HBox(false, 0); auto renamebox = new HBox(false, 0);
dlg.getContentArea.packStart(renamebox, false, false, 0); dlg.getContentArea.packStart(renamebox, false, false, 0);
auto renameentry = new Entry(col.getTitle); auto renameentry = new Entry(col.getTitle.replace("__", "_"));
auto renamebutton = new Button("object-select-symbolic", GtkIconSize.SMALL_TOOLBAR); 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)
col.setTitle(newname); col.setTitle(newname.replace("_", "__"));
else else
displayMessage("Spaces are forbidden in column name"); displayMessage("Spaces are forbidden in column name");
}); });