basetextdocument.h 3.69 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28 29
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33 34 35 36 37
#ifndef BASETEXTDOCUMENT_H
#define BASETEXTDOCUMENT_H

#include "texteditor_global.h"

38 39
#include <coreplugin/ifile.h>

con's avatar
con committed
40 41 42 43 44 45 46
QT_BEGIN_NAMESPACE
class QTextCursor;
class QTextDocument;
QT_END_NAMESPACE

namespace TextEditor {

47 48 49
class ITextMarkable;
class StorageSettings;
class TabSettings;
50
class ExtraEncodingSettings;
51
class SyntaxHighlighter;
52
class BaseTextDocumentPrivate;
con's avatar
con committed
53

hjk's avatar
hjk committed
54
class TEXTEDITOR_EXPORT BaseTextDocument : public Core::IFile
con's avatar
con committed
55 56 57 58 59
{
    Q_OBJECT

public:
    BaseTextDocument();
60
    virtual ~BaseTextDocument();
con's avatar
con committed
61

62 63
    void setStorageSettings(const StorageSettings &storageSettings);
    void setTabSettings(const TabSettings &tabSettings);
64
    void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
con's avatar
con committed
65

66 67
    const StorageSettings &storageSettings() const;
    const TabSettings &tabSettings() const;
68
    const ExtraEncodingSettings &extraEncodingSettings() const;
69 70

    ITextMarkable *documentMarker() const;
con's avatar
con committed
71

hjk's avatar
hjk committed
72
    // IFile implementation.
73
    virtual bool save(QString *errorString, const QString &fileName = QString());
74
    virtual QString fileName() const;
con's avatar
con committed
75 76
    virtual bool isReadOnly() const;
    virtual bool isModified() const;
77
    virtual bool isSaveAsAllowed() const;
78
    virtual void checkPermissions();
79 80
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
    void reload(ReloadFlag flag, ChangeType type);
con's avatar
con committed
81 82
    virtual QString mimeType() const;
    void setMimeType(const QString &mt);
dt's avatar
dt committed
83
    virtual void rename(const QString &newName);
con's avatar
con committed
84

85 86
    virtual QString defaultPath() const;
    virtual QString suggestedFileName() const;
con's avatar
con committed
87

88 89
    void setDefaultPath(const QString &defaultPath);
    void setSuggestedFileName(const QString &suggestedFileName);
con's avatar
con committed
90 91 92 93

    virtual bool open(const QString &fileName = QString());
    virtual void reload();

94
    QTextDocument *document() const;
95
    void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
96
    SyntaxHighlighter *syntaxHighlighter() const;
con's avatar
con committed
97

98 99 100 101
    bool hasDecodingError() const;
    QTextCodec *codec() const;
    void setCodec(QTextCodec *c);
    QByteArray decodingErrorSample() const;
con's avatar
con committed
102 103

    void reload(QTextCodec *codec);
104
    void cleanWhitespace(const QTextCursor &cursor);
105

con's avatar
con committed
106 107 108 109
signals:
    void titleChanged(QString title);

private:
hjk's avatar
hjk committed
110 111
    void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
    void ensureFinalNewLine(QTextCursor &cursor);
112
    void documentClosing();
113 114

    BaseTextDocumentPrivate *d;
con's avatar
con committed
115 116 117 118
};

} // namespace TextEditor

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