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,13 +308,14 @@ 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(widget);
|
QFontComboBox *fontComboBox = new QFontComboBox(this);
|
||||||
fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts);
|
fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts);
|
||||||
fontComboBox->setCurrentFont(TerminalSettings::instance().font.value());
|
fontComboBox->setCurrentFont(TerminalSettings::instance().font.value());
|
||||||
|
|
||||||
@@ -339,9 +328,9 @@ QWidget *TerminalSettingsPage::widget()
|
|||||||
QPushButton *loadThemeButton = new QPushButton(Tr::tr("Load Theme..."));
|
QPushButton *loadThemeButton = new QPushButton(Tr::tr("Load Theme..."));
|
||||||
QPushButton *resetTheme = new QPushButton(Tr::tr("Reset Theme to default"));
|
QPushButton *resetTheme = new QPushButton(Tr::tr("Reset Theme to default"));
|
||||||
|
|
||||||
connect(loadThemeButton, &QPushButton::clicked, this, [widget] {
|
connect(loadThemeButton, &QPushButton::clicked, this, [this] {
|
||||||
const FilePath path = FileUtils::getOpenFilePath(
|
const FilePath path = FileUtils::getOpenFilePath(
|
||||||
widget,
|
this,
|
||||||
"Open Theme",
|
"Open Theme",
|
||||||
{},
|
{},
|
||||||
"All Scheme formats (*.itermcolors *.json *.colorscheme *.theme *.theme.txt);;"
|
"All Scheme formats (*.itermcolors *.json *.colorscheme *.theme *.theme.txt);;"
|
||||||
@@ -361,7 +350,7 @@ QWidget *TerminalSettingsPage::widget()
|
|||||||
|
|
||||||
const expected_str<void> result = loadColorScheme(path);
|
const expected_str<void> result = loadColorScheme(path);
|
||||||
if (!result)
|
if (!result)
|
||||||
QMessageBox::warning(widget, Tr::tr("Error"), result.error());
|
QMessageBox::warning(this, Tr::tr("Error"), result.error());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(resetTheme, &QPushButton::clicked, this, [] {
|
connect(resetTheme, &QPushButton::clicked, this, [] {
|
||||||
@@ -428,23 +417,37 @@ QWidget *TerminalSettingsPage::widget()
|
|||||||
settings.shellArguments,
|
settings.shellArguments,
|
||||||
},
|
},
|
||||||
st,
|
st,
|
||||||
}.attachTo(widget);
|
}.attachTo(this);
|
||||||
// clang-format on
|
// 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