diff --git a/src/Emulation.cpp b/src/Emulation.cpp index 5473f9d0a..37e9d4ca7 100644 --- a/src/Emulation.cpp +++ b/src/Emulation.cpp @@ -92,6 +92,8 @@ ScreenWindow* Emulation::createWindow() connect(window , SIGNAL(selectionChanged()), this , SLOT(bufferedUpdate())); + connect(window, SIGNAL(selectionChanged()), + this, SLOT(checkSelectedText())); connect(this , SIGNAL(outputChanged()), window , SLOT(notifyOutputChanged()) ); @@ -104,6 +106,12 @@ void Emulation::checkScreenInUse() emit primaryScreenInUse( _currentScreen == _screen[0] ); } +void Emulation::checkSelectedText() +{ + QString text = _currentScreen->selectedText(true); + emit selectedText(text); +} + Emulation::~Emulation() { QListIterator windowIter(_windows); @@ -129,6 +137,7 @@ void Emulation::setScreen(int n) window->setScreen(_currentScreen); checkScreenInUse(); + checkSelectedText(); } } diff --git a/src/Emulation.h b/src/Emulation.h index 7c22e843c..590ebf6cb 100644 --- a/src/Emulation.h +++ b/src/Emulation.h @@ -409,7 +409,13 @@ signals: * screen is in use. */ void primaryScreenInUse(bool use); + + /** + * Emitted when the text selection is changed + */ + void selectedText(const QString & text); + protected: virtual void setMode(int mode) = 0; virtual void resetMode(int mode) = 0; @@ -464,6 +470,9 @@ protected slots: // used to emit the primaryScreenInUse(bool) signal void checkScreenInUse(); + + // used to emit the selectedText(QString) signal + void checkSelectedText(); private slots: diff --git a/src/Session.cpp b/src/Session.cpp index 09f0e4a1a..dbc727482 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -142,6 +142,8 @@ Session::Session(QObject* parent) : SLOT(updateFlowControlState(bool)) ); connect( _emulation, SIGNAL(primaryScreenInUse(bool)) , this, SLOT(onPrimaryScreenInUse(bool)) ); + connect( _emulation, SIGNAL(selectedText(const QString &)) , this, + SLOT(onSelectedText(const QString &)) ); //create new teletype for I/O with shell process openTeletype(-1); @@ -621,6 +623,11 @@ void Session::onPrimaryScreenInUse(bool use) emit primaryScreenInUse(use); } +void Session::onSelectedText(const QString & text) +{ + emit selectedText(text); +} + void Session::activityStateSet(int state) { if (state == NOTIFYBELL) diff --git a/src/Session.h b/src/Session.h index ea2702ecf..8c2fb8565 100644 --- a/src/Session.h +++ b/src/Session.h @@ -585,6 +585,15 @@ signals: */ void primaryScreenInUse( bool use); + /** + * Emitted when the text selection is changed. + * + * This signal serves as a relayer of Emulation::selectedText(QString), + * making it usable for higher level component. + */ + void selectedText(const QString & text); + + private slots: void done(int, QProcess::ExitStatus); @@ -611,6 +620,9 @@ private slots: // signal relayer void onPrimaryScreenInUse(bool use); + // signal relayer + void onSelectedText(const QString & text); + private: void updateTerminalSize(); diff --git a/src/SessionController.cpp b/src/SessionController.cpp index f54892556..2f2b24fb8 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -303,6 +303,15 @@ void SessionController::setupPrimaryScreenSpecificActions( bool use) resetAction->setEnabled(use); } +void SessionController::updateCopyAction( const QString & text ) +{ + KActionCollection * collection = actionCollection() ; + QAction * copyAction = collection->action("edit_copy"); + + // copy action is meaningful only when some text is selcted. + copyAction->setEnabled(!text.isEmpty()); +} + bool SessionController::eventFilter(QObject* watched , QEvent* event) { if ( watched == _view ) @@ -424,6 +433,8 @@ void SessionController::setupActions() // Copy and Paste action = KStandardAction::copy(this, SLOT(copy()), collection); action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)); + // disabled at first, since nothing has been selected now + action->setEnabled(false); action = KStandardAction::paste(this, SLOT(paste()), collection); KShortcut pasteShortcut = action->shortcut(); diff --git a/src/SessionController.h b/src/SessionController.h index 6cc492f72..aa4303e60 100644 --- a/src/SessionController.h +++ b/src/SessionController.h @@ -162,6 +162,13 @@ public slots: * update actions which are meaningful only when rimary screen is in use. */ void setupPrimaryScreenSpecificActions( bool use); + + /** + * enable or disable the copy action + */ + void updateCopyAction( const QString & text ); + + private slots: // menu item handlers diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 9e61f193b..0395d8882 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -522,6 +522,8 @@ SessionController* ViewManager::createController(Session* session , TerminalDisp connect( session , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) ); connect( session , SIGNAL(primaryScreenInUse(bool)) , controller , SLOT(setupPrimaryScreenSpecificActions(bool)) ); + connect( session , SIGNAL(selectedText(QString)) , + controller , SLOT(updateCopyAction(QString)) ); connect( view , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) ); // if this is the first controller created then set it as the active controller