Mantid
Loading...
Searching...
No Matches
ScriptEditor.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------
10// Includes
11//----------------------------------
12#include "DllOption.h"
13#include <QDialog>
14#include <QTextDocument>
15#include <Qsci/qsciscintilla.h>
16
17//----------------------------------
18// Forward declarations
19//----------------------------------
21
22class QAction;
23class QMenu;
24class QMimeData;
25class QKeyEvent;
26class QMouseEvent;
27class QsciAPIs;
28
37class EXPORT_OPT_MANTIDQT_COMMON ScriptEditor : public QsciScintilla {
38 // Qt macro
39 Q_OBJECT
40
41public:
45 class SaveCancelledException : public std::exception {
46 public:
48 const char *what() const noexcept override { return m_msg.c_str(); }
49
50 private:
51 std::string m_msg{"File Saving was cancelled"};
52 };
53
54public:
55 ScriptEditor(const QString &lexerName, const QFont &font = QFont(), QWidget *parent = nullptr);
56 ScriptEditor(QWidget *parent = nullptr, QsciLexer *lexer = nullptr, QString settingsGroup = "");
58 ~ScriptEditor() override;
59
61 void setSettingsGroup(const QString &name);
63 QString settingsGroup() const;
65 void readSettings();
67 void writeSettings();
68
70 void setLexer(QsciLexer * /*codelexer*/) override;
71 // Make the object resize to margin to fit the contents
72 void setAutoMarginResize();
75 void enableAutoCompletion(AutoCompletionSource source = QsciScintilla::AcsAPIs);
77 void disableAutoCompletion();
78
79 // Size hint
80 QSize sizeHint() const override;
81 // Unhide base class method to avoid intel compiler warning
82 using QsciScintilla::setText;
84 void setText(int lineno, const QString &text, int index = 0);
86 void keyPressEvent(QKeyEvent *event) override;
88 inline QString fileName() const { return m_filename; }
90 void setFileName(const QString &filename);
91
93 void wheelEvent(QWheelEvent *e) override;
94
96 void clearKeyBinding(const QString &keyCombination);
97
99 inline QsciAPIs *scintillaAPI() const { return m_completer; }
100
102 void replaceAll(const QString &search, const QString &replace, bool regex, bool caseSensitive, bool matchWords,
103 bool wrap, bool forward = true);
104
106 int getZoom() const;
107
108public slots:
110 void saveAs();
112 void saveToCurrentFile();
114 void saveScript(const QString &filename);
115
117 void padMargin();
119 void setMarkerState(bool enabled);
121 void updateProgressMarkerFromThread(int lineno, bool error = false);
123 void updateProgressMarker(int lineno, bool error = false);
125 void markExecutingLineAsError();
127 void updateCompletionAPI(const QStringList &keywords);
129 void print();
131 virtual void showFindReplaceDialog();
132
134 void zoomTo(int level) override;
135
136signals:
138 void undoAvailable(bool /*_t1*/);
140 void redoAvailable(bool /*_t1*/);
146 void fileNameChanged(const QString &fileName);
148 void progressMade(const int progress);
149
150protected:
152 virtual void writeToDevice(QIODevice &device) const;
153
154 void dropEvent(QDropEvent *de) override;
155 void dragMoveEvent(QDragMoveEvent *de) override;
156 void dragEnterEvent(QDragEnterEvent *de) override;
157 QByteArray fromMimeData(const QMimeData *source, bool &rectangular) const override;
158
159private slots:
160
161private:
164 void forwardKeyPressToBase(QKeyEvent *event);
165
167 QString m_filename;
168
174 QsciAPIs *m_completer;
176 static QColor g_success_colour;
178 static QColor g_error_colour;
185};
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Raises a dialog allowing the user to find/replace text in the editor.
Exception type to indicate that saving was cancelled.
Definition: ScriptEditor.h:45
const char * what() const noexcept override
Return a message.
Definition: ScriptEditor.h:48
This class provides an area to write scripts.
Definition: ScriptEditor.h:37
int m_currentExecLine
Hold the line number of the currently executing line.
Definition: ScriptEditor.h:172
QsciAPIs * scintillaAPI() const
Return a pointer to the object responsible for code completion.
Definition: ScriptEditor.h:99
void undoAvailable(bool)
Inform observers that undo information is available.
int m_progressArrowKey
The margin marker.
Definition: ScriptEditor.h:170
void redoAvailable(bool)
Inform observers that redo information is available.
void fileNameChanged(const QString &fileName)
Notify that the filename has been modified.
int m_previousKey
previous key
Definition: ScriptEditor.h:180
QsciAPIs * m_completer
A pointer to a QsciAPI object that handles the code completion.
Definition: ScriptEditor.h:174
void progressMade(const int progress)
Progress has been made in script execution.
QString fileName() const
The current filename.
Definition: ScriptEditor.h:88
static QColor g_success_colour
The colour of the marker for a success state.
Definition: ScriptEditor.h:176
static QColor g_error_colour
The colour of the marker for an error state.
Definition: ScriptEditor.h:178
FindReplaceDialog * m_findDialog
A pointer to the find replace dialog.
Definition: ScriptEditor.h:182
QString m_filename
The file name associated with this editor.
Definition: ScriptEditor.h:167
QString m_settingsGroup
Name of group that the settings are stored under.
Definition: ScriptEditor.h:184
void textZoomedIn()
Emitted when a zoom in is requested.
void textZoomedOut()
Emitted when a zoom out is requested.