2014-11-16 22:48:56 +00:00
|
|
|
import std.stdio;
|
|
|
|
import std.string;
|
|
|
|
import std.conv : to;
|
|
|
|
|
|
|
|
|
|
|
|
import gtk.Main;
|
|
|
|
import gtk.MainWindow;
|
|
|
|
import gtk.TreeView;
|
|
|
|
import gtk.ListStore;
|
|
|
|
import gtk.TreeViewColumn;
|
|
|
|
import gtk.TreeIter;
|
|
|
|
import gtk.Label;
|
|
|
|
import gtk.Entry;
|
|
|
|
import gtk.CellRenderer;
|
|
|
|
import gtk.CellRendererText;
|
|
|
|
import gtk.CellRendererSpin;
|
|
|
|
|
|
|
|
void[] Serialize(VT...)(VT data){
|
|
|
|
void[] ret;
|
|
|
|
foreach(d ; data){
|
|
|
|
ret~=cast(void[])([d]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(string[] args)
|
|
|
|
{
|
2014-11-17 10:50:11 +00:00
|
|
|
//auto color = GdkColor(0, 0x5C, 0x35, 0x66);
|
|
|
|
auto color = GdkRGBA(0.36, 0.13, 0.4, 1.0);
|
2014-11-16 22:48:56 +00:00
|
|
|
auto twoda = new TwoDA("test.2da");
|
|
|
|
|
|
|
|
|
|
|
|
Main.init(args);
|
|
|
|
|
2014-11-16 23:05:09 +00:00
|
|
|
auto window = new MainWindow("2DA-Edit");
|
2014-11-16 22:48:56 +00:00
|
|
|
|
|
|
|
|
2014-11-16 23:05:09 +00:00
|
|
|
GType type[];
|
2014-11-17 10:50:11 +00:00
|
|
|
type~=GType.STRING;
|
|
|
|
foreach(i;1..twoda.header.length)type~=GType.STRING;
|
2014-11-16 23:05:09 +00:00
|
|
|
auto store = new ListStore(type);
|
2014-11-16 22:48:56 +00:00
|
|
|
|
|
|
|
auto tree = new TreeView(store);
|
|
|
|
window.add(tree);
|
|
|
|
tree.setHeadersVisible(true);
|
|
|
|
tree.setEnableSearch(true);
|
|
|
|
tree.setModel(store);
|
2014-11-17 10:50:11 +00:00
|
|
|
tree.setProperty("enable-grid-lines", GtkTreeViewGridLines.VERTICAL);
|
2014-11-16 22:48:56 +00:00
|
|
|
|
|
|
|
foreach(index, s ; twoda.header){
|
|
|
|
|
2014-11-17 10:50:11 +00:00
|
|
|
CellRendererText cr;
|
2014-11-16 22:48:56 +00:00
|
|
|
if(index==0){
|
2014-11-17 10:50:11 +00:00
|
|
|
cr = new CellRendererText();
|
2014-11-16 23:05:09 +00:00
|
|
|
cr.setProperty("editable", true);
|
2014-11-17 10:50:11 +00:00
|
|
|
cr.setProperty("background-rgba", cast(ulong)(&color));
|
|
|
|
cr.setProperty("background-set", true);
|
|
|
|
|
2014-11-16 22:48:56 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
cr = new CellRendererText();
|
2014-11-17 10:50:11 +00:00
|
|
|
|
2014-11-16 22:48:56 +00:00
|
|
|
cr.setProperty("editable", true);
|
2014-11-17 10:50:11 +00:00
|
|
|
|
|
|
|
cr.addOnEdited((string path, string newval, CellRendererText crt){
|
|
|
|
TreeIter t = new TreeIter(tree.getModel(), path);
|
|
|
|
store.setValue(t, cast(int)crt.getData("colnumber"), newval);
|
|
|
|
});
|
2014-11-16 22:48:56 +00:00
|
|
|
}
|
2014-11-17 10:50:11 +00:00
|
|
|
cr.setData("colnumber", cast(void*)cast(int)index);
|
|
|
|
|
2014-11-16 22:48:56 +00:00
|
|
|
|
|
|
|
//cr.setSensitive(true);
|
|
|
|
|
2014-11-17 10:50:11 +00:00
|
|
|
auto col = new TreeViewColumn(s, cr, "text", cast(int)index);
|
2014-11-16 22:48:56 +00:00
|
|
|
col.setResizable(true);
|
|
|
|
//if(index!=0) col.setReorderable(true);
|
|
|
|
tree.appendColumn(col);
|
|
|
|
}
|
|
|
|
|
2014-11-17 10:50:11 +00:00
|
|
|
TreeIter iter = new TreeIter();
|
2014-11-16 22:48:56 +00:00
|
|
|
|
|
|
|
for(int i=0 ; i<=twoda.lastLine ; i++){
|
2014-11-17 10:50:11 +00:00
|
|
|
store.append(iter);
|
|
|
|
//itertable~= new TreeIter(iter);
|
|
|
|
|
2014-11-16 22:48:56 +00:00
|
|
|
store.setValue(iter, 0, i);
|
|
|
|
|
|
|
|
if(i in twoda.values){
|
|
|
|
foreach(index, v ; twoda.values[i]){
|
2014-11-17 10:50:11 +00:00
|
|
|
store.setValue(iter, cast(int)index+1, v);
|
2014-11-16 22:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
foreach(index ; 1..twoda.header.length){
|
2014-11-17 10:50:11 +00:00
|
|
|
store.setValue(iter, cast(int)index+1, "_");
|
2014-11-16 22:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tree.columnsAutosize();
|
|
|
|
|
|
|
|
|
|
|
|
window.showAll();
|
|
|
|
Main.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TwoDA{
|
|
|
|
import std.regex;
|
|
|
|
import std.file;
|
|
|
|
|
|
|
|
this(string filepath){
|
|
|
|
lastLine = 0;
|
|
|
|
foreach(index, line ; readText(filepath).splitLines()){
|
|
|
|
|
|
|
|
string data[];
|
|
|
|
|
|
|
|
auto results = matchAll(line, rgxField);
|
|
|
|
foreach(res ; results){
|
|
|
|
string s;
|
|
|
|
if(res[0][0]=='"') data~= res[2];
|
|
|
|
else data~= res[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(index==0){
|
|
|
|
header = data;
|
|
|
|
//writeln(header);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
int nLine = data[0].to!int;
|
|
|
|
values[nLine] = data[1..$];
|
|
|
|
//writeln(values[nLine]);
|
|
|
|
|
|
|
|
if(nLine > lastLine)
|
|
|
|
lastLine = nLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] header;
|
|
|
|
string[][uint] values;
|
|
|
|
uint lastLine;
|
|
|
|
enum rgxField = ctRegex!"(?:\\b([^\\s]+?)\\b|\"([^\"]+?)\")";
|
|
|
|
}
|
|
|
|
|