[gedit-plugins/gnome-2-32] Add new plugin textsize.



commit fbe5b0200165bfd6958794cfa1dab09384e359a8
Author: Jesse van den Kieboom <jesse icecrew nl>
Date:   Mon Aug 30 00:49:13 2010 +0200

    Add new plugin textsize.
    
    This plugin allows to increase/decrease the size of the text or of a specific
    selection of text.

 configure.ac                                       |   13 +-
 plugins/textsize/Makefile.am                       |   20 ++
 .../textsize/textsize.gedit-plugin.desktop.in.in   |   10 +
 plugins/textsize/textsize/.gitignore               |   22 ++
 plugins/textsize/textsize/Makefile.am              |   12 +
 plugins/textsize/textsize/__init__.py              |   46 ++++
 plugins/textsize/textsize/constants.py             |   24 ++
 plugins/textsize/textsize/documenthelper.py        |  182 ++++++++++++++++
 plugins/textsize/textsize/signals.py               |   92 ++++++++
 plugins/textsize/textsize/windowhelper.py          |  227 ++++++++++++++++++++
 10 files changed, 643 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 39e35e3..65e3208 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,9 +89,9 @@ ALL_PLUGINS="bookmarks showtabbar charmap drawspaces wordcompletion"
 USEFUL_PLUGINS="bookmarks showtabbar charmap drawspaces wordcompletion"
 DEFAULT_PLUGINS="bookmarks showtabbar charmap drawspaces wordcompletion"
 
-PYTHON_ALL_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit sessionsaver smartspaces terminal synctex"
-PYTHON_USEFUL_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit sessionsaver smartspaces terminal synctex"
-PYTHON_DEFAULT_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit sessionsaver smartspaces terminal synctex"
+PYTHON_ALL_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
+PYTHON_USEFUL_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
+PYTHON_DEFAULT_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
 
 DIST_PLUGINS="$ALL_PLUGINS $PYTHON_ALL_PLUGINS"
 
@@ -113,8 +113,8 @@ AC_ARG_WITH([plugins],
 			  build the specified plugins. Available:
 			  bracketcompletion, charmap, codecomment,
 			  colorpicker, drawspaces, joinlines, multiedit,
-			  showtabbar, sessionsaver, smartspaces, terminal,
-			  wordcompletion, as well as the aliases
+			  textsize, showtabbar, sessionsaver, smartspaces,
+			  terminal, wordcompletion, as well as the aliases
 			  default, all, and really-all],
 			  [plugins=$with_plugins],
 			  [plugins="default"])
@@ -436,6 +436,9 @@ plugins/joinlines/joinlines.gedit-plugin.desktop.in
 plugins/multiedit/Makefile
 plugins/multiedit/multiedit/Makefile
 plugins/multiedit/multiedit.gedit-plugin.desktop.in
+plugins/textsize/Makefile
+plugins/textsize/textsize/Makefile
+plugins/textsize/textsize.gedit-plugin.desktop.in
 plugins/sessionsaver/Makefile
 plugins/sessionsaver/sessionsaver.gedit-plugin.desktop.in
 plugins/showtabbar/Makefile
