Sample/Window.bjs
authorAlan Knowles <alan@akkbhome.com>
Wed, 1 Dec 2010 13:57:31 +0000 (21:57 +0800)
committerAlan Knowles <alan@akkbhome.com>
Wed, 1 Dec 2010 13:57:31 +0000 (21:57 +0800)
Sample/Window.bjs

index da28d07..27afc72 100644 (file)
                                                                             "|redraw": "function() {\n   this.highlightWidget = false;\n    print(\"REDRAW CALLED\");\n    this.activePath = this.get('/LeftTree').getActivePath();\n    if (this.renderedEl) {\n      print(\"QUEUE DRAW CALLING\");\n      this.renderedEl.queue_draw();\n   }\n}\n",
                                                                             "|renderJS": "function(data, withDebug)\n{\n      this.highlightWidget = false;\n   \n    this.withDebug = false;\n    while (this.get('view').el.get_children().length) {\n        var c = this.get('view').el.get_children()[0];\n        this.get('view').el.remove(c);        \n        c.destroy();\n    }\n     if (!data) {\n         return; \n    }\n    \n    var tree =  this.get('/LeftTree.model').toJS(false,true)[0];\n    // in theory tree is actually window..  \n   try {\n  \n        this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);\n      \n  } catch (e) {\n     print(e.message);\n    return;\n  }\n    this.get('view').el.set_size_request(\n        tree.default_width * 1 || 400, tree.default_height * 1 || 400\n    ) ;\n    if (this.renderedEl) {\n        this.renderedEl.set_size_request(\n            tree.default_width || 600,\n            tree.default_height || 400\n        );\n    }\n    this.get('view').el.show_all();\n    \n    \n    \n}",
                                                                             "|showInWindow": "function() {\n  print(\"GET PROEJCT\");\n\tvar pr = this.get('/LeftProjectTree').getActiveProject();\n  \n\tconsole.log(pr.paths);\n    return;\n/*\n     var src= this.buildJS(\n\t\tthis.get('/LeftTree.model').toJS()[0], \n\t\ttrue);\n      // show term?? \n\n\n    //var x = new imports.sandbox.Context();\n    //x.add_globals();\n    //print(src);\n    try {\n        Seed.check_syntax('var e = ' + src);\n        //x.eval(src);\n    } catch( e) {\n        this.get('/Terminal').feed(e.message || e.toString() + \"\\n\");\n        this.get('/Terminal').feed(console._dump(e)+\"\\n\");\n        if (e.line) {\n            var lines = src.split(\"\\n\");\n            var start = Math.max(0, e.line - 10);\n            var end = Math.min(lines.length, e.line + 10);\n            for (var i =start ; i < end; i++) {\n                if (i == e.line) {\n                    this.get('/Terminal').feed(\">>>>>\" + lines[i] + \"\\n\");\n                    continue;\n                }\n                this.get('/Terminal').feed(lines[i] + \"\\n\");\n            }\n            \n        }\n        \n        return;\n    }\n     this.get('/BottomPane').el.set_current_page(1);\n    this.get('/Terminal').el.fork_command( null , [], [], \"/tmp\", false,false,false); \n    var cmd = \"/usr/bin/seed /tmp/BuilderGtkView.js\\n\";\n    this.get('/Terminal').el.feed_child(cmd, cmd.length);\n     /*\n    var _top = x.get_global_object()._top;\n    \n    _top.el.set_screen(Gdk.Screen.get_default()); // just in case..\n    _top.el.show_all();\n    if (_top.el.popup) {\n        _top.el.popup(null, null, null, null, 3, null);\n    }\n*/\n}\n",
