store.append(iter,parentIter);Getting a directory listing uses the new Phobos (or generic D binding backend) binding code.
store.set(iter, 0, "node title");
store.set(iter, 1, {directory: pdir + name + "/" });
var filelist = File.listdir("/home/alan");I did notice one little gotcha for the dmdscript backend, that it does not support the "in" comparison operator So
if ("fred" in myobject) {...}
becomes
if (myobject.hasOwnProperty("fred")) {....}
Talking of gotcha's I spent quite a long time getting the manual to work in IE. My little extjs tricks noted that comma's are a bit of a nightmare in IE, in that It doesnt like trailing comma's in lists of object properties. As typical with any Microsoft product, this is totally inconsistant with the behaviour for arrays, in which case it quite happily accepts trailing commans. Not only does it accept them, it adds an undefined element on the end of the array... - which broke my method list horribly in IE.
Otherwise getting it to work in IE basically consisted of using Ext.DomQuery rather than trying to use standard DOM calls which never seem to work as expected. Anyway comment away...
var store = new Gtk.ListStore(At present I've used the Gtype names to define what is being stored where. - This may need simplifying, and integrating somehow with the writing mechanism as validating data types written to the tree is a bit haphazard at present.
"gchararray",
"gfloat",
"gpointer",
"gboolean",
"GdkPixbuf");
var iter = new Gtk.TreeIter();The append method loads the Row reader writer, so that it can access the new row.
store.append(iter);
store.set(iter, 0, new G.Value("test"));all this could easily be abstracted by defining a simple prototype
store.set(iter, 1, new G.Value(1.0));
store.set(iter, 2, new G.Value({ a: 1, c: 2}));
store.set(iter, 3, new G.Value(true) );
var pixbuf = Gdk.Pixbuf.newFromFile("gnome-logo-icon.png");
store.set(iter, 4, new G.Value(pixbuf) );
Gtk.ListStore.prototype.appendRow = function(rdata) {Next step is to build the Widget. And the renderers (the classes that turn the data into visable data). Gtk comes with a few renderers, It will be interesting to see if creating them in Javascript is feasible.
var iter = new Gtk.TreeIter();
this.append(iter);
for(var i =0;i<rdata.length;i++) {
this.set(iter,i, new G.Value(rdata[i]));
}
}
.....
store.appendRow(["test", 1.0, {a: 1}, true, Gtk.Pixbuf.newFromFile(....)]);
var view = new Gtk.TreeView();Adding columns is again a little raw, as we cant use the varargs methods the C does, so we have to combine a few calls.
var renderer = new Gtk.CellRendererText ();
var pixrenderer = new Gtk.CellRendererPixbuf ();
Again a nice wrapper could be written.
var col = new Gtk.TreeViewColumn();
col.setTitle("Name");
col.packStart(renderer, true);
col.addAttribute(renderer, "text", 0);
view.insertColumn( col, -1);
Gtk.TreeView.prototype.insertColumnAuto = function(config) {
var col = new Gtk.TreeViewColumn();
col.setTitle(config.title);
col.packStart(config.renderer, true);
col.addAttribute(config.renderer,
config.renderer.isPrototypeOf(GtkCellRenderText) ?
"text" : "pixbuf", 0);
this.insertColumn( col, -1);
}
...
view.insertColumnAuto({
title: "text here",
renderer: new GtkCellRendererText(),
}
view.setModel ( store );
window.add(view); // add it to a GtkWindow..
window.showAll();
Gtk.main();
view.connect("row-activated", function(view, path, col) {At present this is a little klunky, but again with some prototype modifications it should be pretty easy to solve.
var model = view.getModel();
var iter = new Gtk.TreeIter();
if (model.getIter(iter, path)) {
var name = new G.Value();
var name2 = new G.Value();
model.getValue(iter, 0, name);
model.getValue(iter, 1, name2);
println (
"The row containing the name '"+
name.getString() +
"' has been double-clicked. holding" +
name2.getFloat()
);
model = new Gtk.ListStore(model);
model.remove(iter);
println ("removed?");
}
});
var menuBar = new Gtk.MenuBar.quick([In the above example, I've created an extended class Gtk.MenuItem.quick, and Gtk.MenuBar.quick (it could just be Ext.MenuBar / Ext.MenuItem...) - Just adding it to the Gtk.Menubar Class namespace seemed clever at the time.
new Gtk.MenuItem.quick("File" , function () {
println("File");
}),
new Gtk.MenuItem.quick("Edit" , function () {
println("Edit");
}),
new Gtk.MenuItem.quick("Search" , function () {
println("Search");
})
]);
new Gtk.MenuItem.quick({This morphing of the Gtk bindings is all done in the Javascript code,
title: "Search" ,
icon: Gtk.Stock.SEARCH, // this doesnt work yet!
handler: function () {
println("Search");
}
})
Gtk.MenuItem.quick = function(label, activate) {(using snippets of code from Extjs) to implement the extending.
Gtk.MenuItem.quick.superclass.constructor.call(this,label);
this.connect("activate", activate);
}
Ext.extend(Gtk.MenuItem.quick, Gtk.MenuItem, {});
Gtk.MenuBar.quick = function(ar)
{
Gtk.MenuBar.quick.superclass.constructor.call(this,label);
for (var i in ar) {
this.append(ar[i]);
}
}
Ext.extend(Gtk.MenuBar.quick , Gtk.MenuBar, {});
var a = new Gtk.Window(0);
a.connect("delete", function() { Gtk.exit(1); });
Gtk.Widget.prototype.on = function (sig, call) { return this.connect(sig,call); }
run with
Gtk.init();
var w = new Gtk.Window(0);
w.setTitle("hello world");
w.showAll();
Gtk.main();
/tmp/gtkjs hello.ds
svn co http://www.akbkhome.com/svn/gtkDSNow I just wonder what use it is ;)
cd gtkDS/wrap
#download API Files (needs curl / tar etc.)
sh downloadFiles.sh
#compile it - needs dmd installed..
sh buildit.sh
cd ..
#build the bindings - requires compd from dsource.org/projects/dool
compd gdkds.compd
/tmp/gtkjs test/hello.ds