feature: auto link options dialog
This commit is contained in:
parent
f0530d6737
commit
35255a85fa
|
@ -33,6 +33,7 @@ SOURCES += \
|
||||||
qsynedit/Search.cpp \
|
qsynedit/Search.cpp \
|
||||||
qsynedit/SearchBase.cpp \
|
qsynedit/SearchBase.cpp \
|
||||||
qsynedit/SearchRegex.cpp \
|
qsynedit/SearchRegex.cpp \
|
||||||
|
settingsdialog/compilerautolinkwidget.cpp \
|
||||||
settingsdialog/debuggeneralwidget.cpp \
|
settingsdialog/debuggeneralwidget.cpp \
|
||||||
settingsdialog/editorautosavewidget.cpp \
|
settingsdialog/editorautosavewidget.cpp \
|
||||||
settingsdialog/editorcodecompletionwidget.cpp \
|
settingsdialog/editorcodecompletionwidget.cpp \
|
||||||
|
@ -109,6 +110,7 @@ HEADERS += \
|
||||||
qsynedit/Search.h \
|
qsynedit/Search.h \
|
||||||
qsynedit/SearchBase.h \
|
qsynedit/SearchBase.h \
|
||||||
qsynedit/SearchRegex.h \
|
qsynedit/SearchRegex.h \
|
||||||
|
settingsdialog/compilerautolinkwidget.h \
|
||||||
settingsdialog/debuggeneralwidget.h \
|
settingsdialog/debuggeneralwidget.h \
|
||||||
settingsdialog/editorautosavewidget.h \
|
settingsdialog/editorautosavewidget.h \
|
||||||
settingsdialog/editorcodecompletionwidget.h \
|
settingsdialog/editorcodecompletionwidget.h \
|
||||||
|
@ -166,6 +168,7 @@ HEADERS += \
|
||||||
widgets/searchresultview.h
|
widgets/searchresultview.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
settingsdialog/compilerautolinkwidget.ui \
|
||||||
settingsdialog/debuggeneralwidget.ui \
|
settingsdialog/debuggeneralwidget.ui \
|
||||||
settingsdialog/editorautosavewidget.ui \
|
settingsdialog/editorautosavewidget.ui \
|
||||||
settingsdialog/editorcodecompletionwidget.ui \
|
settingsdialog/editorcodecompletionwidget.ui \
|
||||||
|
|
|
@ -420,6 +420,16 @@ void Settings::Editor::setAutoSaveStrategy(AutoSaveStrategy newAutoSaveStrategy)
|
||||||
mAutoSaveStrategy = newAutoSaveStrategy;
|
mAutoSaveStrategy = newAutoSaveStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Settings::Editor::enableAutolink() const
|
||||||
|
{
|
||||||
|
return mEnableAutolink;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::Editor::setEnableAutolink(bool newEnableAutolink)
|
||||||
|
{
|
||||||
|
mEnableAutolink = newEnableAutolink;
|
||||||
|
}
|
||||||
|
|
||||||
AutoSaveTarget Settings::Editor::autoSaveTarget() const
|
AutoSaveTarget Settings::Editor::autoSaveTarget() const
|
||||||
{
|
{
|
||||||
return mAutoSaveTarget;
|
return mAutoSaveTarget;
|
||||||
|
@ -891,6 +901,9 @@ void Settings::Editor::doSave()
|
||||||
saveValue("auto_save_target",mAutoSaveTarget);
|
saveValue("auto_save_target",mAutoSaveTarget);
|
||||||
saveValue("auto_save_strategy",mAutoSaveStrategy);
|
saveValue("auto_save_strategy",mAutoSaveStrategy);
|
||||||
|
|
||||||
|
//auto link
|
||||||
|
saveValue("enable_autolink",mEnableAutolink);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
saveValue("default_encoding",mDefaultEncoding);
|
saveValue("default_encoding",mDefaultEncoding);
|
||||||
saveValue("readonly_system_header",mReadOnlySytemHeader);
|
saveValue("readonly_system_header",mReadOnlySytemHeader);
|
||||||
|
@ -983,6 +996,9 @@ void Settings::Editor::doLoad()
|
||||||
mAutoSaveStrategy = static_cast<enum AutoSaveStrategy>(
|
mAutoSaveStrategy = static_cast<enum AutoSaveStrategy>(
|
||||||
intValue("auto_save_strategy",AutoSaveStrategy::assOverwrite));
|
intValue("auto_save_strategy",AutoSaveStrategy::assOverwrite));
|
||||||
|
|
||||||
|
//auto link
|
||||||
|
mEnableAutolink = boolValue("enable_autolink",true);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
|
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
|
||||||
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
|
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
|
||||||
|
|
|
@ -285,6 +285,9 @@ public:
|
||||||
AutoSaveStrategy autoSaveStrategy() const;
|
AutoSaveStrategy autoSaveStrategy() const;
|
||||||
void setAutoSaveStrategy(AutoSaveStrategy newAutoSaveStrategy);
|
void setAutoSaveStrategy(AutoSaveStrategy newAutoSaveStrategy);
|
||||||
|
|
||||||
|
bool enableAutolink() const;
|
||||||
|
void setEnableAutolink(bool newEnableAutolink);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//General
|
//General
|
||||||
// indents
|
// indents
|
||||||
|
@ -366,6 +369,9 @@ public:
|
||||||
enum AutoSaveTarget mAutoSaveTarget;
|
enum AutoSaveTarget mAutoSaveTarget;
|
||||||
enum AutoSaveStrategy mAutoSaveStrategy;
|
enum AutoSaveStrategy mAutoSaveStrategy;
|
||||||
|
|
||||||
|
//auto link
|
||||||
|
bool mEnableAutolink;
|
||||||
|
|
||||||
//Misc
|
//Misc
|
||||||
QByteArray mDefaultEncoding;
|
QByteArray mDefaultEncoding;
|
||||||
bool mReadOnlySytemHeader;
|
bool mReadOnlySytemHeader;
|
||||||
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
#include "compilerautolinkwidget.h"
|
||||||
|
#include "ui_compilerautolinkwidget.h"
|
||||||
|
#include "../mainwindow.h"
|
||||||
|
#include "../settings.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
CompilerAutolinkWidget::CompilerAutolinkWidget(const QString& name, const QString& group, QWidget* parent) :
|
||||||
|
SettingsWidget(name,group,parent),
|
||||||
|
ui(new Ui::CompilerAutolinkWidget)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->tblAutolinks->setModel(&mModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
CompilerAutolinkWidget::~CompilerAutolinkWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompilerAutolinkWidget::doLoad()
|
||||||
|
{
|
||||||
|
ui->grpAutolink->setChecked(pSettings->editor().enableAutolink());
|
||||||
|
mModel.setLinks(pAutolinkManager->links());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompilerAutolinkWidget::doSave()
|
||||||
|
{
|
||||||
|
pSettings->editor().setEnableAutolink(ui->grpAutolink->isChecked());
|
||||||
|
pSettings->editor().save();
|
||||||
|
pAutolinkManager->clear();
|
||||||
|
auto iter = mModel.links().cbegin();
|
||||||
|
while (iter!=mModel.links().cend()) {
|
||||||
|
PAutolink link = iter.value();
|
||||||
|
pAutolinkManager->setLink(
|
||||||
|
link->header,
|
||||||
|
link->linkOption
|
||||||
|
);
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
pAutolinkManager->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
AutolinkModel::AutolinkModel(QObject *parent):QAbstractTableModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int AutolinkModel::rowCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return mLinks.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int AutolinkModel::columnCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant AutolinkModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||||
|
switch(section) {
|
||||||
|
case 0:
|
||||||
|
return tr("Header");
|
||||||
|
case 1:
|
||||||
|
return tr("Link options");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant AutolinkModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
|
int row = index.row();
|
||||||
|
QList<PAutolink> links = mLinks.values();
|
||||||
|
if (row<0 || row>=links.count())
|
||||||
|
return QVariant();
|
||||||
|
PAutolink link = links[row];
|
||||||
|
switch(index.column()) {
|
||||||
|
case 0:
|
||||||
|
return link->header;
|
||||||
|
case 1:
|
||||||
|
return link->linkOption;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AutolinkModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return false;
|
||||||
|
if (role == Qt::EditRole) {
|
||||||
|
int row = index.row();
|
||||||
|
QList<PAutolink> links = mLinks.values();
|
||||||
|
if (row<0 || row>=links.count())
|
||||||
|
return false;
|
||||||
|
PAutolink link = links[row];
|
||||||
|
QString s=value.toString();
|
||||||
|
if (index.column() == 0) {
|
||||||
|
if (s.isEmpty())
|
||||||
|
return false;
|
||||||
|
PAutolink oldLink = mLinks.value(s,PAutolink());
|
||||||
|
if (oldLink) {
|
||||||
|
QMessageBox::warning(pMainWindow,
|
||||||
|
tr("Header exists"),
|
||||||
|
tr("Header already exists."),
|
||||||
|
QMessageBox::Yes);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mLinks.remove(link->header);
|
||||||
|
PAutolink newLink = std::make_shared<Autolink>();
|
||||||
|
newLink->header = s;
|
||||||
|
newLink->linkOption = link->linkOption;
|
||||||
|
mLinks.insert(newLink->header,newLink);
|
||||||
|
return true;
|
||||||
|
} else if (index.column() == 1) {
|
||||||
|
PAutolink newLink = std::make_shared<Autolink>();
|
||||||
|
newLink->header = link->header;
|
||||||
|
newLink->linkOption = s;
|
||||||
|
mLinks.insert(newLink->header,newLink);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags AutolinkModel::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
Qt::ItemFlags flags = Qt::NoItemFlags;
|
||||||
|
if (index.isValid()) {
|
||||||
|
flags = Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable ;
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QMap<QString, PAutolink> &AutolinkModel::links() const
|
||||||
|
{
|
||||||
|
return mLinks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutolinkModel::setLinks(const QMap<QString, PAutolink> &newLinks)
|
||||||
|
{
|
||||||
|
mLinks = newLinks;
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
#ifndef COMPILERAUTOLINKWIDGET_H
|
||||||
|
#define COMPILERAUTOLINKWIDGET_H
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
#include <QWidget>
|
||||||
|
#include "settingswidget.h"
|
||||||
|
#include "../autolinkmanager.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class CompilerAutolinkWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AutolinkModel: public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AutolinkModel(QObject* parent=nullptr);
|
||||||
|
|
||||||
|
// QAbstractItemModel interface
|
||||||
|
public:
|
||||||
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
const QMap<QString, PAutolink> &links() const;
|
||||||
|
void setLinks(const QMap<QString, PAutolink> &newLinks);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<QString,PAutolink> mLinks;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CompilerAutolinkWidget : public SettingsWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CompilerAutolinkWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
|
||||||
|
~CompilerAutolinkWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
AutolinkModel mModel;
|
||||||
|
private:
|
||||||
|
Ui::CompilerAutolinkWidget *ui;
|
||||||
|
|
||||||
|
// SettingsWidget interface
|
||||||
|
protected:
|
||||||
|
void doLoad() override;
|
||||||
|
void doSave() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COMPILERAUTOLINKWIDGET_H
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CompilerAutolinkWidget</class>
|
||||||
|
<widget class="QWidget" name="CompilerAutolinkWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="grpAutolink">
|
||||||
|
<property name="title">
|
||||||
|
<string>Enable auto link</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="tblAutolinks">
|
||||||
|
<property name="textElideMode">
|
||||||
|
<enum>Qt::ElideNone</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ui_settingsdialog.h"
|
#include "ui_settingsdialog.h"
|
||||||
#include "settingswidget.h"
|
#include "settingswidget.h"
|
||||||
#include "compilersetoptionwidget.h"
|
#include "compilersetoptionwidget.h"
|
||||||
|
#include "compilerautolinkwidget.h"
|
||||||
#include "editorgeneralwidget.h"
|
#include "editorgeneralwidget.h"
|
||||||
#include "editorfontwidget.h"
|
#include "editorfontwidget.h"
|
||||||
#include "editorclipboardwidget.h"
|
#include "editorclipboardwidget.h"
|
||||||
|
@ -39,6 +40,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||||
pCompilerSetOptionWidget->init();
|
pCompilerSetOptionWidget->init();
|
||||||
addWidget(pCompilerSetOptionWidget);
|
addWidget(pCompilerSetOptionWidget);
|
||||||
|
|
||||||
|
pCompilerAutolinkWidget = new CompilerAutolinkWidget(tr("Auto Link"),tr("Compiler"));
|
||||||
|
pCompilerAutolinkWidget->init();
|
||||||
|
addWidget(pCompilerAutolinkWidget);
|
||||||
|
|
||||||
pEditorGeneralWidget = new EditorGeneralWidget(tr("General"),tr("Editor"));
|
pEditorGeneralWidget = new EditorGeneralWidget(tr("General"),tr("Editor"));
|
||||||
pEditorGeneralWidget->init();
|
pEditorGeneralWidget->init();
|
||||||
addWidget(pEditorGeneralWidget);
|
addWidget(pEditorGeneralWidget);
|
||||||
|
|
|
@ -11,6 +11,7 @@ class SettingsDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompilerSetOptionWidget;
|
class CompilerSetOptionWidget;
|
||||||
|
class CompilerAutolinkWidget;
|
||||||
class EditorGeneralWidget;
|
class EditorGeneralWidget;
|
||||||
class EditorFontWidget;
|
class EditorFontWidget;
|
||||||
class EditorClipboardWidget;
|
class EditorClipboardWidget;
|
||||||
|
@ -54,6 +55,7 @@ private:
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
|
|
||||||
CompilerSetOptionWidget *pCompilerSetOptionWidget;
|
CompilerSetOptionWidget *pCompilerSetOptionWidget;
|
||||||
|
CompilerAutolinkWidget *pCompilerAutolinkWidget;
|
||||||
EditorGeneralWidget *pEditorGeneralWidget;
|
EditorGeneralWidget *pEditorGeneralWidget;
|
||||||
EditorFontWidget *pEditorFontWidget;
|
EditorFontWidget *pEditorFontWidget;
|
||||||
EditorClipboardWidget *pEditorClipboardWidget;
|
EditorClipboardWidget *pEditorClipboardWidget;
|
||||||
|
|
|
@ -43,6 +43,7 @@ void SettingsWidget::connectAbstractItemView(QAbstractItemView *pView)
|
||||||
connect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
|
connect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
|
||||||
connect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
|
connect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
|
||||||
connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
||||||
|
connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsWidget::disconnectAbstractItemView(QAbstractItemView *pView)
|
void SettingsWidget::disconnectAbstractItemView(QAbstractItemView *pView)
|
||||||
|
|
Loading…
Reference in New Issue