/usr/lib/gedit/plugins/devhelp.py is in devhelp-common 3.4.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | # -*- coding: utf-8 py-indent-offset: 4 -*-
#
# Gedit devhelp plugin
# Copyright (C) 2006 Imendio AB
# Copyright (C) 2011 Red Hat, Inc.
#
# Author: Richard Hult <richard@imendio.com>
# Author: Dan Williams <dcbw@redhat.com>
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gi.repository import GObject, Gtk, Gedit
import os
import gettext
ui_str = """
<ui>
<menubar name="MenuBar">
<menu name="ToolsMenu" action="Tools">
<placeholder name="ToolsOps_5">
<menuitem name="Devhelp" action="Devhelp"/>
</placeholder>
</menu>
</menubar>
</ui>
"""
class DevhelpPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "DevhelpPlugin"
window = GObject.property(type=Gedit.Window)
def __init__(self):
GObject.Object.__init__(self)
def do_activate(self):
self._insert_menu()
def do_deactivate(self):
self._remove_menu()
def _remove_menu(self):
manager = self.window.get_ui_manager()
manager.remove_ui(self._ui_id)
manager.remove_action_group(self._action_group)
self._action_group = None
manager.ensure_update()
def _insert_menu(self):
manager = self.window.get_ui_manager()
# Translate actions below, hardcoding domain here to avoid complications now
_ = lambda s: gettext.dgettext('devhelp', s);
self._action_group = Gtk.ActionGroup(name="GeditDevhelpPluginActions")
self._action_group.add_actions([('Devhelp', None,
_('Show API Documentation'),
'F2',
_('Show API Documentation for the word at the cursor'),
lambda a, w: self.do_devhelp(w.get_active_document()))],
self.window)
manager.insert_action_group(self._action_group, -1)
self._ui_id = manager.add_ui_from_string(ui_str)
def _is_word_separator(self, c):
return not (c.isalnum() or c == '_')
def do_devhelp(self, document):
# Get the word at the cursor
start = document.get_iter_at_mark(document.get_insert())
end = start.copy()
# If just after a word, move back into it
c = start.get_char()
if self._is_word_separator(c):
start.backward_char()
# Go backward
while True:
c = start.get_char()
if not self._is_word_separator(c):
if not start.backward_char():
break
else:
start.forward_char()
break
# Go forward
while True:
c = end.get_char()
if not self._is_word_separator(c):
if not end.forward_char():
break
else:
break
if end.compare(start) > 0:
text = document.get_text(start,end,False).strip()
if text:
# FIXME: We need a dbus interface for devhelp soon...
os.spawnlp(os.P_NOWAIT, 'devhelp', 'devhelp', '-s', text)
|