[gedit-latex] Tweak the DocumentPrefs work to prefer any key over ini or system settings.
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-latex] Tweak the DocumentPrefs work to prefer any key over ini or system settings.
- Date: Wed, 17 Aug 2011 11:08:00 +0000 (UTC)
commit a7e9361bccd89dd03f511f58456ae97159db4cff
Author: John Stowers <john stowers gmail com>
Date: Wed Aug 17 22:35:45 2011 +1200
Tweak the DocumentPrefs work to prefer any key over
ini or system settings.
Use this new ability to allow one to specify the graphics
paths and extensions from the master document, either via
modelines, or via ini files
...org.gnome.gedit.plugins.latex.gschema.xml.in.in | 8 ++++
latex/latex/editor.py | 10 +++--
latex/latex/validator.py | 40 ++++++++++++--------
latex/preferences/__init__.py | 17 +++++---
test/article.tex | 6 +++
test/chap3.tex | 2 +-
6 files changed, 56 insertions(+), 27 deletions(-)
---
diff --git a/data/org.gnome.gedit.plugins.latex.gschema.xml.in.in b/data/org.gnome.gedit.plugins.latex.gschema.xml.in.in
index b00eab9..ec7b930 100644
--- a/data/org.gnome.gedit.plugins.latex.gschema.xml.in.in
+++ b/data/org.gnome.gedit.plugins.latex.gschema.xml.in.in
@@ -47,6 +47,14 @@
<default>'.tex,.sty,.Rnw'</default>
<_summary>LaTeX Extensions</_summary>
</key>
+ <key name="graphics-extensions" type="s">
+ <default>'.eps,.pdf,.jpg,.jpeg,.gif,.png'</default>
+ <_summary>Graphics File Extensions</_summary>
+ </key>
+ <key name="graphics-paths" type="s">
+ <default>'.'</default>
+ <_summary>Paths Relative to .tex File to Look for Graphics</_summary>
+ </key>
<key name="light-foreground-color" type="s">
<default>'#957d47'</default>
diff --git a/latex/latex/editor.py b/latex/latex/editor.py
index 9c9daef..8a75e19 100644
--- a/latex/latex/editor.py
+++ b/latex/latex/editor.py
@@ -287,7 +287,7 @@ class LaTeXEditor(Editor, IIssueHandler):
self._outline_view.set_outline(self._outline)
# validate
- self._validator.validate(self._document, self._outline, self)
+ self._validator.validate(self._document, self._outline, self, self._preferences)
else:
self._log.debug("Document is not a master")
@@ -318,7 +318,9 @@ class LaTeXEditor(Editor, IIssueHandler):
self._outline = self._outline_generator.generate(self._document, self)
# validate
- self._validator.validate(self._document, self._outline, self)
+ prefs = DocumentPreferences(master_file)
+ prefs.parse_content(master_content)
+ self._validator.validate(self._document, self._outline, self, prefs)
# pass outline to completion
self.__latex_completion_handler.set_outline(self._outline)
@@ -335,7 +337,7 @@ class LaTeXEditor(Editor, IIssueHandler):
if master_filename:
# relativize the master filename
master_filename = File(master_filename).relativize(self._file.dirname, True)
- self._preferences.set("document-master-filename", master_filename)
+ self._preferences.set("master-filename", master_filename)
return master_filename
@property
@@ -345,7 +347,7 @@ class LaTeXEditor(Editor, IIssueHandler):
@return: base.File
"""
- path = self._preferences.get("document-master-filename")
+ path = self._preferences.get("master-filename")
if path != None:
if File.is_absolute(path):
self._log.debug("Path is absolute")
diff --git a/latex/latex/validator.py b/latex/latex/validator.py
index db07007..4be8a12 100644
--- a/latex/latex/validator.py
+++ b/latex/latex/validator.py
@@ -21,6 +21,7 @@
"""
latex.validator
"""
+import os.path
from logging import getLogger
from os.path import exists
@@ -31,6 +32,7 @@ from ..util import escape
from parser import Node
from environment import Environment
+LOG = getLogger(__name__)
class LaTeXValidator(object):
"""
@@ -41,25 +43,29 @@ class LaTeXValidator(object):
* unclosed environments, also "\[" and "\]"
"""
- _log = getLogger("LaTeXValidator")
-
def __init__(self):
self._environment = Environment()
- def validate(self, document_node, outline, issue_handler):
+ def validate(self, document_node, outline, issue_handler, document_preferences):
"""
Validate a LaTeX document
@param document_node: the root node of the document tree
@param outline: a LaTeX outline object
@param issue_handler: an object implementing IIssueHandler
+ @param document_preferences: a DocumentPreferences object, so we can query the
+ graphics file extensions, etc
"""
- self._log.debug("validate")
+ LOG.debug("Validating")
#~ # TODO: this is dangerous, the outline object could be outdated
#~ self._outline = outline
+ # cache some settings now to save time
+ self._potential_graphics_extensions = [""] + document_preferences.get("graphics-extensions").split(",")
+ self._potential_graphics_paths = document_preferences.get("graphics-paths").split(",")
+
# prepare a map for checking labels
self._labels = {}
for label in outline.labels:
@@ -140,20 +146,22 @@ class LaTeXValidator(object):
# check referenced image file
target = node.firstOfType(Node.MANDATORY_ARGUMENT).innerText
if len(target) > 0:
+ found = False
+
if File.is_absolute(target):
- filename = target
+ for ext in self._potential_graphics_extensions:
+ if exists(target + ext):
+ found = True
+ break
else:
- file = File.create_from_relative_path(target, node.file.dirname)
- filename = file.path
-
- # an image may be specified without the extension
- potential_extensions = ["", ".eps", ".pdf", ".jpg", ".jpeg", ".gif", ".png"]
-
- found = False
- for ext in potential_extensions:
- if exists(filename + ext):
- found = True
- break
+ for p in self._potential_graphics_paths:
+ if found: break
+ for ext in self._potential_graphics_extensions:
+ if found: break
+ filename = os.path.abspath(os.path.join(node.file.dirname, p, target) + ext)
+ print filename
+ if os.path.exists(filename):
+ found = True
if not found:
issue_handler.issue(Issue("Image <b>%s</b> could not be found" % escape(target), node.start, node.lastEnd, node.file, Issue.SEVERITY_WARNING))
diff --git a/latex/preferences/__init__.py b/latex/preferences/__init__.py
index fab7ae2..ea6d18b 100644
--- a/latex/preferences/__init__.py
+++ b/latex/preferences/__init__.py
@@ -101,12 +101,17 @@ class Preferences(_Preferences):
class DocumentPreferences(_Preferences):
"""
- Similar to @Preferences, but treats keys starting with 'document-' differently
- """
+ Similar to @Preferences, but first tries to **GET** keys from the current
+ document. Searches for lines of the following
+
+ % gedit:key-name = value
- KEYS = dict([(k,True) for k in (
- "document-master-filename",
- )])
+ If that fails, it also looks in a .filename.ini file for key-name = value
+ lines. If that fails, look in the system settings.
+
+ When **SETTING** keys, they do not persist if they were previously defined in
+ the document text, otherwise, they are set in the .ini file.
+ """
def __init__(self, file):
_Preferences.__init__(self)
@@ -123,7 +128,7 @@ class DocumentPreferences(_Preferences):
self.emit("preferences-changed", key, value)
def _is_docpref(self,key):
- return key.startswith("document-") and key in self.KEYS
+ return key in self._modelines
def parse_content(self, content, max_lines=100):
""" Parses txt content from the document looking for modelines """
diff --git a/test/article.tex b/test/article.tex
index 9598be4..35a7b0f 100644
--- a/test/article.tex
+++ b/test/article.tex
@@ -1,3 +1,6 @@
+
+% gedit:graphics-paths = .
+
\documentclass[12pt]{book}
\usepackage{graphicx}
\usepackage{caption}
@@ -14,6 +17,7 @@
\begin{document}
\maketitle
+
\chapter{Main Stuff}
\section{foo}
bar pleas see \ref{fig:fixme}
@@ -23,6 +27,8 @@ baz.
Lets enjoy \teste{12}. Lets complete complete. Lets \testcite{dijkstra68}
+%FIXME: foo
+
\section{baz}
I like \cite{dijkstra76}
diff --git a/test/chap3.tex b/test/chap3.tex
index 0cabb61..aed0bad 100644
--- a/test/chap3.tex
+++ b/test/chap3.tex
@@ -1,4 +1,4 @@
-% gedit:document-master-filename = article.tex
+% gedit:master-filename = article.tex
\chapter{A Third Chapter}
\section{Imma Let You Finish}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]