itom  4.1.0
scriptEditorOrganizer.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet 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 SCRIPTEDITORORGANIZER_H
24 #define SCRIPTEDITORORGANIZER_H
25 
26 #include "../widgets/scriptDockWidget.h"
27 #include "../widgets/outlineSelectorWidget.h"
28 #include "../common/sharedStructuresQt.h"
29 #include "../models/bookmarkModel.h"
30 
31 #include <qsignalmapper.h>
32 #include <qlist.h>
33 
34 namespace ito
35 {
36 
37 QDataStream &operator<<(QDataStream &out, const ito::ScriptEditorStorage &obj);
38 
39 QDataStream &operator>>(QDataStream &in, ito::ScriptEditorStorage &obj);
40 
41 class ScriptEditorOrganizer : public QObject
42 {
43  Q_OBJECT
44 
45 public:
46  ScriptEditorOrganizer( bool dockAvailable);
48 
49  RetVal saveAllScripts(bool askFirst = true, bool ignoreNewScripts = false, int *saveScriptState = NULL);
50  RetVal closeAllScripts(bool saveFirst);
51 
52  void saveScriptState();
54 
55  const QStringList &getRecentlyUsedFiles() const { return m_recentlyUsedFiles; }
56 
57  inline const ScriptEditorActions& getScriptEditorActions() const { return m_commonScriptEditorActions; }
58 
59  QStringList openedScripts() const;
60 
61  inline BookmarkModel* getBookmarkModel() const
62  {
63  return m_pBookmarkModel;
64  }
65 
66  ScriptDockWidget* activateOpenedScriptByFilename(const QString &filename, int currentDebugLine = -1, int UID = -1);
67 
69  QList<OutlineSelectorWidget::EditorOutline> getAllOutlines(const ScriptDockWidget *currentScriptDockWidget, int &currentIndex) const;
70 
71 protected:
72  ScriptDockWidget* createEmptyScriptDock(bool docked, Qt::DockWidgetArea area = Qt::TopDockWidgetArea, const QString &objectName = QString());
73 
74  RetVal applyGoBackNavigationItem(const GoBackNavigationItem &item);
75  void updateGoBackNavigationActions();
76 
77 private:
81 
82  BookmarkModel *m_pBookmarkModel;
83 
84  QList<ScriptDockWidget*> m_scriptDockElements;
85  QSet<QString> m_usedObjectNames;
88  mutable QMutex m_scriptStackMutex;
89 
90  QStringList m_recentlyUsedFiles;
91 
92  ScriptEditorActions m_commonScriptEditorActions;
93  QMenu *m_pGoBackNavigationMenu;
94  QSignalMapper *m_pGoBackNavigationMapper;
95  QList<GoBackNavigationItem> m_goBackNavigationHistory;
97  static const int MaxGoBackNavigationEntries;
98 
99 signals:
100  void addScriptDockWidgetToMainWindow(AbstractDockWidget *dockWidget, Qt::DockWidgetArea area);
102 
103  void pythonRunFile(QString filename);
104  void pythonDebugFile(QString filename);
105 
106 public slots:
108 
109  void dockScriptTab(ScriptDockWidget* widget, int index, bool closeDockIfEmpty = false);
110  void undockScriptTab(ScriptDockWidget* widget, int index, bool undockToNewScriptWindow = false, bool closeDockIfEmpty = false);
111 
112  RetVal openNewScriptWindow(bool docked, ItomSharedSemaphore* semaphore = NULL);
113  RetVal newScript(ItomSharedSemaphore* semaphore = NULL);
114  RetVal openScript(const QString &filename, ItomSharedSemaphore* semaphore = NULL, int visibleLineNr = -1, bool errorMessageClick = false, bool showSelectedCallstackLine = false);
115 
116  ScriptDockWidget* openScriptRequested(const QString &filename, ScriptDockWidget* widget);
117 
118  void pythonRunFileRequested(QString filename);
119  void pythonDebugFileRequested(QString filename);
120 
121  void pythonDebugPositionChanged(QString filename, int lineNo);
122 
123  void fileOpenedOrSaved(const QString &filename);
124 
125 private slots:
126  void widgetFocusChanged(QWidget* old, QWidget* now);
127 
128  void onAddGoBackNavigationItem(const GoBackNavigationItem &item);
129  void onGotoBookmark(const BookmarkItem &item);
130 
131  //Action slots
132  void mnuNavigateForward();
133  void mnuNavigateBackward();
134  void mnuNavigateBackwardItem(int index);
135 };
136 
137 } //end namespace ito
138 
139 #endif
void fileOpenedOrSaved(const QString &filename)
This slot is called if a file is saved or stored in any widget.
Definition: scriptEditorOrganizer.cpp:357
int m_goBackNavigationIndex
history of go back navigation items. Newer items are at the end of the list. The list is limited to a...
Definition: scriptEditorOrganizer.h:96
void pythonRunFile(QString filename)
signal emitted if dockWidget should be removed from main window
void addScriptDockWidgetToMainWindow(AbstractDockWidget *dockWidget, Qt::DockWidgetArea area)
maximum number of entries in the go back navigation history.
QSet< QString > m_usedObjectNames
list with references to all ScriptDockWidgets (docked or windows-style)
Definition: scriptEditorOrganizer.h:85
static const int MaxGoBackNavigationEntries
current position of script editors in goBackNavigationHistory. If equal to m_goBackNavigationHistory...
Definition: scriptEditorOrganizer.h:97
RetVal saveAllScripts(bool askFirst=true, bool ignoreNewScripts=false, int *saveScriptState=NULL)
saves all opened scripts, if changes exist
Definition: scriptEditorOrganizer.cpp:490
ScriptDockWidget * getFirstDockedElement() const
returns first ScriptDockWidget of the widget-list which is docked. This is also the last activated do...
Definition: scriptEditorOrganizer.cpp:602
widget containing one or multiple script editors (tabbed). This widget can either be a docking widget...
Definition: scriptDockWidget.h:60
void removeScriptDockWidget(ScriptDockWidget *widget)
signal emitted if macro (filename) should be debugged in python
Definition: scriptEditorOrganizer.cpp:465
RetVal newScript(ItomSharedSemaphore *semaphore=NULL)
slot, invoked if new script should be opened
Definition: scriptEditorOrganizer.cpp:802
this struct can hold common actions for all script editor and script dock widgets ...
Definition: scriptDockWidget.h:53
ScriptDockWidget * getFirstUndockedElement() const
Definition: scriptEditorOrganizer.cpp:641
RetVal closeAllScripts(bool saveFirst)
tries to close all opened script.
Definition: scriptEditorOrganizer.cpp:571
model for management of all bookmarks. This model will be displayed by a viewer-widget in the main wi...
Class for managing status values (like errors or warning)
Definition: retVal.h:54
organizes script editors, independent on their appearance (docked or window-style) ...
Definition: scriptEditorOrganizer.h:41
Definition: scriptEditorWidget.h:66
void undockScriptTab(ScriptDockWidget *widget, int index, bool undockToNewScriptWindow=false, bool closeDockIfEmpty=false)
slot invoked if tab, defined by its index, in the given widget should be undocked ...
Definition: scriptEditorOrganizer.cpp:742
void pythonRunFileRequested(QString filename)
slot invoked if someone wants to run a python file with filename.
Definition: scriptEditorOrganizer.cpp:983
bool m_dockedNewWidget
true if docking mode is available, else: false
Definition: scriptEditorOrganizer.h:87
QStringList m_recentlyUsedFiles
mutex locking any changes to m_scriptDockElements. This mutex can also be changed in const methods ...
Definition: scriptEditorOrganizer.h:90
Definition: apiFunctionsGraph.cpp:39
RetVal restoreScriptState()
This function is called to get all the saved informations about widgets after itom starts...
Definition: scriptEditorOrganizer.cpp:209
void dockScriptTab(ScriptDockWidget *widget, int index, bool closeDockIfEmpty=false)
slot invoked if tab, defined by its index, if the given widget should be docked
Definition: scriptEditorOrganizer.cpp:711
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
ScriptDockWidget * openScriptRequested(const QString &filename, ScriptDockWidget *widget)
slot invoked if a file open command has been executed in any script window.
Definition: scriptEditorOrganizer.cpp:942
ScriptEditorOrganizer(bool dockAvailable)
constructor
Definition: scriptEditorOrganizer.cpp:78
void widgetFocusChanged(QWidget *old, QWidget *now)
slot is connected to signal "focusChanged" of QApplication and indicates every change in the active w...
Definition: scriptEditorOrganizer.cpp:664
ScriptDockWidget * getActiveDockWidget() const
returns the ScriptDockWidget, which actually has the focus or lastly got the focus.
Definition: scriptEditorOrganizer.cpp:622
void pythonDebugFileRequested(QString filename)
slot invoked if someone wants to debug a python file with filename.
Definition: scriptEditorOrganizer.cpp:1018
abstract dock widget class which inherits QDockWidget. The content of QDockWidget consists of an inst...
Definition: abstractDockWidget.h:54
~ScriptEditorOrganizer()
destructor
Definition: scriptEditorOrganizer.cpp:123
ScriptDockWidget * createEmptyScriptDock(bool docked, Qt::DockWidgetArea area=Qt::TopDockWidgetArea, const QString &objectName=QString())
creates new ScriptDockWidget without any script editor tab.
Definition: scriptEditorOrganizer.cpp:381
void pythonDebugPositionChanged(QString filename, int lineNo)
slot invoked if line in python debugging process has been changed
Definition: scriptEditorOrganizer.cpp:1055
ScriptDockWidget * activateOpenedScriptByFilename(const QString &filename, int currentDebugLine=-1, int UID=-1)
returns the outlines of all opened scripts
Definition: scriptEditorOrganizer.cpp:334
RetVal openNewScriptWindow(bool docked, ItomSharedSemaphore *semaphore=NULL)
slot invoked if empty new script window should be created and displayed
Definition: scriptEditorOrganizer.cpp:771
RetVal openScript(const QString &filename, ItomSharedSemaphore *semaphore=NULL, int visibleLineNr=-1, bool errorMessageClick=false, bool showSelectedCallstackLine=false)
slot, invoked if python macro file should be opened as new tab in active script editor window ...
Definition: scriptEditorOrganizer.cpp:855
void removeScriptDockWidgetFromMainWindow(AbstractDockWidget *dockWidget)
signal emitted if dockWidget should be added to docking area in main window
QSignalMapper * m_pGoBackNavigationMapper
menu for the backward items
Definition: scriptEditorOrganizer.h:94
bool m_dockAvailable
currently used objectNames for script windows
Definition: scriptEditorOrganizer.h:86
Definition: scriptEditorWidget.h:74
void pythonDebugFile(QString filename)
signal emitted if macro (filename) should be executed in python
item of BookmarkModel
Definition: bookmarkModel.h:42
void saveScriptState()
This function is called to save all the informations about widgets before itom is closed...
Definition: scriptEditorOrganizer.cpp:148