Final User interface tweaks to basic commit code (shows dialogs while it does stuff)
[gitlive] / gitlive.js
index 0c6972d..d426fce 100644 (file)
 * 
 * 
 */
-GI      = imports.gi.GIRepository;
-Gio      = imports.gi.Gio;
-GLib      = imports.gi.GLib;
-Gtk      = imports.gi.Gtk;
-Notify = imports.gi.Notify;
 
-Spawn = imports.Spawn;
-Git = imports.Git;
-StatusIcon = imports.StatusIcon.StatusIcon;
-Monitor = imports.Monitor.Monitor;
+GIRepository      = imports.gi.GIRepository
+GLib        = imports.gi.GLib;
 
+//print(JSON.stringify(GI, null,4));
+// we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
+// see the install instructions on how to override the default gir's
+GIRepository.Repository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.2');
+
+var Gio      = imports.gi.Gio;
+var Gtk      = imports.gi.Gtk;
+var Notify = imports.gi.Notify;
 
-//File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
-Gtk.init (null, null);
  
-var gitlive = GLib.get_home_dir() + "/gitlive";
+var StatusIcon = imports.StatusIcon.StatusIcon;
+var Monitor = imports.Monitor.Monitor;
+var GitMonitor  = imports.GitMonitor.GitMonitor;
+
+
+Gtk.init (null, null);
+
+// sanity check...
 
