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