diff --git a/plugins/textsize/Makefile.am b/plugins/textsize/Makefile.am
new file mode 100644
index 0000000..b819f3c
--- /dev/null
+++ b/plugins/textsize/Makefile.am
@@ -0,0 +1,20 @@
+# Textsize
+
+SUBDIRS = textsize
+
+plugindir = $(GEDIT_PLUGINS_LIBS_DIR)
+
+plugin_in_files = textsize.gedit-plugin.desktop.in
+
+%.gedit-plugin: %.gedit-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po)
+	$(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+plugin_DATA = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
+
+EXTRA_DIST = $(plugin_in_files)
+
+CLEANFILES = $(plugin_DATA)
+
+DISTCLEANFILES = $(plugin_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/textsize/textsize.gedit-plugin.desktop.in.in b/plugins/textsize/textsize.gedit-plugin.desktop.in.in
new file mode 100644
index 0000000..4d77a5f
--- /dev/null
+++ b/plugins/textsize/textsize.gedit-plugin.desktop.in.in
@@ -0,0 +1,10 @@
+[Gedit Plugin]
+Loader=python
+Module=textsize
+IAge=3
+_Name=Text Size
+_Description=Easily increase and decrease the text size
+Authors=Konstantin Mikhaylov <jtraub devel gmail com>\nWouter Bolsterlee <wbolster gnome org>\nJesse van den Kieboom <jessevdk gnome org>
+Copyright=Copyright © 2008 by the authors
+Website=http://www.gedit.org
+Version= VERSION@
diff --git a/plugins/textsize/textsize/.gitignore b/plugins/textsize/textsize/.gitignore
new file mode 100644
index 0000000..2e54566
--- /dev/null
+++ b/plugins/textsize/textsize/.gitignore
@@ -0,0 +1,22 @@
+/*.bak
+/*.lo
+/*.o
+/*.orig
+/*.rej
+/*.tab.c
+/*~
+/.*.sw[nop]
+/.deps
+/.gitignore
+/.libs
+/GPATH
+/GRTAGS
+/GSYMS
+/GTAGS
+/ID
+/Makefile
+/Makefile.in
+/TAGS
+/_libs
+/so_locations
+/tags
diff --git a/plugins/textsize/textsize/Makefile.am b/plugins/textsize/textsize/Makefile.am
new file mode 100644
index 0000000..c457af2
--- /dev/null
+++ b/plugins/textsize/textsize/Makefile.am
@@ -0,0 +1,12 @@
+# Textsize
+
+plugindir = $(GEDIT_PLUGINS_LIBS_DIR)/textsize
+
+plugin_PYTHON =	\
+	constants.py \
+	documenthelper.py \
+	__init__.py \
+	signals.py \
+	windowhelper.py
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/textsize/textsize/__init__.py b/plugins/textsize/textsize/__init__.py
new file mode 100644
index 0000000..c1ee8bd
--- /dev/null
+++ b/plugins/textsize/textsize/__init__.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+#
+#  __init__.py - Text size plugin
+#
+#  Copyright (C) 2008 - Konstantin Mikhaylov <jtraub devel gmail com>
+#  Copyright (C) 2009 - Wouter Bolsterlee <wbolster gnome org>
+#  Copyright (C) 2010 - Ignacio Casal Quinteiro <icq gnome org>
+#  Copyright (C) 2010 - Jesse van den Kieboom <jessevdk gnome org>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330,
+#  Boston, MA 02111-1307, USA.
+
+from gettext import gettext as _
+
+import gtk
+import gedit
+from windowhelper import WindowHelper
+
+class TextSizePlugin(gedit.Plugin):
+    def __init__(self):
+        gedit.Plugin.__init__(self)
+        self._instances = {}
+
+    def activate(self, window):
+        self._instances[window] = WindowHelper(self, window)
+
+    def deactivate(self, window):
+        self._instances[window].deactivate()
+        del self._instances[window]
+
+    def update_ui(self, window):
+        self._instances[window].update_ui()
+
+# ex:ts=4:et:
diff --git a/plugins/textsize/textsize/constants.py b/plugins/textsize/textsize/constants.py
new file mode 100644
index 0000000..5a26bc3
--- /dev/null
+++ b/plugins/textsize/textsize/constants.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+#
+#  constants.py - Constants
+#
+#  Copyright (C) 2010 - Jesse van den Kieboom
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330,
+#  Boston, MA 02111-1307, USA.
+
+DOCUMENT_HELPER_KEY = 'GeditTextSizePluginDocumentHelperKey'
+
+# ex:ts=4:et:
diff --git a/plugins/textsize/textsize/documenthelper.py b/plugins/textsize/textsize/documenthelper.py
new file mode 100644
index 0000000..38a0146
--- /dev/null
+++ b/plugins/textsize/textsize/documenthelper.py
@@ -0,0 +1,182 @@
+# -*- coding: utf-8 -*-
+#
+#  documenthelper.py - Document helper
+#
+#  Copyright (C) 2010 - Jesse van den Kieboom
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330,
+#  Boston, MA 02111-1307, USA.
+
+from signals import Signals
+import constants
+import pango
+import gtk
+
+class DocumentHelper(Signals):
+    def __init__(self, view):
+        Signals.__init__(self)
+
+        self._view = view
+
+        self.connect_signal(self._view, 'scroll-event', self.on_scroll_event)
+        self.connect_signal(self._view, 'button-press-event', self.on_button_press_event)
+
+        self._view.set_data(constants.DOCUMENT_HELPER_KEY, self)
+
+        self._default_font = None
+        self._last_font = None
+        self._font_tags = {}
+
+    def stop(self):
+        if self._default_font:
+            self._view.modify_font(self._default_font)
+
+        self.remove_font_tags()
+        self.disconnect_signals(self._view)
+
+    def remove_font_tags(self):
+        buf = self._view.get_buffer()
+        table = buf.get_tag_table()
+
+        # Remove all the font tags
+        for size in self._font_tags:
+            tag = self._font_tags[size]
+            table.remove(tag)
+
+        self._font_tags = {}
+
+    def update_default_font(self):
+        description = self._view.get_style().font_desc
+
+        if not self._last_font or description.hash() != self._last_font.hash():
+            self._default_font = description.copy()
+
+    def get_font_tags(self, start, end):
+        tags = set()
+
+        # Check all the know font tags
+        for size in self._font_tags:
+            tag = self._font_tags[size]
+
+            if start.has_tag(tag):
+                tags.add(tag)
+            else:
+                cp = start.copy()
+
+                if cp.forward_to_tag_toggle(tag) and cp.compare(end) < 0:
+                    tags.add(tag)
+
+        return list(tags)
+
+    def set_font_size(self, amount):
+        self.update_default_font()
+
+        description = self._view.get_style().font_desc
+
+        buf = self._view.get_buffer()
+        bounds = buf.get_selection_bounds()
+        size = description.get_size() / pango.SCALE
+
+        if not bounds:
+            description.set_size(max(1, (size + amount)) * pango.SCALE)
+
+            self._view.modify_font(description)
+            self._last_font = description
+        else:
+            start = bounds[0]
+            end = bounds[1]
+
+            tags = self.get_font_tags(start, end)
+
+            if not tags:
+                # Simply use the overall font size as the base
+                newsize = size + amount
+            elif len(tags) == 1:
+                newsize = tags[0].props.font_desc.get_size() / pango.SCALE + amount
+            else:
+                newsize = 0
+
+                for tag in tags:
+                    newsize += tag.props.font_desc.get_size() / pango.SCALE
+
+                newsize = round(newsize / len(tags))
+
+            newsize = int(max(1, newsize))
+
+            if not newsize in self._font_tags:
+                newtag = buf.create_tag(None)
+
+                desc = description.copy()
+                desc.set_size(newsize * pango.SCALE)
+
+                newtag.props.font_desc = desc
+                self._font_tags[newsize] = newtag
+            else:
+                newtag = self._font_tags[newsize]
+
+            # Remove all the previous mix of tags
+            for tag in tags:
+                buf.remove_tag(tag, start, end)
+
+            buf.apply_tag(newtag, start, end)
+
+    def increase_font_size(self):
+        self.set_font_size(1)
+
+    def decrease_font_size(self):
+        self.set_font_size(-1)
+
+    def reset_font_size(self):
+        self.update_default_font()
+
+        buf = self._view.get_buffer()
+        bounds = buf.get_selection_bounds()
+
+        if not bounds:
+            self.remove_font_tags()
+
+            self._view.modify_font(self._default_font)
+            self._last_font = self._default_font
+        else:
+            tags = self.get_font_tags(bounds[0], bounds[1])
+
+            for tag in tags:
+                buf.remove_tag(tag, bounds[0], bounds[1])
+
+    def on_scroll_event(self, view, event):
+        state = event.state & gtk.accelerator_get_default_mod_mask()
+
+        if state != gtk.gdk.CONTROL_MASK:
+            return False
+
+        if event.direction == gtk.gdk.SCROLL_UP:
+            self.increase_font_size()
+            return True
+        elif event.direction == gtk.gdk.SCROLL_DOWN:
+            self.decrease_font_size()
+            return True
+
+        return False
+
+    def on_button_press_event(self, view, event):
+        state = event.state & gtk.accelerator_get_default_mod_mask()
+
+        if state == gtk.gdk.CONTROL_MASK and event.button == 2:
+            self.reset_font_size()
+            return True
+        else:
+            return False
+
+# ex:ts=4:et:
diff --git a/plugins/textsize/textsize/signals.py b/plugins/textsize/textsize/signals.py
new file mode 100644
index 0000000..286b692
--- /dev/null
+++ b/plugins/textsize/textsize/signals.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+#
+#  signals.py - Multi Edit
+#
+#  Copyright (C) 2009 - Jesse van den Kieboom
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330,
+#  Boston, MA 02111-1307, USA.
+
+class Signals:
+    def __init__(self):
+        self._signals = {}
+
+    def _connect(self, obj, name, handler, connector):
+        ret = self._signals.setdefault(obj, {})
+
+        hid = connector(name, handler)
+        ret.setdefault(name, []).append(hid)
+
+        return hid
+
+    def connect_signal(self, obj, name, handler):
+        return self._connect(obj, name, handler, obj.connect)
+
+    def connect_signal_after(self, obj, name, handler):
+        return self._connect(obj, name, handler, obj.connect_after)
+
+    def disconnect_signals(self, obj):
+        if not obj in self._signals:
+            return False
+
+        for name in self._signals[obj]:
+            for hid in self._signals[obj][name]:
+                obj.disconnect(hid)
+
+        del self._signals[obj]
+        return True
+
+    def block_signal(self, obj, name):
+        if not obj in self._signals:
+            return False
+
+        if not name in self._signals[obj]:
+            return False
+
+        for hid in self._signals[obj][name]:
+            obj.handler_block(hid)
+
+        return True
+
+    def unblock_signal(self, obj, name):
+        if not obj in self._signals:
+            return False
+
+        if not name in self._signals[obj]:
+            return False
+
+        for hid in self._signals[obj][name]:
+            obj.handler_unblock(hid)
+
+        return True
+
+    def disconnect_signal(self, obj, name):
+        if not obj in self._signals:
+            return False
+
+        if not name in self._signals[obj]:
+            return False
+
+        for hid in self._signals[obj][name]:
+            obj.disconnect(hid)
+
+        del self._signals[obj][name]
+
+        if len(self._signals[obj]) == 0:
+            del self._signals[obj]
+
+        return True
+
+# ex:ts=4:et:
diff --git a/plugins/textsize/textsize/windowhelper.py b/plugins/textsize/textsize/windowhelper.py
new file mode 100644
index 0000000..e6dfd1a
--- /dev/null
+++ b/plugins/textsize/textsize/windowhelper.py
@@ -0,0 +1,227 @@
+# -*- coding: utf-8 -*-
+#
+#  textsize.py - Change text size plugin
+#
+#  Copyright (C) 2008 - Konstantin Mikhaylov <jtraub devel gmail com>
+#  Copyright (C) 2009 - Wouter Bolsterlee <wbolster gnome org>
+#  Copyright (C) 2010 - Ignacio Casal Quinteiro <icq gnome org>
+#  Copyright (C) 2010 - Jesse van den Kieboom <jessevdk gnome org>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330,
+#  Boston, MA 02111-1307, USA.
+
+import gtk
+from gettext import gettext as _
+import constants
+from documenthelper import DocumentHelper
+from signals import Signals
+
+# UI manager snippet to add menu items to the View menu
+ui_str = """
+<ui>
+  <menubar name="MenuBar">
+    <menu name="ViewMenu" action="View">
+      <placeholder name="ViewOps_2">
+        <menuitem name="IncreaseFontSize" action="IncreaseFontSizeAction"/>
+        <menuitem name="DecreaseFontSize" action="DecreaseFontSizeAction"/>
+        <menuitem name="ResetFontSize" action="ResetFontSizeAction"/>
+      </placeholder>
+    </menu>
+  </menubar>
+</ui>
+"""
+
+class WindowHelper(Signals):
+    def __init__(self, plugin, window):
+        Signals.__init__(self)
+
+        self._window = window
+        self._plugin = plugin
+        self._views  = {}
+
+        # Insert menu items
+        self._insert_menu()
+
+        # Insert document helpers
+        for view in window.get_views():
+            self.add_document_helper(view)
+
+        self.connect_signal(window, 'tab-added', self.on_tab_added)
+        self.connect_signal(window, 'tab-removed', self.on_tab_removed)
+
+        self._accel_group = gtk.AccelGroup()
+        self._window.add_accel_group(self._accel_group)
+
+        self._proxy_callback_map = {
+            'IncreaseFontSizeAction': self.on_increase_font_accel,
+            'DecreaseFontSizeAction': self.on_decrease_font_accel,
+            'ResetFontSizeAction': self.on_reset_font_accel
+        }
+
+        self._proxy_mapping = {}
+        self._init_proxy_accels()
+        self._accel_map_handler_id = gtk.accel_map_get().connect('changed', self.on_accel_map_changed)
+
+    def _install_proxy(self, action):
+        if not isinstance(action, gtk.Action):
+            action = self._action_group.get_action(str(action))
+
+        if not action:
+            return
+
+        entry = gtk.accel_map_lookup_entry(action.get_accel_path())
+
+        if not entry:
+            return
+
+        mapping = {
+            gtk.keysyms.plus: gtk.keysyms.KP_Add,
+            gtk.keysyms.KP_Add: gtk.keysyms.plus,
+            gtk.keysyms.minus: gtk.keysyms.KP_Subtract,
+            gtk.keysyms.KP_Subtract: gtk.keysyms.minus,
+            gtk.keysyms._0: gtk.keysyms.KP_0,
+            gtk.keysyms.KP_0: gtk.keysyms._0
+        }
+
+        if entry[0] in mapping:
+            key = mapping[entry[0]]
+            mod = entry[1]
+
+            callback = self._proxy_callback_map[action.get_name()]
+
+            self._accel_group.connect_group(key, mod, gtk.ACCEL_LOCKED, callback)
+            self._proxy_mapping[action] = (key, mod)
+
+    def _init_proxy_accels(self):
+        self._install_proxy('IncreaseFontSizeAction')
+        self._install_proxy('DecreaseFontSizeAction')
+        self._install_proxy('ResetFontSizeAction')
+
+    def deactivate(self):
+        # Remove any installed menu items
+        self._remove_menu()
+
+        for view in self._window.get_views():
+            self.remove_document_helper(view)
+
+        self._window.remove_accel_group(self._accel_group)
+
+        gtk.accel_map_get().disconnect(self._accel_map_handler_id)
+
+        self._window = None
+        self._plugin = None
+        self._accel_group = None
+        self._action_group = None
+
+    def _insert_menu(self):
+        # Get the GtkUIManager
+        manager = self._window.get_ui_manager()
+
+        # Create a new action group
+        self._action_group = gtk.ActionGroup("TextSizePluginActions")
+        self._action_group.add_actions([("IncreaseFontSizeAction", None, _("_Increase font size"),
+                                         "<Ctrl>plus", None,
+                                         self.on_increase_font_size_activate),
+                                         ("DecreaseFontSizeAction", None, _("_Decrease font size"),
+                                         "<Ctrl>minus", None,
+                                         self.on_decrease_font_size_activate),
+                                         ("ResetFontSizeAction", None, _("_Reset font size"),
+                                         "<Ctrl>0", None,
+                                         self.on_reset_font_size_activate)])
+
+        # Insert the action group
+        manager.insert_action_group(self._action_group, -1)
+
+        # Merge the UI
+        self._ui_id = manager.add_ui_from_string(ui_str)
+
+    def _remove_menu(self):
+        # Get the GtkUIManager
+        manager = self._window.get_ui_manager()
+
+        # Remove the ui
+        manager.remove_ui(self._ui_id)
+
+        # Remove the action group
+        manager.remove_action_group(self._action_group)
+
+        # Make sure the manager updates
+        manager.ensure_update()
+
+    def update_ui(self):
+        self._action_group.set_sensitive(self._window.get_active_document() != None)
+
+    def get_helper(self, view):
+        return view.get_data(constants.DOCUMENT_HELPER_KEY)
+
+    def add_document_helper(self, view):
+        if self.get_helper(view) != None:
+            return
+
+        DocumentHelper(view)
+
+    def remove_document_helper(self, view):
+        helper = self.get_helper(view)
+
+        if helper != None:
+            helper.stop()
+
+    def call_helper(self, cb):
+        view = self._window.get_active_view()
+
+        if view:
+            cb(self.get_helper(view))
+
+    # Menu activate handlers
+    def on_increase_font_size_activate(self, action):
+        self.call_helper(lambda helper: helper.increase_font_size())
+
+    def on_decrease_font_size_activate(self, action):
+        self.call_helper(lambda helper: helper.decrease_font_size())
+
+    def on_reset_font_size_activate(self, action):
+        self.call_helper(lambda helper: helper.reset_font_size())
+
+    def on_increase_font_accel(self, group, accel, key, mod):
+        self.call_helper(lambda helper: helper.increase_font_size())
+
+    def on_decrease_font_accel(self, group, accel, key, mod):
+        self.call_helper(lambda helper: helper.decrease_font_size())
+
+    def on_reset_font_accel(self, group, accel, key, mod):
+        self.call_helper(lambda helper: helper.reset_font_size())
+
+    def on_tab_added(self, window, tab):
+        self.add_document_helper(tab.get_view())
+
+    def on_tab_removed(self, window, tab):
+        self.remove_document_helper(tab.get_view())
+
+    def _remap_proxy(self, action):
+        # Remove previous proxy
+
+        if action in self._proxy_mapping:
+            item = self._proxy_mapping[action]
+            self._accel_group.disconnect_key(item[0], item[1])
+
+        self._install_proxy(action)
+
+    def on_accel_map_changed(self, accelmap, path, key, mod):
+        for action in self._action_group.list_actions():
+            if action.get_accel_path() == path:
+                self._remap_proxy(action)
+                return
+
+# ex:ts=4:et:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]