Commit 97c63103 authored by Paolo Borelli's avatar Paolo Borelli

lazy loading by Jesse

parent 0e1a6e82
2006-02-19 Jesse van den Kieboom <jesse@icecrew.nl>
* plugins/snippets/snippets/SnippetsLibrary.py: inspect files as lazy as
possible. Files will be scanned now on first request for snippet data from
the plugin (either dialog or controller in the view)
* plugins/snippets/snippets/__init__.py: remove old error message code,
call SnippetsLibrary().set_dirs instead of SnippetsLibrary().set_data
2006-02-18 Paolo Maggi <paolo@gnome.org>
Lazy loading of taglists (improve gedit startup time when taglist plugin
......
......@@ -558,6 +558,8 @@ class SnippetsLibraryImpl:
def __init__(self):
self._accelerator_activated_cb = None
self.loaded = False
# Contains all the language containers which have tag/accel mappings
self.containers = {}
......@@ -567,20 +569,15 @@ class SnippetsLibraryImpl:
# Contains the suppressed snippets
self.overridden = {}
def set_data(self, userdir, systemdirs):
def set_dirs(self, userdir, systemdirs):
self.userdir = userdir
self.systemdirs = systemdirs
self.libraries = {}
self.containers = {}
self.overridden = {}
self.userdir = userdir
searched = []
searched = self.find_libraries(userdir, searched, \
self._add_user_library)
for d in systemdirs:
searched = self.find_libraries(d, searched, \
self._add_system_library)
self.loaded = False
def set_accelerator_callback(self, cb):
self._accelerator_activated_cb = cb
......@@ -776,12 +773,7 @@ class SnippetsLibraryImpl:
def ref(self, language):
language = self.normalize_language(language)
if not language in self.libraries:
return
snippets_debug('Ref:', language)
self.ensure(language)
self.container(language).ref()
def unref(self, language):
......@@ -803,18 +795,35 @@ class SnippetsLibraryImpl:
def ensure(self, language):
language = self.normalize_language(language)
if language in self.libraries:
# Ensure language as well as the global snippets (None)
for lang in (None, language):
if lang in self.libraries:
# Ensure the container exists
self.container(language)
self.container(lang)
for library in self.libraries[language]:
for library in self.libraries[lang]:
library.ensure()
def ensure_files(self):
if self.loaded:
return
searched = []
searched = self.find_libraries(self.userdir, searched, \
self._add_user_library)
for d in self.systemdirs:
searched = self.find_libraries(d, searched, \
self._add_system_library)
self.loaded = True
# Snippet getters
# ===============
# Get snippets for a given language
def get_snippets(self, language=None):
self.ensure_files()
language = self.normalize_language(language)
if not language in self.libraries:
......@@ -827,8 +836,9 @@ class SnippetsLibraryImpl:
# Get snippets for a given accelerator
def from_accelerator(self, accelerator, language=None):
result = []
self.ensure_files()
result = []
language = self.normalize_language(language)
if not language in self.containers:
......@@ -844,8 +854,9 @@ class SnippetsLibraryImpl:
# Get snippets for a given tag
def from_tag(self, tag, language=None):
result = []
self.ensure_files()
result = []
language = self.normalize_language(language)
if not language in self.containers:
......
......@@ -36,15 +36,7 @@ class SnippetsPlugin(gedit.Plugin):
library.set_accelerator_callback(self.accelerator_activated)
userdir = os.path.join(os.environ['HOME'], '.gnome2', 'gedit', 'snippets')
library.set_data(userdir, self.system_dirs())
#self.xml_error_message = \
# _('Could not load the file "%s". ' \
# 'The file is probably corrupt. Please fix or ' \
# 'remove the file. To try to load the file again, select ' \
# 'the Tools -> Manage Snippets... menu item.') % self.XML_FILE
#self.show_xml_error = not self.load_xml()
library.set_dirs(userdir, self.system_dirs())
def system_dirs(self):
if 'XDG_DATA_DIRS' in os.environ:
......@@ -62,18 +54,10 @@ class SnippetsPlugin(gedit.Plugin):
return dirs
def idle_error_message(self, window):
message_dialog(window, gtk.MESSAGE_ERROR, self.xml_error_message)
return False
def activate(self, window):
data = SnippetsPluginInstance(self)
window._snippets_plugin_data = data
data.run(window)
#if self.show_xml_error:
# self.show_xml_error = None
# gobject.idle_add(self.idle_error_message, window)
def deactivate(self, window):
window._snippets_plugin_data.stop()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment