Mantid
|
This class provides an area to write scripts. More...
#include <ScriptEditor.h>
Classes | |
class | SaveCancelledException |
Exception type to indicate that saving was cancelled. More... | |
Public Slots | |
void | markExecutingLineAsError () |
Mark the progress arrow as an error. More... | |
void | padMargin () |
Ensure the margin width is big enough to hold everything + padding. More... | |
void | print () |
Print the text within the widget. More... | |
void | saveAs () |
Save the script, opening a dialog. More... | |
void | saveScript (const QString &filename) |
Save a the text to the given filename. More... | |
void | saveToCurrentFile () |
Save to the current filename, opening a dialog if blank. More... | |
void | setMarkerState (bool enabled) |
Set the marker state. More... | |
virtual void | showFindReplaceDialog () |
Raise find replace dialog. More... | |
void | updateCompletionAPI (const QStringList &keywords) |
Refresh the autocomplete information base on a new set of keywords. More... | |
void | updateProgressMarker (int lineno, bool error=false) |
Update the progress marker. More... | |
void | updateProgressMarkerFromThread (int lineno, bool error=false) |
Update the progress marker potentially from a separate thread. More... | |
void | zoomTo (int level) override |
Override zoomTo slot. More... | |
Signals | |
void | fileNameChanged (const QString &fileName) |
Notify that the filename has been modified. More... | |
void | progressMade (const int progress) |
Progress has been made in script execution. More... | |
void | redoAvailable (bool) |
Inform observers that redo information is available. More... | |
void | textZoomedIn () |
Emitted when a zoom in is requested. More... | |
void | textZoomedOut () |
Emitted when a zoom out is requested. More... | |
void | undoAvailable (bool) |
Inform observers that undo information is available. More... | |
Public Member Functions | |
void | clearKeyBinding (const QString &keyCombination) |
Clear keyboard shortcut binding. More... | |
void | disableAutoCompletion () |
Disable the auto complete. More... | |
void | enableAutoCompletion (AutoCompletionSource source=QsciScintilla::AcsAPIs) |
Enable the auto complete. More... | |
QString | fileName () const |
The current filename. More... | |
int | getZoom () const |
Get the current zoom factor. More... | |
void | keyPressEvent (QKeyEvent *event) override |
Capture key presses. More... | |
void | readSettings () |
Read settings from persistent store. More... | |
void | replaceAll (const QString &search, const QString &replace, bool regex, bool caseSensitive, bool matchWords, bool wrap, bool forward=true) |
Replace all occurences of a string. More... | |
QsciAPIs * | scintillaAPI () const |
Return a pointer to the object responsible for code completion. More... | |
ScriptEditor (const QString &lexerName, const QFont &font=QFont(), QWidget *parent=nullptr) | |
Construction based on a string defining the langauge used for syntax highlighting. More... | |
ScriptEditor (QWidget *parent=nullptr, QsciLexer *lexer=nullptr, QString settingsGroup="") | |
Constructor. More... | |
void | setAutoMarginResize () |
Make the object resize to margin to fit the contents with padding. More... | |
void | setFileName (const QString &filename) |
Set a new file name. More... | |
void | setLexer (QsciLexer *) override |
Set a new code lexer for this object. More... | |
void | setSettingsGroup (const QString &name) |
Set the name of the group to save the settings for. More... | |
void | setText (int lineno, const QString &text, int index=0) |
Set the text on a given line number. More... | |
QString | settingsGroup () const |
Settings group. More... | |
QSize | sizeHint () const override |
Default size hint. More... | |
void | wheelEvent (QWheelEvent *e) override |
Override so that ctrl + mouse wheel will zoom in and out. More... | |
void | writeSettings () |
Write settings from persistent store. More... | |
~ScriptEditor () override | |
Destructor. More... | |
Protected Member Functions | |
void | dragEnterEvent (QDragEnterEvent *de) override |
Accept a drag enter event and selects whether to accept the action. More... | |
void | dragMoveEvent (QDragMoveEvent *de) override |
Accept a drag move event and selects whether to accept the action. More... | |
void | dropEvent (QDropEvent *de) override |
Accept a drag drop event and process the data appropriately. More... | |
QByteArray | fromMimeData (const QMimeData *source, bool &rectangular) const override |
If the QMimeData object holds workspaces names then extract text from a QMimeData object and add the necessary wrapping text to import mantid. More... | |
virtual void | writeToDevice (QIODevice &device) const |
Write to the given device. More... | |
Private Member Functions | |
void | forwardKeyPressToBase (QKeyEvent *event) |
Forward a KeyPress event to QsciScintilla base class. More... | |
Private Attributes | |
QsciAPIs * | m_completer |
A pointer to a QsciAPI object that handles the code completion. More... | |
int | m_currentExecLine |
Hold the line number of the currently executing line. More... | |
QString | m_filename |
The file name associated with this editor. More... | |
FindReplaceDialog * | m_findDialog |
A pointer to the find replace dialog. More... | |
int | m_previousKey |
previous key More... | |
int | m_progressArrowKey |
The margin marker. More... | |
QString | m_settingsGroup |
Name of group that the settings are stored under. More... | |
Static Private Attributes | |
static QColor | g_error_colour = QColor("red") |
The colour of the marker for an error state. More... | |
static QColor | g_success_colour = QColor("lightgreen") |
The colour of the marker for a success state. More... | |
This class provides an area to write scripts.
It inherits from QScintilla to use functionality such as auto-indent and if supported, syntax highlighting.
Definition at line 37 of file ScriptEditor.h.
ScriptEditor::ScriptEditor | ( | const QString & | lexerName, |
const QFont & | font = QFont() , |
||
QWidget * | parent = nullptr |
||
) |
Construction based on a string defining the langauge used for syntax highlighting.
lexerName | A string choosing the name of a lexer |
font | A reference to the initial font to be used in the editor |
parent | Parent widget |
Definition at line 79 of file ScriptEditor.cpp.
ScriptEditor::ScriptEditor | ( | QWidget * | parent = nullptr , |
QsciLexer * | codelexer = nullptr , |
||
QString | settingsGroup = "" |
||
) |
Constructor.
parent | The parent widget (can be NULL) |
codelexer | define the syntax highlighting and code completion. |
settingsGroup | Used when saving settings to persistent store |
Definition at line 88 of file ScriptEditor.cpp.
References clearKeyBinding(), readSettings(), redoAvailable(), setLexer(), and undoAvailable().
|
override |
void ScriptEditor::clearKeyBinding | ( | const QString & | keyCombination | ) |
Clear keyboard shortcut binding.
if key identifier bound to a command
Definition at line 329 of file ScriptEditor.cpp.
Referenced by ScriptEditor().
void ScriptEditor::disableAutoCompletion | ( | ) |
Disable the auto complete.
Definition at line 197 of file ScriptEditor.cpp.
|
overrideprotected |
Accept a drag enter event and selects whether to accept the action.
de | :: The drag enter event |
Definition at line 466 of file ScriptEditor.cpp.
|
overrideprotected |
Accept a drag move event and selects whether to accept the action.
de | :: The drag move event |
Definition at line 456 of file ScriptEditor.cpp.
|
overrideprotected |
Accept a drag drop event and process the data appropriately.
de | :: The drag drop event |
Definition at line 488 of file ScriptEditor.cpp.
void ScriptEditor::enableAutoCompletion | ( | AutoCompletionSource | source = QsciScintilla::AcsAPIs | ) |
Enable the auto complete.
Default is for backwards compatability with existing code
Definition at line 187 of file ScriptEditor.cpp.
|
inline |
The current filename.
Definition at line 88 of file ScriptEditor.h.
Referenced by saveToCurrentFile().
|
signal |
Notify that the filename has been modified.
Referenced by setFileName().
|
private |
Forward a KeyPress event to QsciScintilla base class.
Forward the QKeyEvent to the QsciScintilla base class.
Necessary due to bug in QsciScintilla
Under Gnome on Linux with Qscintilla versions < 2.4.2 there is a bug with the autocomplete box that means the editor loses focus as soon as it the box appears. This functions forwards the call and sets the correct flags on the resulting window so that this does not occur
Definition at line 544 of file ScriptEditor.cpp.
Referenced by keyPressEvent().
|
overrideprotected |
If the QMimeData object holds workspaces names then extract text from a QMimeData object and add the necessary wrapping text to import mantid.
source | An existing QMimeData object |
rectangular | On return rectangular is set if the text corresponds to a rectangular selection. |
Definition at line 480 of file ScriptEditor.cpp.
int ScriptEditor::getZoom | ( | ) | const |
Get the current zoom factor.
Definition at line 614 of file ScriptEditor.cpp.
|
override |
Capture key presses.
Enter/Return executes the code or asks for more input if necessary. Up/Down search the command history
event | A pointer to the QKeyPressEvent object |
Definition at line 280 of file ScriptEditor.cpp.
References forwardKeyPressToBase(), textZoomedIn(), and textZoomedOut().
|
slot |
Mark the progress arrow as an error.
Definition at line 412 of file ScriptEditor.cpp.
References m_currentExecLine, and updateProgressMarker().
|
slot |
Ensure the margin width is big enough to hold everything + padding.
Ensure the margin width is big enough to hold everything.
Definition at line 347 of file ScriptEditor.cpp.
Referenced by setAutoMarginResize().
|
slot |
Print the text within the widget.
Print the current text.
Definition at line 499 of file ScriptEditor.cpp.
|
signal |
Progress has been made in script execution.
Referenced by updateProgressMarker().
void ScriptEditor::readSettings | ( | ) |
Read settings from persistent store.
Read settings saved to persistent store.
Definition at line 145 of file ScriptEditor.cpp.
Referenced by ScriptEditor().
|
signal |
Inform observers that redo information is available.
Referenced by ScriptEditor().
void ScriptEditor::replaceAll | ( | const QString & | search, |
const QString & | replace, | ||
bool | regex, | ||
bool | caseSensitive, | ||
bool | matchWords, | ||
bool | wrap, | ||
bool | forward = true |
||
) |
Replace all occurences of a string.
Definition at line 587 of file ScriptEditor.cpp.
References index.
Referenced by FindReplaceDialog::replaceAll().
|
slot |
Save the script, opening a dialog.
Save the script, opening a dialog to ask for the filename.
Definition at line 211 of file ScriptEditor.cpp.
References saveScript().
Referenced by saveToCurrentFile().
|
slot |
Save a the text to the given filename.
Save the text to the given filename.
filename | :: The filename to use |
std::runtime_error | if the file could not be opened |
Definition at line 244 of file ScriptEditor.cpp.
References m_filename, and writeToDevice().
Referenced by saveAs(), and saveToCurrentFile().
|
slot |
Save to the current filename, opening a dialog if blank.
Definition at line 229 of file ScriptEditor.cpp.
References fileName(), saveAs(), and saveScript().
|
inline |
Return a pointer to the object responsible for code completion.
Definition at line 99 of file ScriptEditor.h.
void ScriptEditor::setAutoMarginResize | ( | ) |
Make the object resize to margin to fit the contents with padding.
Definition at line 182 of file ScriptEditor.cpp.
References padMargin().
void ScriptEditor::setFileName | ( | const QString & | filename | ) |
Set a new file name.
Definition at line 304 of file ScriptEditor.cpp.
References fileNameChanged(), and m_filename.
|
override |
Set a new code lexer for this object.
Note that this clears all auto complete information
Definition at line 156 of file ScriptEditor.cpp.
References m_completer.
Referenced by ScriptEditor().
|
slot |
Set the marker state.
enabled | :: If true then the progress arrow is enabled |
Definition at line 361 of file ScriptEditor.cpp.
References m_progressArrowKey.
void ScriptEditor::setSettingsGroup | ( | const QString & | name | ) |
Set the name of the group to save the settings for.
name | The name of the group |
Definition at line 133 of file ScriptEditor.cpp.
References m_settingsGroup.
void ScriptEditor::setText | ( | int | lineno, |
const QString & | txt, | ||
int | index = 0 |
||
) |
Set the text on a given line number.
Set the text on the given line, something I feel is missing from the QScintilla API.
Note that like QScintilla line numbers start from 0
lineno | :: A zero-based index representing the linenumber, |
txt | :: The text to insert at the given line |
index | :: The position of text in a line number,default value is zero |
Definition at line 265 of file ScriptEditor.cpp.
References index.
QString ScriptEditor::settingsGroup | ( | ) | const |
Settings group.
Returns a string containing the settings group to use
Definition at line 140 of file ScriptEditor.cpp.
References m_settingsGroup.
|
virtualslot |
Raise find replace dialog.
Raises the find replace dialog.
Definition at line 513 of file ScriptEditor.cpp.
References m_findDialog.
|
override |
Default size hint.
Definition at line 206 of file ScriptEditor.cpp.
|
signal |
Emitted when a zoom in is requested.
Referenced by keyPressEvent(), and wheelEvent().
|
signal |
Emitted when a zoom out is requested.
Referenced by keyPressEvent(), and wheelEvent().
|
signal |
Inform observers that undo information is available.
Referenced by ScriptEditor().
|
slot |
Refresh the autocomplete information base on a new set of keywords.
Update the completion API with a new list of keywords.
Note that the old is cleared
2012-08-14 M. Gigg: QScintilla v2.6.1 contains a bug surrounding the calltips. If the entire list of completions is exhausted then the underlying API keeps on trying to iterate further due to a bug in the stopping condition. It sorts the keyword list so that it can quickly jump to a starting point when trying to match what the user has typed with the completions it has. A short cut out is when it first checks that the current completion starts with the users' text and if not the loop is halted correctly.
This line adds a single character that is guaranteed to be after all of the other completions (due to ascii ordering) but is not alpha-numeric so a user would not want to complete on it. Even better it won't show up in the auto complete list because a user has to type at least 2 characters for that to appear.
Definition at line 418 of file ScriptEditor.cpp.
References m_completer.
|
slot |
Update the progress marker.
Update the arrow marker to point to the correct line and colour it depending on the error state.
lineno | :: The line to place the marker at. A negative number will clear all markers |
error | :: If true, the marker will turn red |
Definition at line 393 of file ScriptEditor.cpp.
References error, g_error_colour, g_success_colour, m_currentExecLine, m_progressArrowKey, and progressMade().
Referenced by markExecutingLineAsError(), and updateProgressMarkerFromThread().
|
slot |
Update the progress marker potentially from a separate thread.
Update the arrow marker to point to the correct line and colour it depending on the error state.
If the call is from a thread other than the application thread then the call is reperformed on that thread
lineno | :: The line to place the marker at. A negative number will clear all markers |
error | :: If true, the marker will turn red |
Definition at line 378 of file ScriptEditor.cpp.
References error, and updateProgressMarker().
|
override |
Override so that ctrl + mouse wheel will zoom in and out.
Ctrl + Rotating the mouse wheel will increase/decrease the font size.
Definition at line 312 of file ScriptEditor.cpp.
References textZoomedIn(), and textZoomedOut().
void ScriptEditor::writeSettings | ( | ) |
Write settings from persistent store.
Read settings saved to persistent store.
Definition at line 150 of file ScriptEditor.cpp.
|
protectedvirtual |
Write to the given device.
Definition at line 531 of file ScriptEditor.cpp.
Referenced by saveScript().
|
overrideslot |
Override zoomTo slot.
Override the zoomTo slot to make the font size larger on Mac as the defaults are tiny.
level | Set the font size to this level of zoom |
Definition at line 520 of file ScriptEditor.cpp.
|
staticprivate |
The colour of the marker for an error state.
Definition at line 178 of file ScriptEditor.h.
Referenced by updateProgressMarker().
|
staticprivate |
The colour of the marker for a success state.
Definition at line 176 of file ScriptEditor.h.
Referenced by updateProgressMarker().
|
private |
A pointer to a QsciAPI object that handles the code completion.
Definition at line 174 of file ScriptEditor.h.
Referenced by setLexer(), updateCompletionAPI(), and ~ScriptEditor().
|
private |
Hold the line number of the currently executing line.
Definition at line 172 of file ScriptEditor.h.
Referenced by markExecutingLineAsError(), and updateProgressMarker().
|
private |
The file name associated with this editor.
Definition at line 167 of file ScriptEditor.h.
Referenced by saveScript(), and setFileName().
|
private |
A pointer to the find replace dialog.
Definition at line 182 of file ScriptEditor.h.
Referenced by showFindReplaceDialog().
|
private |
previous key
Definition at line 180 of file ScriptEditor.h.
|
private |
The margin marker.
Definition at line 170 of file ScriptEditor.h.
Referenced by setMarkerState(), and updateProgressMarker().
|
private |
Name of group that the settings are stored under.
Definition at line 184 of file ScriptEditor.h.
Referenced by setSettingsGroup(), and settingsGroup().