- fix: Edting / show context menu when code analysis is turned on may crash app.

- fix: Show context menu when edting non c/c++ file may crash app.
This commit is contained in:
Roy Qu 2022-11-06 09:43:28 +08:00
parent 46ee9e1c7d
commit 4eec64939e
3 changed files with 36 additions and 22 deletions

View File

@ -7,6 +7,8 @@ Red Panda C++ Version 2.2
- fix: Pressing '*' at begin of line will crash app - fix: Pressing '*' at begin of line will crash app
- enhancement: switch header/source in editor's context menu - enhancement: switch header/source in editor's context menu
- enhancement: base class dropdown list in new class dialog now works - enhancement: base class dropdown list in new class dialog now works
- fix: Edting / show context menu when code analysis is turned on may crash app.
- fix: Show context menu when edting non c/c++ file may crash app.
Red Panda C++ Version 2.1 Red Panda C++ Version 2.1

View File

@ -915,7 +915,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (token.isEmpty()) if (token.isEmpty())
return; return;
if (mParser && mParser->enabled() && highlighter()) { if (mParser && highlighter()) {
QString lineText = document()->getString(line-1); QString lineText = document()->getString(line-1);
if (mParser->isIncludeLine(lineText)) { if (mParser->isIncludeLine(lineText)) {
if (cursor() == Qt::PointingHandCursor) { if (cursor() == Qt::PointingHandCursor) {
@ -932,7 +932,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
} }
} }
} }
} else if (attr == highlighter()->identifierAttribute()) { } else if (mParser->enabled() && attr == highlighter()->identifierAttribute()) {
QSynedit::BufferCoord p{aChar,line}; QSynedit::BufferCoord p{aChar,line};
// BufferCoord pBeginPos,pEndPos; // BufferCoord pBeginPos,pEndPos;
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
@ -1057,18 +1057,19 @@ bool Editor::event(QEvent *event)
switch (reason) { switch (reason) {
case TipType::Preprocessor: case TipType::Preprocessor:
// When hovering above a preprocessor line, determine if we want to show an include or a identifier hint // When hovering above a preprocessor line, determine if we want to show an include or a identifier hint
if (mParser) {
s = document()->getString(p.line - 1); s = document()->getString(p.line - 1);
isIncludeNextLine = mParser->isIncludeNextLine(s); isIncludeNextLine = mParser->isIncludeNextLine(s);
if (!isIncludeNextLine) if (!isIncludeNextLine)
isIncludeLine = mParser->isIncludeLine(s); isIncludeLine = mParser->isIncludeLine(s);
if (!isIncludeNextLine &&!isIncludeLine) if (!isIncludeNextLine &&!isIncludeLine)
s = wordAtRowCol(p); s = wordAtRowCol(p);
}
break; break;
case TipType::Identifier: case TipType::Identifier:
if (pMainWindow->debugger()->executing() && !pMainWindow->debugger()->inferiorRunning()) if (pMainWindow->debugger()->executing() && !pMainWindow->debugger()->inferiorRunning())
s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpEvaluation); // debugging s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpEvaluation); // debugging
else if (//devEditor.ParserHints and else if (!mCompletionPopup->isVisible()
!mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) { && !mHeaderCompletionPopup->isVisible()) {
expression = getExpressionAtPosition(p); expression = getExpressionAtPosition(p);
s = expression.join(""); // information during coding s = expression.join(""); // information during coding
@ -1090,7 +1091,9 @@ bool Editor::event(QEvent *event)
s = s.trimmed(); s = s.trimmed();
if ((s == mCurrentWord) && (mCurrentTipType == reason)) { if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
if (qApp->queryKeyboardModifiers() == Qt::ControlModifier) { if (mParser
&& mParser->enabled()
&& qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
if (!hasFocus()) if (!hasFocus())
activate(); activate();
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
@ -1148,7 +1151,9 @@ bool Editor::event(QEvent *event)
if (!hint.isEmpty()) { if (!hint.isEmpty()) {
// QApplication* app = dynamic_cast<QApplication *>(QApplication::instance()); // QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) { // if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
if (qApp->queryKeyboardModifiers() == Qt::ControlModifier) { if (mParser
&& mParser->enabled()
&& qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
if (!hasFocus()) if (!hasFocus())
activate(); activate();
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
@ -1201,7 +1206,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
&& (event->button() == Qt::LeftButton)) { && (event->button() == Qt::LeftButton)) {
QSynedit::BufferCoord p; QSynedit::BufferCoord p;
if (pointToCharLine(event->pos(),p)) { if (mParser && pointToCharLine(event->pos(),p)) {
QString s = document()->getString(p.line - 1); QString s = document()->getString(p.line - 1);
if (mParser->isIncludeNextLine(s)) { if (mParser->isIncludeNextLine(s)) {
QString filename = mParser->getHeaderFileName(mFilename,s, true); QString filename = mParser->getHeaderFileName(mFilename,s, true);
@ -1211,7 +1216,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
QString filename = mParser->getHeaderFileName(mFilename,s); QString filename = mParser->getHeaderFileName(mFilename,s);
pMainWindow->openFile(filename); pMainWindow->openFile(filename);
return; return;
} else { } else if (mParser->enabled()) {
gotoDefinition(p); gotoDefinition(p);
return; return;
} }
@ -3457,7 +3462,7 @@ bool Editor::onCompletionInputMethod(QInputMethodEvent *event)
Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos) Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
{ {
// Only allow in the text area... // Only allow in the text area...
if (pointToCharLine(point, pos)) { if (pointToCharLine(point, pos) && highlighter()) {
if (!pMainWindow->debugger()->executing() if (!pMainWindow->debugger()->executing()
&& getSyntaxIssueAtPosition(pos)) { && getSyntaxIssueAtPosition(pos)) {
return TipType::Error; return TipType::Error;
@ -3628,6 +3633,9 @@ void Editor::updateFunctionTip(bool showTip)
if (!highlighter()) if (!highlighter())
return; return;
if (!mParser || !mParser->enabled())
return;
bool isFunction = false; bool isFunction = false;
auto action = finally([&isFunction]{ auto action = finally([&isFunction]{
if (!isFunction) if (!isFunction)

View File

@ -4424,10 +4424,12 @@ void MainWindow::onEditorContextMenu(const QPoint& pos)
//mouse on editing area //mouse on editing area
menu.addAction(ui->actionCompile_Run); menu.addAction(ui->actionCompile_Run);
menu.addAction(ui->actionDebug); menu.addAction(ui->actionDebug);
if (editor->parser() && editor->parser()->enabled()) {
menu.addSeparator(); menu.addSeparator();
menu.addAction(ui->actionGoto_Declaration); menu.addAction(ui->actionGoto_Declaration);
menu.addAction(ui->actionGoto_Definition); menu.addAction(ui->actionGoto_Definition);
menu.addAction(ui->actionFind_references); menu.addAction(ui->actionFind_references);
}
menu.addSeparator(); menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder); menu.addAction(ui->actionOpen_Containing_Folder);
@ -4454,9 +4456,11 @@ void MainWindow::onEditorContextMenu(const QPoint& pos)
menu.addAction(ui->actionFile_Properties); menu.addAction(ui->actionFile_Properties);
//these actions needs parser //these actions needs parser
if (editor->parser() && editor->parser()->enabled()) {
ui->actionGoto_Declaration->setEnabled(!editor->parser()->parsing()); ui->actionGoto_Declaration->setEnabled(!editor->parser()->parsing());
ui->actionGoto_Definition->setEnabled(!editor->parser()->parsing()); ui->actionGoto_Definition->setEnabled(!editor->parser()->parsing());
ui->actionFind_references->setEnabled(!editor->parser()->parsing()); ui->actionFind_references->setEnabled(!editor->parser()->parsing());
}
} else { } else {
//mouse on gutter //mouse on gutter