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