Ai
1 Star 1 Fork 1

HuanZeng/texstudio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
codesnippet.h 4.35 KB
一键复制 编辑 原始数据 按行查看 历史
MeanSquaredError 提交于 2019-10-22 03:23 +08:00 . Fix gcc9 compile warnings (#753)
#ifndef CODESNIPPET_H
#define CODESNIPPET_H
#include "mostQtHeaders.h"
class QDocumentCursor;
class QEditor;
class Texstudio;
enum CompletionType {CT_COMMANDS, CT_NORMALTEXT, CT_CITATIONS, CT_CITATIONCOMMANDS, CT_LABELS};
/*!
* \brief store information for placeholder
*/
struct CodeSnippetPlaceHolder {
int offset /*< column position*/, length /*< lenght*/;
int id; ///< identification number to match mirror placeholders
enum Flag {AutoSelect = 1, Mirrored = 2, Mirror = 4, PreferredMultilineAutoSelect = 8, Persistent = 16, Translatable = 32};
int flags; ///< type of placeholder
int offsetEnd() const; ///< return end-column of placeholder = offset+lenght
};
/*!
* \class CodeSnippet
* \brief contains data for command completion
*
* Handles all information for command completion, especially sort-order, placeholder handling including mirror-placeholders and final cursor positioning
* Usually these information is encoded via special comments, see manual
*/
class CodeSnippet
{
public:
CodeSnippet(): cursorLine(-1), cursorOffset(-1), anchorOffset(-1), usageCount(0), index(0), snippetLength(0), score(0), type(none) {} ///< generate empty codesnippet
CodeSnippet(const CodeSnippet &cw): word(cw.word), sortWord(cw.sortWord), lines(cw.lines), cursorLine(cw.cursorLine), cursorOffset(cw.cursorOffset), anchorOffset(cw.anchorOffset), placeHolders(cw.placeHolders), usageCount(cw.usageCount), index(cw.index), snippetLength(cw.snippetLength), score(cw.score), type(cw.type), name(cw.name) {} ///< copy constructor
CodeSnippet(const QString &newWord, bool replacePercentNewline = true); ///< generate codesnippet from text string
CodeSnippet & operator= (const CodeSnippet&) = default; // Avoid GCC9 -Wdeprecated-copy warning
bool operator< (const CodeSnippet &cw) const; ///< define sorting operator
bool operator== (const CodeSnippet &cw) const;
enum PlaceholderMode { PlacehodersActive, PlaceholdersToPlainText, PlaceholdersRemoved }; ///< configuaration of placeholder handling
QString word; ///< displayed snippet name
QString sortWord; ///< for sorting used snippet name, allows change of sort-order by replacement special characters especially braces
QStringList lines; ///< to be inserted code
//TODO: Multirow selection
int cursorLine; ///< placement of cursor after insert concerning line of codesnippet; -1 => not defined
int cursorOffset; ///< placement of cursor after insert concerning column; -1 => not defined
int anchorOffset; ///< placement of cursor anchor after insert
QList<QList<CodeSnippetPlaceHolder> > placeHolders; //used to draw
int usageCount; ///< usage count for favourite detection
uint index; ///< hash index for usage count identification
int snippetLength; ///< number of characters
int score;
enum Type {none, length,userConstruct};
Type type;
QString expandCode(const QString &code);
QString environmentContent(const QString &envName);
void insert(QEditor *editor) const; ///< insert snippet text into given editor at current cursor position
void insertAt(QEditor *editor, QDocumentCursor *cursor, PlaceholderMode placeholderMode = PlacehodersActive, bool byCompleter = false, bool isKeyVal = false) const;
void setName(const QString &newName); ///< set codesnippet name, used for usertags
QString getName() const; ///< get codesnippet name, used for usertags
static bool autoReplaceCommands;
static bool debugDisableAutoTranslate;
private:
QString name;
QDocumentCursor getCursor(QEditor *editor, const CodeSnippetPlaceHolder &ph, int snippetLine, int baseLine, int baseLineIndent, int lastLineRemainingLength) const;
};
Q_DECLARE_METATYPE(CodeSnippet)
Q_DECLARE_METATYPE(CodeSnippet::PlaceholderMode)
/*!
* \brief special list class for codesnippets
*
* The method for combining are optmized for sorted lists
*/
class CodeSnippetList: public QList<CodeSnippet>
{
public:
void unite(CodeSnippetList &lst); ///< merge two list (both need to be sorted !)
void unite(const QList<CodeSnippet> &lst); ///< merge two list (both need to be sorted !)
void insert(const QString &elem); ///< insert one element into list at correct position to maintain sorting
CodeSnippetList::iterator insert(CodeSnippetList::iterator before, const CodeSnippet &cs) ///< insert before given iterator
{
return QList<CodeSnippet>::insert(before, cs);
}
};
#endif // CODESNIPPET_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xmrzh/texstudio.git
git@gitee.com:xmrzh/texstudio.git
xmrzh
texstudio
texstudio
master

搜索帮助