diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 31e865230..3e9df6648 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -71,14 +71,14 @@ static QSet CppTypeQualifiers { }; Editor::Editor(QWidget *parent): - Editor{parent,"untitled",ENCODING_AUTO_DETECT,nullptr,true,nullptr} + Editor{parent,"untitled",ENCODING_AUTO_DETECT, FileType::None, QString(), nullptr,true,nullptr} { } Editor::Editor(QWidget *parent, const QString& filename, - const QByteArray& encoding, - Project* pProject, bool isNew, - QTabWidget* parentPageControl): + const QByteArray& encoding, FileType fileType, + const QString& contextFile, Project* pProject, + bool isNew, QTabWidget* parentPageControl): QSynEdit{parent}, mInited{false}, mEncodingOption{encoding}, @@ -95,7 +95,7 @@ Editor::Editor(QWidget *parent, const QString& filename, mHoverModifiedLine{-1}, mWheelAccumulatedDelta{0}, mCtrlClicking{false}, - mFileType{FileType::None} + mContextFile{contextFile} { mLastFocusOutTime = 0; mInited=false; @@ -107,7 +107,9 @@ Editor::Editor(QWidget *parent, const QString& filename, if (mFilename.isEmpty()) { mFilename = QString("untitled%1").arg(getNewFileNumber()); } - doSetFileType(getFileType(mFilename)); + if (fileType == FileType::None) + fileType = getFileType(mFilename); + doSetFileType(fileType); if (mProject && mEncodingOption==ENCODING_PROJECT) { mEncodingOption=mProject->options().encoding; } @@ -4542,9 +4544,12 @@ FileType Editor::fileType() const void Editor::setFileType(FileType newFileType) { + if (newFileType == FileType::None) + newFileType = getFileType(mFilename); if (mFileType==newFileType) return; doSetFileType(newFileType); + applyColorScheme(pSettings->editor().colorScheme()); if (!inProject()) { initParser(); reparse(false); @@ -4583,16 +4588,13 @@ void Editor::doSetFileType(FileType newFileType, bool force) } QSynedit::PSyntaxer syntaxer{syntaxerManager.getSyntaxer(mFileType)}; + setSyntaxer(syntaxer); if (syntaxer) { - setSyntaxer(syntaxer); setFormatter(syntaxerManager.getFormatter(syntaxer->language())); setUseCodeFolding(true); } else { setUseCodeFolding(false); } - - setSyntaxer(syntaxer); - applyColorScheme(pSettings->editor().colorScheme()); } Editor* Editor::openFileInContext(const QString &filename) diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index b8bce0f76..ba30e668a 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -126,6 +126,8 @@ class Editor : public QSynedit::QSynEdit explicit Editor(QWidget *parent, const QString& filename, const QByteArray& encoding, + FileType fileType, + const QString& contextFile, Project* pProject, bool isNew,QTabWidget* parentPageControl); ~Editor(); diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 802878268..17102eed6 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -43,8 +43,9 @@ EditorList::EditorList(QTabWidget* leftPageWidget, } Editor* EditorList::newEditor(const QString& filename, const QByteArray& encoding, - Project *pProject, bool newFile, - QTabWidget* page) { + FileType fileType, const QString& contextFile, + Project *pProject, bool newFile, + QTabWidget* page) { QTabWidget * parentPageControl = nullptr; if (page == nullptr) parentPageControl = getNewEditorPageControl(); @@ -55,7 +56,7 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin } // parentPageControl takes the owner ship - Editor * e = new Editor(parentPageControl,filename,encoding,pProject,newFile,parentPageControl); + Editor * e = new Editor(parentPageControl, filename, encoding, fileType, contextFile, pProject, newFile, parentPageControl); connect(e, &Editor::renamed, this, &EditorList::onEditorRenamed); updateLayout(); connect(e,&Editor::fileSaved, diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index f540b4b08..de8c7d854 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -40,6 +40,7 @@ class EditorList : public QObject QWidget* panel, QObject* parent = nullptr); Editor* newEditor(const QString& filename, const QByteArray& encoding, + FileType fileType, const QString& contextFile, Project *pProject, bool newFile, QTabWidget* page=nullptr); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index a57b45342..9e1932523 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1798,7 +1798,7 @@ void MainWindow::openFiles(const QStringList &files) } } -Editor* MainWindow::openFile(QString filename, bool activate, QTabWidget* page) +Editor* MainWindow::openFile(QString filename, bool activate, QTabWidget* page, FileType fileType, const QString& contextFile) { if (!fileExists(filename)) return nullptr; @@ -1812,6 +1812,8 @@ Editor* MainWindow::openFile(QString filename, bool activate, QTabWidget* page) Editor* editor = mEditorList->getOpenedEditorByFilename(filename); if (editor!=nullptr) { + editor->setContextFile(contextFile); + editor->setFileType(fileType); if (activate) { editor->activate(); } @@ -1837,7 +1839,8 @@ Editor* MainWindow::openFile(QString filename, bool activate, QTabWidget* page) if (pProject && encoding==ENCODING_PROJECT) encoding=pProject->options().encoding; editor = mEditorList->newEditor(filename,encoding, - pProject, false, page); + fileType, contextFile, + pProject, false, page); // if (mProject) { // mProject->associateEditorToUnit(editor,unit); // } @@ -3549,6 +3552,18 @@ void MainWindow::loadLastOpens() if (!fileExists(editorFilename)) continue; bool onLeft = fileObj["onLeft"].toBool(); + QSynedit::BufferCoord pos; + pos.ch = fileObj["caretX"].toInt(1); + pos.line = fileObj["caretY"].toInt(1); + QByteArray encoding; + if (fileObj.contains("encodingOption")) + encoding = fileObj["encodingOption"].toString().toLatin1(); + QString contextFile; + if (fileObj.contains("contextFile")) + contextFile = fileObj["contextFile"].toString(); + FileType fileType{FileType::None}; + if (fileObj.contains("fileType")) + fileType = nameToFileType(fileObj["fileType"].toString()); QTabWidget* page; if (onLeft) page = mEditorList->leftPageWidget(); @@ -3559,12 +3574,14 @@ void MainWindow::loadLastOpens() unit = mProject->findUnit(editorFilename); } bool inProject = (mProject && unit); - QByteArray encoding = unit ? unit->encoding() : - (pSettings->editor().autoDetectFileEncoding()? QByteArray(ENCODING_AUTO_DETECT) : pSettings->editor().defaultEncoding()); + if (encoding.isEmpty()) { + encoding = unit ? unit->encoding() : + (pSettings->editor().autoDetectFileEncoding()? QByteArray(ENCODING_AUTO_DETECT) : pSettings->editor().defaultEncoding()); + } Project* pProject = (inProject?mProject.get():nullptr); if (pProject && encoding==ENCODING_PROJECT) encoding=pProject->options().encoding; - Editor * editor = mEditorList->newEditor(editorFilename, encoding, pProject,false,page); + Editor * editor = mEditorList->newEditor(editorFilename, encoding, fileType, contextFile, pProject,false,page); if (inProject && editor) { mProject->loadUnitLayout(editor); @@ -3574,9 +3591,6 @@ void MainWindow::loadLastOpens() // } if (!editor) continue; - QSynedit::BufferCoord pos; - pos.ch = fileObj["caretX"].toInt(1); - pos.line = fileObj["caretY"].toInt(1); editor->setCaretXY(pos); editor->setTopPos( fileObj["top"].toInt(1) @@ -3584,13 +3598,6 @@ void MainWindow::loadLastOpens() editor->setLeftPos( fileObj["left"].toInt(1) ); - if (fileObj.contains("contextFile")) - editor->setContextFile(fileObj["contextFile"].toString()); - if (fileObj.contains("fileType")) { - editor->setFileType(nameToFileType(fileObj["fileType"].toString())); - } - if (fileObj.contains("encodingOption")) - editor->setEncodingOption(fileObj["encodingOption"].toString().toLatin1()); if (fileObj["focused"].toBool(false)) focusedEditor = editor; //mVisitHistoryManager->removeFile(editorFilename); @@ -3670,6 +3677,7 @@ void MainWindow::newEditor(const QString& suffix) } while(mEditorList->hasFilename(filename)); Editor * editor=mEditorList->newEditor(filename, pSettings->editor().defaultEncoding(), + FileType::None, QString(), nullptr,true); editor->activate(); //updateForEncodingInfo(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index fe9792fd5..9f04f77a9 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -219,7 +219,7 @@ class MainWindow : public QMainWindow TodoModel* todoModel(); - Editor* openFile(QString filename, bool activate=true, QTabWidget* page=nullptr); + Editor* openFile(QString filename, bool activate=true, QTabWidget* page=nullptr, FileType fileType=FileType::None, const QString& contextFile = QString()); void openProject(QString filename, bool openFiles = true); void changeOptions(const QString& widgetName=QString(), const QString& groupName=QString()); void changeProjectOptions(const QString& widgetName=QString(), const QString& groupName=QString()); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 6a322c668..4306528aa 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -941,7 +941,7 @@ QTabWidget::North - 2 + 6 diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 953387afe..182314a19 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -391,7 +391,7 @@ Editor* Project::openUnit(PProjectUnit& unit, bool forceOpen) { if (encoding==ENCODING_PROJECT) encoding=options().encoding; - editor = mEditorList->newEditor(unit->fileName(), encoding, this, false); + editor = mEditorList->newEditor(unit->fileName(), encoding, FileType::None, QString(), this, false); if (editor) { //editor->setProject(this); //unit->setEncoding(encoding); @@ -420,7 +420,7 @@ Editor *Project::openUnit(PProjectUnit &unit, const PProjectEditorLayout &layout encoding = unit->encoding(); if (encoding==ENCODING_PROJECT) encoding=options().encoding; - editor = mEditorList->newEditor(unit->fileName(), encoding, this, false); + editor = mEditorList->newEditor(unit->fileName(), encoding, FileType::None, QString(), this, false); if (editor) { //editor->setInProject(true); editor->setCaretY(layout->caretY); @@ -983,6 +983,8 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b Editor * editor = mEditorList->newEditor( unit->fileName(), unit->encoding()==ENCODING_PROJECT?options().encoding:unit->encoding(), + FileType::None, + QString(), this, false); editor->activate(); @@ -1000,6 +1002,8 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b Editor * editor = mEditorList->newEditor( unit->fileName(), unit->encoding()==ENCODING_PROJECT?options().encoding:unit->encoding(), + FileType::None, + QString(), this, true);