From 6eebebc97f84a94f732b05a793ea8e4c000643ab Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 13 Dec 2008 23:21:54 +0100 Subject: [PATCH] Add buffer-specific actions to ChatView context menu for single-buffer scenes Also, don't add such actions outside of the actionProvider. --- src/qtui/chatitem.cpp | 13 +++---------- src/qtui/chatscene.cpp | 3 +++ src/qtui/chatscene.h | 1 + src/uisupport/networkmodelactionprovider.cpp | 17 ++++++++++++----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index b629a263..a5eae80a 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -589,18 +589,11 @@ void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) { default: break; } - } + } else { - // Buffer-specific actions - // We add these in ChatItem (rather than the scene), because they depend on the current clickable - if(chatScene()->isSingleBufferScene()) { - QModelIndex index = Client::networkModel()->bufferIndex(chatScene()->singleBufferId()); - if(index.isValid()) { - menu->addSeparator(); - QtUi::mainWindow()->allBuffersView()->addActionsToMenu(menu, index); - } + // Buffer-specific actions + Client::mainUi()->actionProvider()->addActions(menu, chatScene()->filter(), data(MessageModel::BufferIdRole).value()); } - } void ContentsChatItem::copyLinkToClipboard() { diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index f83cfe81..867561bf 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -587,6 +587,9 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { ChatItem *item = chatItemAt(pos); if(item) item->addActionsToMenu(&menu, item->mapFromScene(pos)); + else + // no item -> default scene actions + Client::mainUi()->actionProvider()->addActions(&menu, filter(), BufferId()); menu.exec(event->screenPos()); diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 41fb51a9..b90de710 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -72,6 +72,7 @@ public: virtual ~ChatScene(); inline QAbstractItemModel *model() const { return _model; } + inline MessageFilter *filter() const { return qobject_cast(_model); } inline QString idString() const { return _idString; } int rowByScenePos(qreal y) const; diff --git a/src/uisupport/networkmodelactionprovider.cpp b/src/uisupport/networkmodelactionprovider.cpp index 555535ef..31117f4e 100644 --- a/src/uisupport/networkmodelactionprovider.cpp +++ b/src/uisupport/networkmodelactionprovider.cpp @@ -207,13 +207,18 @@ void NetworkModelActionProvider::addActions(QMenu *menu, // ChatView actions if(_contextItem.isEmpty()) { // a) query buffer: handle like ircuser - // b) general chatview: only react if _contextItem is set (i.e. we right-clicked on something) + // b) general chatview: handle like channel iff it displays a single buffer // NOTE stuff breaks probably with merged buffers, need to rework a lot around here then - // for now, use the item type of a random buffer... assuming we never mix channel and query buffers - //if(!_messageFilter->containedBuffers.count()) - // return; - //BufferId randomBuf = _messageFilter->containedBuffers.values().at(0); + if(_messageFilter->containedBuffers().count() == 1) { + // we can handle this like a single bufferItem + QModelIndex index = Client::networkModel()->bufferIndex(_messageFilter->containedBuffers().values().at(0)); + _indexList = QList() << index; + addBufferItemActions(menu, index); + return; + } else { + // TODO: actions for merged buffers... _indexList contains the index of the message we clicked on + } } } } @@ -506,6 +511,8 @@ void NetworkModelActionProvider::handleHideAction(ActionType type, QAction *acti } void NetworkModelActionProvider::handleGeneralAction(ActionType type, QAction *action) { + Q_UNUSED(action) + if(!_indexList.count()) return; NetworkId networkId = _indexList.at(0).data(NetworkModel::NetworkIdRole).value(); -- 2.20.1