Final User interface tweaks to basic commit code (shows dialogs while it does stuff)
[gitlive] / Monitor.js
index 7c36e7b..5d4ba1b 100644 (file)
@@ -1,6 +1,6 @@
 //<Script type="text/javascript">
-Gio      = imports.gi.Gio;
-GLib      = imports.gi.GLib;
+var Gio      = imports.gi.Gio;
+var GLib      = imports.gi.GLib;
 
 
 /**
@@ -22,7 +22,7 @@ GLib      = imports.gi.GLib;
  */
  
  
-Monitor = function(cfg){
+function Monitor(cfg){
     for (var i in cfg) {
         this[i] = cfg[i];
     }
@@ -38,6 +38,7 @@ Monitor.prototype = {
     
     monitors : false, // Array of GioFileMonitors
     top : false, // list of top level directories..
+    paused : false,
     /**
      * add a directory or file to monitor
      */
@@ -63,40 +64,71 @@ Monitor.prototype = {
         })
         this.monitors = [];
     },
+    /**
+     * pause monitoring - without changing what's monitored 
+     */
+    pause : function()
+    {
+        this.paused = true;
+    },
+    /**
+     * resume monitoring - without changing what's monitored 
+     */
+    resume : function()
+    {
+        this.paused = false;
+    },
     /**
      * monitor a file or directory (privatish)
+     *
+     * initially called with ~/gitlive  null 0 (effectvely)
      * 
      * 
      */
     monitor : function(path, fn, depth)
     {
         var _this = this;
-        depth = depth  ? depth *1 : 0;
+        
+       // print("ADD: " + path)
+        
+        depth = typeof(depth) == 'number'  ? depth *1 : 0;
+        
+        
         fn = fn || function (fm, f, of, event_type, uh) {
             _this.onEvent(fm, f, of, event_type, uh);
         }
        
-        if (depth > 0 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
+        // if we are not at top level.. and there is a .git directory  (it's a submodule .. ignore) 
+        if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
             return;
         }
             
        
        
-       
+        
         var f = Gio.file_new_for_path(path);
-        //var cancel = new Gio.Cancellable ();
-        var fm = f.monitor(2,null); //Gio.FileMonitorFlags.SEND_MOVED
-        fm.signal.changed.connect(fn);
-        this.monitors.push(fm);
+            //var cancel = new Gio.Cancellable ();
+        if (depth > 0) {     
+            var fm = f.monitor(2,null); //Gio.FileMonitorFlags.SEND_MOVED
+            fm.signal.changed.connect(fn);
+            this.monitors.push(fm);
+            // print("ADD path " + depth + ' ' + path);
+        }
         // iterate children?
         
+        if (GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR) && this.initRepo) {
+            
+            this.initRepo(path);
+        }
+        
+        
         var file_enum = f.enumerate_children(
             Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ','+ 
             Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
             Gio.FileQueryInfoFlags.NONE,
             null);
         
-        print("ADD path " + depth + ' ' + path);
+       
         
         while ((next_file = file_enum.next_file(null)) != null) {
          
@@ -119,6 +151,9 @@ Monitor.prototype = {
     
     onEvent : function(fm, f, of, event_type, uh)
     {
+        if (this.paused) {
+            return;
+        }
         var src = {
             name : f.get_basename(),
             path : f.get_path(),
@@ -136,8 +171,8 @@ Monitor.prototype = {
                 event_name = i;
             }
         }
-        print ("got event: " +event_name);
-        print ("got src: " + src.toString());
+        //print ("got event: " +event_name);
+        //print ("got src: " + src.toString());
         //print ("got event: " + src.toString());
         try {
                 
@@ -175,7 +210,7 @@ Monitor.prototype = {
     },
     
     /** override these to do stuff.. */
-     
+    initRepo : function(src) { }, // called on startup at the top level repo dir.
     onChanged : function(src) { },
     onChangesDoneHint : function(src) { },
     onDeleted : function(src) { },