Added JoinLines plugin. Removed logic to split lines. Moved Join Line shortcut from Layout to Editing section.
This commit is contained in:
parent
2bb61b9190
commit
385d32dbfc
|
@ -0,0 +1,12 @@
|
||||||
|
[Plugin]
|
||||||
|
Loader=python3
|
||||||
|
Module=joinlines
|
||||||
|
IAge=3
|
||||||
|
_Name=Join Lines
|
||||||
|
_Description=Join several lines
|
||||||
|
Icon=gnome-mime-text-x-python
|
||||||
|
Authors=Steve Frécinaux <steve@istique.net>;André Homeyer;Linux Mint team
|
||||||
|
Copyright=Copyright @ 2006-2007 Steve Frécinaux, André Homeyer
|
||||||
|
Website=https://github.com/linuxmint
|
||||||
|
Builtin=true
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
from gi.repository import GObject, Gtk, Xed
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
gettext.install("xed")
|
||||||
|
|
||||||
|
MENU_PATH = "/MenuBar/ViewMenu/ViewOps_1"
|
||||||
|
|
||||||
|
class JoinLinesPlugin(GObject.Object, Xed.WindowActivatable):
|
||||||
|
__gtype_name__ = "JoinLinesPlugin"
|
||||||
|
|
||||||
|
window = GObject.property(type=Xed.Window)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
GObject.Object.__init__(self)
|
||||||
|
|
||||||
|
def do_activate(self):
|
||||||
|
self._views = {}
|
||||||
|
|
||||||
|
self._insert_menu()
|
||||||
|
|
||||||
|
def _insert_menu(self):
|
||||||
|
manager = self.window.get_ui_manager()
|
||||||
|
|
||||||
|
self._action_group = Gtk.ActionGroup(name="XedJoinLinesPluginActions")
|
||||||
|
self._action_group.add_actions(
|
||||||
|
[("JoinLinesAction", None, _("_Join Lines"), "<Ctrl>J",
|
||||||
|
_("Join the selected lines"),
|
||||||
|
lambda w: self.join_lines(w))])
|
||||||
|
|
||||||
|
manager.insert_action_group(self._action_group)
|
||||||
|
|
||||||
|
self._ui_id = manager.new_merge_id()
|
||||||
|
|
||||||
|
manager.add_ui(self._ui_id,
|
||||||
|
MENU_PATH,
|
||||||
|
"JoinLinesAction",
|
||||||
|
"JoinLinesAction",
|
||||||
|
Gtk.UIManagerItemType.MENUITEM,
|
||||||
|
False)
|
||||||
|
|
||||||
|
def do_update_state(self):
|
||||||
|
self._action_group.set_sensitive(self.window.get_active_document() != None)
|
||||||
|
|
||||||
|
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)
|
||||||
|
manager.ensure_update()
|
||||||
|
|
||||||
|
def join_lines(self, w):
|
||||||
|
doc = self.window.get_active_document()
|
||||||
|
if doc is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
doc.begin_user_action()
|
||||||
|
|
||||||
|
# If there is a selection use it, otherwise join the
|
||||||
|
# next line
|
||||||
|
try:
|
||||||
|
start, end = doc.get_selection_bounds()
|
||||||
|
except ValueError:
|
||||||
|
start = doc.get_iter_at_mark(doc.get_insert())
|
||||||
|
end = start.copy()
|
||||||
|
end.forward_line()
|
||||||
|
|
||||||
|
end_mark = doc.create_mark(None, end)
|
||||||
|
|
||||||
|
if not start.ends_line():
|
||||||
|
start.forward_to_line_end()
|
||||||
|
|
||||||
|
# Include trailing spaces in the chunk to be removed
|
||||||
|
while start.backward_char() and start.get_char() in ('\t', ' '):
|
||||||
|
pass
|
||||||
|
start.forward_char()
|
||||||
|
|
||||||
|
while doc.get_iter_at_mark(end_mark).compare(start) == 1:
|
||||||
|
end = start.copy()
|
||||||
|
while end.get_char() in ('\r', '\n', ' ', '\t'):
|
||||||
|
end.forward_char()
|
||||||
|
doc.delete(start, end)
|
||||||
|
|
||||||
|
doc.insert(start, ' ')
|
||||||
|
start.forward_to_line_end()
|
||||||
|
|
||||||
|
doc.delete_mark(end_mark)
|
||||||
|
doc.end_user_action()
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
install_subdir(
|
||||||
|
'joinlines',
|
||||||
|
install_dir: pluginslibdir
|
||||||
|
)
|
||||||
|
|
||||||
|
textsize_desktop = custom_target(
|
||||||
|
'joinlines_desktop',
|
||||||
|
input: 'joinlines.plugin.desktop.in',
|
||||||
|
output: 'joinlines.plugin',
|
||||||
|
command: [intltool_merge, '-d', '-u', po_dir, '@INPUT@', '@OUTPUT@'],
|
||||||
|
install: true,
|
||||||
|
install_dir: pluginslibdir,
|
||||||
|
)
|
|
@ -3,6 +3,7 @@ pluginslibdir = join_paths(libdir, 'xed', 'plugins')
|
||||||
|
|
||||||
subdir('docinfo')
|
subdir('docinfo')
|
||||||
subdir('filebrowser')
|
subdir('filebrowser')
|
||||||
|
subdir('joinlines')
|
||||||
subdir('modelines')
|
subdir('modelines')
|
||||||
subdir('open-uri-context-menu')
|
subdir('open-uri-context-menu')
|
||||||
subdir('sort')
|
subdir('sort')
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<object class="GtkShortcutsSection">
|
<object class="GtkShortcutsSection">
|
||||||
<property name="visible">1</property>
|
<property name="visible">1</property>
|
||||||
<property name="section-name">shortcuts</property>
|
<property name="section-name">shortcuts</property>
|
||||||
<property name="max-height">14</property>
|
<property name="max-height">15</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsGroup">
|
<object class="GtkShortcutsGroup">
|
||||||
<property name="visible">1</property>
|
<property name="visible">1</property>
|
||||||
|
@ -354,6 +354,13 @@
|
||||||
<property name="title" translatable="yes">Toggle comment</property>
|
<property name="title" translatable="yes">Toggle comment</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="visible">1</property>
|
||||||
|
<property name="accelerator"><ctrl>J</property>
|
||||||
|
<property name="title" translatable="yes">Join Lines</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
Loading…
Reference in New Issue