+void MainWindow::on_add_view(const QString &title, views::ViewType type,
+ Session *session)
+{
+ // We get a pointer and need a reference
+ for (std::shared_ptr<Session> s : sessions_)
+ if (s.get() == session)
+ add_view(title, type, *s);
+}
+
+void MainWindow::on_focus_changed()
+{
+ static shared_ptr<Session> prev_session;
+
+ shared_ptr<views::ViewBase> view = get_active_view();
+
+ if (view) {
+ for (shared_ptr<Session> session : sessions_) {
+ if (session->has_view(view)) {
+ if (session != prev_session) {
+ // Activate correct tab if necessary
+ shared_ptr<Session> tab_session = get_tab_session(
+ session_selector_.currentIndex());
+ if (tab_session != session)
+ session_selector_.setCurrentWidget(
+ session_windows_.at(session));
+
+ on_focused_session_changed(session);
+ }
+
+ prev_session = session;
+ break;
+ }
+ }
+ }
+
+ if (sessions_.empty())
+ setWindowTitle(WindowTitle);
+}
+
+void MainWindow::on_focused_session_changed(shared_ptr<Session> session)
+{
+ setWindowTitle(session->name() + " - " + WindowTitle);
+}
+
+void MainWindow::on_new_session_clicked()
+{
+ add_session();
+}
+
+void MainWindow::on_session_name_changed()
+{
+ // Update the corresponding dock widget's name(s)
+ Session *session = qobject_cast<Session*>(QObject::sender());
+ assert(session);
+
+ for (shared_ptr<views::ViewBase> view : session->views()) {
+ // Get the dock that contains the view
+ for (auto entry : view_docks_)
+ if (entry.second == view) {
+ entry.first->setObjectName(session->name());
+ entry.first->setWindowTitle(session->name());
+ }
+ }
+
+ // Refresh window title if the affected session has focus
+ shared_ptr<views::ViewBase> view = get_active_view();
+
+ if (view && session->has_view(view))
+ setWindowTitle(session->name() + " - " + WindowTitle);
+}
+
+void MainWindow::on_new_view(Session *session)
+{
+ // We get a pointer and need a reference
+ for (std::shared_ptr<Session> s : sessions_)
+ if (s.get() == session)
+ add_view(session->name(), views::ViewTypeTrace, *s);
+}
+
+void MainWindow::on_view_close_clicked()
+{
+ // Find the dock widget that contains the close button that was clicked
+ QObject *w = QObject::sender();
+ QDockWidget *dock = 0;
+
+ while (w) {
+ dock = qobject_cast<QDockWidget*>(w);
+ if (dock)
+ break;
+ w = w->parent();
+ }
+
+ // Get the view contained in the dock widget
+ shared_ptr<views::ViewBase> view;
+
+ for (auto entry : view_docks_)
+ if (entry.first == dock)
+ view = entry.second;
+
+ // Deregister the view
+ for (shared_ptr<Session> session : sessions_) {
+ if (!session->has_view(view))
+ continue;
+
+ // Also destroy the entire session if its main view is closing
+ if (view == session->main_view()) {
+ remove_session(session);
+ break;
+ } else
+ session->deregister_view(view);
+ }
+}
+
+void MainWindow::on_tab_changed(int index)
+{
+ shared_ptr<Session> session = get_tab_session(index);
+
+ if (session)
+ on_focused_session_changed(session);
+}
+
+void MainWindow::on_tab_close_requested(int index)
+{
+ // TODO Ask user if this is intended in case data is unsaved
+
+ shared_ptr<Session> session = get_tab_session(index);
+
+ if (session)
+ remove_session(session);
+}
+