sync
[gitlive] / old_seed_version / Merger.bjs
diff --git a/old_seed_version/Merger.bjs b/old_seed_version/Merger.bjs
new file mode 100644 (file)
index 0000000..fa7ebd0
--- /dev/null
@@ -0,0 +1,276 @@
+{
+    "id": "file-gtk-5",
+    "name": "Merger",
+    "parent": "",
+    "title": false,
+    "path": "/home/alan/gitlive/gitlive/Merger.bjs",
+    "items": [
+        {
+            "listeners": {
+                "destroy_event": "function (self, event) {\n     this.el.hide();\n                return false;\n}",
+                "response": "function (self, id) {\n  // hide\n     //if (id < 1) {\n        this.el.hide();\n        return;\n    //}\n    if (typeof(this.get('bug').getValue()) != 'object') {\n        print(\"ERROR\");\n        return;\n    }\n \n    this.el.hide();\n        \n    //var val = this.get('bug').getValue();\n     //   Seed.print(val);\n}"
+            },
+            "border_width": 3,
+            "default_height": 700,
+            "default_width": 800,
+            "id": "Merger",
+            "title": "Merger",
+            "xtype": "Dialog",
+            "|deletable": "true",
+            "|show": "function(c) {\n    \n    if (!this.el) {\n        this.init();\n    }\n    var _this = this;\n     \n      //this.el.set_title(\"Merger - ??? \");\n//   this.el.set_title(\"Merger - \" + this.repo.repopath);\n\n\n     Merger.loading = true; // stop change firing on combos.\n     /// load up branches\n     \n     this.get('/historyTreeStore').el.clear();\n     this.get('/changedFilesStore').el.clear();\n     this.get('/patchview').clear();\n    \n     \n     \n     this.get('/workingCombo').load(Merger.repo.branches);\n     \n     this.get('/releaseCombo').load(Merger.repo.branches);\n\n\n\n\n     Merger.loading = false;\n\n    this.el.show_all();\n    //this.get('/ok_button').el.set_sensitive(false);\n    \n    // block until we return.\n    var run_ret = this.el.run();\n    if (run_ret < 1 ) {\n        return  \"DONE\";\n    }\n    print(\"RUN RETURN : \" + run_ret);\n    return \"DONE\";\n    //print(JSON.stringify(this.get('bug').getValue()));\n   // return this.get('bug').getValue();\n    //this.success = c.success;\n}\n",
+            "|xns": "Gtk",
+            "items": [
+                {
+                    "xtype": "VBox",
+                    "|pack": " function(p,e) {\n        p.el.get_content_area().pack_start(e.el,true,true,0)\n    }\n",
+                    "|xns": "Gtk",
+                    "items": [
+                        {
+                            "pack": "pack_start,false,true",
+                            "xtype": "HBox",
+                            "|xns": "Gtk",
+                            "items": [
+                                {
+                                    "label": "Working Branch",
+                                    "xtype": "Label",
+                                    "|xns": "Gtk"
+                                },
+                                {
+                                    "listeners": {
+                                        "changed": "function (self) {\n   this.get('/historyTreeStore').loadTree();\n}"
+                                    },
+                                    "id": "workingCombo",
+                                    "xtype": "ComboBox",
+                                    "|init": "function() {\n    this.el = new Gtk.ComboBox.with_entry();\n    \n    \n    this.model  = new XObject(this.model);\n    this.model.init();\n    this.el.set_model(this.model.el);\n    this.el.set_entry_text_column (0);\n     XObject.prototype.init.call(this);\n    \n}\n",
+                                    "|load": "function(tr)\n{\n    //this.insert(citer,iter,0);\n    this.model.el.clear();\n    \n    var master = false;\n    var working = false;\n    \n    for(var i =0 ; i < tr.length; i++) {\n        if (!tr[i].name.length) {\n            continue;\n        }\n        var ret = {  };\n        this.model.el.append(ret);\n        //print(JSON.stringify(ret,null,4));\n        if (tr[i].name == 'master') {\n            master = i;\n        }\n        if (tr[i].name == 'working') {\n            working = i;\n        }          \n        this.model.el.set_value(ret.iter, 0, '' + tr[i].name );\n        this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );\n \n        \n    }     \n    if (master !== false) {\n        this.el.set_active(master);\n    }\n    if (working !== false) {\n        this.el.set_active(working);\n    }\n    \n}",
+                                    "|xns": "Gtk",
+                                    "items": [
+                                        {
+                                            "*prop": "model",
+                                            "xtype": "ListStore",
+                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n           GObject.TYPE_STRING, // file  \n          GObject.TYPE_STRING, // added\n          GObject.TYPE_STRING, // removed\n      ] );\n}\n",
+                                            "|xns": "Gtk"
+                                        }
+                                    ]
+                                },
+                                {
+                                    "label": "Release Branch",
+                                    "xtype": "Label",
+                                    "|xns": "Gtk"
+                                },
+                                {
+                                    "listeners": {
+                                        "changed": "function (self) {\n   this.get('/historyTreeStore').loadTree();\n}"
+                                    },
+                                    "id": "releaseCombo",
+                                    "xtype": "ComboBox",
+                                    "|init": "function() {\n    this.el = new Gtk.ComboBox.with_entry();\n    \n    \n    this.model  = new XObject(this.model);\n    this.model.init();\n    this.el.set_model(this.model.el);\n    this.el.set_entry_text_column (0);\n     XObject.prototype.init.call(this);\n    \n}\n",
+                                    "|load": "function(tr)\n{\n    //this.insert(citer,iter,0);\n    this.model.el.clear();\n    \n    var master = false;\n    var release = false;\n    \n    for(var i =0 ; i < tr.length; i++) {\n        var ret = {  };\n        if (!tr[i].name.length) {\n            continue;\n        }\n        \n        this.model.el.append(ret);\n        //print(JSON.stringify(ret,null,4));\n        if (tr[i].name == 'master') {\n            master = i;\n        }\n        if (tr[i].name == 'release') {\n            release = i;\n        }\n         \n        this.model.el.set_value(ret.iter, 0, '' + tr[i].name );\n        this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );\n \n        \n    }     \n    if (master !== false) {\n        this.el.set_active(master);\n    }\n    if (release !== false) {\n        this.el.set_active(release);\n    }\n    \n}",
+                                    "|xns": "Gtk",
+                                    "items": [
+                                        {
+                                            "*prop": "model",
+                                            "xtype": "ListStore",
+                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n           GObject.TYPE_STRING, // file  \n          GObject.TYPE_STRING, // added\n          GObject.TYPE_STRING, // removed\n      ] );\n}\n",
+                                            "|xns": "Gtk"
+                                        }
+                                    ]
+                                }
+                            ]
+                        },
+                        {
+                            "pack": "pack_end,true,true,0",
+                            "position": 400,
+                            "xtype": "VPaned",
+                            "|xns": "Gtk",
+                            "items": [
+                                {
+                                    "pack": "add",
+                                    "position": 200,
+                                    "xtype": "HPaned",
+                                    "|xns": "Gtk",
+                                    "items": [
+                                        {
+                                            "xtype": "ScrolledWindow",
+                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n     this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
+                                            "|xns": "Gtk",
+                                            "items": [
+                                                {
+                                                    "listeners": {
+                                                        "cursor_changed": "function (self) {\n\n    if (this.el.get_selection().count_selected_rows() < 1) {\n        //nothing?\n        return;\n    }\n    var model = this.get('/historyTreeStore');\n    var ret = {};        \n     var s = this.el.get_selection();\n    s.get_selected(ret);\n    \n    var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();\n     print(\"OUT?\" + value);// id..\n    // load the list in the right grid..\n    var Repo = imports.Scm.Git.Repo.Repo;\n    \n    \n   \n    if (model.release === false) {\n        return;\n    }\n    model.rev = value;\n   \n    var files = Merger.repo.changedFiles('/',   'rev', model.release + '..' + value);\n    this.get('/changedFilesStore').load(files);\n    return true;\n\n}"
+                                                    },
+                                                    "pack": "add",
+                                                    "xtype": "TreeView",
+                                                    "|init": "function() {\n    XObject.prototype.init.call(this);\n        var description = new Pango.FontDescription.c_new();\n   description.set_size(8000);\n     this.el.modify_font(description);\n\n     this.selection = this.el.get_selection();\n      this.selection.set_mode( Gtk.SelectionMode.SINGLE);\n    var _this = this;\n    /*\n 780                                                                     \n 781                                                                         // is this really needed??\n 782                                                                         this.selection.signal['changed'].connect(function() {\n 783                                                                                 _this.get('/LeftTree.view').listeners.cursor_changed.apply(\n 784                                                                                     _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']\n 785                                                                                 );\n 786                                                                         });\n 787                                                                         \n */\n }\n",
+                                                    "|xns": "Gtk",
+                                                    "items": [
+                                                        {
+                                                            "id": "historyTreeStore",
+                                                            "pack": "set_model",
+                                                            "release": false,
+                                                            "xtype": "TreeStore",
+                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n       GObject.TYPE_STRING, // title \n      GObject.TYPE_STRING, // rev \n  ] );\n}\n",
+                                                            "|load": "function(tr,iter)\n{\n    //this.insert(citer,iter,0);\n    if (!iter) {\n        this.el.clear();\n    }\n    \n    for(var i =0 ; i < tr.length; i++) {\n        var ret = {  };\n        if (iter) {\n            this.el.insert(ret ,iter,-1);\n        } else {\n            this.el.append(ret);\n        }\n        //print(JSON.stringify(ret,null,4));\n         \n          \n        this.el.set_value(ret.iter, 0, ''  +  tr[i].text );\n        this.el.set_value(ret.iter, 1, '' + tr[i].rev  );\n \n        if (tr[i].children && tr[i].children.length) {\n            this.load(tr[i].children, ret.iter);\n        }\n    }     \n}",
+                                                            "|loadTree": "function() {\n\n   this.working = false;\n   if (Merger.loading) {\n        return;\n   }\n   \n   \n   var wid = this.get('/workingCombo').el.get_active();\n   var rid = this.get('/releaseCombo').el.get_active();\n   if (wid < 0 || rid < 0 || rid == wid) {\n        return;\n   }\n   \n   var w = Merger.repo.branches[wid];\n   var r = Merger.repo.branches[rid];\n   \n\n\n    var rev = r.name + '..' + w.name;\n    this.release = r.name;\n    this.working = w.name;\n    \n    // this takes some time, lets. try and dialog it..\n\n    \n    \n    \n    var msg = new Gtk.MessageDialog( {\n        buttons : Gtk.ButtonsType.NONE,\n        text: \"Loading History\"\n        \n    });\n    \n    msg.set_transient_for(Merger.el);\n    msg.set_modal(true);\n    msg.show_all();\n\n    var hist = Merger.repo.dayTree('/', false, 'rev', rev);\n    msg.hide();\n    \n    this.load(hist);\n        \n       \n}\n",
+                                                            "|xns": "Gtk"
+                                                        },
+                                                        {
+                                                            "pack": "append_column",
+                                                            "title": "Changes",
+                                                            "xtype": "TreeViewColumn",
+                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 0 );\n\n}\n",
+                                                            "|xns": "Gtk",
+                                                            "items": [
+                                                                {
+                                                                    "pack": "pack_start",
+                                                                    "xtype": "CellRendererText",
+                                                                    "|xns": "Gtk"
+                                                                }
+                                                            ]
+                                                        }
+                                                    ]
+                                                }
+                                            ]
+                                        },
+                                        {
+                                            "xtype": "ScrolledWindow",
+                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n      this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
+                                            "|xns": "Gtk",
+                                            "items": [
+                                                {
+                                                    "listeners": {
+                                                        "cursor_changed": "function (self) {\n  // SEE SELECTION.CHANGED\n    var files = this.files();\n    this.get('/patchview').showDiff(files); \n    //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();\n     //print(\"OUT?\" + value);// id..\n    // load the list in the right grid..\n     \n    return true;\n\n}"
+                                                    },
+                                                    "id": "changedFilesView",
+                                                    "pack": "add",
+                                                    "xtype": "TreeView",
+                                                    "|files": "function() {\n     if (this.el.get_selection().count_selected_rows() < 1) {\n        //nothing? - clea it?\n        return [];\n    }\n\n    var ret = {};         \n \n\n     var s = this.el.get_selection();\n     var files = [];\n      s.selected_foreach(function(model,p,iter) {\n    \n       files.push( model.get_value(iter, 0).value.get_string());\n     \n    });\n    return files;\n}\n",
+                                                    "|init": "function() {\n    XObject.prototype.init.call(this);\n        var description = new Pango.FontDescription.c_new();\n   description.set_size(8000);\n     this.el.modify_font(description);\n\n     this.selection = this.el.get_selection();\n      this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);\n    var _this = this;\n  this.selection.signal['changed'].connect(function() {\n     _this.listeners.cursor_changed.apply(\n          _this, [ _this, '']\n       );\n             });\n  }\n",
+                                                    "|xns": "Gtk",
+                                                    "items": [
+                                                        {
+                                                            "id": "changedFilesStore",
+                                                            "pack": "set_model",
+                                                            "xtype": "ListStore",
+                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n       GObject.TYPE_STRING, // file  \n      GObject.TYPE_STRING, // added\n      GObject.TYPE_STRING, // removed\n  ] );\n}\n",
+                                                            "|load": "function(tr)\n{\n    //this.insert(citer,iter,0);\n    this.el.clear();\n    for(var i =0 ; i < tr.length; i++) {\n        var ret = {  };\n       \n        this.el.append(ret);\n        \n        //print(JSON.stringify(ret,null,4));\n         \n          \n        this.el.set_value(ret.iter, 0, ''  +  tr[i].filename );\n        this.el.set_value(ret.iter, 1, '' + tr[i].added  );\n        this.el.set_value(ret.iter, 2, '' + tr[i].removed  );\n \n        \n    }     \n}",
+                                                            "|xns": "Gtk"
+                                                        },
+                                                        {
+                                                            "resizable": true,
+                                                            "min_width": 200,
+                                                            "pack": "append_column",
+                                                            "title": "Filename",
+                                                            "xtype": "TreeViewColumn",
+                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 0 );\n\n}\n",
+                                                            "|xns": "Gtk",
+                                                            "items": [
+                                                                {
+                                                                    "pack": "pack_start",
+                                                                    "xtype": "CellRendererText",
+                                                                    "|xns": "Gtk"
+                                                                }
+                                                            ]
+                                                        },
+                                                        {
+                                                            "min_width": 50,
+                                                            "pack": "append_column",
+                                                            "title": "Added",
+                                                            "xtype": "TreeViewColumn",
+                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 1 );\n\n}\n",
+                                                            "|xns": "Gtk",
+                                                            "items": [
+                                                                {
+                                                                    "pack": "pack_start",
+                                                                    "xtype": "CellRendererText",
+                                                                    "|xns": "Gtk"
+                                                                }
+                                                            ]
+                                                        },
+                                                        {
+                                                            "min_width": 50,
+                                                            "pack": "append_column",
+                                                            "title": "Removed",
+                                                            "xtype": "TreeViewColumn",
+                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 2 );\n\n}\n",
+                                                            "|xns": "Gtk",
+                                                            "items": [
+                                                                {
+                                                                    "pack": "pack_start",
+                                                                    "xtype": "CellRendererText",
+                                                                    "|xns": "Gtk"
+                                                                }
+                                                            ]
+                                                        }
+                                                    ]
+                                                },
+                                                {
+                                                    "|xns": "Gtk",
+                                                    "xtype": "TreeView",
+                                                    "pack": false,
+                                                    "items": [
+                                                        {
+                                                            "|xns": "Gtk",
+                                                            "xtype": "ListStore",
+                                                            "pack": false
+                                                        }
+                                                    ]
+                                                }
+                                            ]
+                                        }
+                                    ]
+                                },
+                                {
+                                    "xtype": "VBox",
+                                    "|xns": "Gtk",
+                                    "items": [
+                                        {
+                                            "pack": "pack_start,false,false,0",
+                                            "xtype": "HBox",
+                                            "|xns": "Gtk",
+                                            "items": [
+                                                {
+                                                    "listeners": {
+                                                        "clicked": "function (self) {\n    \n     \n     var model = this.get('/historyTreeStore');\n    \n    if (model.release === false) {\n        return;\n    }\n    \n \n    var files = this.get('/changedFilesView').files();\n    \n     if (!files.length) {\n        return; // error.!\n    }\n    var diff = Merger.repo.diff(files, model.release, model.rev);\n   \n   \n   print(\"history?\");\n   \n    \n    var history =  Merger.repo.history(files, 1, 'rev', model.rev);\n    \n    print(\"History\" + JSON.stringify(history, null,4));\n    \n    Commit = imports.Commit.Commit;\n\n    Commit.el.set_modal(true);\n    Commit.el.set_transient_for(Merger.el);\n\n    var ce = Commit.show({\n        repo : Merger.repo,\n        files : files,\n        release : model.release,\n        rev : model.rev,\n        author : history[0].changeby,\n        changed : history[0].changed_raw\n        \n    \n    });\n    if (ce === false ) {\n        return;\n    }\n    \n    \n    var diff = Merger.repo.diff(files, model.release, model.rev);\n    \n    \n    print(JSON.stringify(ce,null,4));\n    //.... commit!!!\n    \n    imports.GitMonitor.GitMonitor.pause();\n    \n    \n    \n    var msg = new Gtk.MessageDialog( {\n        buttons : Gtk.ButtonsType.NONE,\n        text: \"Committing Changes\"\n    });\n    \n    msg.set_transient_for(Merger.el);\n    msg.set_modal(true);\n    msg.show_all();\n\n     \n    \n    try { \n        \n        Merger.repo.checkout(model.release);\n        \n        print(\"Call apply patch\");\n        \n        Merger.repo.applyPatch(diff);\n        \n        var author = Merger.repo.parseAuthor(ce.author);\n        \n        print(\"Add new files.\");\n        // add all the files..\n        Merger.repo.add(files);\n        \n        print(\"Commit changes.\");\n        Merger.repo.commit({\n            name    : author.name,\n            email   : author.email,\n            author  : ce.author,\n            changed : ce.changed,\n            reason  : ce.message,\n            files : files\n            \n        });\n        \n      \n    } catch (e) {\n     //message..\n        msg.hide();\n         \n        var emsg = new Gtk.MessageDialog({\n                message_type: Gtk.MessageType.ERROR, \n                buttons : Gtk.ButtonsType.OK, \n                text: e.message\n        });\n        emsg.set_transient_for(Merger.el);\n        emsg.set_modal(true);\n        emsg.run();\n        emsg.destroy();\n        Merger.repo.stash(); // revert change.. - so we can go back...\n    }\n    msg.show_all();\n    msg.set_markup(\"Changing to previous branch\");\n    Merger.repo.checkout(model.working);\n    \n    \n    // if gitlive was previously running warn the user that it is now paused..\n    /*\n    var cmsg = new Gtk.MessageDialog({\n            message_type: Gtk.MessageType.ERROR, \n            buttons : Gtk.ButtonsType.OK, \n            text: \"Git Live is now paused \"\n    });\n    cmsg.run();\n    cmsg.destroy();\n    */\n    var _t = this;\n    GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 5, function() {\n         imports.GitMonitor.GitMonitor.resume();\n         msg.hide();\n         msg.destroy();\n          _t.get('/historyTreeStore').loadTree();\n          _t.get('/changedFilesStore').el.clear();\n          _t.get('/patchview').showDiff(files); \n         return false; //only once.\n    });\n     \n    \n\n\n}   "
+                                                    },
+                                                    "label": "Commit diff (no merge)",
+                                                    "xtype": "Button",
+                                                    "|xns": "Gtk"
+                                                }
+                                            ]
+                                        },
+                                        {
+                                            "pack": "pack_end,true,true,0",
+                                            "xtype": "ScrolledWindow",
+                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n      this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
+                                            "|xns": "Gtk",
+                                            "items": [
+                                                {
+                                                    "id": "patchview",
+                                                    "pack": "add",
+                                                    "xtype": "WebView",
+                                                    "|clear": "function() {\n    \n    \n    \n     \n   // remove..\n    var s  = \"document.body.textContent='';\"\n        \n    this.el.execute_script(s);\n        \n        \n    \n    \n    \n}\n",
+                                                    "|showDiff": "function(files) {\n    this.clear();\n    \n    \n     var model = this.get('/historyTreeStore');\n    \n    if (model.release === false) {\n        return;\n    }\n    \n    var diff = Merger.repo.diff(files, model.release, model.rev);\n    \n   // remove..\n    var s  = \"var pre  = document.createElement('pre'); document.body.appendChild(pre);\";\n    s += \"pre.textContent =  \" +\n             JSON.stringify(Merger.repo.lastCmd + \"\\n\") + '+  ' + \n           JSON.stringify(diff) + \";\";\n    print(s);\n        \n    this.el.execute_script(s);\n        \n        \n    \n    \n    \n}\n",
+                                                    "|xns": "WebKit"
+                                                }
+                                            ]
+                                        }
+                                    ]
+                                }
+                            ]
+                        }
+                    ]
+                },
+                {
+                    "id": "ok_button",
+                    "label": "Close",
+                    "pack": "add_action_widget,1",
+                    "xtype": "Button",
+                    "|xns": "Gtk"
+                }
+            ]
+        }
+    ],
+    "permname": "",
+    "modOrder": ""
+}
\ No newline at end of file