ScriptingWindow.h 5.96 KB
Newer Older
1
2
3
4
5
6
#ifndef SCRIPTINGWINDOW_H_
#define SCRIPTINGWINDOW_H_

//----------------------------------
// Includes
//----------------------------------
Roman Tolchenov's avatar
Roman Tolchenov committed
7
#include "MantidQtWidgets/Common/IProjectSerialisable.h"
8
#include "Script.h"
9
#include <QMainWindow>
10
11
12
13

//----------------------------------------------------------
// Forward declarations
//---------------------------------------------------------
14
class MultiTabScriptInterpreter;
15
16
17
18
19
class ScriptingEnv;
class QTextEdit;
class QPoint;
class QMenu;
class QAction;
20
class QActionGroup;
21
class QCloseEvent;
22
23
class QShowEvent;
class QHideEvent;
24

25
/** @class ScriptingWindow
26
27
    This class displays a seperate window for editing and executing scripts
*/
28
class ScriptingWindow : public QMainWindow {
29
  /// Qt macro
30
31
32
  Q_OBJECT

public:
33
34
35
36
  /// Constructor
  ScriptingWindow(ScriptingEnv *env, bool capturePrint = true,
                  QWidget *parent = 0, Qt::WindowFlags flags = 0);
  /// Destructor
37
  ~ScriptingWindow() override;
38
  /// Override the closeEvent
39
  void closeEvent(QCloseEvent *event) override;
40
  /// Override the showEvent
41
  void showEvent(QShowEvent *event) override;
42
  /// Is a script running?
43
  bool isExecuting() const;
44
  /// Save the current state of the script window for next time
45
  void saveSettings();
46
47
  /// Read settings from store
  void readSettings();
48
49
  /// Open a script in a new tab. Primarily useful for automatically
  /// opening a script
50
51
52
  void open(const QString &filename, bool newtab = true);
  /// Executes whatever is in the current tab. Primarily useful for
  /// automatically
53
54
  /// running a script loaded with open
  void executeCurrentTab(const Script::ExecutionMode mode);
55
  /// Set whether to accept/reject close events
56
  void acceptCloseEvent(const bool value);
57
  /// Opens a script providing a copy is not already open
58
  void openUnique(QString filename);
59
  /// Saves the open script names to the current project
60
  std::string saveToProject(ApplicationWindow *app);
61
62
  /// Loads the open script names for the current project
  void loadFromProject(const std::string &lines, ApplicationWindow *app,
63
                       const int fileVersion);
Samuel Jackson's avatar
Samuel Jackson committed
64
65
  // Loads the scripts from a list of filenames
  void loadFromFileList(const QStringList &files);
66
67
68
signals:
  /// Show the scripting language dialog
  void chooseScriptingLanguage();
69
70
71
72
  /// Tell others we are closing
  void closeMe();
  /// Tell others we are hiding
  void hideMe();
73

Nick Draper's avatar
Nick Draper committed
74
protected:
75
  /// Accept a custom defined event
76
77
78
79
  void customEvent(QEvent *event) override;
  void dragEnterEvent(QDragEnterEvent *de) override;
  void dragMoveEvent(QDragMoveEvent *de) override;
  void dropEvent(QDropEvent *de) override;
Nick Draper's avatar
Nick Draper committed
80

81
private slots:
82
83
84
85
86
87
88
89
90
91
  /// Populate file menu
  void populateFileMenu();
  /// Ensure the list is up to date
  void populateRecentScriptsMenu();
  /// Populate edit menu
  void populateEditMenu();
  /// Populate execute menu
  void populateExecMenu();
  /// Populate window menu
  void populateWindowMenu();
92
93
  /// Populate help menu
  void populateHelpMenu();
94

95
96
  /// Update window flags
  void updateWindowFlags();
97
98
  /// Update menus based on current tab counts
  void setMenuStates(int nTabs);
99
  /// Sets the execution actions based on the flag
100
  void setEditActionsDisabled(bool off);
101
  /// Sets the execution actions based on the flag
102
103
104
  void setExecutionActionsDisabled(bool off);
  /// Sets the abort actions based on the flag or the environment
  void setAbortActionsDisabled(bool off);
105

106
107
  /// Finds the script corresponding to the action and
  /// asks the manager to open it
108
  void openRecentScript(QAction *);
109

110
111
  /// Execute all using the current mode option
  void executeAll();
112
  /// Execute selection using the current mode option
113
  void executeSelection();
114
115
  /// Abort the current script
  void abortCurrent();
116
117
  /// Clear out any previous variable definitions in the current script
  void clearScriptVariables();
118

119
120
121
122
123
  /// Opens help page for scripting window
  void showHelp();
  /// Opens help page for Python API
  void showPythonHelp();

124
125
126
127
128
129
130
131
132
133
134
135
136
137
private:
  /// Create menu bar
  void initMenus();

  /// Create all actions
  void initActions();
  /// Create the file actions
  void initFileMenuActions();
  /// Create the edit menu actions
  void initEditMenuActions();
  /// Create the execute menu actions
  void initExecMenuActions();
  /// Create the window menu actions
  void initWindowMenuActions();
138
139
  /// Create the help menu actions
  void initHelpMenuActions();
140

141
142
  /// Should we enable abort functionality
  bool shouldEnableAbort() const;
143
144
  /// Opens tabs based on QStringList
  void openPreviousTabs(const QStringList &tabsToOpen);
145
146
147
  /// Returns the current execution mode
  Script::ExecutionMode getExecutionMode() const;

Nick Draper's avatar
Nick Draper committed
148
  /// Extract py files from urllist
149
  QStringList extractPyFiles(const QList<QUrl> &urlList) const;
150

151
private:
152
  /// The script editors' manager
153
  MultiTabScriptInterpreter *m_manager;
154

155
  /// File menu
156
157
  QMenu *m_fileMenu;
  /// File menu actions
158
159
  QAction *m_newTab, *m_openInCurTab, *m_openInNewTab, *m_save, *m_saveAs,
      *m_print, *m_closeTab;
160
  QMenu *m_recentScripts;
161
  /// Edit menu
162
163
  QMenu *m_editMenu;
  /// Edit menu actions
164
  QAction *m_undo, *m_redo, *m_cut, *m_copy, *m_paste, *m_comment, *m_uncomment,
165
      *m_tabsToSpaces, *m_spacesToTabs, *m_find;
166
  /// Run menu
167
168
  QMenu *m_runMenu;
  /// Execute menu actions
169
  QAction *m_execSelect, *m_execAll, *m_abortCurrent, *m_clearScriptVars;
170
171
172
173
174
175
  /// Execution mode menu
  QMenu *m_execModeMenu;
  /// Execute mode actions
  QAction *m_execParallel, *m_execSerial;
  /// Action group for execution mode
  QActionGroup *m_execModeGroup;
176
  /// Window menu
177
  QMenu *m_windowMenu;
178
  /// Window actions
179
  QAction *m_alwaysOnTop, *m_hide, *m_zoomIn, *m_zoomOut, *m_resetZoom,
180
181
      *m_toggleProgress, *m_toggleFolding, *m_toggleWrapping,
      *m_toggleWhitespace, *m_openConfigTabs, *m_selectFont;
182
183
184
185
  /// Help menu
  QMenu *m_helpMenu;
  /// Help actions
  QAction *m_showHelp, *m_showPythonHelp;
186
187
  /// Change scripting language
  QAction *m_scripting_lang;
188
189
  /// Flag to define whether we should accept a close event
  bool m_acceptClose;
190
191
};

192
#endif // SCRIPTINGWINDOW_H_