itom
Loading...
Searching...
No Matches
scriptDockWidget.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef SCRIPTDOCKWIDGET_H
24#define SCRIPTDOCKWIDGET_H
25
26#include "abstractDockWidget.h"
27#include "itomQWidgets.h"
28#include "outlineSelectorWidget.h"
29#include "scriptEditorWidget.h"
30#include "tabSwitcherWidget.h"
31
32#include <qaction.h>
33#include <qcombobox.h>
34#include <qpointer.h>
35#include <qsharedpointer.h>
36#include <qstring.h>
37#include <qtoolbar.h>
38
39#include "../models/bookmarkModel.h"
40#include "../models/outlineItem.h"
41
42#include <qevent.h>
43
44#include "../ui/widgetFindWord.h"
45
46namespace ito {
47
48class DialogReplace; // forward declaration
49
52{
53 QAction* actNavigationForward;
54 QAction* actNavigationBackward;
55};
56
57
59{
60 Q_OBJECT
61public:
63 const QString& title,
64 const QString& objName,
65 bool docked,
66 bool isDockAvailable,
67 const ScriptEditorActions& commonActions,
68 BookmarkModel* bookmarkModel,
69 QWidget* parent = 0,
70 Qt::WindowFlags flags = Qt::WindowFlags());
72
73 QStringList getModifiedFilenames(bool ignoreNewScripts = false, int excludeIndex = -1) const;
74 QStringList getAllFilenames() const;
75 void getAllCanonicalFilenamesWithModificationState(QStringList &filenames, QList<bool> &modified) const;
76
79 RetVal openScript(QString filename, bool silent = false);
81 bool askFirst = true, bool ignoreNewScripts = false, int excludeIndex = -1);
83 bool saveFirst = true,
84 bool askFirst = true,
85 bool ignoreNewScripts = false,
86 int excludeIndex = -1,
87 bool closeScriptWidgetIfLastTabClosed = true);
88
89 inline bool isTabIndexValid(int tabIndex) const
90 {
91 return (tabIndex >= 0 && tabIndex < m_tab->count());
92 }
93 inline int getTabCount() const
94 {
95 return m_tab->count();
96 }
97 inline int getCurrentIndex() const
98 {
99 return m_tab->currentIndex();
100 }
101 void setCurrentIndex(int index);
102
103 bool containsNewScripts() const;
104
105 RetVal appendEditor(ScriptEditorWidget* editorWidget);
107 ScriptEditorWidget* removeEditor(
108 int index);
110 ScriptEditorWidget* getCurrentEditor() const;
111
112 bool activateTabByFilename(const QString& filename, int currentDebugLine = -1, int UID = -1);
113 bool activeTabEnsureLineVisible(
114 const int lineNr, bool errorMessageClick = false, bool showSelectedCallstackLine = false);
115 void activeTabShowLineAndHighlightWord(
116 const int line,
117 const QString& highlightedText,
118 Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive);
119 const QTabWidget* tabWidget() const
120 {
121 return m_tab;
122 }
123
124 QList<ito::ScriptEditorStorage> saveScriptState() const;
125 RetVal restoreScriptState(const QList<ito::ScriptEditorStorage>& states);
126
128 QList<OutlineSelectorWidget::EditorOutline> getAllOutlines(int& activeIndex) const;
129
130 ScriptEditorWidget* getEditorByCanonicalFilepath(const QString &filepath) const;
131
132protected:
133 ScriptEditorWidget* getEditorByIndex(int index) const;
134
135 int getIndexByEditor(const ScriptEditorWidget* sew) const;
136 void tabFilenameOrModificationChanged(int index);
137
138 void createActions();
139 // void deleteActions();
140 void createMenus();
141 void createToolBars();
142 void createStatusBar();
143 void closeEvent(QCloseEvent* event);
144 virtual void windowStateChanged(bool windowNotToolbox);
145
146 RetVal closeTab(int index, bool saveFirst = true, bool closeScriptWidgetIfLastTabClosed = true);
147 RetVal saveTab(int index, bool forceSaveAs = false, bool askFirst = true);
148
149private:
150 QWidget* m_pCenterWidget;
151 QVBoxLayout* m_pVBox;
153 WidgetFindWord* m_pWidgetFindWord;
154 DialogReplace* m_pDialogReplace;
155 BookmarkModel* m_pBookmarkModel;
158
159 static const char* statusBarStatePropertyName;
160
164 /*
165 This list is used to initialize the tabSwitcherWidget if Ctrl+Tab is pressed.
166 */
167 QList<int> m_stackHistory;
168
169 QSharedPointer<TabSwitcherWidget> m_tabSwitcherWidget;
170 QSharedPointer<OutlineSelectorWidget> m_outlineSelectorWidget;
171
172 // ACTIONS
173 ShortcutAction* m_tabMoveLeftAction;
174 ShortcutAction* m_tabMoveRightAction;
175 ShortcutAction* m_tabMoveFirstAction;
176 ShortcutAction* m_tabMoveLastAction;
177 ShortcutAction* m_tabCloseAction;
178 ShortcutAction* m_tabCloseOthersAction;
179 ShortcutAction* m_tabCloseAllAction;
180 ShortcutAction* m_tabDockAction;
181 ShortcutAction* m_tabUndockAction;
182 ShortcutAction* m_newScriptAction;
183 ShortcutAction* m_openScriptAction;
184 ShortcutAction* m_saveScriptAction;
185 ShortcutAction* m_saveScriptAsAction;
186 ShortcutAction* m_saveAllScriptsAction;
187 ShortcutAction* m_printAction;
188 ShortcutAction* m_cutAction;
189 ShortcutAction* m_copyAction;
190 ShortcutAction* m_pasteAction;
191 ShortcutAction* m_undoAction;
192 ShortcutAction* m_redoAction;
193 ShortcutAction* m_commentAction;
194 ShortcutAction* m_uncommentAction;
195 ShortcutAction* m_indentAction;
196 ShortcutAction* m_unindentAction;
197 ShortcutAction* m_autoCodeFormatAction;
198 ShortcutAction* m_referenceRenameAction;
199 ShortcutAction* m_pyDocstringGeneratorAction;
200 ShortcutAction* m_scriptRunAction;
201 ShortcutAction* m_scriptRunSelectionAction;
202 ShortcutAction* m_scriptDebugAction;
203 ShortcutAction* m_scriptStopAction;
204 ShortcutAction* m_scriptContinueAction;
205 ShortcutAction* m_scriptStepAction;
206 ShortcutAction* m_scriptStepOverAction;
207 ShortcutAction* m_scriptStepOutAction;
208 ShortcutAction* m_findTextExprAction;
209 ShortcutAction* m_findTextExprActionSC;
210 ShortcutAction* m_replaceTextExprAction;
211 ShortcutAction* m_gotoAction;
212 ShortcutAction* m_openIconBrowser;
213 ShortcutAction* m_bookmarkToggle;
214
215 ShortcutAction* m_insertCodecAct;
216 ShortcutAction* m_copyFilename;
217 ShortcutAction* m_findSymbols;
218
219 ScriptEditorActions m_commonActions;
220
221 QMenu* m_tabContextMenu;
222 QMenu* m_fileMenu;
223 QMenu* m_lastFilesMenu;
224 QMenu* m_editMenu;
225 QMenu* m_scriptMenu;
226 QMenu* m_winMenu;
227 QMenu* m_bookmark;
228
229 QToolBar* m_fileToolBar;
230 QToolBar* m_editToolBar;
231 QToolBar* m_scriptToolBar;
232 QToolBar* m_bookmarkToolBar;
233
234 QString m_autoCodeFormatCmd;
235
236 // ClassNavigator
237 QWidget* m_classMenuBar;
238 QComboBox* m_classBox;
239 QComboBox* m_methodBox;
240 bool m_outlineShowNavigation;
241 void fillNavigationClassComboBox(
242 const QSharedPointer<OutlineItem>& parent, const QString& prefix);
243 void fillNavigationMethodComboBox(
244 const QSharedPointer<OutlineItem>& parent, const QString& prefix);
245 void showOutlineNavigationBar(bool show);
246
247 static QPointer<ScriptEditorWidget>
248 currentSelectedCallstackLineEditor; // this static variable holds the (weak) pointer to the
249 // script editor widget that received the last "selected
250 // callstack line" selector.
251
252
253signals:
255 ScriptDockWidget* widget);
259 const QString& filename,
260 ScriptDockWidget* scriptDockWidget);
264 ScriptDockWidget* widget,
265 int index,
266 bool closeDockIfEmpty =
267 false);
270 ScriptDockWidget* widget,
271 int index,
272 bool undockToNewScriptWindow = false,
273 bool closeDockIfEmpty =
274 false);
277 void pythonRunFileRequest(QString filename);
279 void pythonDebugFileRequest(QString filename);
282 void pythonDebugCommand(tPythonDbgCmd cmd);
284 QString selectionText);
286 void addGoBackNavigationItem(const GoBackNavigationItem& item);
287
288 void statusBarInformationChanged(
289 const QPointer<ScriptDockWidget> sourceDockWidget,
290 const QString& encoding,
291 int line,
292 int column);
293
294private slots:
295 void tabContextMenuEvent(QContextMenuEvent* event);
296
297 void findTextExpr(
298 QString expr,
299 bool regExpr,
300 bool caseSensitive,
301 bool wholeWord,
302 bool wrap,
303 bool forward,
304 bool isQuickSeach);
305 void replaceTextExpr(QString expr, QString replace);
306 void replaceAllExpr(
307 QString expr,
308 QString replace,
309 bool regExpr,
310 bool caseSensitive,
311 bool wholeWord,
312 bool findInSel);
313 void insertIconBrowserText(QString iconLink);
314
315 void currentTabChanged(int index);
316 void tabCloseRequested(int index);
317 void tabCloseRequested(ScriptEditorWidget* sew, bool ignoreModifications);
318 void scriptModificationChanged(bool changed);
319
320 void updateEditorActions();
321 void updatePythonActions();
323
324 void mnuOpenIconBrowser();
325
326 void mnuTabMoveLeft();
327 void mnuTabMoveRight();
328 void mnuTabMoveFirst();
329 void mnuTabMoveLast();
330 void mnuTabClose();
331 void mnuTabCloseOthers();
332 void mnuTabCloseAll();
333 void mnuTabDock();
334 void mnuTabUndock();
335 void mnuNewScript();
336 void mnuOpenScript();
337 void mnuSaveScript();
338 void mnuSaveScriptAs();
339 void mnuSaveAllScripts();
340 void mnuPrint();
341 void mnuCut();
342 void mnuCopy();
343 void mnuPaste();
344 void mnuUndo();
345 void mnuRedo();
346 void mnuComment();
347 void mnuUncomment();
348 void mnuIndent();
349 void mnuUnindent();
350 void mnuScriptRun();
351 void mnuScriptRunSelection();
352 void mnuScriptDebug();
353 void mnuScriptStop();
354 void mnuScriptContinue();
355 void mnuScriptStep();
356 void mnuScriptStepOver();
357 void mnuScriptStepOut();
358 void mnuFindTextExpr();
359 void mnuReplaceTextExpr();
360 void mnuGoto();
361 void mnuToggleBookmark();
362 void mnuInsertCodec();
363 void mnuCopyFilename();
364 void mnuPyCodeFormatting();
365 void mnuPyReferenceRenaming();
366 void mnuPyDocstringGenerator();
367
368
369 void menuLastFilesAboutToShow();
370 void lastFileOpen(const QString& path);
371
372 // Class Navigator
373 void navigatorClassSelected(int row);
374 void navigatorMethodSelected(int row);
375
376 void loadSettings();
377 void findWordWidgetFinished();
378
379 void currentScriptCursorPositionChanged();
380
381public slots:
382 void editorMarginChanged();
383 void updateCodeNavigation(ScriptEditorWidget* editor, QSharedPointer<OutlineItem> rootItem);
384 void tabChangedRequest();
385 void mnuFindSymbolsShow();
386};
387
388} // end namespace ito
389
390#endif
abstract dock widget class which inherits QDockWidget. The content of QDockWidget consists of an inst...
Definition abstractDockWidget.h:55
model for management of all bookmarks. This model will be displayed by a viewer-widget in the main wi...
Definition bookmarkModel.h:65
Definition dialogReplace.h:38
Definition itomQWidgets.h:43
Class for managing status values (like errors or warning)
Definition retVal.h:54
widget containing one or multiple script editors (tabbed). This widget can either be a docking widget...
Definition scriptDockWidget.h:59
ScriptEditorWidget * getEditorByIndex(int index) const
returns ScriptEditorWidget by given tab-index
Definition scriptDockWidget.cpp:1473
void mnuTabUndock()
undock the active tab and closes this ScriptDockWidget, if it is not docked and empty after docking
Definition scriptDockWidget.cpp:2327
RetVal saveAllScripts(bool askFirst=true, bool ignoreNewScripts=false, int excludeIndex=-1)
tries to save all opened scripts in this ScriptDockWidget
Definition scriptDockWidget.cpp:977
void mnuScriptStepOver()
slot invoked to execute a python debugging step over
Definition scriptDockWidget.cpp:2571
void pythonDebugCommand(tPythonDbgCmd cmd)
void mnuTabMoveFirst()
moves active tab to the first position
Definition scriptDockWidget.cpp:2276
void mnuTabMoveLeft()
moves active tab by one position to the left
Definition scriptDockWidget.cpp:2241
bool activateTabByFilename(const QString &filename, int currentDebugLine=-1, int UID=-1)
activates tab with script whose filename corresponds to the filename parameter (or the UID,...
Definition scriptDockWidget.cpp:2128
void openScriptRequest(const QString &filename, ScriptDockWidget *scriptDockWidget)
void mnuSaveScriptAs()
slot invoked by action to save active script with new filename (save as)
Definition scriptDockWidget.cpp:2360
void createMenus()
create menus
Definition scriptDockWidget.cpp:1914
QStringList getAllFilenames() const
returns a list of all filenames of all opened scripts (besides new scripts)
Definition scriptDockWidget.cpp:830
void mnuCopy()
slot invoked to execute a copy command in active script editor
Definition scriptDockWidget.cpp:2413
void mnuTabDock()
dock the active tab and closes this ScriptDockWidget, if it is not docked and empty after docking
Definition scriptDockWidget.cpp:2320
void mnuOpenScript()
slot invoked by action to open an existing script
Definition scriptDockWidget.cpp:2342
void mnuScriptStop()
slot invoked to stop python script execution
Definition scriptDockWidget.cpp:2546
RetVal closeTab(int index, bool saveFirst=true, bool closeScriptWidgetIfLastTabClosed=true)
public method to close any specific tab with or without saving its script first
Definition scriptDockWidget.cpp:1404
void closeEvent(QCloseEvent *event)
this method is invoked if this ScriptDockWidget should be closed.
Definition scriptDockWidget.cpp:2771
bool containsNewScripts() const
checks whether any editor in this ScriptDockWidget has no filename
Definition scriptDockWidget.cpp:1187
RetVal newScript()
creates new instance of ScriptEditorWidget and appends it to the tab-widget
Definition scriptDockWidget.cpp:860
QTabWidgetItom * m_tab
Definition scriptDockWidget.h:152
ScriptDockWidget(const QString &title, const QString &objName, bool docked, bool isDockAvailable, const ScriptEditorActions &commonActions, BookmarkModel *bookmarkModel, QWidget *parent=0, Qt::WindowFlags flags=Qt::WindowFlags())
constructor
Definition scriptDockWidget.cpp:76
void mnuScriptRun()
slot invoked to run the active script in python engine
Definition scriptDockWidget.cpp:2496
void mnuIndent()
slot invoked to execute an indentation command in active script editor
Definition scriptDockWidget.cpp:2474
int m_actTabIndex
indices of the tabs. The most recently activated tab index is at the front.
Definition scriptDockWidget.h:161
void dockScriptTab(ScriptDockWidget *widget, int index, bool closeDockIfEmpty=false)
void scriptModificationChanged(bool changed)
slot connected to each ScriptEditorWidget instance. Invoked if any content in any script changed.
Definition scriptDockWidget.cpp:1340
void pythonRunFileRequest(QString filename)
void mnuCut()
slot invoked to execute a cut command in active script editor
Definition scriptDockWidget.cpp:2402
void tabContextMenuEvent(QContextMenuEvent *event)
method is invoked, if a context menu is requested
Definition scriptDockWidget.cpp:1529
void updateTabContextActions()
updates actions before context menu of tabs is shown
Definition scriptDockWidget.cpp:1643
void mnuUnindent()
slot invoked to execute an unindentation command in active script editor
Definition scriptDockWidget.cpp:2485
int getTabCount() const
Definition scriptDockWidget.h:93
void mnuUncomment()
slot invoked to execute an uncomment command in active script editor
Definition scriptDockWidget.cpp:2463
void createToolBars()
create toolbars
Definition scriptDockWidget.cpp:2007
RetVal openScript()
method to open an existing script which can be indicated by the user by a getOpenFileName-dialog.
Definition scriptDockWidget.cpp:877
void mnuTabCloseOthers()
closes every tab besides active one (asks for saving tabs, which should be closed)
Definition scriptDockWidget.cpp:2306
void mnuScriptStepOut()
slot invoked to execute a python debugging step out
Definition scriptDockWidget.cpp:2578
void undockScriptTab(ScriptDockWidget *widget, int index, bool undockToNewScriptWindow=false, bool closeDockIfEmpty=false)
RetVal appendEditor(ScriptEditorWidget *editorWidget)
append given ScriptEditorWidget as new tab
Definition scriptDockWidget.cpp:1066
RetVal saveTab(int index, bool forceSaveAs=false, bool askFirst=true)
saves tab
Definition scriptDockWidget.cpp:1442
void mnuNewScript()
slot invoked by action to open a new script
Definition scriptDockWidget.cpp:2335
void createActions()
creates actions
Definition scriptDockWidget.cpp:1673
QLabel * m_pStatusBarWidget
Definition scriptDockWidget.h:157
void createStatusBar()
init status bar
Definition scriptDockWidget.cpp:2060
int getIndexByEditor(const ScriptEditorWidget *sew) const
returns tab-index by given reference to ScriptEditorWidget
Definition scriptDockWidget.cpp:1492
void mnuCopyFilename()
slot invoked by action to copy the filename to clipboard
Definition scriptDockWidget.cpp:2963
void showOutlineNavigationBar(bool show)
< displays or hides the entire outline navigation bar (class and method combo box)
Definition scriptDockWidget.cpp:677
void mnuTabMoveLast()
moves active tab to the last position
Definition scriptDockWidget.cpp:2286
void tabCloseRequested(int index)
slot invoked if close button of any tab of m_tab (QTabWidgetItom) has been pressed
Definition scriptDockWidget.cpp:1371
void mnuSaveScript()
slot invoked by action to save active script
Definition scriptDockWidget.cpp:2349
void mnuScriptContinue()
slot invoked to continue debugging process if actually waiting at breakpoint
Definition scriptDockWidget.cpp:2557
void updateEditorActions()
updates actions which deal with editor commands but are not dependent on the state of python.
Definition scriptDockWidget.cpp:1553
void mnuComment()
slot invoked to execute a comment command in active script editor
Definition scriptDockWidget.cpp:2452
void mnuSaveAllScripts()
slot invoked by action to save all opened scripts
Definition scriptDockWidget.cpp:2376
void mnuTabMoveRight()
moves active tab by one position to the right
Definition scriptDockWidget.cpp:2251
ScriptEditorWidget * removeEditor(int index)
removes ScriptEditorWidget at given tab position from tab-widget and returns its reference
Definition scriptDockWidget.cpp:1126
void removeAndDeleteScriptDockWidget(ScriptDockWidget *widget)
RetVal closeAllScripts(bool saveFirst=true, bool askFirst=true, bool ignoreNewScripts=false, int excludeIndex=-1, bool closeScriptWidgetIfLastTabClosed=true)
closes all opened scripts in this ScriptDockWidget
Definition scriptDockWidget.cpp:1030
void mnuPaste()
slot invoked to execute a paste command in active script editor
Definition scriptDockWidget.cpp:2424
RetVal restoreScriptState(const QList< ito::ScriptEditorStorage > &states)
return all outlines in the tabs of this script dock widget
Definition scriptDockWidget.cpp:717
void pythonDebugFileRequest(QString filename)
void mnuScriptStep()
slot invoked to execute a python debugging step
Definition scriptDockWidget.cpp:2564
~ScriptDockWidget()
destructor
Definition scriptDockWidget.cpp:190
bool isTabIndexValid(int tabIndex) const
Definition scriptDockWidget.h:89
void mnuRedo()
slot invoked to execute a redo command in active script editor
Definition scriptDockWidget.cpp:2444
void pythonRunSelection(QString selectionText)
void mnuUndo()
slot invoked to execute an undo command in active script editor
Definition scriptDockWidget.cpp:2436
void mnuTabCloseAll()
closes every tab, asks for saving first
Definition scriptDockWidget.cpp:2313
QStringList getModifiedFilenames(bool ignoreNewScripts=false, int excludeIndex=-1) const
returns a list of filenames, which have been modified in this ScriptDockWidget
Definition scriptDockWidget.cpp:754
void mnuTabClose()
closes active tab
Definition scriptDockWidget.cpp:2296
void mnuScriptDebug()
slot invoked to debug the active script in python engine
Definition scriptDockWidget.cpp:2526
void updatePythonActions()
Definition scriptDockWidget.cpp:1590
void mnuOpenIconBrowser()
Open the icon browser.
Definition scriptDockWidget.cpp:2261
ScriptEditorWidget * getCurrentEditor() const
returns reference to current ScriptEditorWidget
Definition scriptDockWidget.cpp:1514
void currentTabChanged(int index)
slot invoked by tab-widget if current tab changed
Definition scriptDockWidget.cpp:1273
Definition scriptEditorWidget.h:99
Definition shortcutAction.h:41
Definition widgetFindWord.h:36
Definition apiFunctionsGraph.cpp:40
Definition scriptEditorWidget.h:78
this struct can hold common actions for all script editor and script dock widgets
Definition scriptDockWidget.h:52