- enhancement: parser not called when open a file, if option "clean parser symbols when hidden" is turned on.

This commit is contained in:
Roy Qu 2022-01-24 20:59:02 +08:00
parent d0faf50bad
commit ee9db9cdfd
9 changed files with 66 additions and 73 deletions

View File

@ -25,6 +25,7 @@ Red Panda C++ Version 0.13.3
- fix: search around option can't be disabled
- enhancement: show a confirm dialog when search/replace around
- enhancement: auto zoom ui when screen's zoom factor changed (windows)
- enhancement: parser not called when open a file, if option "clean parser symbols when hidden" is turned on.
Red Panda C++ Version 0.13.2
- fix: "delete and exit" button in the environtment / folder option page doesn't work correctly

View File

@ -43,7 +43,7 @@ PSynHighlighter HighlighterManager::getHighlighter(const QString &filename)
|| suffix == "CPP" || suffix =="H" || suffix == "c++"
|| suffix == "h++") {
return getCppHighlighter();
} else if (suffix == "vs" || suffix == "fs") {
} else if (suffix == "vs" || suffix == "fs" || suffix == "frag") {
return getGLSLHighlighter();
}
}

View File

@ -32,7 +32,15 @@ AutolinkManager::AutolinkManager()
PAutolink AutolinkManager::getLink(const QString &header) const
{
return mLinks.value(header,PAutolink());
PAutolink link = mLinks.value(header,PAutolink());
if (link)
return link;
foreach (QString key, mLinks.keys()) {
if (header.endsWith("/"+key, PATH_SENSITIVITY)) {
return mLinks.value(key);
}
}
return PAutolink();
}
void AutolinkManager::load()

View File

