# HG changeset patch
# User Simon Heimberg <[email protected]>
# Date 1238183010 -3600
# Node ID 6440156bc2f9bf6ea0c1639ba64f5175bfbfabb9
# Parent  6eedd2d5972e81c3bd1bb1e8453a612fa17911ff
nautilus: notify from hggtk dialogs

hgtk writes the names of the changed files to ~/.tortoisehg/notify
nautilus-thg monitors this file, reads the data and truncates the file
the icons of the files and of their parent directories are invalidated

diff -r 6eedd2d5972e -r 6440156bc2f9 contrib/nautilus-thg.py
--- a/contrib/nautilus-thg.py   Die Mai 12 09:59:34 2009 +0200
+++ b/contrib/nautilus-thg.py   Fre Mär 27 20:43:30 2009 +0100
@@ -12,6 +12,7 @@
 import gtk
 import gobject
 import nautilus
+import gnomevfs
 
 try:
     from mercurial import demandimport
@@ -64,18 +65,43 @@
         self.cacherepo = None
         self.cacheroot = None
         self.scanStack = []
+        self.allvfs = {}
+        self.inv_dirs = set()
 
         from thgutil import menuthg
         self.hgtk = paths.find_in_path('hgtk')
         self.menu = menuthg.menuThg()
+        self.notify = os.path.expanduser('~/.tortoisehg/notify')
+        try:
+            f = open(self.notify, 'w')
+            f.close()
+            ds_uri = gnomevfs.get_uri_from_local_path(self.notify)
+            self.gmon = gnomevfs.monitor_add(ds_uri,
+                      gnomevfs.MONITOR_FILE, self.notified)
+        except (gnomevfs.NotSupportedError, IOError), e:
+            debugf('no notification because of %s', e)
+            self.notify = ''
 
     def icon(self, iname):
         return paths.get_tortoise_icon(iname)
 
-    def get_path_for_vfs_file(self, vfs_file):
-        if vfs_file.is_gone() or vfs_file.get_uri_scheme() != 'file':
+    def get_path_for_vfs_file(self, vfs_file, store=True):
+        if vfs_file.get_uri_scheme() != 'file':
             return None
-        return urllib.unquote(vfs_file.get_uri()[7:])
+        path = urllib.unquote(vfs_file.get_uri()[7:])
+        if vfs_file.is_gone():
+            self.allvfs.pop(path, '')
+            return None
+        if store:
+            self.allvfs[path] = vfs_file
+        return path
+
+    def get_vfs(self, path):
+        vfs = self.allvfs.get(path, None)
+        if vfs and vfs.is_gone():
+            del self.allvfs[path]
+            return None
+        return vfs
 
     def get_repo_for_path(self, path):
         '''
@@ -239,6 +265,50 @@
         vfs_file.add_string_attribute('hg_status', status)
         return True
 
+    def notified(self, mon_uri=None, event_uri=None, event=None):
+        debugf('notified from hgtk, %s', event, level='n')
+        f = open(self.notify, 'a+')
+        files = None
+        try:
+            files = [line[:-1] for line in f if line]
+            if files:
+                f.truncate(0)
+        finally:
+            f.close()
+        if not files:
+            return
+        root = os.path.commonprefix(files)
+        root = paths.find_root(root)
+        self.invalidate(files, root)
+
+    def invalidate(self, paths, root = ''):
+        from tortoise import cachethg
+        started = bool(self.inv_dirs)
+        if cachethg.cache_pdir == root and root not in self.inv_dirs:
+            cachethg.overlay_cache.clear()
+        self.inv_dirs.update([os.path.dirname(root), '/', ''])
+        for path in paths:
+            path = os.path.join(root, path)
+            while path not in self.inv_dirs:
+                self.inv_dirs.add(path)
+                path = os.path.dirname(path)
+                if cachethg.cache_pdir == path:
+                    cachethg.overlay_cache.clear()
+        if started:
+            return
+        if len(paths) > 1:
+            self._invalidate_dirs()
+        else:
+            #group invalidation of directories
+            gobject.timeout_add(200, self._invalidate_dirs)
+
+    def _invalidate_dirs(self):
+        for path in self.inv_dirs:
+            vfs = self.get_vfs(path)
+            if vfs:
+                vfs.invalidate_extension_info()
+        self.inv_dirs.clear()
+
     # property page borrowed from http://www.gnome.org/~gpoo/hg/nautilus-hg/
     def __add_row(self, row, label_item, label_value):
         label = gtk.Label(label_item)
diff -r 6eedd2d5972e -r 6440156bc2f9 thgutil/shlib.py
--- a/thgutil/shlib.py  Die Mai 12 09:59:34 2009 +0200
+++ b/thgutil/shlib.py  Fre Mär 27 20:43:30 2009 +0100
@@ -178,4 +178,17 @@
                                  pidl, None)
 else:
     def shell_notify(paths):
-        pass
+        if not paths:
+            return
+        notify = os.environ.get('THG_NOTIFY', '.tortoisehg/notify')
+        if not os.path.isabs(notify):
+            notify = os.path.join(os.path.expanduser('~'), notify)
+            os.environ['THG_NOTIFY'] = notify
+        if not os.path.isfile(notify):
+            return
+        f_notify = open(notify, 'w')
+        try:
+            f_notify.write('\n'.join([os.path.abspath(path) for path in 
paths]))
+        finally:
+            f_notify.close()
+
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Tortoisehg-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to