Commit aa5306c4 authored by Christian Muehlhaeuser's avatar Christian Muehlhaeuser
Browse files

Support opening new sessions in current working dir

Summary:
When a Konsole profile has the "Start in same directory as current session"
setting enabled, Yakuake now respects the setting and opens new sessions
in the current working dir, just like Konsole would.

BUG: 396472
FIXED-IN: 20.04.0

Reviewers: hein, #yakuake, #konsole, tcanabrava, hindenburg, mweepigeon, ngraham

Reviewed By: mweepigeon, ngraham

Subscribers: ngraham, mweepigeon, ryanmccoskrie

Differential Revision: https://phabricator.kde.org/D26744
parent c37e13d6
......@@ -26,8 +26,9 @@
int Session::m_availableSessionId = 0;
Session::Session(SessionType type, QWidget* parent) : QObject(parent)
Session::Session(const QString& workingDir, SessionType type, QWidget* parent) : QObject(parent)
{
m_workingDir = workingDir;
m_sessionId = m_availableSessionId;
m_availableSessionId++;
......@@ -154,9 +155,14 @@ void Session::setupSession(SessionType type)
}
}
Terminal* Session::addTerminal(QWidget* parent)
Terminal* Session::addTerminal(QWidget* parent, QString workingDir)
{
Terminal* terminal = new Terminal(parent);
if (workingDir.isEmpty()) {
// fallback to session's default working dir
workingDir = m_workingDir;
}
Terminal* terminal = new Terminal(workingDir, parent);
connect(terminal, SIGNAL(activated(int)), this, SLOT(setActiveTerminal(int)));
connect(terminal, SIGNAL(manuallyActivated(Terminal*)), this, SIGNAL(terminalManuallyActivated(Terminal*)));
connect(terminal, SIGNAL(titleChanged(int,QString)), this, SLOT(setTitle(int,QString)));
......@@ -284,7 +290,7 @@ int Session::split(Terminal* terminal, Qt::Orientation orientation)
if (splitter->orientation() != orientation)
splitter->setOrientation(orientation);
terminal = addTerminal(splitter);
terminal = addTerminal(splitter, terminal->currentWorkingDirectory());
QList<int> newSplitterSizes;
newSplitterSizes << (splitterWidth / 2) << (splitterWidth / 2);
......@@ -310,7 +316,7 @@ int Session::split(Terminal* terminal, Qt::Orientation orientation)
terminal->setSplitter(newSplitter);
terminal = addTerminal(newSplitter);
terminal = addTerminal(newSplitter, terminal->currentWorkingDirectory());
splitter->setSizes(splitterSizes);
QList<int> newSplitterSizes;
......
......@@ -41,7 +41,7 @@ class Session : public QObject
enum SessionType { Single, TwoHorizontal, TwoVertical, Quad };
enum GrowthDirection { Up, Right, Down, Left };
explicit Session(SessionType type = Single, QWidget* parent = 0);
explicit Session(const QString& workingDir, SessionType type = Single, QWidget* parent = 0);
~Session();
int id() { return m_sessionId; }
......@@ -120,9 +120,10 @@ class Session : public QObject
private:
void setupSession(SessionType type);
Terminal* addTerminal(QWidget* parent);
Terminal* addTerminal(QWidget* parent, QString workingDir = QString());
int split(Terminal* terminal, Qt::Orientation orientation);
QString m_workingDir;
static int m_availableSessionId;
int m_sessionId;
......
......@@ -51,7 +51,11 @@ SessionStack::~SessionStack()
int SessionStack::addSessionImpl(Session::SessionType type)
{
Session* session = new Session(type, this);
Session* currentSession = m_sessions.value(activeSessionId());
Terminal* currentTerminal = currentSession ? currentSession->getTerminal(currentSession->activeTerminalId()) : NULL;
QString workingDir = currentTerminal ? currentTerminal->currentWorkingDirectory() : QString();
Session* session = new Session(workingDir, type, this);
connect(session, SIGNAL(titleChanged(int,QString)), this, SIGNAL(titleChanged(int,QString)));
connect(session, SIGNAL(terminalManuallyActivated(Terminal*)), this, SLOT(handleManualTerminalActivation(Terminal*)));
connect(session, SIGNAL(keyboardInputBlocked(Terminal*)), m_visualEventOverlay, SLOT(indicateKeyboardInputBlocked(Terminal*)));
......
......@@ -41,7 +41,7 @@
int Terminal::m_availableTerminalId = 0;
Terminal::Terminal(QWidget* parent) : QObject(parent)
Terminal::Terminal(const QString& workingDir, QWidget* parent) : QObject(parent)
{
m_terminalId = m_availableTerminalId;
m_availableTerminalId++;
......@@ -84,7 +84,12 @@ Terminal::Terminal(QWidget* parent) : QObject(parent)
disableOffendingPartActions();
m_terminalInterface = qobject_cast<TerminalInterface*>(m_part);
m_terminalInterface = qobject_cast<TerminalInterfaceV2*>(m_part);
bool startInWorkingDir = m_terminalInterface->profileProperty(QStringLiteral("StartInCurrentSessionDir")).toBool();
if (startInWorkingDir && !workingDir.isEmpty()) {
m_terminalInterface->showShellInDir(workingDir);
}
}
else
displayKPartLoadError();
......@@ -299,3 +304,8 @@ void Terminal::silenceDetected()
{
emit silenceDetected(this);
}
QString Terminal::currentWorkingDirectory() const
{
return m_terminalInterface->currentWorkingDirectory();
}
......@@ -29,7 +29,8 @@
class QKeyEvent;
class TerminalInterface;
// Requires V2 to access profileProperty().
class TerminalInterfaceV2;
class Terminal : public QObject
......@@ -37,7 +38,7 @@ class Terminal : public QObject
Q_OBJECT
public:
explicit Terminal(QWidget* parent = 0);
explicit Terminal(const QString& workingDir, QWidget* parent = 0);
~Terminal();
bool eventFilter(QObject* watched, QEvent* event) override;
......@@ -65,6 +66,8 @@ class Terminal : public QObject
bool monitorSilenceEnabled() { return m_monitorSilenceEnabled; }
void setMonitorSilenceEnabled(bool enabled);
QString currentWorkingDirectory() const;
void deletePart();
......@@ -94,7 +97,7 @@ class Terminal : public QObject
int m_terminalId;
KParts::Part* m_part;
TerminalInterface* m_terminalInterface;
TerminalInterfaceV2* m_terminalInterface;
QWidget* m_partWidget;
QPointer<QWidget> m_terminalWidget;
QWidget* m_parentSplitter;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment