2021-05-14 23:56:43 +08:00
|
|
|
#include "TextBuffer.h"
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTextStream>
|
2021-10-17 21:09:50 +08:00
|
|
|
#include <QMutexLocker>
|
2021-05-14 23:56:43 +08:00
|
|
|
#include <stdexcept>
|
2021-05-18 15:49:58 +08:00
|
|
|
#include "SynEdit.h"
|
2021-05-14 23:56:43 +08:00
|
|
|
#include "../utils.h"
|
2021-09-03 20:55:14 +08:00
|
|
|
#include "../platform.h"
|
2021-09-26 22:39:26 +08:00
|
|
|
#include <QMessageBox>
|
2021-05-14 23:56:43 +08:00
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
SynEditStringList::SynEditStringList(SynEdit *pEdit, QObject *parent):
|
|
|
|
QObject(parent),
|
|
|
|
mEdit(pEdit)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
mAppendNewLineAtEOF = true;
|
|
|
|
mFileEndingType = FileEndingType::Windows;
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
mUpdateCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ListIndexOutOfBounds(int index) {
|
|
|
|
throw IndexOutOfRange(index);
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int SynEditStringList::parenthesisLevels(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
2021-09-23 12:06:26 +08:00
|
|
|
return mList[Index]->fRange.parenthesisLevel;
|
2021-05-14 23:56:43 +08:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int SynEditStringList::bracketLevels(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
2021-09-23 12:06:26 +08:00
|
|
|
return mList[Index]->fRange.bracketLevel;
|
2021-05-14 23:56:43 +08:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int SynEditStringList::braceLevels(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
2021-09-23 12:06:26 +08:00
|
|
|
return mList[Index]->fRange.braceLevel;
|
2021-05-14 23:56:43 +08:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
//QString SynEditStringList::expandedStrings(int Index)
|
|
|
|
//{
|
|
|
|
// if (Index>=0 && Index < mList.size()) {
|
|
|
|
// if (mList[Index]->fFlags & SynEditStringFlag::sfHasNoTabs)
|
|
|
|
// return mList[Index]->fString;
|
|
|
|
// else
|
|
|
|
// return ExpandString(Index);
|
|
|
|
// } else
|
|
|
|
// return QString();
|
|
|
|
//}
|
2021-05-14 23:56:43 +08:00
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
int SynEditStringList::lineColumns(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
2021-05-18 15:49:58 +08:00
|
|
|
if (mList[Index]->fColumns == -1) {
|
|
|
|
return calculateLineColumns(Index);
|
|
|
|
} else
|
|
|
|
return mList[Index]->fColumns;
|
2021-05-14 23:56:43 +08:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int SynEditStringList::leftBraces(int Index)
|
2021-09-23 12:06:26 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-09-23 12:06:26 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
2021-09-23 14:46:42 +08:00
|
|
|
return mList[Index]->fLeftBraces;
|
2021-09-23 12:06:26 +08:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int SynEditStringList::rightBraces(int Index)
|
2021-09-23 12:06:26 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-09-23 12:06:26 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
2021-09-23 14:46:42 +08:00
|
|
|
return mList[Index]->fRightBraces;
|
2021-09-23 12:06:26 +08:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-07 07:52:20 +08:00
|
|
|
int SynEditStringList::lengthOfLongestLine() {
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (mIndexOfLongestLine < 0) {
|
|
|
|
int MaxLen = -1;
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
if (mList.count() > 0 ) {
|
|
|
|
for (int i=0;i<mList.size();i++) {
|
2021-05-18 15:49:58 +08:00
|
|
|
int len = lineColumns(i);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (len > MaxLen) {
|
|
|
|
MaxLen = len;
|
|
|
|
mIndexOfLongestLine = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mIndexOfLongestLine >= 0)
|
2021-05-18 15:49:58 +08:00
|
|
|
return mList[mIndexOfLongestLine]->fColumns;
|
2021-05-14 23:56:43 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-07 07:52:20 +08:00
|
|
|
QString SynEditStringList::lineBreak() const
|
2021-05-29 21:35:46 +08:00
|
|
|
{
|
|
|
|
switch(mFileEndingType) {
|
|
|
|
case FileEndingType::Linux:
|
|
|
|
return "\n";
|
|
|
|
case FileEndingType::Windows:
|
|
|
|
return "\r\n";
|
|
|
|
case FileEndingType::Mac:
|
|
|
|
return "\r";
|
|
|
|
}
|
2021-08-16 23:17:48 +08:00
|
|
|
return "\n";
|
2021-05-29 21:35:46 +08:00
|
|
|
}
|
|
|
|
|
2021-10-24 13:03:54 +08:00
|
|
|
SynRangeState SynEditStringList::ranges(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index>=0 && Index < mList.size()) {
|
|
|
|
return mList[Index]->fRange;
|
2021-09-23 12:06:26 +08:00
|
|
|
} else {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
return {0};
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::insertItem(int Index, const QString &s)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
beginUpdate();
|
|
|
|
PSynEditStringRec line = std::make_shared<SynEditStringRec>();
|
|
|
|
line->fString = s;
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
mList.insert(Index,line);
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
2021-05-24 00:41:00 +08:00
|
|
|
void SynEditStringList::addItem(const QString &s)
|
|
|
|
{
|
|
|
|
beginUpdate();
|
|
|
|
PSynEditStringRec line = std::make_shared<SynEditStringRec>();
|
|
|
|
line->fString = s;
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
mList.append(line);
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
bool SynEditStringList::getAppendNewLineAtEOF()
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
return mAppendNewLineAtEOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
mAppendNewLineAtEOF = appendNewLineAtEOF;
|
|
|
|
}
|
|
|
|
|
2021-09-23 14:46:42 +08:00
|
|
|
void SynEditStringList::setRange(int Index, const SynRangeState& ARange, int ALeftBraces, int ARightBraces)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index<0 || Index>=mList.count()) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
|
|
|
mList[Index]->fRange = ARange;
|
2021-09-23 14:46:42 +08:00
|
|
|
mList[Index]->fLeftBraces = ALeftBraces;
|
|
|
|
mList[Index]->fRightBraces = ARightBraces;
|
2021-05-14 23:56:43 +08:00
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
QString SynEditStringList::getString(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index<0 || Index>=mList.count()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
return mList[Index]->fString;
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int SynEditStringList::count()
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
return mList.count();
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void *SynEditStringList::getObject(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index<0 || Index>=mList.count()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mList[Index]->fObject;
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
QString SynEditStringList::text()
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-08-08 17:22:37 +08:00
|
|
|
return getTextStr();
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::setText(const QString &text)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
|
|
|
putTextStr(text);
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
2021-09-03 16:39:20 +08:00
|
|
|
void SynEditStringList::setContents(const QStringList &text)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-09-03 16:39:20 +08:00
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
2021-10-17 21:09:50 +08:00
|
|
|
internalClear();
|
2021-09-03 16:39:20 +08:00
|
|
|
if (text.count() > 0) {
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
int FirstAdded = mList.count();
|
|
|
|
|
|
|
|
foreach (const QString& s,text) {
|
|
|
|
addItem(s);
|
|
|
|
}
|
|
|
|
emit inserted(FirstAdded,text.count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
QStringList SynEditStringList::contents()
|
2021-08-23 10:16:06 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-08-23 10:16:06 +08:00
|
|
|
QStringList Result;
|
2021-10-05 21:25:23 +08:00
|
|
|
SynEditStringRecList list = mList;
|
|
|
|
foreach (const PSynEditStringRec& line, list) {
|
2021-08-23 10:16:06 +08:00
|
|
|
Result.append(line->fString);
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2021-05-14 23:56:43 +08:00
|
|
|
void SynEditStringList::beginUpdate()
|
|
|
|
{
|
|
|
|
if (mUpdateCount == 0) {
|
2021-10-17 21:09:50 +08:00
|
|
|
setUpdateState(true);
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
mUpdateCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::endUpdate()
|
|
|
|
{
|
|
|
|
mUpdateCount--;
|
|
|
|
if (mUpdateCount == 0) {
|
2021-10-17 21:09:50 +08:00
|
|
|
setUpdateState(false);
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SynEditStringList::add(const QString &s)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
beginUpdate();
|
|
|
|
int Result = mList.count();
|
2021-10-17 21:09:50 +08:00
|
|
|
insertItem(Result, s);
|
2021-05-14 23:56:43 +08:00
|
|
|
emit inserted(Result,1);
|
|
|
|
endUpdate();
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2021-06-21 22:01:35 +08:00
|
|
|
void SynEditStringList::addStrings(const QStringList &Strings)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Strings.count() > 0) {
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
|
|
|
int FirstAdded = mList.count();
|
|
|
|
|
|
|
|
for (const QString& s:Strings) {
|
2021-05-24 00:41:00 +08:00
|
|
|
addItem(s);
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
emit inserted(FirstAdded,Strings.count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynEditStringList::getTextLength()
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
int Result = 0;
|
2021-08-29 10:14:07 +08:00
|
|
|
foreach (const PSynEditStringRec& line, mList ) {
|
2021-05-14 23:56:43 +08:00
|
|
|
Result += line->fString.length();
|
|
|
|
if (mFileEndingType == FileEndingType::Windows) {
|
|
|
|
Result += 2;
|
|
|
|
} else {
|
|
|
|
Result += 1;
|
|
|
|
}
|
|
|
|
}
|
2021-06-12 22:36:23 +08:00
|
|
|
return Result;
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::clear()
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
|
|
|
internalClear();
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::deleteLines(int Index, int NumLines)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (NumLines<=0)
|
|
|
|
return;
|
|
|
|
if ((Index < 0) || (Index >= mList.count())) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
|
|
|
if (mIndexOfLongestLine>=Index && (mIndexOfLongestLine <Index+NumLines)) {
|
|
|
|
mIndexOfLongestLine = - 1;
|
|
|
|
}
|
|
|
|
int LinesAfter = mList.count() - (Index + NumLines);
|
|
|
|
if (LinesAfter < 0) {
|
|
|
|
NumLines = mList.count() - Index;
|
|
|
|
}
|
|
|
|
mList.remove(Index,NumLines);
|
|
|
|
emit deleted(Index,NumLines);
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::exchange(int Index1, int Index2)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if ((Index1 < 0) || (Index1 >= mList.count())) {
|
|
|
|
ListIndexOutOfBounds(Index1);
|
|
|
|
}
|
|
|
|
if ((Index2 < 0) || (Index2 >= mList.count())) {
|
|
|
|
ListIndexOutOfBounds(Index2);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
|
|
|
mList.swapItemsAt(Index1,Index2);
|
|
|
|
if (mIndexOfLongestLine == Index1) {
|
|
|
|
mIndexOfLongestLine = Index2;
|
|
|
|
} else if (mIndexOfLongestLine == Index2) {
|
|
|
|
mIndexOfLongestLine = Index1;
|
|
|
|
}
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::insert(int Index, const QString &s)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if ((Index < 0) || (Index > mList.count())) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
2021-10-17 21:09:50 +08:00
|
|
|
insertItem(Index, s);
|
2021-05-14 23:56:43 +08:00
|
|
|
emit inserted(Index,1);
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::deleteAt(int Index)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if ((Index < 0) || (Index >= mList.count())) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
|
|
|
if (mIndexOfLongestLine == Index)
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
mList.removeAt(Index);
|
|
|
|
emit deleted(Index,1);
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
2021-10-07 07:52:20 +08:00
|
|
|
QString SynEditStringList::getTextStr() const
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-09-02 12:14:02 +08:00
|
|
|
QString result;
|
|
|
|
for (int i=0;i<mList.count()-1;i++) {
|
|
|
|
const PSynEditStringRec& line = mList[i];
|
|
|
|
result.append(line->fString);
|
|
|
|
result.append(lineBreak());
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
2021-09-02 12:14:02 +08:00
|
|
|
if (mList.length()>0) {
|
|
|
|
result.append(mList.back()->fString);
|
|
|
|
}
|
|
|
|
return result;
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::putString(int Index, const QString &s) {
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index == mList.count()) {
|
|
|
|
add(s);
|
|
|
|
} else {
|
|
|
|
if (Index<0 || Index>=mList.count()) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
mList[Index]->fString = s;
|
2021-06-07 11:02:03 +08:00
|
|
|
mList[Index]->fColumns = -1;
|
2021-05-14 23:56:43 +08:00
|
|
|
emit putted(Index,1);
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::putObject(int Index, void *AObject)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index<0 || Index>=mList.count()) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
beginUpdate();
|
|
|
|
mList[Index]->fObject = AObject;
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::setUpdateState(bool Updating)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
if (Updating)
|
|
|
|
emit changing();
|
|
|
|
else
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
int SynEditStringList::calculateLineColumns(int Index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
PSynEditStringRec line = mList[Index];
|
2021-05-18 15:49:58 +08:00
|
|
|
|
2021-05-21 23:33:53 +08:00
|
|
|
line->fColumns = mEdit->stringColumns(line->fString,0);
|
2021-05-18 15:49:58 +08:00
|
|
|
return line->fColumns;
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::insertLines(int Index, int NumLines)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-06-05 23:43:45 +08:00
|
|
|
if (Index<0 || Index>mList.count()) {
|
2021-05-14 23:56:43 +08:00
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
if (NumLines<=0)
|
|
|
|
return;
|
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
|
|
|
PSynEditStringRec line;
|
|
|
|
mList.insert(Index,NumLines,line);
|
|
|
|
for (int i=Index;i<Index+NumLines;i++) {
|
|
|
|
line = std::make_shared<SynEditStringRec>();
|
|
|
|
mList[i]=line;
|
|
|
|
}
|
|
|
|
emit inserted(Index,NumLines);
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::insertStrings(int Index, const QStringList &NewStrings)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-06-05 23:43:45 +08:00
|
|
|
if (Index<0 || Index>mList.count()) {
|
2021-05-14 23:56:43 +08:00
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
if (NewStrings.isEmpty())
|
|
|
|
return;
|
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
|
|
|
PSynEditStringRec line;
|
|
|
|
mList.insert(Index,NewStrings.length(),line);
|
|
|
|
for (int i=0;i<NewStrings.length();i++) {
|
|
|
|
line = std::make_shared<SynEditStringRec>();
|
|
|
|
line->fString = NewStrings[i];
|
|
|
|
mList[i+Index]=line;
|
|
|
|
}
|
|
|
|
emit inserted(Index,NewStrings.length());
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::insertText(int Index, const QString &NewText)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
if (Index<0 || Index>=mList.count()) {
|
|
|
|
ListIndexOutOfBounds(Index);
|
|
|
|
}
|
|
|
|
if (NewText.isEmpty())
|
|
|
|
return;
|
|
|
|
QStringList lines = TextToLines(NewText);
|
2021-10-17 21:09:50 +08:00
|
|
|
insertStrings(Index,lines);
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-09-26 22:39:26 +08:00
|
|
|
QFile file(filename);
|
|
|
|
if (!file.open(QFile::ReadOnly ))
|
2021-05-14 23:56:43 +08:00
|
|
|
throw FileError(tr("Can't open file '%1' for read!").arg(file.fileName()));
|
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
|
|
|
//test for utf8 / utf 8 bom
|
|
|
|
if (encoding == ENCODING_AUTO_DETECT) {
|
2021-05-24 00:41:00 +08:00
|
|
|
if (file.atEnd()) {
|
|
|
|
realEncoding = ENCODING_ASCII;
|
|
|
|
return;
|
|
|
|
}
|
2021-05-14 23:56:43 +08:00
|
|
|
QByteArray line = file.readLine();
|
|
|
|
QTextCodec* codec;
|
2021-05-24 00:41:00 +08:00
|
|
|
QTextCodec::ConverterState state;
|
2021-05-14 23:56:43 +08:00
|
|
|
bool needReread = false;
|
|
|
|
bool allAscii = true;
|
|
|
|
//test for BOM
|
|
|
|
if ((line.length()>=3) && ((unsigned char)line[0]==0xEF) && ((unsigned char)line[1]==0xBB) && ((unsigned char)line[2]==0xBF) ) {
|
|
|
|
realEncoding = ENCODING_UTF8_BOM;
|
|
|
|
line = line.mid(3);
|
|
|
|
codec = QTextCodec::codecForName(ENCODING_UTF8);
|
|
|
|
} else {
|
|
|
|
realEncoding = ENCODING_UTF8;
|
|
|
|
codec = QTextCodec::codecForName(ENCODING_UTF8);
|
|
|
|
}
|
2021-05-24 22:57:01 +08:00
|
|
|
if (line.endsWith("\r\n")) {
|
|
|
|
mFileEndingType = FileEndingType::Windows;
|
|
|
|
} else if (line.endsWith("\n")) {
|
|
|
|
mFileEndingType = FileEndingType::Linux;
|
|
|
|
} else if (line.endsWith("\r")) {
|
|
|
|
mFileEndingType = FileEndingType::Mac;
|
|
|
|
}
|
2021-10-17 21:09:50 +08:00
|
|
|
internalClear();
|
2021-09-26 22:39:26 +08:00
|
|
|
while (true) {
|
2021-05-14 23:56:43 +08:00
|
|
|
if (allAscii) {
|
|
|
|
allAscii = isTextAllAscii(line);
|
|
|
|
}
|
|
|
|
if (allAscii) {
|
2021-05-29 21:35:46 +08:00
|
|
|
addItem(TrimRight(QString::fromLatin1(line)));
|
2021-05-14 23:56:43 +08:00
|
|
|
} else {
|
2021-05-24 00:41:00 +08:00
|
|
|
QString newLine = codec->toUnicode(line.constData(),line.length(),&state);
|
|
|
|
if (state.invalidChars>0) {
|
2021-05-14 23:56:43 +08:00
|
|
|
needReread = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-29 21:35:46 +08:00
|
|
|
addItem(TrimRight(newLine));
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
2021-05-24 22:09:14 +08:00
|
|
|
if (file.atEnd()){
|
|
|
|
break;
|
|
|
|
}
|
2021-05-14 23:56:43 +08:00
|
|
|
line = file.readLine();
|
2021-09-26 22:39:26 +08:00
|
|
|
}
|
|
|
|
emit inserted(0,mList.count());
|
2021-05-14 23:56:43 +08:00
|
|
|
if (!needReread) {
|
|
|
|
if (allAscii)
|
|
|
|
realEncoding = ENCODING_ASCII;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
realEncoding = ENCODING_SYSTEM_DEFAULT;
|
|
|
|
} else {
|
|
|
|
realEncoding = encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (realEncoding == ENCODING_SYSTEM_DEFAULT) {
|
2021-09-28 22:26:12 +08:00
|
|
|
realEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
file.reset();
|
|
|
|
QTextStream textStream(&file);
|
|
|
|
if (realEncoding == ENCODING_UTF8_BOM) {
|
|
|
|
textStream.setAutoDetectUnicode(true);
|
|
|
|
textStream.setCodec(ENCODING_UTF8);
|
|
|
|
} else {
|
|
|
|
textStream.setAutoDetectUnicode(false);
|
|
|
|
textStream.setCodec(realEncoding);
|
|
|
|
}
|
|
|
|
QString line;
|
2021-10-17 21:09:50 +08:00
|
|
|
internalClear();
|
2021-05-14 23:56:43 +08:00
|
|
|
while (textStream.readLineInto(&line)) {
|
2021-05-29 21:35:46 +08:00
|
|
|
addItem(TrimRight(line));
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
2021-09-26 22:39:26 +08:00
|
|
|
emit inserted(0,mList.count());
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-24 13:03:54 +08:00
|
|
|
void SynEditStringList::saveToFile(QFile &file, const QByteArray& encoding,
|
|
|
|
const QByteArray& defaultEncoding, QByteArray& realEncoding)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-24 22:57:01 +08:00
|
|
|
if (!file.open(QFile::WriteOnly | QFile::Truncate))
|
2021-05-14 23:56:43 +08:00
|
|
|
throw FileError(tr("Can't open file '%1' for save!").arg(file.fileName()));
|
|
|
|
if (mList.isEmpty())
|
|
|
|
return;
|
|
|
|
bool allAscii = true;
|
|
|
|
|
|
|
|
QTextCodec* codec;
|
2021-06-12 22:36:23 +08:00
|
|
|
realEncoding = encoding;
|
2021-05-14 23:56:43 +08:00
|
|
|
if (realEncoding == ENCODING_UTF8_BOM) {
|
2021-06-12 22:36:23 +08:00
|
|
|
codec = QTextCodec::codecForName(ENCODING_UTF8);
|
|
|
|
file.putChar(0xEF);
|
|
|
|
file.putChar(0xBB);
|
|
|
|
file.putChar(0xBF);
|
2021-05-24 00:41:00 +08:00
|
|
|
} else if (realEncoding == ENCODING_SYSTEM_DEFAULT) {
|
2021-05-14 23:56:43 +08:00
|
|
|
codec = QTextCodec::codecForLocale();
|
2021-06-12 22:36:23 +08:00
|
|
|
} else if (realEncoding == ENCODING_AUTO_DETECT) {
|
2021-10-24 13:03:54 +08:00
|
|
|
codec = QTextCodec::codecForName(defaultEncoding);
|
|
|
|
if (!codec)
|
|
|
|
codec = QTextCodec::codecForLocale();
|
2021-05-24 22:57:01 +08:00
|
|
|
} else {
|
|
|
|
codec = QTextCodec::codecForName(realEncoding);
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
for (PSynEditStringRec& line:mList) {
|
|
|
|
if (allAscii) {
|
|
|
|
allAscii = isTextAllAscii(line->fString);
|
|
|
|
}
|
|
|
|
if (!allAscii) {
|
|
|
|
file.write(codec->fromUnicode(line->fString));
|
|
|
|
} else {
|
|
|
|
file.write(line->fString.toLatin1());
|
|
|
|
}
|
2021-06-12 22:36:23 +08:00
|
|
|
file.write(lineBreak().toLatin1());
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
2021-06-12 22:36:23 +08:00
|
|
|
if (encoding == ENCODING_AUTO_DETECT) {
|
|
|
|
if (allAscii)
|
|
|
|
realEncoding = ENCODING_ASCII;
|
2021-09-28 22:26:12 +08:00
|
|
|
else if (codec->name() == "System") {
|
|
|
|
realEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
|
|
|
|
} else {
|
2021-06-12 22:36:23 +08:00
|
|
|
realEncoding = codec->name();
|
2021-09-28 22:26:12 +08:00
|
|
|
}
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::putTextStr(const QString &text)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
endUpdate();
|
|
|
|
});
|
2021-10-17 21:09:50 +08:00
|
|
|
internalClear();
|
2021-05-14 23:56:43 +08:00
|
|
|
int pos = 0;
|
|
|
|
int start;
|
|
|
|
while (pos < text.length()) {
|
|
|
|
start = pos;
|
|
|
|
while (pos<text.length()) {
|
|
|
|
if (text[pos] == '\r' || text[pos] == '\n') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
add(text.mid(start,pos-start));
|
|
|
|
if (pos>=text.length())
|
|
|
|
break;
|
|
|
|
if (text[pos] == '\r')
|
|
|
|
pos++;
|
|
|
|
if (text[pos] == '\n')
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
void SynEditStringList::internalClear()
|
|
|
|
{
|
|
|
|
if (!mList.isEmpty()) {
|
|
|
|
beginUpdate();
|
|
|
|
int oldCount = mList.count();
|
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
mList.clear();
|
|
|
|
emit deleted(0,oldCount);
|
|
|
|
endUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileEndingType SynEditStringList::getFileEndingType()
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
return mFileEndingType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditStringList::setFileEndingType(const FileEndingType &fileEndingType)
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-14 23:56:43 +08:00
|
|
|
mFileEndingType = fileEndingType;
|
|
|
|
}
|
|
|
|
|
2021-05-24 00:41:00 +08:00
|
|
|
bool SynEditStringList::empty()
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
|
|
|
return mList.count()==0;
|
2021-05-24 00:41:00 +08:00
|
|
|
}
|
|
|
|
|
2021-06-07 11:02:03 +08:00
|
|
|
void SynEditStringList::resetColumns()
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-06-07 11:02:03 +08:00
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
if (mList.count() > 0 ) {
|
|
|
|
for (int i=0;i<mList.size();i++) {
|
|
|
|
mList[i]->fColumns = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
void SynEditStringList::invalidAllLineColumns()
|
|
|
|
{
|
2021-10-17 21:09:50 +08:00
|
|
|
QMutexLocker locker(&mMutex);
|
2021-05-18 15:49:58 +08:00
|
|
|
mIndexOfLongestLine = -1;
|
|
|
|
for (PSynEditStringRec& line:mList) {
|
|
|
|
line->fColumns = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 23:56:43 +08:00
|
|
|
SynEditStringRec::SynEditStringRec():
|
|
|
|
fString(),
|
|
|
|
fObject(nullptr),
|
2021-09-23 14:46:42 +08:00
|
|
|
fRange{0,0,0,0,0},
|
2021-09-23 12:06:26 +08:00
|
|
|
fColumns(-1)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SynEditUndoList::SynEditUndoList():QObject()
|
|
|
|
{
|
|
|
|
mMaxUndoActions = 1024;
|
|
|
|
mNextChangeNumber = 1;
|
|
|
|
mInsideRedo = false;
|
|
|
|
|
|
|
|
mBlockChangeNumber=0;
|
|
|
|
mBlockCount=0;
|
|
|
|
mFullUndoImposible=false;
|
|
|
|
mLockCount = 0;
|
|
|
|
mInitialChangeNumber = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::AddChange(SynChangeReason AReason, const BufferCoord &AStart,
|
|
|
|
const BufferCoord &AEnd, const QString &ChangeText,
|
|
|
|
SynSelectionMode SelMode)
|
|
|
|
{
|
|
|
|
if (mLockCount != 0)
|
|
|
|
return;
|
|
|
|
int changeNumber;
|
|
|
|
if (mBlockChangeNumber != 0) {
|
|
|
|
changeNumber = mBlockChangeNumber;
|
|
|
|
} else {
|
|
|
|
changeNumber = mNextChangeNumber;
|
|
|
|
if (mBlockCount == 0) {
|
|
|
|
mNextChangeNumber++;
|
|
|
|
if (mNextChangeNumber == 0) {
|
|
|
|
mNextChangeNumber++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PSynEditUndoItem NewItem = std::make_shared<SynEditUndoItem>(AReason,
|
|
|
|
SelMode,AStart,AEnd,ChangeText,
|
|
|
|
changeNumber);
|
|
|
|
PushItem(NewItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::AddGroupBreak()
|
|
|
|
{
|
|
|
|
//Add the GroupBreak even if ItemCount = 0. Since items are stored in
|
|
|
|
//reverse order in TCustomSynEdit.fRedoList, a GroupBreak could be lost.
|
|
|
|
if (LastChangeReason() != SynChangeReason::crGroupBreak) {
|
|
|
|
AddChange(SynChangeReason::crGroupBreak, {0,0}, {0,0}, "", SynSelectionMode::smNormal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::BeginBlock()
|
|
|
|
{
|
|
|
|
mBlockCount++;
|
|
|
|
mBlockChangeNumber = mNextChangeNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::Clear()
|
|
|
|
{
|
|
|
|
mItems.clear();
|
|
|
|
mFullUndoImposible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::DeleteItem(int index)
|
|
|
|
{
|
|
|
|
if (index <0 || index>=mItems.count()) {
|
|
|
|
ListIndexOutOfBounds(index);
|
|
|
|
}
|
|
|
|
mItems.removeAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::EndBlock()
|
|
|
|
{
|
|
|
|
if (mBlockCount > 0) {
|
|
|
|
mBlockCount--;
|
|
|
|
if (mBlockCount == 0) {
|
|
|
|
int iBlockID = mBlockChangeNumber;
|
|
|
|
mBlockChangeNumber = 0;
|
|
|
|
mNextChangeNumber++;
|
|
|
|
if (mNextChangeNumber == 0)
|
|
|
|
mNextChangeNumber++;
|
|
|
|
if (mItems.count() > 0 && PeekItem()->changeNumber() == iBlockID)
|
|
|
|
emit addedUndo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SynChangeReason SynEditUndoList::LastChangeReason()
|
|
|
|
{
|
|
|
|
if (mItems.count() == 0)
|
|
|
|
return SynChangeReason::crNothing;
|
|
|
|
else
|
2021-06-21 22:01:35 +08:00
|
|
|
return mItems.last()->changeReason();
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::Lock()
|
|
|
|
{
|
|
|
|
mLockCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
PSynEditUndoItem SynEditUndoList::PeekItem()
|
|
|
|
{
|
|
|
|
if (mItems.count() == 0)
|
|
|
|
return PSynEditUndoItem();
|
|
|
|
else
|
|
|
|
return mItems.last();
|
|
|
|
}
|
|
|
|
|
|
|
|
PSynEditUndoItem SynEditUndoList::PopItem()
|
|
|
|
{
|
|
|
|
if (mItems.count() == 0)
|
|
|
|
return PSynEditUndoItem();
|
|
|
|
else {
|
|
|
|
PSynEditUndoItem item = mItems.last();
|
|
|
|
mItems.removeLast();
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::PushItem(PSynEditUndoItem Item)
|
|
|
|
{
|
|
|
|
if (!Item)
|
|
|
|
return;
|
|
|
|
mItems.append(Item);
|
|
|
|
EnsureMaxEntries();
|
|
|
|
if (Item->changeReason()!= SynChangeReason::crGroupBreak)
|
2021-08-29 10:14:07 +08:00
|
|
|
emit addedUndo();
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::Unlock()
|
|
|
|
{
|
|
|
|
if (mLockCount > 0)
|
|
|
|
mLockCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SynEditUndoList::CanUndo()
|
|
|
|
{
|
|
|
|
return mItems.count()>0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynEditUndoList::ItemCount()
|
|
|
|
{
|
|
|
|
return mItems.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynEditUndoList::maxUndoActions() const
|
|
|
|
{
|
|
|
|
return mMaxUndoActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::setMaxUndoActions(int maxUndoActions)
|
|
|
|
{
|
|
|
|
mMaxUndoActions = maxUndoActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SynEditUndoList::initialState()
|
|
|
|
{
|
|
|
|
if (ItemCount() == 0) {
|
|
|
|
return mInitialChangeNumber == 0;
|
|
|
|
} else {
|
|
|
|
return PeekItem()->changeNumber() == mInitialChangeNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PSynEditUndoItem SynEditUndoList::item(int index)
|
|
|
|
{
|
|
|
|
if (index <0 || index>=mItems.count()) {
|
|
|
|
ListIndexOutOfBounds(index);
|
|
|
|
}
|
|
|
|
return mItems[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::setInitialState(const bool Value)
|
|
|
|
{
|
|
|
|
if (Value) {
|
|
|
|
if (ItemCount() == 0)
|
|
|
|
mInitialChangeNumber = 0;
|
|
|
|
else
|
|
|
|
mInitialChangeNumber = PeekItem()->changeNumber();
|
|
|
|
} else if (ItemCount() == 0) {
|
|
|
|
if (mInitialChangeNumber == 0) {
|
|
|
|
mInitialChangeNumber = -1;
|
|
|
|
}
|
|
|
|
} else if (PeekItem()->changeNumber() == mInitialChangeNumber) {
|
|
|
|
mInitialChangeNumber = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::setItem(int index, PSynEditUndoItem Value)
|
|
|
|
{
|
|
|
|
if (index <0 || index>=mItems.count()) {
|
|
|
|
ListIndexOutOfBounds(index);
|
|
|
|
}
|
|
|
|
mItems[index]=Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynEditUndoList::blockChangeNumber() const
|
|
|
|
{
|
|
|
|
return mBlockChangeNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::setBlockChangeNumber(int blockChangeNumber)
|
|
|
|
{
|
|
|
|
mBlockChangeNumber = blockChangeNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynEditUndoList::blockCount() const
|
|
|
|
{
|
|
|
|
return mBlockCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SynEditUndoList::insideRedo() const
|
|
|
|
{
|
|
|
|
return mInsideRedo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::setInsideRedo(bool insideRedo)
|
|
|
|
{
|
|
|
|
mInsideRedo = insideRedo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SynEditUndoList::fullUndoImposible() const
|
|
|
|
{
|
|
|
|
return mFullUndoImposible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditUndoList::EnsureMaxEntries()
|
|
|
|
{
|
|
|
|
if (mItems.count() > mMaxUndoActions){
|
|
|
|
mFullUndoImposible = true;
|
|
|
|
while (mItems.count() > mMaxUndoActions) {
|
|
|
|
mItems.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SynSelectionMode SynEditUndoItem::changeSelMode() const
|
|
|
|
{
|
|
|
|
return mChangeSelMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferCoord SynEditUndoItem::changeStartPos() const
|
|
|
|
{
|
|
|
|
return mChangeStartPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferCoord SynEditUndoItem::changeEndPos() const
|
|
|
|
{
|
|
|
|
return mChangeEndPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SynEditUndoItem::changeStr() const
|
|
|
|
{
|
|
|
|
return mChangeStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynEditUndoItem::changeNumber() const
|
|
|
|
{
|
|
|
|
return mChangeNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
SynEditUndoItem::SynEditUndoItem(SynChangeReason reason, SynSelectionMode selMode,
|
|
|
|
BufferCoord startPos, BufferCoord endPos,
|
|
|
|
const QString &str, int number)
|
|
|
|
{
|
|
|
|
mChangeReason = reason;
|
|
|
|
mChangeSelMode = selMode;
|
|
|
|
mChangeStartPos = startPos;
|
|
|
|
mChangeEndPos = endPos;
|
|
|
|
mChangeStr = str;
|
|
|
|
mChangeNumber = number;
|
|
|
|
}
|
|
|
|
|
|
|
|
SynChangeReason SynEditUndoItem::changeReason() const
|
|
|
|
{
|
|
|
|
return mChangeReason;
|
|
|
|
}
|