Commit 916707c0 authored by Paolo Borelli's avatar Paolo Borelli

snippets bugfixes from Jesse

parent c97b32b9
2006-02-18 Jesse van den Kieboom <jesse@icecrew.nl>
* plugins/snippets/snippets/SnippetsLibrary.py: give more informative
error messages when loading a file fails. Only add snippets once the
whole file loaded ok.
* plugins/snippets/snippets/SnippetPluginInstance.py: fix adding
SnippetControllers to views in the window when activating the snippets
plugin
* po/POTFILES.in: removed plugins/snippets/snippets/__init__.py as it
no longer contains translatable strings
2006-02-14 Steve Frécinaux <steve@istique.net>
* plugins/externaltools/tools/tools.glade: use "Accelerator" instead
......
......@@ -44,7 +44,7 @@ class SnippetsPluginInstance:
# Add controllers to all the current views
for view in self.window.get_views():
if isinstance(view, gedit.View) and not self.has_controller(view):
view._snippet_controller = SnippetController(view)
view._snippet_controller = SnippetController(self, view)
self.update()
......
......@@ -322,9 +322,13 @@ class SnippetsSystemFile:
self.language = None
self.ok = True
def load_error(self, message):
sys.stderr.write("An error occurred loading " + self.path + ":\n")
sys.stderr.write(message + "\nSnippets in this file will not be " \
"available, please correct or remove the file.\n")
def _add_snippet(self, element):
snippet = SnippetsLibrary().add_snippet(self, element)
return snippet
self.loading_elements.append(element)
def set_language(self, element):
self.language = element.attrib.get('language')
......@@ -338,12 +342,15 @@ class SnippetsSystemFile:
def _preprocess_element(self, element):
if not self.loaded:
if not element.tag == "snippets":
self.load_error("Root element should be `snippets' instead " \
"of `%s'" % element.tag)
return False
else:
self._set_root(element)
self.loaded = True
elif element.tag != 'snippet' and not self.insnippet:
snippets_debug('Element is not of type snippet: ' + element.tag)
self.load_error("Element should be `snippet' instead of `%s'" \
% element.tag)
return False
else:
self.insnippet = True
......@@ -405,17 +412,22 @@ class SnippetsSystemFile:
self.loaded = False
self.ok = False
self.loading_elements = []
for element in self.parse_xml():
if element[1]:
if not self._preprocess_element(element[0]):
sys.stderr.write("Error while preprocessing!\n")
del self.loading_elements[:]
return
else:
if not self._process_element(element[0]):
sys.stderr.write("Error while post processing!\n")
del self.loading_elements[:]
return
for element in self.loading_elements:
snippet = SnippetsLibrary().add_snippet(self, element)
del self.loading_elements[:]
self.ok = True
# This function will get the language for a file by just inspecting the
......
......@@ -64,7 +64,6 @@ plugins/sample/gedit-sample-plugin.c
plugins/sample/sample.gedit-plugin.desktop.in
plugins/snippets/snippets.gedit-plugin.desktop.in
plugins/snippets/snippets/snippets.glade
plugins/snippets/snippets/__init__.py
plugins/snippets/snippets/SnippetPluginInstance.py
plugins/snippets/snippets/SnippetsDialog.py
plugins/sort/gedit-sort-plugin.c
......
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