Changeset View
Changeset View
Standalone View
Standalone View
src/panels/terminal/terminalpanel.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
60 | { | 60 | { | ||
61 | } | 61 | } | ||
62 | 62 | | |||
63 | void TerminalPanel::goHome() | 63 | void TerminalPanel::goHome() | ||
64 | { | 64 | { | ||
65 | sendCdToTerminal(QDir::homePath(), HistoryPolicy::SkipHistory); | 65 | sendCdToTerminal(QDir::homePath(), HistoryPolicy::SkipHistory); | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | QString TerminalPanel::currentWorkingDirectory() | 68 | QString TerminalPanel::currentWorkingDirectory() | ||
elvisangelaccio: Unrelated change, should go in its own commit. | |||||
69 | { | 69 | { | ||
70 | if (m_terminal) { | 70 | if (m_terminal) { | ||
71 | return m_terminal->currentWorkingDirectory(); | 71 | return m_terminal->currentWorkingDirectory(); | ||
72 | } | 72 | } | ||
73 | return QString(); | 73 | return QString(); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | void TerminalPanel::terminalExited() | 76 | void TerminalPanel::terminalExited() | ||
77 | { | 77 | { | ||
78 | m_terminal = nullptr; | 78 | m_terminal = nullptr; | ||
79 | emit hideTerminalPanel(); | 79 | emit hideTerminalPanel(); | ||
80 | } | 80 | } | ||
81 | 81 | | |||
82 | bool TerminalPanel::isHiddenInVisibleWindow() | 82 | bool TerminalPanel::isHiddenInVisibleWindow() const | ||
83 | { | 83 | { | ||
84 | return parentWidget() | 84 | return parentWidget() | ||
85 | && parentWidget()->isHidden() | 85 | && parentWidget()->isHidden() | ||
86 | && m_terminal | 86 | && m_terminal | ||
87 | && (m_terminal->foregroundProcessId() == -1); | 87 | && !hasProgramRunning(); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | void TerminalPanel::dockVisibilityChanged() | 90 | void TerminalPanel::dockVisibilityChanged() | ||
91 | { | 91 | { | ||
92 | // Only react when the DockWidget itself (not some parent) is hidden. This way we don't | 92 | // Only react when the DockWidget itself (not some parent) is hidden. This way we don't | ||
93 | // respond when e.g. Dolphin is minimized. | 93 | // respond when e.g. Dolphin is minimized. | ||
94 | if (isHiddenInVisibleWindow()) { | 94 | if (isHiddenInVisibleWindow()) { | ||
95 | // Make sure that the following "cd /" command will not affect the view. | 95 | // Make sure that the following "cd /" command will not affect the view. | ||
96 | disconnect(m_konsolePart, SIGNAL(currentDirectoryChanged(QString)), | 96 | disconnect(m_konsolePart, SIGNAL(currentDirectoryChanged(QString)), | ||
97 | this, SLOT(slotKonsolePartCurrentDirectoryChanged(QString))); | 97 | this, SLOT(slotKonsolePartCurrentDirectoryChanged(QString))); | ||
98 | 98 | | |||
99 | // Make sure this terminal does not prevent unmounting any removable drives | 99 | // Make sure this terminal does not prevent unmounting any removable drives | ||
100 | changeDir(QUrl::fromLocalFile(QStringLiteral("/"))); | 100 | changeDir(QUrl::fromLocalFile(QStringLiteral("/"))); | ||
101 | 101 | | |||
102 | // Because we have disconnected from the part's currentDirectoryChanged() | 102 | // Because we have disconnected from the part's currentDirectoryChanged() | ||
103 | // signal, we have to update m_konsolePartCurrentDirectory manually. If this | 103 | // signal, we have to update m_konsolePartCurrentDirectory manually. If this | ||
104 | // was not done, showing the panel again might not set the part's working | 104 | // was not done, showing the panel again might not set the part's working | ||
105 | // directory correctly. | 105 | // directory correctly. | ||
106 | m_konsolePartCurrentDirectory = '/'; | 106 | m_konsolePartCurrentDirectory = '/'; | ||
107 | } | 107 | } | ||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | QString TerminalPanel::runningProgramName() const | ||||
111 | { | ||||
112 | return m_terminal ? m_terminal->foregroundProcessName() : QString(); | ||||
113 | } | ||||
114 | | ||||
elvisangelaccio: `else` is not really need after a `return`. | |||||
115 | bool TerminalPanel::hasProgramRunning() const | ||||
rkflx: Add `{}` like it's done in most places in the codebase. | |||||
rkflx: Better, but indentation seem off. | |||||
116 | { | ||||
117 | return m_terminal && (m_terminal->foregroundProcessId() != -1); | ||||
118 | } | ||||
119 | | ||||
110 | bool TerminalPanel::urlChanged() | 120 | bool TerminalPanel::urlChanged() | ||
111 | { | 121 | { | ||
112 | if (!url().isValid()) { | 122 | if (!url().isValid()) { | ||
113 | return false; | 123 | return false; | ||
114 | } | 124 | } | ||
115 | 125 | | |||
116 | const bool sendInput = m_terminal && (m_terminal->foregroundProcessId() == -1) && isVisible(); | 126 | const bool sendInput = m_terminal && !hasProgramRunning() && isVisible(); | ||
117 | if (sendInput) { | 127 | if (sendInput) { | ||
118 | changeDir(url()); | 128 | changeDir(url()); | ||
119 | } | 129 | } | ||
120 | 130 | | |||
121 | return true; | 131 | return true; | ||
122 | } | 132 | } | ||
123 | 133 | | |||
124 | void TerminalPanel::showEvent(QShowEvent* event) | 134 | void TerminalPanel::showEvent(QShowEvent* event) | ||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |
Unrelated change, should go in its own commit.