home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / gedit-2 / plugins / snippets / __init__.py next >
Encoding:
Python Source  |  2009-04-14  |  3.2 KB  |  94 lines

  1. #    Gedit snippets plugin
  2. #    Copyright (C) 2005-2006  Jesse van den Kieboom <jesse@icecrew.nl>
  3. #
  4. #    This program is free software; you can redistribute it and/or modify
  5. #    it under the terms of the GNU General Public License as published by
  6. #    the Free Software Foundation; either version 2 of the License, or
  7. #    (at your option) any later version.
  8. #
  9. #    This program is distributed in the hope that it will be useful,
  10. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. #    GNU General Public License for more details.
  13. #
  14. #    You should have received a copy of the GNU General Public License
  15. #    along with this program; if not, write to the Free Software
  16. #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17.  
  18. import sys
  19. import os
  20. import shutil
  21.  
  22. import gtk
  23. from gtk import gdk    
  24. import gedit
  25. import platform
  26.  
  27. from WindowHelper import WindowHelper
  28. from Library import Library
  29. from Manager import Manager
  30. from Snippet import Snippet
  31.  
  32. class SnippetsPlugin(gedit.Plugin):
  33.         def __init__(self):
  34.                 gedit.Plugin.__init__(self)
  35.  
  36.                 self.dlg = None
  37.                 
  38.                 library = Library()
  39.                 library.set_accelerator_callback(self.accelerator_activated)
  40.                 
  41.                 if platform.platform() == 'Windows':
  42.                     userdir = os.path.expanduser('~/gedit/snippets')
  43.             else:
  44.                 userdir = os.path.expanduser('~/.gnome2/gedit/snippets')
  45.  
  46.                 library.set_dirs(userdir, self.system_dirs())
  47.         
  48.         def system_dirs(self):
  49.             if platform.platform() != 'Windows':
  50.                 if 'XDG_DATA_DIRS' in os.environ:
  51.                         datadirs = os.environ['XDG_DATA_DIRS']
  52.                 else:
  53.                         datadirs = '/usr/local/share:/usr/share'
  54.                 
  55.                 dirs = []
  56.                 
  57.                 for d in datadirs.split(':'):
  58.                         d = os.path.join(d, 'gedit-2', 'plugins', 'snippets')
  59.                         
  60.                         if os.path.isdir(d):
  61.                                 dirs.append(d)
  62.                 
  63.                 dirs.append(self.get_data_dir())
  64.                 return dirs
  65.         
  66.         def activate(self, window):
  67.                 data = WindowHelper(self)
  68.                 window._snippets_plugin_data = data
  69.                 data.run(window)
  70.  
  71.         def deactivate(self, window):
  72.                 window._snippets_plugin_data.stop()
  73.                 window._snippets_plugin_data = None
  74.                 
  75.         def update_ui(self, window):
  76.                 window._snippets_plugin_data.update()
  77.         
  78.         def create_configure_dialog(self):
  79.                 if not self.dlg:
  80.                         self.dlg = Manager(self.get_data_dir())
  81.                 else:
  82.                         self.dlg.run()
  83.                 
  84.                 window = gedit.app_get_default().get_active_window()
  85.                 
  86.                 if window:
  87.                         self.dlg.dlg.set_transient_for(window)
  88.                 
  89.                 return self.dlg.dlg
  90.         
  91.         def accelerator_activated(self, group, obj, keyval, mod):
  92.                 if hasattr(obj, '_snippets_plugin_data'):
  93.                         obj._snippets_plugin_data.accelerator_activated(keyval, mod)
  94.