2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <libsigrokdecode/libsigrokdecode.h>
31 #include <QApplication>
32 #include <QCloseEvent>
34 #include <QDockWidget>
35 #include <QHBoxLayout>
36 #include <QMessageBox>
41 #include "mainwindow.hpp"
43 #include "devicemanager.hpp"
44 #include "devices/hardwaredevice.hpp"
45 #include "dialogs/settings.hpp"
46 #include "globalsettings.hpp"
47 #include "toolbars/mainbar.hpp"
49 #include "views/trace/view.hpp"
50 #include "views/trace/standardbar.hpp"
52 #include <libsigrokcxx/libsigrokcxx.hpp>
54 using std::dynamic_pointer_cast;
55 using std::make_shared;
56 using std::shared_ptr;
65 using toolbars::MainBar;
67 const QString MainWindow::WindowTitle = tr("PulseView");
69 MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) :
71 device_manager_(device_manager),
72 session_selector_(this),
73 session_state_mapper_(this),
74 icon_red_(":/icons/status-red.svg"),
75 icon_green_(":/icons/status-green.svg"),
76 icon_grey_(":/icons/status-grey.svg")
78 qRegisterMetaType<util::Timestamp>("util::Timestamp");
79 qRegisterMetaType<uint64_t>("uint64_t");
81 GlobalSettings::add_change_handler(this);
84 restore_ui_settings();
87 MainWindow::~MainWindow()
89 GlobalSettings::remove_change_handler(this);
91 while (!sessions_.empty())
92 remove_session(sessions_.front());
95 void MainWindow::show_session_error(const QString text, const QString info_text)
97 qDebug().noquote() << "Notifying user of session error:" << info_text;
101 msg.setInformativeText(info_text);
102 msg.setStandardButtons(QMessageBox::Ok);
103 msg.setIcon(QMessageBox::Warning);
107 shared_ptr<views::ViewBase> MainWindow::get_active_view() const
109 // If there's only one view, use it...
110 if (view_docks_.size() == 1)
111 return view_docks_.begin()->second;
113 // ...otherwise find the dock widget the widget with focus is contained in
114 QObject *w = QApplication::focusWidget();
115 QDockWidget *dock = nullptr;
118 dock = qobject_cast<QDockWidget*>(w);
124 // Get the view contained in the dock widget
125 for (auto entry : view_docks_)
126 if (entry.first == dock)
132 shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
133 views::ViewType type, Session &session)
135 GlobalSettings settings;
136 shared_ptr<views::ViewBase> v;
138 QMainWindow *main_window = nullptr;
139 for (auto entry : session_windows_)
140 if (entry.first.get() == &session)
141 main_window = entry.second;
145 shared_ptr<MainBar> main_bar = session.main_bar();
147 QDockWidget* dock = new QDockWidget(title, main_window);
148 dock->setObjectName(title);
149 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
151 // Insert a QMainWindow into the dock widget to allow for a tool bar
152 QMainWindow *dock_main = new QMainWindow(dock);
153 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
155 if (type == views::ViewTypeTrace)
156 // This view will be the main view if there's no main bar yet
157 v = make_shared<views::trace::View>(session,
158 (main_bar ? false : true), dock_main);
163 view_docks_[dock] = v;
164 session.register_view(v);
166 dock_main->setCentralWidget(v.get());
167 dock->setWidget(dock_main);
169 dock->setContextMenuPolicy(Qt::PreventContextMenu);
170 dock->setFeatures(QDockWidget::DockWidgetMovable |
171 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
173 QAbstractButton *close_btn =
174 dock->findChildren<QAbstractButton*>
175 ("qt_dockwidget_closebutton").front();
177 connect(close_btn, SIGNAL(clicked(bool)),
178 this, SLOT(on_view_close_clicked()));
180 connect(&session, SIGNAL(trigger_event(int, util::Timestamp)),
181 qobject_cast<views::ViewBase*>(v.get()),
182 SLOT(trigger_event(int, util::Timestamp)));
184 if (type == views::ViewTypeTrace) {
185 views::trace::View *tv =
186 qobject_cast<views::trace::View*>(v.get());
188 tv->enable_colored_bg(settings.value(GlobalSettings::Key_View_ColoredBG).toBool());
189 tv->enable_show_sampling_points(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
190 tv->enable_show_analog_minor_grid(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
193 /* Initial view, create the main bar */
194 main_bar = make_shared<MainBar>(session, this, tv);
195 dock_main->addToolBar(main_bar.get());
196 session.set_main_bar(main_bar);
198 connect(main_bar.get(), SIGNAL(new_view(Session*)),
199 this, SLOT(on_new_view(Session*)));
201 main_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
203 /* For the main view we need to prevent the dock widget from
204 * closing itself when its close button is clicked. This is
205 * so we can confirm with the user first. Regular views don't
207 close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close()));
209 /* Additional view, create a standard bar */
210 pv::views::trace::StandardBar *standard_bar =
211 new pv::views::trace::StandardBar(session, this, tv);
212 dock_main->addToolBar(standard_bar);
214 standard_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
221 void MainWindow::remove_view(shared_ptr<views::ViewBase> view)
223 for (shared_ptr<Session> session : sessions_) {
224 if (!session->has_view(view))
227 // Find the dock the view is contained in and remove it
228 for (auto entry : view_docks_)
229 if (entry.second == view) {
230 // Remove the view from the session
231 session->deregister_view(view);
233 // Remove the view from its parent; otherwise, Qt will
234 // call deleteLater() on it, which causes a double free
235 // since the shared_ptr in view_docks_ doesn't know
236 // that Qt keeps a pointer to the view around
237 view->setParent(nullptr);
239 // Delete the view's dock widget and all widgets inside it
240 entry.first->deleteLater();
242 // Remove the dock widget from the list and stop iterating
243 view_docks_.erase(entry.first);
249 shared_ptr<Session> MainWindow::add_session()
251 static int last_session_id = 1;
252 QString name = tr("Session %1").arg(last_session_id++);
254 shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
256 connect(session.get(), SIGNAL(add_view(const QString&, views::ViewType, Session*)),
257 this, SLOT(on_add_view(const QString&, views::ViewType, Session*)));
258 connect(session.get(), SIGNAL(name_changed()),
259 this, SLOT(on_session_name_changed()));
260 session_state_mapper_.setMapping(session.get(), session.get());
261 connect(session.get(), SIGNAL(capture_state_changed(int)),
262 &session_state_mapper_, SLOT(map()));
264 sessions_.push_back(session);
266 QMainWindow *window = new QMainWindow();
267 window->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
268 session_windows_[session] = window;
270 int index = session_selector_.addTab(window, name);
271 session_selector_.setCurrentIndex(index);
272 last_focused_session_ = session;
274 window->setDockNestingEnabled(true);
276 shared_ptr<views::ViewBase> main_view =
277 add_view(name, views::ViewTypeTrace, *session);
282 void MainWindow::remove_session(shared_ptr<Session> session)
284 // Determine the height of the button before it collapses
285 int h = new_session_button_->height();
287 // Stop capture while the session still exists so that the UI can be
288 // updated in case we're currently running. If so, this will schedule a
289 // call to our on_capture_state_changed() slot for the next run of the
290 // event loop. We need to have this executed immediately or else it will
291 // be dismissed since the session object will be deleted by the time we
292 // leave this method and the event loop gets a chance to run again.
293 session->stop_capture();
294 QApplication::processEvents();
296 for (shared_ptr<views::ViewBase> view : session->views())
299 QMainWindow *window = session_windows_.at(session);
300 session_selector_.removeTab(session_selector_.indexOf(window));
302 session_windows_.erase(session);
304 if (last_focused_session_ == session)
305 last_focused_session_.reset();
307 // Remove the session from our list of sessions (which also destroys it)
308 sessions_.remove_if([&](shared_ptr<Session> s) {
309 return s == session; });
311 if (sessions_.empty()) {
312 // When there are no more tabs, the height of the QTabWidget
313 // drops to zero. We must prevent this to keep the static
315 for (QWidget *w : static_tab_widget_->findChildren<QWidget*>())
316 w->setMinimumHeight(h);
318 int margin = static_tab_widget_->layout()->contentsMargins().bottom();
319 static_tab_widget_->setMinimumHeight(h + 2 * margin);
320 session_selector_.setMinimumHeight(h + 2 * margin);
322 // Update the window title if there is no view left to
323 // generate focus change events
324 setWindowTitle(WindowTitle);
328 void MainWindow::add_session_with_file(string open_file_name,
329 string open_file_format)
331 shared_ptr<Session> session = add_session();
332 session->load_init_file(open_file_name, open_file_format);
335 void MainWindow::add_default_session()
337 // Only add the default session if there would be no session otherwise
338 if (sessions_.size() > 0)
341 shared_ptr<Session> session = add_session();
343 // Check the list of available devices. Prefer the one that was
344 // found with user supplied scan specs (if applicable). Then try
345 // one of the auto detected devices that are not the demo device.
346 // Pick demo in the absence of "genuine" hardware devices.
347 shared_ptr<devices::HardwareDevice> user_device, other_device, demo_device;
348 for (shared_ptr<devices::HardwareDevice> dev : device_manager_.devices()) {
349 if (dev == device_manager_.user_spec_device()) {
351 } else if (dev->hardware_device()->driver()->name() == "demo") {
358 session->select_device(user_device);
359 else if (other_device)
360 session->select_device(other_device);
362 session->select_device(demo_device);
365 void MainWindow::save_sessions()
370 for (shared_ptr<Session> session : sessions_) {
371 // Ignore sessions using the demo device or no device at all
372 if (session->device()) {
373 shared_ptr<devices::HardwareDevice> device =
374 dynamic_pointer_cast< devices::HardwareDevice >
378 device->hardware_device()->driver()->name() == "demo")
381 settings.beginGroup("Session" + QString::number(id++));
382 settings.remove(""); // Remove all keys in this group
383 session->save_settings(settings);
388 settings.setValue("sessions", id);
391 void MainWindow::restore_sessions()
394 int i, session_count;
396 session_count = settings.value("sessions", 0).toInt();
398 for (i = 0; i < session_count; i++) {
399 settings.beginGroup("Session" + QString::number(i));
400 shared_ptr<Session> session = add_session();
401 session->restore_settings(settings);
406 void MainWindow::on_setting_changed(const QString &key, const QVariant &value)
408 if (key == GlobalSettings::Key_View_ColoredBG)
409 on_settingViewColoredBg_changed(value);
411 if (key == GlobalSettings::Key_View_ShowSamplingPoints)
412 on_settingViewShowSamplingPoints_changed(value);
414 if (key == GlobalSettings::Key_View_ShowAnalogMinorGrid)
415 on_settingViewShowAnalogMinorGrid_changed(value);
418 void MainWindow::setup_ui()
420 setObjectName(QString::fromUtf8("MainWindow"));
422 setCentralWidget(&session_selector_);
424 // Set the window icon
426 icon.addFile(QString(":/icons/pulseview.png"));
429 view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
430 view_sticky_scrolling_shortcut_->setAutoRepeat(false);
432 view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
433 view_show_sampling_points_shortcut_->setAutoRepeat(false);
435 view_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut()));
436 view_show_analog_minor_grid_shortcut_->setAutoRepeat(false);
438 view_colored_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_colored_bg_shortcut()));
439 view_colored_bg_shortcut_->setAutoRepeat(false);
441 // Set up the tab area
442 new_session_button_ = new QToolButton();
443 new_session_button_->setIcon(QIcon::fromTheme("document-new",
444 QIcon(":/icons/document-new.png")));
445 new_session_button_->setToolTip(tr("Create New Session"));
446 new_session_button_->setAutoRaise(true);
448 run_stop_button_ = new QToolButton();
449 run_stop_button_->setAutoRaise(true);
450 run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
451 run_stop_button_->setToolTip(tr("Start/Stop Acquisition"));
453 run_stop_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Space), run_stop_button_, SLOT(click()));
454 run_stop_shortcut_->setAutoRepeat(false);
456 settings_button_ = new QToolButton();
457 settings_button_->setIcon(QIcon::fromTheme("preferences-system",
458 QIcon(":/icons/preferences-system.png")));
459 settings_button_->setToolTip(tr("Settings"));
460 settings_button_->setAutoRaise(true);
462 QFrame *separator1 = new QFrame();
463 separator1->setFrameStyle(QFrame::VLine | QFrame::Raised);
464 QFrame *separator2 = new QFrame();
465 separator2->setFrameStyle(QFrame::VLine | QFrame::Raised);
467 QHBoxLayout* layout = new QHBoxLayout();
468 layout->setContentsMargins(2, 2, 2, 2);
469 layout->addWidget(new_session_button_);
470 layout->addWidget(separator1);
471 layout->addWidget(run_stop_button_);
472 layout->addWidget(separator2);
473 layout->addWidget(settings_button_);
475 static_tab_widget_ = new QWidget();
476 static_tab_widget_->setLayout(layout);
478 session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
479 session_selector_.setTabsClosable(true);
481 close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
482 close_application_shortcut_->setAutoRepeat(false);
484 close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
486 connect(new_session_button_, SIGNAL(clicked(bool)),
487 this, SLOT(on_new_session_clicked()));
488 connect(run_stop_button_, SIGNAL(clicked(bool)),
489 this, SLOT(on_run_stop_clicked()));
490 connect(&session_state_mapper_, SIGNAL(mapped(QObject*)),
491 this, SLOT(on_capture_state_changed(QObject*)));
492 connect(settings_button_, SIGNAL(clicked(bool)),
493 this, SLOT(on_settings_clicked()));
495 connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
496 this, SLOT(on_tab_close_requested(int)));
497 connect(&session_selector_, SIGNAL(currentChanged(int)),
498 this, SLOT(on_tab_changed(int)));
501 connect(static_cast<QApplication *>(QCoreApplication::instance()),
502 SIGNAL(focusChanged(QWidget*, QWidget*)),
503 this, SLOT(on_focus_changed()));
506 void MainWindow::save_ui_settings()
510 settings.beginGroup("MainWindow");
511 settings.setValue("state", saveState());
512 settings.setValue("geometry", saveGeometry());
516 void MainWindow::restore_ui_settings()
520 settings.beginGroup("MainWindow");
522 if (settings.contains("geometry")) {
523 restoreGeometry(settings.value("geometry").toByteArray());
524 restoreState(settings.value("state").toByteArray());
531 shared_ptr<Session> MainWindow::get_tab_session(int index) const
533 // Find the session that belongs to the tab's main window
534 for (auto entry : session_windows_)
535 if (entry.second == session_selector_.widget(index))
541 void MainWindow::closeEvent(QCloseEvent *event)
543 bool data_saved = true;
545 for (auto entry : session_windows_)
546 if (!entry.first->data_saved())
549 if (!data_saved && (QMessageBox::question(this, tr("Confirmation"),
550 tr("There is unsaved data. Close anyway?"),
551 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
560 QMenu* MainWindow::createPopupMenu()
565 bool MainWindow::restoreState(const QByteArray &state, int version)
570 // Do nothing. We don't want Qt to handle this, or else it
571 // will try to restore all the dock widgets and create havoc.
576 void MainWindow::on_add_view(const QString &title, views::ViewType type,
579 // We get a pointer and need a reference
580 for (shared_ptr<Session> s : sessions_)
581 if (s.get() == session)
582 add_view(title, type, *s);
585 void MainWindow::on_focus_changed()
587 shared_ptr<views::ViewBase> view = get_active_view();
590 for (shared_ptr<Session> session : sessions_) {
591 if (session->has_view(view)) {
592 if (session != last_focused_session_) {
593 // Activate correct tab if necessary
594 shared_ptr<Session> tab_session = get_tab_session(
595 session_selector_.currentIndex());
596 if (tab_session != session)
597 session_selector_.setCurrentWidget(
598 session_windows_.at(session));
600 on_focused_session_changed(session);
608 if (sessions_.empty())
609 setWindowTitle(WindowTitle);
612 void MainWindow::on_focused_session_changed(shared_ptr<Session> session)
614 last_focused_session_ = session;
616 setWindowTitle(session->name() + " - " + WindowTitle);
618 // Update the state of the run/stop button, too
619 on_capture_state_changed(session.get());
622 void MainWindow::on_new_session_clicked()
627 void MainWindow::on_run_stop_clicked()
629 shared_ptr<Session> session = last_focused_session_;
634 switch (session->get_capture_state()) {
635 case Session::Stopped:
636 session->start_capture([&](QString message) {
637 show_session_error("Capture failed", message); });
639 case Session::AwaitingTrigger:
640 case Session::Running:
641 session->stop_capture();
646 void MainWindow::on_settings_clicked()
648 dialogs::Settings dlg(device_manager_);
652 void MainWindow::on_session_name_changed()
654 // Update the corresponding dock widget's name(s)
655 Session *session = qobject_cast<Session*>(QObject::sender());
658 for (shared_ptr<views::ViewBase> view : session->views()) {
659 // Get the dock that contains the view
660 for (auto entry : view_docks_)
661 if (entry.second == view) {
662 entry.first->setObjectName(session->name());
663 entry.first->setWindowTitle(session->name());
667 // Update the tab widget by finding the main window and the tab from that
668 for (auto entry : session_windows_)
669 if (entry.first.get() == session) {
670 QMainWindow *window = entry.second;
671 const int index = session_selector_.indexOf(window);
672 session_selector_.setTabText(index, session->name());
675 // Refresh window title if the affected session has focus
676 if (session == last_focused_session_.get())
677 setWindowTitle(session->name() + " - " + WindowTitle);
680 void MainWindow::on_capture_state_changed(QObject *obj)
682 Session *caller = qobject_cast<Session*>(obj);
684 // Ignore if caller is not the currently focused session
685 // unless there is only one session
686 if ((sessions_.size() > 1) && (caller != last_focused_session_.get()))
689 int state = caller->get_capture_state();
691 const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_};
692 run_stop_button_->setIcon(*icons[state]);
693 run_stop_button_->setText((state == pv::Session::Stopped) ?
694 tr("Run") : tr("Stop"));
697 void MainWindow::on_new_view(Session *session)
699 // We get a pointer and need a reference
700 for (shared_ptr<Session> s : sessions_)
701 if (s.get() == session)
702 add_view(session->name(), views::ViewTypeTrace, *s);
705 void MainWindow::on_view_close_clicked()
707 // Find the dock widget that contains the close button that was clicked
708 QObject *w = QObject::sender();
709 QDockWidget *dock = nullptr;
712 dock = qobject_cast<QDockWidget*>(w);
718 // Get the view contained in the dock widget
719 shared_ptr<views::ViewBase> view;
721 for (auto entry : view_docks_)
722 if (entry.first == dock)
725 // Deregister the view
726 for (shared_ptr<Session> session : sessions_) {
727 if (!session->has_view(view))
730 // Also destroy the entire session if its main view is closing...
731 if (view == session->main_view()) {
732 // ...but only if data is saved or the user confirms closing
733 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
734 tr("This session contains unsaved data. Close it anyway?"),
735 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
736 remove_session(session);
739 // All other views can be closed at any time as no data will be lost
744 void MainWindow::on_tab_changed(int index)
746 shared_ptr<Session> session = get_tab_session(index);
749 on_focused_session_changed(session);
752 void MainWindow::on_tab_close_requested(int index)
754 shared_ptr<Session> session = get_tab_session(index);
759 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
760 tr("This session contains unsaved data. Close it anyway?"),
761 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
762 remove_session(session);
765 void MainWindow::on_view_colored_bg_shortcut()
767 GlobalSettings settings;
769 bool state = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
770 settings.setValue(GlobalSettings::Key_View_ColoredBG, !state);
773 void MainWindow::on_view_sticky_scrolling_shortcut()
775 GlobalSettings settings;
777 bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
778 settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state);
781 void MainWindow::on_view_show_sampling_points_shortcut()
783 GlobalSettings settings;
785 bool state = settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
786 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state);
789 void MainWindow::on_view_show_analog_minor_grid_shortcut()
791 GlobalSettings settings;
793 bool state = settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
794 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state);
797 void MainWindow::on_settingViewColoredBg_changed(const QVariant new_value)
799 bool state = new_value.toBool();
801 for (auto entry : view_docks_) {
802 shared_ptr<views::ViewBase> viewbase = entry.second;
804 // Only trace views have this setting
805 views::trace::View* view =
806 qobject_cast<views::trace::View*>(viewbase.get());
808 view->enable_colored_bg(state);
812 void MainWindow::on_settingViewShowSamplingPoints_changed(const QVariant new_value)
814 bool state = new_value.toBool();
816 for (auto entry : view_docks_) {
817 shared_ptr<views::ViewBase> viewbase = entry.second;
819 // Only trace views have this setting
820 views::trace::View* view =
821 qobject_cast<views::trace::View*>(viewbase.get());
823 view->enable_show_sampling_points(state);
827 void MainWindow::on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value)
829 bool state = new_value.toBool();
831 for (auto entry : view_docks_) {
832 shared_ptr<views::ViewBase> viewbase = entry.second;
834 // Only trace views have this setting
835 views::trace::View* view =
836 qobject_cast<views::trace::View*>(viewbase.get());
838 view->enable_show_analog_minor_grid(state);
842 void MainWindow::on_close_current_tab()
844 int tab = session_selector_.currentIndex();
846 on_tab_close_requested(tab);