gedit에서 "중복 줄" 단축키를 얻는 방법은 무엇입니까?

gedit에서 "중복 줄" 단축키를 얻는 방법은 무엇입니까?

gedit에서 현재 선택한 줄을 복제하는 단축키를 갖고 싶습니다. 다른 많은 편집자들은 이를 위해 Ctrl+ D또는 Ctrl+ Shift+를 사용 D하지만 gedit는 다릅니다.

기본 동작은 다음과 같습니다.

  • Ctrl+ D: 줄을 제거합니다
  • Ctrl+ Shift+ D: GTK 검사기를 엽니다.

다른 단축키가 내가 실제로 원하는 작업을 수행하는 한 현재 두 가지 동작 모두에 문제가 없습니다.

그래서 나는 보았다이 답변표시된 곳에서 실제로 gedit 바이너리를 패치할 수 있습니다. 그러나 바이너리 패치는 아마도 할 수 있는 최악의 해결 방법이기 때문에 이 작업을 수행하고 싶지 않습니다(업데이트 및 바이너리 변경을 생각해 보십시오). 또한 해당 질문에서는 "라인 삭제" 단축키만 제거되었고 "중복 라인" 단축키는 더 이상 존재하지 않는 플러그인과 함께 추가되었습니다.

그렇다면 gedit에서 "이 줄 복제" 동작을 어떻게 얻을 수 있습니까?

답변1

그만큼플러그인의견에 언급되었으며 다른 답변이 최근 업데이트되었으며 설치 후 사용할 수 있습니다Ctrl+Shift+D선이나 선택 항목을 복제합니다.

Ubuntu 16.04의 gedit 3.18.3에서 테스트했지만 모든 버전에서 작동합니다.>=3.14.0비록 gedit 개발자들이 마이너 버전의 주요 변경 사항을 도입하는 것을 부끄러워하지 않기 때문에 약간 의심스럽습니다.의미론적 버전 관리) 그리고 플러그인 개발에 대한 최신 문서가 없는 것 같습니다.

답변2

아직도 답을 찾고 있나요? 나는 파이썬에 익숙하지 않기 때문에 확실하지는 않지만 올바른 것을 가지고 있다고 생각합니다.
1. 다음에서 Duplicateline.py 파일을 편집해야 합니다.gedit3용 플러그인이 방법:


import gettext
from gi.repository import GObject, Gtk, Gio, Gedit
ACCELERATOR = ['<Alt>d']

#class DuplicateLineWindowActivatable(GObject.Object, Gedit.WindowActivatable):
class DuplicateLineAppActivatable(GObject.Object, Gedit.AppActivatable):
    __gtype_name__ = "DuplicateLineWindowActivatable"

    app = GObject.Property(type=Gedit.App)

    def __init__(self):
        GObject.Object.__init__(self)

    def do_activate(self):
        #self._insert_menu()
        self.app.set_accels_for_action("win.duplicate", ACCELERATOR)
        self.menu_ext = self.extend_menu("tools-section")
        item = Gio.MenuItem.new(_("Duplicate Line"), "win.duplicate")
        self.menu_ext.prepend_menu_item(item)

    def do_deactivate(self):
        #self._remove_menu()
        self.app.set_accels_for_action("win.duplicate", [])
        self.menu_ext = None

        #self._action_group = None

    #def _insert_menu(self):
        #manager = self.window.get_ui_manager()

        # Add our menu action and set ctrl+shift+D to activate.
        #self._action_group = Gtk.ActionGroup("DuplicateLinePluginActions")
        #self._action_group.add_actions([(
            #"DuplicateLine",
            #None,
            #_("Duplicate Line"),
            #"d",
            #_("Duplicate current line, current selection or selected lines"),
            #self.on_duplicate_line_activate
        #)])

        #manager.insert_action_group(self._action_group, -1)

        #self._ui_id = manager.add_ui_from_string(ui_str)

    #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 do_update_state(self):
        #self._action_group.set_sensitive(self.window.get_active_document() != None)
        pass
class DuplicateLineWindowActivatable(GObject.Object, Gedit.WindowActivatable):
    window = GObject.property(type=Gedit.Window)

    def __init__(self):
        GObject.Object.__init__(self)
        self.settings = Gio.Settings.new("org.gnome.gedit.preferences.editor")

    def do_activate(self):
        action = Gio.SimpleAction(name="duplicate")
        action.connect('activate', self.on_duplicate_line_activate)
        self.window.add_action(action)

    def on_duplicate_line_activate(self, action, user_data=None):
        doc = self.window.get_active_document()
        if not doc:
            return

        if doc.get_has_selection():
            # User has text selected, get bounds.
            s, e = doc.get_selection_bounds()
            l1 = s.get_line()
            l2 = e.get_line()

            if l1 != l2:
                # Multi-lines selected. Grab the text, insert.
                s.set_line_offset(0)
                e.set_line_offset(e.get_chars_in_line())

                text = doc.get_text(s, e, False)
                if text[-1:] != '\n':
                    # Text doesn't have a new line at the end. Add one for the beginning of the next.
                    text = "\n" + text

                doc.insert(e, text)
            else:
                # Same line selected. Grab the text, insert on same line after selection.
                text = doc.get_text(s, e, False)
                doc.move_mark_by_name("selection_bound", s)
                doc.insert(e, text)
        else:
            # No selection made. Grab the current line the cursor is on, insert on new line.
            s = doc.get_iter_at_mark(doc.get_insert())
            e = doc.get_iter_at_mark(doc.get_insert())
            s.set_line_offset(0)

            if not e.ends_line():
                e.forward_to_line_end()

            text = "\n" + doc.get_text(s, e, False)

            doc.insert(e, text)



2. Alt+는 D한 줄을 복제합니다. 단축키를 변경할 수 있습니다. 3D 줄 "ACCELERATOR = ['<Alt>d']"를 적절하다고 생각되는 대로 편집하세요.
3. 적어도 gedit v. 3.14.3에서는 작동합니다.

관련 정보