diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -500,22 +500,8 @@ if (!profile) { profile = ProfileManager::instance()->defaultProfile(); } - - Session *session = SessionManager::instance()->createSession(profile); - - if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { - session->setInitialWorkingDirectory(directory); - } - - session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); - - // create view before starting the session process so that the session - // doesn't suffer a change in terminal size right after the session - // starts. Some applications such as GNU Screen and Midnight Commander - // don't like this happening - _viewManager->createView(session); - - return session; + int sessionId = _viewManager->newSession(profile->name(), directory, false); + return SessionManager::instance()->idToSession(sessionId); } Session *MainWindow::createSSHSession(Profile::Ptr profile, const QUrl &url) diff --git a/src/Part.cpp b/src/Part.cpp --- a/src/Part.cpp +++ b/src/Part.cpp @@ -200,21 +200,14 @@ void Part::createSession(const QString &profileName, const QString &directory) { - Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); - if (!profileName.isEmpty()) { - profile = ProfileManager::instance()->loadProfile(profileName); - } + auto profile = profileName.isEmpty() ? + ProfileManager::instance()->defaultProfile() : + ProfileManager::instance()->loadProfile(profileName); Q_ASSERT(profile); - Session *session = SessionManager::instance()->createSession(profile); - - // override the default directory specified in the profile - if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { - session->setInitialWorkingDirectory(directory); - } - - _viewManager->createView(session); + const auto initialDir = profile->startInCurrentSessionDir() ? directory : QString(); + _viewManager->newSession(profile->name(), initialDir, false); } void Part::activeViewChanged(SessionController *controller) diff --git a/src/ViewManager.h b/src/ViewManager.h --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -251,18 +251,12 @@ /** DBus slot that sets the current (active) session window */ Q_SCRIPTABLE void setCurrentSession(int sessionId); - /** DBus slot that creates a new session in the current view. - * @param profile the name of the profile to be used - * started. - */ - Q_SCRIPTABLE int newSession(const QString &profile); - /** DBus slot that creates a new session in the current view. * @param profile the name of the profile to be used * @param directory the working directory where the session is * started. */ - Q_SCRIPTABLE int newSession(const QString &profile, const QString &directory); + Q_SCRIPTABLE int newSession(const QString &profile = QString(), const QString &directory = QString(), bool runSession = true); // TODO: its semantic is application-wide. Move it to more appropriate place // DBus slot that returns the name of default profile @@ -272,11 +266,6 @@ // DBus slot that returns a string list of defined (known) profiles Q_SCRIPTABLE QStringList profileList(); - /** DBus slot that creates a new session in the current view with the associated - * default profile and the default working directory - */ - Q_SCRIPTABLE int newSession(); - /** DBus slot that changes the view port to the next session */ Q_SCRIPTABLE void nextSession(); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -1066,60 +1066,29 @@ } } -int ViewManager::newSession() +int ViewManager::newSession(const QString &profile, const QString &directory, bool runSession) { - Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); - Session *session = SessionManager::instance()->createSession(profile); - - session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); - - createView(session); - session->run(); - - return session->sessionId(); -} - -int ViewManager::newSession(const QString &profile) -{ - const QList profilelist = ProfileManager::instance()->allProfiles(); Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); - for (const auto &i : profilelist) { - if (i->name() == profile) { - profileptr = i; - break; - } - } - - Session *session = SessionManager::instance()->createSession(profileptr); - - session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); - - createView(session); - session->run(); - - return session->sessionId(); -} - -int ViewManager::newSession(const QString &profile, const QString &directory) -{ - const QList profilelist = ProfileManager::instance()->allProfiles(); - Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); - - for (const auto &i : profilelist) { - if (i->name() == profile) { - profileptr = i; - break; + if (!profile.isEmpty()) { + const QList profilelist = ProfileManager::instance()->allProfiles(); + for (const auto &i : profilelist) { + if (i->name() == profile) { + profileptr = i; + break; + } } } Session *session = SessionManager::instance()->createSession(profileptr); - session->setInitialWorkingDirectory(directory); + if (!directory.isEmpty()) + session->setInitialWorkingDirectory(directory); session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); createView(session); - session->run(); + if (runSession) + session->run(); return session->sessionId(); }