- feature: choose c or c++ as default file type
This commit is contained in:
parent
74fbeffeef
commit
08ac0ad419
|
@ -70,7 +70,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
|||
mCurrentWord(),
|
||||
mCurrentTipType(TipType::None)
|
||||
{
|
||||
mUseCppSyntax = true;
|
||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||
if (mFilename.isEmpty()) {
|
||||
newfileCount++;
|
||||
mFilename = tr("untitled%1").arg(newfileCount);
|
||||
|
@ -106,13 +106,13 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
|||
initParser();
|
||||
}
|
||||
|
||||
if (mParser->isSystemHeaderFile(filename) || mParser->isProjectHeaderFile(filename)) {
|
||||
if (pSettings->editor().readOnlySytemHeader()
|
||||
&& (mParser->isSystemHeaderFile(filename) || mParser->isProjectHeaderFile(filename))) {
|
||||
this->setModified(false);
|
||||
setReadOnly(true);
|
||||
updateCaption();
|
||||
}
|
||||
// mCompletionPopup = std::make_shared<CodeCompletionPopup>();
|
||||
// mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
|
||||
|
||||
mCompletionPopup = pMainWindow->completionPopup();
|
||||
mHeaderCompletionPopup = pMainWindow->headerCompletionPopup();
|
||||
|
||||
|
@ -143,6 +143,16 @@ void Editor::loadFile() {
|
|||
pMainWindow->updateForEncodingInfo();
|
||||
if (pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenSave())
|
||||
pMainWindow->checkSyntaxInBack(this);
|
||||
switch(getFileType(mFilename)) {
|
||||
case FileType::CppSource:
|
||||
mUseCppSyntax = true;
|
||||
break;
|
||||
case FileType::CSource:
|
||||
mUseCppSyntax = false;
|
||||
break;
|
||||
default:
|
||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::saveFile(const QString &filename) {
|
||||
|
@ -151,6 +161,16 @@ void Editor::saveFile(const QString &filename) {
|
|||
pMainWindow->updateForEncodingInfo();
|
||||
if (pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenSave())
|
||||
pMainWindow->checkSyntaxInBack(this);
|
||||
switch(getFileType(mFilename)) {
|
||||
case FileType::CppSource:
|
||||
mUseCppSyntax = true;
|
||||
break;
|
||||
case FileType::CSource:
|
||||
mUseCppSyntax = false;
|
||||
break;
|
||||
default:
|
||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::convertToEncoding(const QByteArray &encoding)
|
||||
|
@ -193,7 +213,11 @@ bool Editor::save(bool force, bool doReparse) {
|
|||
}
|
||||
|
||||
bool Editor::saveAs(){
|
||||
QString selectedFileFilter = pSystemConsts->defaultFileFilter();
|
||||
QString selectedFileFilter;
|
||||
if (pSettings->editor().defaultFileCpp())
|
||||
selectedFileFilter = pSystemConsts->defaultCPPFileFilter();
|
||||
else
|
||||
selectedFileFilter = pSystemConsts->defaultCFileFilter();
|
||||
QString newName = QFileDialog::getSaveFileName(pMainWindow,
|
||||
tr("Save As"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
|
||||
&selectedFileFilter);
|
||||
|
|
|
@ -1004,7 +1004,11 @@ void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
|
|||
void MainWindow::on_actionOpen_triggered()
|
||||
{
|
||||
try {
|
||||
QString selectedFileFilter = pSystemConsts->defaultFileFilter();
|
||||
QString selectedFileFilter;
|
||||
if (pSettings->editor().defaultFileCpp())
|
||||
selectedFileFilter = pSystemConsts->defaultCPPFileFilter();
|
||||
else
|
||||
selectedFileFilter = pSystemConsts->defaultCFileFilter();
|
||||
QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
|
||||
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
|
||||
&selectedFileFilter);
|
||||
|
|
|
@ -366,6 +366,26 @@ void Settings::Editor::setReadOnlySytemHeader(bool newReadOnlySytemHeader)
|
|||
mReadOnlySytemHeader = newReadOnlySytemHeader;
|
||||
}
|
||||
|
||||
bool Settings::Editor::defaultFileCpp() const
|
||||
{
|
||||
return mDefaultFileCpp;
|
||||
}
|
||||
|
||||
void Settings::Editor::setDefaultFileCpp(bool newDefaultFileCpp)
|
||||
{
|
||||
mDefaultFileCpp = newDefaultFileCpp;
|
||||
}
|
||||
|
||||
bool Settings::Editor::autoLoadLastFiles() const
|
||||
{
|
||||
return mAutoLoadLastFiles;
|
||||
}
|
||||
|
||||
void Settings::Editor::setAutoLoadLastFiles(bool newAutoLoadLastFiles)
|
||||
{
|
||||
mAutoLoadLastFiles = newAutoLoadLastFiles;
|
||||
}
|
||||
|
||||
bool Settings::Editor::syntaxCheckWhenSave() const
|
||||
{
|
||||
return mSyntaxCheckWhenSave;
|
||||
|
@ -738,8 +758,7 @@ void Settings::Editor::setAutoHideScrollbar(bool autoHideScrollbar)
|
|||
|
||||
void Settings::Editor::doSave()
|
||||
{
|
||||
saveValue("default_encoding",mDefaultEncoding);
|
||||
saveValue("readonly_system_header",mReadOnlySytemHeader);
|
||||
|
||||
// indents
|
||||
saveValue("auto_indent", mAutoIndent);
|
||||
saveValue("add_indent", mAddIndent);
|
||||
|
@ -811,12 +830,17 @@ void Settings::Editor::doSave()
|
|||
saveValue("check_syntax",mSyntaxCheck);
|
||||
saveValue("check_syntax_when_save",mSyntaxCheckWhenSave);
|
||||
saveValue("check_syntax_when_line_changed",mSyntaxCheckWhenLineChanged);
|
||||
|
||||
//misc
|
||||
saveValue("default_encoding",mDefaultEncoding);
|
||||
saveValue("readonly_system_header",mReadOnlySytemHeader);
|
||||
saveValue("auto_load_last_files",mAutoLoadLastFiles);
|
||||
saveValue("default_file_cpp",mDefaultFileCpp);
|
||||
}
|
||||
|
||||
void Settings::Editor::doLoad()
|
||||
{
|
||||
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
|
||||
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
|
||||
|
||||
// indents
|
||||
mAutoIndent = boolValue("auto_indent", true);
|
||||
mAddIndent = boolValue("add_indent", true);
|
||||
|
@ -890,6 +914,12 @@ void Settings::Editor::doLoad()
|
|||
mSyntaxCheck = boolValue("check_syntax",true);
|
||||
mSyntaxCheckWhenSave = boolValue("check_syntax_when_save",true);
|
||||
mSyntaxCheckWhenLineChanged = boolValue("check_syntax_when_line_changed",true);
|
||||
|
||||
//misc
|
||||
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
|
||||
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
|
||||
mAutoLoadLastFiles = boolValue("auto_load_last_files",true);
|
||||
mDefaultFileCpp = boolValue("default_file_cpp",true);
|
||||
}
|
||||
|
||||
SynEditCaretType Settings::Editor::caretForOverwrite() const
|
||||
|
|
|
@ -265,10 +265,14 @@ public:
|
|||
bool readOnlySytemHeader() const;
|
||||
void setReadOnlySytemHeader(bool newReadOnlySytemHeader);
|
||||
|
||||
bool autoLoadLastFiles() const;
|
||||
void setAutoLoadLastFiles(bool newAutoLoadLastFiles);
|
||||
|
||||
bool defaultFileCpp() const;
|
||||
void setDefaultFileCpp(bool newDefaultFileCpp);
|
||||
|
||||
private:
|
||||
QByteArray mDefaultEncoding;
|
||||
//General
|
||||
bool mReadOnlySytemHeader;
|
||||
// indents
|
||||
bool mAutoIndent;
|
||||
bool mAddIndent;
|
||||
|
@ -342,6 +346,12 @@ public:
|
|||
bool mSyntaxCheckWhenSave;
|
||||
bool mSyntaxCheckWhenLineChanged;
|
||||
|
||||
//Misc
|
||||
QByteArray mDefaultEncoding;
|
||||
bool mReadOnlySytemHeader;
|
||||
bool mAutoLoadLastFiles;
|
||||
bool mDefaultFileCpp;
|
||||
|
||||
// _Base interface
|
||||
protected:
|
||||
void doSave() override;
|
||||
|
|
|
@ -17,10 +17,15 @@ EditorMiscWidget::~EditorMiscWidget()
|
|||
|
||||
void EditorMiscWidget::doLoad()
|
||||
{
|
||||
|
||||
ui->chkReadonlySystemHeaders->setChecked(pSettings->editor().readOnlySytemHeader());
|
||||
ui->chkLoadLastFiles->setChecked(pSettings->editor().autoLoadLastFiles());
|
||||
ui->rbCppFile->setChecked(pSettings->editor().defaultFileCpp());
|
||||
}
|
||||
|
||||
void EditorMiscWidget::doSave()
|
||||
{
|
||||
pSettings->editor().setReadOnlySytemHeader(ui->chkReadonlySystemHeaders->isChecked());
|
||||
pSettings->editor().setAutoLoadLastFiles(ui->chkLoadLastFiles->isChecked());
|
||||
pSettings->editor().setDefaultFileCpp(ui->rbCppFile->isChecked());
|
||||
pSettings->editor().save();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "editorcodecompletionwidget.h"
|
||||
#include "editorsyntaxcheckwidget.h"
|
||||
#include "editorsymbolcompletionwidget.h"
|
||||
#include "editormiscwidget.h"
|
||||
#include "environmentappearencewidget.h"
|
||||
#include "executorgeneralwidget.h"
|
||||
#include "debuggeneralwidget.h"
|
||||
|
@ -64,6 +65,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
|||
pEditorSyntaxCheckWidget->init();
|
||||
addWidget(pEditorSyntaxCheckWidget);
|
||||
|
||||
pEditorMiscWidget = new EditorMiscWidget(tr("Misc"),tr("Editor"));
|
||||
pEditorMiscWidget->init();
|
||||
addWidget(pEditorMiscWidget);
|
||||
|
||||
|
||||
pExecutorGeneralWidget = new ExecutorGeneralWidget(tr("General"),tr("Program Runner"));
|
||||
pExecutorGeneralWidget->init();
|
||||
|
|
|
@ -18,6 +18,7 @@ class EditorSymbolCompletionWidget;
|
|||
class EditorColorSchemeWidget;
|
||||
class EditorSyntaxCheckWidget;
|
||||
class EditorCodeCompletionWidget;
|
||||
class EditorMiscWidget;
|
||||
class EnvironmentAppearenceWidget;
|
||||
class ExecutorGeneralWidget;
|
||||
class DebugGeneralWidget;
|
||||
|
@ -59,6 +60,7 @@ private:
|
|||
EditorSymbolCompletionWidget *pEditorSymbolCompletionWidget;
|
||||
EditorCodeCompletionWidget *pEditorCodeCompletionWidget;
|
||||
EditorSyntaxCheckWidget *pEditorSyntaxCheckWidget;
|
||||
EditorMiscWidget *pEditorMiscWidget;
|
||||
ExecutorGeneralWidget *pExecutorGeneralWidget;
|
||||
DebugGeneralWidget *pDebugGeneralWidget;
|
||||
};
|
||||
|
|
|
@ -19,7 +19,12 @@ const QStringList &SystemConsts::defaultFileFilters() const noexcept
|
|||
return mDefaultFileFilters;
|
||||
}
|
||||
|
||||
const QString &SystemConsts::defaultFileFilter() const noexcept
|
||||
const QString &SystemConsts::defaultCFileFilter() const noexcept
|
||||
{
|
||||
return mDefaultFileFilters[0];
|
||||
}
|
||||
|
||||
const QString &SystemConsts::defaultCPPFileFilter() const noexcept
|
||||
{
|
||||
return mDefaultFileFilters[1];
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@ class SystemConsts
|
|||
public:
|
||||
SystemConsts();
|
||||
const QStringList& defaultFileFilters() const noexcept;
|
||||
const QString& defaultFileFilter() const noexcept;
|
||||
const QString& defaultCFileFilter() const noexcept;
|
||||
const QString& defaultCPPFileFilter() const noexcept;
|
||||
void addDefaultFileFilter(const QString& name, const QString& fileExtensions);
|
||||
private:
|
||||
QStringList mDefaultFileFilters;
|
||||
|
|
Loading…
Reference in New Issue