-                                                                            "|viewAdd": "function(item, par)\n{\n\n    // does something similar to xobject..\n    item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;\n    \n    if (item.pack===false || item.pack === 'false') {  // no ;\n        return;\n    }\n    print(\"CREATE: \" + item['|xns'] + '.' + item['xtype']);\n    \n    \n    var type = item['|xns'] + '.' + item['xtype'];\n    \n    if (item['|xns'] == 'GtkClutter') { // we can not add this yet!\n        return false;\n    }\n    \n    var ns = imports.gi[item['|xns']];\n    var ctr = ns[item['xtype']]; // why are we using array here..?\n    \n\n    \n    var ctr_args = { };\n    for(var k in item) {\n        var kv = item[k];\n        if (typeof(kv) == 'object' || typeof(kv) == 'function') {\n            continue;\n        }\n        if ( \n            k == 'pack' ||\n            k == 'items' ||\n            k == 'id' ||\n            k == 'xtype' ||\n            k == 'xdebug' ||\n            k == 'xns' ||\n            k == '|xns'\n        ) {\n            continue;\n        }\n\n\tif (k[0] == '|' && typeof(kv) == 'string') {\n\n\t\tif (kv.match(new RegExp('function'))) {\n\t\t\tcontinue;\n                }\n\t\tprint(\"WASL \" + k + '=' + kv);\n\t\ttry {\n\t\t\teval( 'kv = ' + kv);\n\t\t} catch(e) {    continue; }\n                \n\t\tk = k.substring(1);\n             // print(k + '=' + kv);\n\t}\n        if (k[0] == '|') { // should be boolean or number..\n\t\tk = k.substring(1);\n\t\t//print(k + '=' + kv);\n        }\n         \n\tif (k == 'show_tabs') { // force tab showing for notebooks.\n           kv = true;\n        }\n        print(k + '=' + typeof(kv) + \" : \" + kv);\n        ctr_args[k] = kv;\n        \n    } \n    var altctr =  XObject.baseXObject({ xtype:  ctr} );\n    if (!item.pack && altctr) {\n        // try XObject.\n        item.pack = altctr.prototype.pack;\n        \n        \n        \n    \n    }\n    \n    var el = new ctr(ctr_args);\n    \n    print(\"PACK\" + item.pack);\n    //console.dump(item.pack);\n    \n    \n    \n    \n    var args = [];\n    var pack_m  = false;\n    if (typeof(item.pack) == 'string') {\n         \n        item.pack.split(',').forEach(function(e, i) {\n            \n            if (e == 'false') { args.push( false); return; }\n            if (e == 'true') {  args.push( true);  return; }\n            if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }\n            args.push(e);\n        });\n        //print(args.join(\",\"));\n        \n        pack_m = args.shift();\n    } else {\n        pack_m = item.pack.shift();\n        args = item.pack;\n    }\n    \n    // handle error.\n    if (pack_m && typeof(par[pack_m]) == 'undefined') {\n        throw {\n                name: \"ArgumentError\", \n                message : 'pack method not available : ' + par.id + \" : \" + par + '.' +  pack_m +\n                        \"ADDING : \" + item.id + \" \" +  el\n                    \n\t    };\n\n        return;\n    }\n    \n    console.dump(args);\n    args.unshift(el);\n    //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');\n    //Seed.print('args: ' + args.length);\n    if (pack_m) {\n        par[pack_m].apply(par, args);\n    }\n    \n    var _this = this;\n    item.items = item.items || [];\n    item.items.forEach(function(ch,n) {\n\n          print (\"type:\" + type);\n          \n           print (\"ch.pack:\" + ch.pack);\n         if (type == 'Gtk.Table' && ch.pack == 'add') {\n            var c = n % item.n_columns;\n            var r = Math.floor(n/item.n_columns);\n            ch.pack = [ 'attach', c, c+1, r, r+1, \n                     typeof(ch.x_options) == 'undefined' ?  5 : ch.x_options,\n                        typeof(ch.y_options) == 'undefined' ?  5 : ch.y_options,\n                        typeof(ch.x_padding) == 'undefined' ?  0 : ch.x_padding,\n                        typeof(ch.x_padding) == 'undefined' ?  0 : ch.x_padding\n            ].join(',');\n        }\n    \n        _this.viewAdd(ch, el);\n    });\n    \n    \n    \n    // add the signal handlers.\n    // is it a widget!?!!?\n   \n    \n    try {\n         \n        \n        el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item  ], true));\n        el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item  ], true));\n        el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item  ], true));\n        el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item  ], true ));\n  el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item  ], true ));\n    } catch(e) {\n        // ignore!\n       }\n    \n    \n    \n    return el;\n    \n}",
+                                                                            "|viewAdd": "function(item, par)\n{\n\n    // does something similar to xobject..\n    item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;\n    \n    if (item.pack===false || item.pack === 'false') {  // no ;\n        return;\n    }\n    print(\"CREATE: \" + item['|xns'] + '.' + item['xtype']);\n    \n    \n    var type = item['|xns'] + '.' + item['xtype'];\n    \n    if (item['|xns'] == 'GtkClutter') { // we can not add this yet!\n        return false;\n    }\n    \n    var ns = imports.gi[item['|xns']];\n    var ctr = ns[item['xtype']]; // why are we using array here..?\n    \n\n    \n    var ctr_args = { };\n    for(var k in item) {\n        var kv = item[k];\n        if (typeof(kv) == 'object' || typeof(kv) == 'function') {\n            continue;\n        }\n        if ( \n            k == 'pack' ||\n            k == 'items' ||\n            k == 'id' ||\n            k == 'xtype' ||\n            k == 'xdebug' ||\n            k == 'xns' ||\n            k == '|xns'\n        ) {\n            continue;\n        }\n\n\tif (k[0] == '|' && typeof(kv) == 'string') {\n\n\t\tif (kv.match(new RegExp('function'))) {\n\t\t\tcontinue;\n                }\n\t\tprint(\"WASL \" + k + '=' + kv);\n\t\ttry {\n\t\t\teval( 'kv = ' + kv);\n\t\t} catch(e) {    continue; }\n                \n\t\tk = k.substring(1);\n             // print(k + '=' + kv);\n\t}\n        if (k[0] == '|') { // should be boolean or number..\n\t\tk = k.substring(1);\n\t\t//print(k + '=' + kv);\n        }\n         \n\tif (k == 'show_tabs') { // force tab showing for notebooks.\n           kv = true;\n        }\n        print(k + '=' + typeof(kv) + \" : \" + kv);\n        ctr_args[k] = kv;\n        \n    } \n    var altctr =  XObject.baseXObject({ xtype:  ctr} );\n    var pack_m  = false;\n    if (!item.pack && altctr) {\n        // try XObject.\n        pack_m = altctr.prototype.pack;\n        \n        \n    }\n    \n    var el = new ctr(ctr_args);\n    \n    print(\"PACK\" + item.pack);\n    //console.dump(item.pack);\n    \n    \n    \n    \n    var args = [];\n\n    if (typeof(item.pack) == 'string') {\n         \n        item.pack.split(',').forEach(function(e, i) {\n            \n            if (e == 'false') { args.push( false); return; }\n            if (e == 'true') {  args.push( true);  return; }\n            if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }\n            args.push(e);\n        });\n        //print(args.join(\",\"));\n        \n        pack_m = args.shift();\n    } else {\n        pack_m = item.pack.shift();\n        args = item.pack;\n    }\n    \n    // handle error.\n    if (pack_m && typeof(par[pack_m]) == 'undefined') {\n        throw {\n                name: \"ArgumentError\", \n                message : 'pack method not available : ' + par.id + \" : \" + par + '.' +  pack_m +\n                        \"ADDING : \" + item.id + \" \" +  el\n                    \n\t    };\n\n        return;\n    }\n    \n    console.dump(args);\n    args.unshift(el);\n    //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');\n    //Seed.print('args: ' + args.length);\n    if (pack_m) {\n        par[pack_m].apply(par, args);\n    }\n    \n    var _this = this;\n    item.items = item.items || [];\n    item.items.forEach(function(ch,n) {\n\n          print (\"type:\" + type);\n          \n           print (\"ch.pack:\" + ch.pack);\n         if (type == 'Gtk.Table' && ch.pack == 'add') {\n            var c = n % item.n_columns;\n            var r = Math.floor(n/item.n_columns);\n            ch.pack = [ 'attach', c, c+1, r, r+1, \n                     typeof(ch.x_options) == 'undefined' ?  5 : ch.x_options,\n                        typeof(ch.y_options) == 'undefined' ?  5 : ch.y_options,\n                        typeof(ch.x_padding) == 'undefined' ?  0 : ch.x_padding,\n                        typeof(ch.x_padding) == 'undefined' ?  0 : ch.x_padding\n            ].join(',');\n        }\n    \n        _this.viewAdd(ch, el);\n    });\n    \n    \n    \n    // add the signal handlers.\n    // is it a widget!?!!?\n   \n    \n    try {\n         \n        \n        el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item  ], true));\n        el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item  ], true));\n        el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item  ], true));\n        el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item  ], true ));\n  el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item  ], true ));\n    } catch(e) {\n        // ignore!\n       }\n    \n    \n    \n    return el;\n    \n}",
                                                                             "|widgetDragDropEvent": "function() {\n      print(\"WIDGET DRAGDROP\"); \n            return true;\n}\n",
                                                                             "|widgetDragMotionEvent": "function() {\n     print(\"WIDGET DRAGMOTION\"); \n            return true;\n}\n",
                                                                             "|widgetExposeEvent": "function(w, evt, ud, item) {\n    var widget = w;\n     if (this.inRender) {\n         return false;\n     }\n     \n     if ( this.highlightWidget) {\n          this.inRender = true;\n          if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {\n                 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);\n            }\n           this.inRender = false;\n           return false;\n     }\n     \n     \n     if (this.activePath != item.xtreepath) {\n        return false;\n     }\n     \n   //  print(\"HIGHLIGHT: \" + item.xtreepath ); // draw highlight??\n     // work out the coords of the window..\n     if (!this.gc) {\n      var dr = widget.window;\n      this.gc = (new Gdk.GC.c_new(dr));\n      this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));\n      this.gc.set_line_attributes(4,  Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);\n    }\n\n    \n     var r  = evt.expose.area;\n     // console.dump([r.x, r.y, r.width, r.height ] );\n     //return false;\n//     print(widget.get_parent().toString().match(/GtkScrolledWindow/);\n     if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak\n         // happens with gtkscrollview embedded stuff..\n         var np =this.activePath.split(':');\n         np.pop();\n         this.activePath = np.join(':');\n         this.renderedEl.queue_draw();\n         return true;\n\n        \n     }\n\n       \n     \n     \n      this.box = {\n        x : r.x - 2,\n        y : r.y - 2,\n        w: r.width + 4,\n        h: r.height + 4\n      }; \n      // let's draw it..\n      this.inRender = true;\n\n      \n      this.highlightWidget = widget;\n    \n    \n \n\n    //  print(\"DRAW BOX\");\n       //console.dump(this.box);\n      Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);\n            this.inRender = false;\n            return false;\n}\n",