2022-01-10 09:42:23 +08:00
|
|
|
|
/*
|
2021-12-26 23:18:28 +08:00
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2021-04-06 23:10:57 +08:00
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QFileInfo>
|
2021-04-09 17:48:25 +08:00
|
|
|
|
#include <QFont>
|
2021-04-08 10:29:21 +08:00
|
|
|
|
#include <QTextCodec>
|
2021-04-07 22:44:08 +08:00
|
|
|
|
#include <QVariant>
|
2021-04-09 17:48:25 +08:00
|
|
|
|
#include <QWheelEvent>
|
2021-04-07 21:13:15 +08:00
|
|
|
|
#include <memory>
|
2021-04-08 10:29:21 +08:00
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "mainwindow.h"
|
2021-04-11 21:33:08 +08:00
|
|
|
|
#include "systemconsts.h"
|
2021-04-11 12:39:22 +08:00
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QDebug>
|
2021-06-12 22:36:23 +08:00
|
|
|
|
#include <QMimeData>
|
2021-05-24 00:41:00 +08:00
|
|
|
|
#include "qsynedit/highlighter/cpp.h"
|
2021-05-26 00:04:20 +08:00
|
|
|
|
#include "HighlighterManager.h"
|
2021-06-12 22:36:23 +08:00
|
|
|
|
#include "qsynedit/exporter/synrtfexporter.h"
|
|
|
|
|
#include "qsynedit/exporter/synhtmlexporter.h"
|
2021-06-19 22:58:35 +08:00
|
|
|
|
#include "qsynedit/Constants.h"
|
2021-06-12 22:36:23 +08:00
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
#include <QClipboard>
|
2021-06-24 16:05:19 +08:00
|
|
|
|
#include <QPainter>
|
2021-08-29 17:23:40 +08:00
|
|
|
|
#include <QToolTip>
|
2021-08-29 22:08:43 +08:00
|
|
|
|
#include <QApplication>
|
2021-09-03 10:30:08 +08:00
|
|
|
|
#include <QInputDialog>
|
2021-10-07 07:52:20 +08:00
|
|
|
|
#include <QPrinter>
|
|
|
|
|
#include <QPrintDialog>
|
|
|
|
|
#include <QTextDocument>
|
2021-10-24 13:03:54 +08:00
|
|
|
|
#include <QTextCodec>
|
2022-03-18 23:13:43 +08:00
|
|
|
|
#include <QScrollBar>
|
2021-06-24 16:05:19 +08:00
|
|
|
|
#include "iconsmanager.h"
|
2021-08-01 09:13:38 +08:00
|
|
|
|
#include "debugger.h"
|
2021-08-23 10:16:06 +08:00
|
|
|
|
#include "editorlist.h"
|
2021-08-29 17:23:40 +08:00
|
|
|
|
#include <QDebug>
|
2021-09-11 18:42:49 +08:00
|
|
|
|
#include "project.h"
|
2022-09-26 14:54:28 +08:00
|
|
|
|
#include <qt_utils/charsetinfo.h>
|
2021-04-07 21:13:15 +08:00
|
|
|
|
|
|
|
|
|
using namespace std;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
|
SaveException::SaveException(const QString& reason) {
|
|
|
|
|
mReason = reason;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
mReasonBuffer = mReason.toLocal8Bit();
|
2021-04-11 21:33:08 +08:00
|
|
|
|
}
|
|
|
|
|
SaveException::SaveException(const QString&& reason) {
|
|
|
|
|
mReason = reason;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
mReasonBuffer = mReason.toLocal8Bit();
|
2021-04-11 21:33:08 +08:00
|
|
|
|
}
|
|
|
|
|
const QString& SaveException::reason() const noexcept{
|
|
|
|
|
return mReason;
|
|
|
|
|
}
|
2021-08-29 10:14:07 +08:00
|
|
|
|
const char* SaveException::what() const noexcept {
|
|
|
|
|
return mReasonBuffer;
|
2021-04-11 21:33:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 09:47:34 +08:00
|
|
|
|
QHash<ParserLanguage,std::weak_ptr<CppParser>> Editor::mSharedParsers;
|
2022-10-27 15:18:57 +08:00
|
|
|
|
|
2021-06-19 22:58:35 +08:00
|
|
|
|
Editor::Editor(QWidget *parent):
|
2022-10-30 11:58:42 +08:00
|
|
|
|
Editor(parent,"untitled",ENCODING_AUTO_DETECT,nullptr,true,nullptr)
|
2021-06-19 22:58:35 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 17:48:25 +08:00
|
|
|
|
Editor::Editor(QWidget *parent, const QString& filename,
|
2021-04-08 10:29:21 +08:00
|
|
|
|
const QByteArray& encoding,
|
2022-10-09 22:19:18 +08:00
|
|
|
|
Project* pProject, bool isNew,
|
2021-04-06 23:10:57 +08:00
|
|
|
|
QTabWidget* parentPageControl):
|
2021-05-24 00:41:00 +08:00
|
|
|
|
SynEdit(parent),
|
2021-04-08 10:29:21 +08:00
|
|
|
|
mEncodingOption(encoding),
|
2021-10-23 17:32:03 +08:00
|
|
|
|
mFilename(QFileInfo(filename).absoluteFilePath()),
|
2021-06-20 14:30:47 +08:00
|
|
|
|
mParentPageControl(parentPageControl),
|
2022-10-09 22:19:18 +08:00
|
|
|
|
mProject(pProject),
|
2021-06-24 16:05:19 +08:00
|
|
|
|
mIsNew(isNew),
|
2021-09-13 22:45:50 +08:00
|
|
|
|
mSyntaxIssues(),
|
2022-01-04 16:50:54 +08:00
|
|
|
|
mSyntaxErrorColor(Qt::red),
|
2021-07-26 00:22:08 +08:00
|
|
|
|
mSyntaxWarningColor("orange"),
|
|
|
|
|
mLineCount(0),
|
2021-08-25 08:48:33 +08:00
|
|
|
|
mActiveBreakpointLine(-1),
|
2021-08-29 17:23:40 +08:00
|
|
|
|
mLastIdCharPressed(0),
|
|
|
|
|
mCurrentWord(),
|
2021-09-10 12:37:02 +08:00
|
|
|
|
mCurrentTipType(TipType::None),
|
2021-11-03 18:09:12 +08:00
|
|
|
|
mOldHighlightedWord(),
|
|
|
|
|
mCurrentHighlightedWord(),
|
2022-06-08 16:05:54 +08:00
|
|
|
|
mSaving(false),
|
|
|
|
|
mHoverModifiedLine(-1)
|
2021-04-06 23:10:57 +08:00
|
|
|
|
{
|
2022-10-19 19:43:48 +08:00
|
|
|
|
mHighlightCharPos1 = QSynedit::BufferCoord{0,0};
|
|
|
|
|
mHighlightCharPos2 = QSynedit::BufferCoord{0,0};
|
2021-11-04 00:38:40 +08:00
|
|
|
|
mCurrentLineModified = false;
|
2021-08-30 18:36:44 +08:00
|
|
|
|
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
2021-04-07 21:13:15 +08:00
|
|
|
|
if (mFilename.isEmpty()) {
|
2022-10-30 11:58:42 +08:00
|
|
|
|
mFilename = QString("untitled%1").arg(getNewFileNumber());
|
2021-04-07 21:13:15 +08:00
|
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
|
QFileInfo fileInfo(mFilename);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighter highlighter;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
if (!isNew) {
|
|
|
|
|
loadFile();
|
2021-06-07 11:02:03 +08:00
|
|
|
|
highlighter = highlighterManager.getHighlighter(mFilename);
|
2021-04-06 23:10:57 +08:00
|
|
|
|
} else {
|
2022-03-12 17:37:53 +08:00
|
|
|
|
mFileEncoding = ENCODING_ASCII;
|
2021-06-07 11:02:03 +08:00
|
|
|
|
highlighter=highlighterManager.getCppHighlighter();
|
2021-05-27 01:05:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (highlighter) {
|
|
|
|
|
setHighlighter(highlighter);
|
|
|
|
|
setUseCodeFolding(true);
|
|
|
|
|
} else {
|
|
|
|
|
setUseCodeFolding(false);
|
2021-04-06 23:10:57 +08:00
|
|
|
|
}
|
2021-04-09 17:48:25 +08:00
|
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (mProject) {
|
|
|
|
|
mParser = mProject->cppParser();
|
2021-08-23 17:27:17 +08:00
|
|
|
|
} else {
|
|
|
|
|
initParser();
|
|
|
|
|
}
|
2021-08-30 13:30:42 +08:00
|
|
|
|
|
2022-09-30 17:51:26 +08:00
|
|
|
|
if (shouldOpenInReadonly()) {
|
2021-08-30 13:30:42 +08:00
|
|
|
|
this->setModified(false);
|
|
|
|
|
setReadOnly(true);
|
|
|
|
|
}
|
2021-08-30 18:36:44 +08:00
|
|
|
|
|
2021-08-29 10:29:56 +08:00
|
|
|
|
mCompletionPopup = pMainWindow->completionPopup();
|
|
|
|
|
mHeaderCompletionPopup = pMainWindow->headerCompletionPopup();
|
2021-08-25 08:48:33 +08:00
|
|
|
|
|
2021-06-07 11:02:03 +08:00
|
|
|
|
applySettings();
|
2021-06-20 14:30:47 +08:00
|
|
|
|
applyColorScheme(pSettings->editor().colorScheme());
|
2021-06-10 09:34:59 +08:00
|
|
|
|
|
2021-10-02 10:05:14 +08:00
|
|
|
|
//Initialize User Code Template stuff;
|
|
|
|
|
mXOffsetSince =0;
|
|
|
|
|
mTabStopY=-1;
|
|
|
|
|
mTabStopBegin= -1;
|
|
|
|
|
mTabStopEnd= -1;
|
|
|
|
|
//mLineBeforeTabStop="";
|
|
|
|
|
//mLineAfterTabStop = "";
|
|
|
|
|
|
2021-06-10 09:34:59 +08:00
|
|
|
|
connect(this,&SynEdit::statusChanged,this,&Editor::onStatusChanged);
|
2022-10-27 07:42:05 +08:00
|
|
|
|
|
|
|
|
|
if (mParentPageControl)
|
|
|
|
|
connect(this,&SynEdit::gutterClicked,this,&Editor::onGutterClicked);
|
2021-08-23 17:27:17 +08:00
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
onStatusChanged(QSynedit::StatusChange::scOpenFile);
|
2021-08-30 13:30:42 +08:00
|
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_Hover,true);
|
2021-09-02 12:14:02 +08:00
|
|
|
|
|
|
|
|
|
connect(this,&SynEdit::linesDeleted,
|
|
|
|
|
this, &Editor::onLinesDeleted);
|
|
|
|
|
connect(this,&SynEdit::linesInserted,
|
|
|
|
|
this, &Editor::onLinesInserted);
|
2021-09-03 00:26:49 +08:00
|
|
|
|
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2022-10-27 07:42:05 +08:00
|
|
|
|
|
|
|
|
|
if (mParentPageControl)
|
|
|
|
|
connect(this, &QWidget::customContextMenuRequested,
|
2021-09-03 00:26:49 +08:00
|
|
|
|
pMainWindow, &MainWindow::onEditorContextMenu);
|
2021-10-21 19:33:11 +08:00
|
|
|
|
|
2021-11-12 12:40:47 +08:00
|
|
|
|
mCanAutoSave = false;
|
2021-10-22 16:43:53 +08:00
|
|
|
|
if (isNew && parentPageControl!=nullptr) {
|
|
|
|
|
QString fileTemplate = pMainWindow->codeSnippetManager()->newFileTemplate();
|
|
|
|
|
if (!fileTemplate.isEmpty()) {
|
|
|
|
|
insertCodeSnippet(fileTemplate);
|
2022-06-23 20:39:00 +08:00
|
|
|
|
setCaretPosition(1,1);
|
2021-11-12 12:40:47 +08:00
|
|
|
|
mCanAutoSave = true;
|
2021-10-22 16:43:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-27 07:42:05 +08:00
|
|
|
|
if (!isNew && parentPageControl) {
|
2021-10-22 16:43:53 +08:00
|
|
|
|
resetBookmarks();
|
|
|
|
|
resetBreakpoints();
|
|
|
|
|
}
|
2022-10-27 07:42:05 +08:00
|
|
|
|
|
2021-11-07 22:34:19 +08:00
|
|
|
|
mStatementColors = pMainWindow->statementColors();
|
2022-10-27 07:42:05 +08:00
|
|
|
|
if (mParentPageControl) {
|
2022-01-24 20:59:02 +08:00
|
|
|
|
mParentPageControl->addTab(this,"");
|
|
|
|
|
updateCaption();
|
|
|
|
|
}
|
2022-10-27 07:42:05 +08:00
|
|
|
|
|
2022-04-16 20:14:47 +08:00
|
|
|
|
if (mParentPageControl==nullptr) {
|
|
|
|
|
setExtraKeystrokes();
|
|
|
|
|
}
|
2022-10-27 07:42:05 +08:00
|
|
|
|
|
|
|
|
|
if (mParentPageControl)
|
|
|
|
|
connect(&mFunctionTipTimer, &QTimer::timeout,
|
2022-03-10 12:15:44 +08:00
|
|
|
|
this, &Editor::onFunctionTipsTimer);
|
2022-03-18 23:13:43 +08:00
|
|
|
|
|
|
|
|
|
connect(horizontalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
|
this, &Editor::onScrollBarValueChanged);
|
|
|
|
|
connect(verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
|
this, &Editor::onScrollBarValueChanged);
|
2021-04-07 22:44:08 +08:00
|
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
|
|
2021-04-07 22:44:08 +08:00
|
|
|
|
Editor::~Editor() {
|
2022-10-10 18:05:18 +08:00
|
|
|
|
//qDebug()<<"editor "<<mFilename<<" deleted";
|
2021-04-06 23:10:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 17:32:03 +08:00
|
|
|
|
void Editor::loadFile(QString filename) {
|
2021-09-17 07:44:03 +08:00
|
|
|
|
if (filename.isEmpty()) {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
this->document()->loadFromFile(mFilename,mEncodingOption,mFileEncoding);
|
2021-09-17 07:44:03 +08:00
|
|
|
|
} else {
|
2021-10-23 17:32:03 +08:00
|
|
|
|
filename = QFileInfo(filename).absoluteFilePath();
|
2022-04-19 21:18:41 +08:00
|
|
|
|
this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding);
|
2021-09-16 23:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
//this->setModified(false);
|
2021-05-24 18:11:07 +08:00
|
|
|
|
updateCaption();
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl)
|
|
|
|
|
pMainWindow->updateForEncodingInfo(this);
|
2021-08-30 18:36:44 +08:00
|
|
|
|
switch(getFileType(mFilename)) {
|
|
|
|
|
case FileType::CppSource:
|
|
|
|
|
mUseCppSyntax = true;
|
|
|
|
|
break;
|
|
|
|
|
case FileType::CSource:
|
|
|
|
|
mUseCppSyntax = false;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
|
|
|
|
}
|
2022-10-10 18:05:18 +08:00
|
|
|
|
if (highlighter()) {
|
2022-10-18 12:24:59 +08:00
|
|
|
|
reparse(true);
|
2021-09-02 12:14:02 +08:00
|
|
|
|
if (pSettings->editor().syntaxCheckWhenLineChanged()) {
|
|
|
|
|
checkSyntaxInBack();
|
2021-08-31 14:40:41 +08:00
|
|
|
|
}
|
2021-10-03 17:18:43 +08:00
|
|
|
|
reparseTodo();
|
2021-08-31 14:40:41 +08:00
|
|
|
|
}
|
2021-09-17 07:44:03 +08:00
|
|
|
|
mLastIdCharPressed = 0;
|
2021-04-07 21:13:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 17:32:03 +08:00
|
|
|
|
void Editor::saveFile(QString filename) {
|
2021-04-07 21:13:15 +08:00
|
|
|
|
QFile file(filename);
|
2022-04-13 16:42:23 +08:00
|
|
|
|
QByteArray encoding = mFileEncoding;
|
2022-04-13 23:15:31 +08:00
|
|
|
|
if (mEncodingOption!=ENCODING_AUTO_DETECT || mFileEncoding==ENCODING_ASCII)
|
2022-04-13 16:42:23 +08:00
|
|
|
|
encoding = mEncodingOption;
|
2022-10-26 16:23:34 +08:00
|
|
|
|
|
2022-04-19 21:18:41 +08:00
|
|
|
|
this->document()->saveToFile(file,encoding,
|
2022-03-12 17:37:53 +08:00
|
|
|
|
pSettings->editor().defaultEncoding(),
|
2021-10-24 13:03:54 +08:00
|
|
|
|
mFileEncoding);
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (isVisible() && mParentPageControl)
|
2022-10-26 16:23:34 +08:00
|
|
|
|
pMainWindow->updateForEncodingInfo(this);
|
2022-10-09 22:19:18 +08:00
|
|
|
|
emit fileSaved(filename, inProject());
|
2021-06-12 22:36:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::convertToEncoding(const QByteArray &encoding)
|
|
|
|
|
{
|
|
|
|
|
mEncodingOption = encoding;
|
|
|
|
|
setModified(true);
|
|
|
|
|
save();
|
2021-04-06 23:10:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 10:16:06 +08:00
|
|
|
|
bool Editor::save(bool force, bool doReparse) {
|
2021-09-17 07:44:03 +08:00
|
|
|
|
if (this->mIsNew && !force) {
|
2021-04-11 12:39:22 +08:00
|
|
|
|
return saveAs();
|
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
//is this file writable;
|
2021-11-02 01:07:37 +08:00
|
|
|
|
pMainWindow->fileSystemWatcher()->removePath(mFilename);
|
|
|
|
|
try {
|
2022-10-25 10:13:51 +08:00
|
|
|
|
if (pSettings->editor().autoFormatWhenSaved()) {
|
|
|
|
|
reformat(false);
|
|
|
|
|
}
|
2021-11-02 01:07:37 +08:00
|
|
|
|
saveFile(mFilename);
|
|
|
|
|
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
|
|
|
|
setModified(false);
|
|
|
|
|
mIsNew = false;
|
2022-10-26 16:23:34 +08:00
|
|
|
|
updateCaption();
|
2021-11-02 01:07:37 +08:00
|
|
|
|
} catch (SaveException& exception) {
|
|
|
|
|
if (!force) {
|
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
|
|
|
|
exception.reason());
|
2021-04-11 21:33:08 +08:00
|
|
|
|
}
|
2021-11-02 01:07:37 +08:00
|
|
|
|
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
|
|
|
|
return false;
|
2021-04-11 12:39:22 +08:00
|
|
|
|
}
|
2021-04-08 10:29:21 +08:00
|
|
|
|
|
2022-10-21 12:43:02 +08:00
|
|
|
|
if (doReparse && isVisible()) {
|
2022-10-18 12:24:59 +08:00
|
|
|
|
reparse(false);
|
2022-11-07 17:03:46 +08:00
|
|
|
|
if (pSettings->editor().syntaxCheckWhenSave())
|
|
|
|
|
checkSyntaxInBack();
|
2022-10-21 12:43:02 +08:00
|
|
|
|
reparseTodo();
|
|
|
|
|
}
|
2021-04-11 12:39:22 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-18 10:47:35 +08:00
|
|
|
|
bool Editor::saveAs(const QString &name, bool fromProject){
|
|
|
|
|
QString newName = name;
|
2022-01-02 10:37:00 +08:00
|
|
|
|
QString oldName = mFilename;
|
|
|
|
|
bool firstSave = isNew();
|
2021-09-18 10:47:35 +08:00
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
|
QString selectedFileFilter;
|
2021-10-19 22:41:38 +08:00
|
|
|
|
QString defaultExt;
|
|
|
|
|
if (pSettings->editor().defaultFileCpp()) {
|
2021-09-18 10:47:35 +08:00
|
|
|
|
selectedFileFilter = pSystemConsts->defaultCPPFileFilter();
|
2021-10-19 22:41:38 +08:00
|
|
|
|
defaultExt = "cpp";
|
|
|
|
|
} else {
|
2021-09-18 10:47:35 +08:00
|
|
|
|
selectedFileFilter = pSystemConsts->defaultCFileFilter();
|
2021-10-19 22:41:38 +08:00
|
|
|
|
defaultExt = "c";
|
|
|
|
|
}
|
2021-09-18 10:47:35 +08:00
|
|
|
|
QFileDialog dialog(this,tr("Save As"),extractFilePath(mFilename),
|
|
|
|
|
pSystemConsts->defaultFileFilters().join(";;"));
|
|
|
|
|
dialog.selectNameFilter(selectedFileFilter);
|
2021-10-19 22:41:38 +08:00
|
|
|
|
dialog.setDefaultSuffix(defaultExt);
|
2021-09-18 10:47:35 +08:00
|
|
|
|
dialog.selectFile(mFilename);
|
|
|
|
|
dialog.setFileMode(QFileDialog::AnyFile);
|
2021-10-19 22:41:38 +08:00
|
|
|
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
2021-09-18 10:47:35 +08:00
|
|
|
|
connect(&dialog, &QFileDialog::filterSelected,
|
|
|
|
|
[&dialog](const QString &filter){
|
|
|
|
|
int pos = filter.indexOf("*.");
|
|
|
|
|
if (pos>=0) {
|
|
|
|
|
QString suffix;
|
|
|
|
|
pos+=2;
|
|
|
|
|
while (pos<filter.length()) {
|
|
|
|
|
if (filter[pos] == ';' || filter[pos] ==' ' || filter[pos] == ')')
|
|
|
|
|
break;
|
|
|
|
|
suffix+=filter[pos];
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
dialog.setDefaultSuffix(suffix);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-09-17 07:44:03 +08:00
|
|
|
|
|
2021-11-06 14:49:11 +08:00
|
|
|
|
if (dialog.exec()!=QFileDialog::Accepted) {
|
2021-09-18 10:47:35 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
newName = dialog.selectedFiles()[0];
|
2021-11-06 14:49:11 +08:00
|
|
|
|
QDir::setCurrent(extractFileDir(newName));
|
2021-04-11 12:39:22 +08:00
|
|
|
|
}
|
2021-09-17 13:35:50 +08:00
|
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
|
if (pMainWindow->editorList()->getOpenedEditorByFilename(newName)) {
|
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
|
|
|
|
tr("File %1 already openned!").arg(newName));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-09-17 13:35:50 +08:00
|
|
|
|
// Update project information
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (mProject && !fromProject) {
|
|
|
|
|
PProjectUnit unit = mProject->findUnit(newName);
|
2022-10-08 23:30:30 +08:00
|
|
|
|
if (!unit) {
|
2022-10-09 22:19:18 +08:00
|
|
|
|
setProject(nullptr);
|
2021-09-17 13:35:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-24 15:17:31 +08:00
|
|
|
|
clearSyntaxIssues();
|
2021-08-31 14:40:41 +08:00
|
|
|
|
pMainWindow->fileSystemWatcher()->removePath(mFilename);
|
2022-11-07 21:44:12 +08:00
|
|
|
|
if (pSettings->codeCompletion().enabled() && mParser && !inProject()) {
|
2021-08-31 14:40:41 +08:00
|
|
|
|
mParser->invalidateFile(mFilename);
|
2022-07-28 13:51:38 +08:00
|
|
|
|
}
|
2022-10-25 10:13:51 +08:00
|
|
|
|
|
|
|
|
|
if (pSettings->editor().autoFormatWhenSaved()) {
|
|
|
|
|
reformat(false);
|
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
try {
|
|
|
|
|
mFilename = newName;
|
2021-06-12 22:36:23 +08:00
|
|
|
|
saveFile(mFilename);
|
2021-04-11 21:33:08 +08:00
|
|
|
|
mIsNew = false;
|
|
|
|
|
setModified(false);
|
|
|
|
|
} catch (SaveException& exception) {
|
2021-06-21 11:21:26 +08:00
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
2021-04-11 21:33:08 +08:00
|
|
|
|
exception.reason());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (mProject && !fromProject) {
|
|
|
|
|
mProject->associateEditor(this);
|
2022-03-15 20:17:47 +08:00
|
|
|
|
}
|
2021-08-31 14:40:41 +08:00
|
|
|
|
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
2021-08-30 22:05:45 +08:00
|
|
|
|
switch(getFileType(mFilename)) {
|
|
|
|
|
case FileType::CppSource:
|
|
|
|
|
mUseCppSyntax = true;
|
|
|
|
|
break;
|
|
|
|
|
case FileType::CSource:
|
|
|
|
|
mUseCppSyntax = false;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
|
|
|
|
}
|
2021-04-11 12:39:22 +08:00
|
|
|
|
|
2021-08-31 14:40:41 +08:00
|
|
|
|
//update (reassign highlighter)
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename);
|
2021-08-31 14:40:41 +08:00
|
|
|
|
if (newHighlighter) {
|
|
|
|
|
setUseCodeFolding(true);
|
|
|
|
|
} else {
|
|
|
|
|
setUseCodeFolding(false);
|
|
|
|
|
}
|
|
|
|
|
setHighlighter(newHighlighter);
|
2022-11-23 14:57:26 +08:00
|
|
|
|
if (!newHighlighter || newHighlighter->language() != QSynedit::HighlighterLanguage::Cpp) {
|
2021-09-17 13:35:50 +08:00
|
|
|
|
mSyntaxIssues.clear();
|
|
|
|
|
}
|
2021-08-31 14:40:41 +08:00
|
|
|
|
applyColorScheme(pSettings->editor().colorScheme());
|
|
|
|
|
|
2022-11-07 21:44:12 +08:00
|
|
|
|
if (!inProject())
|
|
|
|
|
reparse(false);
|
2021-08-31 14:40:41 +08:00
|
|
|
|
|
2022-11-07 17:03:46 +08:00
|
|
|
|
if (pSettings->editor().syntaxCheckWhenSave())
|
|
|
|
|
checkSyntaxInBack();
|
2022-11-07 21:44:12 +08:00
|
|
|
|
|
|
|
|
|
if (!inProject())
|
|
|
|
|
reparseTodo();
|
2021-10-09 11:33:23 +08:00
|
|
|
|
|
2022-09-30 17:51:26 +08:00
|
|
|
|
if (!shouldOpenInReadonly()) {
|
2021-09-28 10:01:13 +08:00
|
|
|
|
setReadOnly(false);
|
|
|
|
|
}
|
2022-10-26 09:33:45 +08:00
|
|
|
|
updateCaption();
|
2022-01-02 10:37:00 +08:00
|
|
|
|
|
|
|
|
|
emit renamed(oldName, newName , firstSave);
|
2021-04-08 10:29:21 +08:00
|
|
|
|
return true;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
}
|
2021-04-08 10:29:21 +08:00
|
|
|
|
|
2021-04-12 00:00:29 +08:00
|
|
|
|
void Editor::activate()
|
|
|
|
|
{
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl)
|
2021-06-19 22:58:35 +08:00
|
|
|
|
mParentPageControl->setCurrentWidget(this);
|
|
|
|
|
setFocus();
|
2021-04-12 00:00:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
|
const QByteArray& Editor::encodingOption() const noexcept{
|
2021-04-08 10:29:21 +08:00
|
|
|
|
return mEncodingOption;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
void Editor::setEncodingOption(const QByteArray& encoding) noexcept{
|
2022-01-24 09:24:43 +08:00
|
|
|
|
if (mEncodingOption == encoding)
|
|
|
|
|
return;
|
2021-04-08 10:29:21 +08:00
|
|
|
|
mEncodingOption = encoding;
|
2021-06-20 09:27:37 +08:00
|
|
|
|
if (!isNew())
|
|
|
|
|
loadFile();
|
2022-10-26 22:39:40 +08:00
|
|
|
|
else if (mParentPageControl)
|
2022-10-26 09:33:45 +08:00
|
|
|
|
pMainWindow->updateForEncodingInfo(this);
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (mProject) {
|
|
|
|
|
PProjectUnit unit = mProject->findUnit(this);
|
|
|
|
|
if (unit) {
|
|
|
|
|
unit->setEncoding(mEncodingOption);
|
2021-09-14 12:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-08 10:29:21 +08:00
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
const QByteArray& Editor::fileEncoding() const noexcept{
|
2021-04-06 23:10:57 +08:00
|
|
|
|
return mFileEncoding;
|
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
const QString& Editor::filename() const noexcept{
|
2021-04-06 23:10:57 +08:00
|
|
|
|
return mFilename;
|
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
bool Editor::inProject() const noexcept{
|
2022-10-09 22:19:18 +08:00
|
|
|
|
return mProject!=nullptr;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
}
|
2021-04-11 21:33:08 +08:00
|
|
|
|
bool Editor::isNew() const noexcept {
|
2021-04-06 23:10:57 +08:00
|
|
|
|
return mIsNew;
|
|
|
|
|
}
|
2021-04-09 17:48:25 +08:00
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
|
QTabWidget* Editor::pageControl() noexcept{
|
2021-04-09 17:48:25 +08:00
|
|
|
|
return mParentPageControl;
|
|
|
|
|
}
|
2021-10-13 11:32:59 +08:00
|
|
|
|
static int findWidgetInPageControl(QTabWidget* pageControl, QWidget* child) {
|
|
|
|
|
for (int i=0;i<pageControl->count();i++) {
|
|
|
|
|
if (pageControl->widget(i)==child)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
void Editor::setPageControl(QTabWidget *newPageControl)
|
|
|
|
|
{
|
|
|
|
|
if (mParentPageControl==newPageControl)
|
|
|
|
|
return;
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl) {
|
2021-10-13 11:32:59 +08:00
|
|
|
|
int index = findWidgetInPageControl(mParentPageControl,this);
|
|
|
|
|
if (index>=0)
|
|
|
|
|
mParentPageControl->removeTab(index);
|
|
|
|
|
}
|
|
|
|
|
mParentPageControl= newPageControl;
|
|
|
|
|
if (newPageControl!=nullptr) {
|
|
|
|
|
mParentPageControl->addTab(this,"");
|
|
|
|
|
updateCaption();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-09 17:48:25 +08:00
|
|
|
|
|
2021-06-23 08:55:56 +08:00
|
|
|
|
void Editor::undoSymbolCompletion(int pos)
|
|
|
|
|
{
|
2022-11-23 11:41:16 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr;
|
|
|
|
|
QString token;
|
2021-06-23 08:55:56 +08:00
|
|
|
|
bool tokenFinished;
|
|
|
|
|
|
|
|
|
|
if (!highlighter())
|
|
|
|
|
return;
|
|
|
|
|
if (!pSettings->editor().removeSymbolPairs())
|
|
|
|
|
return;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if (!getHighlighterAttriAtRowCol(caretXY(), token, tokenFinished, attr))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return ;
|
|
|
|
|
//convert caret x to string index;
|
|
|
|
|
pos--;
|
|
|
|
|
|
|
|
|
|
if (pos<0 || pos+1>=lineText().length())
|
|
|
|
|
return;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
QChar DeletedChar = lineText().at(pos);
|
|
|
|
|
QChar NextChar = lineText().at(pos+1);
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((attr->tokenType() == QSynedit::TokenType::Character) && (DeletedChar != '\''))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
// if (attr->tokenType() == QSynedit::TokenType::StringEscapeSequence)
|
|
|
|
|
// return;
|
|
|
|
|
if (attr->tokenType() == QSynedit::TokenType::String) {
|
2021-06-23 08:55:56 +08:00
|
|
|
|
if ((DeletedChar!='"') && (DeletedChar!='('))
|
|
|
|
|
return;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((DeletedChar=='"') && (token!="\"\""))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((DeletedChar=='(') && (!token.startsWith("R\"")))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((DeletedChar == '\'') && (attr->tokenType() == QSynedit::TokenType::Number))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return;
|
|
|
|
|
if ((DeletedChar == '<') &&
|
2022-03-19 14:26:06 +08:00
|
|
|
|
!(mParser && mParser->isIncludeLine(lineText())))
|
2021-06-23 08:55:56 +08:00
|
|
|
|
return;
|
|
|
|
|
if ( (pSettings->editor().completeBracket() && (DeletedChar == '[') && (NextChar == ']')) ||
|
|
|
|
|
(pSettings->editor().completeParenthese() && (DeletedChar == '(') && (NextChar == ')')) ||
|
|
|
|
|
(pSettings->editor().completeGlobalInclude() && (DeletedChar == '<') && (NextChar == '>')) ||
|
|
|
|
|
(pSettings->editor().completeBrace() && (DeletedChar == '{') && (NextChar == '}')) ||
|
|
|
|
|
(pSettings->editor().completeSingleQuote() && (DeletedChar == '\'') && (NextChar == '\'')) ||
|
|
|
|
|
(pSettings->editor().completeDoubleQuote() && (DeletedChar == '\"') && (NextChar == '\"'))) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteChar);
|
2021-06-23 08:55:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 17:48:25 +08:00
|
|
|
|
void Editor::wheelEvent(QWheelEvent *event) {
|
|
|
|
|
if ( (event->modifiers() & Qt::ControlModifier)!=0) {
|
2021-06-12 22:36:23 +08:00
|
|
|
|
int size = pSettings->editor().fontSize();
|
2021-04-09 17:48:25 +08:00
|
|
|
|
if (event->angleDelta().y()>0) {
|
2021-06-12 22:36:23 +08:00
|
|
|
|
size = std::min(99,size+1);
|
|
|
|
|
pSettings->editor().setFontSize(size);
|
2022-02-03 07:45:59 +08:00
|
|
|
|
pSettings->editor().save();
|
2021-06-12 22:36:23 +08:00
|
|
|
|
pMainWindow->updateEditorSettings();
|
2021-06-09 17:12:23 +08:00
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
2021-07-01 19:44:38 +08:00
|
|
|
|
} else if (event->angleDelta().y()<0) {
|
2021-06-12 22:36:23 +08:00
|
|
|
|
size = std::max(2,size-1);
|
|
|
|
|
pSettings->editor().setFontSize(size);
|
2022-02-03 07:45:59 +08:00
|
|
|
|
pSettings->editor().save();
|
2021-06-12 22:36:23 +08:00
|
|
|
|
pMainWindow->updateEditorSettings();
|
2021-06-09 17:12:23 +08:00
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
2021-04-09 17:48:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-09 17:12:23 +08:00
|
|
|
|
SynEdit::wheelEvent(event);
|
2021-04-08 10:29:21 +08:00
|
|
|
|
}
|
2021-04-11 12:39:22 +08:00
|
|
|
|
|
2021-06-12 22:36:23 +08:00
|
|
|
|
void Editor::focusInEvent(QFocusEvent *event)
|
|
|
|
|
{
|
|
|
|
|
SynEdit::focusInEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::focusOutEvent(QFocusEvent *event)
|
|
|
|
|
{
|
|
|
|
|
SynEdit::focusOutEvent(event);
|
2021-09-26 12:19:46 +08:00
|
|
|
|
//pMainWindow->updateClassBrowserForEditor(nullptr);
|
2021-09-25 21:34:10 +08:00
|
|
|
|
pMainWindow->functionTip()->hide();
|
2021-06-12 22:36:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 16:25:21 +08:00
|
|
|
|
void Editor::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
bool handled = false;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
auto action = finally([&,this]{
|
|
|
|
|
if (!handled) {
|
|
|
|
|
SynEdit::keyPressEvent(event);
|
|
|
|
|
} else {
|
|
|
|
|
event->accept();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (readOnly())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (event->key()) {
|
2021-10-02 10:05:14 +08:00
|
|
|
|
case Qt::Key_Return:
|
2021-10-09 09:09:05 +08:00
|
|
|
|
case Qt::Key_Enter:
|
2021-10-02 10:05:14 +08:00
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
if (mTabStopBegin>=0) { // editing user code template
|
|
|
|
|
handled = true;
|
|
|
|
|
mTabStopBegin = -1;
|
|
|
|
|
invalidateLine(caretY());
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
} else {
|
|
|
|
|
QString s = lineText().mid(0,caretX()-1).trimmed();
|
|
|
|
|
if (s=="/**") { //javadoc style docstring
|
|
|
|
|
s = lineText().mid(caretX()-1).trimmed();
|
|
|
|
|
if (s=="*/") {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p = caretXY();
|
2021-10-02 10:05:14 +08:00
|
|
|
|
setBlockBegin(p);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch = lineText().length()+1;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
setBlockEnd(p);
|
|
|
|
|
setSelText("");
|
|
|
|
|
}
|
|
|
|
|
handled = true;
|
|
|
|
|
QStringList insertString;
|
2021-10-02 10:05:48 +08:00
|
|
|
|
insertString.append("");
|
2021-11-08 09:19:50 +08:00
|
|
|
|
PStatement function;
|
|
|
|
|
if (mParser)
|
|
|
|
|
function = mParser->findFunctionAt(mFilename,caretY()+1);
|
2021-10-02 13:29:45 +08:00
|
|
|
|
if (function) {
|
|
|
|
|
QStringList params;
|
|
|
|
|
QString funcName = function->command;
|
|
|
|
|
bool isVoid = (function->type == "void");
|
|
|
|
|
foreach (const PStatement& child, function->children) {
|
|
|
|
|
if (child->kind == StatementKind::skParameter)
|
|
|
|
|
params.append(child->command);
|
|
|
|
|
}
|
|
|
|
|
insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS);
|
2021-10-03 09:57:19 +08:00
|
|
|
|
if (!params.isEmpty())
|
|
|
|
|
insertString.append(" * ");
|
2021-10-02 13:29:45 +08:00
|
|
|
|
foreach (const QString& param, params) {
|
|
|
|
|
insertString.append(QString(" * @param %1 %2")
|
|
|
|
|
.arg(param, USER_CODE_IN_INSERT_POS));
|
|
|
|
|
}
|
|
|
|
|
if (!isVoid) {
|
|
|
|
|
insertString.append(" * ");
|
|
|
|
|
insertString.append(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
|
|
|
|
|
}
|
2021-11-07 10:48:09 +08:00
|
|
|
|
insertString.append(" */");
|
2021-10-03 09:57:19 +08:00
|
|
|
|
// } else if (caretY()==1) { /* file header */
|
|
|
|
|
// insertString.append(QString(" * @file %1<SOURCEPATH>%2")
|
|
|
|
|
// .arg(USER_CODE_IN_REPL_POS_BEGIN)
|
|
|
|
|
// .arg(USER_CODE_IN_REPL_POS_END));
|
|
|
|
|
// insertString.append(QString(" * @brief: ")+ USER_CODE_IN_INSERT_POS);
|
|
|
|
|
// insertString.append(QString(" * @version: ")+ USER_CODE_IN_INSERT_POS);
|
|
|
|
|
// insertString.append(QString(" * @copyright: ")+ USER_CODE_IN_INSERT_POS);
|
|
|
|
|
// insertString.append(QString(" * @author: ")+ USER_CODE_IN_INSERT_POS);
|
|
|
|
|
// insertString.append(" * @date: <DATETIME>");
|
|
|
|
|
// insertString.append(" * ");
|
|
|
|
|
// insertString.append(" **/");
|
2021-10-02 13:29:45 +08:00
|
|
|
|
} else {
|
|
|
|
|
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
|
2021-11-07 10:48:09 +08:00
|
|
|
|
insertString.append(" */");
|
2021-10-02 13:29:45 +08:00
|
|
|
|
}
|
2021-11-12 10:51:00 +08:00
|
|
|
|
insertCodeSnippet(linesToText(insertString));
|
2021-10-02 13:29:45 +08:00
|
|
|
|
} else if (highlighter()
|
|
|
|
|
&& caretY()>=2
|
|
|
|
|
&& highlighter()->isLastLineCommentNotFinished(
|
2022-04-19 21:18:41 +08:00
|
|
|
|
document()->ranges(caretY()-2).state)) {
|
2021-11-12 10:51:00 +08:00
|
|
|
|
s=trimLeft(lineText());
|
2021-10-02 13:29:45 +08:00
|
|
|
|
if (s.startsWith("* ")) {
|
|
|
|
|
handled = true;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
int right = document()->getString(caretY()-1).length()-caretX();
|
2021-10-03 08:25:28 +08:00
|
|
|
|
s=lineBreak()+"* ";
|
2021-10-02 13:29:45 +08:00
|
|
|
|
insertString(s,false);
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p = caretXY();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.line++;
|
|
|
|
|
p.ch = document()->getString(p.line-1).length()+1;
|
2021-11-07 01:07:41 +08:00
|
|
|
|
if (right>0) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch -=right+1;
|
2021-11-07 01:07:41 +08:00
|
|
|
|
}
|
2021-10-02 13:29:45 +08:00
|
|
|
|
setCaretXY(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
case Qt::Key_Escape: // Update function tip
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
if (mTabStopBegin>=0) {
|
|
|
|
|
mTabStopBegin = -1;
|
2022-03-02 11:31:03 +08:00
|
|
|
|
setBlockEnd(caretXY());
|
2021-10-02 13:29:45 +08:00
|
|
|
|
invalidateLine(caretY());
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
}
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
return;
|
|
|
|
|
case Qt::Key_Tab:
|
2022-04-16 20:14:47 +08:00
|
|
|
|
handled = true;
|
2021-10-06 23:35:45 +08:00
|
|
|
|
tab();
|
2021-10-02 13:29:45 +08:00
|
|
|
|
return;
|
2022-04-16 20:14:47 +08:00
|
|
|
|
case Qt::Key_Backtab:
|
|
|
|
|
handled = true;
|
|
|
|
|
shifttab();
|
|
|
|
|
return;
|
2021-10-02 13:29:45 +08:00
|
|
|
|
case Qt::Key_Up:
|
|
|
|
|
if (pMainWindow->functionTip()->isVisible()) {
|
|
|
|
|
handled = true;
|
|
|
|
|
pMainWindow->functionTip()->previousTip();
|
|
|
|
|
} else {
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
case Qt::Key_Down:
|
|
|
|
|
if (pMainWindow->functionTip()->isVisible()) {
|
|
|
|
|
handled = true;
|
|
|
|
|
pMainWindow->functionTip()->nextTip();
|
|
|
|
|
} else {
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
}
|
|
|
|
|
return;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
|
// remove completed character
|
|
|
|
|
mLastIdCharPressed = 0;
|
2021-10-02 13:29:45 +08:00
|
|
|
|
if (!selAvail()) {
|
|
|
|
|
undoSymbolCompletion(caretX());
|
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
return;
|
|
|
|
|
case Qt::Key_Backspace:
|
|
|
|
|
// remove completed character
|
|
|
|
|
mLastIdCharPressed = 0;
|
2021-10-02 13:29:45 +08:00
|
|
|
|
if (!selAvail()) {
|
|
|
|
|
undoSymbolCompletion(caretX()-1);
|
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString t = event->text();
|
|
|
|
|
if (t.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (activeSelectionMode()==QSynedit::SelectionMode::Column)
|
2022-03-25 12:59:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-08-25 08:48:33 +08:00
|
|
|
|
QChar ch = t[0];
|
|
|
|
|
if (isIdentChar(ch)) {
|
|
|
|
|
mLastIdCharPressed++;
|
2021-08-30 16:59:08 +08:00
|
|
|
|
if (pSettings->codeCompletion().enabled()
|
|
|
|
|
&& pSettings->codeCompletion().showCompletionWhileInput() ) {
|
2022-01-10 21:46:03 +08:00
|
|
|
|
if (mParser && mParser->isIncludeLine(lineText())
|
|
|
|
|
&& mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) {
|
|
|
|
|
// is a #include line
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
2022-01-10 21:46:03 +08:00
|
|
|
|
showHeaderCompletion(false);
|
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
|
|
|
|
} else if (mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()){
|
|
|
|
|
QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY());
|
2022-11-25 10:01:10 +08:00
|
|
|
|
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (mParser && !lastWord.isEmpty()) {
|
2022-11-25 10:01:10 +08:00
|
|
|
|
if (lastWord == "using") {
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
|
|
|
|
showCompletion(lastWord,false, CodeCompletionType::ComplexKeyword);
|
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
2022-11-27 13:32:14 +08:00
|
|
|
|
} else if (lastWord == "namespace") {
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
|
|
|
|
showCompletion(lastWord,false, CodeCompletionType::Namespaces);
|
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
2022-11-25 10:01:10 +08:00
|
|
|
|
} else if (CppTypeKeywords.contains(lastWord)) {
|
2022-11-10 13:35:13 +08:00
|
|
|
|
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
|
|
|
|
|
while(currentScope && currentScope->kind==StatementKind::skBlock) {
|
|
|
|
|
currentScope = currentScope->parentScope.lock();
|
|
|
|
|
}
|
|
|
|
|
if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
|
|
|
|
|
//may define a function
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
|
|
|
|
showCompletion(lastWord,false,CodeCompletionType::FunctionWithoutDefinition);
|
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-10 21:46:03 +08:00
|
|
|
|
if (lastWord == "long" ||
|
|
|
|
|
lastWord == "short" ||
|
|
|
|
|
lastWord == "signed" ||
|
|
|
|
|
lastWord == "unsigned"
|
|
|
|
|
) {
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
2022-11-25 10:01:10 +08:00
|
|
|
|
showCompletion(lastWord,false, CodeCompletionType::ComplexKeyword);
|
2022-01-10 21:46:03 +08:00
|
|
|
|
handled=true;
|
2021-08-30 16:59:08 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-10 09:05:34 +08:00
|
|
|
|
|
|
|
|
|
|
2022-01-10 21:46:03 +08:00
|
|
|
|
//last word is a type keyword, this is a var or param define, and dont show suggestion
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PStatement statement = mParser->findStatementOf(
|
|
|
|
|
mFilename,
|
|
|
|
|
lastWord,
|
|
|
|
|
caretY());
|
2022-01-27 20:31:44 +08:00
|
|
|
|
StatementKind kind = getKindOfStatement(statement);
|
2022-01-10 21:46:03 +08:00
|
|
|
|
if (kind == StatementKind::skClass
|
|
|
|
|
|| kind == StatementKind::skEnumClassType
|
|
|
|
|
|| kind == StatementKind::skEnumType
|
|
|
|
|
|| kind == StatementKind::skTypedef) {
|
2022-11-10 13:35:13 +08:00
|
|
|
|
|
|
|
|
|
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
|
|
|
|
|
while(currentScope && currentScope->kind==StatementKind::skBlock) {
|
|
|
|
|
currentScope = currentScope->parentScope.lock();
|
|
|
|
|
}
|
|
|
|
|
if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
|
|
|
|
|
//may define a function
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
|
|
|
|
showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition);
|
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 21:46:03 +08:00
|
|
|
|
//last word is a typedef/class/struct, this is a var or param define, and dont show suggestion
|
|
|
|
|
return;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
2021-08-18 13:42:32 +08:00
|
|
|
|
}
|
2022-11-10 13:35:13 +08:00
|
|
|
|
lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(caretXY());
|
|
|
|
|
if (!lastWord.isEmpty()) {
|
|
|
|
|
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
|
|
|
|
|
while(currentScope && currentScope->kind==StatementKind::skBlock) {
|
|
|
|
|
currentScope = currentScope->parentScope.lock();
|
|
|
|
|
}
|
|
|
|
|
if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
|
|
|
|
|
//may define a function
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
|
|
|
|
showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition);
|
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2022-01-10 21:46:03 +08:00
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
2021-06-23 08:55:56 +08:00
|
|
|
|
}
|
2021-08-30 16:59:08 +08:00
|
|
|
|
}
|
2021-06-21 16:25:21 +08:00
|
|
|
|
} else {
|
2021-08-25 08:48:33 +08:00
|
|
|
|
//preprocessor ?
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (mParser && (mLastIdCharPressed=0) && (ch=='#') && lineText().isEmpty()) {
|
2021-08-30 16:59:08 +08:00
|
|
|
|
if (pSettings->codeCompletion().enabled()
|
|
|
|
|
&& pSettings->codeCompletion().showCompletionWhileInput() ) {
|
|
|
|
|
mLastIdCharPressed++;
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2021-08-30 16:59:08 +08:00
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
|
|
|
|
//javadoc directive?
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (mParser && (mLastIdCharPressed=0) && (ch=='#') &&
|
2021-08-25 08:48:33 +08:00
|
|
|
|
lineText().trimmed().startsWith('*')) {
|
2021-08-30 16:59:08 +08:00
|
|
|
|
if (pSettings->codeCompletion().enabled()
|
|
|
|
|
&& pSettings->codeCompletion().showCompletionWhileInput() ) {
|
|
|
|
|
mLastIdCharPressed++;
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2021-08-30 16:59:08 +08:00
|
|
|
|
handled=true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
switch (ch.unicode()) {
|
|
|
|
|
case '"':
|
|
|
|
|
case '\'':
|
|
|
|
|
case ')':
|
|
|
|
|
case '{':
|
|
|
|
|
case '}':
|
|
|
|
|
case '[':
|
|
|
|
|
case ']':
|
|
|
|
|
case '<':
|
|
|
|
|
case '*':
|
|
|
|
|
handled = handleSymbolCompletion(ch);
|
|
|
|
|
return;
|
2022-04-13 16:42:23 +08:00
|
|
|
|
case '(': {
|
2022-04-22 15:55:39 +08:00
|
|
|
|
QChar nextCh = nextNonSpaceChar(caretY()-1,caretX()-1);
|
|
|
|
|
if (!isIdentChar(nextCh) && nextCh!='('
|
|
|
|
|
&& nextCh!='"' && nextCh!='\'' ){
|
2022-03-31 19:36:46 +08:00
|
|
|
|
handled = handleSymbolCompletion(ch);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2022-04-13 16:42:23 +08:00
|
|
|
|
}
|
2021-10-10 20:20:43 +08:00
|
|
|
|
case '>':
|
|
|
|
|
if ((caretX() <= 1) || lineText().isEmpty()
|
|
|
|
|
|| lineText()[caretX() - 2] != '-') {
|
|
|
|
|
handled = handleSymbolCompletion(ch);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
2021-06-21 16:25:21 +08:00
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
|
|
|
|
|
// Spawn code completion window if we are allowed to
|
2021-08-30 16:59:08 +08:00
|
|
|
|
if (pSettings->codeCompletion().enabled())
|
|
|
|
|
handled = handleCodeCompletion(ch);
|
2021-06-21 16:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 16:05:19 +08:00
|
|
|
|
void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y)
|
|
|
|
|
{
|
2021-12-23 00:24:52 +08:00
|
|
|
|
IconsManager::PPixmap icon;
|
2021-06-24 16:05:19 +08:00
|
|
|
|
|
2021-07-26 00:22:08 +08:00
|
|
|
|
if (mActiveBreakpointLine == aLine) {
|
2021-12-23 00:24:52 +08:00
|
|
|
|
icon = pIconsManager->getPixmap(IconsManager::GUTTER_ACTIVEBREAKPOINT);
|
2021-07-26 00:22:08 +08:00
|
|
|
|
} else if (hasBreakpoint(aLine)) {
|
2021-12-23 00:24:52 +08:00
|
|
|
|
icon = pIconsManager->getPixmap(IconsManager::GUTTER_BREAKPOINT);
|
2021-08-01 01:06:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
PSyntaxIssueList lst = getSyntaxIssuesAtLine(aLine);
|
|
|
|
|
if (lst) {
|
|
|
|
|
bool hasError=false;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
for (const PSyntaxIssue& issue : *lst) {
|
2021-08-01 01:06:43 +08:00
|
|
|
|
if (issue->issueType == CompileIssueType::Error) {
|
|
|
|
|
hasError = true;
|
|
|
|
|
break;;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasError) {
|
2021-12-23 00:24:52 +08:00
|
|
|
|
icon = pIconsManager->getPixmap(IconsManager::GUTTER_SYNTAX_ERROR);
|
2021-08-01 01:06:43 +08:00
|
|
|
|
} else {
|
2021-12-23 00:24:52 +08:00
|
|
|
|
icon = pIconsManager->getPixmap(IconsManager::GUTTER_SYNTAX_WARNING);
|
2021-08-01 01:06:43 +08:00
|
|
|
|
}
|
2021-12-21 07:38:49 +08:00
|
|
|
|
} else if (hasBookmark(aLine)) {
|
2021-12-23 00:24:52 +08:00
|
|
|
|
icon = pIconsManager->getPixmap(IconsManager::GUTTER_BOOKMARK);
|
2021-10-21 17:31:25 +08:00
|
|
|
|
}
|
2021-06-24 16:05:19 +08:00
|
|
|
|
}
|
2021-12-20 09:36:18 +08:00
|
|
|
|
if (icon) {
|
|
|
|
|
X = 5;
|
|
|
|
|
Y += (this->textHeight() - icon->height()) / 2;
|
|
|
|
|
painter.drawPixmap(X,Y,*icon);
|
|
|
|
|
}
|
2021-06-24 16:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList)
|
2021-06-24 16:05:19 +08:00
|
|
|
|
{
|
|
|
|
|
areaList.clear();
|
2021-10-02 10:05:14 +08:00
|
|
|
|
if (mTabStopBegin>=0 && mTabStopY == Line) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PEditingArea p = make_shared<QSynedit::EditingArea>();
|
|
|
|
|
p->type = QSynedit::EditingAreaType::eatRectangleBorder;
|
2021-10-03 09:57:19 +08:00
|
|
|
|
// int spaceCount = leftSpaces(mLineBeforeTabStop);
|
|
|
|
|
// int spaceBefore = mLineBeforeTabStop.length()-TrimLeft(mLineBeforeTabStop).length();
|
2021-10-05 23:30:34 +08:00
|
|
|
|
p->beginX = mTabStopBegin;
|
|
|
|
|
p->endX = mTabStopEnd;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
p->color = highlighter()->stringAttribute()->foreground();
|
|
|
|
|
areaList.append(p);
|
|
|
|
|
}
|
2021-06-24 16:05:19 +08:00
|
|
|
|
PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line);
|
|
|
|
|
if (lst) {
|
2021-08-29 10:14:07 +08:00
|
|
|
|
for (const PSyntaxIssue& issue: *lst) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
|
2021-06-24 16:05:19 +08:00
|
|
|
|
p->beginX = issue->col;
|
|
|
|
|
p->endX = issue->endCol;
|
|
|
|
|
if (issue->issueType == CompileIssueType::Error) {
|
|
|
|
|
p->color = mSyntaxErrorColor;
|
|
|
|
|
} else {
|
2021-07-26 00:22:08 +08:00
|
|
|
|
p->color = mSyntaxWarningColor;
|
2021-06-24 16:05:19 +08:00
|
|
|
|
}
|
2022-09-27 14:01:38 +08:00
|
|
|
|
p->type = QSynedit::EditingAreaType::eatWaveUnderLine;
|
2021-06-24 16:05:19 +08:00
|
|
|
|
areaList.append(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 13:57:22 +08:00
|
|
|
|
bool Editor::onGetSpecialLineColors(int Line, QColor &foreground, QColor &backgroundColor)
|
|
|
|
|
{
|
2021-07-27 00:14:24 +08:00
|
|
|
|
if (Line == mActiveBreakpointLine &&
|
2021-11-03 23:27:05 +08:00
|
|
|
|
mActiveBreakpointBackgroundColor.isValid()) {
|
|
|
|
|
if (mActiveBreakpointForegroundColor.isValid())
|
|
|
|
|
foreground = mActiveBreakpointForegroundColor;
|
2021-07-26 00:22:08 +08:00
|
|
|
|
backgroundColor = mActiveBreakpointBackgroundColor;
|
2021-07-27 00:14:24 +08:00
|
|
|
|
return true;
|
2021-11-03 23:27:05 +08:00
|
|
|
|
} else if (hasBreakpoint(Line) && mBreakpointBackgroundColor.isValid()) {
|
|
|
|
|
if (mBreakpointForegroundColor.isValid())
|
|
|
|
|
foreground = mBreakpointForegroundColor;
|
2021-07-26 00:22:08 +08:00
|
|
|
|
backgroundColor = mBreakpointBackgroundColor;
|
2021-07-27 00:14:24 +08:00
|
|
|
|
return true;
|
2021-07-26 00:22:08 +08:00
|
|
|
|
}
|
|
|
|
|
// end else if Line = fErrorLine then begin
|
|
|
|
|
// StrToThemeColor(tc, devEditor.Syntax.Values[cErr]);
|
|
|
|
|
// BG := tc.Background;
|
|
|
|
|
// FG := tc.Foreground;
|
|
|
|
|
// if (BG <> clNone) or (FG<>clNone) then
|
|
|
|
|
// Special := TRUE;
|
|
|
|
|
// end;
|
2021-07-27 00:14:24 +08:00
|
|
|
|
return false;
|
2021-07-03 13:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &token, QSynedit::PHighlighterAttribute attr, QSynedit::FontStyles &style, QColor &foreground, QColor &background)
|
2021-08-28 09:01:40 +08:00
|
|
|
|
{
|
|
|
|
|
if (token.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (mParser && highlighter()) {
|
2022-06-08 16:05:54 +08:00
|
|
|
|
QString lineText = document()->getString(line-1);
|
|
|
|
|
if (mParser->isIncludeLine(lineText)) {
|
|
|
|
|
if (cursor() == Qt::PointingHandCursor) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (line==p.line){
|
2022-06-08 16:05:54 +08:00
|
|
|
|
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
|
|
|
|
|
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
|
|
|
|
|
pos1++;
|
|
|
|
|
pos2++;
|
|
|
|
|
if (pos1>0 && pos2>0 && pos1<aChar && aChar < pos2) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsUnderline);
|
2022-06-08 16:05:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-23 12:51:23 +08:00
|
|
|
|
} else if (mParser->enabled() && attr->tokenType() == QSynedit::TokenType::Identifier) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p{aChar,line};
|
2022-06-08 16:05:54 +08:00
|
|
|
|
// BufferCoord pBeginPos,pEndPos;
|
|
|
|
|
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
|
|
|
|
// qDebug()<<s;
|
|
|
|
|
// PStatement statement = mParser->findStatementOf(mFilename,
|
|
|
|
|
// s , p.Line);
|
|
|
|
|
QStringList expression = getExpressionAtPosition(p);
|
|
|
|
|
PStatement statement = parser()->findStatementOf(
|
|
|
|
|
filename(),
|
|
|
|
|
expression,
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.line);
|
2022-06-08 16:05:54 +08:00
|
|
|
|
StatementKind kind = getKindOfStatement(statement);
|
|
|
|
|
if (kind == StatementKind::skUnknown) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
2022-06-08 16:05:54 +08:00
|
|
|
|
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ((pEndPos.line>=1)
|
|
|
|
|
&& (pEndPos.ch>=0)
|
|
|
|
|
&& (pEndPos.ch+1 < document()->getString(pEndPos.line-1).length())
|
|
|
|
|
&& (document()->getString(pEndPos.line-1)[pEndPos.ch+1] == '(')) {
|
2022-06-08 16:05:54 +08:00
|
|
|
|
kind = StatementKind::skFunction;
|
|
|
|
|
} else {
|
|
|
|
|
kind = StatementKind::skVariable;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem());
|
|
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
|
foreground = item->foreground();
|
|
|
|
|
//background = item->background();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsBold,item->bold());
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsItalic,item->italic());
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsUnderline,item->underlined());
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsStrikeOut,item->strikeout());
|
2021-08-28 09:01:40 +08:00
|
|
|
|
} else {
|
2022-06-08 16:05:54 +08:00
|
|
|
|
foreground = highlighter()->identifierAttribute()->foreground();
|
|
|
|
|
}
|
|
|
|
|
if (cursor() == Qt::PointingHandCursor) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (line==p.line && (aChar<=p.ch && p.ch<aChar+token.length())) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsUnderline);
|
2022-06-08 16:05:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-28 09:01:40 +08:00
|
|
|
|
}
|
2021-10-10 21:23:25 +08:00
|
|
|
|
}
|
2021-11-03 18:09:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//selection
|
2021-11-03 23:27:05 +08:00
|
|
|
|
if (highlighter() && attr) {
|
2022-11-23 12:51:23 +08:00
|
|
|
|
if (attr->tokenType() == QSynedit::TokenType::Keyword) {
|
2022-11-22 15:14:05 +08:00
|
|
|
|
if (CppTypeKeywords.contains(token)
|
|
|
|
|
||
|
|
|
|
|
(
|
|
|
|
|
highlighter()->language()==QSynedit::HighlighterLanguage::Cpp
|
|
|
|
|
&&
|
|
|
|
|
((QSynedit::CppHighlighter*)highlighter().get())->customTypeKeywords().contains(token)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
2022-11-14 11:56:38 +08:00
|
|
|
|
PColorSchemeItem item = mStatementColors->value(StatementKind::skKeywordType,PColorSchemeItem());
|
|
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
|
if (item->foreground().isValid())
|
|
|
|
|
foreground = item->foreground();
|
|
|
|
|
if (item->background().isValid())
|
|
|
|
|
background = item->background();
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsBold,item->bold());
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsItalic,item->italic());
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsUnderline,item->underlined());
|
|
|
|
|
style.setFlag(QSynedit::FontStyle::fsStrikeOut,item->strikeout());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-23 12:51:23 +08:00
|
|
|
|
if (((attr->tokenType() == QSynedit::TokenType::Identifier)
|
|
|
|
|
|| (attr->tokenType() == QSynedit::TokenType::Keyword)
|
|
|
|
|
|| (attr->tokenType() == QSynedit::TokenType::Preprocessor)
|
2021-11-03 23:27:05 +08:00
|
|
|
|
)
|
|
|
|
|
&& (token == mCurrentHighlightedWord)) {
|
2021-11-03 18:09:12 +08:00
|
|
|
|
if (mCurrentHighlighWordForeground.isValid())
|
|
|
|
|
foreground = mCurrentHighlighWordForeground;
|
|
|
|
|
if (mCurrentHighlighWordBackground.isValid())
|
|
|
|
|
background = mCurrentHighlighWordBackground;
|
2021-11-18 21:25:28 +08:00
|
|
|
|
} else if (!selAvail() && attr->name() == SYNS_AttrSymbol
|
|
|
|
|
&& pSettings->editor().highlightMathingBraces()) {
|
2021-11-03 23:27:05 +08:00
|
|
|
|
// qDebug()<<line<<":"<<aChar<<" - "<<mHighlightCharPos1.Line<<":"<<mHighlightCharPos1.Char<<" - "<<mHighlightCharPos2.Line<<":"<<mHighlightCharPos2.Char;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ( (line == mHighlightCharPos1.line)
|
|
|
|
|
&& (aChar == mHighlightCharPos1.ch)) {
|
2021-11-03 23:27:05 +08:00
|
|
|
|
if (mCurrentHighlighWordForeground.isValid())
|
|
|
|
|
foreground = mCurrentHighlighWordForeground;
|
|
|
|
|
if (mCurrentHighlighWordBackground.isValid())
|
|
|
|
|
background = mCurrentHighlighWordBackground;
|
|
|
|
|
}
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ((line == mHighlightCharPos2.line)
|
|
|
|
|
&& (aChar == mHighlightCharPos2.ch)) {
|
2021-11-03 23:27:05 +08:00
|
|
|
|
if (mCurrentHighlighWordForeground.isValid())
|
|
|
|
|
foreground = mCurrentHighlighWordForeground;
|
|
|
|
|
if (mCurrentHighlighWordBackground.isValid())
|
|
|
|
|
background = mCurrentHighlighWordBackground;
|
|
|
|
|
}
|
2021-11-03 18:09:12 +08:00
|
|
|
|
}
|
2021-11-03 23:27:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (token == mCurrentHighlightedWord) {
|
2021-11-03 18:09:12 +08:00
|
|
|
|
if (mCurrentHighlighWordForeground.isValid())
|
|
|
|
|
foreground = mCurrentHighlighWordForeground;
|
|
|
|
|
if (mCurrentHighlighWordBackground.isValid())
|
|
|
|
|
background = mCurrentHighlighWordBackground;
|
|
|
|
|
}
|
2021-08-28 09:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 17:23:40 +08:00
|
|
|
|
bool Editor::event(QEvent *event)
|
|
|
|
|
{
|
2021-09-21 20:36:43 +08:00
|
|
|
|
if ((event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove)
|
2022-04-07 17:30:06 +08:00
|
|
|
|
&& qApp->mouseButtons() == Qt::NoButton
|
2021-09-21 20:36:43 +08:00
|
|
|
|
&& pSettings->editor().enableTooltips()
|
2022-01-26 12:17:15 +08:00
|
|
|
|
&& !pMainWindow->completionPopup()->isVisible()
|
|
|
|
|
&& !pMainWindow->functionTip()->isVisible()
|
|
|
|
|
&& !pMainWindow->headerCompletionPopup()->isVisible()) {
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if(mHoverModifiedLine!=-1) {
|
|
|
|
|
invalidateLine(mHoverModifiedLine);
|
|
|
|
|
mHoverModifiedLine=-1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 13:30:42 +08:00
|
|
|
|
QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event);
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
TipType reason = getTipType(helpEvent->pos(),p);
|
|
|
|
|
PSyntaxIssue pError;
|
|
|
|
|
int line ;
|
|
|
|
|
if (reason == TipType::Error) {
|
|
|
|
|
pError = getSyntaxIssueAtPosition(p);
|
2021-09-20 15:57:48 +08:00
|
|
|
|
} else if (pointToLine(helpEvent->pos(),line)) {
|
2021-09-21 20:36:43 +08:00
|
|
|
|
//issue tips is prefered
|
2021-08-29 17:23:40 +08:00
|
|
|
|
PSyntaxIssueList issues = getSyntaxIssuesAtLine(line);
|
|
|
|
|
if (issues && !issues->isEmpty()) {
|
|
|
|
|
reason = TipType::Error;
|
|
|
|
|
pError = issues->front();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get subject
|
|
|
|
|
bool isIncludeLine = false;
|
2022-10-18 12:24:59 +08:00
|
|
|
|
bool isIncludeNextLine = false;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
QString s;
|
2021-12-17 21:47:37 +08:00
|
|
|
|
QStringList expression;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
switch (reason) {
|
|
|
|
|
case TipType::Preprocessor:
|
|
|
|
|
// When hovering above a preprocessor line, determine if we want to show an include or a identifier hint
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (mParser) {
|
|
|
|
|
s = document()->getString(p.line - 1);
|
|
|
|
|
isIncludeNextLine = mParser->isIncludeNextLine(s);
|
|
|
|
|
if (!isIncludeNextLine)
|
|
|
|
|
isIncludeLine = mParser->isIncludeLine(s);
|
|
|
|
|
if (!isIncludeNextLine &&!isIncludeLine)
|
|
|
|
|
s = wordAtRowCol(p);
|
|
|
|
|
}
|
2021-08-29 17:23:40 +08:00
|
|
|
|
break;
|
|
|
|
|
case TipType::Identifier:
|
2021-12-27 10:59:04 +08:00
|
|
|
|
if (pMainWindow->debugger()->executing() && !pMainWindow->debugger()->inferiorRunning())
|
2021-09-03 16:39:20 +08:00
|
|
|
|
s = getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpEvaluation); // debugging
|
2022-11-06 09:43:28 +08:00
|
|
|
|
else if (!mCompletionPopup->isVisible()
|
2021-12-17 21:47:37 +08:00
|
|
|
|
&& !mHeaderCompletionPopup->isVisible()) {
|
|
|
|
|
expression = getExpressionAtPosition(p);
|
|
|
|
|
s = expression.join(""); // information during coding
|
|
|
|
|
}
|
2021-08-29 17:23:40 +08:00
|
|
|
|
break;
|
|
|
|
|
case TipType::Selection:
|
|
|
|
|
s = selText(); // when a selection is available, always only use that
|
|
|
|
|
break;
|
|
|
|
|
case TipType::Error:
|
|
|
|
|
s = pError->token;
|
|
|
|
|
break;
|
|
|
|
|
case TipType::None:
|
|
|
|
|
cancelHint();
|
2022-01-15 11:33:41 +08:00
|
|
|
|
mCurrentWord = "";
|
|
|
|
|
mCurrentTipType = TipType::None;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
event->ignore();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = s.trimmed();
|
|
|
|
|
if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (mParser
|
|
|
|
|
&& mParser->enabled()
|
|
|
|
|
&& qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if (!hasFocus())
|
|
|
|
|
activate();
|
2021-08-29 22:08:43 +08:00
|
|
|
|
setCursor(Qt::PointingHandCursor);
|
2021-09-27 00:52:25 +08:00
|
|
|
|
} else {
|
|
|
|
|
updateMouseCursor();
|
2021-08-29 22:08:43 +08:00
|
|
|
|
}
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if (pointToLine(helpEvent->pos(),line)) {
|
|
|
|
|
invalidateLine(line);
|
|
|
|
|
mHoverModifiedLine=line;
|
|
|
|
|
}
|
2021-08-29 17:23:40 +08:00
|
|
|
|
event->ignore();
|
|
|
|
|
return true; // do NOT remove hint when subject stays the same
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove hint
|
|
|
|
|
cancelHint();
|
|
|
|
|
mCurrentWord = s;
|
|
|
|
|
mCurrentTipType = reason;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Determine what to do with subject
|
|
|
|
|
QString hint = "";
|
|
|
|
|
switch (reason) {
|
|
|
|
|
case TipType::Preprocessor:
|
2022-10-18 12:24:59 +08:00
|
|
|
|
if (isIncludeNextLine || isIncludeLine) {
|
2021-09-21 20:36:43 +08:00
|
|
|
|
if (pSettings->editor().enableHeaderToolTips())
|
2022-10-18 12:24:59 +08:00
|
|
|
|
hint = getFileHint(s, isIncludeNextLine);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
} else if (//devEditor.ParserHints and
|
|
|
|
|
!mCompletionPopup->isVisible()
|
|
|
|
|
&& !mHeaderCompletionPopup->isVisible()) {
|
2021-09-21 20:36:43 +08:00
|
|
|
|
if (pSettings->editor().enableIdentifierToolTips())
|
2022-07-04 10:01:40 +08:00
|
|
|
|
hint = getParserHint(QStringList(),s,p.line);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case TipType::Identifier:
|
|
|
|
|
case TipType::Selection:
|
|
|
|
|
if (!mCompletionPopup->isVisible()
|
|
|
|
|
&& !mHeaderCompletionPopup->isVisible()) {
|
2021-09-21 20:36:43 +08:00
|
|
|
|
if (pMainWindow->debugger()->executing()
|
|
|
|
|
&& (pSettings->editor().enableDebugTooltips())) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
showDebugHint(s,p.line);
|
2021-09-21 20:36:43 +08:00
|
|
|
|
} else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
hint = getParserHint(expression, s, p.line);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case TipType::Error:
|
2021-09-21 20:36:43 +08:00
|
|
|
|
if (pSettings->editor().enableIssueToolTips())
|
|
|
|
|
hint = getErrorHint(pError);
|
2021-10-20 18:05:43 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
2021-08-30 13:30:42 +08:00
|
|
|
|
// qDebug()<<"hint:"<<hint;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
if (!hint.isEmpty()) {
|
2021-08-30 13:30:42 +08:00
|
|
|
|
// QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
|
|
|
|
|
// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (mParser
|
|
|
|
|
&& mParser->enabled()
|
|
|
|
|
&& qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if (!hasFocus())
|
|
|
|
|
activate();
|
2021-08-29 22:08:43 +08:00
|
|
|
|
setCursor(Qt::PointingHandCursor);
|
2021-09-26 23:47:37 +08:00
|
|
|
|
} else if (cursor() == Qt::PointingHandCursor) {
|
2021-09-27 00:52:25 +08:00
|
|
|
|
updateMouseCursor();
|
2021-08-29 22:08:43 +08:00
|
|
|
|
}
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if (pointToLine(helpEvent->pos(),line)) {
|
|
|
|
|
invalidateLine(line);
|
|
|
|
|
mHoverModifiedLine=line;
|
|
|
|
|
}
|
2022-01-15 11:22:20 +08:00
|
|
|
|
if (pMainWindow->functionTip()->isVisible()) {
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
}
|
2022-04-07 21:35:09 +08:00
|
|
|
|
QToolTip::showText(mapToGlobal(helpEvent->pos()),hint,this);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
event->ignore();
|
2021-08-29 22:08:43 +08:00
|
|
|
|
} else {
|
2021-09-27 00:52:25 +08:00
|
|
|
|
updateMouseCursor();
|
2021-08-29 22:08:43 +08:00
|
|
|
|
event->ignore();
|
|
|
|
|
}
|
2021-08-30 13:30:42 +08:00
|
|
|
|
return true;
|
|
|
|
|
} else if (event->type() == QEvent::HoverLeave) {
|
|
|
|
|
cancelHint();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease ) {
|
|
|
|
|
if (!mCurrentWord.isEmpty()) {
|
|
|
|
|
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
|
|
|
|
|
if (keyEvent->key() == Qt::Key_Control) {
|
|
|
|
|
QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
|
2022-10-10 18:05:18 +08:00
|
|
|
|
//postEvent takes the owner ship
|
2021-08-30 13:30:42 +08:00
|
|
|
|
QHoverEvent* hoverEvent=new QHoverEvent(QEvent::HoverMove,
|
|
|
|
|
mapFromGlobal(QCursor::pos()),
|
|
|
|
|
mapFromGlobal(QCursor::pos()),
|
|
|
|
|
Qt::ControlModifier
|
|
|
|
|
);
|
|
|
|
|
app->postEvent(this,hoverEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
return SynEdit::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 13:30:42 +08:00
|
|
|
|
void Editor::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->button() | Qt::LeftButton) {
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if ctrl+clicked
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if ((cursor() == Qt::PointingHandCursor) && (event->modifiers() == Qt::ControlModifier)
|
2021-08-30 13:30:42 +08:00
|
|
|
|
&& (event->button() == Qt::LeftButton)) {
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (mParser && pointToCharLine(event->pos(),p)) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
QString s = document()->getString(p.line - 1);
|
2022-10-18 12:24:59 +08:00
|
|
|
|
if (mParser->isIncludeNextLine(s)) {
|
|
|
|
|
QString filename = mParser->getHeaderFileName(mFilename,s, true);
|
2022-10-18 19:09:46 +08:00
|
|
|
|
pMainWindow->openFile(filename);
|
2022-10-18 23:22:29 +08:00
|
|
|
|
return;
|
2022-10-18 12:24:59 +08:00
|
|
|
|
} if (mParser->isIncludeLine(s)) {
|
2021-08-30 13:30:42 +08:00
|
|
|
|
QString filename = mParser->getHeaderFileName(mFilename,s);
|
2022-10-18 19:09:46 +08:00
|
|
|
|
pMainWindow->openFile(filename);
|
2022-10-18 23:22:29 +08:00
|
|
|
|
return;
|
2022-11-06 09:43:28 +08:00
|
|
|
|
} else if (mParser->enabled()) {
|
2022-03-19 15:33:15 +08:00
|
|
|
|
gotoDefinition(p);
|
2021-08-30 19:52:38 +08:00
|
|
|
|
return;
|
2021-08-30 13:30:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::SynEdit::mouseReleaseEvent(event);
|
2021-08-30 13:30:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 15:34:18 +08:00
|
|
|
|
void Editor::inputMethodEvent(QInputMethodEvent *event)
|
|
|
|
|
{
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::SynEdit::inputMethodEvent(event);
|
2021-10-05 00:42:35 +08:00
|
|
|
|
QString s = event->commitString();
|
|
|
|
|
if (s.isEmpty())
|
|
|
|
|
return;
|
2021-10-02 15:34:18 +08:00
|
|
|
|
if (pMainWindow->completionPopup()->isVisible()) {
|
2021-10-05 00:42:35 +08:00
|
|
|
|
onCompletionInputMethod(event);
|
|
|
|
|
return;
|
2021-10-02 15:34:18 +08:00
|
|
|
|
} else {
|
2021-10-05 00:42:35 +08:00
|
|
|
|
mLastIdCharPressed+=s.length();
|
|
|
|
|
if (pSettings->codeCompletion().enabled()
|
|
|
|
|
&& pSettings->codeCompletion().showCompletionWhileInput() ) {
|
2022-01-10 21:46:03 +08:00
|
|
|
|
if (mLastIdCharPressed>=pSettings->codeCompletion().minCharRequired()) {
|
2021-10-05 00:42:35 +08:00
|
|
|
|
QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY());
|
|
|
|
|
if (!lastWord.isEmpty()) {
|
|
|
|
|
if (CppTypeKeywords.contains(lastWord)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PStatement statement = mParser->findStatementOf(
|
|
|
|
|
mFilename,
|
|
|
|
|
lastWord,
|
|
|
|
|
caretY());
|
2022-01-27 20:31:44 +08:00
|
|
|
|
StatementKind kind = getKindOfStatement(statement);
|
2021-10-05 00:42:35 +08:00
|
|
|
|
if (kind == StatementKind::skClass
|
|
|
|
|
|| kind == StatementKind::skEnumClassType
|
|
|
|
|
|| kind == StatementKind::skEnumType
|
|
|
|
|
|| kind == StatementKind::skTypedef) {
|
|
|
|
|
//last word is a typedef/class/struct, this is a var or param define, and dont show suggestion
|
|
|
|
|
// if devEditor.UseTabnine then
|
|
|
|
|
// ShowTabnineCompletion;
|
|
|
|
|
return;
|
2021-10-02 15:34:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2021-10-05 00:42:35 +08:00
|
|
|
|
return;
|
2021-10-02 15:34:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-04 22:32:34 +08:00
|
|
|
|
void Editor::closeEvent(QCloseEvent *)
|
|
|
|
|
{
|
|
|
|
|
if (mHeaderCompletionPopup)
|
|
|
|
|
mHeaderCompletionPopup->hide();
|
|
|
|
|
if (mCompletionPopup)
|
|
|
|
|
mCompletionPopup->hide();
|
|
|
|
|
if (pMainWindow->functionTip())
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl) {
|
|
|
|
|
pMainWindow->updateForEncodingInfo(true);
|
|
|
|
|
pMainWindow->updateStatusbarForLineCol(true);
|
|
|
|
|
pMainWindow->updateForStatusbarModeInfo(true);
|
|
|
|
|
}
|
2021-10-04 22:32:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 20:59:02 +08:00
|
|
|
|
void Editor::showEvent(QShowEvent */*event*/)
|
|
|
|
|
{
|
2022-08-27 11:07:48 +08:00
|
|
|
|
// if (pSettings->codeCompletion().clearWhenEditorHidden()
|
|
|
|
|
// && !inProject()) {
|
|
|
|
|
//// initParser();
|
|
|
|
|
// }
|
2022-08-24 17:05:16 +08:00
|
|
|
|
if (mParser && !pMainWindow->isClosingAll()
|
|
|
|
|
&& !pMainWindow->isQuitting()
|
|
|
|
|
&& !mParser->isFileParsed(mFilename)
|
|
|
|
|
) {
|
2022-01-24 20:59:02 +08:00
|
|
|
|
connect(mParser.get(),
|
|
|
|
|
&CppParser::onEndParsing,
|
|
|
|
|
this,
|
2022-09-25 09:55:18 +08:00
|
|
|
|
&QSynedit::SynEdit::invalidate);
|
2022-10-18 12:24:59 +08:00
|
|
|
|
reparse(false);
|
2022-01-24 20:59:02 +08:00
|
|
|
|
}
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl) {
|
|
|
|
|
pMainWindow->debugger()->setIsForProject(inProject());
|
|
|
|
|
pMainWindow->bookmarkModel()->setIsForProject(inProject());
|
|
|
|
|
pMainWindow->todoModel()->setIsForProject(inProject());
|
|
|
|
|
}
|
2022-10-22 23:29:12 +08:00
|
|
|
|
|
2022-10-21 12:43:02 +08:00
|
|
|
|
if (!pMainWindow->isClosingAll()
|
|
|
|
|
&& !pMainWindow->isQuitting()) {
|
2022-10-24 22:53:46 +08:00
|
|
|
|
if (!inProject() || !pMainWindow->closingProject()) {
|
|
|
|
|
checkSyntaxInBack();
|
|
|
|
|
reparseTodo();
|
|
|
|
|
}
|
2022-10-21 12:43:02 +08:00
|
|
|
|
}
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl) {
|
|
|
|
|
pMainWindow->updateClassBrowserForEditor(this);
|
|
|
|
|
pMainWindow->updateAppTitle(this);
|
|
|
|
|
pMainWindow->updateEditorActions(this);
|
|
|
|
|
pMainWindow->updateForEncodingInfo(this);
|
|
|
|
|
pMainWindow->updateStatusbarForLineCol(this);
|
|
|
|
|
pMainWindow->updateForStatusbarModeInfo(this);
|
|
|
|
|
}
|
2022-10-24 22:53:46 +08:00
|
|
|
|
if (inProject() && !pMainWindow->closingProject()) {
|
2022-10-24 20:01:46 +08:00
|
|
|
|
pMainWindow->setProjectCurrentFile(mFilename);
|
|
|
|
|
}
|
2022-10-23 10:40:00 +08:00
|
|
|
|
|
|
|
|
|
setHideTime(QDateTime::currentDateTime());
|
2022-01-24 20:59:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::hideEvent(QHideEvent */*event*/)
|
|
|
|
|
{
|
2022-10-18 12:24:59 +08:00
|
|
|
|
if (pSettings->codeCompletion().clearWhenEditorHidden()
|
|
|
|
|
&& !inProject() && mParser
|
|
|
|
|
&& !pMainWindow->isMinimized()) {
|
2022-11-23 11:41:16 +08:00
|
|
|
|
//recreate a parser, to totally clean memories the parser uses;
|
|
|
|
|
resetCppParser(mParser);
|
2022-10-18 12:24:59 +08:00
|
|
|
|
}
|
2022-01-24 20:59:02 +08:00
|
|
|
|
if (mParser) {
|
|
|
|
|
disconnect(mParser.get(),
|
|
|
|
|
&CppParser::onEndParsing,
|
|
|
|
|
this,
|
2022-09-25 09:55:18 +08:00
|
|
|
|
&QSynedit::SynEdit::invalidate);
|
2022-01-24 20:59:02 +08:00
|
|
|
|
}
|
2022-10-26 09:33:45 +08:00
|
|
|
|
pMainWindow->updateForEncodingInfo(nullptr);
|
|
|
|
|
pMainWindow->updateStatusbarForLineCol(nullptr);
|
|
|
|
|
pMainWindow->updateForStatusbarModeInfo(nullptr);
|
2022-10-23 10:40:00 +08:00
|
|
|
|
|
2022-01-24 20:59:02 +08:00
|
|
|
|
setHideTime(QDateTime::currentDateTime());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-11 09:25:22 +08:00
|
|
|
|
void Editor::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::SynEdit::resizeEvent(event);
|
2022-04-11 09:25:22 +08:00
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-12 22:36:23 +08:00
|
|
|
|
void Editor::copyToClipboard()
|
|
|
|
|
{
|
|
|
|
|
if (pSettings->editor().copySizeLimit()) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int startLine = blockBegin().line;
|
|
|
|
|
int endLine = blockEnd().line;
|
2021-08-27 00:49:50 +08:00
|
|
|
|
if ((endLine-startLine+1) > pSettings->editor().copyLineLimits()) {
|
2021-06-21 11:21:26 +08:00
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
2021-06-12 22:36:23 +08:00
|
|
|
|
tr("The text to be copied exceeds count limit!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-27 00:49:50 +08:00
|
|
|
|
if ((selText().length()) > pSettings->editor().copyCharLimits() * 1000) {
|
2021-06-21 11:21:26 +08:00
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
2021-06-12 22:36:23 +08:00
|
|
|
|
tr("The text to be copied exceeds character limit!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch(pSettings->editor().copyWithFormatAs()) {
|
|
|
|
|
case 1: //HTML
|
|
|
|
|
copyAsHTML();
|
|
|
|
|
break;;
|
|
|
|
|
default:
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::SynEdit::copyToClipboard();
|
2021-06-12 22:36:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::cutToClipboard()
|
|
|
|
|
{
|
|
|
|
|
if (pSettings->editor().copySizeLimit()) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int startLine = blockBegin().line;
|
|
|
|
|
int endLine = blockEnd().line;
|
2022-06-01 20:52:35 +08:00
|
|
|
|
if ((endLine-startLine+1) > pSettings->editor().copyLineLimits()) {
|
2021-06-21 11:21:26 +08:00
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
2021-06-12 22:36:23 +08:00
|
|
|
|
tr("The text to be cut exceeds count limit!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-06-01 20:52:35 +08:00
|
|
|
|
if ((selText().length()) > pSettings->editor().copyCharLimits() * 1000) {
|
2021-06-21 11:21:26 +08:00
|
|
|
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
2021-06-12 22:36:23 +08:00
|
|
|
|
tr("The text to be cut exceeds character limit!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::SynEdit::cutToClipboard();
|
2021-04-11 12:39:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-12 22:36:23 +08:00
|
|
|
|
void Editor::copyAsHTML()
|
|
|
|
|
{
|
|
|
|
|
if (!selAvail())
|
|
|
|
|
return;
|
2022-09-26 14:54:28 +08:00
|
|
|
|
QSynedit::SynHTMLExporter exporter(tabWidth(), pCharsetInfoManager->getDefaultSystemEncoding());
|
2021-06-12 22:36:23 +08:00
|
|
|
|
|
2021-10-12 09:47:58 +08:00
|
|
|
|
exporter.setTitle(QFileInfo(mFilename).fileName());
|
|
|
|
|
exporter.setExportAsText(false);
|
|
|
|
|
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
|
|
|
|
exporter.setFont(font());
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighter hl = highlighter();
|
2021-06-20 22:54:16 +08:00
|
|
|
|
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
|
|
|
|
hl = highlighterManager.copyHighlighter(highlighter());
|
|
|
|
|
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
|
|
|
|
}
|
2021-10-12 09:47:58 +08:00
|
|
|
|
exporter.setHighlighter(hl);
|
|
|
|
|
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
|
|
|
|
this,
|
|
|
|
|
std::placeholders::_1,
|
|
|
|
|
std::placeholders::_2,
|
|
|
|
|
std::placeholders::_3,
|
|
|
|
|
std::placeholders::_4,
|
|
|
|
|
std::placeholders::_5
|
|
|
|
|
));
|
|
|
|
|
exporter.setCreateHTMLFragment(true);
|
2021-06-12 22:36:23 +08:00
|
|
|
|
|
2022-04-19 21:18:41 +08:00
|
|
|
|
exporter.ExportRange(document(),blockBegin(),blockEnd());
|
2021-06-12 22:36:23 +08:00
|
|
|
|
|
2022-10-10 18:05:18 +08:00
|
|
|
|
//clipboard takes the owner ship
|
2021-06-12 22:36:23 +08:00
|
|
|
|
QMimeData * mimeData = new QMimeData;
|
|
|
|
|
|
|
|
|
|
//sethtml will convert buffer to QString , which will cause encoding trouble
|
2021-10-12 09:47:58 +08:00
|
|
|
|
mimeData->setData(exporter.clipboardFormat(),exporter.buffer());
|
2021-06-12 22:36:23 +08:00
|
|
|
|
mimeData->setText(selText());
|
|
|
|
|
|
|
|
|
|
QGuiApplication::clipboard()->clear();
|
|
|
|
|
QGuiApplication::clipboard()->setMimeData(mimeData);
|
2021-04-11 13:55:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-05 21:05:38 +08:00
|
|
|
|
void Editor::setCaretPosition(int line, int aChar)
|
2021-06-24 16:05:19 +08:00
|
|
|
|
{
|
|
|
|
|
this->uncollapseAroundLine(line);
|
2022-09-25 09:55:18 +08:00
|
|
|
|
this->setCaretXYCentered(QSynedit::BufferCoord{aChar,line});
|
2021-06-24 16:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-05 21:05:38 +08:00
|
|
|
|
void Editor::setCaretPositionAndActivate(int line, int aChar)
|
2021-06-24 16:05:19 +08:00
|
|
|
|
{
|
|
|
|
|
this->uncollapseAroundLine(line);
|
|
|
|
|
if (!this->hasFocus())
|
|
|
|
|
this->activate();
|
2022-09-25 09:55:18 +08:00
|
|
|
|
this->setCaretXYCentered(QSynedit::BufferCoord{aChar,line});
|
2021-06-24 16:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueType errorType, const QString &hint)
|
2021-06-23 22:38:02 +08:00
|
|
|
|
{
|
|
|
|
|
PSyntaxIssue pError;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2021-06-23 22:38:02 +08:00
|
|
|
|
QString token;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
int start;
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr;
|
2021-06-23 22:38:02 +08:00
|
|
|
|
PSyntaxIssueList lst;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if ((line<1) || (line>document()->count()))
|
2021-06-23 22:38:02 +08:00
|
|
|
|
return;
|
|
|
|
|
pError = std::make_shared<SyntaxIssue>();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch = startChar;
|
|
|
|
|
p.line = line;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (startChar >= document()->getString(line-1).length()) {
|
2021-06-23 22:38:02 +08:00
|
|
|
|
start = 1;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
token = document()->getString(line-1);
|
2021-06-24 16:05:19 +08:00
|
|
|
|
} else if (endChar < 1) {
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if (!getHighlighterAttriAtRowColEx(p,token,start,attr))
|
2021-06-23 22:38:02 +08:00
|
|
|
|
return;
|
2021-06-24 16:05:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
start = startChar;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
token = document()->getString(line-1).mid(start-1,endChar-startChar);
|
2021-06-23 22:38:02 +08:00
|
|
|
|
}
|
|
|
|
|
pError->startChar = start;
|
|
|
|
|
pError->endChar = start + token.length();
|
2021-10-05 21:25:23 +08:00
|
|
|
|
// pError->col = charToColumn(line,pError->startChar);
|
|
|
|
|
// pError->endCol = charToColumn(line,pError->endChar);
|
|
|
|
|
pError->col = pError->startChar;
|
|
|
|
|
pError->endCol = pError->endChar;
|
2021-06-23 22:38:02 +08:00
|
|
|
|
pError->hint = hint;
|
|
|
|
|
pError->token = token;
|
|
|
|
|
pError->issueType = errorType;
|
|
|
|
|
if (mSyntaxIssues.contains(line)) {
|
|
|
|
|
lst = mSyntaxIssues[line];
|
|
|
|
|
} else {
|
|
|
|
|
lst = std::make_shared<SyntaxIssueList>();
|
|
|
|
|
mSyntaxIssues[line] = lst;
|
|
|
|
|
}
|
|
|
|
|
lst->append(pError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::clearSyntaxIssues()
|
|
|
|
|
{
|
|
|
|
|
mSyntaxIssues.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::gotoNextSyntaxIssue()
|
|
|
|
|
{
|
|
|
|
|
auto iter = mSyntaxIssues.find(caretY());
|
|
|
|
|
if (iter==mSyntaxIssues.end())
|
|
|
|
|
return;
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter==mSyntaxIssues.end())
|
|
|
|
|
return;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch = (*iter)->at(0)->startChar;
|
|
|
|
|
p.line = iter.key();
|
2021-06-23 22:38:02 +08:00
|
|
|
|
setCaretXY(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::gotoPrevSyntaxIssue()
|
|
|
|
|
{
|
|
|
|
|
auto iter = mSyntaxIssues.find(caretY());
|
|
|
|
|
if (iter==mSyntaxIssues.end())
|
|
|
|
|
return;
|
|
|
|
|
if (iter==mSyntaxIssues.begin())
|
|
|
|
|
return;
|
|
|
|
|
iter--;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch = (*iter)->at(0)->startChar;
|
|
|
|
|
p.line = iter.key();
|
2021-06-23 22:38:02 +08:00
|
|
|
|
setCaretXY(p);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::hasNextSyntaxIssue() const
|
|
|
|
|
{
|
|
|
|
|
auto iter = mSyntaxIssues.find(caretY());
|
|
|
|
|
if (iter==mSyntaxIssues.end())
|
|
|
|
|
return false;
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter==mSyntaxIssues.end())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::hasPrevSyntaxIssue() const
|
|
|
|
|
{
|
|
|
|
|
auto iter = mSyntaxIssues.find(caretY());
|
|
|
|
|
if (iter==mSyntaxIssues.end())
|
|
|
|
|
return true;
|
|
|
|
|
if (iter==mSyntaxIssues.begin())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 16:05:19 +08:00
|
|
|
|
Editor::PSyntaxIssueList Editor::getSyntaxIssuesAtLine(int line)
|
2021-06-23 22:38:02 +08:00
|
|
|
|
{
|
|
|
|
|
if (mSyntaxIssues.contains(line))
|
|
|
|
|
return mSyntaxIssues[line];
|
|
|
|
|
return PSyntaxIssueList();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
Editor::PSyntaxIssue Editor::getSyntaxIssueAtPosition(const QSynedit::BufferCoord &pos)
|
2021-06-23 22:38:02 +08:00
|
|
|
|
{
|
2022-07-04 10:01:40 +08:00
|
|
|
|
PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.line);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
if (!lst)
|
|
|
|
|
return PSyntaxIssue();
|
2021-08-29 10:14:07 +08:00
|
|
|
|
foreach (const PSyntaxIssue& issue, *lst) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (issue->startChar<=pos.ch && pos.ch<=issue->endChar)
|
2021-06-23 22:38:02 +08:00
|
|
|
|
return issue;
|
|
|
|
|
}
|
|
|
|
|
return PSyntaxIssue();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
void Editor::onStatusChanged(QSynedit::StatusChanges changes)
|
2021-06-10 09:34:59 +08:00
|
|
|
|
{
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if ((!changes.testFlag(QSynedit::StatusChange::scReadOnly)
|
|
|
|
|
&& !changes.testFlag(QSynedit::StatusChange::scInsertMode)
|
2022-04-19 21:18:41 +08:00
|
|
|
|
&& (document()->count()!=mLineCount)
|
|
|
|
|
&& (document()->count()!=0) && ((mLineCount>0) || (document()->count()>1)))
|
2021-11-04 00:38:40 +08:00
|
|
|
|
||
|
|
|
|
|
(mCurrentLineModified
|
2022-09-27 14:01:38 +08:00
|
|
|
|
&& !changes.testFlag(QSynedit::StatusChange::scReadOnly)
|
|
|
|
|
&& changes.testFlag(QSynedit::StatusChange::scCaretY))) {
|
2021-11-04 00:38:40 +08:00
|
|
|
|
mCurrentLineModified = false;
|
2022-10-21 12:43:02 +08:00
|
|
|
|
if (!changes.testFlag(QSynedit::StatusChange::scOpenFile)) {
|
2022-10-18 12:24:59 +08:00
|
|
|
|
reparse(false);
|
2022-11-07 17:03:46 +08:00
|
|
|
|
if (pSettings->editor().syntaxCheckWhenLineChanged())
|
|
|
|
|
checkSyntaxInBack();
|
2022-10-21 12:43:02 +08:00
|
|
|
|
reparseTodo();
|
|
|
|
|
}
|
2022-08-24 17:05:16 +08:00
|
|
|
|
// if (pSettings->codeCompletion().clearWhenEditorHidden()
|
|
|
|
|
// && changes.testFlag(SynStatusChange::scOpenFile)) {
|
|
|
|
|
// } else{
|
|
|
|
|
// reparse();
|
|
|
|
|
// }
|
2021-06-24 20:43:09 +08:00
|
|
|
|
}
|
2022-04-19 21:18:41 +08:00
|
|
|
|
mLineCount = document()->count();
|
2022-09-25 09:55:18 +08:00
|
|
|
|
if (changes.testFlag(QSynedit::scModifyChanged)) {
|
2021-06-10 09:34:59 +08:00
|
|
|
|
updateCaption();
|
|
|
|
|
}
|
2022-09-25 09:55:18 +08:00
|
|
|
|
if (changes.testFlag(QSynedit::scModified)) {
|
2021-11-04 00:38:40 +08:00
|
|
|
|
mCurrentLineModified = true;
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (mParentPageControl)
|
2021-11-12 12:40:47 +08:00
|
|
|
|
mCanAutoSave = true;
|
2021-11-04 00:38:40 +08:00
|
|
|
|
}
|
2021-06-10 09:34:59 +08:00
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (changes.testFlag(QSynedit::StatusChange::scCaretX)
|
|
|
|
|
|| changes.testFlag(QSynedit::StatusChange::scCaretY)) {
|
2021-10-02 13:29:45 +08:00
|
|
|
|
if (mTabStopBegin >=0) {
|
|
|
|
|
if (mTabStopY==caretY()) {
|
|
|
|
|
if (mLineAfterTabStop.isEmpty()) {
|
|
|
|
|
if (lineText().startsWith(mLineBeforeTabStop))
|
|
|
|
|
mTabStopBegin = mLineBeforeTabStop.length()+1;
|
|
|
|
|
mTabStopEnd = lineText().length()+1;
|
|
|
|
|
} else {
|
|
|
|
|
if (lineText().startsWith(mLineBeforeTabStop)
|
|
|
|
|
&& lineText().endsWith(mLineAfterTabStop))
|
2021-10-03 09:57:19 +08:00
|
|
|
|
mTabStopBegin = mLineBeforeTabStop.length()+1;
|
2021-10-02 13:29:45 +08:00
|
|
|
|
mTabStopEnd = lineText().length()
|
2021-10-03 09:57:19 +08:00
|
|
|
|
- mLineAfterTabStop.length()+1;
|
2021-10-02 13:29:45 +08:00
|
|
|
|
}
|
|
|
|
|
mXOffsetSince = mTabStopEnd - caretX();
|
|
|
|
|
if (caretX() < mTabStopBegin ||
|
|
|
|
|
caretX() > (mTabStopEnd+1)) {
|
|
|
|
|
mTabStopBegin = -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (mTabStopBegin>=0) {
|
|
|
|
|
invalidateLine(mTabStopY);
|
|
|
|
|
mTabStopBegin = -1;
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-18 23:17:06 +08:00
|
|
|
|
} else if (!selAvail() && highlighter() && pSettings->editor().highlightMathingBraces()){
|
2022-07-04 10:01:40 +08:00
|
|
|
|
invalidateLine(mHighlightCharPos1.line);
|
|
|
|
|
invalidateLine(mHighlightCharPos2.line);
|
2022-09-25 09:55:18 +08:00
|
|
|
|
mHighlightCharPos1 = QSynedit::BufferCoord{0,0};
|
|
|
|
|
mHighlightCharPos2 = QSynedit::BufferCoord{0,0};
|
2021-10-12 20:38:39 +08:00
|
|
|
|
// Is there a bracket char before us?
|
|
|
|
|
int lineLength = lineText().length();
|
|
|
|
|
int ch = caretX() - 2;
|
2022-10-21 09:07:32 +08:00
|
|
|
|
QSynedit::BufferCoord coord{0,0};
|
2021-10-12 20:38:39 +08:00
|
|
|
|
if (ch>=0 && ch<lineLength && isBraceChar(lineText()[ch]) ) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
coord.ch = ch+1;
|
|
|
|
|
coord.line = caretY();
|
2021-10-12 20:38:39 +08:00
|
|
|
|
}
|
|
|
|
|
//or after us?
|
|
|
|
|
ch = caretX()-1;
|
|
|
|
|
if (ch>=0 && ch<lineLength && isBraceChar(lineText()[ch]) ) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
coord.ch = ch+1;
|
|
|
|
|
coord.line = caretY();
|
2021-10-12 20:38:39 +08:00
|
|
|
|
}
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr;
|
2021-10-12 20:38:39 +08:00
|
|
|
|
QString token;
|
|
|
|
|
if (getHighlighterAttriAtRowCol(coord,token,attr)
|
2022-11-23 12:51:23 +08:00
|
|
|
|
&& attr->tokenType() == QSynedit::TokenType::Operator) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord complementCharPos = getMatchingBracketEx(coord);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (!foldHidesLine(coord.line)
|
|
|
|
|
&& !foldHidesLine(complementCharPos.line)) {
|
2021-10-12 20:38:39 +08:00
|
|
|
|
mHighlightCharPos1 = coord;
|
|
|
|
|
mHighlightCharPos2 = complementCharPos;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
invalidateLine(mHighlightCharPos1.line);
|
|
|
|
|
invalidateLine(mHighlightCharPos2.line);
|
2021-10-12 20:38:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 10:05:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-10 09:34:59 +08:00
|
|
|
|
|
|
|
|
|
// scSelection includes anything caret related
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (changes.testFlag(QSynedit::StatusChange::scSelection)) {
|
2021-11-18 21:25:28 +08:00
|
|
|
|
if (!selAvail() && pSettings->editor().highlightCurrentWord()) {
|
2021-11-03 23:27:05 +08:00
|
|
|
|
mCurrentHighlightedWord = wordAtCursor();
|
2021-11-18 21:25:28 +08:00
|
|
|
|
} else if (selAvail() && blockBegin() == wordStart()
|
|
|
|
|
&& blockEnd() == wordEnd()){
|
|
|
|
|
mCurrentHighlightedWord = selText();
|
2021-11-03 23:27:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
mCurrentHighlightedWord = "";
|
|
|
|
|
}
|
2021-11-08 21:19:48 +08:00
|
|
|
|
|
2021-11-03 18:09:12 +08:00
|
|
|
|
if (mOldHighlightedWord != mCurrentHighlightedWord) {
|
2021-08-31 14:40:41 +08:00
|
|
|
|
invalidate();
|
2021-11-03 18:09:12 +08:00
|
|
|
|
mOldHighlightedWord = mCurrentHighlightedWord;
|
2021-08-31 14:40:41 +08:00
|
|
|
|
}
|
2021-06-12 22:36:23 +08:00
|
|
|
|
pMainWindow->updateStatusbarForLineCol();
|
2021-06-10 09:34:59 +08:00
|
|
|
|
|
2021-09-24 11:41:14 +08:00
|
|
|
|
// Update the function tip
|
|
|
|
|
if (pSettings->editor().showFunctionTips()) {
|
2022-03-10 12:15:44 +08:00
|
|
|
|
updateFunctionTip(false);
|
|
|
|
|
mFunctionTipTimer.stop();
|
|
|
|
|
mFunctionTipTimer.start(500);
|
2022-03-18 23:13:43 +08:00
|
|
|
|
// updateFunctionTip();
|
2021-09-24 11:41:14 +08:00
|
|
|
|
}
|
2021-06-10 09:34:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 11:41:14 +08:00
|
|
|
|
|
2021-06-10 09:34:59 +08:00
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
if (changes.testFlag(QSynedit::scInsertMode) | changes.testFlag(QSynedit::scReadOnly))
|
2021-06-12 22:36:23 +08:00
|
|
|
|
pMainWindow->updateForStatusbarModeInfo();
|
|
|
|
|
|
|
|
|
|
pMainWindow->updateEditorActions();
|
2021-06-10 09:34:59 +08:00
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (changes.testFlag(QSynedit::StatusChange::scCaretY) && mParentPageControl) {
|
2021-09-02 12:14:02 +08:00
|
|
|
|
pMainWindow->caretList().addCaret(this,caretY(),caretX());
|
|
|
|
|
pMainWindow->updateCaretActions();
|
|
|
|
|
}
|
2021-06-21 16:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 10:14:07 +08:00
|
|
|
|
void Editor::onGutterClicked(Qt::MouseButton button, int , int , int line)
|
2021-07-03 13:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
|
toggleBreakpoint(line);
|
|
|
|
|
}
|
|
|
|
|
mGutterClickedLine = line;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 10:07:35 +08:00
|
|
|
|
void Editor::onTipEvalValueReady(const QString& value)
|
2021-08-29 22:08:43 +08:00
|
|
|
|
{
|
|
|
|
|
if (mCurrentWord == mCurrentDebugTipWord) {
|
2021-10-31 10:11:30 +08:00
|
|
|
|
QString newValue;
|
|
|
|
|
if (value.length()>100) {
|
|
|
|
|
newValue = value.left(100) + "...";
|
|
|
|
|
} else {
|
|
|
|
|
newValue = value;
|
|
|
|
|
}
|
2022-04-07 21:35:09 +08:00
|
|
|
|
QToolTip::showText(QCursor::pos(), mCurrentDebugTipWord + " = " + newValue, this);
|
2021-08-29 22:08:43 +08:00
|
|
|
|
}
|
|
|
|
|
disconnect(pMainWindow->debugger(), &Debugger::evalValueReady,
|
|
|
|
|
this, &Editor::onTipEvalValueReady);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-02 12:14:02 +08:00
|
|
|
|
void Editor::onLinesDeleted(int first, int count)
|
|
|
|
|
{
|
|
|
|
|
pMainWindow->caretList().linesDeleted(this,first,count);
|
2022-10-16 23:10:57 +08:00
|
|
|
|
pMainWindow->debugger()->breakpointModel()->onFileDeleteLines(mFilename,first,count,inProject());
|
2022-10-11 21:51:33 +08:00
|
|
|
|
pMainWindow->bookmarkModel()->onFileDeleteLines(mFilename,first,count, inProject());
|
2021-09-05 22:16:54 +08:00
|
|
|
|
resetBreakpoints();
|
2021-10-21 17:31:25 +08:00
|
|
|
|
resetBookmarks();
|
2021-09-05 22:16:54 +08:00
|
|
|
|
if (!pSettings->editor().syntaxCheckWhenLineChanged()) {
|
|
|
|
|
//todo: update syntax issues
|
|
|
|
|
}
|
2021-09-02 12:14:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::onLinesInserted(int first, int count)
|
|
|
|
|
{
|
|
|
|
|
pMainWindow->caretList().linesInserted(this,first,count);
|
2022-10-16 23:10:57 +08:00
|
|
|
|
pMainWindow->debugger()->breakpointModel()->onFileInsertLines(mFilename,first,count, inProject());
|
2022-10-11 21:51:33 +08:00
|
|
|
|
pMainWindow->bookmarkModel()->onFileInsertLines(mFilename,first,count, inProject());
|
2021-09-05 22:16:54 +08:00
|
|
|
|
resetBreakpoints();
|
2021-10-21 17:31:25 +08:00
|
|
|
|
resetBookmarks();
|
2021-09-05 22:16:54 +08:00
|
|
|
|
if (!pSettings->editor().syntaxCheckWhenLineChanged()) {
|
|
|
|
|
//todo: update syntax issues
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 12:15:44 +08:00
|
|
|
|
void Editor::onFunctionTipsTimer()
|
|
|
|
|
{
|
|
|
|
|
mFunctionTipTimer.stop();
|
|
|
|
|
updateFunctionTip(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 20:38:39 +08:00
|
|
|
|
bool Editor::isBraceChar(QChar ch)
|
|
|
|
|
{
|
|
|
|
|
switch( ch.unicode()) {
|
|
|
|
|
case '{':
|
|
|
|
|
case '}':
|
|
|
|
|
case '[':
|
|
|
|
|
case ']':
|
|
|
|
|
case '(':
|
|
|
|
|
case ')':
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 17:51:26 +08:00
|
|
|
|
bool Editor::shouldOpenInReadonly()
|
|
|
|
|
{
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (mProject && mProject->findUnit(mFilename))
|
2022-09-30 17:51:26 +08:00
|
|
|
|
return false;
|
|
|
|
|
return pSettings->editor().readOnlySytemHeader()
|
|
|
|
|
&& mParser && (mParser->isSystemHeaderFile(mFilename) || mParser->isProjectHeaderFile(mFilename));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 17:31:25 +08:00
|
|
|
|
void Editor::resetBookmarks()
|
|
|
|
|
{
|
2022-10-11 21:51:33 +08:00
|
|
|
|
mBookmarkLines=pMainWindow->bookmarkModel()->bookmarksInFile(mFilename,inProject());
|
2021-10-21 17:31:25 +08:00
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-05 22:16:54 +08:00
|
|
|
|
void Editor::resetBreakpoints()
|
|
|
|
|
{
|
|
|
|
|
mBreakpointLines.clear();
|
|
|
|
|
foreach (const PBreakpoint& breakpoint,
|
2022-10-16 23:10:57 +08:00
|
|
|
|
pMainWindow->debugger()->breakpointModel()->breakpoints(inProject())) {
|
2021-09-05 22:16:54 +08:00
|
|
|
|
if (breakpoint->filename == mFilename) {
|
|
|
|
|
mBreakpointLines.insert(breakpoint->line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
invalidate();
|
2021-09-02 12:14:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 14:51:20 +08:00
|
|
|
|
bool Editor::notParsed()
|
|
|
|
|
{
|
|
|
|
|
if (!mParser)
|
|
|
|
|
return true;
|
|
|
|
|
return mParser->findFileIncludes(mFilename)==nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 16:16:58 +08:00
|
|
|
|
void Editor::insertLine()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecInsertLine,QChar(),nullptr);
|
2021-11-22 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::deleteWord()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteWord,QChar(),nullptr);
|
2021-11-22 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 11:23:30 +08:00
|
|
|
|
void Editor::deleteToWordStart()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteWordStart,QChar(),nullptr);
|
2022-01-24 11:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::deleteToWordEnd()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteWordEnd,QChar(),nullptr);
|
2022-01-24 11:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 16:16:58 +08:00
|
|
|
|
void Editor::deleteLine()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteLine,QChar(),nullptr);
|
2021-11-22 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::duplicateLine()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDuplicateLine,QChar(),nullptr);
|
2021-11-22 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::deleteToEOL()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteEOL,QChar(),nullptr);
|
2021-11-22 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::deleteToBOL()
|
|
|
|
|
{
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecDeleteBOL,QChar(),nullptr);
|
2021-11-22 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 15:18:57 +08:00
|
|
|
|
void Editor::gotoBlockStart()
|
|
|
|
|
{
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecBlockStart,QChar(),nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::gotoBlockEnd()
|
|
|
|
|
{
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecBlockEnd,QChar(),nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion(
|
2022-09-25 09:55:18 +08:00
|
|
|
|
const QSynedit::BufferCoord &pos,
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QString &memberOperator,
|
|
|
|
|
QStringList &memberExpression)
|
|
|
|
|
{
|
2021-12-17 21:47:37 +08:00
|
|
|
|
QStringList expression = getExpressionAtPosition(pos);
|
2021-12-18 23:36:58 +08:00
|
|
|
|
return getOwnerExpressionAndMember(expression,memberOperator,memberExpression);
|
2021-12-04 10:02:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 21:47:37 +08:00
|
|
|
|
QStringList Editor::getExpressionAtPosition(
|
2022-09-25 09:55:18 +08:00
|
|
|
|
const QSynedit::BufferCoord &pos)
|
2021-12-01 23:41:14 +08:00
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
if (!highlighter())
|
|
|
|
|
return result;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int line = pos.line-1;
|
|
|
|
|
int ch = pos.ch-1;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
int symbolMatchingLevel = 0;
|
|
|
|
|
LastSymbolType lastSymbolType=LastSymbolType::None;
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighter highlighter;
|
2022-04-07 21:35:09 +08:00
|
|
|
|
if (isNew())
|
|
|
|
|
highlighter = highlighterManager.getCppHighlighter();
|
|
|
|
|
else
|
|
|
|
|
highlighter = highlighterManager.getHighlighter(mFilename);
|
2021-12-19 10:16:46 +08:00
|
|
|
|
if (!highlighter)
|
|
|
|
|
return result;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
while (true) {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (line>=document()->count() || line<0)
|
2021-12-01 23:41:14 +08:00
|
|
|
|
break;
|
|
|
|
|
QStringList tokens;
|
|
|
|
|
if (line==0) {
|
2021-12-19 10:16:46 +08:00
|
|
|
|
highlighter->resetState();
|
2021-12-01 23:41:14 +08:00
|
|
|
|
} else {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
highlighter->setState(document()->ranges(line-1));
|
2021-12-01 23:41:14 +08:00
|
|
|
|
}
|
2022-04-19 21:18:41 +08:00
|
|
|
|
QString sLine = document()->getString(line);
|
2021-12-19 10:16:46 +08:00
|
|
|
|
highlighter->setLine(sLine,line-1);
|
|
|
|
|
while (!highlighter->eol()) {
|
|
|
|
|
int start = highlighter->getTokenPos();
|
|
|
|
|
QString token = highlighter->getToken();
|
2021-12-01 23:41:14 +08:00
|
|
|
|
int endPos = start + token.length()-1;
|
|
|
|
|
if (start>ch) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr = highlighter->getTokenAttribute();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ( (line == pos.line-1)
|
2021-12-01 23:41:14 +08:00
|
|
|
|
&& (start<=ch) && (ch<=endPos)) {
|
2022-11-23 12:51:23 +08:00
|
|
|
|
if (attr->tokenType() == QSynedit::TokenType::Comment
|
|
|
|
|
|| attr->tokenType() == QSynedit::TokenType::String) {
|
2021-12-01 23:41:14 +08:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-23 12:51:23 +08:00
|
|
|
|
if (attr->tokenType() != QSynedit::TokenType::Comment
|
|
|
|
|
&& attr->tokenType() != QSynedit::TokenType::Space){
|
2021-12-01 23:41:14 +08:00
|
|
|
|
tokens.append(token);
|
|
|
|
|
}
|
2021-12-19 10:16:46 +08:00
|
|
|
|
highlighter->next();
|
2021-12-01 23:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
for (int i=tokens.count()-1;i>=0;i--) {
|
|
|
|
|
QString token = tokens[i];
|
|
|
|
|
switch(lastSymbolType) {
|
2021-12-03 11:40:05 +08:00
|
|
|
|
case LastSymbolType::ScopeResolutionOperator: //before '::'
|
|
|
|
|
if (token==">") {
|
|
|
|
|
lastSymbolType=LastSymbolType::MatchingAngleQuotation;
|
|
|
|
|
symbolMatchingLevel=0;
|
|
|
|
|
} else if (isIdentChar(token.front())) {
|
|
|
|
|
lastSymbolType=LastSymbolType::Identifier;
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::ObjectMemberOperator: //before '.'
|
|
|
|
|
case LastSymbolType::PointerMemberOperator: //before '->'
|
|
|
|
|
case LastSymbolType::PointerToMemberOfObjectOperator: //before '.*'
|
|
|
|
|
case LastSymbolType::PointerToMemberOfPointerOperator: //before '->*'
|
|
|
|
|
if (token == ")" ) {
|
|
|
|
|
lastSymbolType=LastSymbolType::MatchingParenthesis;
|
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (token == "]") {
|
|
|
|
|
lastSymbolType=LastSymbolType::MatchingBracket;
|
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (isIdentChar(token.front())) {
|
|
|
|
|
lastSymbolType=LastSymbolType::Identifier;
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::AsteriskSign: // before '*':
|
|
|
|
|
if (token == '*') {
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::AmpersandSign: // before '&':
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::ParenthesisMatched: //before '()'
|
2021-12-12 13:02:00 +08:00
|
|
|
|
// if (token == ".") {
|
|
|
|
|
// lastSymbolType=LastSymbolType::ObjectMemberOperator;
|
|
|
|
|
// } else if (token=="->") {
|
|
|
|
|
// lastSymbolType = LastSymbolType::PointerMemberOperator;
|
|
|
|
|
// } else if (token == ".*") {
|
|
|
|
|
// lastSymbolType = LastSymbolType::PointerToMemberOfObjectOperator;
|
|
|
|
|
// } else if (token == "->*"){
|
|
|
|
|
// lastSymbolType = LastSymbolType::PointerToMemberOfPointerOperator;
|
|
|
|
|
// } else if (token==">") {
|
|
|
|
|
// lastSymbolType=LastSymbolType::MatchingAngleQuotation;
|
|
|
|
|
// symbolMatchingLevel=0;
|
|
|
|
|
// } else
|
|
|
|
|
if (token == ")" ) {
|
2021-12-03 11:40:05 +08:00
|
|
|
|
lastSymbolType=LastSymbolType::MatchingParenthesis;
|
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (token == "]") {
|
|
|
|
|
lastSymbolType=LastSymbolType::MatchingBracket;
|
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (token == "*") {
|
|
|
|
|
lastSymbolType=LastSymbolType::AsteriskSign;
|
|
|
|
|
} else if (token == "&") {
|
|
|
|
|
lastSymbolType=LastSymbolType::AmpersandSign;
|
|
|
|
|
} else if (isIdentChar(token.front())) {
|
|
|
|
|
lastSymbolType=LastSymbolType::Identifier;
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::BracketMatched: //before '[]'
|
|
|
|
|
if (token == ")" ) {
|
|
|
|
|
lastSymbolType=LastSymbolType::MatchingParenthesis;
|
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (token == "]") {
|
|
|
|
|
lastSymbolType=LastSymbolType::MatchingBracket;
|
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (isIdentChar(token.front())) {
|
|
|
|
|
lastSymbolType=LastSymbolType::Identifier;
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::AngleQuotationMatched: //before '<>'
|
|
|
|
|
if (isIdentChar(token.front())) {
|
|
|
|
|
lastSymbolType=LastSymbolType::Identifier;
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
case LastSymbolType::None:
|
2021-12-03 11:40:05 +08:00
|
|
|
|
if (token =="::") {
|
|
|
|
|
lastSymbolType=LastSymbolType::ScopeResolutionOperator;
|
|
|
|
|
} else if (token == ".") {
|
|
|
|
|
lastSymbolType=LastSymbolType::ObjectMemberOperator;
|
|
|
|
|
} else if (token=="->") {
|
|
|
|
|
lastSymbolType = LastSymbolType::PointerMemberOperator;
|
|
|
|
|
} else if (token == ".*") {
|
|
|
|
|
lastSymbolType = LastSymbolType::PointerToMemberOfObjectOperator;
|
|
|
|
|
} else if (token == "->*"){
|
|
|
|
|
lastSymbolType = LastSymbolType::PointerToMemberOfPointerOperator;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
} else if (token == ")" ) {
|
2021-12-02 18:29:37 +08:00
|
|
|
|
lastSymbolType=LastSymbolType::MatchingParenthesis;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (token == "]") {
|
2021-12-02 18:29:37 +08:00
|
|
|
|
lastSymbolType=LastSymbolType::MatchingBracket;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
symbolMatchingLevel = 0;
|
|
|
|
|
} else if (isIdentChar(token.front())) {
|
|
|
|
|
lastSymbolType=LastSymbolType::Identifier;
|
|
|
|
|
} else
|
|
|
|
|
return result;
|
|
|
|
|
break;
|
2021-12-03 11:40:05 +08:00
|
|
|
|
case LastSymbolType::TildeSign:
|
|
|
|
|
if (token =="::") {
|
|
|
|
|
lastSymbolType=LastSymbolType::ScopeResolutionOperator;
|
2021-12-04 10:02:07 +08:00
|
|
|
|
} else {
|
|
|
|
|
// "~" must appear after "::"
|
|
|
|
|
result.pop_front();
|
2021-12-03 11:40:05 +08:00
|
|
|
|
return result;
|
2021-12-04 10:02:07 +08:00
|
|
|
|
}
|
2021-12-03 11:40:05 +08:00
|
|
|
|
break;;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
case LastSymbolType::Identifier:
|
2021-12-03 11:40:05 +08:00
|
|
|
|
if (token =="::") {
|
|
|
|
|
lastSymbolType=LastSymbolType::ScopeResolutionOperator;
|
|
|
|
|
} else if (token == ".") {
|
|
|
|
|
lastSymbolType=LastSymbolType::ObjectMemberOperator;
|
|
|
|
|
} else if (token=="->") {
|
|
|
|
|
lastSymbolType = LastSymbolType::PointerMemberOperator;
|
|
|
|
|
} else if (token == ".*") {
|
|
|
|
|
lastSymbolType = LastSymbolType::PointerToMemberOfObjectOperator;
|
|
|
|
|
} else if (token == "->*"){
|
|
|
|
|
lastSymbolType = LastSymbolType::PointerToMemberOfPointerOperator;
|
|
|
|
|
} else if (token == "~") {
|
|
|
|
|
lastSymbolType=LastSymbolType::TildeSign;
|
|
|
|
|
} else if (token == "*") {
|
|
|
|
|
lastSymbolType=LastSymbolType::AsteriskSign;
|
|
|
|
|
} else if (token == "&") {
|
|
|
|
|
lastSymbolType=LastSymbolType::AmpersandSign;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
} else
|
|
|
|
|
return result; // stop matching;
|
2021-12-02 18:29:37 +08:00
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::MatchingParenthesis:
|
|
|
|
|
if (token=="(") {
|
|
|
|
|
if (symbolMatchingLevel==0) {
|
|
|
|
|
lastSymbolType=LastSymbolType::ParenthesisMatched;
|
|
|
|
|
} else {
|
|
|
|
|
symbolMatchingLevel--;
|
|
|
|
|
}
|
|
|
|
|
} else if (token==")") {
|
|
|
|
|
symbolMatchingLevel++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::MatchingBracket:
|
|
|
|
|
if (token=="[") {
|
|
|
|
|
if (symbolMatchingLevel==0) {
|
|
|
|
|
lastSymbolType=LastSymbolType::BracketMatched;
|
|
|
|
|
} else {
|
|
|
|
|
symbolMatchingLevel--;
|
|
|
|
|
}
|
|
|
|
|
} else if (token=="]") {
|
|
|
|
|
symbolMatchingLevel++;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
}
|
2021-12-03 11:40:05 +08:00
|
|
|
|
break;
|
|
|
|
|
case LastSymbolType::MatchingAngleQuotation:
|
|
|
|
|
if (token=="<") {
|
|
|
|
|
if (symbolMatchingLevel==0) {
|
2022-11-29 12:06:29 +08:00
|
|
|
|
lastSymbolType=LastSymbolType::AngleQuotationMatched;
|
2021-12-03 11:40:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
symbolMatchingLevel--;
|
|
|
|
|
}
|
|
|
|
|
} else if (token==">") {
|
|
|
|
|
symbolMatchingLevel++;
|
|
|
|
|
}
|
2021-12-02 18:29:37 +08:00
|
|
|
|
break;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
}
|
2021-12-03 11:40:05 +08:00
|
|
|
|
result.push_front(token);
|
2021-12-01 23:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
line--;
|
|
|
|
|
if (line>=0)
|
2022-04-19 21:18:41 +08:00
|
|
|
|
ch = document()->getString(line).length()+1;
|
2021-12-01 23:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QString Editor::getWordForCompletionSearch(const QSynedit::BufferCoord &pos,bool permitTilde)
|
2021-12-04 10:02:07 +08:00
|
|
|
|
{
|
|
|
|
|
QString result = "";
|
|
|
|
|
QString s;
|
|
|
|
|
|
2022-07-04 10:01:40 +08:00
|
|
|
|
s = document()->getString(pos.line - 1);
|
2021-12-04 10:02:07 +08:00
|
|
|
|
int len = s.length();
|
|
|
|
|
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int wordBegin = pos.ch - 1 - 1; //BufferCoord::Char starts with 1
|
|
|
|
|
int wordEnd = pos.ch - 1 - 1;
|
2021-12-04 10:02:07 +08:00
|
|
|
|
|
|
|
|
|
while ((wordBegin >= 0) && (wordBegin<len)) {
|
|
|
|
|
if (isIdentChar(s[wordBegin])) {
|
|
|
|
|
wordBegin--;
|
|
|
|
|
} else if (permitTilde && s[wordBegin] == '~') { // allow destructor signs
|
|
|
|
|
wordBegin--;
|
|
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Get end result
|
|
|
|
|
return s.mid(wordBegin+1, wordEnd - wordBegin);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 23:00:34 +08:00
|
|
|
|
QChar Editor::getCurrentChar()
|
|
|
|
|
{
|
|
|
|
|
if (lineText().length()<caretX())
|
|
|
|
|
return QChar();
|
|
|
|
|
else
|
2021-08-29 10:14:07 +08:00
|
|
|
|
return lineText().at(caretX()-1);
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 13:24:26 +08:00
|
|
|
|
bool Editor::handleSymbolCompletion(QChar key)
|
2021-06-21 16:25:21 +08:00
|
|
|
|
{
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (!pSettings->editor().completeSymbols())
|
2021-06-22 13:24:26 +08:00
|
|
|
|
return false;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
if (!insertMode())
|
|
|
|
|
return false;
|
2021-06-21 16:25:21 +08:00
|
|
|
|
|
2021-06-22 13:24:26 +08:00
|
|
|
|
//todo: better methods to detect current caret type
|
2022-04-03 11:54:07 +08:00
|
|
|
|
if (highlighter()) {
|
|
|
|
|
if (caretX() <= 1) {
|
|
|
|
|
if (caretY()>1) {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (highlighter()->isLastLineCommentNotFinished(document()->ranges(caretY() - 2).state))
|
2022-04-03 11:54:07 +08:00
|
|
|
|
return false;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state)
|
2022-04-03 11:54:07 +08:00
|
|
|
|
&& (key!='\"') && (key!='\''))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord HighlightPos = QSynedit::BufferCoord{caretX()-1, caretY()};
|
2022-04-03 11:54:07 +08:00
|
|
|
|
// Check if that line is highlighted as comment
|
2022-11-23 11:41:16 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr;
|
|
|
|
|
QString token;
|
2022-04-03 11:54:07 +08:00
|
|
|
|
bool tokenFinished;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if (getHighlighterAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) {
|
|
|
|
|
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
|
2022-04-03 11:54:07 +08:00
|
|
|
|
return false;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((attr->tokenType() == QSynedit::TokenType::String) && (!tokenFinished)
|
2022-04-03 11:54:07 +08:00
|
|
|
|
&& (key!='\'') && (key!='\"') && (key!='(') && (key!=')'))
|
|
|
|
|
return false;
|
|
|
|
|
if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText())))
|
|
|
|
|
return false;
|
2022-11-23 11:41:16 +08:00
|
|
|
|
if ((key == '\'') && (attr->name() == "SYNS_AttrNumber"))
|
2022-04-03 11:54:07 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if that line is highlighted as string or character or comment
|
|
|
|
|
// if (Attr = fText.Highlighter.StringAttribute) or (Attr = fText.Highlighter.CommentAttribute) or SameStr(Attr.Name,
|
|
|
|
|
// 'Character') then
|
|
|
|
|
// Exit;
|
|
|
|
|
|
|
|
|
|
QuoteStatus status;
|
|
|
|
|
switch(key.unicode()) {
|
|
|
|
|
case '(':
|
|
|
|
|
if (pSettings->editor().completeParenthese()) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleParentheseCompletion();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case ')':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail())
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
if (pSettings->editor().completeParenthese() && pSettings->editor().overwriteSymbols()) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleParentheseSkip();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case '[':
|
|
|
|
|
if (pSettings->editor().completeBracket()) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleBracketCompletion();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case ']':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail())
|
|
|
|
|
return false;
|
|
|
|
|
if (pSettings->editor().completeBracket() && pSettings->editor().overwriteSymbols()) {
|
|
|
|
|
return handleBracketSkip();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
case '*':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
status = getQuoteStatus();
|
|
|
|
|
if (pSettings->editor().completeComment() && (status == QuoteStatus::NotQuote)) {
|
|
|
|
|
return handleMultilineCommentCompletion();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
case '{':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (pSettings->editor().completeBrace()) {
|
|
|
|
|
return handleBraceCompletion();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
case '}':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail())
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
if (pSettings->editor().completeBrace() && pSettings->editor().overwriteSymbols()) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleBraceSkip();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case '\'':
|
|
|
|
|
if (pSettings->editor().completeSingleQuote()) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleSingleQuoteCompletion();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case '\"':
|
|
|
|
|
if (pSettings->editor().completeDoubleQuote()) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleDoubleQuoteCompletion();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case '<':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail())
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
if (pSettings->editor().completeGlobalInclude()) { // #include <>
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleGlobalIncludeCompletion();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case '>':
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail())
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
if (pSettings->editor().completeGlobalInclude() && pSettings->editor().overwriteSymbols()) { // #include <>
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return handleGlobalIncludeSkip();
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 23:00:34 +08:00
|
|
|
|
bool Editor::handleParentheseCompletion()
|
|
|
|
|
{
|
|
|
|
|
QuoteStatus status = getQuoteStatus();
|
|
|
|
|
if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail() && status == QuoteStatus::NotQuote) {
|
|
|
|
|
QString text=selText();
|
|
|
|
|
beginUpdate();
|
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'(');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setSelText(text);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,')');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
endUndoBlock();
|
|
|
|
|
endUpdate();
|
|
|
|
|
} else {
|
|
|
|
|
beginUpdate();
|
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'(');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret = caretXY();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,')');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setCaretXY(oldCaret);
|
|
|
|
|
endUndoBlock();
|
|
|
|
|
endUpdate();
|
|
|
|
|
}
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// if (status == QuoteStatus::NotQuote) && FunctionTipAllowed then
|
|
|
|
|
// fFunctionTip.Activated := true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleParentheseSkip()
|
2021-06-22 13:24:26 +08:00
|
|
|
|
{
|
2021-06-22 23:00:34 +08:00
|
|
|
|
if (getCurrentChar() != ')')
|
|
|
|
|
return false;
|
|
|
|
|
QuoteStatus status = getQuoteStatus();
|
|
|
|
|
if (status == QuoteStatus::RawStringNoEscape) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (status != QuoteStatus::NotQuote)
|
|
|
|
|
return false;
|
2022-03-02 15:45:43 +08:00
|
|
|
|
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (document()->count()==0)
|
2022-03-02 15:45:43 +08:00
|
|
|
|
return false;
|
2022-04-13 20:04:10 +08:00
|
|
|
|
if (highlighter()) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
2022-04-13 20:04:10 +08:00
|
|
|
|
if (lastLineState.parenthesisLevel==0) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2022-04-13 20:04:10 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pos = getMatchingBracket();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (pos.line != 0) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2022-04-13 20:04:10 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
2022-03-02 15:45:43 +08:00
|
|
|
|
return false;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleBracketCompletion()
|
|
|
|
|
{
|
|
|
|
|
// QuoteStatus status = getQuoteStatus();
|
|
|
|
|
// if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
QuoteStatus status = getQuoteStatus();
|
|
|
|
|
if (selAvail() && status == QuoteStatus::NotQuote) {
|
|
|
|
|
QString text=selText();
|
|
|
|
|
beginUpdate();
|
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'[');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setSelText(text);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,']');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
endUndoBlock();
|
|
|
|
|
endUpdate();
|
|
|
|
|
} else {
|
|
|
|
|
beginUpdate();
|
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'[');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret = caretXY();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,']');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setCaretXY(oldCaret);
|
|
|
|
|
endUndoBlock();
|
|
|
|
|
endUpdate();
|
|
|
|
|
}
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleBracketSkip()
|
|
|
|
|
{
|
|
|
|
|
if (getCurrentChar() != ']')
|
|
|
|
|
return false;
|
2022-04-13 20:04:10 +08:00
|
|
|
|
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (document()->count()==0)
|
2022-03-02 15:45:43 +08:00
|
|
|
|
return false;
|
2022-04-13 20:04:10 +08:00
|
|
|
|
if (highlighter()) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
2022-04-13 20:04:10 +08:00
|
|
|
|
if (lastLineState.bracketLevel==0) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2022-04-13 20:04:10 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pos = getMatchingBracket();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (pos.line != 0) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2022-04-13 20:04:10 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleMultilineCommentCompletion()
|
|
|
|
|
{
|
2022-11-04 20:27:35 +08:00
|
|
|
|
if ((caretX()-2>=0) && (caretX()-2 < lineText().length()) && (lineText()[caretX() - 2] == '/')) {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
QString text=selText();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
beginUpdate();
|
2022-03-07 20:51:56 +08:00
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'*');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret;
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
oldCaret = caretXY();
|
|
|
|
|
else
|
|
|
|
|
setSelText(text);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'*');
|
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'/');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
setCaretXY(oldCaret);
|
2022-03-07 20:51:56 +08:00
|
|
|
|
endUndoBlock();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
endUpdate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleBraceCompletion()
|
|
|
|
|
{
|
|
|
|
|
QString s = lineText().trimmed();
|
|
|
|
|
int i= caretY()-2;
|
|
|
|
|
while ((s.isEmpty()) && (i>=0)) {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
s=document()->getString(i);
|
2021-06-22 23:00:34 +08:00
|
|
|
|
i--;
|
|
|
|
|
}
|
2022-03-07 21:53:52 +08:00
|
|
|
|
QString text=selText();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
beginUpdate();
|
2022-03-07 20:51:56 +08:00
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'{');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret;
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
|
oldCaret = caretXY();
|
|
|
|
|
} else {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecInsertLine);
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setSelText(text);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecInsertLine);
|
2022-03-07 21:53:52 +08:00
|
|
|
|
}
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'}');
|
2021-06-22 23:00:34 +08:00
|
|
|
|
if (
|
|
|
|
|
( (s.startsWith("struct")
|
|
|
|
|
|| s.startsWith("class")
|
|
|
|
|
|| s.startsWith("union")
|
|
|
|
|
|| s.startsWith("typedef")
|
|
|
|
|
|| s.startsWith("public")
|
|
|
|
|
|| s.startsWith("private")
|
|
|
|
|
|| s.startsWith("enum") )
|
|
|
|
|
&& !s.contains(';')
|
|
|
|
|
) || s.endsWith('=')) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,';');
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
setCaretXY(oldCaret);
|
2022-03-07 20:51:56 +08:00
|
|
|
|
endUndoBlock();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
endUpdate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleBraceSkip()
|
|
|
|
|
{
|
|
|
|
|
if (getCurrentChar() != '}')
|
|
|
|
|
return false;
|
2022-04-13 20:04:10 +08:00
|
|
|
|
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (document()->count()==0)
|
2022-03-02 15:45:43 +08:00
|
|
|
|
return false;
|
2022-04-13 20:04:10 +08:00
|
|
|
|
if (highlighter()) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
2022-04-13 20:04:10 +08:00
|
|
|
|
if (lastLineState.braceLevel==0) {
|
|
|
|
|
bool oldInsertMode = insertMode();
|
|
|
|
|
setInsertMode(false); //set mode to overwrite
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'}');
|
2022-04-13 20:04:10 +08:00
|
|
|
|
setInsertMode(oldInsertMode);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pos = getMatchingBracket();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (pos.line != 0) {
|
2022-04-13 20:04:10 +08:00
|
|
|
|
bool oldInsertMode = insertMode();
|
|
|
|
|
setInsertMode(false); //set mode to overwrite
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'}');
|
2022-04-13 20:04:10 +08:00
|
|
|
|
setInsertMode(oldInsertMode);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleSingleQuoteCompletion()
|
|
|
|
|
{
|
|
|
|
|
QuoteStatus status = getQuoteStatus();
|
|
|
|
|
QChar ch = getCurrentChar();
|
|
|
|
|
if (ch == '\'') {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (status == QuoteStatus::SingleQuote && !selAvail()) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (status == QuoteStatus::NotQuote) {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail()) {
|
|
|
|
|
QString text=selText();
|
|
|
|
|
beginUpdate();
|
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'\'');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setSelText(text);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'\'');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
endUndoBlock();
|
|
|
|
|
endUpdate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-06-23 08:55:56 +08:00
|
|
|
|
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
// insert ''
|
|
|
|
|
beginUpdate();
|
2022-03-07 20:51:56 +08:00
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'\'');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret = caretXY();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'\'');
|
2021-06-22 23:00:34 +08:00
|
|
|
|
setCaretXY(oldCaret);
|
2022-03-07 20:51:56 +08:00
|
|
|
|
endUndoBlock();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
endUpdate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleDoubleQuoteCompletion()
|
|
|
|
|
{
|
|
|
|
|
QuoteStatus status = getQuoteStatus();
|
|
|
|
|
QChar ch = getCurrentChar();
|
|
|
|
|
if (ch == '"') {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if ((status == QuoteStatus::DoubleQuote || status == QuoteStatus::RawString)
|
|
|
|
|
&& !selAvail()) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (status == QuoteStatus::NotQuote) {
|
2022-03-07 21:53:52 +08:00
|
|
|
|
if (selAvail()) {
|
|
|
|
|
QString text=selText();
|
|
|
|
|
beginUpdate();
|
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'"');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
setSelText(text);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'"');
|
2022-03-07 21:53:52 +08:00
|
|
|
|
endUndoBlock();
|
|
|
|
|
endUpdate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-06-23 08:55:56 +08:00
|
|
|
|
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
// insert ""
|
|
|
|
|
beginUpdate();
|
2022-03-07 20:51:56 +08:00
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'"');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret = caretXY();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'"');
|
2021-06-22 23:00:34 +08:00
|
|
|
|
setCaretXY(oldCaret);
|
2022-03-07 20:51:56 +08:00
|
|
|
|
endUndoBlock();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
endUpdate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleGlobalIncludeCompletion()
|
|
|
|
|
{
|
|
|
|
|
if (!lineText().startsWith('#'))
|
|
|
|
|
return false;
|
|
|
|
|
QString s= lineText().mid(1).trimmed();
|
|
|
|
|
if (!s.startsWith("include")) //it's not #include
|
|
|
|
|
return false;
|
|
|
|
|
beginUpdate();
|
2022-03-07 20:51:56 +08:00
|
|
|
|
beginUndoBlock();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'<');
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCaret = caretXY();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,'>');
|
2021-06-22 23:00:34 +08:00
|
|
|
|
setCaretXY(oldCaret);
|
|
|
|
|
endUpdate();
|
2022-03-07 20:51:56 +08:00
|
|
|
|
endUndoBlock();
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Editor::handleGlobalIncludeSkip()
|
|
|
|
|
{
|
|
|
|
|
if (getCurrentChar()!='>')
|
|
|
|
|
return false;
|
|
|
|
|
QString s= lineText().mid(1).trimmed();
|
|
|
|
|
if (!s.startsWith("include")) //it's not #include
|
|
|
|
|
return false;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pos = getMatchingBracket();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (pos.line != 0) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
setCaretXY(QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
2021-06-22 23:00:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2021-06-22 13:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 20:18:20 +08:00
|
|
|
|
bool Editor::handleCodeCompletion(QChar key)
|
2021-08-25 08:48:33 +08:00
|
|
|
|
{
|
|
|
|
|
if (!mCompletionPopup->isEnabled())
|
2021-08-26 20:18:20 +08:00
|
|
|
|
return false;
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (mParser) {
|
|
|
|
|
switch(key.unicode()) {
|
|
|
|
|
case '.':
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar, key);
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2022-01-23 23:27:48 +08:00
|
|
|
|
return true;
|
|
|
|
|
case '>':
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar, key);
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if ((caretX() > 2) && (lineText().length() >= 2) &&
|
|
|
|
|
(lineText()[caretX() - 3] == '-'))
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2022-01-23 23:27:48 +08:00
|
|
|
|
return true;
|
|
|
|
|
case ':':
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar,':',nullptr);
|
2022-01-23 23:27:48 +08:00
|
|
|
|
//setSelText(key);
|
|
|
|
|
if ((caretX() > 2) && (lineText().length() >= 2) &&
|
|
|
|
|
(lineText()[caretX() - 3] == ':'))
|
2022-11-10 13:35:13 +08:00
|
|
|
|
showCompletion("",false,CodeCompletionType::Normal);
|
2022-01-23 23:27:48 +08:00
|
|
|
|
return true;
|
|
|
|
|
case '/':
|
|
|
|
|
case '\\':
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar, key);
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (mParser->isIncludeLine(lineText())) {
|
|
|
|
|
showHeaderCompletion(false);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-23 23:27:48 +08:00
|
|
|
|
return false;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 10:16:06 +08:00
|
|
|
|
void Editor::initParser()
|
|
|
|
|
{
|
2022-10-27 15:18:57 +08:00
|
|
|
|
if (pSettings->codeCompletion().shareParser()) {
|
|
|
|
|
if (pSettings->codeCompletion().enabled()
|
2022-11-23 14:57:26 +08:00
|
|
|
|
&& (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp)
|
2022-10-27 15:18:57 +08:00
|
|
|
|
) {
|
2022-10-28 09:47:34 +08:00
|
|
|
|
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
|
2022-10-27 15:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 12:51:50 +08:00
|
|
|
|
mParser = std::make_shared<CppParser>();
|
|
|
|
|
if (mUseCppSyntax) {
|
|
|
|
|
mParser->setLanguage(ParserLanguage::CPlusPlus);
|
|
|
|
|
} else {
|
|
|
|
|
mParser->setLanguage(ParserLanguage::C);
|
|
|
|
|
}
|
|
|
|
|
mParser->setOnGetFileStream(
|
|
|
|
|
std::bind(
|
|
|
|
|
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
|
|
|
|
|
std::placeholders::_1, std::placeholders::_2));
|
|
|
|
|
resetCppParser(mParser);
|
|
|
|
|
mParser->setEnabled(
|
|
|
|
|
pSettings->codeCompletion().enabled() &&
|
2022-11-23 14:57:26 +08:00
|
|
|
|
(highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp));
|
2021-08-23 10:16:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 13:24:26 +08:00
|
|
|
|
Editor::QuoteStatus Editor::getQuoteStatus()
|
|
|
|
|
{
|
|
|
|
|
QuoteStatus Result = QuoteStatus::NotQuote;
|
2022-01-23 21:04:08 +08:00
|
|
|
|
if (!highlighter())
|
|
|
|
|
return Result;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if ((caretY()>1) && highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state))
|
2021-06-22 13:24:26 +08:00
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
|
2022-04-19 21:18:41 +08:00
|
|
|
|
QString Line = document()->getString(caretY()-1);
|
2021-06-22 23:00:34 +08:00
|
|
|
|
int posX = caretX()-1;
|
|
|
|
|
if (posX >= Line.length()) {
|
|
|
|
|
posX = Line.length()-1;
|
|
|
|
|
}
|
2021-06-23 08:55:56 +08:00
|
|
|
|
for (int i=0; i<posX;i++) {
|
2021-06-22 23:00:34 +08:00
|
|
|
|
if (i+1<Line.length() && (Line[i] == 'R') && (Line[i+1] == '"') && (Result == QuoteStatus::NotQuote)) {
|
|
|
|
|
Result = QuoteStatus::RawString;
|
|
|
|
|
i++; // skip R
|
|
|
|
|
} else if (Line[i] == '(') {
|
|
|
|
|
switch(Result) {
|
|
|
|
|
case QuoteStatus::RawString:
|
|
|
|
|
Result=QuoteStatus::RawStringNoEscape;
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (Line[i] == ')') {
|
|
|
|
|
switch(Result) {
|
|
|
|
|
case QuoteStatus::RawStringNoEscape:
|
|
|
|
|
Result=QuoteStatus::RawString;
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (Line[i] == '"') {
|
|
|
|
|
switch(Result) {
|
|
|
|
|
case QuoteStatus::NotQuote:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuote:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuote:
|
|
|
|
|
Result = QuoteStatus::NotQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::RawString:
|
|
|
|
|
Result=QuoteStatus::NotQuote;
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (Line[i] == '\'') {
|
|
|
|
|
switch(Result) {
|
|
|
|
|
case QuoteStatus::NotQuote:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuote:
|
|
|
|
|
Result = QuoteStatus::NotQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuote:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (Line[i] == '\\') {
|
|
|
|
|
switch(Result) {
|
|
|
|
|
case QuoteStatus::NotQuote:
|
|
|
|
|
Result = QuoteStatus::NotQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuote:
|
|
|
|
|
Result = QuoteStatus::SingleQuoteEscape;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuote:
|
|
|
|
|
Result = QuoteStatus::DoubleQuoteEscape;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch(Result) {
|
|
|
|
|
case QuoteStatus::NotQuote:
|
|
|
|
|
Result = QuoteStatus::NotQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuote:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::SingleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::SingleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuote:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
|
|
|
|
case QuoteStatus::DoubleQuoteEscape:
|
|
|
|
|
Result = QuoteStatus::DoubleQuote;
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-06-22 23:00:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-22 13:24:26 +08:00
|
|
|
|
return Result;
|
2021-06-10 09:34:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 12:24:59 +08:00
|
|
|
|
void Editor::reparse(bool resetParser)
|
2021-08-23 10:16:06 +08:00
|
|
|
|
{
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (!mParentPageControl)
|
|
|
|
|
return;
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (!pSettings->codeCompletion().enabled())
|
|
|
|
|
return;
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (!highlighter())
|
|
|
|
|
return;
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp
|
|
|
|
|
&& highlighter()->language() != QSynedit::HighlighterLanguage::GLSL)
|
2022-01-23 23:27:48 +08:00
|
|
|
|
return;
|
2022-10-10 18:05:18 +08:00
|
|
|
|
if (!mParser)
|
|
|
|
|
return;
|
|
|
|
|
if (!mParser->enabled())
|
2022-10-09 22:19:18 +08:00
|
|
|
|
return;
|
|
|
|
|
//mParser->setEnabled(pSettings->codeCompletion().enabled());
|
2022-07-28 13:51:38 +08:00
|
|
|
|
ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
|
2022-10-28 09:47:34 +08:00
|
|
|
|
if (!inProject()) {
|
|
|
|
|
if (pSettings->codeCompletion().shareParser()) {
|
|
|
|
|
if (language!=mParser->language()) {
|
|
|
|
|
mParser->invalidateFile(mFilename);
|
|
|
|
|
mParser=sharedParser(language);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (language!=mParser->language()) {
|
|
|
|
|
mParser->setLanguage(language);
|
|
|
|
|
resetCppParser(mParser);
|
|
|
|
|
} else if (resetParser) {
|
|
|
|
|
resetCppParser(mParser);
|
|
|
|
|
}
|
2022-10-27 15:18:57 +08:00
|
|
|
|
}
|
2022-07-28 13:51:38 +08:00
|
|
|
|
}
|
2022-10-09 22:19:18 +08:00
|
|
|
|
parseFile(mParser,mFilename, inProject());
|
2021-08-23 10:16:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-03 17:18:43 +08:00
|
|
|
|
void Editor::reparseTodo()
|
|
|
|
|
{
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (!mParentPageControl)
|
|
|
|
|
return;
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (!highlighter())
|
|
|
|
|
return;
|
2022-11-07 21:44:12 +08:00
|
|
|
|
if (pSettings->editor().parseTodos())
|
|
|
|
|
pMainWindow->todoParser()->parseFile(mFilename, inProject());
|
2021-10-03 17:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 23:51:05 +08:00
|
|
|
|
void Editor::insertString(const QString &value, bool moveCursor)
|
|
|
|
|
{
|
|
|
|
|
beginUpdate();
|
|
|
|
|
auto action = finally([this]{
|
|
|
|
|
endUpdate();
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord oldCursorPos = caretXY();
|
2021-09-16 23:51:05 +08:00
|
|
|
|
setSelText(value);
|
|
|
|
|
if (!moveCursor) {
|
|
|
|
|
setCaretXY(oldCursorPos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 20:10:48 +08:00
|
|
|
|
void Editor::insertCodeSnippet(const QString &code)
|
|
|
|
|
{
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
mXOffsetSince = 0;
|
|
|
|
|
mTabStopBegin = -1;
|
|
|
|
|
mTabStopEnd = -1;
|
|
|
|
|
mTabStopY =0;
|
|
|
|
|
mLineBeforeTabStop = "";
|
|
|
|
|
mLineAfterTabStop = "";
|
|
|
|
|
// prevent lots of repaints
|
|
|
|
|
beginUpdate();
|
|
|
|
|
auto action = finally([this]{
|
|
|
|
|
endUpdate();
|
|
|
|
|
});
|
2022-06-28 09:37:18 +08:00
|
|
|
|
if (selAvail())
|
|
|
|
|
setSelText("");
|
2021-11-12 10:51:00 +08:00
|
|
|
|
QStringList sl = textToLines(parseMacros(code));
|
2021-09-30 21:25:48 +08:00
|
|
|
|
int lastI=0;
|
2022-03-10 15:05:16 +08:00
|
|
|
|
// int spaceCount = GetLeftSpacing(
|
|
|
|
|
// leftSpaces(lineText()),true).length();
|
2021-09-30 21:25:48 +08:00
|
|
|
|
QStringList newSl;
|
|
|
|
|
for (int i=0;i<sl.count();i++) {
|
2021-10-03 09:57:19 +08:00
|
|
|
|
int lastPos = 0;
|
2022-03-10 15:05:16 +08:00
|
|
|
|
QString s = sl[i];
|
2022-03-10 14:58:53 +08:00
|
|
|
|
if (i>0)
|
|
|
|
|
lastPos = countLeadingWhitespaceChars(s);
|
2021-09-30 21:25:48 +08:00
|
|
|
|
while (true) {
|
2021-10-01 21:16:22 +08:00
|
|
|
|
int insertPos = s.indexOf(USER_CODE_IN_INSERT_POS);
|
2021-09-30 21:25:48 +08:00
|
|
|
|
if (insertPos < 0) // no %INSERT% macro in this line now
|
|
|
|
|
break;
|
|
|
|
|
PTabStop p = std::make_shared<TabStop>();
|
2021-10-01 21:16:22 +08:00
|
|
|
|
s.remove(insertPos, QString(USER_CODE_IN_INSERT_POS).length());
|
2021-10-03 09:57:19 +08:00
|
|
|
|
//insertPos--;
|
2021-09-30 21:25:48 +08:00
|
|
|
|
p->x = insertPos - lastPos;
|
2021-10-03 09:57:19 +08:00
|
|
|
|
p->endX = p->x ;
|
2021-09-30 21:25:48 +08:00
|
|
|
|
p->y = i - lastI;
|
|
|
|
|
lastPos = insertPos;
|
|
|
|
|
lastI = i;
|
|
|
|
|
mUserCodeInTabStops.append(p);
|
|
|
|
|
}
|
2021-10-03 09:57:19 +08:00
|
|
|
|
lastPos = 0;
|
2022-03-10 14:58:53 +08:00
|
|
|
|
if (i>0)
|
|
|
|
|
lastPos = countLeadingWhitespaceChars(s);
|
2021-10-01 21:16:22 +08:00
|
|
|
|
while (true) {
|
|
|
|
|
int insertPos = s.indexOf(USER_CODE_IN_REPL_POS_BEGIN);
|
|
|
|
|
if (insertPos < 0) // no %INSERT% macro in this line now
|
|
|
|
|
break;
|
|
|
|
|
PTabStop p = std::make_shared<TabStop>();
|
|
|
|
|
s.remove(insertPos, QString(USER_CODE_IN_REPL_POS_BEGIN).length());
|
2021-10-03 09:57:19 +08:00
|
|
|
|
//insertPos--;
|
2021-10-01 21:16:22 +08:00
|
|
|
|
p->x = insertPos - lastPos;
|
|
|
|
|
|
|
|
|
|
int insertEndPos = insertPos +
|
|
|
|
|
s.mid(insertPos).indexOf(USER_CODE_IN_REPL_POS_END);
|
|
|
|
|
if (insertEndPos < insertPos) {
|
|
|
|
|
p->endX = s.length();
|
|
|
|
|
} else {
|
|
|
|
|
s.remove(insertEndPos, QString(USER_CODE_IN_REPL_POS_END).length());
|
2021-10-03 09:57:19 +08:00
|
|
|
|
//insertEndPos--;
|
2021-10-01 21:16:22 +08:00
|
|
|
|
p->endX = insertEndPos - lastPos;
|
|
|
|
|
}
|
|
|
|
|
p->y=i-lastI;
|
|
|
|
|
lastPos = insertEndPos;
|
|
|
|
|
lastI = i;
|
|
|
|
|
mUserCodeInTabStops.append(p);
|
|
|
|
|
}
|
|
|
|
|
newSl.append(s);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord cursorPos = caretXY();
|
2021-11-12 10:51:00 +08:00
|
|
|
|
QString s = linesToText(newSl);
|
2021-10-01 21:16:22 +08:00
|
|
|
|
// if EndsStr(#13#10,s) then
|
|
|
|
|
// Delete(s,Length(s)-1,2)
|
|
|
|
|
// else if EndsStr(#10, s) then
|
|
|
|
|
// Delete(s,Length(s),1);
|
|
|
|
|
setSelText(s);
|
|
|
|
|
if (mUserCodeInTabStops.count()>0) {
|
2022-05-25 18:41:56 +08:00
|
|
|
|
setCaretXY(cursorPos); //restore cursor pos before insert
|
2021-10-01 21:16:22 +08:00
|
|
|
|
mTabStopBegin = caretX();
|
|
|
|
|
mTabStopEnd = caretX();
|
|
|
|
|
popUserCodeInTabStops();
|
|
|
|
|
}
|
|
|
|
|
if (!code.isEmpty()) {
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
}
|
2021-09-30 20:10:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 07:52:20 +08:00
|
|
|
|
void Editor::print()
|
|
|
|
|
{
|
|
|
|
|
QPrinter printer;
|
|
|
|
|
|
|
|
|
|
QPrintDialog dialog(&printer, this);
|
|
|
|
|
dialog.setWindowTitle(tr("Print Document"));
|
|
|
|
|
// if (editor->selAvail())
|
|
|
|
|
// dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
|
|
|
|
|
if (dialog.exec() != QDialog::Accepted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QTextDocument doc;
|
|
|
|
|
// if (editor->selAvail()) {
|
|
|
|
|
// doc.setPlainText(editor->selText());
|
|
|
|
|
// } else {
|
|
|
|
|
QStringList lst = contents();
|
|
|
|
|
for (int i=0;i<lst.length();i++) {
|
|
|
|
|
int columns = 0;
|
|
|
|
|
QString line = lst[i];
|
|
|
|
|
QString newLine;
|
|
|
|
|
for (QChar ch:line) {
|
|
|
|
|
if (ch=='\t') {
|
|
|
|
|
int charCol = tabWidth() - (columns % tabWidth());
|
|
|
|
|
newLine += QString(charCol,' ');
|
|
|
|
|
columns += charCol;
|
|
|
|
|
} else {
|
|
|
|
|
newLine+=ch;
|
|
|
|
|
columns+=charColumns(ch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lst[i]=newLine;
|
|
|
|
|
}
|
|
|
|
|
doc.setDefaultFont(font());
|
|
|
|
|
doc.setPlainText(lst.join(lineBreak()));
|
|
|
|
|
doc.print(&printer);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 09:47:58 +08:00
|
|
|
|
void Editor::exportAsRTF(const QString &rtfFilename)
|
|
|
|
|
{
|
2022-09-26 14:54:28 +08:00
|
|
|
|
QSynedit::SynRTFExporter exporter(pCharsetInfoManager->getDefaultSystemEncoding());
|
2021-10-12 09:47:58 +08:00
|
|
|
|
exporter.setTitle(extractFileName(rtfFilename));
|
|
|
|
|
exporter.setExportAsText(true);
|
|
|
|
|
exporter.setUseBackground(pSettings->editor().copyRTFUseBackground());
|
|
|
|
|
exporter.setFont(font());
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighter hl = highlighter();
|
2021-10-12 09:47:58 +08:00
|
|
|
|
if (!pSettings->editor().copyRTFUseEditorColor()) {
|
|
|
|
|
hl = highlighterManager.copyHighlighter(highlighter());
|
|
|
|
|
highlighterManager.applyColorScheme(hl,pSettings->editor().copyRTFColorScheme());
|
|
|
|
|
}
|
|
|
|
|
exporter.setHighlighter(hl);
|
|
|
|
|
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
|
|
|
|
this,
|
|
|
|
|
std::placeholders::_1,
|
|
|
|
|
std::placeholders::_2,
|
|
|
|
|
std::placeholders::_3,
|
|
|
|
|
std::placeholders::_4,
|
|
|
|
|
std::placeholders::_5
|
|
|
|
|
));
|
2022-04-19 21:18:41 +08:00
|
|
|
|
exporter.ExportAll(document());
|
2021-10-12 09:47:58 +08:00
|
|
|
|
exporter.SaveToFile(rtfFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::exportAsHTML(const QString &htmlFilename)
|
|
|
|
|
{
|
2022-09-26 14:54:28 +08:00
|
|
|
|
QSynedit::SynHTMLExporter exporter(tabWidth(), pCharsetInfoManager->getDefaultSystemEncoding());
|
2021-10-12 09:47:58 +08:00
|
|
|
|
exporter.setTitle(extractFileName(htmlFilename));
|
|
|
|
|
exporter.setExportAsText(false);
|
|
|
|
|
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
|
|
|
|
exporter.setFont(font());
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighter hl = highlighter();
|
2021-10-12 09:47:58 +08:00
|
|
|
|
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
|
|
|
|
hl = highlighterManager.copyHighlighter(highlighter());
|
|
|
|
|
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
|
|
|
|
}
|
|
|
|
|
exporter.setHighlighter(hl);
|
|
|
|
|
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
|
|
|
|
this,
|
|
|
|
|
std::placeholders::_1,
|
|
|
|
|
std::placeholders::_2,
|
|
|
|
|
std::placeholders::_3,
|
|
|
|
|
std::placeholders::_4,
|
|
|
|
|
std::placeholders::_5
|
|
|
|
|
));
|
2022-04-19 21:18:41 +08:00
|
|
|
|
exporter.ExportAll(document());
|
2021-10-12 09:47:58 +08:00
|
|
|
|
exporter.SaveToFile(htmlFilename);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 13:35:13 +08:00
|
|
|
|
void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeCompletionType type)
|
2021-08-25 08:48:33 +08:00
|
|
|
|
{
|
2022-01-15 11:22:20 +08:00
|
|
|
|
if (pMainWindow->functionTip()->isVisible()) {
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
}
|
2021-08-30 16:59:08 +08:00
|
|
|
|
if (!pSettings->codeCompletion().enabled())
|
|
|
|
|
return;
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (!mParser || !mParser->enabled())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!highlighter())
|
2021-08-25 08:48:33 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (mCompletionPopup->isVisible()) // already in search, don't do it again
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString word="";
|
|
|
|
|
|
|
|
|
|
QString s;
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
bool tokenFinished;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pBeginPos, pEndPos;
|
2021-09-20 15:57:48 +08:00
|
|
|
|
if (getHighlighterAttriAtRowCol(
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord{caretX() - 1,
|
2022-11-23 11:41:16 +08:00
|
|
|
|
caretY()}, s, tokenFinished, attr)) {
|
|
|
|
|
if (attr->tokenType() == QSynedit::TokenType::Preprocessor) {//Preprocessor
|
2021-09-03 16:39:20 +08:00
|
|
|
|
word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpDirective);
|
2021-08-25 23:53:35 +08:00
|
|
|
|
if (!word.startsWith('#')) {
|
2021-11-10 21:28:08 +08:00
|
|
|
|
word = "";
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
2022-11-23 11:41:16 +08:00
|
|
|
|
} else if (attr->tokenType() == QSynedit::TokenType::Comment) { //Comment, javadoc tag
|
2021-09-03 16:39:20 +08:00
|
|
|
|
word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpJavadoc);
|
2021-08-25 23:53:35 +08:00
|
|
|
|
if (!word.startsWith('@')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2022-11-23 11:41:16 +08:00
|
|
|
|
(attr->tokenType() != QSynedit::TokenType::Operator) &&
|
|
|
|
|
(attr->tokenType() != QSynedit::TokenType::Space) &&
|
|
|
|
|
(attr->tokenType() != QSynedit::TokenType::Keyword) &&
|
|
|
|
|
(attr->tokenType() != QSynedit::TokenType::Identifier)
|
2021-08-25 23:53:35 +08:00
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Position it at the top of the next line
|
2021-09-20 15:57:48 +08:00
|
|
|
|
QPoint p = rowColumnToPixels(displayXY());
|
2021-08-25 23:53:35 +08:00
|
|
|
|
p+=QPoint(0,textHeight()+2);
|
|
|
|
|
mCompletionPopup->move(mapToGlobal(p));
|
|
|
|
|
|
2021-08-30 16:59:08 +08:00
|
|
|
|
mCompletionPopup->setRecordUsage(pSettings->codeCompletion().recordUsage());
|
|
|
|
|
mCompletionPopup->setSortByScope(pSettings->codeCompletion().sortByScope());
|
|
|
|
|
mCompletionPopup->setShowKeywords(pSettings->codeCompletion().showKeywords());
|
2021-09-30 20:10:48 +08:00
|
|
|
|
mCompletionPopup->setShowCodeSnippets(pSettings->codeCompletion().showCodeIns());
|
2022-03-01 22:03:54 +08:00
|
|
|
|
mCompletionPopup->setHideSymbolsStartWithUnderline(pSettings->codeCompletion().hideSymbolsStartsWithUnderLine());
|
|
|
|
|
mCompletionPopup->setHideSymbolsStartWithTwoUnderline(pSettings->codeCompletion().hideSymbolsStartsWithTwoUnderLine());
|
2021-09-30 20:10:48 +08:00
|
|
|
|
if (pSettings->codeCompletion().showCodeIns()) {
|
|
|
|
|
mCompletionPopup->setCodeSnippets(pMainWindow->codeSnippetManager()->snippets());
|
|
|
|
|
}
|
2021-08-30 16:59:08 +08:00
|
|
|
|
mCompletionPopup->setIgnoreCase(pSettings->codeCompletion().ignoreCase());
|
|
|
|
|
mCompletionPopup->resize(pSettings->codeCompletion().width(),
|
|
|
|
|
pSettings->codeCompletion().height());
|
2021-08-25 23:53:35 +08:00
|
|
|
|
// fCompletionBox.CodeInsList := dmMain.CodeInserts.ItemList;
|
|
|
|
|
// fCompletionBox.SymbolUsage := dmMain.SymbolUsage;
|
|
|
|
|
// fCompletionBox.ShowCount := devCodeCompletion.MaxCount;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
//Set Font size;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
mCompletionPopup->setFont(font());
|
2021-08-25 08:48:33 +08:00
|
|
|
|
// Redirect key presses to completion box if applicable
|
2021-08-25 23:53:35 +08:00
|
|
|
|
//todo:
|
|
|
|
|
mCompletionPopup->setKeypressedCallback([this](QKeyEvent *event)->bool{
|
|
|
|
|
return onCompletionKeyPressed(event);
|
|
|
|
|
});
|
|
|
|
|
mCompletionPopup->setParser(mParser);
|
2021-09-25 21:34:10 +08:00
|
|
|
|
pMainWindow->functionTip()->hide();
|
2021-08-25 23:53:35 +08:00
|
|
|
|
mCompletionPopup->show();
|
2021-08-25 08:48:33 +08:00
|
|
|
|
|
|
|
|
|
// Scan the current function body
|
2022-11-10 08:05:04 +08:00
|
|
|
|
mCompletionPopup->setCurrentScope(
|
|
|
|
|
mParser->findScopeStatement(mFilename, caretY())
|
2021-08-25 23:53:35 +08:00
|
|
|
|
);
|
2021-08-25 08:48:33 +08:00
|
|
|
|
|
2022-01-23 23:27:48 +08:00
|
|
|
|
QSet<QString> keywords;
|
|
|
|
|
if (highlighter()) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp ) {
|
2022-01-23 23:27:48 +08:00
|
|
|
|
keywords = highlighter()->keywords();
|
|
|
|
|
} else {
|
2022-11-22 15:14:05 +08:00
|
|
|
|
if (mUseCppSyntax) {
|
|
|
|
|
foreach (const QString& keyword, CppKeywords.keys()) {
|
|
|
|
|
keywords.insert(keyword);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
keywords = CKeywords;
|
|
|
|
|
}
|
|
|
|
|
if (pSettings->editor().enableCustomCTypeKeywords()) {
|
|
|
|
|
foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) {
|
|
|
|
|
keywords.insert(keyword);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-23 23:27:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 18:29:37 +08:00
|
|
|
|
if (word.isEmpty()) {
|
|
|
|
|
//word=getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpCompletion);
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QString memberOperator;
|
|
|
|
|
QStringList memberExpression;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pos = caretXY();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
pos.ch--;
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QStringList ownerExpression = getOwnerExpressionAndMemberAtPositionForCompletion(
|
2021-12-19 16:54:31 +08:00
|
|
|
|
pos,
|
2021-12-04 10:02:07 +08:00
|
|
|
|
memberOperator,
|
|
|
|
|
memberExpression);
|
2021-12-08 22:47:28 +08:00
|
|
|
|
// qDebug()<<ownerExpression<<memberExpression;
|
2021-12-04 10:02:07 +08:00
|
|
|
|
word = memberExpression.join("");
|
|
|
|
|
mCompletionPopup->prepareSearch(
|
|
|
|
|
preWord,
|
|
|
|
|
ownerExpression,
|
|
|
|
|
memberOperator,
|
|
|
|
|
memberExpression,
|
|
|
|
|
mFilename,
|
2022-01-23 23:27:48 +08:00
|
|
|
|
caretY(),
|
2022-11-10 13:35:13 +08:00
|
|
|
|
type,
|
2022-01-23 23:27:48 +08:00
|
|
|
|
keywords);
|
2021-12-03 21:07:40 +08:00
|
|
|
|
} else {
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QStringList memberExpression;
|
|
|
|
|
memberExpression.append(word);
|
|
|
|
|
mCompletionPopup->prepareSearch(preWord,
|
|
|
|
|
QStringList(),
|
|
|
|
|
"",
|
2022-11-10 13:35:13 +08:00
|
|
|
|
memberExpression, mFilename, caretY(),type,keywords);
|
2021-12-02 18:29:37 +08:00
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
|
|
|
|
|
// Filter the whole statement list
|
2021-08-25 23:53:35 +08:00
|
|
|
|
if (mCompletionPopup->search(word, autoComplete)) { //only one suggestion and it's not input while typing
|
2021-08-30 16:59:08 +08:00
|
|
|
|
completionInsert(pSettings->codeCompletion().appendFunc());
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 21:43:42 +08:00
|
|
|
|
void Editor::showHeaderCompletion(bool autoComplete, bool forceShow)
|
2021-08-25 23:53:35 +08:00
|
|
|
|
{
|
2021-08-30 16:59:08 +08:00
|
|
|
|
if (!pSettings->codeCompletion().enabled())
|
|
|
|
|
return;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
// if not devCodeCompletion.Enabled then
|
|
|
|
|
// Exit;
|
|
|
|
|
|
2022-06-20 21:43:42 +08:00
|
|
|
|
if (!forceShow && mHeaderCompletionPopup->isVisible()) // already in search, don't do it again
|
2021-08-29 10:14:07 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Position it at the top of the next line
|
2021-09-20 15:57:48 +08:00
|
|
|
|
QPoint p = rowColumnToPixels(displayXY());
|
2021-08-29 10:14:07 +08:00
|
|
|
|
p.setY(p.y() + textHeight() + 2);
|
|
|
|
|
mHeaderCompletionPopup->move(mapToGlobal(p));
|
|
|
|
|
|
|
|
|
|
|
2021-08-30 16:59:08 +08:00
|
|
|
|
mHeaderCompletionPopup->setIgnoreCase(pSettings->codeCompletion().ignoreCase());
|
|
|
|
|
mHeaderCompletionPopup->resize(pSettings->codeCompletion().width(),
|
|
|
|
|
pSettings->codeCompletion().height());
|
2021-08-29 10:14:07 +08:00
|
|
|
|
//Set Font size;
|
|
|
|
|
mHeaderCompletionPopup->setFont(font());
|
|
|
|
|
|
|
|
|
|
// Redirect key presses to completion box if applicable
|
|
|
|
|
mHeaderCompletionPopup->setKeypressedCallback([this](QKeyEvent* event)->bool{
|
|
|
|
|
return onHeaderCompletionKeyPressed(event);
|
|
|
|
|
});
|
|
|
|
|
mHeaderCompletionPopup->setParser(mParser);
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
2021-09-03 16:39:20 +08:00
|
|
|
|
QString word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos,
|
2021-08-29 10:14:07 +08:00
|
|
|
|
WordPurpose::wpHeaderCompletionStart);
|
2022-06-20 21:43:42 +08:00
|
|
|
|
|
2021-08-29 10:14:07 +08:00
|
|
|
|
if (word.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!word.startsWith('"') && !word.startsWith('<'))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (word.lastIndexOf('"')>0 || word.lastIndexOf('>')>0)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-09-25 21:34:10 +08:00
|
|
|
|
pMainWindow->functionTip()->hide();
|
2021-08-29 10:14:07 +08:00
|
|
|
|
mHeaderCompletionPopup->show();
|
|
|
|
|
mHeaderCompletionPopup->setSearchLocal(word.startsWith('"'));
|
|
|
|
|
word.remove(0,1);
|
|
|
|
|
|
|
|
|
|
mHeaderCompletionPopup->prepareSearch(word, mFilename);
|
|
|
|
|
|
|
|
|
|
// Filter the whole statement list
|
|
|
|
|
if (mHeaderCompletionPopup->search(word, autoComplete)) //only one suggestion and it's not input while typing
|
|
|
|
|
headerCompletionInsert(); // if only have one suggestion, just use it
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 11:58:29 +08:00
|
|
|
|
bool Editor::testInFunc(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
QString s = document()->getString(y);
|
2021-08-26 11:58:29 +08:00
|
|
|
|
int posY = y;
|
|
|
|
|
int posX = std::min(x,s.length()-1); // x is started from 1
|
|
|
|
|
int bracketLevel=0;
|
|
|
|
|
while (true) {
|
|
|
|
|
while (posX < 0) {
|
|
|
|
|
posY--;
|
|
|
|
|
if (posY < 0)
|
|
|
|
|
return false;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
s = document()->getString(posY);
|
2021-08-26 11:58:29 +08:00
|
|
|
|
posX = s.length()-1;
|
|
|
|
|
}
|
|
|
|
|
if (s[posX] == '>'
|
|
|
|
|
|| s[posX] == ']') {
|
|
|
|
|
bracketLevel++;
|
|
|
|
|
} else if (s[posX] == '<'
|
|
|
|
|
|| s[posX] == '[') {
|
|
|
|
|
bracketLevel--;
|
|
|
|
|
} else if (bracketLevel==0) {
|
|
|
|
|
switch (s[posX].unicode()) {
|
|
|
|
|
case '(':
|
|
|
|
|
return true;
|
|
|
|
|
case ';':
|
|
|
|
|
case '{':
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!(isIdentChar(s[posX])
|
|
|
|
|
|| s[posX] == ' '
|
|
|
|
|
|| s[posX] == '\t'
|
|
|
|
|
|| s[posX] == '*'
|
|
|
|
|
|| s[posX] == '&'))
|
|
|
|
|
break;;
|
|
|
|
|
}
|
|
|
|
|
posX--;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 17:48:23 +08:00
|
|
|
|
void Editor::completionInsert(bool appendFunc)
|
|
|
|
|
{
|
|
|
|
|
PStatement statement = mCompletionPopup->selectedStatement();
|
|
|
|
|
if (!statement)
|
|
|
|
|
return;
|
2021-09-30 11:20:43 +08:00
|
|
|
|
|
|
|
|
|
if (pSettings->codeCompletion().recordUsage()
|
2021-09-30 20:10:48 +08:00
|
|
|
|
&& statement->kind != StatementKind::skUserCodeSnippet) {
|
2021-09-30 11:20:43 +08:00
|
|
|
|
statement->usageCount+=1;
|
|
|
|
|
pMainWindow->symbolUsageManager()->updateUsage(statement->fullName,
|
|
|
|
|
statement->usageCount);
|
|
|
|
|
}
|
2021-08-26 17:48:23 +08:00
|
|
|
|
|
|
|
|
|
QString funcAddOn = "";
|
|
|
|
|
|
|
|
|
|
// delete the part of the word that's already been typed ...
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p = wordEnd();
|
|
|
|
|
QSynedit::BufferCoord pStart = wordStart();
|
2021-10-02 13:29:45 +08:00
|
|
|
|
setCaretAndSelection(pStart,pStart,p);
|
2021-08-26 17:48:23 +08:00
|
|
|
|
|
|
|
|
|
// if we are inserting a function,
|
|
|
|
|
if (appendFunc) {
|
2022-03-15 21:33:27 +08:00
|
|
|
|
if (statement->kind == StatementKind::skAlias) {
|
|
|
|
|
PStatement newStatement = mParser->findAliasedStatement(statement);
|
|
|
|
|
if (newStatement)
|
|
|
|
|
statement = newStatement;
|
|
|
|
|
}
|
2022-06-01 17:02:03 +08:00
|
|
|
|
if ( (statement->kind == StatementKind::skFunction
|
|
|
|
|
&& !IOManipulators.contains(statement->fullName))
|
2021-08-26 17:48:23 +08:00
|
|
|
|
|| statement->kind == StatementKind::skConstructor
|
2022-03-15 20:17:47 +08:00
|
|
|
|
|| statement->kind == StatementKind::skDestructor
|
|
|
|
|
||
|
|
|
|
|
(statement->kind == StatementKind::skPreprocessor
|
|
|
|
|
&& !statement->args.isEmpty())) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
QChar nextCh = nextNonSpaceChar(caretY()-1,p.ch-1);
|
2022-04-22 15:55:39 +08:00
|
|
|
|
if (nextCh=='(') {
|
|
|
|
|
funcAddOn = "";
|
|
|
|
|
} else if (isIdentChar(nextCh) || nextCh == '"'
|
|
|
|
|
|| nextCh == '\'') {
|
|
|
|
|
funcAddOn = '(';
|
|
|
|
|
} else {
|
|
|
|
|
funcAddOn = "()";
|
2021-08-26 17:48:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ... by replacing the selection
|
2021-09-30 20:10:48 +08:00
|
|
|
|
if (statement->kind == StatementKind::skUserCodeSnippet) { // it's a user code template
|
|
|
|
|
// insertUserCodeIn(Statement->value);
|
2021-10-02 13:29:45 +08:00
|
|
|
|
//first move caret to the begin of the word to be replaced
|
2021-09-30 20:10:48 +08:00
|
|
|
|
insertCodeSnippet(statement->value);
|
2021-08-26 17:48:23 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (
|
|
|
|
|
(statement->kind == StatementKind::skKeyword
|
|
|
|
|
|| statement->kind == StatementKind::skPreprocessor)
|
|
|
|
|
&& (statement->command.startsWith('#')
|
|
|
|
|
|| statement->command.startsWith('@'))
|
|
|
|
|
) {
|
2022-10-26 19:40:34 +08:00
|
|
|
|
|
2021-08-26 17:48:23 +08:00
|
|
|
|
setSelText(statement->command.mid(1));
|
|
|
|
|
} else
|
|
|
|
|
setSelText(statement->command + funcAddOn);
|
|
|
|
|
|
|
|
|
|
if (!funcAddOn.isEmpty())
|
|
|
|
|
mLastIdCharPressed = 0;
|
|
|
|
|
|
|
|
|
|
// Move caret inside the ()'s, only when the user has something to do there...
|
|
|
|
|
if (!funcAddOn.isEmpty()
|
|
|
|
|
&& (statement->args != "()")
|
|
|
|
|
&& (statement->args != "(void)")) {
|
|
|
|
|
setCaretX(caretX() - funcAddOn.length()+1);
|
|
|
|
|
|
|
|
|
|
//todo: function hint
|
|
|
|
|
// immediately activate function hint
|
|
|
|
|
// if devEditor.ShowFunctionTip and Assigned(fText.Highlighter) then begin
|
|
|
|
|
// fText.SetFocus;
|
|
|
|
|
// fFunctionTip.Parser := fParser;
|
|
|
|
|
// fFunctionTip.FileName := fFileName;
|
|
|
|
|
// fFunctionTip.Show;
|
|
|
|
|
// end;
|
2022-07-20 16:57:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
setCaretX(caretX());
|
2021-08-26 17:48:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mCompletionPopup->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 10:14:07 +08:00
|
|
|
|
void Editor::headerCompletionInsert()
|
|
|
|
|
{
|
2022-04-14 22:25:49 +08:00
|
|
|
|
QString headerName = mHeaderCompletionPopup->selectedFilename(true);
|
2022-06-20 21:43:42 +08:00
|
|
|
|
if (headerName.isEmpty()) {
|
|
|
|
|
mHeaderCompletionPopup->hide();
|
2021-08-29 10:14:07 +08:00
|
|
|
|
return;
|
2022-06-20 21:43:42 +08:00
|
|
|
|
}
|
2021-08-29 10:14:07 +08:00
|
|
|
|
|
|
|
|
|
// delete the part of the word that's already been typed ...
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p = caretXY();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int posBegin = p.ch-1;
|
|
|
|
|
int posEnd = p.ch-1;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
QString sLine = lineText();
|
|
|
|
|
while ((posBegin>0) &&
|
2022-02-22 15:38:40 +08:00
|
|
|
|
(isIdentChar(sLine[posBegin-1]) || (sLine[posBegin-1]=='.') || (sLine[posBegin-1]=='+')))
|
2021-08-29 10:14:07 +08:00
|
|
|
|
posBegin--;
|
|
|
|
|
|
|
|
|
|
while ((posEnd < sLine.length())
|
2022-02-22 15:38:40 +08:00
|
|
|
|
&& (isIdentChar(sLine[posEnd]) || (sLine[posEnd]=='.') || (sLine[posBegin-1]=='+')))
|
2021-08-29 10:14:07 +08:00
|
|
|
|
posEnd++;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch = posBegin+1;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
setBlockBegin(p);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
p.ch = posEnd+1;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
setBlockEnd(p);
|
|
|
|
|
|
|
|
|
|
setSelText(headerName);
|
|
|
|
|
|
2022-07-20 16:57:42 +08:00
|
|
|
|
setCaretX(caretX());
|
|
|
|
|
|
2022-06-20 21:43:42 +08:00
|
|
|
|
if (headerName.endsWith("/")) {
|
|
|
|
|
showHeaderCompletion(false,true);
|
|
|
|
|
} else {
|
|
|
|
|
mHeaderCompletionPopup->hide();
|
|
|
|
|
}
|
2021-08-29 10:14:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 17:48:23 +08:00
|
|
|
|
bool Editor::onCompletionKeyPressed(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
bool processed = false;
|
|
|
|
|
if (!mCompletionPopup->isEnabled())
|
|
|
|
|
return false;
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QString oldPhrase = mCompletionPopup->memberPhrase();
|
2021-08-29 10:14:07 +08:00
|
|
|
|
WordPurpose purpose = WordPurpose::wpCompletion;
|
|
|
|
|
if (oldPhrase.startsWith('#')) {
|
|
|
|
|
purpose = WordPurpose::wpDirective;
|
|
|
|
|
} else if (oldPhrase.startsWith('@')) {
|
|
|
|
|
purpose = WordPurpose::wpJavadoc;
|
|
|
|
|
}
|
2021-08-26 17:48:23 +08:00
|
|
|
|
QString phrase;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
2021-08-26 17:48:23 +08:00
|
|
|
|
switch (event->key()) {
|
2021-09-28 14:18:51 +08:00
|
|
|
|
case Qt::Key_Shift:
|
2021-10-02 15:34:18 +08:00
|
|
|
|
case Qt::Key_Control:
|
|
|
|
|
case Qt::Key_Meta:
|
|
|
|
|
case Qt::Key_Alt:
|
2021-09-28 14:18:51 +08:00
|
|
|
|
//ignore it
|
|
|
|
|
return true;
|
2021-08-26 17:48:23 +08:00
|
|
|
|
case Qt::Key_Backspace:
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::EditCommand::ecDeleteLastChar,
|
2021-08-26 17:48:23 +08:00
|
|
|
|
QChar(), nullptr); // Simulate backspace in editor
|
2021-12-04 10:02:07 +08:00
|
|
|
|
if (purpose == WordPurpose::wpCompletion) {
|
|
|
|
|
phrase = getWordForCompletionSearch(caretXY(), mCompletionPopup->memberOperator()=="::");
|
|
|
|
|
} else
|
|
|
|
|
phrase = getWordAtPosition(this,caretXY(),
|
|
|
|
|
pBeginPos,pEndPos,
|
|
|
|
|
purpose);
|
2021-08-26 17:48:23 +08:00
|
|
|
|
mLastIdCharPressed = phrase.length();
|
2021-12-04 10:02:07 +08:00
|
|
|
|
if (phrase.isEmpty()) {
|
|
|
|
|
mCompletionPopup->hide();
|
|
|
|
|
} else {
|
|
|
|
|
mCompletionPopup->search(phrase, false);
|
|
|
|
|
}
|
2021-08-26 17:48:23 +08:00
|
|
|
|
return true;
|
|
|
|
|
case Qt::Key_Escape:
|
|
|
|
|
mCompletionPopup->hide();
|
|
|
|
|
return true;
|
|
|
|
|
case Qt::Key_Return:
|
2021-10-09 09:09:05 +08:00
|
|
|
|
case Qt::Key_Enter:
|
2021-08-26 17:48:23 +08:00
|
|
|
|
case Qt::Key_Tab:
|
2021-08-30 16:59:08 +08:00
|
|
|
|
completionInsert(pSettings->codeCompletion().appendFunc());
|
2021-08-26 17:48:23 +08:00
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
if (event->text().isEmpty()) {
|
|
|
|
|
//stop completion
|
|
|
|
|
mCompletionPopup->hide();
|
|
|
|
|
keyPressEvent(event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QChar ch = event->text().front();
|
|
|
|
|
if (isIdentChar(ch)) {
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar, ch);
|
2021-12-02 18:29:37 +08:00
|
|
|
|
if (purpose == WordPurpose::wpCompletion) {
|
2021-12-04 10:02:07 +08:00
|
|
|
|
phrase = getWordForCompletionSearch(caretXY(),mCompletionPopup->memberOperator()=="::");
|
2021-12-02 18:29:37 +08:00
|
|
|
|
} else
|
|
|
|
|
phrase = getWordAtPosition(this,caretXY(),
|
2021-08-26 17:48:23 +08:00
|
|
|
|
pBeginPos,pEndPos,
|
2021-08-29 10:14:07 +08:00
|
|
|
|
purpose);
|
2021-08-26 17:48:23 +08:00
|
|
|
|
mLastIdCharPressed = phrase.length();
|
|
|
|
|
mCompletionPopup->search(phrase, false);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
//stop completion
|
|
|
|
|
mCompletionPopup->hide();
|
|
|
|
|
keyPressEvent(event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return processed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 10:14:07 +08:00
|
|
|
|
bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
bool processed = false;
|
2021-09-27 00:52:25 +08:00
|
|
|
|
if (!mHeaderCompletionPopup->isEnabled())
|
2021-08-29 10:14:07 +08:00
|
|
|
|
return false;
|
|
|
|
|
QString phrase;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
switch (event->key()) {
|
|
|
|
|
case Qt::Key_Backspace:
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::EditCommand::ecDeleteLastChar,
|
2021-08-29 10:14:07 +08:00
|
|
|
|
QChar(), nullptr); // Simulate backspace in editor
|
2021-09-03 16:39:20 +08:00
|
|
|
|
phrase = getWordAtPosition(this,caretXY(),
|
2021-08-29 10:14:07 +08:00
|
|
|
|
pBeginPos,pEndPos,
|
|
|
|
|
WordPurpose::wpHeaderCompletion);
|
|
|
|
|
mLastIdCharPressed = phrase.length();
|
|
|
|
|
mHeaderCompletionPopup->search(phrase, false);
|
|
|
|
|
return true;
|
|
|
|
|
case Qt::Key_Escape:
|
|
|
|
|
mHeaderCompletionPopup->hide();
|
|
|
|
|
return true;
|
|
|
|
|
case Qt::Key_Return:
|
2021-10-09 09:09:05 +08:00
|
|
|
|
case Qt::Key_Enter:
|
2021-08-29 10:14:07 +08:00
|
|
|
|
case Qt::Key_Tab:
|
|
|
|
|
headerCompletionInsert();
|
2022-06-20 21:43:42 +08:00
|
|
|
|
//mHeaderCompletionPopup->hide();
|
2021-08-29 10:14:07 +08:00
|
|
|
|
return true;
|
2021-09-27 00:52:25 +08:00
|
|
|
|
case Qt::Key_Shift:
|
|
|
|
|
return false;
|
2021-08-29 10:14:07 +08:00
|
|
|
|
default:
|
|
|
|
|
if (event->text().isEmpty()) {
|
|
|
|
|
//stop completion
|
|
|
|
|
mHeaderCompletionPopup->hide();
|
|
|
|
|
keyPressEvent(event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QChar ch = event->text().front();
|
2021-09-27 00:52:25 +08:00
|
|
|
|
|
|
|
|
|
if (isIdentChar(ch) || ch == '.'
|
|
|
|
|
|| ch =='_' || ch=='+') {
|
2022-10-26 19:40:34 +08:00
|
|
|
|
commandProcessor(QSynedit::EditCommand::ecChar, ch);
|
2021-09-03 16:39:20 +08:00
|
|
|
|
phrase = getWordAtPosition(this,caretXY(),
|
2021-08-29 10:14:07 +08:00
|
|
|
|
pBeginPos,pEndPos,
|
|
|
|
|
WordPurpose::wpHeaderCompletion);
|
|
|
|
|
mLastIdCharPressed = phrase.length();
|
|
|
|
|
mHeaderCompletionPopup->search(phrase, false);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
//stop completion
|
|
|
|
|
mHeaderCompletionPopup->hide();
|
|
|
|
|
keyPressEvent(event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return processed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 15:34:18 +08:00
|
|
|
|
bool Editor::onCompletionInputMethod(QInputMethodEvent *event)
|
|
|
|
|
{
|
|
|
|
|
bool processed = false;
|
|
|
|
|
if (!mCompletionPopup->isVisible())
|
|
|
|
|
return processed;
|
|
|
|
|
QString s=event->commitString();
|
|
|
|
|
if (!s.isEmpty()) {
|
2021-12-04 10:02:07 +08:00
|
|
|
|
QString phrase = getWordForCompletionSearch(caretXY(),mCompletionPopup->memberOperator()=="::");
|
2021-10-02 15:34:18 +08:00
|
|
|
|
mLastIdCharPressed = phrase.length();
|
|
|
|
|
mCompletionPopup->search(phrase, false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return processed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
|
2021-08-29 17:23:40 +08:00
|
|
|
|
{
|
|
|
|
|
// Only allow in the text area...
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (pointToCharLine(point, pos) && highlighter()) {
|
2021-08-29 17:23:40 +08:00
|
|
|
|
if (!pMainWindow->debugger()->executing()
|
|
|
|
|
&& getSyntaxIssueAtPosition(pos)) {
|
|
|
|
|
return TipType::Error;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
QString s;
|
|
|
|
|
|
|
|
|
|
// Only allow hand tips in highlighted areas
|
2021-09-20 15:57:48 +08:00
|
|
|
|
if (getHighlighterAttriAtRowCol(pos,s,attr)) {
|
2021-08-29 17:23:40 +08:00
|
|
|
|
// Only allow Identifiers, Preprocessor directives, and selection
|
|
|
|
|
if (attr) {
|
|
|
|
|
if (selAvail()) {
|
|
|
|
|
// do not allow when dragging selection
|
2021-09-20 15:57:48 +08:00
|
|
|
|
if (isPointInSelection(pos))
|
2021-08-29 17:23:40 +08:00
|
|
|
|
return TipType::Selection;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
} else if (mParser && mParser->isIncludeLine(document()->getString(pos.line-1))) {
|
2021-08-29 17:23:40 +08:00
|
|
|
|
return TipType::Preprocessor;
|
2021-12-27 10:59:04 +08:00
|
|
|
|
}else if (attr == highlighter()->identifierAttribute())
|
|
|
|
|
return TipType::Identifier;
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TipType::None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::cancelHint()
|
|
|
|
|
{
|
2022-06-08 16:05:54 +08:00
|
|
|
|
if(mHoverModifiedLine!=-1) {
|
|
|
|
|
invalidateLine(mHoverModifiedLine);
|
|
|
|
|
mHoverModifiedLine=-1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 17:23:40 +08:00
|
|
|
|
//MainForm.Debugger.OnEvalReady := nil;
|
|
|
|
|
|
|
|
|
|
// disable editor hint
|
|
|
|
|
QToolTip::hideText();
|
2022-01-15 11:22:20 +08:00
|
|
|
|
//mCurrentWord = "";
|
|
|
|
|
//mCurrentTipType = TipType::None;
|
2021-09-27 00:52:25 +08:00
|
|
|
|
updateMouseCursor();
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 12:24:59 +08:00
|
|
|
|
QString Editor::getFileHint(const QString &s, bool fromNext)
|
2021-08-29 17:23:40 +08:00
|
|
|
|
{
|
2022-10-18 12:24:59 +08:00
|
|
|
|
QString fileName = mParser->getHeaderFileName(mFilename, s, fromNext);
|
2021-09-07 10:28:40 +08:00
|
|
|
|
if (fileExists(fileName)) {
|
2021-08-29 17:23:40 +08:00
|
|
|
|
return fileName + " - " + tr("Ctrl+click for more info");
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 20:59:02 +08:00
|
|
|
|
QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/, int line)
|
2021-08-29 17:23:40 +08:00
|
|
|
|
{
|
2022-10-24 12:51:50 +08:00
|
|
|
|
if (!mParser)
|
|
|
|
|
return "";
|
2021-08-29 17:23:40 +08:00
|
|
|
|
// This piece of code changes the parser database, possibly making hints and code completion invalid...
|
|
|
|
|
QString result;
|
2022-06-30 14:39:12 +08:00
|
|
|
|
// Exit early, don't bother creating a stream (which is slow)
|
2021-12-18 23:36:58 +08:00
|
|
|
|
PStatement statement = mParser->findStatementOf(
|
|
|
|
|
mFilename,expression,
|
2021-12-19 10:16:46 +08:00
|
|
|
|
line);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
if (!statement)
|
|
|
|
|
return result;
|
|
|
|
|
if (statement->kind == StatementKind::skFunction
|
|
|
|
|
|| statement->kind == StatementKind::skConstructor
|
|
|
|
|
|| statement->kind == StatementKind::skDestructor) {
|
2022-07-04 11:39:06 +08:00
|
|
|
|
//PStatement parentScope = statement->parentScope.lock();
|
2022-06-30 14:39:12 +08:00
|
|
|
|
// if (parentScope && parentScope->kind == StatementKind::skNamespace) {
|
|
|
|
|
// PStatementList namespaceStatementsList =
|
|
|
|
|
// mParser->findNamespace(parentScope->command);
|
|
|
|
|
// if (namespaceStatementsList) {
|
|
|
|
|
// int counts=0;
|
|
|
|
|
// foreach (const PStatement& namespaceStatement, *namespaceStatementsList) {
|
|
|
|
|
// QString hint = getHintForFunction(statement,namespaceStatement,
|
|
|
|
|
// mFilename,line);
|
|
|
|
|
// if (!hint.isEmpty()) {
|
|
|
|
|
// counts++;
|
|
|
|
|
// if (!result.isEmpty())
|
|
|
|
|
// result += "\n";
|
|
|
|
|
// if (counts>4) {
|
|
|
|
|
// result += "...";
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// result += hint;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } else
|
2022-07-04 11:39:06 +08:00
|
|
|
|
result = getHintForFunction(statement,mFilename,line);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
} else if (statement->line>0) {
|
|
|
|
|
QFileInfo fileInfo(statement->fileName);
|
2021-08-30 13:30:42 +08:00
|
|
|
|
result = mParser->prettyPrintStatement(statement,mFilename, line) + " - "
|
2022-01-22 21:07:41 +08:00
|
|
|
|
+ QString("%1(%2) ").arg(fileInfo.fileName()).arg(statement->line)
|
2021-08-29 17:23:40 +08:00
|
|
|
|
+ tr("Ctrl+click for more info");
|
|
|
|
|
} else { // hard defines
|
2021-08-29 22:08:43 +08:00
|
|
|
|
result = mParser->prettyPrintStatement(statement, mFilename);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
// Result := StringReplace(Result, '|', #5, [rfReplaceAll]);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 22:08:43 +08:00
|
|
|
|
void Editor::showDebugHint(const QString &s, int line)
|
|
|
|
|
{
|
2021-08-29 22:51:23 +08:00
|
|
|
|
PStatement statement = mParser->findStatementOf(mFilename,s,line);
|
2021-08-29 22:08:43 +08:00
|
|
|
|
if (statement) {
|
|
|
|
|
if (statement->kind != StatementKind::skVariable
|
2021-08-29 22:51:23 +08:00
|
|
|
|
&& statement->kind != StatementKind::skGlobalVariable
|
|
|
|
|
&& statement->kind != StatementKind::skLocalVariable
|
|
|
|
|
&& statement->kind != StatementKind::skParameter) {
|
2021-08-29 22:08:43 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (pMainWindow->debugger()->commandRunning())
|
|
|
|
|
return;
|
2022-01-15 11:22:20 +08:00
|
|
|
|
if (pMainWindow->functionTip()->isVisible()) {
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
}
|
2021-08-29 22:08:43 +08:00
|
|
|
|
connect(pMainWindow->debugger(), &Debugger::evalValueReady,
|
|
|
|
|
this, &Editor::onTipEvalValueReady);
|
|
|
|
|
mCurrentDebugTipWord = s;
|
2021-11-24 22:16:40 +08:00
|
|
|
|
pMainWindow->debugger()->sendCommand("-data-evaluate-expression",s);
|
2021-08-29 22:08:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Editor::getErrorHint(const PSyntaxIssue& issue)
|
|
|
|
|
{
|
|
|
|
|
if (issue) {
|
|
|
|
|
return issue->hint;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 11:39:06 +08:00
|
|
|
|
QString Editor::getHintForFunction(const PStatement &statement, const QString& filename, int line)
|
2021-08-29 17:23:40 +08:00
|
|
|
|
{
|
2022-06-30 14:39:12 +08:00
|
|
|
|
QFileInfo fileInfo(statement->fileName);
|
2021-08-29 17:23:40 +08:00
|
|
|
|
QString result;
|
2022-06-30 14:39:12 +08:00
|
|
|
|
result = mParser->prettyPrintStatement(statement,filename,line) + " - "
|
|
|
|
|
+ QString("%1(%2) ").arg(fileInfo.fileName()).arg(statement->line)
|
|
|
|
|
+ tr("Ctrl+click for more info");
|
|
|
|
|
// const StatementMap& children = mParser->statementList().childrenStatements(scopeStatement);
|
|
|
|
|
// foreach (const PStatement& childStatement, children){
|
|
|
|
|
// if (statement->command == childStatement->command
|
|
|
|
|
// && statement->kind == childStatement->kind) {
|
|
|
|
|
// if ((line < childStatement->line) &&
|
|
|
|
|
// childStatement->fileName == filename)
|
|
|
|
|
// continue;
|
|
|
|
|
// if (!result.isEmpty())
|
|
|
|
|
// result += "\n";
|
|
|
|
|
// QFileInfo fileInfo(childStatement->fileName);
|
|
|
|
|
// result = mParser->prettyPrintStatement(childStatement,filename,line) + " - "
|
|
|
|
|
// + QString("%1(%2) ").arg(fileInfo.fileName()).arg(childStatement->line)
|
|
|
|
|
// + tr("Ctrl+click for more info");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2021-08-29 17:23:40 +08:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 12:15:44 +08:00
|
|
|
|
void Editor::updateFunctionTip(bool showTip)
|
2021-09-24 11:41:14 +08:00
|
|
|
|
{
|
2021-09-25 21:34:10 +08:00
|
|
|
|
if (pMainWindow->completionPopup()->isVisible()) {
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-03-10 12:15:44 +08:00
|
|
|
|
if (inputMethodOn()) {
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-18 20:31:07 +08:00
|
|
|
|
if (!highlighter())
|
|
|
|
|
return;
|
2021-09-24 11:41:14 +08:00
|
|
|
|
|
2022-11-06 09:43:28 +08:00
|
|
|
|
if (!mParser || !mParser->enabled())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-18 20:31:07 +08:00
|
|
|
|
bool isFunction = false;
|
|
|
|
|
auto action = finally([&isFunction]{
|
|
|
|
|
if (!isFunction)
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
});
|
2022-01-18 21:03:43 +08:00
|
|
|
|
const int maxLines=10;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord caretPos = caretXY();
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int currentLine = caretPos.line-1;
|
|
|
|
|
int currentChar = caretPos.ch-1;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord functionNamePos{-1,-1};
|
2022-01-18 20:31:07 +08:00
|
|
|
|
bool foundFunctionStart = false;
|
|
|
|
|
int parenthesisLevel = 0;
|
|
|
|
|
int braceLevel = 0;
|
|
|
|
|
int bracketLevel = 0;
|
|
|
|
|
int paramsCount = 1;
|
|
|
|
|
int currentParamPos = 1;
|
2022-04-19 21:18:41 +08:00
|
|
|
|
if (currentLine>=document()->count())
|
2021-09-24 11:41:14 +08:00
|
|
|
|
return;
|
2022-04-22 15:55:39 +08:00
|
|
|
|
QChar ch=lastNonSpaceChar(currentLine,currentChar);
|
|
|
|
|
if (ch!="(" && ch!=",")
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-18 20:31:07 +08:00
|
|
|
|
while (currentLine>=0) {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
QString line = document()->getString(currentLine);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (currentLine!=caretPos.line-1)
|
2022-01-18 20:31:07 +08:00
|
|
|
|
currentChar = line.length();
|
|
|
|
|
QStringList tokens;
|
|
|
|
|
QList<int> positions;
|
|
|
|
|
if (currentLine==0)
|
|
|
|
|
highlighter()->resetState();
|
|
|
|
|
else
|
|
|
|
|
highlighter()->setState(
|
2022-04-19 21:18:41 +08:00
|
|
|
|
document()->ranges(currentLine-1));
|
2022-01-18 20:31:07 +08:00
|
|
|
|
highlighter()->setLine(line,currentLine);
|
|
|
|
|
while(!highlighter()->eol()) {
|
|
|
|
|
int start = highlighter()->getTokenPos();
|
|
|
|
|
QString token = highlighter()->getToken();
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr = highlighter()->getTokenAttribute();
|
2022-01-18 20:31:07 +08:00
|
|
|
|
if (start>=currentChar)
|
|
|
|
|
break;
|
2021-09-24 11:41:14 +08:00
|
|
|
|
|
2022-11-23 12:51:23 +08:00
|
|
|
|
if (attr->tokenType() != QSynedit::TokenType::Comment
|
|
|
|
|
&& attr->tokenType() != QSynedit::TokenType::Space) {
|
2022-01-18 20:31:07 +08:00
|
|
|
|
if (foundFunctionStart) {
|
|
|
|
|
if (attr!=highlighter()->identifierAttribute())
|
|
|
|
|
return; // not a function
|
2022-07-04 10:01:40 +08:00
|
|
|
|
functionNamePos.line = currentLine+1;
|
|
|
|
|
functionNamePos.ch = start+1;
|
2021-09-25 07:51:48 +08:00
|
|
|
|
break;
|
2021-09-24 11:41:14 +08:00
|
|
|
|
}
|
2022-01-18 20:31:07 +08:00
|
|
|
|
tokens.append(token);
|
|
|
|
|
positions.append(start);
|
2022-11-23 12:51:23 +08:00
|
|
|
|
} else if (attr->tokenType() == QSynedit::TokenType::Comment
|
2022-07-04 10:01:40 +08:00
|
|
|
|
&& currentLine == caretPos.line-1 && start<caretPos.ch
|
|
|
|
|
&& start+token.length()>=caretPos.ch) {
|
2022-01-18 20:31:07 +08:00
|
|
|
|
return; // in comment, do nothing
|
2021-09-24 11:41:14 +08:00
|
|
|
|
}
|
2022-01-18 20:31:07 +08:00
|
|
|
|
highlighter()->next();
|
|
|
|
|
}
|
|
|
|
|
if (!foundFunctionStart) {
|
|
|
|
|
for (int i=tokens.length()-1;i>=0;i--) {
|
|
|
|
|
if (braceLevel>0) {
|
|
|
|
|
if (tokens[i]=="{") {
|
|
|
|
|
braceLevel--;
|
|
|
|
|
} else if (tokens[i]=="}") {
|
|
|
|
|
braceLevel++;
|
|
|
|
|
}
|
|
|
|
|
} else if (bracketLevel>0) {
|
|
|
|
|
if (tokens[i]=="[") {
|
2022-01-28 19:30:50 +08:00
|
|
|
|
bracketLevel--;
|
2022-01-18 20:31:07 +08:00
|
|
|
|
} else if (tokens[i]=="]") {
|
2022-01-28 19:30:50 +08:00
|
|
|
|
bracketLevel++;
|
2022-01-18 20:31:07 +08:00
|
|
|
|
}
|
|
|
|
|
}else if (parenthesisLevel>0){
|
|
|
|
|
if (tokens[i]==")") {
|
|
|
|
|
parenthesisLevel++;
|
|
|
|
|
} else if (tokens[i]=="(") {
|
|
|
|
|
parenthesisLevel--;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (tokens[i]=="(") {
|
|
|
|
|
// found start of function
|
|
|
|
|
foundFunctionStart = true;
|
|
|
|
|
if (i>0) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
functionNamePos.line = currentLine+1;
|
|
|
|
|
functionNamePos.ch = positions[i-1]+1;
|
2022-01-18 20:31:07 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else if (tokens[i]=="[") {
|
|
|
|
|
//we are not in a function call
|
|
|
|
|
return;
|
|
|
|
|
} else if (tokens[i]=="{") {
|
|
|
|
|
//we are not in a function call
|
|
|
|
|
return;
|
|
|
|
|
} else if (tokens[i]==";") {
|
|
|
|
|
//we are not in a function call
|
|
|
|
|
return;
|
|
|
|
|
} else if (tokens[i]==")") {
|
|
|
|
|
parenthesisLevel++;
|
|
|
|
|
} else if (tokens[i]=="}") {
|
|
|
|
|
braceLevel++;
|
2022-01-28 19:30:50 +08:00
|
|
|
|
} else if (tokens[i]=="]") {
|
2022-01-18 20:31:07 +08:00
|
|
|
|
bracketLevel++;
|
|
|
|
|
} else if (tokens[i]==",") {
|
2022-01-28 19:30:50 +08:00
|
|
|
|
paramsCount++;
|
2022-01-18 20:31:07 +08:00
|
|
|
|
}
|
2021-09-25 08:40:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-24 11:41:14 +08:00
|
|
|
|
}
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (functionNamePos.ch>=0)
|
2021-09-24 11:41:14 +08:00
|
|
|
|
break;
|
2022-01-18 20:31:07 +08:00
|
|
|
|
currentLine--;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (caretPos.line-currentLine>maxLines)
|
2021-09-24 11:41:14 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 10:01:40 +08:00
|
|
|
|
isFunction = functionNamePos.ch>=0;
|
2022-01-18 20:31:07 +08:00
|
|
|
|
currentParamPos = paramsCount-1;
|
|
|
|
|
if (!isFunction)
|
2021-09-24 11:41:14 +08:00
|
|
|
|
return;
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pWordBegin, pWordEnd;
|
2021-09-24 11:41:14 +08:00
|
|
|
|
|
2022-01-18 20:31:07 +08:00
|
|
|
|
QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);
|
2021-09-24 11:41:14 +08:00
|
|
|
|
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int x = pWordBegin.ch-1-1;
|
|
|
|
|
QString line = document()->getString(pWordBegin.line-1);
|
2022-01-26 12:17:15 +08:00
|
|
|
|
bool hasPreviousWord=false;
|
|
|
|
|
while (x>=0) {
|
|
|
|
|
QChar ch=line[x];
|
2022-01-26 14:45:21 +08:00
|
|
|
|
if (ch == ' ' || ch == '\t') {
|
|
|
|
|
x--;
|
2022-01-26 12:17:15 +08:00
|
|
|
|
continue;
|
2022-01-26 14:45:21 +08:00
|
|
|
|
}
|
2022-01-26 12:17:15 +08:00
|
|
|
|
if (isIdentChar(ch)) {
|
|
|
|
|
hasPreviousWord = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
hasPreviousWord = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x >= 0 && hasPreviousWord) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord pos = pWordBegin;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
pos.ch = x+1;
|
2022-01-26 12:17:15 +08:00
|
|
|
|
QString previousWord = getPreviousWordAtPositionForSuggestion(pos);
|
|
|
|
|
|
|
|
|
|
PStatement statement = mParser->findStatementOf(
|
|
|
|
|
mFilename,
|
|
|
|
|
previousWord,
|
2022-07-04 10:01:40 +08:00
|
|
|
|
pos.line);
|
2022-01-26 12:17:15 +08:00
|
|
|
|
if (statement) {
|
|
|
|
|
PStatement typeStatement = mParser->findTypeDef(statement,mFilename);
|
|
|
|
|
if (typeStatement && typeStatement->kind == StatementKind::skClass) {
|
|
|
|
|
s = previousWord;
|
|
|
|
|
functionNamePos = pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-25 21:34:10 +08:00
|
|
|
|
// qDebug()<<QString("find word at %1:%2 - '%3'")
|
|
|
|
|
// .arg(FuncStartXY.Line)
|
|
|
|
|
// .arg(FuncStartXY.Char)
|
|
|
|
|
// .arg(s);
|
2021-09-24 11:41:14 +08:00
|
|
|
|
// Don't bother scanning the database when there's no identifier to scan for
|
|
|
|
|
|
|
|
|
|
// Only do the cumbersome list filling when showing a new tooltip...
|
2021-09-24 22:49:36 +08:00
|
|
|
|
|
2021-09-24 11:41:14 +08:00
|
|
|
|
if (s != pMainWindow->functionTip()->functionFullName()
|
|
|
|
|
&& !mParser->parsing()) {
|
|
|
|
|
pMainWindow->functionTip()->clearTips();
|
2021-09-24 22:49:36 +08:00
|
|
|
|
QList<PStatement> statements=mParser->getListOfFunctions(mFilename,
|
|
|
|
|
s,
|
2022-07-04 10:01:40 +08:00
|
|
|
|
functionNamePos.line);
|
2021-09-24 22:49:36 +08:00
|
|
|
|
|
|
|
|
|
foreach (const PStatement statement, statements) {
|
|
|
|
|
pMainWindow->functionTip()->addTip(
|
|
|
|
|
statement->command,
|
|
|
|
|
statement->fullName,
|
|
|
|
|
statement->type,
|
|
|
|
|
statement->args,
|
|
|
|
|
statement->noNameArgs);
|
|
|
|
|
}
|
2021-09-24 11:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 22:49:36 +08:00
|
|
|
|
// If we can't find it in our database, hide
|
|
|
|
|
if (pMainWindow->functionTip()->tipCount()<=0) {
|
2021-09-25 21:34:10 +08:00
|
|
|
|
pMainWindow->functionTip()->hide();
|
2021-09-24 22:49:36 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-25 21:34:10 +08:00
|
|
|
|
// Position it at the top of the next line
|
|
|
|
|
QPoint p = rowColumnToPixels(displayXY());
|
|
|
|
|
p+=QPoint(0,textHeight()+2);
|
|
|
|
|
pMainWindow->functionTip()->move(mapToGlobal(p));
|
2021-09-24 11:41:14 +08:00
|
|
|
|
|
2021-09-24 22:49:36 +08:00
|
|
|
|
pMainWindow->functionTip()->setFunctioFullName(s);
|
2022-01-18 20:31:07 +08:00
|
|
|
|
pMainWindow->functionTip()->guessFunction(paramsCount-1);
|
2021-09-24 22:49:36 +08:00
|
|
|
|
pMainWindow->functionTip()->setParamIndex(
|
2022-01-18 20:31:07 +08:00
|
|
|
|
currentParamPos
|
2021-09-24 22:49:36 +08:00
|
|
|
|
);
|
2022-01-15 11:22:20 +08:00
|
|
|
|
cancelHint();
|
2022-03-10 12:15:44 +08:00
|
|
|
|
if (showTip)
|
|
|
|
|
pMainWindow->functionTip()->show();
|
2021-09-24 11:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-01 21:16:22 +08:00
|
|
|
|
void Editor::clearUserCodeInTabStops()
|
|
|
|
|
{
|
|
|
|
|
mUserCodeInTabStops.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 10:05:14 +08:00
|
|
|
|
void Editor::popUserCodeInTabStops()
|
|
|
|
|
{
|
|
|
|
|
if (mTabStopBegin < 0) {
|
|
|
|
|
clearUserCodeInTabStops();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord newCursorPos;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
int tabStopEnd;
|
2021-10-03 09:57:19 +08:00
|
|
|
|
int tabStopBegin;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
if (mUserCodeInTabStops.count() > 0) {
|
|
|
|
|
PTabStop p = mUserCodeInTabStops.front();
|
|
|
|
|
// Update the cursor
|
|
|
|
|
if (p->y ==0) {
|
2022-03-10 13:07:07 +08:00
|
|
|
|
tabStopBegin = mTabStopEnd + p->x;
|
|
|
|
|
tabStopEnd = mTabStopEnd + p->endX;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
} else {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
int n=countLeadingWhitespaceChars(document()->getString(caretY()-1+p->y));
|
2022-03-10 13:07:07 +08:00
|
|
|
|
// qDebug()<<line<<n<<p->x;
|
|
|
|
|
tabStopBegin = n+p->x+1;
|
|
|
|
|
tabStopEnd = n+p->endX+1;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
}
|
2021-10-02 13:29:45 +08:00
|
|
|
|
mTabStopY = caretY() + p->y;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
newCursorPos.line = mTabStopY;
|
|
|
|
|
newCursorPos.ch = tabStopBegin;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
setCaretXY(newCursorPos);
|
|
|
|
|
setBlockBegin(newCursorPos);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
newCursorPos.ch = tabStopEnd;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
setBlockEnd(newCursorPos);
|
2021-10-03 09:57:19 +08:00
|
|
|
|
|
|
|
|
|
mTabStopBegin = tabStopBegin;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
mTabStopEnd = tabStopEnd;
|
2021-10-03 09:57:19 +08:00
|
|
|
|
mLineBeforeTabStop = lineText().mid(0, mTabStopBegin-1) ;
|
|
|
|
|
mLineAfterTabStop = lineText().mid(mTabStopEnd-1) ;
|
2021-10-02 10:05:14 +08:00
|
|
|
|
mXOffsetSince=0;
|
|
|
|
|
mUserCodeInTabStops.pop_front();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString &token, QSynedit::PHighlighterAttribute& attr)
|
2021-10-12 09:47:58 +08:00
|
|
|
|
{
|
|
|
|
|
if (!syntaxHighlighter)
|
|
|
|
|
return;
|
|
|
|
|
if (token.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
//don't do this
|
|
|
|
|
if (mCompletionPopup->isVisible() || mHeaderCompletionPopup->isVisible())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (mParser && (attr == syntaxHighlighter->identifierAttribute())) {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord p{column,Line};
|
|
|
|
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
2021-10-12 09:47:58 +08:00
|
|
|
|
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
|
|
|
|
// qDebug()<<s;
|
|
|
|
|
PStatement statement = mParser->findStatementOf(mFilename,
|
2022-07-04 10:01:40 +08:00
|
|
|
|
s , p.line);
|
2022-01-27 20:31:44 +08:00
|
|
|
|
StatementKind kind = getKindOfStatement(statement);
|
2021-10-12 09:47:58 +08:00
|
|
|
|
if (kind == StatementKind::skUnknown) {
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ((pEndPos.line>=1)
|
|
|
|
|
&& (pEndPos.ch>=0)
|
|
|
|
|
&& (pEndPos.ch < document()->getString(pEndPos.line-1).length())
|
|
|
|
|
&& (document()->getString(pEndPos.line-1)[pEndPos.ch] == '(')) {
|
2021-10-12 09:47:58 +08:00
|
|
|
|
kind = StatementKind::skFunction;
|
|
|
|
|
} else {
|
|
|
|
|
kind = StatementKind::skVariable;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::CppHighlighter* cppHighlighter = dynamic_cast<QSynedit::CppHighlighter*>(syntaxHighlighter.get());
|
2021-10-12 09:47:58 +08:00
|
|
|
|
switch(kind) {
|
|
|
|
|
case StatementKind::skFunction:
|
|
|
|
|
case StatementKind::skConstructor:
|
|
|
|
|
case StatementKind::skDestructor:
|
|
|
|
|
attr = cppHighlighter->functionAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skClass:
|
|
|
|
|
case StatementKind::skTypedef:
|
|
|
|
|
case StatementKind::skAlias:
|
|
|
|
|
attr = cppHighlighter->classAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skEnumClassType:
|
|
|
|
|
case StatementKind::skEnumType:
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skLocalVariable:
|
|
|
|
|
case StatementKind::skParameter:
|
|
|
|
|
attr = cppHighlighter->localVarAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skVariable:
|
|
|
|
|
attr = cppHighlighter->variableAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skGlobalVariable:
|
|
|
|
|
attr = cppHighlighter->globalVarAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skEnum:
|
|
|
|
|
case StatementKind::skPreprocessor:
|
|
|
|
|
attr = cppHighlighter->preprocessorAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skKeyword:
|
|
|
|
|
attr = cppHighlighter->keywordAttribute();
|
|
|
|
|
break;
|
|
|
|
|
case StatementKind::skNamespace:
|
|
|
|
|
case StatementKind::skNamespaceAlias:
|
|
|
|
|
attr = cppHighlighter->stringAttribute();
|
|
|
|
|
break;
|
2021-10-20 18:05:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-10-12 09:47:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 23:13:43 +08:00
|
|
|
|
void Editor::onScrollBarValueChanged()
|
|
|
|
|
{
|
|
|
|
|
pMainWindow->functionTip()->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 09:47:34 +08:00
|
|
|
|
PCppParser Editor::sharedParser(ParserLanguage language)
|
2022-10-27 15:18:57 +08:00
|
|
|
|
{
|
2022-10-28 09:47:34 +08:00
|
|
|
|
PCppParser parser;
|
|
|
|
|
if (mSharedParsers.contains(language)) {
|
2022-10-28 12:43:47 +08:00
|
|
|
|
parser=mSharedParsers[language].lock();
|
2022-10-28 09:47:34 +08:00
|
|
|
|
}
|
2022-10-27 15:18:57 +08:00
|
|
|
|
if (!parser) {
|
|
|
|
|
parser=std::make_shared<CppParser>();
|
2022-10-28 09:47:34 +08:00
|
|
|
|
parser->setLanguage(language);
|
2022-10-27 15:18:57 +08:00
|
|
|
|
parser->setOnGetFileStream(
|
|
|
|
|
std::bind(
|
|
|
|
|
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
|
|
|
|
|
std::placeholders::_1, std::placeholders::_2));
|
|
|
|
|
resetCppParser(parser);
|
|
|
|
|
parser->setEnabled(true);
|
2022-10-28 09:47:34 +08:00
|
|
|
|
mSharedParsers.insert(language,parser);
|
2022-10-27 15:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
return parser;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 12:40:47 +08:00
|
|
|
|
bool Editor::canAutoSave() const
|
|
|
|
|
{
|
|
|
|
|
return mCanAutoSave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::setCanAutoSave(bool newCanAutoSave)
|
|
|
|
|
{
|
|
|
|
|
mCanAutoSave = newCanAutoSave;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 21:19:48 +08:00
|
|
|
|
const QDateTime &Editor::hideTime() const
|
|
|
|
|
{
|
|
|
|
|
return mHideTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::setHideTime(const QDateTime &newHideTime)
|
|
|
|
|
{
|
|
|
|
|
mHideTime = newHideTime;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 22:34:19 +08:00
|
|
|
|
const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &Editor::statementColors() const
|
|
|
|
|
{
|
|
|
|
|
return mStatementColors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::setStatementColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newStatementColors)
|
|
|
|
|
{
|
|
|
|
|
mStatementColors = newStatementColors;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 00:30:53 +08:00
|
|
|
|
bool Editor::useCppSyntax() const
|
|
|
|
|
{
|
|
|
|
|
return mUseCppSyntax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::setUseCppSyntax(bool newUseCppSyntax)
|
|
|
|
|
{
|
|
|
|
|
mUseCppSyntax = newUseCppSyntax;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
|
void Editor::setProject(Project *pProject)
|
2021-09-10 12:37:02 +08:00
|
|
|
|
{
|
2022-10-09 22:19:18 +08:00
|
|
|
|
if (mProject == pProject)
|
2021-09-10 12:37:02 +08:00
|
|
|
|
return;
|
2022-10-09 22:19:18 +08:00
|
|
|
|
mProject = pProject;
|
|
|
|
|
if (mProject) {
|
|
|
|
|
mParser = mProject->cppParser();
|
2021-10-09 22:03:05 +08:00
|
|
|
|
if (isVisible()) {
|
|
|
|
|
if (mParser && mParser->parsing()) {
|
|
|
|
|
connect(mParser.get(),
|
|
|
|
|
&CppParser::onEndParsing,
|
|
|
|
|
this,
|
2022-09-25 09:55:18 +08:00
|
|
|
|
&QSynedit::SynEdit::invalidate);
|
2021-10-09 22:03:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
initParser();
|
2021-09-10 12:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
void Editor::gotoDeclaration(const QSynedit::BufferCoord &pos)
|
2021-08-30 19:52:38 +08:00
|
|
|
|
{
|
2022-03-04 16:40:16 +08:00
|
|
|
|
if (!parser())
|
2021-08-30 19:52:38 +08:00
|
|
|
|
return;
|
2022-03-04 16:40:16 +08:00
|
|
|
|
// Exit early, don't bother creating a stream (which is slow)
|
|
|
|
|
QStringList expression = getExpressionAtPosition(pos);
|
2021-08-30 19:52:38 +08:00
|
|
|
|
|
2022-03-04 16:40:16 +08:00
|
|
|
|
// Find it's definition
|
|
|
|
|
PStatement statement = parser()->findStatementOf(
|
|
|
|
|
filename(),
|
|
|
|
|
expression,
|
2022-07-04 10:01:40 +08:00
|
|
|
|
pos.line);
|
2022-03-04 16:40:16 +08:00
|
|
|
|
// QString phrase = getWordAtPosition(this,pos,pBeginPos,pEndPos, WordPurpose::wpInformation);
|
|
|
|
|
// if (phrase.isEmpty())
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// PStatement statement = mParser->findStatementOf(
|
|
|
|
|
// mFilename,phrase,pos.Line);
|
2021-08-30 19:52:38 +08:00
|
|
|
|
|
|
|
|
|
if (!statement) {
|
2022-03-04 16:40:16 +08:00
|
|
|
|
// pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase));
|
2021-08-30 19:52:38 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QString filename;
|
|
|
|
|
int line;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (statement->fileName == mFilename && statement->line == pos.line) {
|
2021-08-30 19:52:38 +08:00
|
|
|
|
filename = statement->definitionFileName;
|
|
|
|
|
line = statement->definitionLine;
|
|
|
|
|
} else {
|
|
|
|
|
filename = statement->fileName;
|
|
|
|
|
line = statement->line;
|
|
|
|
|
}
|
2022-10-18 19:09:46 +08:00
|
|
|
|
Editor *e = pMainWindow->openFile(filename);
|
|
|
|
|
if (e) {
|
|
|
|
|
e->setCaretPositionAndActivate(line,1);
|
|
|
|
|
}
|
2021-08-30 19:52:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
void Editor::gotoDefinition(const QSynedit::BufferCoord &pos)
|
2021-08-30 19:52:38 +08:00
|
|
|
|
{
|
2022-03-04 16:40:16 +08:00
|
|
|
|
QStringList expression = getExpressionAtPosition(pos);
|
2021-08-30 19:52:38 +08:00
|
|
|
|
|
2022-03-04 16:40:16 +08:00
|
|
|
|
// Find it's definition
|
|
|
|
|
PStatement statement = parser()->findStatementOf(
|
|
|
|
|
filename(),
|
|
|
|
|
expression,
|
2022-07-04 10:01:40 +08:00
|
|
|
|
pos.line);
|
2021-08-30 19:52:38 +08:00
|
|
|
|
|
|
|
|
|
if (!statement) {
|
2022-03-04 16:40:16 +08:00
|
|
|
|
// pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase));
|
2021-08-30 19:52:38 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QString filename;
|
|
|
|
|
int line;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if (statement->definitionFileName == mFilename && statement->definitionLine == pos.line) {
|
2022-03-19 15:33:15 +08:00
|
|
|
|
filename = statement->fileName;
|
|
|
|
|
line = statement->line;
|
|
|
|
|
} else {
|
|
|
|
|
filename = statement->definitionFileName;
|
|
|
|
|
line = statement->definitionLine;
|
|
|
|
|
}
|
2022-10-18 19:09:46 +08:00
|
|
|
|
Editor *e = pMainWindow->openFile(filename);
|
|
|
|
|
if (e) {
|
|
|
|
|
e->setCaretPositionAndActivate(line,1);
|
|
|
|
|
}
|
2021-08-30 19:52:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QString getWordAtPosition(QSynedit::SynEdit *editor, const QSynedit::BufferCoord &p, QSynedit::BufferCoord &pWordBegin, QSynedit::BufferCoord &pWordEnd, Editor::WordPurpose purpose)
|
2021-08-25 23:53:35 +08:00
|
|
|
|
{
|
|
|
|
|
QString result = "";
|
|
|
|
|
QString s;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ((p.line<1) || (p.line>editor->document()->count())) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
pWordBegin = p;
|
|
|
|
|
pWordEnd = p;
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 10:01:40 +08:00
|
|
|
|
s = editor->document()->getString(p.line - 1);
|
2021-08-26 11:58:29 +08:00
|
|
|
|
int len = s.length();
|
|
|
|
|
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int wordBegin = p.ch - 1 - 1; //BufferCoord::Char starts with 1
|
|
|
|
|
int wordEnd = p.ch - 1 - 1;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
|
|
|
|
|
// Copy forward until end of word
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (purpose == Editor::WordPurpose::wpEvaluation
|
|
|
|
|
|| purpose == Editor::WordPurpose::wpInformation) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while (wordEnd + 1 < len) {
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if ((purpose == Editor::WordPurpose::wpEvaluation)
|
2021-08-26 11:58:29 +08:00
|
|
|
|
&& (s[wordEnd + 1] == '[')) {
|
|
|
|
|
if (!findComplement(s, '[', ']', wordEnd, 1))
|
2021-08-25 23:53:35 +08:00
|
|
|
|
break;
|
2021-09-03 16:39:20 +08:00
|
|
|
|
} else if (editor->isIdentChar(s[wordEnd + 1])) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordEnd++;
|
|
|
|
|
} else
|
|
|
|
|
break;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
2021-08-26 11:58:29 +08:00
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
2021-08-26 11:58:29 +08:00
|
|
|
|
// Copy backward until #
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (purpose == Editor::WordPurpose::wpDirective) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while ((wordBegin >= 0) && (wordBegin < len)) {
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (editor->isIdentChar(s[wordBegin]))
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
|
|
|
|
else if (s[wordBegin] == '#') {
|
|
|
|
|
wordBegin--;
|
|
|
|
|
break;
|
|
|
|
|
} else
|
|
|
|
|
break;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
2021-08-26 11:58:29 +08:00
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
2021-08-26 11:58:29 +08:00
|
|
|
|
// Copy backward until @
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (purpose == Editor::WordPurpose::wpJavadoc) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while ((wordBegin >= 0) && (wordBegin < len)) {
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (editor->isIdentChar(s[wordBegin]))
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
|
|
|
|
else if (s[wordBegin] == '@') {
|
|
|
|
|
wordBegin--;
|
|
|
|
|
break;
|
|
|
|
|
} else
|
|
|
|
|
break;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
2021-08-26 11:58:29 +08:00
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
2021-08-26 11:58:29 +08:00
|
|
|
|
// Copy backward until begin of path
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (purpose == Editor::WordPurpose::wpHeaderCompletion) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while ((wordBegin >= 0) && (wordBegin < len)) {
|
2021-09-27 00:52:25 +08:00
|
|
|
|
if (editor->isIdentChar(s[wordBegin])) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
2021-09-27 00:52:25 +08:00
|
|
|
|
} else if (s[wordBegin] == '.'
|
|
|
|
|
|| s[wordBegin] == '+') {
|
|
|
|
|
wordBegin--;
|
|
|
|
|
} else if (s[wordBegin] == '/'
|
|
|
|
|
|| s[wordBegin] == '\\') {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
|
|
|
|
break;
|
|
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (purpose == Editor::WordPurpose::wpHeaderCompletionStart) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while ((wordBegin >= 0) && (wordBegin < len)) {
|
|
|
|
|
if (s[wordBegin] == '"'
|
|
|
|
|
|| s[wordBegin] == '<') {
|
|
|
|
|
wordBegin--;
|
|
|
|
|
break;
|
|
|
|
|
} else if (s[wordBegin] == '/'
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|| s[wordBegin] == '\\'
|
|
|
|
|
|| s[wordBegin] == '.') {
|
|
|
|
|
wordBegin--;
|
2021-09-03 16:39:20 +08:00
|
|
|
|
} else if (editor->isIdentChar(s[wordBegin]))
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
|
|
|
|
else
|
|
|
|
|
break;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
2021-08-26 11:58:29 +08:00
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
2021-08-26 11:58:29 +08:00
|
|
|
|
// && ( wordBegin < len)
|
|
|
|
|
// Copy backward until begin of word
|
2021-09-03 16:39:20 +08:00
|
|
|
|
if (purpose == Editor::WordPurpose::wpCompletion
|
|
|
|
|
|| purpose == Editor::WordPurpose::wpEvaluation
|
|
|
|
|
|| purpose == Editor::WordPurpose::wpInformation) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while ((wordBegin >= 0) && (wordBegin<len)) {
|
|
|
|
|
if (s[wordBegin] == ']') {
|
|
|
|
|
if (!findComplement(s, ']', '[', wordBegin, -1))
|
2021-08-25 23:53:35 +08:00
|
|
|
|
break;
|
|
|
|
|
else
|
2021-09-29 20:45:03 +08:00
|
|
|
|
wordBegin--; // step over mathing [
|
2021-09-03 16:39:20 +08:00
|
|
|
|
} else if (editor->isIdentChar(s[wordBegin])) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
|
|
|
|
} else if (s[wordBegin] == '.'
|
|
|
|
|
|| s[wordBegin] == ':'
|
|
|
|
|
|| s[wordBegin] == '~') { // allow destructor signs
|
|
|
|
|
wordBegin--;
|
|
|
|
|
} else if (
|
|
|
|
|
(s[wordBegin] == '>')
|
|
|
|
|
&& (wordBegin+2<len)
|
|
|
|
|
&& (s[wordBegin+1]==':')
|
|
|
|
|
&& (s[wordBegin+2]==':')
|
|
|
|
|
) { // allow template
|
|
|
|
|
if (!findComplement(s, '>', '<', wordBegin, -1))
|
2021-08-25 23:53:35 +08:00
|
|
|
|
break;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
else
|
|
|
|
|
wordBegin--; // step over >
|
|
|
|
|
} else if ((wordBegin-1 >= 0)
|
|
|
|
|
&& (s[wordBegin - 1] == '-')
|
|
|
|
|
&& (s[wordBegin] == '>')) {
|
|
|
|
|
wordBegin-=2;
|
|
|
|
|
} else if ((wordBegin-1 >= 0)
|
|
|
|
|
&& (s[wordBegin - 1] == ':')
|
|
|
|
|
&& (s[wordBegin] == ':')) {
|
|
|
|
|
wordBegin-=2;
|
|
|
|
|
} else if ((wordBegin > 0)
|
|
|
|
|
&& (s[wordBegin] == ')')) {
|
|
|
|
|
if (!findComplement(s, ')', '(', wordBegin, -1))
|
2021-08-25 23:53:35 +08:00
|
|
|
|
break;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
else
|
|
|
|
|
wordBegin--; // step over mathing (
|
|
|
|
|
} else
|
|
|
|
|
break;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get end result
|
2021-08-26 20:18:20 +08:00
|
|
|
|
result = s.mid(wordBegin+1, wordEnd - wordBegin);
|
2022-07-04 10:01:40 +08:00
|
|
|
|
pWordBegin.line = p.line;
|
|
|
|
|
pWordBegin.ch = wordBegin+1;
|
|
|
|
|
pWordEnd.line = p.line;
|
|
|
|
|
pWordEnd.ch = wordEnd;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
|
|
|
|
|
// last line still have part of word
|
|
|
|
|
if (!result.isEmpty()
|
|
|
|
|
&& (
|
|
|
|
|
result[0] == '.'
|
|
|
|
|
|| result[0] == '-')
|
2021-09-03 16:39:20 +08:00
|
|
|
|
&& (purpose == Editor::WordPurpose::wpCompletion
|
|
|
|
|
|| purpose == Editor::WordPurpose::wpEvaluation
|
|
|
|
|
|| purpose == Editor::WordPurpose::wpInformation)) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
int i = wordBegin;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int line=p.line;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
while (line>=1) {
|
|
|
|
|
while (i>=0) {
|
|
|
|
|
if (s[i] == ' '
|
|
|
|
|
|| s[i] == '\t')
|
|
|
|
|
i--;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i<0) {
|
|
|
|
|
line--;
|
|
|
|
|
if (line>=1) {
|
2022-04-19 21:18:41 +08:00
|
|
|
|
s=editor->document()->getString(line-1);
|
2021-08-26 11:58:29 +08:00
|
|
|
|
i=s.length();
|
|
|
|
|
continue;
|
|
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord highlightPos;
|
|
|
|
|
QSynedit::BufferCoord pDummy;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
highlightPos.line = line;
|
|
|
|
|
highlightPos.ch = i+1;
|
2021-09-03 16:39:20 +08:00
|
|
|
|
result = getWordAtPosition(editor, highlightPos,pWordBegin,pDummy,purpose)+result;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
|
|
|
|
// Strip function parameters
|
2021-08-26 11:58:29 +08:00
|
|
|
|
int paramBegin,paramEnd;
|
|
|
|
|
while (true) {
|
|
|
|
|
paramBegin = result.indexOf('(');
|
|
|
|
|
if (paramBegin > 0) {
|
|
|
|
|
paramEnd = paramBegin;
|
|
|
|
|
if ((paramBegin==0)
|
|
|
|
|
&& findComplement(result, '(', ')', paramEnd, 1)
|
|
|
|
|
&& (paramEnd = result.length()-1) ) {
|
|
|
|
|
//remove the enclosing parenthese pair
|
|
|
|
|
result = result.mid(1,result.length()-2);
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
paramEnd = paramBegin;
|
|
|
|
|
if (findComplement(result, '(', ')', paramEnd, 1)) {
|
|
|
|
|
result.remove(paramBegin, paramEnd - paramBegin + 1);
|
|
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else
|
2021-08-25 23:53:35 +08:00
|
|
|
|
break;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
2021-08-26 11:58:29 +08:00
|
|
|
|
paramBegin = 0;
|
|
|
|
|
while ((paramBegin < result.length()) && (result[paramBegin] == '*')) {
|
|
|
|
|
paramBegin++;
|
|
|
|
|
}
|
|
|
|
|
result.remove(0,paramBegin);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoord &p)
|
2021-08-26 11:58:29 +08:00
|
|
|
|
{
|
|
|
|
|
QString result;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
if ((p.line<1) || (p.line>document()->count())) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
return "";
|
|
|
|
|
}
|
2022-07-04 10:01:40 +08:00
|
|
|
|
bool inFunc = testInFunc(p.ch-1,p.line-1);
|
2021-08-26 11:58:29 +08:00
|
|
|
|
|
2022-07-04 10:01:40 +08:00
|
|
|
|
QString s = document()->getString(p.line - 1);
|
2021-08-26 11:58:29 +08:00
|
|
|
|
int wordBegin;
|
2022-07-04 10:01:40 +08:00
|
|
|
|
int wordEnd = p.ch-1;
|
2021-08-26 11:58:29 +08:00
|
|
|
|
if (wordEnd >= s.length())
|
|
|
|
|
wordEnd = s.length()-1;
|
|
|
|
|
while (true) {
|
|
|
|
|
int bracketLevel=0;
|
|
|
|
|
bool skipNextWord=false;
|
|
|
|
|
while (wordEnd > 0) {
|
|
|
|
|
if (s[wordEnd] == '>'
|
|
|
|
|
|| s[wordEnd] == ']') {
|
|
|
|
|
bracketLevel++;
|
|
|
|
|
} else if (s[wordEnd] == '<'
|
|
|
|
|
|| s[wordEnd] == '[') {
|
|
|
|
|
bracketLevel--;
|
|
|
|
|
} else if (bracketLevel==0) {
|
|
|
|
|
//we can't differentiate multiple definition and function parameter define here , so we don't handle ','
|
|
|
|
|
if (s[wordEnd] == ',') {
|
|
|
|
|
if (inFunc) // in func, dont skip ','
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
skipNextWord=true;
|
|
|
|
|
} else if (s[wordEnd] != ' '
|
|
|
|
|
&& s[wordEnd] != '\t') {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wordEnd--;
|
|
|
|
|
}
|
|
|
|
|
if (wordEnd<0)
|
|
|
|
|
return "";
|
|
|
|
|
if (bracketLevel > 0)
|
|
|
|
|
return "";
|
|
|
|
|
if (!isIdentChar(s[wordEnd]))
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
wordBegin = wordEnd;
|
2022-02-07 09:53:02 +08:00
|
|
|
|
while ((wordBegin >= 0) && (isIdentChar(s[wordBegin]) || s[wordBegin]==':') ) {
|
2021-08-26 11:58:29 +08:00
|
|
|
|
wordBegin--;
|
|
|
|
|
}
|
|
|
|
|
wordBegin++;
|
|
|
|
|
|
|
|
|
|
if (s[wordBegin]>='0' && s[wordBegin]<='9') // not valid word
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
result = s.mid(wordBegin, wordEnd - wordBegin+1);
|
|
|
|
|
if ((result != "const") && !skipNextWord)
|
|
|
|
|
break;
|
|
|
|
|
wordEnd = wordBegin-1;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2021-08-25 08:48:33 +08:00
|
|
|
|
}
|
2021-09-02 12:14:02 +08:00
|
|
|
|
|
2022-11-10 13:35:13 +08:00
|
|
|
|
QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSynedit::BufferCoord &p)
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
if ((p.line<1) || (p.line>document()->count())) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString s = document()->getString(p.line - 1);
|
|
|
|
|
int wordBegin;
|
|
|
|
|
int wordEnd = p.ch-1;
|
|
|
|
|
if (wordEnd >= s.length())
|
|
|
|
|
wordEnd = s.length()-1;
|
|
|
|
|
while (wordEnd > 0 && (isIdentChar(s[wordEnd]) || s[wordEnd] == ':')) {
|
|
|
|
|
wordEnd--;
|
|
|
|
|
}
|
|
|
|
|
int bracketLevel=0;
|
|
|
|
|
while (wordEnd > 0) {
|
|
|
|
|
if (s[wordEnd] == '>'
|
|
|
|
|
|| s[wordEnd] == ']') {
|
|
|
|
|
bracketLevel++;
|
|
|
|
|
} else if (s[wordEnd] == '<'
|
|
|
|
|
|| s[wordEnd] == '[') {
|
|
|
|
|
bracketLevel--;
|
|
|
|
|
} else if (bracketLevel==0) {
|
|
|
|
|
if (s[wordEnd]=='*' || s[wordEnd]=='&' || s[wordEnd]==' ' || s[wordEnd]=='\t') {
|
|
|
|
|
//do nothing
|
|
|
|
|
} else if (isIdentChar(s[wordEnd]))
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
return ""; //error happened
|
|
|
|
|
}
|
|
|
|
|
wordEnd--;
|
|
|
|
|
}
|
|
|
|
|
if (wordEnd<0)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
// if (!isIdentChar(s[wordEnd]))
|
|
|
|
|
// return "";
|
|
|
|
|
|
|
|
|
|
wordBegin = wordEnd;
|
|
|
|
|
while ((wordBegin >= 0) && isIdentChar(s[wordBegin]) ) {
|
|
|
|
|
wordBegin--;
|
|
|
|
|
}
|
|
|
|
|
wordBegin++;
|
|
|
|
|
|
2022-11-16 11:51:50 +08:00
|
|
|
|
if (wordBegin<s.length() && s[wordBegin]>='0' && s[wordBegin]<='9') // not valid word
|
2022-11-10 13:35:13 +08:00
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
result = s.mid(wordBegin, wordEnd - wordBegin+1);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:13:51 +08:00
|
|
|
|
void Editor::reformat(bool doReparse)
|
2021-09-02 12:14:02 +08:00
|
|
|
|
{
|
|
|
|
|
if (readOnly())
|
|
|
|
|
return;
|
2021-12-27 22:46:54 +08:00
|
|
|
|
#ifndef Q_OS_WIN
|
|
|
|
|
if (!fileExists(pSettings->environment().AStylePath())) {
|
|
|
|
|
QMessageBox::critical(this,
|
|
|
|
|
tr("astyle not found"),
|
|
|
|
|
tr("Can't find astyle in \"%1\".").arg(pSettings->environment().AStylePath()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-09-05 22:16:54 +08:00
|
|
|
|
//we must remove all breakpoints and syntax issues
|
2022-04-19 21:18:41 +08:00
|
|
|
|
onLinesDeleted(1,document()->count());
|
2021-10-07 07:52:20 +08:00
|
|
|
|
QByteArray content = text().toUtf8();
|
2021-09-02 12:14:02 +08:00
|
|
|
|
QStringList args = pSettings->codeFormatter().getArguments();
|
2022-10-10 18:05:18 +08:00
|
|
|
|
//qDebug()<<args;
|
2021-12-27 22:46:54 +08:00
|
|
|
|
#ifdef Q_OS_WIN
|
2021-09-02 12:14:02 +08:00
|
|
|
|
QByteArray newContent = runAndGetOutput("astyle.exe",
|
2021-12-26 15:08:54 +08:00
|
|
|
|
pSettings->dirs().appDir(),
|
2021-09-02 12:14:02 +08:00
|
|
|
|
args,
|
|
|
|
|
content);
|
2021-12-27 22:46:54 +08:00
|
|
|
|
#else
|
|
|
|
|
QByteArray newContent = runAndGetOutput(pSettings->environment().AStylePath(),
|
|
|
|
|
extractFileDir(pSettings->environment().AStylePath()),
|
|
|
|
|
args,
|
|
|
|
|
content);
|
|
|
|
|
#endif
|
2022-06-12 22:54:34 +08:00
|
|
|
|
if (newContent.isEmpty())
|
|
|
|
|
return;
|
2021-11-23 10:32:33 +08:00
|
|
|
|
int oldTopLine = topLine();
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::BufferCoord mOldCaret = caretXY();
|
2021-09-02 12:14:02 +08:00
|
|
|
|
|
2022-06-12 22:54:34 +08:00
|
|
|
|
beginUndoBlock();
|
|
|
|
|
addLeftTopToUndo();
|
|
|
|
|
addCaretToUndo();
|
2022-06-23 13:05:10 +08:00
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::EditorOptions oldOptions = getOptions();
|
|
|
|
|
QSynedit::EditorOptions newOptions = oldOptions;
|
|
|
|
|
newOptions.setFlag(QSynedit::EditorOption::eoAutoIndent,false);
|
2021-11-13 09:05:02 +08:00
|
|
|
|
setOptions(newOptions);
|
2022-06-23 13:05:10 +08:00
|
|
|
|
replaceAll(QString::fromUtf8(newContent));
|
2021-11-23 10:32:33 +08:00
|
|
|
|
setCaretXY(mOldCaret);
|
|
|
|
|
setTopLine(oldTopLine);
|
2021-11-13 09:05:02 +08:00
|
|
|
|
setOptions(oldOptions);
|
2022-06-12 22:54:34 +08:00
|
|
|
|
endUndoBlock();
|
2022-10-25 10:13:51 +08:00
|
|
|
|
|
|
|
|
|
if (doReparse && !pMainWindow->isQuitting() && !pMainWindow->isClosingAll()
|
|
|
|
|
&& !(inProject() && pMainWindow->closingProject())) {
|
|
|
|
|
reparse(true);
|
|
|
|
|
checkSyntaxInBack();
|
|
|
|
|
reparseTodo();
|
|
|
|
|
pMainWindow->updateEditorActions();
|
|
|
|
|
}
|
2021-09-02 12:14:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::checkSyntaxInBack()
|
|
|
|
|
{
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (!mParentPageControl)
|
|
|
|
|
return;
|
2021-09-02 12:14:02 +08:00
|
|
|
|
if (readOnly())
|
|
|
|
|
return;
|
2022-01-23 23:27:48 +08:00
|
|
|
|
if (!highlighter())
|
|
|
|
|
return;
|
2022-09-27 14:01:38 +08:00
|
|
|
|
if (highlighter()->language()!=QSynedit::HighlighterLanguage::Cpp)
|
2022-01-23 23:27:48 +08:00
|
|
|
|
return;
|
2022-10-21 19:12:18 +08:00
|
|
|
|
pMainWindow->checkSyntaxInBack(this);
|
2021-09-02 12:14:02 +08:00
|
|
|
|
}
|
2021-08-25 08:48:33 +08:00
|
|
|
|
|
2021-09-03 16:39:20 +08:00
|
|
|
|
const PCppParser &Editor::parser()
|
2021-08-23 17:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
return mParser;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 23:35:45 +08:00
|
|
|
|
void Editor::tab()
|
|
|
|
|
{
|
|
|
|
|
if (mUserCodeInTabStops.count()>0) {
|
|
|
|
|
int oldLine = caretY();
|
|
|
|
|
popUserCodeInTabStops();
|
|
|
|
|
if (oldLine!=caretY()) {
|
|
|
|
|
invalidateLine(oldLine);
|
|
|
|
|
}
|
|
|
|
|
invalidateLine(caretY());
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
if (mTabStopBegin >= 0) {
|
|
|
|
|
mTabStopBegin = -1;
|
2022-03-02 11:31:03 +08:00
|
|
|
|
setCaretXY(blockEnd());
|
2021-10-06 23:35:45 +08:00
|
|
|
|
invalidateLine(caretY());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SynEdit::tab();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 13:57:22 +08:00
|
|
|
|
int Editor::gutterClickedLine() const
|
|
|
|
|
{
|
|
|
|
|
return mGutterClickedLine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::toggleBreakpoint(int line)
|
|
|
|
|
{
|
|
|
|
|
if (hasBreakpoint(line)) {
|
|
|
|
|
mBreakpointLines.remove(line);
|
2021-08-01 09:13:38 +08:00
|
|
|
|
pMainWindow->debugger()->removeBreakpoint(line,this);
|
2021-07-03 13:57:22 +08:00
|
|
|
|
} else {
|
|
|
|
|
mBreakpointLines.insert(line);
|
2021-08-01 09:13:38 +08:00
|
|
|
|
pMainWindow->debugger()->addBreakpoint(line,this);
|
2021-07-03 13:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invalidateGutterLine(line);
|
|
|
|
|
invalidateLine(line);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 10:30:08 +08:00
|
|
|
|
void Editor::clearBreakpoints()
|
|
|
|
|
{
|
|
|
|
|
pMainWindow->debugger()->deleteBreakpoints(this);
|
|
|
|
|
mBreakpointLines.clear();
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 13:57:22 +08:00
|
|
|
|
bool Editor::hasBreakpoint(int line)
|
|
|
|
|
{
|
|
|
|
|
return mBreakpointLines.contains(line);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 21:51:33 +08:00
|
|
|
|
void Editor::addBookmark(int line)
|
2021-10-21 17:31:25 +08:00
|
|
|
|
{
|
|
|
|
|
mBookmarkLines.insert(line);
|
|
|
|
|
invalidateGutterLine(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Editor::removeBookmark(int line)
|
|
|
|
|
{
|
|
|
|
|
mBookmarkLines.remove(line);
|
|
|
|
|
invalidateGutterLine(line);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 10:58:30 +08:00
|
|
|
|
bool Editor::hasBookmark(int line) const
|
2021-10-21 17:31:25 +08:00
|
|
|
|
{
|
|
|
|
|
return mBookmarkLines.contains(line);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 19:33:11 +08:00
|
|
|
|
void Editor::clearBookmarks()
|
|
|
|
|
{
|
|
|
|
|
mBookmarkLines.clear();
|
|
|
|
|
invalidateGutter();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 00:22:08 +08:00
|
|
|
|
void Editor::removeBreakpointFocus()
|
|
|
|
|
{
|
|
|
|
|
if (mActiveBreakpointLine!=-1) {
|
|
|
|
|
int oldLine = mActiveBreakpointLine;
|
|
|
|
|
mActiveBreakpointLine = -1;
|
|
|
|
|
invalidateGutterLine(oldLine);
|
|
|
|
|
invalidateLine(oldLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 10:30:08 +08:00
|
|
|
|
void Editor::modifyBreakpointProperty(int line)
|
|
|
|
|
{
|
|
|
|
|
int index;
|
2022-10-16 23:10:57 +08:00
|
|
|
|
PBreakpoint breakpoint = pMainWindow->debugger()->breakpointAt(line,this,&index);
|
2021-09-03 10:30:08 +08:00
|
|
|
|
if (!breakpoint)
|
|
|
|
|
return;
|
|
|
|
|
bool isOk;
|
|
|
|
|
QString s=QInputDialog::getText(this,
|
|
|
|
|
tr("Break point condition"),
|
|
|
|
|
tr("Enter the condition of the breakpoint:"),
|
|
|
|
|
QLineEdit::Normal,
|
|
|
|
|
breakpoint->condition,&isOk);
|
|
|
|
|
if (isOk) {
|
2022-10-16 23:10:57 +08:00
|
|
|
|
pMainWindow->debugger()->setBreakPointCondition(index,s,inProject());
|
2021-09-03 10:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 18:22:09 +08:00
|
|
|
|
void Editor::setActiveBreakpointFocus(int Line, bool setFocus)
|
|
|
|
|
{
|
|
|
|
|
if (Line != mActiveBreakpointLine) {
|
|
|
|
|
removeBreakpointFocus();
|
|
|
|
|
|
|
|
|
|
// Put the caret at the active breakpoint
|
|
|
|
|
mActiveBreakpointLine = Line;
|
|
|
|
|
|
|
|
|
|
if (setFocus)
|
|
|
|
|
setCaretPositionAndActivate(Line,1);
|
|
|
|
|
else
|
|
|
|
|
setCaretPosition(Line,1);
|
|
|
|
|
|
|
|
|
|
// Invalidate new active line
|
|
|
|
|
invalidateGutterLine(Line);
|
|
|
|
|
invalidateLine(Line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 11:02:03 +08:00
|
|
|
|
void Editor::applySettings()
|
|
|
|
|
{
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::EditorOptions options = QSynedit::eoAltSetsColumnMode |
|
2022-09-25 09:55:18 +08:00
|
|
|
|
QSynedit::eoDragDropEditing | QSynedit::eoDropFiles | QSynedit::eoKeepCaretX | QSynedit::eoTabsToSpaces |
|
|
|
|
|
QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo;
|
2021-06-09 17:12:23 +08:00
|
|
|
|
|
|
|
|
|
//options
|
2022-09-25 09:55:18 +08:00
|
|
|
|
options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent());
|
|
|
|
|
options.setFlag(QSynedit::eoTabsToSpaces,pSettings->editor().tabToSpaces());
|
|
|
|
|
|
|
|
|
|
options.setFlag(QSynedit::eoLigatureSupport, pSettings->editor().enableLigaturesSupport());
|
|
|
|
|
|
|
|
|
|
options.setFlag(QSynedit::eoKeepCaretX,pSettings->editor().keepCaretX());
|
|
|
|
|
options.setFlag(QSynedit::eoEnhanceHomeKey,pSettings->editor().enhanceHomeKey());
|
|
|
|
|
options.setFlag(QSynedit::eoEnhanceEndKey,pSettings->editor().enhanceEndKey());
|
|
|
|
|
|
|
|
|
|
options.setFlag(QSynedit::eoHideShowScrollbars,pSettings->editor().autoHideScrollbar());
|
|
|
|
|
options.setFlag(QSynedit::eoScrollPastEol,pSettings->editor().scrollPastEol());
|
|
|
|
|
options.setFlag(QSynedit::eoScrollPastEof,pSettings->editor().scrollPastEof());
|
|
|
|
|
options.setFlag(QSynedit::eoScrollByOneLess,pSettings->editor().scrollByOneLess());
|
|
|
|
|
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
|
|
|
|
|
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
|
2022-12-01 22:10:44 +08:00
|
|
|
|
options.setFlag(QSynedit::eoShowRainbowColor,
|
|
|
|
|
pSettings->editor().rainbowParenthesis()
|
|
|
|
|
&& highlighter() && highlighter()->supportBraceLevel());
|
2021-06-07 11:02:03 +08:00
|
|
|
|
setOptions(options);
|
|
|
|
|
|
|
|
|
|
setTabWidth(pSettings->editor().tabWidth());
|
|
|
|
|
setInsertCaret(pSettings->editor().caretForInsert());
|
|
|
|
|
setOverwriteCaret(pSettings->editor().caretForOverwrite());
|
2021-09-15 14:35:37 +08:00
|
|
|
|
setCaretUseTextColor(pSettings->editor().caretUseTextColor());
|
|
|
|
|
setCaretColor(pSettings->editor().caretColor());
|
2021-06-09 17:12:23 +08:00
|
|
|
|
|
2021-10-12 19:39:24 +08:00
|
|
|
|
codeFolding().indentGuides = pSettings->editor().showIndentLines();
|
|
|
|
|
codeFolding().indentGuidesColor = pSettings->editor().indentLineColor();
|
2021-10-20 11:14:49 +08:00
|
|
|
|
codeFolding().fillIndents = pSettings->editor().fillIndents();
|
2021-10-12 19:39:24 +08:00
|
|
|
|
|
2021-12-16 19:14:14 +08:00
|
|
|
|
QFont f=QFont(pSettings->editor().fontName());
|
2021-12-17 09:05:01 +08:00
|
|
|
|
f.setPixelSize(pointToPixel(pSettings->editor().fontSize()));
|
2021-06-09 17:12:23 +08:00
|
|
|
|
f.setStyleStrategy(QFont::PreferAntialias);
|
|
|
|
|
setFont(f);
|
2022-01-26 14:31:26 +08:00
|
|
|
|
QFont f2=QFont(pSettings->editor().nonAsciiFontName());
|
|
|
|
|
f2.setPixelSize(pointToPixel(pSettings->editor().fontSize()));
|
|
|
|
|
f2.setStyleStrategy(QFont::PreferAntialias);
|
|
|
|
|
setFontForNonAscii(f2);
|
2021-06-09 17:12:23 +08:00
|
|
|
|
|
|
|
|
|
// Set gutter properties
|
2021-12-20 09:36:18 +08:00
|
|
|
|
gutter().setLeftOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterLeftOffset());
|
2021-06-09 17:12:23 +08:00
|
|
|
|
gutter().setRightOffset(pSettings->editor().gutterRightOffset());
|
2022-09-27 14:01:38 +08:00
|
|
|
|
gutter().setBorderStyle(QSynedit::GutterBorderStyle::None);
|
2021-06-09 17:12:23 +08:00
|
|
|
|
gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont());
|
|
|
|
|
if (pSettings->editor().gutterUseCustomFont()) {
|
2021-12-16 19:14:14 +08:00
|
|
|
|
f=QFont(pSettings->editor().gutterFontName());
|
2021-12-17 09:05:01 +08:00
|
|
|
|
f.setPixelSize(pointToPixel(pSettings->editor().gutterFontSize()));
|
2021-06-09 17:12:23 +08:00
|
|
|
|
} else {
|
2021-12-16 19:14:14 +08:00
|
|
|
|
f=QFont(pSettings->editor().fontName());
|
2021-12-17 09:05:01 +08:00
|
|
|
|
f.setPixelSize(pointToPixel(pSettings->editor().fontSize()));
|
2021-06-09 17:12:23 +08:00
|
|
|
|
}
|
|
|
|
|
f.setStyleStrategy(QFont::PreferAntialias);
|
|
|
|
|
gutter().setFont(f);
|
|
|
|
|
gutter().setDigitCount(pSettings->editor().gutterDigitsCount());
|
|
|
|
|
gutter().setVisible(pSettings->editor().gutterVisible());
|
|
|
|
|
gutter().setAutoSize(pSettings->editor().gutterAutoSize());
|
|
|
|
|
gutter().setShowLineNumbers(pSettings->editor().gutterShowLineNumbers());
|
|
|
|
|
gutter().setLeadingZeros(pSettings->editor().gutterAddLeadingZero());
|
|
|
|
|
if (pSettings->editor().gutterLineNumbersStartZero())
|
|
|
|
|
gutter().setLineNumberStart(0);
|
|
|
|
|
else
|
|
|
|
|
gutter().setLineNumberStart(1);
|
|
|
|
|
//font color
|
|
|
|
|
|
2021-09-04 19:27:44 +08:00
|
|
|
|
if (pSettings->editor().showRightEdgeLine()) {
|
|
|
|
|
setRightEdge(pSettings->editor().rightEdgeWidth());
|
|
|
|
|
setRightEdgeColor(pSettings->editor().rightEdgeLineColor());
|
|
|
|
|
} else {
|
|
|
|
|
setRightEdge(0);
|
|
|
|
|
}
|
2021-10-20 12:27:44 +08:00
|
|
|
|
|
2022-11-22 15:14:05 +08:00
|
|
|
|
if (pSettings->editor().enableCustomCTypeKeywords()) {
|
|
|
|
|
if (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) {
|
|
|
|
|
QSet<QString> set;
|
|
|
|
|
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
|
|
|
|
|
set.insert(s);
|
|
|
|
|
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(set);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) {
|
|
|
|
|
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(QSet<QString>());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-20 18:10:53 +08:00
|
|
|
|
this->setUndoLimit(pSettings->editor().undoLimit());
|
2022-10-11 22:33:09 +08:00
|
|
|
|
this->setUndoMemoryUsage(pSettings->editor().undoMemoryUsage());
|
2022-03-20 18:10:53 +08:00
|
|
|
|
|
2021-10-20 12:27:44 +08:00
|
|
|
|
setMouseWheelScrollSpeed(pSettings->editor().mouseWheelScrollSpeed());
|
2022-03-04 19:04:45 +08:00
|
|
|
|
setMouseSelectionScrollSpeed(pSettings->editor().mouseSelectionScrollSpeed());
|
2022-01-10 20:16:26 +08:00
|
|
|
|
invalidate();
|
2021-06-07 11:02:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:01:38 +08:00
|
|
|
|
static QSynedit::PHighlighterAttribute createRainbowAttribute(const QString& attrName, const QString& schemeName, const QString& schemeItemName) {
|
2021-09-19 17:59:03 +08:00
|
|
|
|
PColorSchemeItem item = pColorManager->getItem(schemeName,schemeItemName);
|
|
|
|
|
if (item) {
|
2022-11-23 11:41:16 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr = std::make_shared<QSynedit::HighlighterAttribute>(attrName,
|
|
|
|
|
QSynedit::TokenType::Default);
|
2021-09-19 17:59:03 +08:00
|
|
|
|
attr->setForeground(item->foreground());
|
|
|
|
|
attr->setBackground(item->background());
|
|
|
|
|
return attr;
|
|
|
|
|
}
|
2022-09-27 14:01:38 +08:00
|
|
|
|
return QSynedit::PHighlighterAttribute();
|
2021-09-19 17:59:03 +08:00
|
|
|
|
}
|
2021-06-19 22:58:35 +08:00
|
|
|
|
void Editor::applyColorScheme(const QString& schemeName)
|
|
|
|
|
{
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::EditorOptions options = getOptions();
|
2022-12-01 22:10:44 +08:00
|
|
|
|
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor,
|
|
|
|
|
pSettings->editor().rainbowParenthesis()
|
|
|
|
|
&& highlighter() && highlighter()->supportBraceLevel());
|
2021-09-19 17:59:03 +08:00
|
|
|
|
setOptions(options);
|
2021-06-20 22:54:16 +08:00
|
|
|
|
highlighterManager.applyColorScheme(highlighter(),schemeName);
|
2021-09-19 17:59:03 +08:00
|
|
|
|
if (pSettings->editor().rainbowParenthesis()) {
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr0 =createRainbowAttribute(SYNS_AttrSymbol,
|
2021-09-19 17:59:03 +08:00
|
|
|
|
schemeName,COLOR_SCHEME_BRACE_1);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr1 =createRainbowAttribute(SYNS_AttrSymbol,
|
2021-09-19 17:59:03 +08:00
|
|
|
|
schemeName,COLOR_SCHEME_BRACE_2);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr2 =createRainbowAttribute(SYNS_AttrSymbol,
|
2021-09-19 17:59:03 +08:00
|
|
|
|
schemeName,COLOR_SCHEME_BRACE_3);
|
2022-09-27 14:01:38 +08:00
|
|
|
|
QSynedit::PHighlighterAttribute attr3 =createRainbowAttribute(SYNS_AttrSymbol,
|
2021-09-19 17:59:03 +08:00
|
|
|
|
schemeName,COLOR_SCHEME_BRACE_4);
|
|
|
|
|
setRainbowAttrs(attr0,attr1,attr2,attr3);
|
|
|
|
|
}
|
2021-06-19 22:58:35 +08:00
|
|
|
|
PColorSchemeItem item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_LINE);
|
|
|
|
|
if (item) {
|
|
|
|
|
setActiveLineColor(item->background());
|
|
|
|
|
}
|
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_GUTTER);
|
|
|
|
|
if (item) {
|
|
|
|
|
gutter().setTextColor(item->foreground());
|
|
|
|
|
gutter().setColor(item->background());
|
|
|
|
|
}
|
2021-11-03 18:09:12 +08:00
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_GUTTER_ACTIVE_LINE);
|
|
|
|
|
if (item) {
|
|
|
|
|
gutter().setActiveLineTextColor(item->foreground());
|
|
|
|
|
}
|
2021-06-19 22:58:35 +08:00
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_FOLD_LINE);
|
|
|
|
|
if (item) {
|
2021-06-24 22:33:57 +08:00
|
|
|
|
codeFolding().folderBarLinesColor = item->foreground();
|
2021-06-19 22:58:35 +08:00
|
|
|
|
}
|
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_INDENT_GUIDE_LINE);
|
|
|
|
|
if (item) {
|
2021-06-24 22:33:57 +08:00
|
|
|
|
codeFolding().indentGuidesColor = item->foreground();
|
2021-06-19 22:58:35 +08:00
|
|
|
|
}
|
2021-07-26 00:22:08 +08:00
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_ERROR);
|
|
|
|
|
if (item) {
|
|
|
|
|
this->mSyntaxErrorColor = item->foreground();
|
|
|
|
|
}
|
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_WARNING);
|
|
|
|
|
if (item) {
|
|
|
|
|
this->mSyntaxWarningColor = item->foreground();
|
|
|
|
|
}
|
2021-08-28 09:01:40 +08:00
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_SELECTION);
|
|
|
|
|
if (item) {
|
|
|
|
|
setSelectedForeground(item->foreground());
|
|
|
|
|
setSelectedBackground(item->background());
|
2021-11-03 18:09:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
this->setForegroundColor(palette().color(QPalette::HighlightedText));
|
|
|
|
|
this->setBackgroundColor(palette().color(QPalette::Highlight));
|
2021-08-28 09:01:40 +08:00
|
|
|
|
}
|
2021-07-26 00:22:08 +08:00
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_BREAKPOINT);
|
|
|
|
|
if (item) {
|
|
|
|
|
this->mActiveBreakpointForegroundColor = item->foreground();
|
|
|
|
|
this->mActiveBreakpointBackgroundColor = item->background();
|
|
|
|
|
}
|
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_BREAKPOINT);
|
|
|
|
|
if (item) {
|
|
|
|
|
this->mBreakpointForegroundColor = item->foreground();
|
2021-07-27 00:14:24 +08:00
|
|
|
|
this->mBreakpointBackgroundColor = item->background();
|
2021-07-26 00:22:08 +08:00
|
|
|
|
}
|
2021-11-03 18:09:12 +08:00
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_TEXT);
|
|
|
|
|
if (item) {
|
|
|
|
|
this->setForegroundColor(item->foreground());
|
|
|
|
|
this->setBackgroundColor(item->background());
|
|
|
|
|
} else {
|
|
|
|
|
this->setForegroundColor(palette().color(QPalette::Text));
|
|
|
|
|
this->setBackgroundColor(palette().color(QPalette::Base));
|
|
|
|
|
}
|
|
|
|
|
item = pColorManager->getItem(schemeName,COLOR_SCHEME_CURRENT_HIGHLIGHTED_WORD);
|
|
|
|
|
if (item) {
|
|
|
|
|
mCurrentHighlighWordForeground = item->foreground();
|
|
|
|
|
mCurrentHighlighWordBackground = item->background();
|
|
|
|
|
} else {
|
|
|
|
|
mCurrentHighlighWordForeground = selectedForeground();
|
|
|
|
|
mCurrentHighlighWordBackground = selectedBackground();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 22:58:35 +08:00
|
|
|
|
this->invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 12:39:22 +08:00
|
|
|
|
void Editor::updateCaption(const QString& newCaption) {
|
2022-10-26 22:39:40 +08:00
|
|
|
|
if (!mParentPageControl) {
|
2021-04-11 12:39:22 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int index = mParentPageControl->indexOf(this);
|
|
|
|
|
if (index==-1)
|
|
|
|
|
return;
|
|
|
|
|
if (newCaption.isEmpty()) {
|
|
|
|
|
QString caption = QFileInfo(mFilename).fileName();
|
2021-05-24 00:41:00 +08:00
|
|
|
|
if (this->modified()) {
|
2021-04-11 12:39:22 +08:00
|
|
|
|
caption.append("[*]");
|
|
|
|
|
}
|
2021-08-30 13:30:42 +08:00
|
|
|
|
if (this->readOnly()) {
|
|
|
|
|
caption.append("["+tr("Readonly")+"]");
|
|
|
|
|
}
|
2021-04-11 12:39:22 +08:00
|
|
|
|
mParentPageControl->setTabText(index,caption);
|
|
|
|
|
} else {
|
|
|
|
|
mParentPageControl->setTabText(index,newCaption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|