Add buffer-specific actions to ChatView context menu for single-buffer scenes
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 13 Dec 2008 22:21:54 +0000 (23:21 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 13 Dec 2008 22:21:54 +0000 (23:21 +0100)
Also, don't add such actions outside of the actionProvider.

src/qtui/chatitem.cpp
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/uisupport/networkmodelactionprovider.cpp

index b629a26..a5eae80 100644 (file)
@@ -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<BufferId>());
   }
-
 }
 
 void ContentsChatItem::copyLinkToClipboard() {
index f83cfe8..867561b 100644 (file)
@@ -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());
 
index 41fb51a..b90de71 100644 (file)
@@ -72,6 +72,7 @@ public:
   virtual ~ChatScene();
 
   inline QAbstractItemModel *model() const { return _model; }
+  inline MessageFilter *filter() const { return qobject_cast<MessageFilter*>(_model); }
   inline QString idString() const { return _idString; }
 
   int rowByScenePos(qreal y) const;
index 555535e..31117f4 100644 (file)
@@ -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<QModelIndex>() << 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<NetworkId>();