-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripteditor.h
More file actions
56 lines (54 loc) · 1.73 KB
/
Copy pathscripteditor.h
File metadata and controls
56 lines (54 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <QObject>
#include <QUrl>
#include <QVariantList>
#include <QVector>
class ScriptEditor : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList scripts READ scripts NOTIFY stateChanged)
Q_PROPERTY(int currentIndex READ currentIndex NOTIFY selectionChanged)
Q_PROPERTY(QString text READ text NOTIFY textChanged)
Q_PROPERTY(QString fileName READ fileName NOTIFY stateChanged)
Q_PROPERTY(bool modified READ modified NOTIFY stateChanged)
Q_PROPERTY(bool canUndo READ canUndo NOTIFY stateChanged)
Q_PROPERTY(bool canRedo READ canRedo NOTIFY stateChanged)
public:
explicit ScriptEditor(QObject *parent = nullptr) : QObject(parent) {}
QVariantList scripts() const;
int currentIndex() const { return m_index; }
QString text() const;
QString fileName() const;
bool modified() const;
bool canUndo() const;
bool canRedo() const;
Q_INVOKABLE bool openFile(const QUrl &url);
Q_INVOKABLE void selectScript(int index);
Q_INVOKABLE void editText(const QString &text);
Q_INVOKABLE void undo();
Q_INVOKABLE void redo();
Q_INVOKABLE bool save(bool all = false);
Q_INVOKABLE QVariantList search(const QString &query, bool regex);
signals:
void stateChanged();
void selectionChanged();
void textChanged();
void error(const QString &message);
void saved(const QString &message);
private:
struct Script {
QString label;
QString savedText;
QStringList history;
int position = 0;
int start = 0;
int end = 0;
bool saved = false;
};
QVector<Script> m_scripts;
int m_index = -1;
QString m_path;
QString m_source;
QByteArray m_disk;
QString m_newline = QStringLiteral("\n");
};