-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelRegion.cpp
More file actions
152 lines (123 loc) · 4.11 KB
/
Copy pathPanelRegion.cpp
File metadata and controls
152 lines (123 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "layout/PanelRegion.h"
#include "panels/DiagnosticsPanel.h"
#include "panels/OutputPanel.h"
#include "run/CodeRunner.h"
#include "settings/SettingsService.h"
#if defined(COLD_HAS_TERMINAL)
#include "terminal/VtermTerminalWidget.h"
#endif
#include <QDir>
#include <QLabel>
#include <QTabWidget>
#include <QTimer>
#include <QVBoxLayout>
namespace cold {
namespace {
bool isOffscreenPlatform() {
return qgetenv("QT_QPA_PLATFORM") == "offscreen";
}
} // namespace
PanelRegion::PanelRegion(SettingsService& settings, CodeRunner& codeRunner, QWidget* parent)
: QWidget(parent), m_settings(settings), m_codeRunner(codeRunner) {
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_tabs = new QTabWidget(this);
layout->addWidget(m_tabs);
#if defined(COLD_HAS_TERMINAL)
m_terminal = new VtermTerminalWidget(m_settings, m_tabs);
m_tabs->addTab(m_terminal, QStringLiteral("Terminal"));
#else
m_terminalPlaceholder = new QWidget(m_tabs);
auto* placeholderLayout = new QVBoxLayout(m_terminalPlaceholder);
auto* label =
new QLabel(QStringLiteral("Terminal requires building with -DCOLD_ENABLE_TERMINAL=ON"),
m_terminalPlaceholder);
label->setAlignment(Qt::AlignCenter);
placeholderLayout->addWidget(label);
m_tabs->addTab(m_terminalPlaceholder, QStringLiteral("Terminal"));
#endif
m_outputPanel = new OutputPanel(m_tabs);
m_tabs->addTab(m_outputPanel, QStringLiteral("Output"));
m_diagnosticsPanel = new DiagnosticsPanel(m_tabs);
m_tabs->addTab(m_diagnosticsPanel, QStringLiteral("Problems"));
connect(m_outputPanel, &OutputPanel::stopRequested, &m_codeRunner, &CodeRunner::cancel);
connect(&m_codeRunner, &CodeRunner::runStarted, this, [this](const QString& summary) {
m_outputPanel->clear();
m_outputPanel->appendRunHeader(summary);
showOutputTab();
});
connect(&m_codeRunner, &CodeRunner::outputLine, m_outputPanel, &OutputPanel::appendChannel);
connect(&m_codeRunner, &CodeRunner::runFinished, m_outputPanel, &OutputPanel::showExitCode);
connect(&m_codeRunner, &CodeRunner::runFailed, m_outputPanel, &OutputPanel::appendLine);
connect(&m_codeRunner, &CodeRunner::runningChanged, m_outputPanel,
&OutputPanel::setStopEnabled);
#if defined(COLD_HAS_TERMINAL)
connect(m_tabs, &QTabWidget::currentChanged, this, [this](int index) {
if (m_terminal && m_tabs->widget(index) == m_terminal) {
m_terminal->refreshDisplay();
}
});
if (!isOffscreenPlatform()) {
QTimer::singleShot(0, this, [this]() { restartTerminal(QDir::homePath()); });
}
#endif
}
OutputPanel* PanelRegion::outputPanel() const {
return m_outputPanel;
}
DiagnosticsPanel* PanelRegion::diagnosticsPanel() const {
return m_diagnosticsPanel;
}
#if defined(COLD_HAS_TERMINAL)
VtermTerminalWidget* PanelRegion::terminalWidget() const {
return m_terminal;
}
#endif
void PanelRegion::setProjectRoot(const QString& root) {
m_projectRoot = root;
}
void PanelRegion::showTerminalTab() {
#if defined(COLD_HAS_TERMINAL)
m_tabs->setCurrentWidget(m_terminal);
#else
m_tabs->setCurrentWidget(m_terminalPlaceholder);
#endif
}
void PanelRegion::showOutputTab() {
m_tabs->setCurrentWidget(m_outputPanel);
}
void PanelRegion::showProblemsTab() {
m_tabs->setCurrentWidget(m_diagnosticsPanel);
}
PanelPosition PanelRegion::panelPosition() const {
return m_position;
}
void PanelRegion::setPanelPosition(PanelPosition position) {
m_position = position;
}
void PanelRegion::onProjectOpened(const QString& rootPath) {
setProjectRoot(rootPath);
#if defined(COLD_HAS_TERMINAL)
restartTerminal(rootPath);
#endif
}
void PanelRegion::onProjectClosed() {
setProjectRoot({});
#if defined(COLD_HAS_TERMINAL)
if (m_terminal) {
m_terminal->stopSession();
}
#endif
}
void PanelRegion::restartTerminal(const QString& cwd) {
#if defined(COLD_HAS_TERMINAL)
if (isOffscreenPlatform() || !m_terminal) {
return;
}
m_terminal->stopSession();
m_terminal->startSession(cwd);
#else
Q_UNUSED(cwd);
#endif
}
} // namespace cold