-if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
+// where is everything..
+GitMonitor.gitlive =  GLib.get_home_dir() + "/gitlive";
+
+if (!GLib.file_test(GitMonitor.gitlive, GLib.FileTest.IS_DIR)) {
     var msg = new Gtk.MessageDialog({message_type:
         Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
     msg.run();
     msg.destroy();
-    
     Seed.quit();
 }
 
-
-
-var monitor = new Monitor({
-    
-    queue : [],
-    nqv : true, // temp var while I switch to queued version.
-    
-    start: function() {
-        var _this = this;
-        this.lastAdd = new Date();
-        
-        Glib.idle_add(PRIORITY_LOW, function() {
-            if (!_this.queue.length) {
-                return 0;
-            }
-            var last = Math.floor(((new Date()) - this.lastAdd) / 100);
-            if (last < 5) { // wait 1/2 a seconnd before running.
-                return 0;
-            }
-            _this.runQueue();
-        },null,null);
-        
-        Monitor.prototype.start.call(this);
-        var notification = new Notify.Notification({
-            summary: "Git Live",
-            body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
-        });
-
-        notification.set_timeout(500);
-        notification.show();   
-        
-    },
-    
-    runQueue: function()
-    {
-        var cmd;
-        while (true) {
-            cmd = array_shift(this.queue);
-            var sp = Git.run.call(cmd);
-            
-            if (!this.queue.length) {
-                break;
-            }
-            
-        }
-        
-        var notification = new Notify.Notification({
-            summary: "Git Live",
-            body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
-        });
-
-        notification.set_timeout(500);
-        notification.show();   
-        
-    }
-    
-    shouldIgnore: function(f)
-    {
-        if (f.name[0] == '.') {
-            // except!
-            if (f.name == '.htaccess') {
-                return false;
-            }
-            
-            return true;
-        }
-        if (f.name.match(/~$/)) {
-            return true;
-        }
-        // ignore anything in top level!!!!
-        if (!f.vpath.length) {
-            return true;
-        }
-        
-        return false;
-        
-    },
-    
-    parsePath: function(f) {
-           
-        var vpath_ar = f.path.substring(gitlive.length +1).split('/');
-        
-        f.gitpath = gitlive + '/' + vpath_ar.shift();
-        f.vpath =  vpath_ar.join('/');
-        
-        
-    },
-    
-    just_created : {},
-      
-    onChanged : function(src) 
-    { 
-        return; // always ignore this..?
-        //this.parsePath(src);
-    },
-    onChangesDoneHint : function(src) 
-    { 
-        this.parsePath(src);
-        if (this.shouldIgnore(src)) {
-            return;
-        }
-        
-        var add_it = false;
-        if (typeof(this.just_created[src.path]) !='undefined') {
-            delete this.just_created[src.path];
-            this.lastAdd = new Date();
-            this.queue.push( 
-                [ src.gitpath,  'add', src.vpath ],
-                [ src.gitpath,  'commit',  src.vpath, { message: src.vpath} ],
-                [ src.gitpath , 'push', { all: true } ]
-                
-            );
-            if (this.nqv) {
-                
-                Git.run(src.gitpath, 'add', src.vpath);
-                var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
-                Git.run(src.gitpath , 'push', { all: true } );
-                notify(src.name,"CHANGED", sp);
-            }
-            return;
-        }
-        this.lastAdd = new Date();
-        this.queue.push( 
-            [ src.gitpath,  'add', src.vpath ],
-            [ src.gitpath,  'commit', src.vpath, {  message: src.vpath} ],
-            [ src.gitpath , 'push', { all: true } ]
-            
-        );
-        if (this.nqv) {
-            var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
-            Git.run(src.gitpath , 'push', '--all' );
-            notify(src.name,"CHANGED", sp);
-        }
-
-    },
-    onDeleted : function(src) 
-    { 
-        this.parsePath(src);
-        if (this.shouldIgnore(src)) {
-            return;
-        }
-        // should check if monitor needs removing..
-        // it should also check if it was a directory.. - so we dont have to commit all..
-        
-        this.lastAdd = new Date();
-        this.queue.push( 
-            [ src.gitpath, 'rm' , src.vpath ],
-            [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
-            [ src.gitpath, 'push', { all: true } ]
-        );
-        if (!this.nqv) {
-            return;
-        }
-        
-        var sp = Git.run(src.gitpath,'rm' , src.vpath);
-        Git.run(src.gitpath , 'push', { all: true } );
-        if (sp.status !=0) {
-            notify(src.name,"DELETED", sp);
-            return;
-        }
-        sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
-        Git.run(src.gitpath , 'push',{ all: true });
-        notify(src.name,"DELETED", sp);
-        return;
-        
-    },
-    onCreated : function(src) 
-    { 
-        this.parsePath(src);
-        if (this.shouldIgnore(src)) {
-            return;
-        }
-        
-        if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
-            this.just_created[src.path] = true;
-            return; // we do not handle file create flags... - use done hint.
-        }
-        // director has bee created
-        this.monitor(src.path);
-        this.lastAdd = new Date();
-        this.queue.push( 
-            [ src.gitpath, 'add' , src.vpath,  { all: true } ],
-            [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
-            [ src.gitpath, 'push', { all: true } ]
-        );
-        if (!this.nqv) {
-            return;
-        }
-        var sp = Git.run(src.gitpath, 'add', src.vpath);
-        Git.run(src.gitpath , 'push', { all: true } );
-
-        if (sp.status !=0) {
-            notify(src.path,"CREATED", sp);
-            return;
-        }
-        //uh.call(fm,f,of, event_type);
-        sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
-        Git.run(src.gitpath , 'push', { all: true } );
-        notify(src.path,"CREATED", sp);
-        return;
-        
-    },
-    onAttributeChanged : function(src) { 
-        this.parsePath(src);
-        if (this.shouldIgnore(src)) {
-            return;
-        }
-        this.lastAdd = new Date();
-        this.queue.push( 
-            [ src.gitpath, 'commit' ,  src.vpath, { message: src.vpath} ],
-            [ src.gitpath, 'push', { all: true } ]
-        );
-        if (!this.nqv) {
-            return;
-        }
-        var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
-        Git.run(src.gitpath , 'push', { all: true } );
-        notify(src.path,"ATTRIBUTE_CHANGED", sp);
-        return;
-    
-    },
-    
-    onMoved : function(src,dest)
-    { 
-        this.parsePath(src);
-        this.parsePath(dest);
-        
-        if (src.gitpath != dest.gitpath) {
-            this.onDeleted(src);
-            this.onCreated(dest);
-            this.onChangedDoneHint(dest);
-            return;
-        }
-        // needs to handle move to/from unsupported types..
-        
-        if (this.shouldIgnore(src)) {
-            return;
-        }
-        if (this.shouldIgnore(dest)) {
-            return;
-        }
-        this.lastAdd = new Date();
-        this.queue.push( 
-            [ src.gitpath, 'mv',  '-k', src.vpath, dest.vpath ],
-            [ src.gitpath, 'commit' ,  src.vpath, dest.vpath ,
-                { message:   'MOVED ' + src.vpath +' to ' + dest.vpath} ],
-            [ src.gitpath, 'push', { all: true } ]
-        );
-        
-        if (!this.nqv) {
-            return;
-        }
-        
-        var sp = Git.run(src.gitpath,  'mv',  '-k', src.vpath, dest.vpath);
-        if (sp.status !=0) {
-            notify(dest.path,"MOVED", sp);
-            return;
-        }
-        sp = Git.run(src.gitpath,'commit' , { all: true, message:   'MOVED ' + src.vpath +' to ' + dest.vpath} );
-        Git.run(src.gitpath , 'push', { all: true } );
-        notify(src.path,"MOVED", sp);
-        
-    }
-          
-    
-});
-
-function notify(fn, act , sp)
-{
-    var sum = act + " " + fn;
-    
-    var notification = new Notify.Notification({
-       summary: sum,
-               body : sp
-       });
-
-    notification.set_timeout(500);
-    notification.show();
-}
-
-
-
-  
+// I'm lost...
 
 function errorDialog(data) {
     var msg = new Gtk.MessageDialog({
@@ -334,15 +57,18 @@ function errorDialog(data) {
 
  
 
-
-
 //
 // need a better icon...
 
-StatusIcon.init(); 
+
+StatusIcon.init();   
+
+
 Notify.init("gitlive");
-monitor.add(GLib.get_home_dir() + "/gitlive");
-monitor.start();
+
+GitMonitor.add(GitMonitor.gitlive);
+GitMonitor.start();
+
 Gtk.main();
-//icon.signal["activate"].connect(on_left_click);
+vv//icon.signal["activate"].connect(on_left_click);