@ -534,11 +534,10 @@ QString Compiler::parseFileIncludesForAutolink(
PCppParser& parser)
{
QString result;
QString baseName = extractFileName(filename);
if (parsedFiles.contains(filename))
return result;
parsedFiles.insert(filename);
PAutolink autolink = pAutolinkManager->getLink(baseName);
PAutolink autolink = pAutolinkManager->getLink(filename);
if (autolink) {
result += ' '+autolink->linkOption;
}

View File

@ -94,16 +94,16 @@ Editor::Editor(QWidget *parent, const QString& filename,
mCurrentHighlightedWord(),
mSaving(false)
{
qDebug()<<"inited1 ";
mCurrentLineModified = false;
mUseCppSyntax = pSettings->editor().defaultFileCpp();
if (mFilename.isEmpty()) {
mFilename = tr("untitled")+QString("%1").arg(getNewFileNumber());
}
qDebug()<<"inited2 ";
QFileInfo fileInfo(mFilename);
if (mParentPageControl!=nullptr) {
mParentPageControl->addTab(this,"");
updateCaption();
}
qDebug()<<"inited3 ";
PSynHighlighter highlighter;
if (!isNew) {
@ -117,6 +117,8 @@ Editor::Editor(QWidget *parent, const QString& filename,
highlighter=highlighterManager.getCppHighlighter();
}
qDebug()<<"----------inited";
if (highlighter) {
setHighlighter(highlighter);
setUseCodeFolding(true);
@ -134,7 +136,6 @@ Editor::Editor(QWidget *parent, const QString& filename,
&& mParser && (mParser->isSystemHeaderFile(mFilename) || mParser->isProjectHeaderFile(mFilename))) {
this->setModified(false);
setReadOnly(true);
updateCaption();
}
mCompletionPopup = pMainWindow->completionPopup();
@ -180,6 +181,10 @@ Editor::Editor(QWidget *parent, const QString& filename,
resetBreakpoints();
}
mStatementColors = pMainWindow->statementColors();
if (mParentPageControl!=nullptr) {
mParentPageControl->addTab(this,"");
updateCaption();
}
}
Editor::~Editor() {
@ -524,12 +529,6 @@ void Editor::wheelEvent(QWheelEvent *event) {
void Editor::focusInEvent(QFocusEvent *event)
{
SynEdit::focusInEvent(event);
if (mParser) {
connect(mParser.get(),
&CppParser::onEndParsing,
this,
&SynEdit::invalidate);
}
pMainWindow->updateAppTitle();
pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol();
@ -540,12 +539,6 @@ void Editor::focusInEvent(QFocusEvent *event)
void Editor::focusOutEvent(QFocusEvent *event)
{
SynEdit::focusOutEvent(event);
if (mParser) {
disconnect(mParser.get(),
&CppParser::onEndParsing,
this,
&SynEdit::invalidate);
}
//pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
@ -1195,6 +1188,41 @@ void Editor::closeEvent(QCloseEvent *)
pMainWindow->functionTip()->hide();
}
void Editor::showEvent(QShowEvent */*event*/)
{
qDebug()<<"show event";
if (pSettings->codeCompletion().clearWhenEditorHidden()
&& !inProject()) {
initParser();
}
if (mParser) {
connect(mParser.get(),
&CppParser::onEndParsing,
this,
&SynEdit::invalidate);
}
if (pSettings->codeCompletion().clearWhenEditorHidden()
&& !inProject()) {
reparse();
}
reparseTodo();
setHideTime(QDateTime());
}
void Editor::hideEvent(QHideEvent */*event*/)
{
if (mParser) {
disconnect(mParser.get(),
&CppParser::onEndParsing,
this,
&SynEdit::invalidate);
}
if (pSettings->codeCompletion().clearWhenEditorHidden()
&& !inProject() && mParser)
mParser->reset();
setHideTime(QDateTime::currentDateTime());
}
void Editor::copyToClipboard()
{
if (pSettings->editor().copySizeLimit()) {
@ -2407,6 +2435,7 @@ void Editor::reparse()
if (highlighter()->language() != SynHighlighterLanguage::Cpp
&& highlighter()->language() != SynHighlighterLanguage::GLSL)
return;
qDebug()<<"reparse"<<mParser.get()<<mFilename<<mInProject;
parseFile(mParser,mFilename,mInProject);
}
@ -3124,7 +3153,7 @@ QString Editor::getFileHint(const QString &s)
return "";
}
QString Editor::getParserHint(const QStringList& expression,const QString &s, int line)
QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/, int line)
{
// This piece of code changes the parser database, possibly making hints and code completion invalid...
QString result;

View File

@ -372,6 +372,11 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void inputMethodEvent(QInputMethodEvent *) override;
void closeEvent(QCloseEvent *event) override;
// QWidget interface
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
};
QString getWordAtPosition(SynEdit* editor,

View File

@ -954,8 +954,6 @@ void MainWindow::openFiles(const QStringList &files)
auto end = finally([this] {
this->mEditorList->endUpdate();
mOpenningFiles = false;
updateEditorParser(ui->EditorTabsLeft);
updateEditorParser(ui->EditorTabsRight);
});
//Check if there is a project file in the list and open it
for (const QString& file:files) {
@ -5222,39 +5220,6 @@ PSymbolUsageManager &MainWindow::symbolUsageManager()
return mSymbolUsageManager;
}
void MainWindow::updateEditorParser(QTabWidget* tabWidget) {
if (mOpenningFiles)
return;
Editor * editor = mEditorList->getEditor(-1,tabWidget);
if (pSettings->codeCompletion().clearWhenEditorHidden()) {
for (int i=0;i<tabWidget->count();i++) {
Editor * e = (Editor*)(tabWidget->widget(i));
if (!e->inProject()) {
if (e!=editor && e->parser() && !e->notParsed()) {
e->parser()->reset();
}
}
}
}
if (editor && editor->parser() && editor->notParsed()) {
resetCppParser(editor->parser());
editor->reparse();
}
}
void MainWindow::updateEditorHideTime(QTabWidget* tabWidget) {
Editor * editor = mEditorList->getEditor(-1,tabWidget);
for (int i=0;i<tabWidget->count();i++) {
Editor * e = (Editor*)(tabWidget->widget(i));
if (e!=editor) {
if (!e->hideTime().isValid())
e->setHideTime(QDateTime::currentDateTime());
} else {
e->setHideTime(QDateTime());
}
}
}
void MainWindow::showHideInfosTab(QWidget *widget, bool show)
{
int idx = findTabIndex(ui->tabInfos,widget);
@ -5393,25 +5358,12 @@ void MainWindow::onEditorRenamed(const QString &oldFilename, const QString &newF
void MainWindow::on_EditorTabsLeft_currentChanged(int)
{
Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsLeft);
if (editor) {
editor->reparseTodo();
}
updateEditorParser(ui->EditorTabsLeft);
updateEditorHideTime(ui->EditorTabsLeft);
}
void MainWindow::on_EditorTabsRight_currentChanged(int)
{
Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsRight);
if (editor) {
editor->reparseTodo();
}
updateEditorParser(ui->EditorTabsRight);
updateEditorHideTime(ui->EditorTabsRight);
}
void MainWindow::on_tableTODO_doubleClicked(const QModelIndex &index)
{
@ -5422,7 +5374,6 @@ void MainWindow::on_tableTODO_doubleClicked(const QModelIndex &index)
editor->setCaretPositionAndActivate(item->lineNo,item->ch+1);
}
}
}

View File

@ -243,8 +243,6 @@ private:
void doCompileRun(RunType runType);
void updateProblemCaseOutput(POJProblemCase problemCase);
void applyCurrentProblemCaseChanges();
void updateEditorParser(QTabWidget* tabWidget);
void updateEditorHideTime(QTabWidget* tabWidget);
void showHideInfosTab(QWidget *widget, bool show);
void showHideMessagesTab(QWidget *widget, bool show);
void prepareTabInfosData();

View File

@ -50,6 +50,7 @@ void EditorCodeCompletionWidget::doLoad()
ui->chkIgnoreCases->setChecked(pSettings->codeCompletion().ignoreCase());
ui->chkAppendFunc->setChecked(pSettings->codeCompletion().appendFunc());
ui->chkShowCodeIns->setChecked(pSettings->codeCompletion().showCodeIns());
ui->chkClearWhenEditorHidden->setChecked(pSettings->codeCompletion().clearWhenEditorHidden());
ui->spinMinCharRequired->setValue(pSettings->codeCompletion().minCharRequired());
}
@ -74,6 +75,7 @@ void EditorCodeCompletionWidget::doSave()
pSettings->codeCompletion().setShowCodeIns(ui->chkShowCodeIns->isChecked());
pSettings->codeCompletion().setMinCharRequired(ui->spinMinCharRequired->value());
pSettings->codeCompletion().setClearWhenEditorHidden(ui->chkClearWhenEditorHidden->isChecked());
pSettings->codeCompletion().save();
}