itom 2.2.1
K:/git-itom/sources/itom/Qitom/widgets/scriptDockWidget.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom.
00008   
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013 
00014     itom is distributed in the hope that it will be useful, but
00015     WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00017     General Public Licence for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with itom. If not, see <http://www.gnu.org/licenses/>.
00021 *********************************************************************** */
00022 
00023 #ifndef SCRIPTDOCKWIDGET_H
00024 #define SCRIPTDOCKWIDGET_H
00025 
00026 #include "abstractDockWidget.h"
00027 #include "itomQWidgets.h"
00028 #include "scriptEditorWidget.h"
00029 
00030 #include <qaction.h>
00031 #include <qstring.h>
00032 #include <qtoolbar.h>
00033 #include <qcombobox.h>
00034 
00035 #include "../models/classNavigatorItem.h"
00036 
00037 #include <qevent.h>
00038 
00039 #include "../ui/widgetFindWord.h"
00040 
00041 class QSignalMapper; //forward declaration
00042 
00043 namespace ito {
00044 
00045 class DialogReplace; //forward declaration
00046 
00047 class ScriptDockWidget : public AbstractDockWidget
00048 {
00049     Q_OBJECT
00050 public:
00051     ScriptDockWidget(const QString &title, const QString &objName, bool docked, bool isDockAvailable, QWidget *parent = 0, Qt::WindowFlags flags = 0);
00052     ~ScriptDockWidget();
00053 
00054     QStringList getModifiedFileNames(bool ignoreNewScripts = false, int excludeIndex = -1) const;
00055     QStringList getAllFilenames() const;
00056 
00057     RetVal newScript();
00058     RetVal openScript();
00059     RetVal openScript(QString filename, bool silent = false);
00060     RetVal saveAllScripts(bool askFirst = true, bool ignoreNewScripts = false, int excludeIndex = -1);
00061     RetVal closeAllScripts(bool saveFirst = true, bool askFirst = true, bool ignoreNewScripts = false, int excludeIndex = -1);
00062 
00063     inline bool isTabIndexValid(int tabIndex) const { return (tabIndex >= 0 && tabIndex < m_tab->count()); }   
00064     inline int getTabCount() const { return m_tab->count(); }      
00065     inline int getCurrentIndex() const { return m_tab->currentIndex(); }
00066     void setCurrentIndex(int index);
00067 
00068     bool containsNewScripts() const;
00069 
00070     RetVal appendEditor(ScriptEditorWidget* editorWidget);         
00071     ScriptEditorWidget* removeEditor(int index);                    
00072     bool activateTabByFilename(const QString &filename, int line = -1);
00073     bool activeTabEnsureLineVisible(const int lineNr, bool errorMessageClick = false);
00074 
00075     QList<ito::ScriptEditorStorage> saveScriptState() const;
00076     RetVal restoreScriptState(const QList<ito::ScriptEditorStorage> &states);
00077 
00078 protected:
00079     ScriptEditorWidget* getEditorByIndex(int index) const;
00080     ScriptEditorWidget* getCurrentEditor() const;
00081 
00082     int getIndexByEditor(const ScriptEditorWidget* sew) const;
00083 
00084 
00085     void createActions();
00086     //void deleteActions();
00087     void createMenus();
00088     void createToolBars();
00089     void createStatusBar();
00090 
00091     //void windowStateChanged( bool windowNotToolbox );
00092 
00093     void closeEvent(QCloseEvent *event);
00094 
00095     RetVal closeTab(int index, bool saveFirst = true);
00096     RetVal saveTab(int index, bool forceSaveAs = false, bool askFirst = true);
00097 
00098 private:
00099     QWidget *m_pCenterWidget;
00100     QVBoxLayout *m_pVBox;
00101     QTabWidgetItom* m_tab;              
00102     WidgetFindWord *m_pWidgetFindWord;
00103     DialogReplace *m_pDialogReplace;
00104     
00105     int m_actTabIndex;                  
00107     // ACTIONS
00108     ShortcutAction *m_tabMoveLeftAction;
00109     ShortcutAction *m_tabMoveRightAction;
00110     ShortcutAction *m_tabMoveFirstAction;
00111     ShortcutAction *m_tabMoveLastAction;
00112     ShortcutAction *m_tabCloseAction;
00113     ShortcutAction *m_tabCloseOthersAction;
00114     ShortcutAction *m_tabCloseAllAction;
00115     ShortcutAction *m_tabDockAction;
00116     ShortcutAction *m_tabUndockAction;
00117     ShortcutAction *m_newScriptAction;
00118     ShortcutAction *m_openScriptAction;
00119     ShortcutAction *m_saveScriptAction;
00120     ShortcutAction *m_saveScriptAsAction;
00121     ShortcutAction *m_saveAllScriptsAction;
00122     ShortcutAction *m_printAction;
00123     ShortcutAction *m_cutAction;
00124     ShortcutAction *m_copyAction;
00125     ShortcutAction *m_pasteAction;
00126     ShortcutAction *m_undoAction;
00127     ShortcutAction *m_redoAction;
00128     ShortcutAction *m_commentAction;
00129     ShortcutAction *m_uncommentAction;
00130     ShortcutAction *m_indentAction;
00131     ShortcutAction *m_unindentAction;
00132     ShortcutAction *m_scriptRunAction;
00133     ShortcutAction *m_scriptRunSelectionAction;
00134     ShortcutAction *m_scriptDebugAction;
00135     ShortcutAction *m_scriptStopAction;
00136     ShortcutAction *m_scriptContinueAction;
00137     ShortcutAction *m_scriptStepAction;
00138     ShortcutAction *m_scriptStepOverAction;
00139     ShortcutAction *m_scriptStepOutAction;
00140     ShortcutAction *m_findTextExprAction;
00141     ShortcutAction *m_findTextExprActionSC;
00142     ShortcutAction *m_replaceTextExprAction;
00143     ShortcutAction *m_gotoAction;
00144     ShortcutAction *m_openIconBrowser;
00145     ShortcutAction *m_bookmarkToggle;
00146     ShortcutAction *m_bookmarkNext;
00147     ShortcutAction *m_bookmarkPrevious;
00148     ShortcutAction *m_bookmarkClearAll;
00149     ShortcutAction *m_insertCodecAct;
00150 
00151     QMenu *m_tabContextMenu;
00152     QMenu *m_fileMenu;
00153     QMenu *m_lastFilesMenu;
00154     QMenu *m_viewMenu;
00155     QMenu *m_editMenu;
00156     QMenu *m_scriptMenu;
00157     QMenu *m_winMenu;
00158     QMenu *m_bookmark;
00159 
00160     QSignalMapper *m_lastFilesMapper;
00161 
00162     QToolBar* m_fileToolBar;
00163     QToolBar* m_editToolBar;
00164     QToolBar* m_scriptToolBar;
00165     QToolBar* m_bookmarkToolBar;
00166 
00167     // ClassNavigator
00168     QWidget *m_classMenuBar;
00169     QComboBox *m_classBox;
00170     QComboBox *m_methodBox;
00171     bool m_ClassNavigatorEnabled;
00172     void fillClassBox(const ClassNavigatorItem *parent, QString prefix);
00173     void fillMethodBox(const ClassNavigatorItem *parent);
00174     void showClassNavigator(bool show);
00175     QMap<int, ClassNavigatorItem*> m_rootElements;
00176 
00177 signals:
00178     void removeAndDeleteScriptDockWidget(ScriptDockWidget* widget);                             
00180     void openScriptRequest(const QString &filename, ScriptDockWidget* scriptDockWidget);               
00182     void dockScriptTab(ScriptDockWidget* widget, int index, bool closeDockIfEmpty = false);     
00183     void undockScriptTab(ScriptDockWidget* widget, int index, bool undockToNewScriptWindow = false, bool closeDockIfEmpty = false);   
00185     void pythonRunFileRequest(QString filename);                                                
00186     void pythonDebugFileRequest(QString filename);                                              
00187     void pythonInterruptExecution();                                                            
00188     void pythonDebugCommand(tPythonDbgCmd cmd);                                                 
00189     void pythonRunSelection(QString selectionText);                                             
00191     //void lastFileClicked(const QString &path);
00192 
00193 private slots:
00194     void tabContextMenuEvent (QContextMenuEvent * event);
00195 
00196     void findTextExpr(QString expr, bool regExpr, bool caseSensitive, bool wholeWord, bool wrap, bool forward, bool isQuickSeach);
00197     void replaceTextExpr(QString expr, QString replace);
00198     void replaceAllExpr(QString expr, QString replace, bool regExpr, bool caseSensitive, bool wholeWord, int findIn);
00199     void insertIconBrowserText(QString iconLink);
00200 
00201     void currentTabChanged(int index);
00202     void tabCloseRequested(int index);
00203     void tabCloseRequested(ScriptEditorWidget* sew, bool ignoreModifications);
00204     void scriptModificationChanged(bool changed);
00205 
00206     void updateEditorActions();
00207     void updatePythonActions();
00208     void updateTabContextActions();
00209 
00210     void mnuOpenIconBrowser();
00211 
00212     void mnuTabMoveLeft();
00213     void mnuTabMoveRight();
00214     void mnuTabMoveFirst();
00215     void mnuTabMoveLast();
00216     void mnuTabClose();
00217     void mnuTabCloseOthers();
00218     void mnuTabCloseAll();
00219     void mnuTabDock();
00220     void mnuTabUndock();
00221     void mnuNewScript();
00222     void mnuOpenScript();
00223     void mnuSaveScript();
00224     void mnuSaveScriptAs();
00225     void mnuSaveAllScripts();
00226     void mnuPrint();
00227     void mnuCut();
00228     void mnuCopy();
00229     void mnuPaste();
00230     void mnuUndo();
00231     void mnuRedo();
00232     void mnuComment();
00233     void mnuUncomment();
00234     void mnuIndent();
00235     void mnuUnindent();
00236     void mnuScriptRun();
00237     void mnuScriptRunSelection();
00238     void mnuScriptDebug();
00239     void mnuScriptStop();
00240     void mnuScriptContinue();
00241     void mnuScriptStep();
00242     void mnuScriptStepOver();
00243     void mnuScriptStepOut();
00244     void mnuFindTextExpr();
00245     void mnuReplaceTextExpr();
00246     void mnuGoto();
00247     void mnuToggleBookmark();
00248     void mnuClearAllBookmarks();
00249     void mnuGotoNextBookmark();
00250     void mnuGotoPreviousBookmark();
00251     void mnuInsertCodec();
00252 
00253     void menuLastFilesAboutToShow();
00254     void lastFileOpen(const QString &path);
00255 
00256     // Class Navigator
00257     void classChosen(const QString &text);
00258     void methodChosen(const QString &text);
00259 
00260     void loadSettings();
00261     void findWordWidgetFinished();
00262 
00263 public slots:
00264     void editorMarginChanged();
00265     void updateClassesBox(ScriptEditorWidget *editor);
00266 };
00267 
00268 } //end namespace ito
00269 
00270 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends