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 const QString &settingsGroup() const;
65 void readSettings();
67 void writeSettings();
68
70 void setLexer(QsciLexer * /*codelexer*/) override final;
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 const 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();
133 void markFileAsModified();
134
135signals:
137 void undoAvailable(bool /*_t1*/);
139 void redoAvailable(bool /*_t1*/);
145 void fileNameChanged(const QString &fileName);
147 void progressMade(const int progress);
149 void editorFocusIn(const QString &filename);
150
151protected:
153 virtual void writeToDevice(QIODevice &device) const;
154
155 void dropEvent(QDropEvent *de) override;
156 void dragMoveEvent(QDragMoveEvent *de) override;
157 void dragEnterEvent(QDragEnterEvent *de) override;
158 QByteArray fromMimeData(const QMimeData *source, bool &rectangular) const override;
159 void focusInEvent(QFocusEvent *fe) override;
160
161private slots:
162
163private:
166 void forwardKeyPressToBase(QKeyEvent *event);
167
169 QString m_filename;
170
176 QsciAPIs *m_completer;
178 static QColor g_success_colour;
180 static QColor g_error_colour;
187};
std::string name
Definition Run.cpp:60
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
double error
std::map< DeltaEMode::Type, std::string > index
Raises a dialog allowing the user to find/replace text in the editor.
Exception type to indicate that saving was cancelled.
const char * what() const noexcept override
Return a message.
This class provides an area to write scripts.
int m_currentExecLine
Hold the line number of the currently executing line.
QsciAPIs * scintillaAPI() const
Return a pointer to the object responsible for code completion.
void undoAvailable(bool)
Inform observers that undo information is available.
int m_progressArrowKey
The margin marker.
void editorFocusIn(const QString &filename)
The editor now has focus.
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
const QString & fileName() const
The current filename.
QsciAPIs * m_completer
A pointer to a QsciAPI object that handles the code completion.
void progressMade(const int progress)
Progress has been made in script execution.
static QColor g_success_colour
The colour of the marker for a success state.
static QColor g_error_colour
The colour of the marker for an error state.
FindReplaceDialog * m_findDialog
A pointer to the find replace dialog.
QString m_filename
The file name associated with this editor.
QString m_settingsGroup
Name of group that the settings are stored under.
void textZoomedIn()
Emitted when a zoom in is requested.
void textZoomedOut()
Emitted when a zoom out is requested.