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