X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Ftabcompleter.cpp;h=527eb79540a01a953355fd89e3ec64bb18ce5d68;hp=751385a1279f8f65833768e81fab0fea86ca9ddc;hb=d650a89ba2410eea2b6b9a9be4644a7847d16d48;hpb=d316067d1daf6c7ea790ca9ac5e1ff947fe011ce diff --git a/src/uisupport/tabcompleter.cpp b/src/uisupport/tabcompleter.cpp index 751385a1..527eb795 100644 --- a/src/uisupport/tabcompleter.cpp +++ b/src/uisupport/tabcompleter.cpp @@ -28,12 +28,16 @@ #include "network.h" #include "networkmodel.h" #include "uisettings.h" +#include "action.h" +#include "actioncollection.h" +#include "qtui.h" #include const Network *TabCompleter::_currentNetwork; BufferId TabCompleter::_currentBufferId; QString TabCompleter::_currentBufferName; +TabCompleter::Type TabCompleter::_completionType; TabCompleter::TabCompleter(MultiLineEdit *_lineEdit) : QObject(_lineEdit), @@ -41,7 +45,16 @@ TabCompleter::TabCompleter(MultiLineEdit *_lineEdit) _enabled(false), _nickSuffix(": ") { + // use both an Action and generic eventFilter, to make the shortcut configurable + // yet still be able to reset() when required _lineEdit->installEventFilter(this); + ActionCollection *coll = QtUi::actionCollection("General"); + coll->addAction("TabCompletionKey", new Action(tr("Tab completion"), coll, + this, SLOT(onTabCompletionKey()), QKeySequence(Qt::Key_Tab))); +} + +void TabCompleter::onTabCompletionKey() { + complete(); } void TabCompleter::buildCompletionList() { @@ -70,7 +83,7 @@ void TabCompleter::buildCompletionList() { _completionType = ChannelTab; foreach(IrcChannel *ircChannel, _currentNetwork->ircChannels()) { if(regex.indexIn(ircChannel->name()) > -1) - _completionMap[CompletionKey(ircChannel->name(), ChannelTab)] = ircChannel->name(); + _completionMap[ircChannel->name()] = ircChannel->name(); } } else { // user completion @@ -83,16 +96,16 @@ void TabCompleter::buildCompletionList() { return; foreach(IrcUser *ircUser, channel->ircUsers()) { if(regex.indexIn(ircUser->nick()) > -1) - _completionMap[CompletionKey(ircUser->nick().toLower(), UserTab)] = ircUser->nick(); + _completionMap[ircUser->nick().toLower()] = ircUser->nick(); } } break; case BufferInfo::QueryBuffer: if(regex.indexIn(_currentBufferName) > -1) - _completionMap[CompletionKey(_currentBufferName.toLower(), UserTab)] = _currentBufferName; + _completionMap[_currentBufferName.toLower()] = _currentBufferName; case BufferInfo::StatusBuffer: if(!_currentNetwork->myNick().isEmpty() && regex.indexIn(_currentNetwork->myNick()) > -1) - _completionMap[CompletionKey(_currentNetwork->myNick().toLower(), UserTab)] = _currentNetwork->myNick(); + _completionMap[_currentNetwork->myNick().toLower()] = _currentNetwork->myNick(); break; default: return; @@ -129,6 +142,8 @@ void TabCompleter::complete() { if(_completionType == UserTab && _lineEdit->cursorPosition() == _lastCompletionLength) { _lineEdit->insert(_nickSuffix); _lastCompletionLength += _nickSuffix.length(); + } else if (s.addSpaceMidSentence()) { + _lineEdit->insert(" "); } // we're at the end of the list -> start over again @@ -150,18 +165,15 @@ bool TabCompleter::eventFilter(QObject *obj, QEvent *event) { QKeyEvent *keyEvent = static_cast(event); - if(keyEvent->key() == Qt::Key_Tab) { - complete(); - return true; - } else { + if(keyEvent->key() != QtUi::actionCollection("General")->action("TabCompletionKey")->shortcut()) { reset(); - return false; } + return false; } // this determines the sort order bool TabCompleter::CompletionKey::operator<(const CompletionKey &other) const { - switch(this->type) { + switch(_completionType) { case UserTab: { IrcUser *thisUser = _currentNetwork->ircUser(this->contents);