basetextdocument.h 5.21 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34
#ifndef BASETEXTDOCUMENT_H
#define BASETEXTDOCUMENT_H

#include "texteditor_global.h"

hjk's avatar
hjk committed
35 36 37
#include <coreplugin/textdocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
38

hjk's avatar
hjk committed
39
#include <QList>
hjk's avatar
hjk committed
40
#include <QMap>
41
#include <QSharedPointer>
hjk's avatar
hjk committed
42

con's avatar
con committed
43 44 45 46 47 48 49
QT_BEGIN_NAMESPACE
class QTextCursor;
class QTextDocument;
QT_END_NAMESPACE

namespace TextEditor {

50 51
class BaseTextDocumentPrivate;
class ExtraEncodingSettings;
52
class FontSettings;
53
class Indenter;
54
class StorageSettings;
55
class SyntaxHighlighter;
56
class TabSettings;
hjk's avatar
hjk committed
57
class TextMark;
58
class TypingSettings;
con's avatar
con committed
59

hjk's avatar
hjk committed
60
typedef QList<TextMark *> TextMarks;
hjk's avatar
hjk committed
61

62
class TEXTEDITOR_EXPORT BaseTextDocument : public Core::TextDocument
con's avatar
con committed
63 64 65 66 67
{
    Q_OBJECT

public:
    BaseTextDocument();
68
    virtual ~BaseTextDocument();
con's avatar
con committed
69

70 71 72 73 74 75
    static QMap<QString, QString> openedTextDocumentContents();
    static QMap<QString, QTextCodec *> openedTextDocumentEncodings();

    virtual QString plainText() const;
    virtual QString textAt(int pos, int length) const;
    virtual QChar characterAt(int pos) const;
76

Jarek Kobus's avatar
Jarek Kobus committed
77
    void setTypingSettings(const TypingSettings &typingSettings);
78
    void setStorageSettings(const StorageSettings &storageSettings);
79
    void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
con's avatar
con committed
80

Jarek Kobus's avatar
Jarek Kobus committed
81
    const TypingSettings &typingSettings() const;
82 83
    const StorageSettings &storageSettings() const;
    const TabSettings &tabSettings() const;
84
    const ExtraEncodingSettings &extraEncodingSettings() const;
85
    const FontSettings &fontSettings() const;
86

87 88
    void setIndenter(Indenter *indenter);
    Indenter *indenter() const;
89 90
    void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null);
    void autoReindent(const QTextCursor &cursor);
91 92
    QTextCursor indent(const QTextCursor &cursor);
    QTextCursor unindent(const QTextCursor &cursor);
93

hjk's avatar
hjk committed
94
    TextMarks marks() const;
hjk's avatar
hjk committed
95
    bool addMark(TextMark *mark);
hjk's avatar
hjk committed
96
    TextMarks marksAt(int line) const;
hjk's avatar
hjk committed
97 98 99 100
    void removeMark(TextMark *mark);
    void updateMark(TextMark *mark);
    void moveMark(TextMark *mark, int previousLine);
    void removeMarkFromMarksCache(TextEditor::TextMark *mark);
con's avatar
con committed
101

102
    // IDocument implementation.
103 104 105 106 107 108 109
    bool save(QString *errorString, const QString &fileName, bool autoSave);
    bool setContents(const QByteArray &contents);
    bool shouldAutoSave() const;
    bool isFileReadOnly() const;
    bool isModified() const;
    bool isSaveAsAllowed() const;
    void checkPermissions();
110
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
111
    void setFilePath(const QString &newName);
con's avatar
con committed
112

113 114
    QString defaultPath() const;
    QString suggestedFileName() const;
con's avatar
con committed
115

116 117
    void setDefaultPath(const QString &defaultPath);
    void setSuggestedFileName(const QString &suggestedFileName);
con's avatar
con committed
118

119
    virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
120
    virtual bool reload(QString *errorString);
con's avatar
con committed
121

122
    bool setPlainText(const QString &text);
123
    QTextDocument *document() const;
124
    void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
125
    SyntaxHighlighter *syntaxHighlighter() const;
con's avatar
con committed
126

127
    bool reload(QString *errorString, QTextCodec *codec);
128
    void cleanWhitespace(const QTextCursor &cursor);
129

130
    virtual void triggerPendingUpdates();
131

132 133
public slots:
    void setTabSettings(const TextEditor::TabSettings &tabSettings);
134
    void setFontSettings(const TextEditor::FontSettings &fontSettings);
135

con's avatar
con committed
136
signals:
137
    void contentsChanged();
138
    void tabSettingsChanged();
139
    void fontSettingsChanged();
con's avatar
con committed
140

141 142 143
protected slots:
    virtual void applyFontSettings();

con's avatar
con committed
144
private:
hjk's avatar
hjk committed
145 146
    void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
    void ensureFinalNewLine(QTextCursor &cursor);
147 148

    BaseTextDocumentPrivate *d;
con's avatar
con committed
149 150
};

151 152
typedef QSharedPointer<BaseTextDocument> BaseTextDocumentPtr;

con's avatar
con committed
153 154
} // namespace TextEditor

hjk's avatar
hjk committed
155
#endif // BASETEXTDOCUMENT_H