Commit bb818010 authored by Jekyll Wu's avatar Jekyll Wu

Add two profile options for the copy & paste behavior of mouse

  * support "automatially copy selected text into clipboard"
  * mouse middle button can be customized to paste from selectio or
    clipboard

The first feature might look like a unnecessary duplicate of the
"synchronize selection and clipboard" feature of Klipper. However, that
klipper feature is generally problematic, while doing it only in Konsole
is generally useful and harmless.

FEATURE: 183490
FIXED-IN: 4.9.0
REVIEW: 103861
DIGEST:
parent 11814cbf
......@@ -213,6 +213,8 @@ void EditProfileDialog::preparePage(int page)
setupScrollingPage(profile);
else if (pageWidget == _ui->keyboardTab)
setupKeyboardPage(profile);
else if (pageWidget == _ui->mouseTab)
setupMousePage(profile);
else if (pageWidget == _ui->advancedTab)
setupAdvancedPage(profile);
else
......@@ -978,32 +980,29 @@ void EditProfileDialog::showScrollBarRight()
{
updateTempProfileProperty(Profile::ScrollBarPosition, Enum::ScrollBarRight);
}
void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
{
BooleanOption options[] = { {
_ui->enableBlinkingTextButton , Profile::BlinkingTextEnabled ,
SLOT(toggleBlinkingText(bool))
},
{
_ui->enableFlowControlButton , Profile::FlowControlEnabled ,
SLOT(toggleFlowControl(bool))
},
{
_ui->enableBlinkingCursorButton , Profile::BlinkingCursorEnabled ,
SLOT(toggleBlinkingCursor(bool))
},
{
_ui->underlineLinksButton , Profile::UnderlineLinksEnabled,
SLOT(toggleUnderlineLinks(bool))
},
{
_ui->enableBidiRenderingButton , Profile::BidiRenderingEnabled ,
SLOT(togglebidiRendering(bool))
_ui->copyTextToClipboardButton , Profile::AutoCopySelectedText,
SLOT(toggleCopyTextToClipboard(bool))
},
{ 0 , Profile::Property(0) , 0 }
};
setupCheckBoxes(options , profile);
// setup middle click paste mode
const int middleClickPasteMode = profile->property<int>(Profile::MiddleClickPasteMode);
RadioOption pasteModes[] = {
{_ui->pasteFromX11SelectionButton, Enum::PasteFromX11Selection, SLOT(pasteFromX11Selection())},
{_ui->pasteFromClipboardButton, Enum::PasteFromClipboard, SLOT(pasteFromClipboard())},
{0, 0, 0}
};
setupRadio(pasteModes , middleClickPasteMode);
// interaction options
_ui->wordCharacterEdit->setText(profile->wordCharacters());
......@@ -1015,6 +1014,28 @@ void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
connect(_ui->tripleClickModeCombo, SIGNAL(activated(int)), this,
SLOT(TripleClickModeChanged(int)));
}
void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
{
BooleanOption options[] = { {
_ui->enableBlinkingTextButton , Profile::BlinkingTextEnabled ,
SLOT(toggleBlinkingText(bool))
},
{
_ui->enableFlowControlButton , Profile::FlowControlEnabled ,
SLOT(toggleFlowControl(bool))
},
{
_ui->enableBlinkingCursorButton , Profile::BlinkingCursorEnabled ,
SLOT(toggleBlinkingCursor(bool))
},
{
_ui->enableBidiRenderingButton , Profile::BidiRenderingEnabled ,
SLOT(togglebidiRendering(bool))
},
{ 0 , Profile::Property(0) , 0 }
};
setupCheckBoxes(options , profile);
// cursor options
if (profile->useCustomCursorColor())
......@@ -1084,6 +1105,18 @@ void EditProfileDialog::toggleUnderlineLinks(bool enable)
{
updateTempProfileProperty(Profile::UnderlineLinksEnabled, enable);
}
void EditProfileDialog::toggleCopyTextToClipboard(bool enable)
{
updateTempProfileProperty(Profile::AutoCopySelectedText, enable);
}
void EditProfileDialog::pasteFromX11Selection()
{
updateTempProfileProperty(Profile::MiddleClickPasteMode, Enum::PasteFromX11Selection);
}
void EditProfileDialog::pasteFromClipboard()
{
updateTempProfileProperty(Profile::MiddleClickPasteMode, Enum::PasteFromClipboard);
}
void EditProfileDialog::TripleClickModeChanged(int newValue)
{
updateTempProfileProperty(Profile::TripleClickMode, newValue);
......
......@@ -149,19 +149,25 @@ private slots:
void keyBindingSelected();
void removeKeyBinding();
// mouse page
void toggleUnderlineLinks(bool);
void toggleCopyTextToClipboard(bool);
void pasteFromX11Selection();
void pasteFromClipboard();
void TripleClickModeChanged(int);
void wordCharactersChanged(const QString&);
// advanced page
void toggleBlinkingText(bool);
void toggleFlowControl(bool);
void togglebidiRendering(bool);
void toggleBlinkingCursor(bool);
void TripleClickModeChanged(int);
void toggleUnderlineLinks(bool);
void setCursorShape(int);
void autoCursorColor();
void customCursorColor();
void customCursorColorChanged(const QColor&);
void wordCharactersChanged(const QString&);
void setDefaultCodec(QTextCodec*);
// apply the first previewed changes stored up by delayedPreview()
......@@ -175,6 +181,7 @@ private:
void setupKeyboardPage(const Profile::Ptr profile);
void setupScrollingPage(const Profile::Ptr profile);
void setupAdvancedPage(const Profile::Ptr profile);
void setupMousePage(const Profile::Ptr info);
void updateColorSchemeList(bool selectCurrentScheme = false);
void updateColorSchemeButtons();
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<width>594</width>
<height>551</height>
</rect>
</property>
......@@ -267,7 +267,7 @@
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="Konsole::RenameTabWidget" name="renameTabWidget"/>
<widget class="Konsole::RenameTabWidget" name="renameTabWidget" native="true"/>
</item>
</layout>
</widget>
......@@ -532,8 +532,7 @@
</property>
<layout class="QVBoxLayout">
<item>
<widget class="Konsole::HistorySizeWidget" name="historySizeWidget">
</widget>
<widget class="Konsole::HistorySizeWidget" name="historySizeWidget" native="true"/>
</item>
</layout>
</widget>
......@@ -615,7 +614,7 @@
</widget>
<widget class="QWidget" name="keyboardTab">
<attribute name="title">
<string>Input</string>
<string>Keyboard</string>
</attribute>
<layout class="QVBoxLayout">
<item>
......@@ -695,82 +694,22 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="advancedTab">
<widget class="QWidget" name="mouseTab">
<attribute name="title">
<string comment="@title:tab Complex options">Advanced</string>
<string>Mouse</string>
</attribute>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Terminal Features</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="enableBlinkingTextButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Allow terminal programs to create blinking sections of text</string>
</property>
<property name="text">
<string>Allow blinking text</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableFlowControlButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Allow the output to be suspended by pressing Ctrl+S</string>
</property>
<property name="text">
<string>Enable flow control using Ctrl+S, Ctrl+Q</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableBidiRenderingButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Enable Bi-Directional display on terminals (valid for Arabic, Farsi or Hebrew only)</string>
</property>
<property name="text">
<string>Enable Bi-Directional text rendering</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_9">
<property name="title">
<string>Mouse Interaction</string>
<string>Select Text</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="_2">
<item>
<layout class="QHBoxLayout">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
......@@ -794,7 +733,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<layout class="QHBoxLayout" name="_4">
<item>
<widget class="QLabel" name="label_17">
<property name="text">
......@@ -819,21 +758,76 @@
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_14">
<property name="title">
<string>Copy &amp;&amp; Paste</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="copyTextToClipboardButton">
<property name="toolTip">
<string>Automatically copy selected text into clipboard</string>
</property>
<property name="text">
<string>Copy on select</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>561</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Mouse middle button:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="pasteFromX11SelectionButton">
<property name="text">
<string>Paste from selection</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="pasteFromClipboardButton">
<property name="text">
<string>Paste from clipboard</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Miscellaneous</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="underlineLinksButton">
<property name="toolTip">
......@@ -847,6 +841,86 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>328</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="advancedTab">
<attribute name="title">
<string comment="@title:tab Complex options">Advanced</string>
</attribute>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Terminal Features</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="enableBlinkingTextButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Allow terminal programs to create blinking sections of text</string>
</property>
<property name="text">
<string>Allow blinking text</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableFlowControlButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Allow the output to be suspended by pressing Ctrl+S</string>
</property>
<property name="text">
<string>Enable flow control using Ctrl+S, Ctrl+Q</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableBidiRenderingButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Enable Bi-Directional display on terminals (valid for Arabic, Farsi or Hebrew only)</string>
</property>
<property name="text">
<string>Enable Bi-Directional text rendering</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
......
......@@ -88,6 +88,14 @@ public:
SelectForwardsFromCursor = 1
};
/** This enum describes the source from which mouse middle click pastes data . */
enum MiddleClickPasteModeEnum {
/** Paste from X11 Selection. */
PasteFromX11Selection = 0,
/** Paste from Clipboard. */
PasteFromClipboard = 1
};
/**
* This enum describes the different types of sounds and visual effects which
* can be used to alert the user when a 'bell' occurs in the terminal
......
......@@ -102,6 +102,10 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { WordCharacters , "WordCharacters" , INTERACTION_GROUP , QVariant::String }
, { TripleClickMode , "TripleClickMode" , INTERACTION_GROUP , QVariant::Int }
, { UnderlineLinksEnabled , "UnderlineLinksEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { AutoCopySelectedText , "AutoCopySelectedText" , INTERACTION_GROUP , QVariant::Bool }
, { PasteFromSelectionEnabled , "PasteFromSelectionEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { PasteFromClipboardEnabled , "PasteFromClipboardEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { MiddleClickPasteMode, "MiddleClickPasteMode" , INTERACTION_GROUP , QVariant::Int }
// Encoding
, { DefaultEncoding , "DefaultEncoding" , ENCODING_GROUP , QVariant::String }
......@@ -161,6 +165,10 @@ FallbackProfile::FallbackProfile()
setProperty(FlowControlEnabled, true);
setProperty(BlinkingTextEnabled, true);
setProperty(UnderlineLinksEnabled, true);
setProperty(AutoCopySelectedText, false);
setProperty(PasteFromSelectionEnabled, true);
setProperty(PasteFromClipboardEnabled, false);
setProperty(MiddleClickPasteMode, Enum::PasteFromX11Selection);
setProperty(TripleClickMode, Enum::SelectWholeLine);
setProperty(BlinkingCursorEnabled, false);
......
......@@ -196,6 +196,18 @@ public:
* underlined when hovered by the mouse pointer.
*/
UnderlineLinksEnabled,
/** (bool) If true, automatically copy selected text into the clipboard */
AutoCopySelectedText,
/** (bool) If true, middle mouse button pastes from X Selection */
PasteFromSelectionEnabled,
/** (bool) If true, middle mouse button pastes from Clipboard */
PasteFromClipboardEnabled,
/** (MiddleClickPasteModeEnum) Specifies the source from which mouse
* middle click pastes data.
*
* See Enum::MiddleClickPasteModeEnum
*/
MiddleClickPasteMode,
/** (String) Default text codec */
DefaultEncoding,
/** (bool) Whether fonts should be aliased or not */
......@@ -421,6 +433,10 @@ public:
return property<bool>(Profile::UnderlineLinksEnabled);
}
bool autoCopySelectedText() const {
return property<bool>(Profile::AutoCopySelectedText);
}
/** Convenience method for property<QString>(Profile::DefaultEncoding) */
QString defaultEncoding() const {
return property<QString>(Profile::DefaultEncoding);
......
......@@ -543,7 +543,7 @@ void SessionController::setupCommonActions()
pasteShortcut.setAlternate(QKeySequence(Qt::SHIFT + Qt::Key_Insert));
action->setShortcut(pasteShortcut);
action = collection->addAction("paste-selection", this, SLOT(pasteFromXSelection()));
action = collection->addAction("paste-selection", this, SLOT(pasteFromX11Selection()));
action->setText(i18n("Paste Selection"));
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Insert));
......@@ -833,15 +833,15 @@ void SessionController::paste()
{
_view->pasteFromClipboard();
}
void SessionController::pasteFromXSelection()
void SessionController::pasteFromX11Selection()
{
_view->pasteFromXSelection();
_view->pasteFromX11Selection();
}
void SessionController::selectAll()
{
ScreenWindow * screenWindow = _view->screenWindow();
screenWindow->setSelectionByLineRange(0, _session->emulation()->lineCount());
TerminalDisplay::setXSelection(screenWindow->selectedText(true));
_view->copyToX11Selection();
}
static const KXmlGuiWindow* findWindow(const QObject* object)
{
......
......@@ -218,7 +218,7 @@ private slots:
void copy();
void paste();
void selectAll();
void pasteFromXSelection(); // shortcut only
void pasteFromX11Selection(); // shortcut only
void copyInputActionsTriggered(QAction* action);
void copyInputToAllTabs();
void copyInputToSelectedTabs();
......
......@@ -63,6 +63,8 @@
#include "WindowSystemInfo.h"
#include "ExtendedCharTable.h"
#include "TerminalDisplayAccessible.h"
#include "SessionManager.h"
#include "Session.h"
using namespace Konsole;
......@@ -304,6 +306,8 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _lineSelectionMode(false)
, _preserveLineBreaks(false)
, _columnSelectionMode(false)
, _autoCopySelectedText(false)
, _middleClickPasteMode(Enum::PasteFromX11Selection)
, _scrollbarLocation(Enum::ScrollBarRight)
, _wordCharacters(":@-./_~")
, _bellMode(Enum::NotifyBell)
......@@ -1793,10 +1797,21 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
}
}
} else if (ev->button() == Qt::MidButton) {
if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier))
doPaste(true, ev->modifiers() & Qt::ControlModifier);
else
if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier)) {
const bool appendEnter = ev->modifiers() & Qt::ControlModifier;
if ( _middleClickPasteMode == Enum::PasteFromX11Selection ) {
pasteFromX11Selection(appendEnter);
} else if ( _middleClickPasteMode == Enum::PasteFromClipboard ) {
pasteFromClipboard(appendEnter);
} else {
Q_ASSERT(false);
}
} else {
emit mouseSignal(1, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 0);
}
} else if (ev->button() == Qt::RightButton) {
if (_mouseMarks || (ev->modifiers() & Qt::ShiftModifier))
emit configureRequest(ev->pos());
......@@ -2134,7 +2149,7 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev)
_screenWindow->clearSelection();
} else {
if (_actSel > 1) {
setXSelection(_screenWindow->selectedText(_preserveLineBreaks));
copyToX11Selection();
}
_actSel = 0;
......@@ -2269,7 +2284,7 @@ void TerminalDisplay::mouseDoubleClickEvent(QMouseEvent* ev)
_screenWindow->setSelectionEnd(endSel.x() , endSel.y());
setXSelection(_screenWindow->selectedText(_preserveLineBreaks));
copyToX11Selection();
}
_possibleTripleClick = true;
......@@ -2390,7 +2405,7 @@ void TerminalDisplay::mouseTripleClickEvent(QMouseEvent* ev)
_screenWindow->setSelectionEnd(_columns - 1 , _iPntSel.y());
setXSelection(_screenWindow->selectedText(_preserveLineBreaks));
copyToX11Selection();
_iPntSel.ry() += _scrollBar->value();
}
......@@ -2455,28 +2470,47 @@ bool TerminalDisplay::usesMouse() const