+void MainWindow::remove_session(shared_ptr<Session> session)
+{
+ for (shared_ptr<views::ViewBase> view : session->views()) {
+ // Find the dock the view is contained in and remove it
+ for (auto entry : view_docks_)
+ if (entry.second == view) {
+ // Remove the view from the session
+ session->deregister_view(view);
+
+ // Remove the view from its parent; otherwise, Qt will
+ // call deleteLater() on it, which causes a double free
+ // since the shared_ptr in view_docks_ doesn't know
+ // that Qt keeps a pointer to the view around
+ entry.second->setParent(0);
+
+ // Remove this entry from the container
+ view_docks_.erase(entry.first);
+ }
+ }
+
+ QMainWindow *window = session_windows_.at(session);
+ session_selector_.removeTab(session_selector_.indexOf(window));
+
+ session_windows_.erase(session);
+
+ sessions_.remove_if([&](shared_ptr<Session> s) {
+ return s == session; });
+
+ // Update the window title if there is no view left to
+ // generate focus change events
+ if (sessions_.empty())
+ setWindowTitle(WindowTitle);
+}
+