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
#include <coreplugin/textfile.h>
39

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

54
class TEXTEDITOR_EXPORT BaseTextDocument : public Core::TextFile
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, bool autoSave);
74
    virtual QString fileName() const;
75
    virtual bool shouldAutoSave() const;
con's avatar
con committed
76 77
    virtual bool isReadOnly() const;
    virtual bool isModified() const;
78
    virtual bool isSaveAsAllowed() const;
79
    virtual void checkPermissions();
80
    bool reload(QString *errorString, 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
    virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
92
    virtual bool reload(QString *errorString);
con's avatar
con committed
93

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

98
    bool reload(QString *errorString, QTextCodec *codec);
99
    void cleanWhitespace(const QTextCursor &cursor);
100

101 102 103
    bool hasHighlightWarning() const;
    void setHighlightWarning(bool has);

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

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

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

} // namespace TextEditor

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