[gedit-latex/remove-prefs: 3/3] Port to GSettings
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-latex/remove-prefs: 3/3] Port to GSettings
- Date: Mon, 27 Jun 2011 10:14:55 +0000 (UTC)
commit fe8174fb14a28d7344013d765412ea3393276606
Author: John Stowers <john stowers gmail com>
Date: Mon Jun 27 22:12:43 2011 +1200
Port to GSettings
configure.ac | 7 +-
latex/Makefile.am | 12 ++-
latex/base/completion.py | 2 +-
latex/base/config.py | 4 +-
latex/base/templates.py | 6 +-
latex/base/windowactivatable.py | 4 +-
latex/bibtex/completion.py | 2 +-
latex/bibtex/editor.py | 6 +-
latex/bibtex/parser.py | 2 +-
latex/bibtex/views.py | 2 +-
latex/latex/actions.py | 4 +-
latex/latex/completion.py | 2 +-
latex/latex/dialogs.py | 12 +--
latex/latex/editor.py | 14 ++--
latex/latex/outline.py | 6 +-
latex/latex/views.py | 16 ++--
...org.gnome.gedit.plugins.latex.gschema.xml.in.in | 68 +++++++++++++++++
latex/outline.py | 4 +-
latex/preferences.xml.sample | 21 -----
latex/preferences/__init__.py | 79 ++++----------------
latex/preferences/dialog.py | 34 ++++-----
latex/preferences/tools.py | 15 ++++-
latex/tools/__init__.py | 6 +-
latex/tools/postprocess.py | 2 +-
latex/views.py | 14 ++--
po/POTFILES.in | 1 +
26 files changed, 178 insertions(+), 167 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5dfda6f..99bf64b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,9 +60,9 @@ PKG_CHECK_MODULES(GEDIT, [
gedit >= 3.0.0
])
-dnl ================================================================
-dnl GSettings stuff
-dnl ================================================================
+# ================================================================
+# GSettings stuff
+# ================================================================
GLIB_GSETTINGS
@@ -75,6 +75,7 @@ AC_CONFIG_FILES([
Makefile
latex/gldefs.py
latex/latex.plugin.desktop.in
+latex/org.gnome.gedit.plugins.latex.gschema.xml.in
latex/Makefile
latex/base/Makefile
latex/bibtex/Makefile
diff --git a/latex/Makefile.am b/latex/Makefile.am
index b495798..3bbc3e7 100644
--- a/latex/Makefile.am
+++ b/latex/Makefile.am
@@ -9,6 +9,11 @@ plugin_in_files = latex.plugin.desktop.in
plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
+gsettings_SCHEMAS = org.gnome.gedit.plugins.latex.gschema.xml
+
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
pluginlatexdir = $(plugindir)/latex
pluginlatex_PYTHON = \
@@ -24,14 +29,13 @@ pluginlatex_DATA = \
bibtex.xml \
latex.xml \
listings.xml \
- preferences.xml.sample \
symbols.xml \
tools.xml
-EXTRA_DIST = $(plugin_in_files)
+EXTRA_DIST = $(plugin_in_files) org.gnome.gedit.plugins.latex.gschema.xml.in.in
-CLEANFILES = $(plugin_DATA)
+CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
-DISTCLEANFILES = $(plugin_DATA)
+DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
-include $(top_srcdir)/git.mk
diff --git a/latex/base/completion.py b/latex/base/completion.py
index 6ea0c0d..7398820 100644
--- a/latex/base/completion.py
+++ b/latex/base/completion.py
@@ -238,7 +238,7 @@ class DetailsPopup(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP)
- self._color = Preferences().get("LightForeground", "#7f7f7f")
+ self._color = Preferences().get("light-foreground-color")
self._label = Gtk.Label()
self._label.set_use_markup(True)
diff --git a/latex/base/config.py b/latex/base/config.py
index 4447014..5db59c9 100644
--- a/latex/base/config.py
+++ b/latex/base/config.py
@@ -150,8 +150,8 @@ from ..bibtex.views import BibTeXOutlineView
# "BibTeXOutlineView" : BibTeXOutlineView} }
from ..preferences import Preferences
-LATEX_EXTENSIONS = Preferences().get("LatexExtensions", ".tex").split(" ")
-BIBTEX_EXTENSIONS = Preferences().get("BibtexExtensions", ".bib").split(" ")
+LATEX_EXTENSIONS = Preferences().get("latex-extensions").split(",")
+BIBTEX_EXTENSIONS = [".bib"]
WINDOW_SCOPE_VIEWS = {}
EDITOR_SCOPE_VIEWS = {}
diff --git a/latex/base/templates.py b/latex/base/templates.py
index eb5e691..66f58e2 100644
--- a/latex/base/templates.py
+++ b/latex/base/templates.py
@@ -289,10 +289,10 @@ class TemplateDelegate(object):
# create tags
self._tag_template = self._text_buffer.create_tag("template",
- background=Preferences().get("TemplateBackgroundColor", "#f2f7ff"))
+ background=Preferences().get("template-background-color"))
self._tag_placeholder = self._text_buffer.create_tag("placeholder",
- background=Preferences().get("PlaceholderBackgroundColor", "#d6e4ff"),
- foreground=Preferences().get("PlaceholderForegroundColor", "#2a66e1"))
+ background=Preferences().get("placeholder-background-color"),
+ foreground=Preferences().get("placeholder-foreground-color"))
self._active = False
diff --git a/latex/base/windowactivatable.py b/latex/base/windowactivatable.py
index 129d27c..94cfedd 100644
--- a/latex/base/windowactivatable.py
+++ b/latex/base/windowactivatable.py
@@ -404,8 +404,8 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
# FIXME: a hack again...
# the toolbar should hide when it doesn't contain any visible items
- latex_extensions = self._preferences.get("LatexExtensions", ".tex").split(" ")
- show_toolbar = self._preferences.get_bool("ShowLatexToolbar", True)
+ latex_extensions = self._preferences.get("latex-extensions").split(",")
+ show_toolbar = self._preferences.get_bool("show-latex-toolbar")
if show_toolbar and extension in latex_extensions:
self._toolbar.show()
else:
diff --git a/latex/bibtex/completion.py b/latex/bibtex/completion.py
index aceef61..2e40470 100644
--- a/latex/bibtex/completion.py
+++ b/latex/bibtex/completion.py
@@ -38,7 +38,7 @@ class BibTeXEntryTypeProposal(Proposal):
"""
icon = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/document.png"))
- _color = Preferences().get("LightForeground", "#957d47")
+ _color = Preferences().get("light-foreground-color")
def __init__(self, overlap, type):
"""
diff --git a/latex/bibtex/editor.py b/latex/bibtex/editor.py
index bc4616e..ed42430 100644
--- a/latex/bibtex/editor.py
+++ b/latex/bibtex/editor.py
@@ -72,8 +72,8 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
self._file = file
self._context = context
- self.register_marker_type("bibtex-error", self._preferences.get("ErrorBackgroundColor"))
- self.register_marker_type("bibtex-warning", self._preferences.get("WarningBackgroundColor"))
+ self.register_marker_type("bibtex-error", self._preferences.get("error-background-color"))
+ self.register_marker_type("bibtex-warning", self._preferences.get("warning-background-color"))
self._issue_view = context.find_view(self, "IssueView")
self._parser = BibTeXParser()
@@ -192,7 +192,7 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
"""
The cursor has moved
"""
- if self._preferences.get_bool("ConnectOutlineToEditor", True):
+ if self._preferences.get_bool("outline-connect-to-editor"):
self._outline_view.select_path_by_offset(offset)
def destroy(self):
diff --git a/latex/bibtex/parser.py b/latex/bibtex/parser.py
index 3c36187..673d0e0 100644
--- a/latex/bibtex/parser.py
+++ b/latex/bibtex/parser.py
@@ -379,7 +379,7 @@ class BibTeXParser(object):
self._document = Document()
# respect maximum BibTeX file size
- max_size_kb = int(Preferences().get("MaximumBibTeXSize", 500))
+ max_size_kb = int(Preferences().get("maximum-bibtex-size"))
length = len(string)
if length > max_size_kb * 1024:
diff --git a/latex/bibtex/views.py b/latex/bibtex/views.py
index 4c51370..e0d256b 100644
--- a/latex/bibtex/views.py
+++ b/latex/bibtex/views.py
@@ -159,7 +159,7 @@ class OutlineConverter(object):
@param grouping: the grouping to use: GROUP_NONE|GROUP_TYPE|GROUP_AUTHOR|GROUP_YEAR
"""
- color = Preferences().get("LightForeground", "#7f7f7f")
+ color = Preferences().get("light-foreground-color")
tree_store.clear()
diff --git a/latex/latex/actions.py b/latex/latex/actions.py
index 04d47aa..32f1b1b 100644
--- a/latex/latex/actions.py
+++ b/latex/latex/actions.py
@@ -39,11 +39,11 @@ from .dialogs import UseBibliographyDialog, InsertGraphicsDialog, InsertTableDia
from . import LaTeXSource, PropertyFile
class LaTeXAction(Action):
- extensions = Preferences().get("LatexExtensions", ".tex").split(" ")
+ extensions = Preferences().get("latex-extensions").split(",")
class LaTeXIconAction(IconAction):
- extensions = Preferences().get("LatexExtensions", ".tex").split(" ")
+ extensions = Preferences().get("latex-extensions").split(",")
class LaTeXTemplateAction(LaTeXIconAction):
diff --git a/latex/latex/completion.py b/latex/latex/completion.py
index 6ae8f82..fad7bb1 100644
--- a/latex/latex/completion.py
+++ b/latex/latex/completion.py
@@ -237,7 +237,7 @@ class PrefixModelParser(object):
def __init__(self, language_model):
self.__language_model = language_model
- self.__light_foreground = Preferences().get("LightForeground", "#957d47")
+ self.__light_foreground = Preferences().get("light-foreground-color")
def __create_proposals_from_commands(self, commands, overlap):
"""
diff --git a/latex/latex/dialogs.py b/latex/latex/dialogs.py
index 491e472..4b726c7 100644
--- a/latex/latex/dialogs.py
+++ b/latex/latex/dialogs.py
@@ -128,9 +128,9 @@ class ComboBoxProxy(AbstractProxy):
if show_value:
if not value is None and len(value) > 0:
- label_markup = "%s <span color='%s'>%s</span>" % (value, self._preferences.get("LightForeground"), label)
+ label_markup = "%s <span color='%s'>%s</span>" % (value, self._preferences.get("light-foreground-color"), label)
else:
- label_markup = "<span color='%s'>%s</span>" % (self._preferences.get("LightForeground"), label)
+ label_markup = "<span color='%s'>%s</span>" % (self._preferences.get("light-foreground-color"), label)
else:
label_markup = label
@@ -336,10 +336,8 @@ class NewDocumentDialog(GladeInterface):
#
self._proxy_template = ComboBoxProxy(self.find_widget("comboTemplate"), "RecentTemplate")
- #folder = Folder(find_resource("templates", MODE_READWRITE))
-
- folder = Folder(preferences.get("TemplateFolder", find_resource("templates", MODE_READWRITE)))
-
+ folder = Folder(preferences.TEMPLATE_DIR)
+
templates = folder.files
templates.sort()
for template in templates:
@@ -1125,7 +1123,7 @@ class SaveAsTemplateDialog(GladeInterface):
_dialog = None
def get_dialog(self):
- self._folder = Preferences().get("TemplateFolder", find_resource("templates", MODE_READWRITE))
+ self._folder = Preferences().TEMPLATE_DIR
if self._dialog is None:
self._dialog = self.find_widget("dialogSaveAsTemplate")
diff --git a/latex/latex/editor.py b/latex/latex/editor.py
index bdf09ed..7dd622b 100644
--- a/latex/latex/editor.py
+++ b/latex/latex/editor.py
@@ -52,7 +52,7 @@ class LaTeXEditor(Editor, IIssueHandler):
_log = getLogger("LaTeXEditor")
#extensions = [".tex"]
- extensions = Preferences().get("LatexExtensions", ".tex").split(" ")
+ extensions = Preferences().get("latex-extensions").split(",")
dnd_extensions = [".png", ".pdf", ".bib", ".tex"]
@@ -75,8 +75,8 @@ class LaTeXEditor(Editor, IIssueHandler):
self._preferences = Preferences()
self._preferences.connect("preferences-changed", self._on_preferences_changed)
- self.register_marker_type("latex-error", self._preferences.get("ErrorBackgroundColor"))
- self.register_marker_type("latex-warning", self._preferences.get("WarningBackgroundColor"))
+ self.register_marker_type("latex-error", self._preferences.get("error-background-color"))
+ self.register_marker_type("latex-warning", self._preferences.get("warning-background-color"))
self._issue_view = context.find_view(self, "IssueView")
self._outline_view = context.find_view(self, "LaTeXOutlineView")
@@ -102,7 +102,7 @@ class LaTeXEditor(Editor, IIssueHandler):
self.__update_neighbors()
def _on_preferences_changed(self, prefs, key, new_value):
- if key in ["ShowLabelsInOutline", "ShowTablesInOutline", "ShowGraphicsInOutline"]:
+ if key in ["outline-show-labels", "outline-show-tables", "outline-show-graphics"]:
# regenerate outline model
if self._document_is_master:
self._outline = self._outline_generator.generate(self._document, self)
@@ -111,8 +111,8 @@ class LaTeXEditor(Editor, IIssueHandler):
# FIXME: self._document contains the full model of child and master
# so we may not use it for regenerating the outline here
self.__parse()
- elif key == "ShowLatexToolbar":
- show_toolbar = self._preferences.get_bool("ShowLatexToolbar", True)
+ elif key == "show-latex-toolbar":
+ show_toolbar = self._preferences.get_bool("show-latex-toolbar")
if show_toolbar:
self._window_context._window_decorator._toolbar.show()
else:
@@ -383,7 +383,7 @@ class LaTeXEditor(Editor, IIssueHandler):
"""
The cursor has moved
"""
- if self._preferences.get_bool("ConnectOutlineToEditor", True):
+ if self._preferences.get_bool("outline-connect-to-editor"):
self._outline_view.select_path_by_offset(offset)
@property
diff --git a/latex/latex/outline.py b/latex/latex/outline.py
index 8a061bb..d407885 100644
--- a/latex/latex/outline.py
+++ b/latex/latex/outline.py
@@ -100,9 +100,9 @@ class LaTeXOutlineGenerator(object):
"""
# setup
- self.cfgLabelsInTree = Preferences().get_bool("ShowLabelsInOutline", False)
- self.cfgTablesInTree = Preferences().get_bool("ShowTablesInOutline", True)
- self.cfgGraphicsInTree = Preferences().get_bool("ShowGraphicsInOutline", True)
+ self.cfgLabelsInTree = Preferences().get_bool("outline-show-labels")
+ self.cfgTablesInTree = Preferences().get_bool("outline-show-tables")
+ self.cfgGraphicsInTree = Preferences().get_bool("outline-show-graphics")
self._outline = Outline()
self._stack = [self._outline.rootNode]
diff --git a/latex/latex/views.py b/latex/latex/views.py
index d651deb..9a44726 100755
--- a/latex/latex/views.py
+++ b/latex/latex/views.py
@@ -106,7 +106,7 @@ class LaTeXSymbolMapView(SideView):
self.__load_collection(SymbolCollection())
def __load_collection(self, collection):
- self.__expanded_groups = set(self.__preferences.get("ExpandedSymbolGroups", "").split(","))
+ self.__expanded_groups = set(self.__preferences.get("expanded-symbol-groups", "").split(","))
for group in collection.groups:
self.__add_group(group)
@@ -155,7 +155,7 @@ class LaTeXSymbolMapView(SideView):
else:
self.__expanded_groups.remove(group_label)
- self.__preferences.set("ExpandedSymbolGroups", ",".join(self.__expanded_groups))
+ self.__preferences.set("expanded-symbol-groups", ",".join(self.__expanded_groups))
def __on_symbol_selected(self, icon_view):
"""
@@ -217,8 +217,8 @@ class LaTeXOutlineView(BaseOutlineView):
btn_tables.set_tooltip_text("Show tables")
self._toolbar.insert(btn_tables, -1)
- btn_graphics.set_active(Preferences().get_bool("ShowGraphicsInOutline", True))
- btn_tables.set_active(Preferences().get_bool("ShowTablesInOutline", True))
+ btn_graphics.set_active(Preferences().get_bool("outline-show-graphics"))
+ btn_tables.set_active(Preferences().get_bool("outline-show-tables"))
self._handlers[btn_graphics] = btn_graphics.connect("toggled", self._on_graphics_toggled)
self._handlers[btn_tables] = btn_tables.connect("toggled", self._on_tables_toggled)
@@ -242,7 +242,7 @@ class LaTeXOutlineView(BaseOutlineView):
"""
An outline node has been selected
"""
- if Preferences().get_bool("ConnectOutlineToEditor", True):
+ if Preferences().get_bool("outline-connect-to-editor"):
if node.file == self._editor.edited_file:
self._editor.select(node.start, node.end)
@@ -291,13 +291,13 @@ class LaTeXOutlineView(BaseOutlineView):
value = toggle_button.get_active()
# Settings().set("LatexOutlineTables", value)
# self.trigger("tablesToggled", value)
- Preferences().set("ShowTablesInOutline", value)
+ Preferences().set("outline-show-tables", value)
def _on_graphics_toggled(self, toggle_button):
value = toggle_button.get_active()
# Settings().set("LatexOutlineGraphics", value)
# self.trigger("graphicsToggled", value)
- Preferences().set("ShowGraphicsInOutline", value)
+ Preferences().set("outline-show-graphics", value)
def destroy(self):
for obj in self._handlers:
@@ -353,7 +353,7 @@ class OutlineConverter(object):
"""
value = node.value
- color = self._preferences.get("LightForeground", "#957d47")
+ color = self._preferences.get("light-foreground-color")
if node.file and node.file != self._file:
value = "%s <span color='%s'>%s</span>" % (value, color, node.file.shortbasename)
diff --git a/latex/org.gnome.gedit.plugins.latex.gschema.xml.in.in b/latex/org.gnome.gedit.plugins.latex.gschema.xml.in.in
new file mode 100644
index 0000000..47c6207
--- /dev/null
+++ b/latex/org.gnome.gedit.plugins.latex.gschema.xml.in.in
@@ -0,0 +1,68 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.latex" path="/org/gnome/gedit/plugins/latex/">
+ <key name="maximum-bibtex-size" type="i">
+ <default>500</default>
+ <_summary>Maximum BibTeX Size</_summary>
+ </key>
+ <key name="outline-connect-to-editor" type="b">
+ <default>true</default>
+ <_summary>Connect Outline to Editor</_summary>
+ </key>
+ <key name="outline-show-labels" type="b">
+ <default>false</default>
+ <_summary>Show Labels in Outline</_summary>
+ </key>
+ <key name="outline-show-tables" type="b">
+ <default>true</default>
+ <_summary>Show Tables in Outline</_summary>
+ </key>
+ <key name="outline-show-graphics" type="b">
+ <default>true</default>
+ <_summary>Show Graphics in Outline</_summary>
+ </key>
+ <key name="issues-show-warnings" type="b">
+ <default>true</default>
+ <_summary>Show Warnings in Issues</_summary>
+ </key>
+ <key name="issues-show-tasks" type="b">
+ <default>true</default>
+ <_summary>Show Tasks in Issues</_summary>
+ </key>
+ <key name="hide-box-warnings" type="b">
+ <default>false</default>
+ <_summary>Hide Box Warnings</_summary>
+ </key>
+ <key name="show-latex-toolbar" type="b">
+ <default>true</default>
+ <_summary>Show LaTeX Toolbar</_summary>
+ </key>
+ <key name="expanded-symbol-groups" type="s">
+ <default>'Greek,Operators,Arrows,Special'</default>
+ <_summary>Exanded Symbol Groups</_summary>
+ </key>
+ <key name="latex-extensions" type="s">
+ <default>'.tex,.sty,.Rnw'</default>
+ <_summary>LaTeX Extensions</_summary>
+ </key>
+
+ <key name="light-foreground-color" type="s">
+ <default>'#957d47'</default>
+ </key>
+ <key name="error-background-color" type="s">
+ <default>'#ffdddd'</default>
+ </key>
+ <key name="warning-background-color" type="s">
+ <default>'#ffffcf'</default>
+ </key>
+ <key name="template-background-color" type="s">
+ <default>'#f2f7ff'</default>
+ </key>
+ <key name="placeholder-background-color" type="s">
+ <default>'#d6e4ff'</default>
+ </key>
+ <key name="placeholder-foreground-color" type="s">
+ <default>'#2a66e1'</default>
+ </key>
+
+ </schema>
+</schemalist>
diff --git a/latex/outline.py b/latex/outline.py
index 6f6f743..087746b 100644
--- a/latex/outline.py
+++ b/latex/outline.py
@@ -64,7 +64,7 @@ class BaseOutlineView(SideView):
btn_follow = Gtk.ToggleToolButton.new_from_stock(Gtk.STOCK_CONNECT)
btn_follow.set_tooltip_text("Follow Editor")
- btn_follow.set_active(self._preferences.get_bool("ConnectOutlineToEditor", True))
+ btn_follow.set_active(self._preferences.get_bool("outline-connect-to-editor"))
self._base_handlers[btn_follow] = btn_follow.connect("toggled", self._on_follow_toggled)
btn_expand = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ZOOM_IN)
@@ -129,7 +129,7 @@ class BaseOutlineView(SideView):
def _on_follow_toggled(self, toggle_button):
value = toggle_button.get_active()
- self._preferences.set("ConnectOutlineToEditor", value)
+ self._preferences.set("outline-connect-to-editor", value)
def _on_expand_clicked(self, button):
self._view.expand_all()
diff --git a/latex/preferences/__init__.py b/latex/preferences/__init__.py
index 8e49acb..ac0531c 100644
--- a/latex/preferences/__init__.py
+++ b/latex/preferences/__init__.py
@@ -22,28 +22,14 @@
preferences
"""
-from gi.repository import GObject
+from gi.repository import GObject, Gio, GLib
-from logging import getLogger
-import xml.etree.ElementTree as ElementTree
+import os.path
+import logging
from ..base.resources import find_resource, MODE_READWRITE
from ..util import singleton
-def str_to_bool(x):
- """
- Converts a string to a boolean value
- """
- if type(x) is bool:
- return x
- elif type(x) is str or type(x) is unicode:
- try:
- return {"false" : False, "0" : False, "true" : True, "1" : True}[x.strip().lower()]
- except KeyError:
- print "str_to_bool: unsupported value %s" % x
- else:
- print "str_to_bool: unsupported type %s" % str(type(x))
-
@singleton
class Preferences(GObject.GObject):
@@ -56,61 +42,26 @@ class Preferences(GObject.GObject):
A simple map storing preferences as key-value-pairs
"""
- _log = getLogger("Preferences")
+ _log = logging.getLogger("Preferences")
+
+ TEMPLATE_DIR = os.path.join(GLib.get_user_data_dir(), "gedit", "latex", "templates")
def __init__(self):
GObject.GObject.__init__(self)
- self.__preferences_changed = False
- self.__preferences = ElementTree.parse(
- find_resource("preferences.xml", MODE_READWRITE)).getroot()
+ self._settings = Gio.Settings("org.gnome.gedit.plugins.latex")
self._log.debug("Constructed")
- def get(self, key, default_value=None):
- """
- Return the value for a given key
-
- @param key: a key string
- @param default_value: a default value to be stored and returned if the key is not found
- """
- value_element = self.__find_value_element(key)
- if value_element is None:
- return default_value
- else:
- return value_element.text
-
- def get_bool(self, key, default_value=None):
- """
- Special version of get() casting the string value to a boolean value
- """
- return str_to_bool(self.get(key, default_value))
+ def get(self, key, default=None):
+ if default:
+ return default
+ return self._settings[key]
- def __find_value_element(self, key):
- for element in self.__preferences.findall("value"):
- if element.get("key") == key:
- return element
- self._log.debug("<value key='%s'> not found" % key)
- return None
+ def get_bool(self, key):
+ return self._settings[key]
def set(self, key, value):
- self._log.debug("set('%s', '%s')" % (key, value))
-
- value_element = self.__find_value_element(key)
- if value_element is None:
- self._log.debug("Creating new <value key='%s'>" % key)
-
- value_element = ElementTree.SubElement(self.__preferences, "value")
- value_element.set("key", str(key))
- value_element.text = str(value)
-
- self.__preferences_changed = True
+ self._settings[key] = value
self.emit("preferences-changed", str(key), str(value))
def save(self):
- """
- Save the preferences to XML
- """
- if self.__preferences_changed:
- self.__preferences_changed = False
- self._log.debug("Saving preferences...")
- tree = ElementTree.ElementTree(self.__preferences)
- tree.write(find_resource("preferences.xml", MODE_READWRITE), encoding="utf-8")
+ pass
diff --git a/latex/preferences/dialog.py b/latex/preferences/dialog.py
index b8d67c6..cdfa167 100644
--- a/latex/preferences/dialog.py
+++ b/latex/preferences/dialog.py
@@ -42,7 +42,7 @@ def _insert_column_with_attributes(view, pos, title, rend, **kwargs):
view.insert_column(tv, pos)
class PreferencesSpinButtonProxy(object):
- def __init__(self, widget, key, default_value):
+ def __init__(self, widget, key):
"""
@param widget: a SpinButton widget
@param key:
@@ -52,7 +52,7 @@ class PreferencesSpinButtonProxy(object):
self._key = key
self._preferences = Preferences()
- self._widget.set_value(int(self._preferences.get(key, default_value)))
+ self._widget.set_value(int(self._preferences.get(key)))
self._widget.connect("value-changed", self._on_value_changed)
@@ -65,7 +65,7 @@ class PreferencesColorProxy(object):
This connects to a Gdk.Color and gets/sets the value of a certain
preference
"""
- def __init__(self, widget, key, default_value):
+ def __init__(self, widget, key):
"""
@param widget: the Gtk.Widget that serves as a proxy
@param key: the key of the preferences field to be managed
@@ -75,7 +75,7 @@ class PreferencesColorProxy(object):
self._preferences = Preferences()
# init value
- ok, color = Gdk.color_parse(self._preferences.get(key, default_value))
+ ok, color = Gdk.color_parse(self._preferences.get(key))
if ok:
self._widget.set_color(color)
@@ -405,27 +405,27 @@ class PreferencesDialog(GladeInterface):
# misc
check_hide_box = self.find_widget("checkHideBox")
- check_hide_box.set_active(self._preferences.get_bool("HideBoxWarnings", False))
+ check_hide_box.set_active(self._preferences.get_bool("hide-box-warnings"))
check_show_toolbar = self.find_widget("checkShowToolbar")
- check_show_toolbar.set_active(self._preferences.get_bool("ShowLatexToolbar", True))
+ check_show_toolbar.set_active(self._preferences.get_bool("show-latex-toolbar"))
filechooser_tmp = self.find_widget("filechooserTemplates")
- filechooser_tmp.set_filename(self._preferences.get("TemplateFolder", find_resource("templates", MODE_READWRITE)))
+ filechooser_tmp.set_filename(self._preferences.TEMPLATE_DIR)
#
# proxies for ColorButtons and SpinButtons
#
- self._proxies = [ PreferencesColorProxy(self.find_widget("colorLight"), "LightForeground", "#957d47"),
- PreferencesColorProxy(self.find_widget("colorWarning"), "WarningBackgroundColor", "#ffffcf"),
- PreferencesColorProxy(self.find_widget("colorError"), "ErrorBackgroundColor", "#ffdddd"),
- PreferencesColorProxy(self.find_widget("colorTemplateBackground"), "TemplateBackgroundColor", "#f2f7ff"),
- PreferencesColorProxy(self.find_widget("colorPlaceholderBackground"), "PlaceholderBackgroundColor", "#d6e4ff"),
- PreferencesColorProxy(self.find_widget("colorPlaceholderForeground"), "PlaceholderForegroundColor", "#2a66e1"),
- PreferencesSpinButtonProxy(self.find_widget("spinMaxBibSize"), "MaximumBibTeXSize", 500) ]
+ self._proxies = [ PreferencesColorProxy(self.find_widget("colorLight"), "light-foreground-color"),
+ PreferencesColorProxy(self.find_widget("colorWarning"), "warning-background-color"),
+ PreferencesColorProxy(self.find_widget("colorError"), "error-background-color"),
+ PreferencesColorProxy(self.find_widget("colorTemplateBackground"), "template-background-color"),
+ PreferencesColorProxy(self.find_widget("colorPlaceholderBackground"), "placeholder-background-color"),
+ PreferencesColorProxy(self.find_widget("colorPlaceholderForeground"), "placeholder-foreground-color"),
+ PreferencesSpinButtonProxy(self.find_widget("spinMaxBibSize"), "maximum-bibtex-size") ]
#
# signals
@@ -447,18 +447,16 @@ class PreferencesDialog(GladeInterface):
def _on_show_toolbar_toggled(self, togglebutton):
value = togglebutton.get_active()
- self._preferences.set("ShowLatexToolbar", value)
+ self._preferences.set("show-latex-toolbar", value)
def _on_templates_dir_changed(self, filechooser):
folder = filechooser.get_filename()
if folder is None:
return
- self._preferences.set("TemplateFolder", folder)
-
def _on_hide_box_toggled(self, togglebutton):
value = togglebutton.get_active()
- self._preferences.set("HideBoxWarnings", value)
+ self._preferences.set("hide-box-warnings", value)
def _on_tools_changed(self, tools):
self._load_tools()
diff --git a/latex/preferences/tools.py b/latex/preferences/tools.py
index 74fbbba..3192d46 100644
--- a/latex/preferences/tools.py
+++ b/latex/preferences/tools.py
@@ -28,7 +28,20 @@ from ..base.resources import find_resource, MODE_READWRITE
from ..tools import Tool, Job
from ..tools.postprocess import GenericPostProcessor, RubberPostProcessor, LaTeXPostProcessor
from ..util import singleton
-from . import str_to_bool
+
+def str_to_bool(x):
+ """
+ Converts a string to a boolean value
+ """
+ if type(x) is bool:
+ return x
+ elif type(x) is str or type(x) is unicode:
+ try:
+ return {"false" : False, "0" : False, "true" : True, "1" : True}[x.strip().lower()]
+ except KeyError:
+ print "str_to_bool: unsupported value %s" % x
+ else:
+ print "str_to_bool: unsupported type %s" % str(type(x))
@singleton
class ToolPreferences(GObject.GObject):
diff --git a/latex/tools/__init__.py b/latex/tools/__init__.py
index 181d29c..45708bc 100644
--- a/latex/tools/__init__.py
+++ b/latex/tools/__init__.py
@@ -124,10 +124,8 @@ class ToolAction(Action):
if context.active_editor:
from ..preferences import Preferences # FIXME: circ dep
-
- if Preferences().get("SaveBeforeTool", True):
- # FIXME: find better way to save
- context._window_decorator.save_file()
+ # FIXME: find better way to save
+ context._window_decorator.save_file()
self._runner.run(context.active_editor.file, self._tool, tool_view)
self._log.debug("activate: " + str(context.active_editor.file))
diff --git a/latex/tools/postprocess.py b/latex/tools/postprocess.py
index b4c2a6e..18f0976 100644
--- a/latex/tools/postprocess.py
+++ b/latex/tools/postprocess.py
@@ -172,7 +172,7 @@ class RubberPostProcessor(PostProcessor):
# FIXME: circ dep
from ..preferences import Preferences
- self._hide_box_warnings = Preferences().get_bool("HideBoxWarnings", False)
+ self._hide_box_warnings = Preferences().get_bool("hide-box-warnings")
@property
def successful(self):
diff --git a/latex/views.py b/latex/views.py
index 3fcaec4..61cafe1 100644
--- a/latex/views.py
+++ b/latex/views.py
@@ -52,8 +52,8 @@ class IssueView(BottomView):
self._preferences = Preferences()
self._preferences.connect("preferences-changed", self._on_preferences_changed)
- self._show_tasks = self._preferences.get_bool("IssuesShowTasks", True)
- self._show_warnings = self._preferences.get_bool("IssuesShowWarnings", True)
+ self._show_tasks = self._preferences.get_bool("issues-show-tasks")
+ self._show_warnings = self._preferences.get_bool("issues-show-warnings")
self._context = context
@@ -148,7 +148,7 @@ class IssueView(BottomView):
self._editor.select(issue.start, issue.end)
def _on_preferences_changed(self, prefs, key, value):
- if key == "IssuesShowWarnings" or key == "IssuesShowTasks":
+ if key == "issues-show-warnings" or key == "issues-show-tasks":
# update filter
self._store.clear()
for issue, local in self._issues:
@@ -156,11 +156,11 @@ class IssueView(BottomView):
def __on_tasks_toggled(self, togglebutton):
self._show_tasks = togglebutton.get_active()
- self._preferences.set("IssuesShowTasks", self._show_tasks)
+ self._preferences.set("issues-show-tasks", self._show_tasks)
def __on_warnings_toggled(self, togglebutton):
self._show_warnings = togglebutton.get_active()
- self._preferences.set("IssuesShowWarnings", self._show_warnings)
+ self._preferences.set("issues-show-warnings", self._show_warnings)
def clear(self):
"""
@@ -196,8 +196,8 @@ class IssueView(BottomView):
message = issue.message
filename = escape(issue.file.basename)
else:
- message = "<span color='%s'>%s</span>" % (self._preferences.get("LightForeground", "#7f7f7f"), issue.message)
- filename = "<span color='%s'>%s</span>" % (self._preferences.get("LightForeground", "#7f7f7f"), issue.file.basename)
+ message = "<span color='%s'>%s</span>" % (self._preferences.get("light-foreground-color"), issue.message)
+ filename = "<span color='%s'>%s</span>" % (self._preferences.get("light-foreground-color"), issue.file.basename)
self._store.append([self._icons[issue.severity], message, filename, issue])
def destroy(self):
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a979519..bec0e68 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,5 +1,6 @@
latex/bibtex.xml
latex/latex.plugin.desktop.in.in
+latex/org.gnome.gedit.plugins.latex.gschema.xml.in.in
[type: gettext/glade]latex/ui/build_image_dialog.ui
[type: gettext/glade]latex/ui/choose_master_dialog.ui
[type: gettext/glade]latex/ui/configure.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]