Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / editors / sc-ide / widgets / multi_editor.hpp
blob3d70297ef4250a7e2df075ea9daf014203802ef5
1 /*
2 SuperCollider Qt IDE
3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_MULTI_EDITOR_HPP_INCLUDED
22 #define SCIDE_WIDGETS_MULTI_EDITOR_HPP_INCLUDED
24 #include <QWidget>
25 #include <QTabBar>
26 #include <QAction>
27 #include <QPushButton>
28 #include <QToolButton>
29 #include <QLineEdit>
30 #include <QCheckBox>
31 #include <QLabel>
32 #include <QGridLayout>
33 #include <QTextDocument>
34 #include <QSplitter>
36 namespace ScIDE {
38 class Main;
39 class Document;
40 class DocumentManager;
41 class ScCodeEditor;
42 class CodeEditorBox;
43 class MultiSplitter;
44 class SignalMultiplexer;
45 class Session;
46 namespace Settings { class Manager; }
48 class MultiEditor : public QWidget
50 Q_OBJECT
52 public:
54 enum ActionRole
56 // Edit
57 Undo,
58 Redo,
59 Cut,
60 Copy,
61 Paste,
62 IndentLineOrRegion,
63 TriggerAutoCompletion,
64 TriggerMethodCallAid,
65 ToggleComment,
66 ToggleOverwriteMode,
68 CopyLineUp,
69 CopyLineDown,
70 MoveLineUp,
71 MoveLineDown,
73 GotoPreviousBlock,
74 GotoNextBlock,
75 GotoPreviousRegion,
76 GotoNextRegion,
77 GotoPreviousEmptyLine,
78 GotoNextEmptyLine,
80 SelectRegion,
82 // View
83 EnlargeFont,
84 ShrinkFont,
85 ResetFontSize,
86 ShowWhitespace,
88 NextDocument,
89 PreviousDocument,
90 SwitchDocument,
92 SplitHorizontally,
93 SplitVertically,
94 RemoveCurrentSplit,
95 RemoveAllSplits,
97 // Language
98 EvaluateCurrentDocument,
99 EvaluateRegion,
100 EvaluateLine,
102 ActionRoleCount
105 MultiEditor( Main *, QWidget * parent = 0 );
107 int tabCount() { return mTabs->count(); }
108 Document * documentForTab( int index );
109 int tabForDocument( Document * doc );
111 ScCodeEditor *currentEditor();
112 CodeEditorBox *currentBox() { return mCurrentEditorBox; }
113 void split( Qt::Orientation direction );
115 QAction * action( ActionRole role )
116 { return mActions[role]; }
118 bool stepForwardEvaluation() { return mStepForwardEvaluation; }
120 void applySettings( Settings::Manager * );
122 void saveSession( Session * );
123 void switchSession( Session * );
125 signals:
126 void currentDocumentChanged( Document * );
128 public slots:
130 void setCurrent( Document * );
132 void showNextDocument();
133 void showPreviousDocument();
134 void switchDocument();
136 void splitHorizontally() { split(Qt::Horizontal); }
137 void splitVertically() { split(Qt::Vertical); }
138 void removeCurrentSplit();
139 void removeAllSplits();
141 private slots:
142 void onOpen( Document *, int initialCursorPosition, int selectionLength );
143 void onClose( Document * );
144 void show( Document *, int cursorPosition = -1, int selectionLenght = 0 );
145 void update( Document * );
146 void onCloseRequest( int index );
147 void onCurrentTabChanged( int index );
148 void onCurrentEditorChanged( ScCodeEditor * );
149 void onBoxActivated( CodeEditorBox * );
150 void onModificationChanged( bool modified );
151 void evaluateRegion();
152 void evaluateLine();
153 void evaluateDocument();
155 private:
156 void makeSignalConnections();
157 void breakSignalConnections();
158 void createActions();
159 void updateActions();
160 CodeEditorBox *newBox();
161 void setCurrentBox( CodeEditorBox * );
162 void setCurrentEditor( ScCodeEditor * );
163 void loadBoxState( CodeEditorBox *box, const QVariantList & data, const QList<Document *> & documentList );
164 void loadSplitterState( QSplitter *, const QVariantMap & data, const QList<Document *> & documentList );
166 SignalMultiplexer * mSigMux;
167 SignalMultiplexer * mBoxSigMux;
168 QAction *mActions[ActionRoleCount];
170 // gui
171 QTabBar *mTabs;
172 CodeEditorBox *mCurrentEditorBox;
173 MultiSplitter *mSplitter;
174 QIcon mDocModifiedIcon;
176 // settings
177 bool mStepForwardEvaluation;
180 } // namespace ScIDE
182 #endif // SCIDE_WIDGETS_MULTI_EDITOR_HPP_INCLUDED