Properly focus BufferView on first click
[quassel.git] / src / uisupport / bufferview.cpp
index aa349f6..7455269 100644 (file)
@@ -86,6 +86,7 @@ BufferView::BufferView(QWidget *parent)
 {
   connect(this, SIGNAL(collapsed(const QModelIndex &)), SLOT(on_collapse(const QModelIndex &)));
   connect(this, SIGNAL(expanded(const QModelIndex &)), SLOT(on_expand(const QModelIndex &)));
+  connect(this, SIGNAL(clicked(const QModelIndex &)), SLOT(on_clicked(const QModelIndex &)));
 
   setSelectionMode(QAbstractItemView::ExtendedSelection);
 
@@ -354,6 +355,11 @@ void BufferView::on_configChanged() {
   return;
 }
 
+void BufferView::on_clicked(const QModelIndex &index) {
+  Q_UNUSED(index);
+  setFocus(Qt::MouseFocusReason);
+}
+
 void BufferView::on_collapse(const QModelIndex &index) {
   storeExpandedState(index.data(NetworkModel::NetworkIdRole).value<NetworkId>(), false);
 }
@@ -411,7 +417,12 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) {
 }
 
 void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index) {
-  Client::mainUi()->actionProvider()->addActions(contextMenu, index, this, "menuActionTriggered", (bool)config());
+  QModelIndexList indexList = selectedIndexes();
+  // make sure the item we clicked on is first
+  indexList.removeAll(index);
+  indexList.prepend(index);
+
+  Client::mainUi()->actionProvider()->addActions(contextMenu, indexList, this, "menuActionTriggered", (bool)config());
 }
 
 void BufferView::addFilterActions(QMenu *contextMenu, const QModelIndex &index) {