This commit is contained in:
Roy Qu 2024-04-05 09:42:00 +08:00
parent 72481d7de8
commit 4b0772d994
21 changed files with 240 additions and 184 deletions

View File

@ -14,15 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QFile>
#include <QMessageBox>
#include <QProgressDialog>
#include <QTextCodec>
#include <qsynedit/document.h>
#include "cpprefacter.h"
#include "mainwindow.h"
#include "settings.h"
#include "editor.h"
#include "editorlist.h"
#include <QFile>
#include <QMessageBox>
#include <QProgressDialog>
#include <QTextCodec>
#include "syntaxermanager.h"
#include "project.h"
@ -238,7 +239,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
}
editor.setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::CPP));
int posY = 0;
while (posY < editor.document()->count()) {
while (posY < editor.lineCount()) {
QString line = editor.document()->getLine(posY);
if (line.isEmpty()) {
posY++;
@ -299,7 +300,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
oldEditor->clearSelection();
oldEditor->addGroupBreak();
oldEditor->beginEditing();
while (posY < oldEditor->document()->count()) {
while (posY < oldEditor->lineCount()) {
QString line = oldEditor->document()->getLine(posY);
if (posY == 0) {
syntaxer->resetState();
@ -351,7 +352,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
QStringList newContents;
int posY = 0;
while (posY < editor.document()->count()) {
while (posY < editor.lineCount()) {
QString line = editor.document()->getLine(posY);
if (posY == 0) {
editor.syntaxer()->resetState();

View File

@ -1145,7 +1145,7 @@ void GDBMIDebuggerClient::setBreakpointCondition(PBreakpoint breakpoint)
QString("%1").arg(breakpoint->number));
} else {
postCommand("-break-condition",
QString("%1 \"%2\"").arg(breakpoint->number).arg(condition));
QString("%1 %2").arg(breakpoint->number).arg(condition));
}
}

View File

@ -21,22 +21,6 @@
#include <QTextCodec>
#include <QVariant>
#include <QWheelEvent>
#include <memory>
#include "settings.h"
#include "mainwindow.h"
#include "systemconsts.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug>
#include <QMimeData>
#include <QTemporaryFile>
#include "qsynedit/syntaxer/cpp.h"
#include "qsynedit/syntaxer/asm.h"
#include "syntaxermanager.h"
#include "qsynedit/exporter/rtfexporter.h"
#include "qsynedit/exporter/htmlexporter.h"
#include "qsynedit/exporter/qtsupportedhtmlexporter.h"
#include "qsynedit/constants.h"
#include <QGuiApplication>
#include <QClipboard>
#include <QPainter>
@ -49,6 +33,23 @@
#include <QTextCodec>
#include <QScrollBar>
#include <QScreen>
#include <memory>
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug>
#include <QMimeData>
#include <QTemporaryFile>
#include <qsynedit/document.h>
#include <qsynedit/syntaxer/cpp.h>
#include <qsynedit/syntaxer/asm.h>
#include <qsynedit/exporter/rtfexporter.h>
#include <qsynedit/exporter/htmlexporter.h>
#include <qsynedit/exporter/qtsupportedhtmlexporter.h>
#include <qsynedit/constants.h>
#include "settings.h"
#include "mainwindow.h"
#include "systemconsts.h"
#include "syntaxermanager.h"
#include "iconsmanager.h"
#include "debugger/debugger.h"
#include "editorlist.h"
@ -864,12 +865,12 @@ void Editor::keyPressEvent(QKeyEvent *event)
s=trimLeft(lineText());
if (s.startsWith("* ")) {
handled = true;
int right = document()->getLine(caretY()-1).length()-caretX();
int right = lineText(caretY()).length()-caretX();
s=lineBreak()+"* ";
insertString(s,false);
QSynedit::BufferCoord p = caretXY();
p.line++;
p.ch = document()->getLine(p.line-1).length()+1;
p.ch = lineText(p.line).length()+1;
if (right>0) {
p.ch -=right+1;
}
@ -1167,7 +1168,7 @@ void Editor::mouseMoveEvent(QMouseEvent *event)
QSynedit::BufferCoord p;
TipType reason = getTipType(event->pos(),p);
if (reason == TipType::Preprocessor) {
QString s = document()->getLine(p.line - 1);
QString s = lineText(p.line);
if (mParser->isIncludeNextLine(s) || mParser->isIncludeLine(s))
updateHoverLink(p.line);
} else if (reason == TipType::Identifier) {
@ -1269,17 +1270,17 @@ void Editor::onGetEditingAreas(int line, QSynedit::EditingAreaList &areaList)
areaList.append(p);
}
}
QString lineText = document()->getLine(line-1);
if (mParser && mParser->isIncludeLine(lineText)) {
QString s = lineText(line);
if (mParser && mParser->isIncludeLine(s)) {
if (line == mHoverModifiedLine) {
int i=0;
while (i<lineText.length() && lineText[i]!='<' && lineText[i]!='\"')
while (i<s.length() && s[i]!='<' && s[i]!='\"')
i++;
if (i<lineText.length()) {
if (lineText[i]=='<') {
setIncludeUnderline(lineText,i,'>',syntaxer(), foregroundColor(), areaList);
if (i<s.length()) {
if (s[i]=='<') {
setIncludeUnderline(s,i,'>',syntaxer(), foregroundColor(), areaList);
} else {
setIncludeUnderline(lineText,i,'"',syntaxer(), foregroundColor(), areaList);
setIncludeUnderline(s,i,'"',syntaxer(), foregroundColor(), areaList);
}
}
}
@ -1322,11 +1323,11 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
background = syntaxer()->commentAttribute()->background();
return;
}
QString lineText = document()->getLine(line-1);
if (mParser->isIncludeLine(lineText) && attr->tokenType() != QSynedit::TokenType::Comment) {
QString s = lineText(line);
if (mParser->isIncludeLine(s) && attr->tokenType() != QSynedit::TokenType::Comment) {
// #include header names (<>)
int pos1=lineText.indexOf("<")+1;
int pos2=lineText.indexOf(">",pos1);
int pos1=s.indexOf("<")+1;
int pos2=s.indexOf(">",pos1);
if (pos1>0 && pos2>0 && pos1<aChar && aChar<pos2) {
style = syntaxer()->identifierAttribute()->styles();
foreground = syntaxer()->identifierAttribute()->foreground();
@ -1356,8 +1357,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
if ((pEndPos.line>=1)
&& (pEndPos.ch>=0)
&& (pEndPos.ch+1 < document()->getLine(pEndPos.line-1).length())
&& (document()->getLine(pEndPos.line-1)[pEndPos.ch+1] == '(')) {
&& (pEndPos.ch+1 < lineText(pEndPos.line).length())
&& (lineText(pEndPos.line)[pEndPos.ch+1] == '(')) {
kind = StatementKind::Function;
} else {
kind = StatementKind::Variable;
@ -1488,7 +1489,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
QSynedit::BufferCoord p;
if (mParser && pointToCharLine(event->pos(),p)) {
cancelHoverLink();
QString s = document()->getLine(p.line - 1);
QString s = lineText(p.line);
if (mParser->isIncludeNextLine(s)) {
QString filename = mParser->getHeaderFileName(mFilename,s, true);
pMainWindow->openFile(filename);
@ -1748,20 +1749,20 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
int start;
QSynedit::PTokenAttribute attr;
PSyntaxIssueList lst;
if ((line<1) || (line>document()->count()))
if ((line<1) || (line>lineCount()))
return;
pError = std::make_shared<SyntaxIssue>();
p.ch = startChar;
p.line = line;
if (startChar >= document()->getLine(line-1).length()) {
if (startChar >= lineText(line).length()) {
start = 1;
token = document()->getLine(line-1);
token = lineText(line);
} else if (endChar < 1) {
if (!getTokenAttriAtRowColEx(p,token,start,attr))
return;
} else {
start = startChar;
token = document()->getLine(line-1).mid(start-1,endChar-startChar);
token = lineText(line).mid(start-1,endChar-startChar);
}
pError->startChar = start;
pError->endChar = start + token.length();
@ -1855,8 +1856,8 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
{
if ((!changes.testFlag(QSynedit::StatusChange::ReadOnly)
&& !changes.testFlag(QSynedit::StatusChange::InsertMode)
&& (document()->count()!=mLineCount)
&& (document()->count()!=0) && ((mLineCount>0) || (document()->count()>1)))
&& (lineCount()!=mLineCount)
&& (lineCount()!=0) && ((mLineCount>0) || (lineCount()>1)))
||
(mCurrentLineModified
&& !changes.testFlag(QSynedit::StatusChange::ReadOnly)
@ -1874,7 +1875,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
// reparse();
// }
}
mLineCount = document()->count();
mLineCount = lineCount();
if (changes.testFlag(QSynedit::StatusChange::ModifyChanged)) {
updateCaption();
}
@ -2109,7 +2110,7 @@ void Editor::onTooltipTimer()
case TipType::Preprocessor:
// When hovering above a preprocessor line, determine if we want to show an include or a identifier hint
if (mParser) {
s = document()->getLine(p.line - 1);
s = lineText(p.line);
isIncludeNextLine = mParser->isIncludeNextLine(s);
if (!isIncludeNextLine)
isIncludeLine = mParser->isIncludeLine(s);
@ -2146,7 +2147,7 @@ void Editor::onTooltipTimer()
QSynedit::PTokenAttribute attr;
int start;
if (getTokenAttriAtRowColEx(p,s,start,attr)) {
QString line=document()->getLine(p.line-1);
QString line=lineText(p.line);
int idx=start-2;
if (idx>=0 && idx<line.length() && line[idx]=='-')
s='-'+s;
@ -2383,7 +2384,7 @@ QStringList Editor::getExpressionAtPosition(
LastSymbolType lastSymbolType=LastSymbolType::None;
QSynedit::CppSyntaxer syntaxer;
while (true) {
if (line>=document()->count() || line<0)
if (line>=lineCount() || line<0)
break;
QStringList tokens;
if (line==0) {
@ -2612,7 +2613,7 @@ QString Editor::getWordForCompletionSearch(const QSynedit::BufferCoord &pos,bool
QString result = "";
QString s;
s = document()->getLine(pos.line - 1);
s = lineText(pos.line);
int len = s.length();
int wordBegin = pos.ch - 1 - 1; //BufferCoord::Char starts with 1
@ -2797,10 +2798,10 @@ bool Editor::handleParentheseSkip()
if (status != QuoteStatus::NotQuote)
return false;
if (document()->count()==0)
if (lineCount()==0)
return false;
if (syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1);
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(lineCount()-1);
if (lastLineState.parenthesisLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
return true;
@ -2844,10 +2845,10 @@ bool Editor::handleBracketSkip()
if (getCurrentChar() != ']')
return false;
if (document()->count()==0)
if (lineCount()==0)
return false;
if (syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1);
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(lineCount()-1);
if (lastLineState.bracketLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
return true;
@ -2920,10 +2921,10 @@ bool Editor::handleBraceCompletion()
QSynedit::BufferCoord oldSelEnd = blockEnd();
bool shouldBreakLine = false;
bool shouldAddEndLine = false;
QString s1=document()->getLine(oldSelBegin.line-1).left(oldSelBegin.ch-1).trimmed();
QString s1=lineText(oldSelBegin.line).left(oldSelBegin.ch-1).trimmed();
if (s1.isEmpty() ) {
QString s2 = document()->getLine(oldSelEnd.line-1);
QString s2 = lineText(oldSelEnd.line);
if (s2.left(oldSelEnd.ch-1).trimmed().isEmpty()) {
shouldBreakLine = true;
} else if (oldSelEnd.ch > trimRight(s2).length()) {
@ -2957,11 +2958,11 @@ bool Editor::handleBraceSkip()
if (getCurrentChar() != '}')
return false;
if (document()->count()==0)
if (lineCount()==0)
return false;
if (syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1);
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(lineCount()-1);
if (lastLineState.braceLevel==0) {
bool oldInsertMode = insertMode();
setInsertMode(false); //set mode to overwrite
@ -4125,7 +4126,7 @@ Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
// do not allow when dragging selection
if (isPointInSelection(pos))
return TipType::Selection;
} else if (mParser && mParser->isIncludeLine(document()->getLine(pos.line-1))) {
} else if (mParser && mParser->isIncludeLine(lineText(pos.line))) {
return TipType::Preprocessor;
} else if (attr->tokenType() == QSynedit::TokenType::Identifier) {
return TipType::Identifier;
@ -4273,7 +4274,7 @@ void Editor::updateFunctionTip(bool showTip)
int bracketLevel = 0;
int paramsCount = 1;
int currentParamPos = 1;
if (currentLine>=document()->count())
if (currentLine>=lineCount())
return;
QChar ch=lastNonSpaceChar(currentLine,currentChar);
@ -4398,7 +4399,7 @@ void Editor::updateFunctionTip(bool showTip)
QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);
int x = pWordBegin.ch-1-1;
QString line = document()->getLine(pWordBegin.line-1);
QString line = lineText(pWordBegin.line);
bool hasPreviousWord=false;
while (x>=0) {
QChar ch=line[x];
@ -4502,7 +4503,7 @@ void Editor::popUserCodeInTabStops()
tabStopBegin = mTabStopEnd + p->x;
tabStopEnd = mTabStopEnd + p->endX;
} else {
int n=countLeadingWhitespaceChars(document()->getLine(caretY()-1+p->y));
int n=countLeadingWhitespaceChars(lineText(caretY()+p->y));
// qDebug()<<line<<n<<p->x;
tabStopBegin = n+p->x+1;
tabStopEnd = n+p->endX+1;
@ -4547,8 +4548,8 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c
if (kind == StatementKind::Unknown) {
if ((pEndPos.line>=1)
&& (pEndPos.ch>=0)
&& (pEndPos.ch < document()->getLine(pEndPos.line-1).length())
&& (document()->getLine(pEndPos.line-1)[pEndPos.ch] == '(')) {
&& (pEndPos.ch < lineText(pEndPos.line).length())
&& (lineText(pEndPos.line)[pEndPos.ch] == '(')) {
kind = StatementKind::Function;
} else {
kind = StatementKind::Variable;
@ -4783,13 +4784,13 @@ QString getWordAtPosition(QSynedit::QSynEdit *editor, const QSynedit::BufferCoor
{
QString result = "";
QString s;
if ((p.line<1) || (p.line>editor->document()->count())) {
if ((p.line<1) || (p.line>editor->lineCount())) {
pWordBegin = p;
pWordEnd = p;
return "";
}
s = editor->document()->getLine(p.line - 1);
s = editor->lineText(p.line);
int len = s.length();
int wordBegin = p.ch - 1 - 1; //BufferCoord::Char starts with 1
@ -4972,7 +4973,7 @@ QString getWordAtPosition(QSynedit::QSynEdit *editor, const QSynedit::BufferCoor
if (i<0) {
line--;
if (line>=1) {
s=editor->document()->getLine(line-1);
s=editor->lineText(line);
i=s.length();
continue;
} else
@ -5023,12 +5024,12 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
{
hasTypeQualifier = false;
QString result;
if ((p.line<1) || (p.line>document()->count())) {
if ((p.line<1) || (p.line>lineCount())) {
return "";
}
bool inFunc = testInFunc(p);
QString s = document()->getLine(p.line - 1);
QString s = lineText(p.line);
int wordBegin;
int wordEnd = p.ch-2;
if (wordEnd >= s.length())
@ -5092,11 +5093,11 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSynedit::BufferCoord &p)
{
QString result;
if ((p.line<1) || (p.line>document()->count())) {
if ((p.line<1) || (p.line>lineCount())) {
return "";
}
QString s = document()->getLine(p.line - 1);
QString s = lineText(p.line);
int wordBegin;
int wordEnd = p.ch-2;
if (wordEnd >= s.length())
@ -5158,7 +5159,7 @@ void Editor::reformat(bool doReparse)
}
#endif
//we must remove all breakpoints and syntax issues
// onLinesDeleted(1,document()->count());
// onLinesDeleted(1,lineCount());
QByteArray content = text().toUtf8();
QStringList args = pSettings->codeFormatter().getArguments();
//qDebug()<<args;

View File

@ -14,6 +14,38 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QGuiApplication>
#include <QClipboard>
#include <QMessageBox>
#include <QTextCodec>
#include <QCloseEvent>
#include <QComboBox>
#include <QDesktopServices>
#include <QDragEnterEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QMimeData>
#include <QScreen>
#include <QStyleFactory>
#include <QTcpSocket>
#include <QTemporaryFile>
#include <QTextBlock>
#include <QTranslator>
#include <QFileIconProvider>
#include <QMimeDatabase>
#include <QMimeType>
#include <QToolTip>
#include <QCompleter>
#include <QUuid>
#include <QScrollBar>
#include <QTextDocumentFragment>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "editorlist.h"
@ -62,42 +94,10 @@
#include "widgets/projectalreadyopendialog.h"
#include "widgets/searchdialog.h"
#include <QCloseEvent>
#include <QComboBox>
#include <QDesktopServices>
#include <QDragEnterEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QMimeData>
#include <QScreen>
#include <QStyleFactory>
#include <QTcpSocket>
#include <QTemporaryFile>
#include <QTextBlock>
#include <QTranslator>
#include <QFileIconProvider>
#include <QMimeDatabase>
#include <QMimeType>
#include <QToolTip>
#include <QCompleter>
#include <QUuid>
#include "mainwindow.h"
#include <QScrollBar>
#include <QTextDocumentFragment>
#include "settingsdialog/settingsdialog.h"
#include "compiler/compilermanager.h"
#include <QGuiApplication>
#include <QClipboard>
#include <QMessageBox>
#include <QTextCodec>
#include <qsynedit/document.h>
#include "cpprefacter.h"
#include "widgets/newprojectunitdialog.h"
@ -689,7 +689,7 @@ void MainWindow::updateEditorActions(const Editor *e)
} else {
ui->actionCopy->setEnabled(true);
ui->actionCut->setEnabled(true);
ui->actionFoldAll->setEnabled(e->document()->count()>0);
ui->actionFoldAll->setEnabled(e->lineCount()>0);
ui->actionIndent->setEnabled(!e->readOnly());
ui->actionPaste->setEnabled(!e->readOnly());
ui->actionRedo->setEnabled(e->canRedo());
@ -699,17 +699,17 @@ void MainWindow::updateEditorActions(const Editor *e)
ui->actionExport_As_HTML->setEnabled(true);
ui->actionExport_As_RTF->setEnabled(true);
ui->actionPrint->setEnabled(true);
ui->actionToggleComment->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionToggleComment->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionToggle_Block_Comment->setEnabled(!e->readOnly() && e->selAvail());
ui->actionUnIndent->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionUnfoldAll->setEnabled(e->document()->count()>0);
ui->actionDelete_Line->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionDelete_Word->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionDuplicate_Line->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionDelete_to_BOL->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionDelete_to_EOL->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionDelete_to_Word_End->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionDelete_Last_Word->setEnabled(!e->readOnly() && e->document()->count()>0);
ui->actionUnIndent->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionUnfoldAll->setEnabled(e->lineCount()>0);
ui->actionDelete_Line->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionDelete_Word->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionDuplicate_Line->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionDelete_to_BOL->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionDelete_to_EOL->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionDelete_to_Word_End->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->actionDelete_Last_Word->setEnabled(!e->readOnly() && e->lineCount()>0);
ui->menuMove_Caret->setEnabled(true);
ui->actionPage_Up->setEnabled(true);
@ -721,7 +721,7 @@ void MainWindow::updateEditorActions(const Editor *e)
ui->actionGoto_Page_Start->setEnabled(true);
ui->actionGoto_Page_End->setEnabled(true);
ui->actionSelectAll->setEnabled(e->document()->count()>0);
ui->actionSelectAll->setEnabled(e->lineCount()>0);
ui->actionSelect_Word->setEnabled(true);
ui->actionMove_Selection_Up->setEnabled(true);
ui->actionMove_Selection_Down->setEnabled(true);
@ -747,7 +747,7 @@ void MainWindow::updateEditorActions(const Editor *e)
ui->actionClose_Others->setEnabled(mEditorList->pageCount()>1);
int line = e->caretY();
ui->actionAdd_bookmark->setEnabled(e->document()->count()>0 && !e->hasBookmark(line));
ui->actionAdd_bookmark->setEnabled(e->lineCount()>0 && !e->hasBookmark(line));
ui->actionRemove_Bookmark->setEnabled(e->hasBookmark(line));
ui->actionModify_Bookmark_Description->setEnabled(e->hasBookmark(line));
@ -1598,27 +1598,27 @@ void MainWindow::updateStatusbarForLineCol(const Editor* e, bool clear)
if (e->selAvail()) {
msg = tr("Line: %1/%2 Col: %3 Sel: %4")
.arg(e->caretY())
.arg(e->document()->count())
.arg(e->lineCount())
.arg(col)
.arg(e->selCount());
} else {
msg = tr("Line: %1/%2 Col: %3")
.arg(e->caretY())
.arg(e->document()->count())
.arg(e->lineCount())
.arg(col);
}
} else {
if (e->selAvail()) {
msg = tr("Line: %1/%2 Char: %3/%4 Sel: %5")
.arg(e->caretY())
.arg(e->document()->count())
.arg(e->lineCount())
.arg(e->caretX())
.arg(e->lineText().length())
.arg(e->selCount());
} else {
msg = tr("Line: %1/%2 Char: %3/%4")
.arg(e->caretY())
.arg(e->document()->count())
.arg(e->lineCount())
.arg(e->caretX())
.arg(e->lineText().length());
}
@ -5215,7 +5215,7 @@ void MainWindow::onEditorContextMenu(const QPoint& pos)
ui->actionLocate_in_Files_View->setEnabled(!editor->isNew());
ui->actionBreakpoint_property->setEnabled(editor->hasBreakpoint(line));
ui->actionAdd_bookmark->setEnabled(
line>=0 && editor->document()->count()>0
line>=0 && editor->lineCount()>0
&& !editor->hasBookmark(line)
);
ui->actionRemove_Bookmark->setEnabled(editor->hasBookmark(line));
@ -5949,11 +5949,11 @@ void MainWindow::onCompileIssue(PCompileIssue issue)
Editor* e = mEditorList->getOpenedEditorByFilename(issue->filename);
if (e!=nullptr && (issue->line>0)) {
int line = issue->line;
if (line > e->document()->count())
if (line > e->lineCount())
return;
int col = std::min(issue->column,e->document()->getLine(line-1).length()+1);
int col = std::min(issue->column,e->lineText(line).length()+1);
if (col < 1)
col = e->document()->getLine(line-1).length()+1;
col = e->lineText(line).length()+1;
e->addSyntaxIssues(line,col,issue->endColumn,issue->type,issue->description);
}
}
@ -6075,8 +6075,8 @@ void MainWindow::onCompileFinished(QString filename, bool isCheckSyntax)
int line = e->caretY();
int startLine = 1;
QString s = "# "+e->filename()+":";
for(int i=0;i<editor->document()->count();i++) {
QString t=editor->document()->getLine(i).trimmed();
for(int i=1;i<=editor->lineCount();i++) {
QString t=editor->lineText(i).trimmed();
if (t.startsWith(s,PATH_SENSITIVITY)) {
t=t.mid(s.length());
int pos = t.indexOf(":");
@ -6086,7 +6086,7 @@ void MainWindow::onCompileFinished(QString filename, bool isCheckSyntax)
int l=numstring.toInt(&isOk);
if (isOk) {
if (l<=line)
startLine=i+1;
startLine=i;
if (l>=line)
break;
}
@ -8380,7 +8380,7 @@ void MainWindow::on_btnReplace_clicked()
while (!selections.isEmpty()) {
const PSearchResultTreeItem& item = selections.back();
selections.pop_back();
QString line = editor->document()->getLine(item->line-1);
QString line = editor->lineText(item->line);
if (line.mid(item->start-1,results->keyword.length())!=results->keyword) {
QMessageBox::critical(editor,
tr("Replace Error"),
@ -8534,11 +8534,11 @@ void MainWindow::on_actionAdd_bookmark_triggered()
Editor* editor = mEditorList->getEditor();
int line;
if (editor && editor->pointToLine(mEditorContextMenuPos,line)) {
if (editor->document()->count()<=0)
if (editor->lineCount()<=0)
return;
QString desc = QInputDialog::getText(editor,tr("Bookmark Description"),
tr("Description:"),QLineEdit::Normal,
editor->document()->getLine(line-1).trimmed());
editor->lineText(line).trimmed());
desc = desc.trimmed();
editor->addBookmark(line);
mBookmarkModel->addBookmark(editor->filename(),line,desc,editor->inProject());
@ -9836,7 +9836,7 @@ void MainWindow::on_actionGo_to_Line_triggered()
return;
bool ok;
int lineNo=QInputDialog::getInt(e,tr("Go to Line"),tr("Line"),
e->caretY(),1,e->document()->count(),
e->caretY(),1,e->lineCount(),
1,&ok);
if (ok && lineNo!=e->caretY()) {
e->setCaretPosition(lineNo,1);

View File

@ -25,6 +25,7 @@
#include <QDebug>
#include <QInputDialog>
#include <QFileDialog>
#include <qsynedit/document.h>
EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) :
SettingsWidget(name,group,parent),

View File

@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <qsynedit/document.h>
#include "editorsnippetwidget.h"
#include "ui_editorsnippetwidget.h"
#include "../mainwindow.h"

View File

@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <qsynedit/document.h>
#include "formattergeneralwidget.h"
#include "ui_formattergeneralwidget.h"
#include "../settings.h"

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QDesktopWidget>
#include <qsynedit/document.h>
#include "cpudialog.h"
#include "ui_cpudialog.h"
#include "../syntaxermanager.h"

View File

@ -46,7 +46,7 @@ void FilePropertiesDialog::calcFile(Editor *editor,
int &includeLines,
int &charCounts)
{
totalLines = editor->document()->count();
totalLines = editor->lineCount();
codeLines = 0;
commentLines = 0;
emptyLines = 0;
@ -54,14 +54,14 @@ void FilePropertiesDialog::calcFile(Editor *editor,
charCounts = 0;
int lineBreakerLen = QString(LINE_BREAKER).length();
// iterate through all lines of file
for (int i=0;i<editor->document()->count();i++) {
QString line = editor->document()->getLine(i);
for (int i=1;i<=editor->lineCount();i++) {
QString line = editor->lineText(i);
charCounts+=line.length()+lineBreakerLen;
// while (j<line.length() && (line[j]=='\t' || line[j]==' '))
// j++;
QString token;
QSynedit::PTokenAttribute attr;
if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{1,i+1},
if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{1,i},
token,attr)) {
// if it is preprocessor...
if (attr->name() == SYNS_AttrPreprocessor) {
@ -136,7 +136,7 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index)
ui->txtProject->setText("-");
ui->txtPath->setText(editor->filename());
ui->txtRelativeToProject->setText("_");
ui->txtLines->setText(QString("%1").arg(editor->document()->count()));
ui->txtLines->setText(QString("%1").arg(editor->lineCount()));
int totalLines, codeLines,emptyLines,commentLines,includeLines, charCounts;
calcFile(editor,totalLines,commentLines,emptyLines,codeLines,includeLines,charCounts);

View File

@ -17,21 +17,21 @@
#include "searchinfiledialog.h"
#include "ui_searchinfiledialog.h"
#include <QTabBar>
#include "../editor.h"
#include "../mainwindow.h"
#include "../editorlist.h"
#include <qsynedit/searcher/basicsearcher.h>
#include <qsynedit/searcher/regexsearcher.h>
#include "../project.h"
#include "../settings.h"
#include "../systemconsts.h"
#include <QMessageBox>
#include <QDebug>
#include <QProgressDialog>
#include <QCompleter>
#include <QStack>
#include <QFileDialog>
#include <qsynedit/document.h>
#include <qsynedit/searcher/basicsearcher.h>
#include <qsynedit/searcher/regexsearcher.h>
#include "../editor.h"
#include "../mainwindow.h"
#include "../editorlist.h"
#include "../project.h"
#include "../settings.h"
#include "../systemconsts.h"
SearchInFileDialog::SearchInFileDialog(QWidget *parent) :
QDialog(parent),
@ -378,14 +378,14 @@ std::shared_ptr<SearchResultTreeItem> SearchInFileDialog::batchFindInEditor(QSyn
parentItem->parent = nullptr;
execute(e,keyword,"",
[e,&parentItem, filename](const QString&,
const QString&, int Line, int ch, int wordLen){
const QString&, int line, int ch, int wordLen){
PSearchResultTreeItem item = std::make_shared<SearchResultTreeItem>();
item->filename = filename;
item->line = Line;
item->line = line;
item->start = ch;
item->len = wordLen;
item->parent = parentItem.get();
item->text = e->document()->getLine(Line-1);
item->text = e->lineText(line);
item->text.replace('\t',' ');
parentItem->results.append(item);
return QSynedit::SearchAction::Skip;

View File

@ -22,7 +22,6 @@
#include <QTextStream>
#include <QMutexLocker>
#include <stdexcept>
#include "qsynedit.h"
#include <QMessageBox>
#include <cmath>
#include "qt_utils/charsetinfo.h"

View File

@ -18,7 +18,6 @@
#define SYNEDITSTRINGLIST_H
#include <QStringList>
#include "syntaxer/syntaxer.h"
#include <QFontMetrics>
#include <QMutex>
#include <QVector>

View File

@ -15,11 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "exporter.h"
#include "../document.h"
#include <QClipboard>
#include <QFile>
#include <QGuiApplication>
#include <QMimeData>
#include <QPalette>
#include <QTextCodec>
namespace QSynedit {

View File

@ -18,9 +18,24 @@
#define EXPORTER_H
#include <QString>
#include "../qsynedit.h"
#include <memory>
#include <functional>
#include <QIODevice>
#include <QFont>
#include <QColor>
#include <QMap>
#include "qt_utils/utils.h"
#include "../types.h"
namespace QSynedit {
class Document;
using PDocument = std::shared_ptr<Document>;
class Syntaxer;
using PSyntaxer = std::shared_ptr<Syntaxer>;
class TokenAttribute;
using PTokenAttribute = std::shared_ptr<TokenAttribute>;
using FormatTokenHandler = std::function<void(PSyntaxer syntaxHighlighter, int line, int column, const QString& token,
PTokenAttribute& attr)>;
class Exporter

View File

@ -15,6 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "rtfexporter.h"
#include <QFontMetrics>
namespace QSynedit {
RTFExporter::RTFExporter(int tabSize, const QByteArray charset):Exporter(tabSize,charset)

View File

@ -1,5 +1,6 @@
#include "cppformatter.h"
#include "../qsynedit.h"
#include "../document.h"
#include "../syntaxer/cpp.h"
#include <QDebug>
@ -18,14 +19,14 @@ namespace QSynedit {
QSynEdit *editor)
{
Q_ASSERT(editor!=nullptr);
line = std::min(line, editor->document()->count()+1);
line = std::min(line, editor->lineCount()+1);
if (line<=1)
return 0;
// find the first non-empty preceeding line
int startLine = line-1;
QString startLineText;
while (startLine>=1) {
startLineText = editor->document()->getLine(startLine-1);
startLineText = editor->lineText(startLine);
if (!startLineText.startsWith('#') && !startLineText.trimmed().isEmpty()) {
break;
}
@ -87,31 +88,31 @@ namespace QSynedit {
// the line the comment beginning , and add 1 additional space
int commentStartLine = findCommentStartLine(startLine-1,editor);
SyntaxState range;
indentSpaces = editor->leftSpaces(editor->document()->getLine(commentStartLine-1))+1;
indentSpaces = editor->leftSpaces(editor->lineText(commentStartLine))+1;
range = editor->document()->getSyntaxState(commentStartLine-1);
} else {
//indents according to the beginning of the comment and 2 additional space
int commentStartLine = findCommentStartLine(startLine-1,editor);
SyntaxState range;
indentSpaces = editor->leftSpaces(editor->document()->getLine(commentStartLine-1))+2;
indentSpaces = editor->leftSpaces(editor->lineText(commentStartLine))+2;
range = editor->document()->getSyntaxState(commentStartLine-1);
}
} else if (rangeAfterFirstToken.lastUnindent.type!=IndentType::None
&& firstToken=="}") {
IndentInfo matchingIndents = rangeAfterFirstToken.lastUnindent;
indentSpaces = editor->leftSpaces(editor->document()->getLine(matchingIndents.line));
indentSpaces = editor->leftSpaces(editor->lineText(matchingIndents.line+1));
} else if (firstToken=="{") {
IndentInfo matchingIndents = rangeAfterFirstToken.getLastIndent();
if (matchingIndents.line!=line-1) {
indentSpaces = editor->leftSpaces(editor->document()->getLine(matchingIndents.line));
indentSpaces = editor->leftSpaces(editor->lineText(matchingIndents.line+1));
} else if (rangeAfterFirstToken.indents.count()>=2){
IndentInfo info = rangeAfterFirstToken.indents[rangeAfterFirstToken.indents.count()-2];
indentSpaces = editor->leftSpaces(editor->document()->getLine(info.line))+editor->tabSize();
indentSpaces = editor->leftSpaces(editor->lineText(info.line+1))+editor->tabSize();
} else
indentSpaces = 0;
} else if (rangePreceeding.getLastIndentType()!=IndentType::None) {
IndentInfo matchingIndents = rangePreceeding.getLastIndent();
indentSpaces = editor->leftSpaces(editor->document()->getLine(matchingIndents.line))+editor->tabSize();
indentSpaces = editor->leftSpaces(editor->lineText(matchingIndents.line+1))+editor->tabSize();
} else {
indentSpaces = 0;
}

View File

@ -16,7 +16,9 @@
*/
#include "painter.h"
#include "qsynedit.h"
#include "document.h"
#include "constants.h"
#include "syntaxer/syntaxer.h"
#include <cmath>
#include <QDebug>
@ -847,7 +849,7 @@ void QSynEditPainter::paintFoldAttributes()
lastNonBlank = vLine - 1;
while (lastNonBlank + 1 < mEdit->mDocument->count() && mEdit->mDocument->getLine(lastNonBlank).isEmpty())
lastNonBlank++;
if (lastNonBlank>=mEdit->document()->count())
if (lastNonBlank>=mEdit->lineCount())
continue;
lineIndent = mEdit->getLineIndent(mEdit->mDocument->getLine(lastNonBlank));
int braceLevel = mEdit->mDocument->getSyntaxState(lastNonBlank).braceLevel;
@ -1158,9 +1160,7 @@ void QSynEditPainter::paintLines()
tokenLeft+=tokenWidth;
//We don't need to calculate line width,
//So we just quit if already out of the right edge of the editor
if (
(!calculateGlyphPositions || lineTextChanged)
&& (tokenLeft>mRight))
if (lineWidthValid && (tokenLeft>mRight))
break;
// Let the highlighter scan the next token.
mEdit->mSyntaxer->next();

View File

@ -21,8 +21,6 @@
#include <QPainter>
#include <QString>
#include "types.h"
#include "syntaxer/syntaxer.h"
#include "gutter.h"
namespace QSynedit {
struct TokenTextInfo {
@ -39,6 +37,10 @@ struct TokenBackgroundInfo {
};
class Syntaxer;
using PSyntaxer = std::shared_ptr<Syntaxer>;
class TokenAttribute;
using PTokenAttribute = std::shared_ptr<TokenAttribute>;
class QSynEdit;
class QSynEditPainter
{

View File

@ -15,7 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "qsynedit.h"
#include "syntaxer/cpp.h"
#include "document.h"
#include "syntaxer/syntaxer.h""
#include <QApplication>
#include <QFontMetrics>
#include <algorithm>
@ -173,6 +174,11 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
setScrollBars(ScrollStyle::Both);
}
int QSynEdit::lineCount() const
{
return mDocument->count();
}
int QSynEdit::displayLineCount() const
{
if (mDocument->empty()) {
@ -4019,12 +4025,16 @@ void QSynEdit::setTabSize(int newTabSize)
}
}
int QSynEdit::tabWidth() const
{
return mDocument->tabWidth();
}
EditorOptions QSynEdit::getOptions() const
{
return mOptions;
}
static bool sameEditorOption(const EditorOptions& value1, const EditorOptions& value2, EditorOption flag) {
return value1.testFlag(flag)==value2.testFlag(flag);
}
@ -4061,6 +4071,11 @@ void QSynEdit::setOptions(const EditorOptions &value)
}
}
int QSynEdit::tabSize() const
{
return mDocument->tabSize();
}
void QSynEdit::doAddStr(const QString &s)
{
if (mInserting == false && !selAvail()) {
@ -4656,6 +4671,11 @@ QString QSynEdit::lineText() const
return QString();
}
QString QSynEdit::lineText(int line) const
{
return mDocument->getLine(line-1);
}
void QSynEdit::setLineText(const QString s)
{
if (mCaretY >= 1 && mCaretY <= mDocument->count())
@ -4890,7 +4910,7 @@ void QSynEdit::moveCaretToLineEnd(bool isSelection, bool ensureCaretVisible)
void QSynEdit::doGotoBlockStart(bool isSelection)
{
if (mCaretY<0 || mCaretY>document()->count())
if (mCaretY<0 || mCaretY>lineCount())
return;
SyntaxState state = document()->getSyntaxState(mCaretY-1);
//todo: handle block other than {}
@ -4913,7 +4933,7 @@ void QSynEdit::doGotoBlockStart(bool isSelection)
void QSynEdit::doGotoBlockEnd(bool isSelection)
{
if (mCaretY<0 || mCaretY>document()->count())
if (mCaretY<0 || mCaretY>lineCount())
return;
SyntaxState state = document()->getSyntaxState(mCaretY-1);
//todo: handle block other than {}
@ -4921,7 +4941,7 @@ void QSynEdit::doGotoBlockEnd(bool isSelection)
doGotoEditorEnd(isSelection);
} else if (document()->blockEnded(mCaretY-1)==0){
int line=mCaretY+1;
while (line<=document()->count()) {
while (line<=lineCount()) {
if (document()->blockEnded(line-1)>document()->blockStarted(line-1)) {
moveCaretVert(line-1-mCaretY, isSelection);
moveCaretToLineStart(isSelection);

View File

@ -27,7 +27,6 @@
#include "gutter.h"
#include "codefolding.h"
#include "types.h"
#include "document.h"
#include "keystrokes.h"
#include "searcher/baseseacher.h"
#include "formatter/formatter.h"
@ -85,11 +84,11 @@ enum class EditorOption {
AutoHideScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead)
KeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor
RightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location
// eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less
// ScrollByOneLess = 0x00001000, //Forces scrolling to be one less
ScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker
ScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line
InvertMouseScroll = 0x00008000, //Shows the special Characters
// eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event
// SpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event
TabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected
TabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters
ShowRainbowColor = 0x00080000,
@ -135,6 +134,18 @@ struct GlyphPostionsListCache {
class QSynEdit;
using PSynEdit = std::shared_ptr<QSynEdit>;
class TokenAttribute;
using PTokenAttribute = std::shared_ptr<TokenAttribute>;
class Document;
using PDocument = std::shared_ptr<Document>;
class SyntaxState;
class Syntaxer;
using PSyntaxer = std::shared_ptr<Syntaxer>;
class UndoList;
class RedoList;
using PUndoList = std::shared_ptr<UndoList>;
using PRedoList = std::shared_ptr<RedoList>;
class QSynEdit : public QAbstractScrollArea
{
Q_OBJECT
@ -143,6 +154,8 @@ public:
QSynEdit(const QSynEdit&)=delete;
QSynEdit& operator=(const QSynEdit&)=delete;
int lineCount() const;
/**
* Returns how many rows are there in the editor
* @return
@ -361,9 +374,7 @@ public:
QString displayLineText();
QString lineText() const;
QString lineText(int line) const {
return mDocument->getLine(line-1);
}
QString lineText(int line) const;
void setLineText(const QString s);
const PDocument& document() const;
@ -380,9 +391,9 @@ public:
EditorOptions getOptions() const;
void setOptions(const EditorOptions &Value);
int tabSize() const { return mDocument->tabSize(); }
int tabSize() const;
void setTabSize(int tabSize);
int tabWidth() const { return mDocument->tabWidth(); }
int tabWidth() const;
QColor caretColor() const;
void setCaretColor(const QColor &caretColor);

View File

@ -114,7 +114,7 @@ private:
TokenType mTokenType;
};
typedef std::shared_ptr<TokenAttribute> PTokenAttribute;
using PTokenAttribute = std::shared_ptr<TokenAttribute> ;
class Syntaxer {
public: