File indexing completed on 2024-05-19 08:39:54
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Anmol Ahuja <darthcodus@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef SCRIPTCONSOLE_H 0018 #define SCRIPTCONSOLE_H 0019 0020 #include <QMainWindow> 0021 #include <QDockWidget> 0022 #include <QPointer> 0023 0024 namespace KTextEditor{ 0025 class Editor; 0026 } 0027 class QEvent; 0028 class QListWidget; 0029 class QListWidgetItem; 0030 class QModelIndex; 0031 class QJSEngine; 0032 0033 namespace ScriptConsoleNS 0034 { 0035 class ScriptConsoleItem; 0036 class ScriptListDockWidget; 0037 0038 class ScriptConsole : public QMainWindow 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 static ScriptConsole *instance(); 0044 0045 private Q_SLOTS: 0046 void slotAbortEvaluation(); 0047 void slotExecuteNewScript(); 0048 void slotNewScript(); 0049 void setCurrentScriptItem( ScriptConsoleItem *item ); 0050 void slotEvaluationSuspended(); 0051 void slotEvaluationResumed(); 0052 void slotEditScript( ScriptConsoleItem *item ); 0053 0054 private: 0055 explicit ScriptConsole( QWidget *parent ); 0056 ~ScriptConsole() override; 0057 0058 bool eventFilter( QObject *watched, QEvent *event ) override; 0059 QDockWidget *getWidget( const QString &title, QWidget *widget ); 0060 void closeEvent( QCloseEvent *event ) override; 0061 ScriptConsoleItem* createScriptItem( const QString &script ); 0062 ScriptListDockWidget *getScriptListDockWidget(); 0063 0064 QPointer<ScriptConsoleItem> m_scriptItem; 0065 QDockWidget *m_consoleWidget; 0066 QDockWidget *m_codeWidget; 0067 QDockWidget *m_outputWidget; 0068 QDockWidget *m_errorWidget; 0069 QString m_savePath; 0070 KTextEditor::Editor *m_editor; 0071 ScriptListDockWidget *m_scriptListDock; 0072 static QPointer<ScriptConsole> s_instance; 0073 }; 0074 0075 class ScriptListDockWidget : public QDockWidget 0076 { 0077 Q_OBJECT 0078 0079 public: 0080 explicit ScriptListDockWidget( QWidget *parent ); 0081 ~ScriptListDockWidget() override; 0082 QListWidget *listWidget(); 0083 void addScript( ScriptConsoleItem *script ); 0084 ScriptConsoleItem *getScript( const QString &scriptName); 0085 void addItem( QListWidgetItem *item ); 0086 0087 public Q_SLOTS: 0088 void clear(); 0089 void removeCurrentScript(); 0090 void prev(); 0091 void next(); 0092 0093 Q_SIGNALS: 0094 void edit( ScriptConsoleItem *item ); 0095 void executeScript( ScriptConsoleItem *item ); 0096 void currentItemChanged( ScriptConsoleItem *newItem ); 0097 void newScript(); 0098 0099 private Q_SLOTS: 0100 void slotDoubleClicked( const QModelIndex &index ); 0101 void slotCurrentItemChanged( QListWidgetItem *newItem, QListWidgetItem *oldItem ); 0102 0103 private: 0104 QListWidget *m_scriptListWidget; 0105 const int ScriptRole = 1002; 0106 }; 0107 } 0108 0109 #endif // SCRIPTCONSOLE_H