basetextdocument.h 3.7 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
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.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
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
con's avatar
con committed
80 81
    virtual QString mimeType() const;
    void setMimeType(const QString &mt);
dt's avatar
dt committed
82
    virtual void rename(const QString &newName);
con's avatar
con committed
83

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

87 88
    void setDefaultPath(const QString &defaultPath);
    void setSuggestedFileName(const QString &suggestedFileName);
con's avatar
con committed
89

90 91
    virtual bool open(QString *errorString, const QString &fileName = QString());
    virtual bool reload(QString *errorString);
con's avatar
con committed
92

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

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

102
    bool reload(QString *errorString, QTextCodec *codec);
103
    void cleanWhitespace(const QTextCursor &cursor);
104

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

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

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

} // namespace TextEditor

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