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_DOC_MANAGER_HPP_INCLUDED
22 #define SCIDE_DOC_MANAGER_HPP_INCLUDED
24 #include "../widgets/code_editor/highlighter.hpp"
27 #include <QFileSystemWatcher>
32 #include <QStringList>
33 #include <QTextDocument>
34 #include <QPlainTextDocumentLayout>
39 namespace Settings
{ class Manager
; }
42 class DocumentManager
;
44 class Document
: public QObject
48 friend class DocumentManager
;
53 QTextDocument
*textDocument() { return mDoc
; }
54 const QByteArray
& id() { return mId
; }
55 const QString
& filePath() { return mFilePath
; }
56 const QString
& title() { return mTitle
; }
58 QFont
defaultFont() const { return mDoc
->defaultFont(); }
59 void setDefaultFont( const QFont
& font
);
61 int indentWidth() const { return mIndentWidth
; }
62 void setIndentWidth( int numSpaces
);
64 void deleteTrailingSpaces();
67 void applySettings( Settings::Manager
* );
68 void resetDefaultFont();
71 void defaultFontChanged();
82 class DocumentManager
: public QObject
87 typedef QList
< Document
* > DocumentList
;
89 DocumentManager( Main
*, Settings::Manager
* );
90 QList
<Document
*> documents() {
91 return mDocHash
.values();
95 void close( Document
* );
96 bool save( Document
* );
97 bool saveAs( Document
*, const QString
& path
);
98 bool reload( Document
* );
99 const QStringList
& recents() const { return mRecent
; }
102 // initialCursorPosition -1 means "don't change position if already open"
103 Document
* open( const QString
& path
, int initialCursorPosition
= -1, int selectionLength
= -1, bool addToRecent
= true );
105 void storeSettings( Settings::Manager
* );
109 void opened( Document
*, int cursorPosition
, int selectionLength
);
110 void closed( Document
* );
111 void saved( Document
* );
112 void showRequest( Document
*, int pos
= -1 );
113 void changedExternally( Document
* );
114 void recentsChanged();
117 void onFileChanged( const QString
& path
);
120 Document
* createDocument();
121 bool doSaveAs( Document
*, const QString
& path
);
122 void addToRecent( Document
* );
123 void loadRecentDocuments( Settings::Manager
* );
125 typedef QHash
<QByteArray
, Document
*>::iterator DocIterator
;
127 QHash
<QByteArray
, Document
*> mDocHash
;
128 QFileSystemWatcher mFsWatcher
;
131 static const int mMaxRecent
= 10;
136 Q_DECLARE_METATYPE( ScIDE::Document
* );
138 #endif // SCIDE_DOC_MANAGER_HPP_INCLUDED