forked from qt-creator/qt-creator
FakeVim: More compact settings page implementation
Change-Id: Iaca48e8a22f26817442dbf5147f318868dbd1f34 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -340,33 +340,8 @@ private:
|
|||||||
using ExCommandMap = QMap<QString, QRegularExpression>;
|
using ExCommandMap = QMap<QString, QRegularExpression>;
|
||||||
using UserCommandMap = QMap<int, QString>;
|
using UserCommandMap = QMap<int, QString>;
|
||||||
|
|
||||||
class FakeVimOptionPage : public IOptionsPage
|
static void layoutPage(QWidget *widget)
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
FakeVimOptionPage()
|
|
||||||
{
|
|
||||||
setId(SETTINGS_ID);
|
|
||||||
setDisplayName(Tr::tr("General"));
|
|
||||||
setCategory(SETTINGS_CATEGORY);
|
|
||||||
setDisplayCategory(Tr::tr("FakeVim"));
|
|
||||||
setCategoryIconPath(":/fakevim/images/settingscategory_fakevim.png");
|
|
||||||
setLayouter([this](QWidget *widget) { return layoutPage(widget); });
|
|
||||||
setSettings(fakeVimSettings());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void layoutPage(QWidget *);
|
|
||||||
void copyTextEditorSettings();
|
|
||||||
void setQtStyle();
|
|
||||||
void setPlainStyle();
|
|
||||||
};
|
|
||||||
|
|
||||||
void FakeVimOptionPage::layoutPage(QWidget *widget)
|
|
||||||
{
|
|
||||||
auto copyTextEditorSettings = new QPushButton(Tr::tr("Copy Text Editor Settings"));
|
|
||||||
auto setQtStyle = new QPushButton(Tr::tr("Set Qt Style"));
|
|
||||||
auto setPlainStyle = new QPushButton(Tr::tr("Set Plain Style"));
|
|
||||||
|
|
||||||
using namespace Layouting;
|
using namespace Layouting;
|
||||||
FakeVimSettings &s = *fakeVimSettings();
|
FakeVimSettings &s = *fakeVimSettings();
|
||||||
|
|
||||||
@@ -426,63 +401,73 @@ void FakeVimOptionPage::layoutPage(QWidget *widget)
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Row { copyTextEditorSettings, setQtStyle, setPlainStyle, st },
|
Row {
|
||||||
|
PushButton {
|
||||||
|
text(Tr::tr("Copy Text Editor Settings")),
|
||||||
|
onClicked([&s] {
|
||||||
|
TabSettings ts = TextEditorSettings::codeStyle()->tabSettings();
|
||||||
|
TypingSettings tps = TextEditorSettings::typingSettings();
|
||||||
|
s.expandTab.setValue(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
|
||||||
|
s.tabStop.setValue(ts.m_tabSize);
|
||||||
|
s.shiftWidth.setValue(ts.m_indentSize);
|
||||||
|
s.smartTab.setValue(tps.m_smartBackspaceBehavior
|
||||||
|
== TypingSettings::BackspaceFollowsPreviousIndents);
|
||||||
|
s.autoIndent.setValue(true);
|
||||||
|
s.smartIndent.setValue(tps.m_autoIndent);
|
||||||
|
s.incSearch.setValue(true);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
PushButton {
|
||||||
|
text(Tr::tr("Set Qt Style")),
|
||||||
|
onClicked([&s] {
|
||||||
|
s.expandTab.setVolatileValue(true);
|
||||||
|
s.tabStop.setVolatileValue(4);
|
||||||
|
s.shiftWidth.setVolatileValue(4);
|
||||||
|
s.smartTab.setVolatileValue(true);
|
||||||
|
s.autoIndent.setVolatileValue(true);
|
||||||
|
s.smartIndent.setVolatileValue(true);
|
||||||
|
s.incSearch.setVolatileValue(true);
|
||||||
|
s.backspace.setVolatileValue(QString("indent,eol,start"));
|
||||||
|
s.passKeys.setVolatileValue(true);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
PushButton {
|
||||||
|
text(Tr::tr("Set Plain Style")),
|
||||||
|
onClicked([&s] {
|
||||||
|
s.expandTab.setVolatileValue(false);
|
||||||
|
s.tabStop.setVolatileValue(8);
|
||||||
|
s.shiftWidth.setVolatileValue(8);
|
||||||
|
s.smartTab.setVolatileValue(false);
|
||||||
|
s.autoIndent.setVolatileValue(false);
|
||||||
|
s.smartIndent.setVolatileValue(false);
|
||||||
|
s.incSearch.setVolatileValue(false);
|
||||||
|
s.backspace.setVolatileValue(QString());
|
||||||
|
s.passKeys.setVolatileValue(false);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
st
|
||||||
|
},
|
||||||
st
|
st
|
||||||
|
|
||||||
}.attachTo(widget);
|
}.attachTo(widget);
|
||||||
|
|
||||||
s.vimRcPath.setEnabler(&s.readVimRc);
|
s.vimRcPath.setEnabler(&s.readVimRc);
|
||||||
|
|
||||||
connect(copyTextEditorSettings, &QAbstractButton::clicked,
|
|
||||||
this, &FakeVimOptionPage::copyTextEditorSettings);
|
|
||||||
connect(setQtStyle, &QAbstractButton::clicked,
|
|
||||||
this, &FakeVimOptionPage::setQtStyle);
|
|
||||||
connect(setPlainStyle, &QAbstractButton::clicked,
|
|
||||||
this, &FakeVimOptionPage::setPlainStyle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimOptionPage::copyTextEditorSettings()
|
class FakeVimOptionPage : public IOptionsPage
|
||||||
{
|
{
|
||||||
FakeVimSettings &s = *fakeVimSettings();
|
public:
|
||||||
TabSettings ts = TextEditorSettings::codeStyle()->tabSettings();
|
FakeVimOptionPage()
|
||||||
TypingSettings tps = TextEditorSettings::typingSettings();
|
{
|
||||||
s.expandTab.setValue(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
|
setId(SETTINGS_ID);
|
||||||
s.tabStop.setValue(ts.m_tabSize);
|
setDisplayName(Tr::tr("General"));
|
||||||
s.shiftWidth.setValue(ts.m_indentSize);
|
setCategory(SETTINGS_CATEGORY);
|
||||||
s.smartTab.setValue(tps.m_smartBackspaceBehavior
|
setDisplayCategory(Tr::tr("FakeVim"));
|
||||||
== TypingSettings::BackspaceFollowsPreviousIndents);
|
setCategoryIconPath(":/fakevim/images/settingscategory_fakevim.png");
|
||||||
s.autoIndent.setValue(true);
|
setLayouter(&layoutPage);
|
||||||
s.smartIndent.setValue(tps.m_autoIndent);
|
setSettings(fakeVimSettings());
|
||||||
s.incSearch.setValue(true);
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
void FakeVimOptionPage::setQtStyle()
|
|
||||||
{
|
|
||||||
FakeVimSettings &s = *fakeVimSettings();
|
|
||||||
s.expandTab.setVolatileValue(true);
|
|
||||||
s.tabStop.setVolatileValue(4);
|
|
||||||
s.shiftWidth.setVolatileValue(4);
|
|
||||||
s.smartTab.setVolatileValue(true);
|
|
||||||
s.autoIndent.setVolatileValue(true);
|
|
||||||
s.smartIndent.setVolatileValue(true);
|
|
||||||
s.incSearch.setVolatileValue(true);
|
|
||||||
s.backspace.setVolatileValue(QString("indent,eol,start"));
|
|
||||||
s.passKeys.setVolatileValue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FakeVimOptionPage::setPlainStyle()
|
|
||||||
{
|
|
||||||
FakeVimSettings &s = *fakeVimSettings();
|
|
||||||
s.expandTab.setVolatileValue(false);
|
|
||||||
s.tabStop.setVolatileValue(8);
|
|
||||||
s.shiftWidth.setVolatileValue(8);
|
|
||||||
s.smartTab.setVolatileValue(false);
|
|
||||||
s.autoIndent.setVolatileValue(false);
|
|
||||||
s.smartIndent.setVolatileValue(false);
|
|
||||||
s.incSearch.setVolatileValue(false);
|
|
||||||
s.backspace.setVolatileValue(QString());
|
|
||||||
s.passKeys.setVolatileValue(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -804,16 +789,10 @@ class FakeVimExCommandsPageWidget : public IOptionsPageWidget
|
|||||||
public:
|
public:
|
||||||
FakeVimExCommandsPageWidget()
|
FakeVimExCommandsPageWidget()
|
||||||
{
|
{
|
||||||
m_exCommands = new FakeVimExCommandsMappings;
|
auto exCommands = new FakeVimExCommandsMappings;
|
||||||
auto vbox = new QVBoxLayout(this);
|
setOnApply([exCommands] { exCommands->apply(); });
|
||||||
vbox->addWidget(m_exCommands);
|
Layouting::Column { exCommands, Layouting::noMargin }.attachTo(this);
|
||||||
vbox->setContentsMargins(0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
void apply() final { m_exCommands->apply(); }
|
|
||||||
|
|
||||||
FakeVimExCommandsMappings *m_exCommands;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeVimExCommandsPage : public IOptionsPage
|
class FakeVimExCommandsPage : public IOptionsPage
|
||||||
@@ -840,28 +819,17 @@ public:
|
|||||||
FakeVimUserCommandsModel() { m_commandMap = dd->m_userCommandMap; }
|
FakeVimUserCommandsModel() { m_commandMap = dd->m_userCommandMap; }
|
||||||
|
|
||||||
UserCommandMap commandMap() const { return m_commandMap; }
|
UserCommandMap commandMap() const { return m_commandMap; }
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const final { return parent.isValid() ? 0 : 9; }
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex &parent) const final { return parent.isValid() ? 0 : 2; }
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const final;
|
||||||
bool setData(const QModelIndex &index, const QVariant &data, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &data, int role) final;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const final;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UserCommandMap m_commandMap;
|
UserCommandMap m_commandMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
int FakeVimUserCommandsModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return parent.isValid() ? 0 : 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FakeVimUserCommandsModel::columnCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return parent.isValid() ? 0 : 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant FakeVimUserCommandsModel::headerData(int section,
|
QVariant FakeVimUserCommandsModel::headerData(int section,
|
||||||
Qt::Orientation orient, int role) const
|
Qt::Orientation orient, int role) const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user