/usr/lib/gedit/plugins/gdpformat.py is in gedit-developer-plugins 0.5.15-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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | # Copyright (C) 2009-2012 - Curtis Hovey <sinzui.is at verizon.net>
# This software is licensed under the GNU General Public License version 2
# (see the file COPYING)."""Text formatting features for the edit menu."""
__all__ = [
'FormatPlugin',
]
from gettext import gettext as _
from gi.repository import GObject
from gdpbase import (
GDPPluginMixin,
Gedit,
)
from gdp import config
from gdp.format import Formatter
class FormatPlugin(GDPPluginMixin, GObject.Object, Gedit.WindowActivatable):
"""Plugin for formatting code."""
__gtype_name__ = "GDPFormatPlugin"
window = GObject.property(type=Gedit.Window)
CONTROLLER_CLASS = Formatter
ACTION_GROUP_NAME = 'GDPFormatActions'
MENU_XML = """
<ui>
<menubar name="MenuBar">
<menu name='EditMenu' action='Edit'>
<placeholder name="EditOps_3">
<separator />
<menu action="GDPFormatMenu">
<menuitem action="RewrapText"/>
<menuitem action="FixLineEnding"/>
<menuitem action="TabsToSpaces"/>
<menuitem action="QuoteLines"/>
<menuitem action="SortImports"/>
<menuitem action="SingleLine"/>
<menuitem action="REReplace"/>
</menu>
<separator />
</placeholder>
</menu>
<menu name='ToolsMenu' action='Tools'>
<placeholder name="ToolsOps_2">
<separator />
<menuitem action="CheckProblems"/>
<menuitem action="CheckAllProblems"/>
<menuitem action="ShowSyntaxErrorsOnly"/>
<menuitem action="ReformatDoctest"/>
<menuitem action="ReformatCSS"/>
<separator />
</placeholder>
</menu>
</menubar>
</ui>
"""
def actions(self, formatter):
"""See `GDPPluginMixin`"""
return [
('GDPFormatMenu', None, _('_Format'), None, None, None),
('RewrapText', None, _("Rewrap _text"), None,
_("Rewrap the text to 78 characters."),
formatter.rewrap_text),
('FixLineEnding', None, _("Fix _line endings"), None,
_('Remove trailing whitespace and use newline endings.'),
formatter.newline_ending),
('TabsToSpaces', None, _("Convert t_abs to spaces"), None,
_('Convert tabs to spaces using the preferred tab size.'),
formatter.tabs_to_spaces),
('QuoteLines', None, _("_Quote lines"), '<Alt>Q',
_("Format the text as a quoted email."),
formatter.quote_lines),
('SortImports', None, _("Sort _imports"), None,
_('Sort and wrap imports.'),
formatter.sort_imports),
('SingleLine', None, _("_Single line"), None,
_("Format the text as a single line."),
formatter.single_line),
('REReplace', None, _("Regular _expression line replace"), None,
_("Reformat each line using a regular expression."),
formatter.re_replace),
('ReformatDoctest', None, _("Reformat _doctest"), None,
_("Reformat the doctest."),
formatter.reformat_doctest),
('ReformatCSS', None, _("Reformat _CSS"), None,
_("Reformat the CSS file or selection."),
formatter.reformat_css),
('CheckProblems', None, _("C_heck syntax and style"), 'F3',
_("Check syntax and style problems."),
formatter.check_style),
('CheckAllProblems', None,
_("Check syntax and style of all files"), None,
_("Check syntax and style problems in all open documents."),
formatter.check_all_style),
('ShowSyntaxErrorsOnly', None,
_("Show syntax errors only"), None,
_("Check syntax and style ignore info and warnings."),
formatter.on_show_syntax_errors_only_toggled,
config.getboolean('formatter', 'report_only_errors')),
]
def __init__(self):
"""Initialize the plugin the whole Gedit application."""
GObject.Object.__init__(self)
self.controller = None
def do_activate(self):
"""Activate the plugin in the current top-level window.
Add 'Format' to the edit menu and create a Formatter.
"""
self.activate()
self.connect_signal(
self.window, 'tab-added', self.on_tab_added_or_changed)
self.connect_signal(
self.window, 'active-tab-changed', self.on_tab_added_or_changed)
def do_deactivate(self):
"""Deactivate the plugin in the current top-level window."""
self.deactivate()
def do_update_state(self):
"""Toggle the plugin's sensativity in the top-level window.
This plugin is always active.
"""
pass
def on_tab_added_or_changed(self, window, tab):
"""Callback method for `tab-added` window signal.
Connects `document-saved` signal.
"""
document = tab.get_document()
if self.controller is None:
self.activate()
self.controller.correct_language(document)
language = document.get_language()
if language is None:
language_id = None
else:
language_id = language.get_id()
manager = self.window.get_ui_manager()
format_doctest_item = '/MenuBar/ToolsMenu/ToolsOps_2/ReformatDoctest'
manager.get_action(format_doctest_item).props.sensitive = (
language_id == 'doctest')
format_css_item = '/MenuBar/ToolsMenu/ToolsOps_2/ReformatCSS'
manager.get_action(format_css_item).props.sensitive = (
language_id == 'css')
self.connect_signal_after(
document, 'syntax-error-python', self.controller.check_style)
self.connect_signal_after(
document, 'saved', self.controller.check_style_background)
|