Skip to content

Commit

Permalink
Add action to open tab in the channel menu and another one in the tab…
Browse files Browse the repository at this point in the history
…'s menu to close all the tabs
  • Loading branch information
davidebeatrici committed Jul 15, 2018
1 parent e05c384 commit 3765e54
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
26 changes: 23 additions & 3 deletions src/mumble/LogTabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ void LogTabWidget::onTabCloseRequested(int index) {
updateHashMap();
}

void LogTabWidget::onTabCloseAllRequested() {
for (int i = count() - 1; i >= 0; i--) {
if (i == getGeneralTab()) {
continue;
}

QString hashKey = dynamic_cast<LogTab *>(widget(i))->m_hash;
m_hashMap.remove(hashKey);
widget(i)->deleteLater();
removeTab(i);
}

updateHashMap();
}

void LogTabWidget::onTabBarCustomContextMenuRequested(const QPoint& point) {
QSignalMapper *mapper = new QSignalMapper(this);
for (int i = 0; i < count(); i++) {
Expand All @@ -178,11 +193,16 @@ void LogTabWidget::onTabBarCustomContextMenuRequested(const QPoint& point) {

if (tabBar()->tabRect(i).contains(point)) {
QMenu *menu = new QMenu();
QAction *action = menu->addAction(tr("Close"));
mapper->setMapping(action, i);
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
QAction *closeAction = menu->addAction(tr("Close"));
QAction *closeAllAction = menu->addAction(tr("Close all"));

mapper->setMapping(closeAction, i);

connect(closeAllAction, SIGNAL(triggered()), this, SLOT(onTabCloseAllRequested()));
connect(closeAction, SIGNAL(triggered()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(int)), this, SLOT(onTabCloseRequested(int)));
connect(mapper, SIGNAL(mapped(int)), this, SIGNAL(currentChanged(int)));

menu->exec(QCursor::pos());
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/mumble/LogTabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public slots:
void onCurrentChanged(int);
void onTabMoved(int, int);
void onTabCloseRequested(int);
void onTabCloseAllRequested();
void onTabBarCustomContextMenuRequested(const QPoint &);
signals:
void anchorClick(const QUrl &);
Expand Down
13 changes: 13 additions & 0 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,7 @@ void MainWindow::qmChannel_aboutToShow() {
qmChannel->addAction(qaChannelUnlinkAll);
qmChannel->addSeparator();
qmChannel->addAction(qaChannelCopyURL);
qmChannel->addAction(qaChannelOpenTab);
qmChannel->addAction(qaChannelSendMessage);

// hiding the root is nonsense
Expand Down Expand Up @@ -2007,6 +2008,7 @@ void MainWindow::qmChannel_aboutToShow() {
qaChannelLink->setEnabled(link);
qaChannelUnlink->setEnabled(unlink);
qaChannelUnlinkAll->setEnabled(unlinkall);
qaChannelOpenTab->setEnabled(msg);
qaChannelSendMessage->setEnabled(msg);
updateMenuPermissions();
}
Expand Down Expand Up @@ -2116,6 +2118,16 @@ void MainWindow::on_qaChannelUnlinkAll_triggered() {
g.sh->sendMessage(mpcs);
}

void MainWindow::on_qaChannelOpenTab_triggered() {
Channel *c = getContextMenuChannel();
if (!c) {
return;
}

qtwLogTabs->createTab(QString::number(c->iId), c->qsName, true);
qtwLogTabs->openTab(QString::number(c->iId));
}

void MainWindow::on_qaChannelSendMessage_triggered() {
Channel *c = getContextMenuChannel();

Expand Down Expand Up @@ -2256,6 +2268,7 @@ void MainWindow::updateMenuPermissions() {
qaChannelUnlinkAll->setEnabled(p & (ChanACL::Write | ChanACL::LinkChannel));

qaChannelCopyURL->setEnabled(c);
qaChannelOpenTab->setEnabled(p & (ChanACL::Write | ChanACL::TextMessage));
qaChannelSendMessage->setEnabled(p & (ChanACL::Write | ChanACL::TextMessage));
qaChannelFilter->setEnabled(true);
}
Expand Down
1 change: 1 addition & 0 deletions src/mumble/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class MainWindow : public QMainWindow, public MessageHandler, public Ui::MainWin
void on_qaChannelLink_triggered();
void on_qaChannelUnlink_triggered();
void on_qaChannelUnlinkAll_triggered();
void on_qaChannelOpenTab_triggered();
void on_qaChannelSendMessage_triggered();
void on_qaChannelFilter_triggered();
void on_qaChannelCopyURL_triggered();
Expand Down
10 changes: 7 additions & 3 deletions src/mumble/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<x>0</x>
<y>0</y>
<width>671</width>
<height>21</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="qmConfig">
Expand Down Expand Up @@ -111,8 +111,7 @@
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="LogTabWidget" name="qtwLogTabs">
</widget>
<widget class="LogTabWidget" name="qtwLogTabs"/>
</widget>
<widget class="QDockWidget" name="qdwChat">
<property name="sizePolicy">
Expand Down Expand Up @@ -900,6 +899,11 @@ the channel's context menu.</string>
<bool>false</bool>
</property>
</action>
<action name="qaChannelOpenTab">
<property name="text">
<string>Open &amp;tab</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit 3765e54

Please sign in to comment.