Commit 9f3e26e7 authored by Kurt Hindenburg's avatar Kurt Hindenburg

Update 'Copy Input To->' menu items.

Thanks to Thomas Dreibholz for patch.  I made a few minor alterations.

BUG: 168292
GUI

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=1027898
parent 0b0ed49c
<!DOCTYPE kpartgui>
<kpartgui name="session" version="8">
<kpartgui name="session" version="9">
<MenuBar>
<Menu name="file">
<Action name="open-browser" group="session-operations"/>
......@@ -11,7 +11,11 @@
<Action name="paste" group="session-edit-operations" />
<Action name="rename-session" group="session-edit-operations" />
<Separator group="session-edit-operations"/>
<Action name="copy-input-to" group="session-edit-operations"/>
<Menu name="edit-copy-input-to" group="session-edit-operations"><text>Copy Input To</text>
<Action name="copy-input-to-all-tabs" />
<Action name="copy-input-to-selected-tabs" />
<Action name="copy-input-to-none" />
</Menu>
<Action name="zmodem-upload" group="session-edit-operations"/>
<Separator group="session-edit-operations"/>
<Action name="clear" group="session-edit-operations" />
......
......@@ -1241,7 +1241,7 @@ void SessionGroup::addSession(Session* session)
QListIterator<Session*> masterIter(masters());
while ( masterIter.hasNext() )
connectPair(masterIter.next(),session);
connectPair(masterIter.next());
}
void SessionGroup::removeSession(Session* session)
{
......@@ -1252,7 +1252,7 @@ void SessionGroup::removeSession(Session* session)
QListIterator<Session*> masterIter(masters());
while ( masterIter.hasNext() )
disconnectPair(masterIter.next(),session);
disconnectPair(masterIter.next());
_sessions.remove(session);
}
......@@ -1289,9 +1289,9 @@ void SessionGroup::connectAll(bool connect)
if ( other != master )
{
if ( connect )
connectPair(master,other);
connectPair(master);
else
disconnectPair(master,other);
disconnectPair(master);
}
}
}
......@@ -1313,28 +1313,52 @@ void SessionGroup::setMasterStatus(Session* session , bool master)
if ( other != session )
{
if ( master )
connectPair(session,other);
connectPair(session);
else
disconnectPair(session,other);
disconnectPair(session);
}
}
}
void SessionGroup::connectPair(Session* master , Session* other)
void SessionGroup::connectPair(Session* master)
{
if ( _masterMode & CopyInputToAll )
{
connect( master->emulation() , SIGNAL(sendData(const char*,int)) , other->emulation() ,
SLOT(sendString(const char*,int)) );
// It is not possible to connect directly to other->emulation()'s
// sendString() here, since this would cause an infinite loop when
// the destination session is also the master of another group!
connect( master->emulation() , SIGNAL(sendData(const char*,int)) , this,
SLOT(forwardData(const char*,int)) );
}
}
void SessionGroup::disconnectPair(Session* master , Session* other)
void SessionGroup::disconnectPair(Session* master)
{
if ( _masterMode & CopyInputToAll )
{
disconnect( master->emulation() , SIGNAL(sendData(const char*,int)) , other->emulation() ,
SLOT(sendString(const char*,int)) );
disconnect( master->emulation() , SIGNAL(sendData(const char*,int)) , this,
SLOT(forwardData(const char*,int)) );
}
}
void SessionGroup::forwardData(const char* data, int size)
{
static bool _inForwardData = false;
if(_inForwardData) { // Avoid recursive calls among session groups!
// A recursive call happens when a master in group A calls forwardData()
// in group B. If one of the destination sessions in group B is also a
// master of a group including the master session of group A, this would
// again call forwardData() in group A, and so on.
return;
}
_inForwardData = true;
QListIterator<Session*> iter(_sessions.keys());
while(iter.hasNext()) {
Session* other = iter.next();
if(!_sessions[other]) {
other->emulation()->sendString(data, size);
}
}
_inForwardData = false;
}
#include "Session.moc"
......@@ -3,6 +3,7 @@
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
Copyright 2009 by Thomas Dreibholz <dreibh@iem.uni-due.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -706,10 +707,11 @@ public:
private slots:
void sessionFinished();
void forwardData(const char* data, int size);
private:
void connectPair(Session* master , Session* other);
void disconnectPair(Session* master , Session* other);
void connectPair(Session* master);
void disconnectPair(Session* master);
void connectAll(bool connect);
QList<Session*> masters() const;
......
......@@ -38,6 +38,7 @@
#include <KStandardDirs>
#include <KToggleAction>
#include <KUrl>
#include <KXmlGuiWindow>
#include <KXMLGUIFactory>
#include <KXMLGUIBuilder>
#include <kdebug.h>
......@@ -295,6 +296,12 @@ bool SessionController::eventFilter(QObject* watched , QEvent* event)
// second, connect the newly focused view to listen for the session's bell signal
connect( _session , SIGNAL(bellRequest(const QString&)) ,
_view , SLOT(bell(const QString&)) );
if(_copyToAllTabsAction->isChecked()) {
// A session with "Copy To All Tabs" has come into focus:
// Ensure that newly created sessions are included in _copyToGroup!
copyInputToAllTabs();
}
}
// when a mouse move is received, create the URL filter and listen for output changes if
// it has not already been created. If it already exists, then update only if the output
......@@ -421,10 +428,27 @@ void SessionController::setupActions()
action->setShortcut( QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_S) );
connect( action , SIGNAL(triggered()) , this , SLOT(renameSession()) );
// Copy Input To
action = collection->addAction("copy-input-to");
action->setText(i18n("Copy Input To..."));
connect( action , SIGNAL(triggered()) , this , SLOT(copyInputTo()) );
// Copy Input To -> All Tabs in Current Window
_copyToAllTabsAction = collection->addAction("copy-input-to-all-tabs");
_copyToAllTabsAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Comma) );
_copyToAllTabsAction->setText(i18n("&All Tabs in Current Window") );
_copyToAllTabsAction->setCheckable(TRUE);
connect( _copyToAllTabsAction , SIGNAL(triggered()) , this , SLOT(copyInputToAllTabs()) );
// Copy Input To -> Select Tabs
_copyToSelectedAction = collection->addAction("copy-input-to-selected-tabs");
_copyToSelectedAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Period) );
_copyToSelectedAction->setText( i18n("&Select Tabs...") );
_copyToSelectedAction->setCheckable(TRUE);
connect( _copyToSelectedAction , SIGNAL(triggered()) , this , SLOT(copyInputToSelectedTabs()) );
// Copy Input To -> None
_copyToNoneAction = collection->addAction("copy-input-to-none");
_copyToNoneAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Slash) );
_copyToNoneAction->setText( i18n("&None") );
_copyToNoneAction->setCheckable(TRUE);
_copyToNoneAction->setChecked(TRUE);
connect( _copyToNoneAction , SIGNAL(triggered()) , this , SLOT(copyInputToNone()) );
// Clear+Reset
action = collection->addAction("clear-and-reset");
......@@ -633,7 +657,70 @@ void SessionController::pasteSelection()
{
_view->pasteSelection();
}
void SessionController::copyInputTo()
static const KXmlGuiWindow* findWindow(const QObject* object)
{
// Walk up the QObject hierarchy to find a KXmlGuiWindow.
while(object != NULL) {
const KXmlGuiWindow* window = dynamic_cast<const KXmlGuiWindow*>(object);
if(window != NULL) {
return(window);
}
object = object->parent();
}
return(NULL);
}
static bool hasTerminalDisplayInSameWindow(const Session* session, const KXmlGuiWindow* window)
{
// Iterate all TerminalDisplays of this Session ...
QListIterator<TerminalDisplay*> terminalDisplayIterator(session->views());
while(terminalDisplayIterator.hasNext()) {
const TerminalDisplay* terminalDisplay = terminalDisplayIterator.next();
// ... and check whether a TerminalDisplay has the same
// window as given in the parameter
if(window == findWindow(terminalDisplay)) {
return(true);
}
}
return(false);
}
void SessionController::copyInputToAllTabs()
{
if(!_copyToGroup) {
_copyToGroup = new SessionGroup(this);
_copyToGroup->addSession(_session);
_copyToGroup->setMasterStatus(_session, true);
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
}
// Find our window ...
const KXmlGuiWindow* myWindow = findWindow(_view);
QSet<Session*> group =
QSet<Session*>::fromList(SessionManager::instance()->sessions());
for(QSet<Session*>::iterator iterator = group.begin();
iterator != group.end(); ++iterator) {
Session* session = *iterator;
if(session != _session) {
// First, ensure that the session is removed
// (necessary to avoid duplicates on addSession()!)
_copyToGroup->removeSession(session);
// Add current session if it is displayed our window
if(hasTerminalDisplayInSameWindow(session, myWindow)) {
_copyToGroup->addSession(session);
}
}
}
snapshot();
_copyToAllTabsAction->setChecked(TRUE);
_copyToSelectedAction->setChecked(FALSE);
_copyToNoneAction->setChecked(FALSE);
}
void SessionController::copyInputToSelectedTabs()
{
if (!_copyToGroup)
{
......@@ -670,11 +757,33 @@ void SessionController::copyInputTo()
_copyToGroup->removeSession(session);
}
snapshot();
snapshot();
}
delete dialog;
_copyToAllTabsAction->setChecked(FALSE);
_copyToSelectedAction->setChecked(TRUE);
_copyToNoneAction->setChecked(FALSE);
}
void SessionController::copyInputToNone()
{
QSet<Session*> group =
QSet<Session*>::fromList(SessionManager::instance()->sessions());
for(QSet<Session*>::iterator iterator = group.begin();
iterator != group.end(); ++iterator) {
Session* session = *iterator;
if(session != _session) {
_copyToGroup->removeSession(*iterator);
}
}
snapshot();
_copyToAllTabsAction->setChecked(FALSE);
_copyToSelectedAction->setChecked(FALSE);
_copyToNoneAction->setChecked(TRUE);
}
void SessionController::clear()
{
Emulation* emulation = _session->emulation();
......
......@@ -166,7 +166,9 @@ private slots:
void pasteSelection(); // shortcut only
void clear();
void clearAndReset();
void copyInputTo();
void copyInputToAllTabs();
void copyInputToSelectedTabs();
void copyInputToNone();
void editCurrentProfile();
void changeCodec(QTextCodec* codec);
void searchHistory(bool showSearchBar);
......@@ -243,6 +245,10 @@ private:
UrlFilter* _viewUrlFilter;
RegExpFilter* _searchFilter;
KAction* _copyToAllTabsAction;
KAction* _copyToSelectedAction;
KAction* _copyToNoneAction;
KAction* _searchToggleAction;
KAction* _findNextAction;
KAction* _findPreviousAction;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment