- 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
- enhancement: switch header/source in editor's context menu
- 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

View File

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

View File

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