1
# -*- coding: utf-8 -*-
3
# windowhelper.py - Multi Edit
5
# Copyright (C) 2009 - Jesse van den Kieboom
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330,
20
# Boston, MA 02111-1307, USA.
23
from documenthelper import DocumentHelper
24
from signals import Signals
31
gettext.bindtextdomain(GETTEXT_PACKAGE, GP_LOCALEDIR)
32
_ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
38
<menubar name="MenuBar">
39
<menu name="EditMenu" action="Edit">
40
<placeholder name="EditOps_5">
41
<menuitem name="MultiEditMode" action="MultiEditModeAction"/>
48
class WindowHelper(Signals):
49
def __init__(self, plugin, window):
50
Signals.__init__(self)
55
# Insert document helpers
56
for view in window.get_views():
57
self.add_document_helper(view)
59
self.connect_signal(window, 'tab-added', self.on_tab_added)
60
self.connect_signal(window, 'tab-removed', self.on_tab_removed)
65
manager = self._window.get_ui_manager()
67
self._action_group = gtk.ActionGroup("GeditMultiEditPluginActions")
68
self._action_group.add_actions(
69
[('MultiEditModeAction', None, _('Multi Edit Mode'), '<Ctrl><Shift>C', _('Start multi edit mode'), self.on_multi_edit_mode)])
71
manager.insert_action_group(self._action_group, -1)
72
self._merge_id = manager.add_ui_from_string(ui_str)
74
def uninstall_ui(self):
75
manager = self._window.get_ui_manager()
76
manager.remove_ui(self._merge_id)
77
manager.remove_action_group(self._action_group)
79
manager.ensure_update()
82
# Remove document helpers
83
for view in self._window.get_views():
84
self.remove_document_helper(view)
86
self.disconnect_signals(self._window)
95
def add_document_helper(self, view):
96
if view.get_data(constants.DOCUMENT_HELPER_KEY) != None:
101
def remove_document_helper(self, view):
102
helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
107
def on_tab_added(self, window, tab):
108
self.add_document_helper(tab.get_view())
110
def on_tab_removed(self, window, tab):
111
self.remove_document_helper(tab.get_view())
113
def on_multi_edit_mode(self, action):
114
view = self._window.get_active_view()
115
helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
118
helper.enable_multi_edit()