Fix #5560 - Gitlive - branching wip
[gitlive] / old_seed_version / Merger.bjs
1 {
2     "id": "file-gtk-5",
3     "name": "Merger",
4     "parent": "",
5     "title": false,
6     "path": "/home/alan/gitlive/gitlive/Merger.bjs",
7     "items": [
8         {
9             "listeners": {
10                 "destroy_event": "function (self, event) {\n     this.el.hide();\n                return false;\n}",
11                 "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}"
12             },
13             "border_width": 3,
14             "default_height": 700,
15             "default_width": 800,
16             "id": "Merger",
17             "title": "Merger",
18             "xtype": "Dialog",
19             "|deletable": "true",
20             "|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",
21             "|xns": "Gtk",
22             "items": [
23                 {
24                     "xtype": "VBox",
25                     "|pack": " function(p,e) {\n        p.el.get_content_area().pack_start(e.el,true,true,0)\n    }\n",
26                     "|xns": "Gtk",
27                     "items": [
28                         {
29                             "pack": "pack_start,false,true",
30                             "xtype": "HBox",
31                             "|xns": "Gtk",
32                             "items": [
33                                 {
34                                     "label": "Working Branch",
35                                     "xtype": "Label",
36                                     "|xns": "Gtk"
37                                 },
38                                 {
39                                     "listeners": {
40                                         "changed": "function (self) {\n   this.get('/historyTreeStore').loadTree();\n}"
41                                     },
42                                     "id": "workingCombo",
43                                     "xtype": "ComboBox",
44                                     "|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",
45                                     "|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}",
46                                     "|xns": "Gtk",
47                                     "items": [
48                                         {
49                                             "*prop": "model",
50                                             "xtype": "ListStore",
51                                             "|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",
52                                             "|xns": "Gtk"
53                                         }
54                                     ]
55                                 },
56                                 {
57                                     "label": "Release Branch",
58                                     "xtype": "Label",
59                                     "|xns": "Gtk"
60                                 },
61                                 {
62                                     "listeners": {
63                                         "changed": "function (self) {\n   this.get('/historyTreeStore').loadTree();\n}"
64                                     },
65                                     "id": "releaseCombo",
66                                     "xtype": "ComboBox",
67                                     "|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",
68                                     "|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}",
69                                     "|xns": "Gtk",
70                                     "items": [
71                                         {
72                                             "*prop": "model",
73                                             "xtype": "ListStore",
74                                             "|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",
75                                             "|xns": "Gtk"
76                                         }
77                                     ]
78                                 }
79                             ]
80                         },
81                         {
82                             "pack": "pack_end,true,true,0",
83                             "position": 400,
84                             "xtype": "VPaned",
85                             "|xns": "Gtk",
86                             "items": [
87                                 {
88                                     "pack": "add",
89                                     "position": 200,
90                                     "xtype": "HPaned",
91                                     "|xns": "Gtk",
92                                     "items": [
93                                         {
94                                             "xtype": "ScrolledWindow",
95                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n     this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
96                                             "|xns": "Gtk",
97                                             "items": [
98                                                 {
99                                                     "listeners": {
100                                                         "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}"
101                                                     },
102                                                     "pack": "add",
103                                                     "xtype": "TreeView",
104                                                     "|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",
105                                                     "|xns": "Gtk",
106                                                     "items": [
107                                                         {
108                                                             "id": "historyTreeStore",
109                                                             "pack": "set_model",
110                                                             "release": false,
111                                                             "xtype": "TreeStore",
112                                                             "|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",
113                                                             "|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}",
114                                                             "|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",
115                                                             "|xns": "Gtk"
116                                                         },
117                                                         {
118                                                             "pack": "append_column",
119                                                             "title": "Changes",
120                                                             "xtype": "TreeViewColumn",
121                                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 0 );\n\n}\n",
122                                                             "|xns": "Gtk",
123                                                             "items": [
124                                                                 {
125                                                                     "pack": "pack_start",
126                                                                     "xtype": "CellRendererText",
127                                                                     "|xns": "Gtk"
128                                                                 }
129                                                             ]
130                                                         }
131                                                     ]
132                                                 }
133                                             ]
134                                         },
135                                         {
136                                             "xtype": "ScrolledWindow",
137                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n      this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
138                                             "|xns": "Gtk",
139                                             "items": [
140                                                 {
141                                                     "listeners": {
142                                                         "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}"
143                                                     },
144                                                     "id": "changedFilesView",
145                                                     "pack": "add",
146                                                     "xtype": "TreeView",
147                                                     "|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",
148                                                     "|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",
149                                                     "|xns": "Gtk",
150                                                     "items": [
151                                                         {
152                                                             "id": "changedFilesStore",
153                                                             "pack": "set_model",
154                                                             "xtype": "ListStore",
155                                                             "|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",
156                                                             "|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}",
157                                                             "|xns": "Gtk"
158                                                         },
159                                                         {
160                                                             "resizable": true,
161                                                             "min_width": 200,
162                                                             "pack": "append_column",
163                                                             "title": "Filename",
164                                                             "xtype": "TreeViewColumn",
165                                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 0 );\n\n}\n",
166                                                             "|xns": "Gtk",
167                                                             "items": [
168                                                                 {
169                                                                     "pack": "pack_start",
170                                                                     "xtype": "CellRendererText",
171                                                                     "|xns": "Gtk"
172                                                                 }
173                                                             ]
174                                                         },
175                                                         {
176                                                             "min_width": 50,
177                                                             "pack": "append_column",
178                                                             "title": "Added",
179                                                             "xtype": "TreeViewColumn",
180                                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 1 );\n\n}\n",
181                                                             "|xns": "Gtk",
182                                                             "items": [
183                                                                 {
184                                                                     "pack": "pack_start",
185                                                                     "xtype": "CellRendererText",
186                                                                     "|xns": "Gtk"
187                                                                 }
188                                                             ]
189                                                         },
190                                                         {
191                                                             "min_width": 50,
192                                                             "pack": "append_column",
193                                                             "title": "Removed",
194                                                             "xtype": "TreeViewColumn",
195                                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 2 );\n\n}\n",
196                                                             "|xns": "Gtk",
197                                                             "items": [
198                                                                 {
199                                                                     "pack": "pack_start",
200                                                                     "xtype": "CellRendererText",
201                                                                     "|xns": "Gtk"
202                                                                 }
203                                                             ]
204                                                         }
205                                                     ]
206                                                 },
207                                                 {
208                                                     "|xns": "Gtk",
209                                                     "xtype": "TreeView",
210                                                     "pack": false,
211                                                     "items": [
212                                                         {
213                                                             "|xns": "Gtk",
214                                                             "xtype": "ListStore",
215                                                             "pack": false
216                                                         }
217                                                     ]
218                                                 }
219                                             ]
220                                         }
221                                     ]
222                                 },
223                                 {
224                                     "xtype": "VBox",
225                                     "|xns": "Gtk",
226                                     "items": [
227                                         {
228                                             "pack": "pack_start,false,false,0",
229                                             "xtype": "HBox",
230                                             "|xns": "Gtk",
231                                             "items": [
232                                                 {
233                                                     "listeners": {
234                                                         "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}   "
235                                                     },
236                                                     "label": "Commit diff (no merge)",
237                                                     "xtype": "Button",
238                                                     "|xns": "Gtk"
239                                                 }
240                                             ]
241                                         },
242                                         {
243                                             "pack": "pack_end,true,true,0",
244                                             "xtype": "ScrolledWindow",
245                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n      this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
246                                             "|xns": "Gtk",
247                                             "items": [
248                                                 {
249                                                     "id": "patchview",
250                                                     "pack": "add",
251                                                     "xtype": "WebView",
252                                                     "|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",
253                                                     "|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",
254                                                     "|xns": "WebKit"
255                                                 }
256                                             ]
257                                         }
258                                     ]
259                                 }
260                             ]
261                         }
262                     ]
263                 },
264                 {
265                     "id": "ok_button",
266                     "label": "Close",
267                     "pack": "add_action_widget,1",
268                     "xtype": "Button",
269                     "|xns": "Gtk"
270                 }
271             ]
272         }
273     ],
274     "permname": "",
275     "modOrder": ""
276 }