forked from qt-creator/qt-creator
Terminal: Use new settings creation pattern
Does not delay much yet, as settings() is accessed in Plugin::extensionInitialized() Task-number: QTCREATORBUG-29167 Change-Id: I8f7c7fbef78c4ce0f92302e57a81f6216456c27b Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -72,13 +72,13 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
});
|
});
|
||||||
|
|
||||||
const auto updateEscButton = [this] {
|
const auto updateEscButton = [this] {
|
||||||
m_escSettingButton->setChecked(TerminalSettings::instance().sendEscapeToTerminal());
|
m_escSettingButton->setChecked(settings().sendEscapeToTerminal());
|
||||||
static const QString escKey
|
static const QString escKey
|
||||||
= QKeySequence(Qt::Key_Escape).toString(QKeySequence::NativeText);
|
= QKeySequence(Qt::Key_Escape).toString(QKeySequence::NativeText);
|
||||||
static const QString shiftEsc = QKeySequence(
|
static const QString shiftEsc = QKeySequence(
|
||||||
QKeyCombination(Qt::ShiftModifier, Qt::Key_Escape))
|
QKeyCombination(Qt::ShiftModifier, Qt::Key_Escape))
|
||||||
.toString(QKeySequence::NativeText);
|
.toString(QKeySequence::NativeText);
|
||||||
if (TerminalSettings::instance().sendEscapeToTerminal.value()) {
|
if (settings().sendEscapeToTerminal.value()) {
|
||||||
m_escSettingButton->setText(escKey);
|
m_escSettingButton->setText(escKey);
|
||||||
m_escSettingButton->setToolTip(Tr::tr("Sends Esc to terminal instead of Qt Creator."));
|
m_escSettingButton->setToolTip(Tr::tr("Sends Esc to terminal instead of Qt Creator."));
|
||||||
} else {
|
} else {
|
||||||
@@ -93,12 +93,12 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
updateEscButton();
|
updateEscButton();
|
||||||
|
|
||||||
connect(m_escSettingButton, &QToolButton::toggled, this, [this, updateEscButton] {
|
connect(m_escSettingButton, &QToolButton::toggled, this, [this, updateEscButton] {
|
||||||
TerminalSettings::instance().sendEscapeToTerminal.setValue(m_escSettingButton->isChecked());
|
settings().sendEscapeToTerminal.setValue(m_escSettingButton->isChecked());
|
||||||
TerminalSettings::instance().writeSettings();
|
settings().writeSettings();
|
||||||
updateEscButton();
|
updateEscButton();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&TerminalSettings::instance(), &TerminalSettings::applied, this, updateEscButton);
|
connect(&settings(), &TerminalSettings::applied, this, updateEscButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalPane::~TerminalPane() {}
|
TerminalPane::~TerminalPane() {}
|
||||||
@@ -142,7 +142,7 @@ void TerminalPane::openTerminal(const OpenTerminalParameters ¶meters)
|
|||||||
QFileIconProvider iconProvider;
|
QFileIconProvider iconProvider;
|
||||||
const FilePath command = parametersCopy.shellCommand
|
const FilePath command = parametersCopy.shellCommand
|
||||||
? parametersCopy.shellCommand->executable()
|
? parametersCopy.shellCommand->executable()
|
||||||
: TerminalSettings::instance().shell.filePath();
|
: settings().shell.filePath();
|
||||||
icon = iconProvider.icon(command.toFileInfo());
|
icon = iconProvider.icon(command.toFileInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,10 +250,10 @@ void TerminalPane::initActions()
|
|||||||
createShellMenu();
|
createShellMenu();
|
||||||
|
|
||||||
lockKeyboard.setCheckable(true);
|
lockKeyboard.setCheckable(true);
|
||||||
lockKeyboard.setChecked(TerminalSettings::instance().lockKeyboard());
|
lockKeyboard.setChecked(settings().lockKeyboard());
|
||||||
|
|
||||||
auto updateLockKeyboard = [this](bool locked) {
|
auto updateLockKeyboard = [this](bool locked) {
|
||||||
TerminalSettings::instance().lockKeyboard.setValue(locked);
|
settings().lockKeyboard.setValue(locked);
|
||||||
if (locked) {
|
if (locked) {
|
||||||
lockKeyboard.setIcon(LOCK_KEYBOARD_ICON.icon());
|
lockKeyboard.setIcon(LOCK_KEYBOARD_ICON.icon());
|
||||||
lockKeyboard.setToolTip(Tr::tr("Sends keyboard shortcuts to Terminal."));
|
lockKeyboard.setToolTip(Tr::tr("Sends keyboard shortcuts to Terminal."));
|
||||||
@@ -263,7 +263,7 @@ void TerminalPane::initActions()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
updateLockKeyboard(TerminalSettings::instance().lockKeyboard());
|
updateLockKeyboard(settings().lockKeyboard());
|
||||||
connect(&lockKeyboard, &QAction::toggled, this, updateLockKeyboard);
|
connect(&lockKeyboard, &QAction::toggled, this, updateLockKeyboard);
|
||||||
|
|
||||||
newTerminal.setText(Tr::tr("New Terminal"));
|
newTerminal.setText(Tr::tr("New Terminal"));
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public:
|
|||||||
m_terminalPane = nullptr;
|
m_terminalPane = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize() final { addManaged<TerminalSettings>(); }
|
|
||||||
|
|
||||||
void extensionsInitialized() final
|
void extensionsInitialized() final
|
||||||
{
|
{
|
||||||
m_terminalPane = new TerminalPane;
|
m_terminalPane = new TerminalPane;
|
||||||
@@ -61,8 +59,8 @@ public:
|
|||||||
|
|
||||||
static bool isEnabled = false;
|
static bool isEnabled = false;
|
||||||
auto settingsChanged = [enable, disable] {
|
auto settingsChanged = [enable, disable] {
|
||||||
if (isEnabled != TerminalSettings::instance().enableTerminal()) {
|
if (isEnabled != settings().enableTerminal()) {
|
||||||
isEnabled = TerminalSettings::instance().enableTerminal();
|
isEnabled = settings().enableTerminal();
|
||||||
if (isEnabled)
|
if (isEnabled)
|
||||||
enable();
|
enable();
|
||||||
else
|
else
|
||||||
@@ -70,7 +68,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QObject::connect(&TerminalSettings::instance(),
|
QObject::connect(&settings(),
|
||||||
&Utils::AspectContainer::applied,
|
&Utils::AspectContainer::applied,
|
||||||
this,
|
this,
|
||||||
settingsChanged);
|
settingsChanged);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "terminaltr.h"
|
#include "terminaltr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <utils/dropsupport.h>
|
#include <utils/dropsupport.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
@@ -90,13 +91,13 @@ static expected_str<void> loadXdefaults(const FilePath &path)
|
|||||||
const QString colorName = match.captured(1);
|
const QString colorName = match.captured(1);
|
||||||
const QColor color(match.captured(2));
|
const QColor color(match.captured(2));
|
||||||
if (colorName == "foreground") {
|
if (colorName == "foreground") {
|
||||||
TerminalSettings::instance().foregroundColor.setVolatileValue(color);
|
settings().foregroundColor.setVolatileValue(color);
|
||||||
} else if (colorName == "background") {
|
} else if (colorName == "background") {
|
||||||
TerminalSettings::instance().backgroundColor.setVolatileValue(color);
|
settings().backgroundColor.setVolatileValue(color);
|
||||||
} else {
|
} else {
|
||||||
const int colorIndex = colorName.mid(5).toInt();
|
const int colorIndex = colorName.mid(5).toInt();
|
||||||
if (colorIndex >= 0 && colorIndex < 16)
|
if (colorIndex >= 0 && colorIndex < 16)
|
||||||
TerminalSettings::instance().colors[colorIndex].setVolatileValue(color);
|
settings().colors[colorIndex].setVolatileValue(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,14 +153,14 @@ static expected_str<void> loadItermColors(const FilePath &path)
|
|||||||
const auto c = colorName.mid(5, 2);
|
const auto c = colorName.mid(5, 2);
|
||||||
const int colorIndex = c.toInt();
|
const int colorIndex = c.toInt();
|
||||||
if (colorIndex >= 0 && colorIndex < 16)
|
if (colorIndex >= 0 && colorIndex < 16)
|
||||||
TerminalSettings::instance().colors[colorIndex].setVolatileValue(
|
settings().colors[colorIndex].setVolatileValue(
|
||||||
color);
|
color);
|
||||||
} else if (colorName == "Foreground Color") {
|
} else if (colorName == "Foreground Color") {
|
||||||
TerminalSettings::instance().foregroundColor.setVolatileValue(color);
|
settings().foregroundColor.setVolatileValue(color);
|
||||||
} else if (colorName == "Background Color") {
|
} else if (colorName == "Background Color") {
|
||||||
TerminalSettings::instance().backgroundColor.setVolatileValue(color);
|
settings().backgroundColor.setVolatileValue(color);
|
||||||
} else if (colorName == "Selection Color") {
|
} else if (colorName == "Selection Color") {
|
||||||
TerminalSettings::instance().selectionColor.setVolatileValue(color);
|
settings().selectionColor.setVolatileValue(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,33 +197,33 @@ static expected_str<void> loadVsCodeColors(const FilePath &path)
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
const QList<QPair<QStringView, ColorAspect *>> colorKeys = {
|
const QList<QPair<QStringView, ColorAspect *>> colorKeys = {
|
||||||
qMakePair(u"editor.background", &TerminalSettings::instance().backgroundColor),
|
qMakePair(u"editor.background", &settings().backgroundColor),
|
||||||
qMakePair(u"terminal.foreground", &TerminalSettings::instance().foregroundColor),
|
qMakePair(u"terminal.foreground", &settings().foregroundColor),
|
||||||
qMakePair(u"terminal.selectionBackground", &TerminalSettings::instance().selectionColor),
|
qMakePair(u"terminal.selectionBackground", &settings().selectionColor),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiBlack", &TerminalSettings::instance().colors[0]),
|
qMakePair(u"terminal.ansiBlack", &settings().colors[0]),
|
||||||
qMakePair(u"terminal.ansiBrightBlack", &TerminalSettings::instance().colors[8]),
|
qMakePair(u"terminal.ansiBrightBlack", &settings().colors[8]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiRed", &TerminalSettings::instance().colors[1]),
|
qMakePair(u"terminal.ansiRed", &settings().colors[1]),
|
||||||
qMakePair(u"terminal.ansiBrightRed", &TerminalSettings::instance().colors[9]),
|
qMakePair(u"terminal.ansiBrightRed", &settings().colors[9]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiGreen", &TerminalSettings::instance().colors[2]),
|
qMakePair(u"terminal.ansiGreen", &settings().colors[2]),
|
||||||
qMakePair(u"terminal.ansiBrightGreen", &TerminalSettings::instance().colors[10]),
|
qMakePair(u"terminal.ansiBrightGreen", &settings().colors[10]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiYellow", &TerminalSettings::instance().colors[3]),
|
qMakePair(u"terminal.ansiYellow", &settings().colors[3]),
|
||||||
qMakePair(u"terminal.ansiBrightYellow", &TerminalSettings::instance().colors[11]),
|
qMakePair(u"terminal.ansiBrightYellow", &settings().colors[11]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiBlue", &TerminalSettings::instance().colors[4]),
|
qMakePair(u"terminal.ansiBlue", &settings().colors[4]),
|
||||||
qMakePair(u"terminal.ansiBrightBlue", &TerminalSettings::instance().colors[12]),
|
qMakePair(u"terminal.ansiBrightBlue", &settings().colors[12]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiMagenta", &TerminalSettings::instance().colors[5]),
|
qMakePair(u"terminal.ansiMagenta", &settings().colors[5]),
|
||||||
qMakePair(u"terminal.ansiBrightMagenta", &TerminalSettings::instance().colors[13]),
|
qMakePair(u"terminal.ansiBrightMagenta", &settings().colors[13]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiCyan", &TerminalSettings::instance().colors[6]),
|
qMakePair(u"terminal.ansiCyan", &settings().colors[6]),
|
||||||
qMakePair(u"terminal.ansiBrightCyan", &TerminalSettings::instance().colors[14]),
|
qMakePair(u"terminal.ansiBrightCyan", &settings().colors[14]),
|
||||||
|
|
||||||
qMakePair(u"terminal.ansiWhite", &TerminalSettings::instance().colors[7]),
|
qMakePair(u"terminal.ansiWhite", &settings().colors[7]),
|
||||||
qMakePair(u"terminal.ansiBrightWhite", &TerminalSettings::instance().colors[15])
|
qMakePair(u"terminal.ansiBrightWhite", &settings().colors[15])
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
@@ -247,8 +248,6 @@ static expected_str<void> loadVsCodeColors(const FilePath &path)
|
|||||||
|
|
||||||
static expected_str<void> loadKonsoleColorScheme(const FilePath &path)
|
static expected_str<void> loadKonsoleColorScheme(const FilePath &path)
|
||||||
{
|
{
|
||||||
QSettings settings(path.toFSPathString(), QSettings::IniFormat);
|
|
||||||
|
|
||||||
auto parseColor = [](const QStringList &parts) -> expected_str<QColor> {
|
auto parseColor = [](const QStringList &parts) -> expected_str<QColor> {
|
||||||
if (parts.size() != 3 && parts.size() != 4)
|
if (parts.size() != 3 && parts.size() != 4)
|
||||||
return make_unexpected(Tr::tr("Invalid color format."));
|
return make_unexpected(Tr::tr("Invalid color format."));
|
||||||
@@ -257,39 +256,41 @@ static expected_str<void> loadKonsoleColorScheme(const FilePath &path)
|
|||||||
};
|
};
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
const QList<QPair<QString, ColorAspect *>> colorKeys = {
|
TerminalSettings &s = settings();
|
||||||
qMakePair(QLatin1String("Background/Color"), &TerminalSettings::instance().backgroundColor),
|
const QPair<QString, ColorAspect *> colorKeys[] = {
|
||||||
qMakePair(QLatin1String("Foreground/Color"), &TerminalSettings::instance().foregroundColor),
|
{ "Background/Color", &s.backgroundColor },
|
||||||
|
{ "Foreground/Color", &s.foregroundColor},
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color0/Color"), &TerminalSettings::instance().colors[0]),
|
{ "Color0/Color", &s.colors[0] },
|
||||||
qMakePair(QLatin1String("Color0Intense/Color"), &TerminalSettings::instance().colors[8]),
|
{ "Color0Intense/Color", &s.colors[8] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color1/Color"), &TerminalSettings::instance().colors[1]),
|
{ "Color1/Color", &s.colors[1] },
|
||||||
qMakePair(QLatin1String("Color1Intense/Color"), &TerminalSettings::instance().colors[9]),
|
{ "Color1Intense/Color", &s.colors[9] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color2/Color"), &TerminalSettings::instance().colors[2]),
|
{ "Color2/Color", &s.colors[2] },
|
||||||
qMakePair(QLatin1String("Color2Intense/Color"), &TerminalSettings::instance().colors[10]),
|
{ "Color2Intense/Color", &s.colors[10] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color3/Color"), &TerminalSettings::instance().colors[3]),
|
{ "Color3/Color", &s.colors[3] },
|
||||||
qMakePair(QLatin1String("Color3Intense/Color"), &TerminalSettings::instance().colors[11]),
|
{ "Color3Intense/Color", &s.colors[11] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color4/Color"), &TerminalSettings::instance().colors[4]),
|
{ "Color4/Color", &s.colors[4] },
|
||||||
qMakePair(QLatin1String("Color4Intense/Color"), &TerminalSettings::instance().colors[12]),
|
{ "Color4Intense/Color", &s.colors[12] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color5/Color"), &TerminalSettings::instance().colors[5]),
|
{ "Color5/Color", &s.colors[5] },
|
||||||
qMakePair(QLatin1String("Color5Intense/Color"), &TerminalSettings::instance().colors[13]),
|
{ "Color5Intense/Color", &s.colors[13] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color6/Color"), &TerminalSettings::instance().colors[6]),
|
{ "Color6/Color", &s.colors[6] },
|
||||||
qMakePair(QLatin1String("Color6Intense/Color"), &TerminalSettings::instance().colors[14]),
|
{ "Color6Intense/Color", &s.colors[14] },
|
||||||
|
|
||||||
qMakePair(QLatin1String("Color7/Color"), &TerminalSettings::instance().colors[7]),
|
{ "Color7/Color", &s.colors[7] },
|
||||||
qMakePair(QLatin1String("Color7Intense/Color"), &TerminalSettings::instance().colors[15])
|
{ "Color7Intense/Color", &s.colors[15] }
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
QSettings ini(path.toFSPathString(), QSettings::IniFormat);
|
||||||
for (const auto &colorKey : colorKeys) {
|
for (const auto &colorKey : colorKeys) {
|
||||||
if (settings.contains(colorKey.first)) {
|
if (ini.contains(colorKey.first)) {
|
||||||
const auto color = parseColor(settings.value(colorKey.first).toStringList());
|
const auto color = parseColor(ini.value(colorKey.first).toStringList());
|
||||||
if (!color)
|
if (!color)
|
||||||
return make_unexpected(color.error());
|
return make_unexpected(color.error());
|
||||||
|
|
||||||
@@ -313,26 +314,25 @@ static expected_str<void> loadXFCE4ColorScheme(const FilePath &path)
|
|||||||
f.write(*arr);
|
f.write(*arr);
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
QSettings settings(f.fileName(), QSettings::IniFormat);
|
QSettings ini(f.fileName(), QSettings::IniFormat);
|
||||||
|
TerminalSettings &s = settings();
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
const QList<QPair<QString, ColorAspect *>> colorKeys = {
|
const QPair<QString, ColorAspect *> colorKeys[] = {
|
||||||
qMakePair(QLatin1String("Scheme/ColorBackground"), &TerminalSettings::instance().backgroundColor),
|
{ "Scheme/ColorBackground", &s.backgroundColor },
|
||||||
qMakePair(QLatin1String("Scheme/ColorForeground"), &TerminalSettings::instance().foregroundColor),
|
{ "Scheme/ColorForeground", &s.foregroundColor }
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
for (const auto &colorKey : colorKeys) {
|
for (const auto &colorKey : colorKeys) {
|
||||||
if (settings.contains(colorKey.first)) {
|
if (ini.contains(colorKey.first))
|
||||||
colorKey.second->setVolatileValue(QColor(settings.value(colorKey.first).toString()));
|
colorKey.second->setVolatileValue(QColor(ini.value(colorKey.first).toString()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList colors = settings.value(QLatin1String("Scheme/ColorPalette")).toStringList();
|
QStringList colors = ini.value(QLatin1String("Scheme/ColorPalette")).toStringList();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const auto &color : colors) {
|
for (const QString &color : colors)
|
||||||
TerminalSettings::instance().colors[i++].setVolatileValue(QColor(color));
|
s.colors[i++].setVolatileValue(QColor(color));
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -353,23 +353,15 @@ static expected_str<void> loadColorScheme(const FilePath &path)
|
|||||||
return make_unexpected(Tr::tr("Unknown color scheme format."));
|
return make_unexpected(Tr::tr("Unknown color scheme format."));
|
||||||
}
|
}
|
||||||
|
|
||||||
static TerminalSettings *s_instance;
|
TerminalSettings &settings()
|
||||||
|
|
||||||
TerminalSettings &TerminalSettings::instance()
|
|
||||||
{
|
{
|
||||||
return *s_instance;
|
static TerminalSettings theSettings;
|
||||||
|
return theSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalSettings::TerminalSettings()
|
TerminalSettings::TerminalSettings()
|
||||||
{
|
{
|
||||||
s_instance = this;
|
|
||||||
|
|
||||||
setSettingsGroup("Terminal");
|
setSettingsGroup("Terminal");
|
||||||
setId("Terminal.General");
|
|
||||||
setDisplayName("Terminal");
|
|
||||||
setCategory("ZY.Terminal");
|
|
||||||
setDisplayCategory("Terminal");
|
|
||||||
setCategoryIconPath(":/terminal/images/settingscategory_terminal.png");
|
|
||||||
|
|
||||||
enableTerminal.setSettingsKey("EnableTerminal");
|
enableTerminal.setSettingsKey("EnableTerminal");
|
||||||
enableTerminal.setLabelText(Tr::tr("Use internal terminal"));
|
enableTerminal.setLabelText(Tr::tr("Use internal terminal"));
|
||||||
@@ -587,4 +579,20 @@ TerminalSettings::TerminalSettings()
|
|||||||
readSettings();
|
readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TerminalSettingsPage final : public Core::IOptionsPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TerminalSettingsPage()
|
||||||
|
{
|
||||||
|
setId("Terminal.General");
|
||||||
|
setDisplayName("Terminal");
|
||||||
|
setCategory("ZY.Terminal");
|
||||||
|
setDisplayCategory("Terminal");
|
||||||
|
setCategoryIconPath(":/terminal/images/settingscategory_terminal.png");
|
||||||
|
setSettingsProvider([] { return &settings(); });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const TerminalSettingsPage settingsPage;
|
||||||
|
|
||||||
} // Terminal
|
} // Terminal
|
||||||
|
|||||||
@@ -3,17 +3,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <utils/aspects.h>
|
||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
|
|
||||||
class TerminalSettings : public Core::PagedSettings
|
class TerminalSettings : public Utils::AspectContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TerminalSettings();
|
TerminalSettings();
|
||||||
|
|
||||||
static TerminalSettings &instance();
|
|
||||||
|
|
||||||
Utils::BoolAspect enableTerminal{this};
|
Utils::BoolAspect enableTerminal{this};
|
||||||
|
|
||||||
Utils::StringAspect font{this};
|
Utils::StringAspect font{this};
|
||||||
@@ -35,4 +33,6 @@ public:
|
|||||||
Utils::BoolAspect lockKeyboard{this};
|
Utils::BoolAspect lockKeyboard{this};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TerminalSettings &settings();
|
||||||
|
|
||||||
} // Terminal
|
} // Terminal
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ TerminalWidget::TerminalWidget(QWidget *parent, const OpenTerminalParameters &op
|
|||||||
verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
|
verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&TerminalSettings::instance(), &AspectContainer::applied, this, [this] {
|
connect(&settings(), &AspectContainer::applied, this, [this] {
|
||||||
// Setup colors first, as setupFont will redraw the screen.
|
// Setup colors first, as setupFont will redraw the screen.
|
||||||
setupColors();
|
setupColors();
|
||||||
setupFont();
|
setupFont();
|
||||||
@@ -143,8 +143,8 @@ void TerminalWidget::setupPty()
|
|||||||
m_process = std::make_unique<Process>();
|
m_process = std::make_unique<Process>();
|
||||||
|
|
||||||
CommandLine shellCommand = m_openParameters.shellCommand.value_or(
|
CommandLine shellCommand = m_openParameters.shellCommand.value_or(
|
||||||
CommandLine{TerminalSettings::instance().shell(),
|
CommandLine{settings().shell(),
|
||||||
TerminalSettings::instance().shellArguments.value(),
|
settings().shellArguments.value(),
|
||||||
CommandLine::Raw});
|
CommandLine::Raw});
|
||||||
|
|
||||||
Environment env = m_openParameters.environment.value_or(Environment{})
|
Environment env = m_openParameters.environment.value_or(Environment{})
|
||||||
@@ -230,8 +230,8 @@ void TerminalWidget::setupFont()
|
|||||||
{
|
{
|
||||||
QFont f;
|
QFont f;
|
||||||
f.setFixedPitch(true);
|
f.setFixedPitch(true);
|
||||||
f.setFamily(TerminalSettings::instance().font.value());
|
f.setFamily(settings().font.value());
|
||||||
f.setPointSize(TerminalSettings::instance().fontSize.value());
|
f.setPointSize(settings().fontSize.value());
|
||||||
|
|
||||||
setFont(f);
|
setFont(f);
|
||||||
}
|
}
|
||||||
@@ -241,12 +241,12 @@ void TerminalWidget::setupColors()
|
|||||||
// Check if the colors have changed.
|
// Check if the colors have changed.
|
||||||
std::array<QColor, 20> newColors;
|
std::array<QColor, 20> newColors;
|
||||||
for (int i = 0; i < 16; ++i) {
|
for (int i = 0; i < 16; ++i) {
|
||||||
newColors[i] = TerminalSettings::instance().colors[i].value();
|
newColors[i] = settings().colors[i].value();
|
||||||
}
|
}
|
||||||
newColors[ColorIndex::Background] = TerminalSettings::instance().backgroundColor.value();
|
newColors[ColorIndex::Background] = settings().backgroundColor.value();
|
||||||
newColors[ColorIndex::Foreground] = TerminalSettings::instance().foregroundColor.value();
|
newColors[ColorIndex::Foreground] = settings().foregroundColor.value();
|
||||||
newColors[ColorIndex::Selection] = TerminalSettings::instance().selectionColor.value();
|
newColors[ColorIndex::Selection] = settings().selectionColor.value();
|
||||||
newColors[ColorIndex::FindMatch] = TerminalSettings::instance().findMatchColor.value();
|
newColors[ColorIndex::FindMatch] = settings().findMatchColor.value();
|
||||||
|
|
||||||
if (m_currentColors == newColors)
|
if (m_currentColors == newColors)
|
||||||
return;
|
return;
|
||||||
@@ -401,7 +401,7 @@ void TerminalWidget::setupSurface()
|
|||||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||||
});
|
});
|
||||||
connect(m_surface.get(), &Internal::TerminalSurface::bell, this, [] {
|
connect(m_surface.get(), &Internal::TerminalSurface::bell, this, [] {
|
||||||
if (TerminalSettings::instance().audibleBell.value())
|
if (settings().audibleBell.value())
|
||||||
QApplication::beep();
|
QApplication::beep();
|
||||||
});
|
});
|
||||||
connect(m_surface.get(),
|
connect(m_surface.get(),
|
||||||
@@ -438,7 +438,7 @@ void TerminalWidget::setupSurface()
|
|||||||
void TerminalWidget::configBlinkTimer()
|
void TerminalWidget::configBlinkTimer()
|
||||||
{
|
{
|
||||||
bool shouldRun = m_cursor.visible && m_cursor.blink && hasFocus()
|
bool shouldRun = m_cursor.visible && m_cursor.blink && hasFocus()
|
||||||
&& TerminalSettings::instance().allowBlinkingCursor.value();
|
&& settings().allowBlinkingCursor.value();
|
||||||
if (shouldRun != m_cursorBlinkTimer.isActive()) {
|
if (shouldRun != m_cursorBlinkTimer.isActive()) {
|
||||||
if (shouldRun)
|
if (shouldRun)
|
||||||
m_cursorBlinkTimer.start();
|
m_cursorBlinkTimer.start();
|
||||||
@@ -1006,7 +1006,7 @@ void TerminalWidget::paintCursor(QPainter &p) const
|
|||||||
cursor.shape = Internal::Cursor::Shape::Underline;
|
cursor.shape = Internal::Cursor::Shape::Underline;
|
||||||
|
|
||||||
const bool blinkState = !cursor.blink || m_cursorBlinkState
|
const bool blinkState = !cursor.blink || m_cursorBlinkState
|
||||||
|| !TerminalSettings::instance().allowBlinkingCursor.value();
|
|| !settings().allowBlinkingCursor.value();
|
||||||
|
|
||||||
if (cursor.visible && blinkState) {
|
if (cursor.visible && blinkState) {
|
||||||
const int cursorCellWidth = m_surface->cellWidthAt(cursor.position.x(), cursor.position.y());
|
const int cursorCellWidth = m_surface->cellWidthAt(cursor.position.x(), cursor.position.y());
|
||||||
@@ -1162,7 +1162,7 @@ void TerminalWidget::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event->key() == Qt::Key_Escape) {
|
if (event->key() == Qt::Key_Escape) {
|
||||||
bool sendToTerminal = TerminalSettings::instance().sendEscapeToTerminal.value();
|
bool sendToTerminal = settings().sendEscapeToTerminal.value();
|
||||||
bool send = false;
|
bool send = false;
|
||||||
if (sendToTerminal && event->modifiers() == Qt::NoModifier)
|
if (sendToTerminal && event->modifiers() == Qt::NoModifier)
|
||||||
send = true;
|
send = true;
|
||||||
@@ -1570,7 +1570,7 @@ void TerminalWidget::showEvent(QShowEvent *event)
|
|||||||
|
|
||||||
bool TerminalWidget::event(QEvent *event)
|
bool TerminalWidget::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (TerminalSettings::instance().lockKeyboard() && event->type() == QEvent::ShortcutOverride) {
|
if (settings().lockKeyboard() && event->type() == QEvent::ShortcutOverride) {
|
||||||
event->accept();
|
event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1584,7 +1584,7 @@ bool TerminalWidget::event(QEvent *event)
|
|||||||
if (event->type() == QEvent::KeyPress) {
|
if (event->type() == QEvent::KeyPress) {
|
||||||
auto k = static_cast<QKeyEvent *>(event);
|
auto k = static_cast<QKeyEvent *>(event);
|
||||||
|
|
||||||
if (TerminalSettings::instance().lockKeyboard() && m_shortcutMap.tryShortcut(k))
|
if (settings().lockKeyboard() && m_shortcutMap.tryShortcut(k))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
keyPressEvent(k);
|
keyPressEvent(k);
|
||||||
|
|||||||
Reference in New Issue
Block a user