2021-04-06 23:10:57 +08:00
|
|
|
#ifndef EDITOR_H
|
|
|
|
#define EDITOR_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <utils.h>
|
|
|
|
#include <QTabWidget>
|
2021-05-24 00:41:00 +08:00
|
|
|
#include "qsynedit/SynEdit.h"
|
2021-06-19 22:58:35 +08:00
|
|
|
#include "colorscheme.h"
|
2021-06-23 22:38:02 +08:00
|
|
|
#include "common.h"
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
class SaveException: public std::exception {
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SaveException(const QString& reason);
|
|
|
|
explicit SaveException(const QString&& reason);
|
|
|
|
// exception interface
|
|
|
|
const QString& reason() const noexcept;
|
|
|
|
public:
|
|
|
|
const char *what() const noexcept override;
|
|
|
|
private:
|
|
|
|
QString mReason;
|
|
|
|
};
|
|
|
|
|
2021-05-24 00:41:00 +08:00
|
|
|
class Editor : public SynEdit
|
2021-04-06 23:10:57 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-04-29 20:54:44 +08:00
|
|
|
enum MarginNumber {
|
|
|
|
LineNumberMargin = 0,
|
|
|
|
MarkerMargin = 1,
|
|
|
|
FoldMargin = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MarkerNumber {
|
|
|
|
BreakpointMarker,
|
|
|
|
ErrorMarker,
|
|
|
|
WarningMarker
|
|
|
|
};
|
|
|
|
|
2021-06-22 13:24:26 +08:00
|
|
|
enum class QuoteStatus {
|
|
|
|
NotQuote,
|
|
|
|
SingleQuote,
|
|
|
|
SingleQuoteEscape,
|
|
|
|
DoubleQuote,
|
|
|
|
DoubleQuoteEscape,
|
|
|
|
RawString,
|
|
|
|
RawStringNoEscape
|
|
|
|
};
|
|
|
|
|
2021-06-23 22:38:02 +08:00
|
|
|
struct SyntaxIssue {
|
|
|
|
int col;
|
|
|
|
int endCol;
|
|
|
|
int startChar;
|
|
|
|
int endChar;
|
|
|
|
CompileIssueType issueType;
|
|
|
|
QString token;
|
|
|
|
QString hint;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PSyntaxIssue = std::shared_ptr<SyntaxIssue>;
|
|
|
|
using SyntaxIssueList = QVector<PSyntaxIssue>;
|
|
|
|
using PSyntaxIssueList = std::shared_ptr<SyntaxIssueList>;
|
|
|
|
|
2021-06-19 22:58:35 +08:00
|
|
|
explicit Editor(QWidget *parent);
|
|
|
|
|
2021-04-09 17:48:25 +08:00
|
|
|
explicit Editor(QWidget *parent, const QString& filename,
|
2021-04-08 10:29:21 +08:00
|
|
|
const QByteArray& encoding,
|
2021-04-09 17:48:25 +08:00
|
|
|
bool inProject, bool isNew,QTabWidget* parentPageControl);
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2021-04-07 22:44:08 +08:00
|
|
|
~Editor();
|
|
|
|
|
2021-04-11 12:39:22 +08:00
|
|
|
//tell the compiler to prohibit copy/moving editor objects ( we should only use pointers to the editor object)
|
|
|
|
Editor(const Editor&) = delete;
|
|
|
|
Editor(const Editor&&) = delete;
|
|
|
|
Editor& operator=(const Editor&) = delete;
|
|
|
|
Editor& operator=(const Editor&&) = delete;
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
const QByteArray& encodingOption() const noexcept;
|
|
|
|
void setEncodingOption(const QByteArray& encoding) noexcept;
|
|
|
|
const QByteArray& fileEncoding() const noexcept;
|
|
|
|
const QString& filename() const noexcept;
|
|
|
|
bool inProject() const noexcept;
|
|
|
|
bool isNew() const noexcept;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
|
|
|
void loadFile();
|
2021-04-07 21:13:15 +08:00
|
|
|
void saveFile(const QString& filename);
|
2021-06-12 22:36:23 +08:00
|
|
|
void convertToEncoding(const QByteArray& encoding);
|
2021-04-09 10:08:05 +08:00
|
|
|
bool save(bool force=false, bool reparse=true);
|
2021-04-11 12:39:22 +08:00
|
|
|
bool saveAs();
|
2021-04-12 00:00:29 +08:00
|
|
|
void activate();
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
QTabWidget* pageControl() noexcept;
|
2021-04-11 12:39:22 +08:00
|
|
|
|
|
|
|
void updateCaption(const QString& newCaption=QString());
|
2021-06-07 11:02:03 +08:00
|
|
|
void applySettings();
|
2021-06-19 22:58:35 +08:00
|
|
|
void applyColorScheme(const QString& schemeName);
|
2021-06-12 22:36:23 +08:00
|
|
|
void copyToClipboard() override;
|
|
|
|
void cutToClipboard() override;
|
|
|
|
void copyAsHTML();
|
2021-06-23 22:38:02 +08:00
|
|
|
|
|
|
|
void addSyntaxIssues(int line, int startChar, CompileIssueType errorType, const QString& hint);
|
|
|
|
void clearSyntaxIssues();
|
|
|
|
void gotoNextSyntaxIssue();
|
|
|
|
void gotoPrevSyntaxIssue();
|
|
|
|
bool hasPrevSyntaxIssue() const;
|
|
|
|
bool hasNextSyntaxIssue() const;
|
|
|
|
PSyntaxIssueList getErrorsAtLine(int line);
|
|
|
|
PSyntaxIssue getErrorAtPosition(const BufferCoord& pos);
|
2021-04-06 23:10:57 +08:00
|
|
|
signals:
|
|
|
|
|
2021-04-11 12:39:22 +08:00
|
|
|
|
|
|
|
protected slots:
|
2021-04-11 21:33:08 +08:00
|
|
|
void onModificationChanged(bool status) ;
|
2021-06-10 09:34:59 +08:00
|
|
|
void onStatusChanged(SynStatusChanges changes);
|
2021-04-11 12:39:22 +08:00
|
|
|
|
2021-06-21 16:25:21 +08:00
|
|
|
private:
|
2021-06-22 23:00:34 +08:00
|
|
|
QChar getCurrentChar();
|
2021-06-22 13:24:26 +08:00
|
|
|
bool handleSymbolCompletion(QChar key);
|
2021-06-22 23:00:34 +08:00
|
|
|
bool handleParentheseCompletion();
|
|
|
|
bool handleParentheseSkip();
|
|
|
|
bool handleBracketCompletion();
|
|
|
|
bool handleBracketSkip();
|
|
|
|
bool handleMultilineCommentCompletion();
|
|
|
|
bool handleBraceCompletion();
|
|
|
|
bool handleBraceSkip();
|
|
|
|
bool handleSingleQuoteCompletion();
|
|
|
|
bool handleDoubleQuoteCompletion();
|
|
|
|
bool handleGlobalIncludeCompletion();
|
|
|
|
bool handleGlobalIncludeSkip();
|
2021-06-23 08:55:56 +08:00
|
|
|
void undoSymbolCompletion(int pos);
|
2021-06-22 13:24:26 +08:00
|
|
|
QuoteStatus getQuoteStatus();
|
2021-06-21 16:25:21 +08:00
|
|
|
|
2021-04-06 23:10:57 +08:00
|
|
|
private:
|
2021-05-26 00:04:20 +08:00
|
|
|
static int newfileCount;
|
2021-04-08 10:29:21 +08:00
|
|
|
QByteArray mEncodingOption; // the encoding type set by the user
|
|
|
|
QByteArray mFileEncoding; // the real encoding of the file (auto detected)
|
2021-04-06 23:10:57 +08:00
|
|
|
QString mFilename;
|
|
|
|
QTabWidget* mParentPageControl;
|
|
|
|
bool mInProject;
|
|
|
|
bool mIsNew;
|
2021-06-23 22:38:02 +08:00
|
|
|
QMap<int,PSyntaxIssueList> mSyntaxIssues;
|
2021-04-09 17:48:25 +08:00
|
|
|
|
|
|
|
// QWidget interface
|
|
|
|
protected:
|
|
|
|
void wheelEvent(QWheelEvent *event) override;
|
2021-06-21 22:01:35 +08:00
|
|
|
void focusInEvent(QFocusEvent *event) override;
|
|
|
|
void focusOutEvent(QFocusEvent *event) override;
|
|
|
|
void keyPressEvent(QKeyEvent *event) override;
|
2021-04-06 23:10:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITOR_H
|