WindowLog.js
[gitlive] / Monitor.js
index f026ff0..9e9bd0b 100644 (file)
@@ -5,6 +5,9 @@ var GLib      = imports.gi.GLib;
 
 /**
  * Monitor class - handles monitor managment for a large tree...
+ *
+ *
+ * This 
  * 
  * usage : 
  * x = new Monitor({
@@ -38,6 +41,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,6 +67,20 @@ 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)
      *
@@ -83,14 +101,7 @@ Monitor.prototype = {
             _this.onEvent(fm, f, of, event_type, uh);
         }
        
-        // 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 ();
         if (depth > 0) {     
@@ -100,11 +111,11 @@ Monitor.prototype = {
             // print("ADD path " + depth + ' ' + path);
         }
         // iterate children?
-        
-        if (GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR) && this.initRepo) {
+        // - this is not used.
+        //if (GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR) && this.initRepo) {
             
-            this.initRepo(path);
-        }
+        //    this.initRepo(path);
+        //}
         
         
         var file_enum = f.enumerate_children(
@@ -120,6 +131,11 @@ Monitor.prototype = {
             if (next_file.get_file_type() != Gio.FileType.DIRECTORY) {
                 continue;
             }
+            
+            if (next_file.get_file_type() == Gio.FileType.SYMBOLIC_LINK) {
+                continue;
+            }
+            
             if (next_file.get_display_name()[0] == '.') {
                 continue;
             }
@@ -134,18 +150,58 @@ Monitor.prototype = {
     },
     
     
-    onEvent : function(fm, f, of, event_type, uh)
+    
+    realpath : function(file)
+    {
+        if (!file) {
+            return file;
+        }
+        
+        if (GLib.file_test(file.get_path(), GLib.FileTest.EXISTS)) {
+            var rp = imports.os.realpath(file.get_path());
+            return Gio.file_new_for_path(rp);  
+            
+        }
+        // file does not currently exist..
+        // check parent.
+        var bn = file.get_basename();
+        var ar = file.get_path().split('/');
+        ar.pop();
+        var dirname = ar.join('/');
+        var rp = imports.os.realpath(dirname);
+        return Gio.file_new_for_path(rp + '/' + bn);
+        
+        
+    },
+    
+    
+    
+    onEvent : function(fm, f_orig, of_orig, event_type, uh)
     {
+        if (this.paused) {
+            return;
+        }
+        
+        var f = this.realpath(f_orig);
+        
+        var of = this.realpath(of_orig);
         var src = {
             name : f.get_basename(),
             path : f.get_path(),
             dir   : GLib.path_get_dirname(f.get_path())
         };
-        var dest = of ? {
-            name : of.get_basename(),
-            path : of.get_path(),
-            dir   : GLib.path_get_dirname(of.get_path())
-        } : false;
+        
+        var dest = false;
+        
+        if (of) {
+            
+            dest =  {
+                name : of.get_basename(),
+                path : of.get_path(),
+                dir   : GLib.path_get_dirname(of.get_path())
+            }
+        }
         
         
         for(var i in Gio.FileMonitorEvent) {
@@ -153,7 +209,8 @@ Monitor.prototype = {
                 event_name = i;
             }
         }
-        //print ("got event: " +event_name);
+        
+        //print (JSON.stringify([event_name , f.get_path(), of ? of.get_path() : false ] ));
         //print ("got src: " + src.toString());
         //print ("got event: " + src.toString());
         try {