From 3afe034aa155dfb6f43739b161cea57a90f88d3a Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Tue, 28 Sep 2021 10:01:13 +0800 Subject: [PATCH] - fix: crash when load last opens - enhancement: when a system/project header file is saved to non-system folders, un-readonly the editor - minor speedup when processing tooltips --- NEWS.md | 3 +++ RedPandaIDE/compiler/projectcompiler.cpp | 2 +- RedPandaIDE/editor.cpp | 17 +++++++++++------ RedPandaIDE/editorlist.cpp | 6 +++++- RedPandaIDE/mainwindow.cpp | 2 +- RedPandaIDE/parser/parserutils.cpp | 2 ++ RedPandaIDE/utils.cpp | 4 ++++ 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 832133a0..a330843f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +Version 0.2.1 + - fix: crash when load last opens + Version 0.2 - fix : header file completion stop work when input '.' - change: continue to run / debug if there are compiling warnings (but no errors) diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index ecb0a281..123bf4e3 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -376,7 +376,7 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) foreach(const PProjectUnit& unit, mProject->units()) { if (getFileType(unit->fileName())!=FileType::WindowsResourceSource) continue; - if (QFile(unit->fileName()).exists()) { + if (fileExists(unit->fileName())) { QString ResFile = extractRelativePath(mProject->makeFileName(), unit->fileName()); ResFiles = ResFiles + genMakePath2(ResFile) + ' '; } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 9e36ebf5..c554fca9 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -110,7 +110,7 @@ Editor::Editor(QWidget *parent, const QString& filename, } if (pSettings->editor().readOnlySytemHeader() - && (mParser->isSystemHeaderFile(filename) || mParser->isProjectHeaderFile(filename))) { + && (mParser->isSystemHeaderFile(mFilename) || mParser->isProjectHeaderFile(mFilename))) { this->setModified(false); setReadOnly(true); updateCaption(); @@ -316,6 +316,11 @@ bool Editor::saveAs(const QString &name, bool fromProject){ if (pSettings->editor().syntaxCheckWhenSave()) pMainWindow->checkSyntaxInBack(this); + if (pSettings->editor().readOnlySytemHeader() + && (!mParser->isSystemHeaderFile(mFilename) && !mParser->isProjectHeaderFile(mFilename))) { + setReadOnly(false); + updateCaption(); + } return true; } @@ -681,8 +686,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to //selection if (selAvail() && highlighter()) { if (( - (attr->name() == SYNS_AttrIdentifier) - || (attr->name() == SYNS_AttrReservedWord) + (attr == highlighter()->identifierAttribute()) + || (attr == highlighter()->keywordAttribute()) || (attr->name() == SYNS_AttrPreprocessor) ) && (token == mSelectionWord)) { @@ -694,7 +699,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to // qDebug()<name()<<" - "<name() == SYNS_AttrIdentifier)) { + if (mParser && mCompletionPopup && (attr == highlighter()->identifierAttribute())) { BufferCoord p{aChar,line}; BufferCoord pBeginPos,pEndPos; QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); @@ -2125,7 +2130,7 @@ Editor::TipType Editor::getTipType(QPoint point, BufferCoord& pos) // do not allow when dragging selection if (isPointInSelection(pos)) return TipType::Selection; - } else if (attr->name() == SYNS_AttrIdentifier) + } else if (attr == highlighter()->identifierAttribute()) return TipType::Identifier; else if (attr->name() == SYNS_AttrPreprocessor) return TipType::Preprocessor; @@ -2388,7 +2393,7 @@ void Editor::updateFunctionTip() pMainWindow->functionTip()->hide(); return; } - if (HLAttr->name()!=SYNS_AttrIdentifier) { + if (HLAttr != highlighter()->identifierAttribute()) { pMainWindow->functionTip()->hide(); return; } diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index d8d47023..4a8e2234 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -29,7 +29,7 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin parentPageControl = getNewEditorPageControl(); else parentPageControl = page; - if (!filename.isEmpty() && QFile(filename).exists()) { + if (fileExists(filename)) { pMainWindow->fileSystemWatcher()->addPath(filename); } Editor * e = new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl); @@ -255,6 +255,8 @@ void EditorList::forceCloseEditor(Editor *editor) Editor* EditorList::getOpenedEditorByFilename(const QString &filename) { + if (filename.isEmpty()) + return nullptr; QFileInfo fileInfo(filename); QString fullname = fileInfo.absoluteFilePath(); for (int i=0;icount();i++) { @@ -274,6 +276,8 @@ Editor* EditorList::getOpenedEditorByFilename(const QString &filename) Editor *EditorList::getEditorByFilename(const QString &filename) { + if (filename.isEmpty()) + return nullptr; //check if an editor is already openned Editor* e=getOpenedEditorByFilename(filename); if (e!=nullptr) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 10cb82de..e2169f43 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1536,7 +1536,7 @@ void MainWindow::loadLastOpens() updateEditorActions(); updateForEncodingInfo(); } - if (!focusedEditor) + if (focusedEditor) focusedEditor->activate(); } diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index c2795e1f..5e599b7a 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -356,6 +356,8 @@ QString getSystemHeaderFilename(const QString &fileName, const QSet& in bool isSystemHeaderFile(const QString &fileName, const QSet &includePaths) { + if (fileName.isEmpty()) + return false; if (includePaths.isEmpty()) return false; bool isFullName = false; diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 205817a0..a0c592fd 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -135,6 +135,8 @@ bool isNonPrintableAsciiChar(char ch) bool fileExists(const QString &file) { + if (file.isEmpty()) + return false; return QFile(file).exists(); } @@ -148,6 +150,8 @@ bool fileExists(const QString &dir, const QString &fileName) bool directoryExists(const QString &file) { + if (file.isEmpty()) + return false; QFileInfo dir(file); return dir.exists() && dir.isDir(); }