teknoraver

konsole copy

Nov 9th, 2021 (edited)
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.60 KB | None | 0 0
  1. From c5cdd0f2573dc84d24c0f1ee37f2badbf468bc6a Mon Sep 17 00:00:00 2001
  2. From: Matteo Croce <mcroce@microsoft.com>
  3. Date: Wed, 10 Nov 2021 01:22:04 +0100
  4. Subject: [PATCH] copy selected text to clipboard with ^C
  5.  
  6. Pressing ^C usually sends a SIGINT to the shell.
  7. When the selection is not empty, trap ^C and copy the selection
  8. to the clipboard instead.
  9.  
  10. Make this user configurable and disabled by default.
  11. ---
  12. src/profile/Profile.cpp                 |  2 ++
  13.  src/profile/Profile.h                   | 11 +++++++++++
  14.  src/terminalDisplay/TerminalDisplay.cpp |  7 +++++++
  15.  src/widgets/EditProfileAdvancedPage.ui  | 24 ++++++++++++++++++++----
  16.  src/widgets/EditProfileDialog.cpp       |  7 +++++++
  17.  src/widgets/EditProfileDialog.h         |  1 +
  18.  6 files changed, 48 insertions(+), 4 deletions(-)
  19.  
  20. diff --git a/src/profile/Profile.cpp b/src/profile/Profile.cpp
  21. index 09eaf50e..3e30700b 100644
  22. --- a/src/profile/Profile.cpp
  23. +++ b/src/profile/Profile.cpp
  24. @@ -97,6 +97,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
  25.      {FlowControlEnabled, "FlowControlEnabled", TERMINAL_GROUP, QVariant::Bool},
  26.      {BidiRenderingEnabled, "BidiRenderingEnabled", TERMINAL_GROUP, QVariant::Bool},
  27.      {BlinkingCursorEnabled, "BlinkingCursorEnabled", TERMINAL_GROUP, QVariant::Bool},
  28. +    {CtrlCCopy, "CtrlCCopy", TERMINAL_GROUP, QVariant::Bool},
  29.      {BellMode, "BellMode", TERMINAL_GROUP, QVariant::Int},
  30.      {VerticalLine, "VerticalLine", TERMINAL_GROUP, QVariant::Bool},
  31.      {VerticalLineAtChar, "VerticalLineAtChar", TERMINAL_GROUP, QVariant::Int},
  32. @@ -210,6 +211,7 @@ void Profile::useFallback()
  33.      setProperty(UnderlineLinksEnabled, true);
  34.      setProperty(UnderlineFilesEnabled, false);
  35.      setProperty(OpenLinksByDirectClickEnabled, false);
  36. +    setProperty(CtrlCCopy, false);
  37.  
  38.      setProperty(TextEditorCmd, Enum::Kate);
  39.      setProperty(TextEditorCmdCustom, QStringLiteral("kate PATH:LINE:COLUMN"));
  40. diff --git a/src/profile/Profile.h b/src/profile/Profile.h
  41. index 6dc3c30f..e107052c 100644
  42. --- a/src/profile/Profile.h
  43. +++ b/src/profile/Profile.h
  44. @@ -345,6 +345,11 @@ public:
  45.           *  when hovered by the mouse pointer.
  46.           */
  47.          ColorFilterEnabled,
  48. +
  49. +        /** (bool) If true, if the selection is not empty, Ctrl+C will copy the selection
  50. +         * instead of sending a SIGINT signal to the shell.
  51. +         */
  52. +        CtrlCCopy,
  53.      };
  54.  
  55.      Q_ENUM(Property)
  56. @@ -564,6 +569,12 @@ public:
  57.          return property<bool>(Profile::BidiRenderingEnabled);
  58.      }
  59.  
  60. +    /** Convenience method for property<bool>(Profile::CtrlCCopy) */
  61. +    bool ctrlCCopyEnabled() const
  62. +    {
  63. +        return property<bool>(Profile::CtrlCCopy);
  64. +    }
  65. +
  66.      /** Convenience method for property<bool>(Profile::LineSpacing) */
  67.      int lineSpacing() const
  68.      {
  69. diff --git a/src/terminalDisplay/TerminalDisplay.cpp b/src/terminalDisplay/TerminalDisplay.cpp
  70. index 6270d2d5..fda37417 100644
  71. --- a/src/terminalDisplay/TerminalDisplay.cpp
  72. +++ b/src/terminalDisplay/TerminalDisplay.cpp
  73. @@ -2452,6 +2452,13 @@ void TerminalDisplay::keyPressEvent(QKeyEvent *event)
  74.          }
  75.      }
  76.  
  77. +    auto profile = SessionManager::instance()->sessionProfile(_sessionController->session());
  78. +    if (profile->ctrlCCopyEnabled() && event->key() == 'C' && event->modifiers() == Qt::ControlModifier
  79. +        && !_screenWindow->selectedText(currentDecodingOptions()).isEmpty()) {
  80. +        copyToClipboard();
  81. +        _screenWindow->clearSelection();
  82. +        return;
  83. +    }
  84.      Q_EMIT keyPressedSignal(event);
  85.  
  86.  #ifndef QT_NO_ACCESSIBILITY
  87. diff --git a/src/widgets/EditProfileAdvancedPage.ui b/src/widgets/EditProfileAdvancedPage.ui
  88. index 12c52d01..f8962c14 100644
  89. --- a/src/widgets/EditProfileAdvancedPage.ui
  90. +++ b/src/widgets/EditProfileAdvancedPage.ui
  91. @@ -235,6 +235,22 @@
  92.        </widget>
  93.       </item>
  94.       <item row="6" column="1">
  95. +      <widget class="QCheckBox" name="enableCtrlCCopyButton">
  96. +       <property name="sizePolicy">
  97. +        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
  98. +         <horstretch>0</horstretch>
  99. +         <verstretch>0</verstretch>
  100. +        </sizepolicy>
  101. +       </property>
  102. +       <property name="toolTip">
  103. +        <string>When selection is not empty, Ctrl+C will copy selected text instead of sending a SIGINT signal to the shell</string>
  104. +       </property>
  105. +       <property name="text">
  106. +        <string>Copy selection with Ctrl+C</string>
  107. +       </property>
  108. +      </widget>
  109. +     </item>
  110. +     <item row="7" column="1">
  111.        <spacer>
  112.         <property name="orientation">
  113.          <enum>Qt::Vertical</enum>
  114. @@ -250,7 +266,7 @@
  115.         </property>
  116.        </spacer>
  117.       </item>
  118. -     <item row="7" column="0" alignment="Qt::AlignRight">
  119. +     <item row="8" column="0" alignment="Qt::AlignRight">
  120.        <widget class="QLabel" name="label_14">
  121.         <property name="text">
  122.          <string>Default character encoding:</string>
  123. @@ -263,14 +279,14 @@
  124.         </property>
  125.        </widget>
  126.       </item>
  127. -     <item row="7" column="1">
  128. +     <item row="8" column="1">
  129.        <widget class="QPushButton" name="selectEncodingButton">
  130.         <property name="text">
  131.          <string comment="KDE::DoNotExtract">DEFAULTENCODING</string>
  132.         </property>
  133.        </widget>
  134.       </item>
  135. -     <item row="8" column="0" alignment="Qt::AlignRight">
  136. +     <item row="9" column="0" alignment="Qt::AlignRight">
  137.        <widget class="QLabel" name="peekPrimaryLabel">
  138.         <property name="text">
  139.          <string>Shortcut for peeking the primary screen:</string>
  140. @@ -280,7 +296,7 @@
  141.         </property>
  142.        </widget>
  143.       </item>
  144. -     <item row="8" column="1" alignment="Qt::AlignRight">
  145. +     <item row="9" column="1" alignment="Qt::AlignRight">
  146.        <widget class="QKeySequenceEdit" name="peekPrimaryWidget">
  147.        </widget>
  148.       </item>
  149. diff --git a/src/widgets/EditProfileDialog.cpp b/src/widgets/EditProfileDialog.cpp
  150. index 9c856ee6..d5b29653 100644
  151. --- a/src/widgets/EditProfileDialog.cpp
  152. +++ b/src/widgets/EditProfileDialog.cpp
  153. @@ -1771,6 +1771,8 @@ void EditProfileDialog::setupAdvancedPage(const Profile::Ptr &profile)
  154.      connect(_advancedUi->enableBidiRenderingButton, &QPushButton::toggled, this, &EditProfileDialog::togglebidiRendering);
  155.      _advancedUi->enableReverseUrlHints->setChecked(profile->property<bool>(Profile::ReverseUrlHints));
  156.      connect(_advancedUi->enableReverseUrlHints, &QPushButton::toggled, this, &EditProfileDialog::toggleReverseUrlHints);
  157. +    _advancedUi->enableCtrlCCopyButton->setChecked(profile->property<bool>(Profile::CtrlCCopy));
  158. +    connect(_advancedUi->enableCtrlCCopyButton, &QPushButton::toggled, this, &EditProfileDialog::toggleCtrlCCopy);
  159.  
  160.      // Setup the URL hints modifier checkboxes
  161.      {
  162. @@ -1957,6 +1959,11 @@ void EditProfileDialog::toggleFlowControl(bool enable)
  163.      updateTempProfileProperty(Profile::FlowControlEnabled, enable);
  164.  }
  165.  
  166. +void EditProfileDialog::toggleCtrlCCopy(bool enable)
  167. +{
  168. +    updateTempProfileProperty(Profile::CtrlCCopy, enable);
  169. +}
  170. +
  171.  void EditProfileDialog::peekPrimaryKeySequenceChanged()
  172.  {
  173.      updateTempProfileProperty(Profile::PeekPrimaryKeySequence, _advancedUi->peekPrimaryWidget->keySequence().toString());
  174. diff --git a/src/widgets/EditProfileDialog.h b/src/widgets/EditProfileDialog.h
  175. index 8ed10549..5a3bfa9e 100644
  176. --- a/src/widgets/EditProfileDialog.h
  177. +++ b/src/widgets/EditProfileDialog.h
  178. @@ -205,6 +205,7 @@ private Q_SLOTS:
  179.      void togglebidiRendering(bool);
  180.      void updateUrlHintsModifier(bool);
  181.      void toggleReverseUrlHints(bool);
  182. +    void toggleCtrlCCopy(bool);
  183.  
  184.      void setDefaultCodec(QTextCodec *);
  185.  
  186. --
  187. 2.33.1
  188.  
  189.  
Add Comment
Please, Sign In to add comment