forked from qt-creator/qt-creator
Terminal: Use IOptionPage::setWidgetCreator() for settings
Less boilerplate for the implementation add user code access to IOptionPage::{apply,finish} is planned to be removed. Change-Id: Id8ec4006d1060be2032caf8eda6bf80760f6db22 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -44,7 +44,7 @@ bool TerminalPlugin::delayedInitialize()
|
|||||||
|
|
||||||
void TerminalPlugin::extensionsInitialized()
|
void TerminalPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
TerminalSettingsPage::instance().init();
|
(void) TerminalSettingsPage::instance();
|
||||||
TerminalSettings::instance().readSettings(Core::ICore::settings());
|
TerminalSettings::instance().readSettings(Core::ICore::settings());
|
||||||
|
|
||||||
m_terminalPane = new TerminalPane();
|
m_terminalPane = new TerminalPane();
|
||||||
|
@@ -28,18 +28,6 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
|
|
||||||
TerminalSettingsPage::TerminalSettingsPage()
|
|
||||||
{
|
|
||||||
setId("Terminal.General");
|
|
||||||
setDisplayName("Terminal");
|
|
||||||
setCategory("ZY.Terminal");
|
|
||||||
setDisplayCategory("Terminal");
|
|
||||||
setSettings(&TerminalSettings::instance());
|
|
||||||
setCategoryIconPath(":/terminal/images/settingscategory_terminal.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalSettingsPage::init() {}
|
|
||||||
|
|
||||||
static expected_str<void> loadXdefaults(const FilePath &path)
|
static expected_str<void> loadXdefaults(const FilePath &path)
|
||||||
{
|
{
|
||||||
const expected_str<QByteArray> readResult = path.fileContents();
|
const expected_str<QByteArray> readResult = path.fileContents();
|
||||||
@@ -320,131 +308,146 @@ 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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *TerminalSettingsPage::widget()
|
class TerminalSettingsPageWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
QWidget *widget = new QWidget;
|
public:
|
||||||
|
TerminalSettingsPageWidget()
|
||||||
|
{
|
||||||
|
using namespace Layouting;
|
||||||
|
|
||||||
using namespace Layouting;
|
QFontComboBox *fontComboBox = new QFontComboBox(this);
|
||||||
|
fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts);
|
||||||
|
fontComboBox->setCurrentFont(TerminalSettings::instance().font.value());
|
||||||
|
|
||||||
QFontComboBox *fontComboBox = new QFontComboBox(widget);
|
connect(fontComboBox, &QFontComboBox::currentFontChanged, this, [](const QFont &f) {
|
||||||
fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts);
|
TerminalSettings::instance().font.setValue(f.family());
|
||||||
fontComboBox->setCurrentFont(TerminalSettings::instance().font.value());
|
});
|
||||||
|
|
||||||
connect(fontComboBox, &QFontComboBox::currentFontChanged, this, [](const QFont &f) {
|
|
||||||
TerminalSettings::instance().font.setValue(f.family());
|
|
||||||
});
|
|
||||||
|
|
||||||
TerminalSettings &settings = TerminalSettings::instance();
|
|
||||||
|
|
||||||
QPushButton *loadThemeButton = new QPushButton(Tr::tr("Load Theme..."));
|
|
||||||
QPushButton *resetTheme = new QPushButton(Tr::tr("Reset Theme to default"));
|
|
||||||
|
|
||||||
connect(loadThemeButton, &QPushButton::clicked, this, [widget] {
|
|
||||||
const FilePath path = FileUtils::getOpenFilePath(
|
|
||||||
widget,
|
|
||||||
"Open Theme",
|
|
||||||
{},
|
|
||||||
"All Scheme formats (*.itermcolors *.json *.colorscheme *.theme *.theme.txt);;"
|
|
||||||
"Xdefaults (.Xdefaults Xdefaults);;"
|
|
||||||
"iTerm Color Schemes(*.itermcolors);;"
|
|
||||||
"VS Code Color Schemes(*.json);;"
|
|
||||||
"Konsole Color Schemes(*.colorscheme);;"
|
|
||||||
"XFCE4 Terminal Color Schemes(*.theme *.theme.txt);;"
|
|
||||||
"All files (*)",
|
|
||||||
nullptr,
|
|
||||||
{},
|
|
||||||
true,
|
|
||||||
false);
|
|
||||||
|
|
||||||
if (path.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const expected_str<void> result = loadColorScheme(path);
|
|
||||||
if (!result)
|
|
||||||
QMessageBox::warning(widget, Tr::tr("Error"), result.error());
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(resetTheme, &QPushButton::clicked, this, [] {
|
|
||||||
TerminalSettings &settings = TerminalSettings::instance();
|
TerminalSettings &settings = TerminalSettings::instance();
|
||||||
settings.foregroundColor.setVolatileValue(settings.foregroundColor.defaultValue());
|
|
||||||
settings.backgroundColor.setVolatileValue(settings.backgroundColor.defaultValue());
|
|
||||||
settings.selectionColor.setVolatileValue(settings.selectionColor.defaultValue());
|
|
||||||
|
|
||||||
for (auto &color : settings.colors)
|
QPushButton *loadThemeButton = new QPushButton(Tr::tr("Load Theme..."));
|
||||||
color.setVolatileValue(color.defaultValue());
|
QPushButton *resetTheme = new QPushButton(Tr::tr("Reset Theme to default"));
|
||||||
});
|
|
||||||
|
|
||||||
// clang-format off
|
connect(loadThemeButton, &QPushButton::clicked, this, [this] {
|
||||||
Column {
|
const FilePath path = FileUtils::getOpenFilePath(
|
||||||
Group {
|
this,
|
||||||
title(Tr::tr("General")),
|
"Open Theme",
|
||||||
Column {
|
{},
|
||||||
settings.enableTerminal, st,
|
"All Scheme formats (*.itermcolors *.json *.colorscheme *.theme *.theme.txt);;"
|
||||||
settings.sendEscapeToTerminal, st,
|
"Xdefaults (.Xdefaults Xdefaults);;"
|
||||||
settings.audibleBell, st,
|
"iTerm Color Schemes(*.itermcolors);;"
|
||||||
},
|
"VS Code Color Schemes(*.json);;"
|
||||||
},
|
"Konsole Color Schemes(*.colorscheme);;"
|
||||||
Group {
|
"XFCE4 Terminal Color Schemes(*.theme *.theme.txt);;"
|
||||||
title(Tr::tr("Font")),
|
"All files (*)",
|
||||||
Row {
|
nullptr,
|
||||||
settings.font.labelText(), fontComboBox, Space(20),
|
{},
|
||||||
settings.fontSize, st,
|
true,
|
||||||
},
|
false);
|
||||||
},
|
|
||||||
Group {
|
if (path.isEmpty())
|
||||||
title(Tr::tr("Cursor")),
|
return;
|
||||||
Row {
|
|
||||||
settings.allowBlinkingCursor, st,
|
const expected_str<void> result = loadColorScheme(path);
|
||||||
},
|
if (!result)
|
||||||
},
|
QMessageBox::warning(this, Tr::tr("Error"), result.error());
|
||||||
Group {
|
});
|
||||||
title(Tr::tr("Colors")),
|
|
||||||
Column {
|
connect(resetTheme, &QPushButton::clicked, this, [] {
|
||||||
Row {
|
TerminalSettings &settings = TerminalSettings::instance();
|
||||||
Tr::tr("Foreground"), settings.foregroundColor, st,
|
settings.foregroundColor.setVolatileValue(settings.foregroundColor.defaultValue());
|
||||||
Tr::tr("Background"), settings.backgroundColor, st,
|
settings.backgroundColor.setVolatileValue(settings.backgroundColor.defaultValue());
|
||||||
Tr::tr("Selection"), settings.selectionColor, st,
|
settings.selectionColor.setVolatileValue(settings.selectionColor.defaultValue());
|
||||||
Tr::tr("Find match"), settings.findMatchColor, st,
|
|
||||||
},
|
for (auto &color : settings.colors)
|
||||||
Row {
|
color.setVolatileValue(color.defaultValue());
|
||||||
settings.colors[0], settings.colors[1],
|
});
|
||||||
settings.colors[2], settings.colors[3],
|
|
||||||
settings.colors[4], settings.colors[5],
|
// clang-format off
|
||||||
settings.colors[6], settings.colors[7]
|
|
||||||
},
|
|
||||||
Row {
|
|
||||||
settings.colors[8], settings.colors[9],
|
|
||||||
settings.colors[10], settings.colors[11],
|
|
||||||
settings.colors[12], settings.colors[13],
|
|
||||||
settings.colors[14], settings.colors[15]
|
|
||||||
},
|
|
||||||
Row {
|
|
||||||
loadThemeButton, resetTheme, st,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Column {
|
Column {
|
||||||
settings.shell,
|
Group {
|
||||||
settings.shellArguments,
|
title(Tr::tr("General")),
|
||||||
},
|
Column {
|
||||||
st,
|
settings.enableTerminal, st,
|
||||||
}.attachTo(widget);
|
settings.sendEscapeToTerminal, st,
|
||||||
// clang-format on
|
settings.audibleBell, st,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Group {
|
||||||
|
title(Tr::tr("Font")),
|
||||||
|
Row {
|
||||||
|
settings.font.labelText(), fontComboBox, Space(20),
|
||||||
|
settings.fontSize, st,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Group {
|
||||||
|
title(Tr::tr("Cursor")),
|
||||||
|
Row {
|
||||||
|
settings.allowBlinkingCursor, st,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Group {
|
||||||
|
title(Tr::tr("Colors")),
|
||||||
|
Column {
|
||||||
|
Row {
|
||||||
|
Tr::tr("Foreground"), settings.foregroundColor, st,
|
||||||
|
Tr::tr("Background"), settings.backgroundColor, st,
|
||||||
|
Tr::tr("Selection"), settings.selectionColor, st,
|
||||||
|
Tr::tr("Find match"), settings.findMatchColor, st,
|
||||||
|
},
|
||||||
|
Row {
|
||||||
|
settings.colors[0], settings.colors[1],
|
||||||
|
settings.colors[2], settings.colors[3],
|
||||||
|
settings.colors[4], settings.colors[5],
|
||||||
|
settings.colors[6], settings.colors[7]
|
||||||
|
},
|
||||||
|
Row {
|
||||||
|
settings.colors[8], settings.colors[9],
|
||||||
|
settings.colors[10], settings.colors[11],
|
||||||
|
settings.colors[12], settings.colors[13],
|
||||||
|
settings.colors[14], settings.colors[15]
|
||||||
|
},
|
||||||
|
Row {
|
||||||
|
loadThemeButton, resetTheme, st,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Column {
|
||||||
|
settings.shell,
|
||||||
|
settings.shellArguments,
|
||||||
|
},
|
||||||
|
st,
|
||||||
|
}.attachTo(this);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
DropSupport *dropSupport = new DropSupport(widget);
|
DropSupport *dropSupport = new DropSupport(this);
|
||||||
connect(dropSupport,
|
connect(dropSupport,
|
||||||
&DropSupport::filesDropped,
|
&DropSupport::filesDropped,
|
||||||
this,
|
this,
|
||||||
[widget](const QList<DropSupport::FileSpec> &files) {
|
[this](const QList<DropSupport::FileSpec> &files) {
|
||||||
if (files.size() != 1)
|
if (files.size() != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const expected_str<void> result = loadColorScheme(files.at(0).filePath);
|
const expected_str<void> result = loadColorScheme(files.at(0).filePath);
|
||||||
if (!result)
|
if (!result)
|
||||||
QMessageBox::warning(widget, Tr::tr("Error"), result.error());
|
QMessageBox::warning(this, Tr::tr("Error"), result.error());
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return widget;
|
void apply() final {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TerminalSettingsPage
|
||||||
|
|
||||||
|
TerminalSettingsPage::TerminalSettingsPage()
|
||||||
|
{
|
||||||
|
setId("Terminal.General");
|
||||||
|
setDisplayName("Terminal");
|
||||||
|
setCategory("ZY.Terminal");
|
||||||
|
setDisplayCategory("Terminal");
|
||||||
|
setSettings(&TerminalSettings::instance());
|
||||||
|
setCategoryIconPath(":/terminal/images/settingscategory_terminal.png");
|
||||||
|
setWidgetCreator([] { return new TerminalSettingsPageWidget; });
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalSettingsPage &TerminalSettingsPage::instance()
|
TerminalSettingsPage &TerminalSettingsPage::instance()
|
||||||
|
@@ -13,10 +13,6 @@ public:
|
|||||||
TerminalSettingsPage();
|
TerminalSettingsPage();
|
||||||
|
|
||||||
static TerminalSettingsPage &instance();
|
static TerminalSettingsPage &instance();
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Terminal
|
} // namespace Terminal
|
||||||
|
Reference in New Issue
Block a user