2021-05-14 23:56:43 +08:00
|
|
|
#ifndef SYNEDITSTRINGLIST_H
|
|
|
|
#define SYNEDITSTRINGLIST_H
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
#include "highlighter/base.h"
|
2021-10-17 21:09:50 +08:00
|
|
|
#include <QMutex>
|
2021-05-14 23:56:43 +08:00
|
|
|
#include <QVector>
|
|
|
|
#include <memory>
|
|
|
|
#include "MiscProcs.h"
|
|
|
|
#include "../utils.h"
|
|
|
|
#include "Types.h"
|
|
|
|
|
|
|
|
enum SynEditStringFlag {
|
|
|
|
sfHasTabs = 0x0001,
|
|
|
|
sfHasNoTabs = 0x0002,
|
|
|
|
sfExpandedLengthUnknown = 0x0004
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int SynEditStringFlags;
|
|
|
|
|
|
|
|
struct SynEditStringRec {
|
|
|
|
QString fString;
|
|
|
|
void * fObject;
|
|
|
|
SynRangeState fRange;
|
2021-09-23 14:46:42 +08:00
|
|
|
int fLeftBraces;
|
|
|
|
int fRightBraces;
|
2021-05-18 15:49:58 +08:00
|
|
|
int fColumns; //
|
2021-05-14 23:56:43 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SynEditStringRec();
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::shared_ptr<SynEditStringRec> PSynEditStringRec;
|
|
|
|
|
|
|
|
typedef QVector<PSynEditStringRec> SynEditStringRecList;
|
|
|
|
|
|
|
|
typedef std::shared_ptr<SynEditStringRecList> PSynEditStringRecList;
|
|
|
|
|
|
|
|
class SynEditStringList;
|
|
|
|
|
|
|
|
typedef std::shared_ptr<SynEditStringList> PSynEditStringList;
|
|
|
|
|
|
|
|
using StringListChangeCallback = std::function<void(PSynEditStringList* object, int index, int count)>;
|
|
|
|
|
|
|
|
class QFile;
|
2021-05-18 15:49:58 +08:00
|
|
|
|
|
|
|
class SynEdit;
|
2021-05-14 23:56:43 +08:00
|
|
|
class SynEditStringList : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-05-18 15:49:58 +08:00
|
|
|
explicit SynEditStringList(SynEdit* pEdit,QObject* parent=nullptr);
|
2021-05-14 23:56:43 +08:00
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
int parenthesisLevels(int Index);
|
|
|
|
int bracketLevels(int Index);
|
|
|
|
int braceLevels(int Index);
|
2021-05-18 15:49:58 +08:00
|
|
|
int lineColumns(int Index);
|
2021-10-17 21:09:50 +08:00
|
|
|
int leftBraces(int Index);
|
|
|
|
int rightBraces(int Index);
|
2021-05-14 23:56:43 +08:00
|
|
|
int lengthOfLongestLine();
|
2021-10-07 07:52:20 +08:00
|
|
|
QString lineBreak() const;
|
2021-10-24 15:17:31 +08:00
|
|
|
SynRangeState ranges(int Index);
|
2021-09-23 14:46:42 +08:00
|
|
|
void setRange(int Index, const SynRangeState& ARange, int leftBraces, int rightBraces);
|
2021-10-17 21:09:50 +08:00
|
|
|
QString getString(int Index);
|
|
|
|
int count();
|
|
|
|
void* getObject(int Index);
|
|
|
|
QString text();
|
2021-05-14 23:56:43 +08:00
|
|
|
void setText(const QString& text);
|
2021-09-03 16:39:20 +08:00
|
|
|
void setContents(const QStringList& text);
|
2021-10-17 21:09:50 +08:00
|
|
|
QStringList contents();
|
2021-05-14 23:56:43 +08:00
|
|
|
|
|
|
|
void putString(int Index, const QString& s);
|
|
|
|
void putObject(int Index, void * AObject);
|
|
|
|
|
|
|
|
void beginUpdate();
|
|
|
|
void endUpdate();
|
|
|
|
|
|
|
|
int add(const QString& s);
|
2021-06-21 22:01:35 +08:00
|
|
|
void addStrings(const QStringList& Strings);
|
2021-05-14 23:56:43 +08:00
|
|
|
|
|
|
|
int getTextLength();
|
|
|
|
void clear();
|
|
|
|
void deleteAt(int Index);
|
|
|
|
void deleteLines(int Index, int NumLines);
|
2021-10-17 21:09:50 +08:00
|
|
|
void exchange(int Index1, int Index2);
|
|
|
|
void insert(int Index, const QString& s);
|
|
|
|
void insertLines(int Index, int NumLines);
|
|
|
|
void insertStrings(int Index, const QStringList& NewStrings);
|
|
|
|
void insertText(int Index,const QString& NewText);
|
|
|
|
void loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding);
|
2021-10-24 13:03:54 +08:00
|
|
|
void saveToFile(QFile& file, const QByteArray& encoding,
|
|
|
|
const QByteArray& defaultEncoding, QByteArray& realEncoding);
|
2021-10-17 21:09:50 +08:00
|
|
|
|
|
|
|
bool getAppendNewLineAtEOF();
|
2021-05-14 23:56:43 +08:00
|
|
|
void setAppendNewLineAtEOF(bool appendNewLineAtEOF);
|
|
|
|
|
2021-10-17 21:09:50 +08:00
|
|
|
FileEndingType getFileEndingType();
|
2021-05-14 23:56:43 +08:00
|
|
|
void setFileEndingType(const FileEndingType &fileEndingType);
|
2021-05-24 00:41:00 +08:00
|
|
|
|
|
|
|
bool empty();
|
2021-06-07 11:02:03 +08:00
|
|
|
|
|
|
|
void resetColumns();
|
2021-05-18 15:49:58 +08:00
|
|
|
public slots:
|
|
|
|
void invalidAllLineColumns();
|
2021-05-14 23:56:43 +08:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void changed();
|
|
|
|
void changing();
|
|
|
|
void cleared();
|
|
|
|
void deleted(int index, int count);
|
|
|
|
void inserted(int index, int count);
|
|
|
|
void putted(int index, int count);
|
|
|
|
protected:
|
2021-10-07 07:52:20 +08:00
|
|
|
QString getTextStr() const;
|
2021-10-17 21:09:50 +08:00
|
|
|
void setUpdateState(bool Updating);
|
|
|
|
void insertItem(int Index, const QString& s);
|
2021-05-24 00:41:00 +08:00
|
|
|
void addItem(const QString& s);
|
2021-10-17 21:09:50 +08:00
|
|
|
void putTextStr(const QString& text);
|
|
|
|
void internalClear();
|
2021-05-14 23:56:43 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
SynEditStringRecList mList;
|
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
SynEdit* mEdit;
|
2021-05-14 23:56:43 +08:00
|
|
|
//int mCount;
|
|
|
|
//int mCapacity;
|
|
|
|
FileEndingType mFileEndingType;
|
|
|
|
bool mAppendNewLineAtEOF;
|
|
|
|
int mIndexOfLongestLine;
|
|
|
|
int mUpdateCount;
|
2021-10-17 21:09:50 +08:00
|
|
|
QRecursiveMutex mMutex;
|
2021-05-14 23:56:43 +08:00
|
|
|
|
2021-05-18 15:49:58 +08:00
|
|
|
int calculateLineColumns(int Index);
|
2021-05-14 23:56:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class SynChangeReason {crInsert, crPaste, crDragDropInsert,
|
|
|
|
//several undo entries can be chained together via the ChangeNumber
|
|
|
|
//see also TCustomSynEdit.[Begin|End]UndoBlock methods
|
|
|
|
crDeleteAfterCursor, crDelete,
|
|
|
|
crLineBreak, crIndent, crUnindent,
|
|
|
|
crSilentDelete, crSilentDeleteAfterCursor,
|
|
|
|
crAutoCompleteBegin, crAutoCompleteEnd,
|
|
|
|
crPasteBegin, crPasteEnd, //for pasting, since it might do a lot of operations
|
|
|
|
crSpecial1Begin, crSpecial1End,
|
|
|
|
crSpecial2Begin, crSpecial2End,
|
|
|
|
crCaret, //just restore the Caret, allowing better Undo behavior
|
|
|
|
crSelection, //restore Selection
|
|
|
|
crNothing,
|
|
|
|
crGroupBreak,
|
|
|
|
crDeleteAll
|
|
|
|
};
|
|
|
|
class SynEditUndoItem {
|
|
|
|
private:
|
|
|
|
SynChangeReason mChangeReason;
|
|
|
|
SynSelectionMode mChangeSelMode;
|
|
|
|
BufferCoord mChangeStartPos;
|
|
|
|
BufferCoord mChangeEndPos;
|
|
|
|
QString mChangeStr;
|
|
|
|
int mChangeNumber;
|
|
|
|
public:
|
|
|
|
SynEditUndoItem(SynChangeReason reason,
|
|
|
|
SynSelectionMode selMode,
|
|
|
|
BufferCoord startPos,
|
|
|
|
BufferCoord endPos,
|
|
|
|
const QString& str,
|
|
|
|
int number);
|
|
|
|
|
|
|
|
SynChangeReason changeReason() const;
|
|
|
|
SynSelectionMode changeSelMode() const;
|
|
|
|
BufferCoord changeStartPos() const;
|
|
|
|
BufferCoord changeEndPos() const;
|
|
|
|
QString changeStr() const;
|
|
|
|
int changeNumber() const;
|
|
|
|
};
|
|
|
|
using PSynEditUndoItem = std::shared_ptr<SynEditUndoItem>;
|
|
|
|
|
|
|
|
class SynEditUndoList : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit SynEditUndoList();
|
|
|
|
|
|
|
|
void AddChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd,
|
|
|
|
const QString& ChangeText, SynSelectionMode SelMode);
|
|
|
|
|
|
|
|
void AddGroupBreak();
|
|
|
|
void BeginBlock();
|
|
|
|
void Clear();
|
|
|
|
void DeleteItem(int index);
|
|
|
|
void EndBlock();
|
|
|
|
SynChangeReason LastChangeReason();
|
|
|
|
void Lock();
|
|
|
|
PSynEditUndoItem PeekItem();
|
|
|
|
PSynEditUndoItem PopItem();
|
|
|
|
void PushItem(PSynEditUndoItem Item);
|
|
|
|
void Unlock();
|
|
|
|
|
|
|
|
bool CanUndo();
|
|
|
|
int ItemCount();
|
|
|
|
|
|
|
|
int maxUndoActions() const;
|
|
|
|
void setMaxUndoActions(int maxUndoActions);
|
|
|
|
bool initialState();
|
|
|
|
PSynEditUndoItem item(int index);
|
|
|
|
void setInitialState(const bool Value);
|
|
|
|
void setItem(int index, PSynEditUndoItem Value);
|
|
|
|
|
|
|
|
int blockChangeNumber() const;
|
|
|
|
void setBlockChangeNumber(int blockChangeNumber);
|
|
|
|
|
|
|
|
int blockCount() const;
|
|
|
|
|
|
|
|
bool insideRedo() const;
|
|
|
|
void setInsideRedo(bool insideRedo);
|
|
|
|
|
|
|
|
bool fullUndoImposible() const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void addedUndo();
|
2021-10-18 22:06:33 +08:00
|
|
|
protected:
|
|
|
|
void EnsureMaxEntries();
|
2021-05-14 23:56:43 +08:00
|
|
|
protected:
|
|
|
|
int mBlockChangeNumber;
|
|
|
|
int mBlockCount;
|
|
|
|
bool mFullUndoImposible;
|
|
|
|
QVector<PSynEditUndoItem> mItems;
|
|
|
|
int mLockCount;
|
|
|
|
int mMaxUndoActions;
|
|
|
|
int mNextChangeNumber;
|
|
|
|
int mInitialChangeNumber;
|
|
|
|
bool mInsideRedo;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PSynEditUndoList = std::shared_ptr<SynEditUndoList>;
|
|
|
|
|
|
|
|
#endif // SYNEDITSTRINGLIST_H
|