2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
|
|
|
|
|
2014-08-19 00:54:45 +02:00
|
|
|
#include <coreplugin/id.h>
|
2014-07-25 14:10:41 +02:00
|
|
|
#include <coreplugin/textdocument.h>
|
2018-07-13 12:33:46 +02:00
|
|
|
#include <utils/link.h>
|
2009-10-01 16:38:08 +02:00
|
|
|
|
2014-07-18 15:29:04 +02:00
|
|
|
#include <QList>
|
2014-07-25 14:10:41 +02:00
|
|
|
#include <QMap>
|
2014-08-18 17:49:04 +02:00
|
|
|
#include <QSharedPointer>
|
2014-07-18 15:29:04 +02:00
|
|
|
|
2017-11-13 09:09:08 +01:00
|
|
|
#include <functional>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
2017-11-08 13:13:59 +01:00
|
|
|
class QAction;
|
2008-12-02 12:01:29 +01:00
|
|
|
class QTextCursor;
|
|
|
|
|
class QTextDocument;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
2014-10-01 22:39:47 +02:00
|
|
|
class CompletionAssistProvider;
|
2014-01-13 16:56:53 +01:00
|
|
|
class ExtraEncodingSettings;
|
2014-01-21 11:26:39 +01:00
|
|
|
class FontSettings;
|
2014-01-13 16:56:53 +01:00
|
|
|
class Indenter;
|
2017-12-15 09:46:29 +01:00
|
|
|
class IAssistProvider;
|
2010-10-29 15:20:10 +02:00
|
|
|
class StorageSettings;
|
2010-07-09 14:47:18 +02:00
|
|
|
class SyntaxHighlighter;
|
2014-01-13 16:56:53 +01:00
|
|
|
class TabSettings;
|
2014-09-22 18:43:31 +02:00
|
|
|
class TextDocumentPrivate;
|
2014-07-19 11:27:28 +02:00
|
|
|
class TextMark;
|
2014-01-13 16:56:53 +01:00
|
|
|
class TypingSettings;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-19 11:27:28 +02:00
|
|
|
typedef QList<TextMark *> TextMarks;
|
2014-07-18 15:29:04 +02:00
|
|
|
|
2014-09-22 18:43:31 +02:00
|
|
|
class TEXTEDITOR_EXPORT TextDocument : public Core::BaseTextDocument
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-22 18:43:31 +02:00
|
|
|
explicit TextDocument(Core::Id id = Core::Id());
|
2015-06-04 15:54:10 +02:00
|
|
|
~TextDocument() override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-25 14:54:10 +02:00
|
|
|
static QMap<QString, QString> openedTextDocumentContents();
|
|
|
|
|
static QMap<QString, QTextCodec *> openedTextDocumentEncodings();
|
2016-11-25 15:23:52 +01:00
|
|
|
static TextDocument *currentTextDocument();
|
2014-07-25 14:54:10 +02:00
|
|
|
|
|
|
|
|
virtual QString plainText() const;
|
|
|
|
|
virtual QString textAt(int pos, int length) const;
|
|
|
|
|
virtual QChar characterAt(int pos) const;
|
2013-04-18 18:21:17 +02:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
void setTypingSettings(const TypingSettings &typingSettings);
|
2010-10-29 15:20:10 +02:00
|
|
|
void setStorageSettings(const StorageSettings &storageSettings);
|
2011-02-01 14:13:54 +01:00
|
|
|
void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
const TypingSettings &typingSettings() const;
|
2010-10-29 15:20:10 +02:00
|
|
|
const StorageSettings &storageSettings() const;
|
|
|
|
|
const TabSettings &tabSettings() const;
|
2011-02-01 14:13:54 +01:00
|
|
|
const ExtraEncodingSettings &extraEncodingSettings() const;
|
2014-01-21 11:26:39 +01:00
|
|
|
const FontSettings &fontSettings() const;
|
2010-10-29 15:20:10 +02:00
|
|
|
|
2014-01-13 16:56:53 +01:00
|
|
|
void setIndenter(Indenter *indenter);
|
|
|
|
|
Indenter *indenter() const;
|
2014-01-15 17:09:52 +01:00
|
|
|
void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null);
|
|
|
|
|
void autoReindent(const QTextCursor &cursor);
|
2015-07-16 15:56:25 +02:00
|
|
|
QTextCursor indent(const QTextCursor &cursor, bool blockSelection = false, int column = 0,
|
2018-02-15 08:34:26 +01:00
|
|
|
int *offset = nullptr);
|
2015-07-16 15:56:25 +02:00
|
|
|
QTextCursor unindent(const QTextCursor &cursor, bool blockSelection = false, int column = 0,
|
2018-02-15 08:34:26 +01:00
|
|
|
int *offset = nullptr);
|
2014-01-13 16:56:53 +01:00
|
|
|
|
2014-07-18 15:29:04 +02:00
|
|
|
TextMarks marks() const;
|
2014-07-19 11:27:28 +02:00
|
|
|
bool addMark(TextMark *mark);
|
2014-07-18 15:29:04 +02:00
|
|
|
TextMarks marksAt(int line) const;
|
2014-07-19 11:27:28 +02:00
|
|
|
void removeMark(TextMark *mark);
|
|
|
|
|
void updateMark(TextMark *mark);
|
|
|
|
|
void moveMark(TextMark *mark, int previousLine);
|
2014-09-22 18:43:31 +02:00
|
|
|
void removeMarkFromMarksCache(TextMark *mark);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
// IDocument implementation.
|
2015-06-04 15:54:10 +02:00
|
|
|
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
2016-01-15 15:39:23 +01:00
|
|
|
QByteArray contents() const override;
|
2015-06-04 15:54:10 +02:00
|
|
|
bool setContents(const QByteArray &contents) override;
|
|
|
|
|
bool shouldAutoSave() const override;
|
|
|
|
|
bool isFileReadOnly() const override;
|
2016-10-20 08:34:55 +00:00
|
|
|
bool isModified() const override;
|
2015-06-04 15:54:10 +02:00
|
|
|
bool isSaveAsAllowed() const override;
|
|
|
|
|
void checkPermissions() override;
|
|
|
|
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
|
|
|
|
void setFilePath(const Utils::FileName &newName) override;
|
|
|
|
|
|
2016-01-14 14:45:01 +01:00
|
|
|
QString fallbackSaveAsPath() const override;
|
|
|
|
|
QString fallbackSaveAsFileName() const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-14 14:45:01 +01:00
|
|
|
void setFallbackSaveAsPath(const QString &fallbackSaveAsPath);
|
|
|
|
|
void setFallbackSaveAsFileName(const QString &fallbackSaveAsFileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-06-04 15:54:10 +02:00
|
|
|
OpenResult open(QString *errorString, const QString &fileName,
|
|
|
|
|
const QString &realFileName) override;
|
2011-04-04 15:24:13 +02:00
|
|
|
virtual bool reload(QString *errorString);
|
2016-10-19 16:44:25 +02:00
|
|
|
bool reload(QString *errorString, const QString &realFileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-01-28 13:26:57 +01:00
|
|
|
bool setPlainText(const QString &text);
|
2010-10-29 15:20:10 +02:00
|
|
|
QTextDocument *document() const;
|
2010-07-09 14:47:18 +02:00
|
|
|
void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
|
2010-10-29 15:20:10 +02:00
|
|
|
SyntaxHighlighter *syntaxHighlighter() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-04 15:24:13 +02:00
|
|
|
bool reload(QString *errorString, QTextCodec *codec);
|
2009-09-09 16:37:09 +02:00
|
|
|
void cleanWhitespace(const QTextCursor &cursor);
|
2008-12-09 17:43:31 +01:00
|
|
|
|
2014-02-06 12:59:00 +01:00
|
|
|
virtual void triggerPendingUpdates();
|
2014-01-22 15:36:06 +01:00
|
|
|
|
2014-10-01 22:39:47 +02:00
|
|
|
void setCompletionAssistProvider(CompletionAssistProvider *provider);
|
|
|
|
|
virtual CompletionAssistProvider *completionAssistProvider() const;
|
2017-12-15 09:46:29 +01:00
|
|
|
virtual IAssistProvider *quickFixAssistProvider() const;
|
2014-10-01 22:39:47 +02:00
|
|
|
|
2014-01-17 17:09:15 +01:00
|
|
|
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
2014-01-21 11:26:39 +01:00
|
|
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
2014-01-17 17:09:15 +01:00
|
|
|
|
2017-11-08 13:13:59 +01:00
|
|
|
static QAction *createDiffAgainstCurrentFileAction(QObject *parent,
|
|
|
|
|
const std::function<Utils::FileName()> &filePath);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
2015-06-02 17:14:48 +02:00
|
|
|
void aboutToOpen(const QString &fileName, const QString &realFileName);
|
|
|
|
|
void openFinishedSuccessfully();
|
2015-09-28 17:42:43 +02:00
|
|
|
void contentsChangedWithPosition(int position, int charsRemoved, int charsAdded);
|
2014-01-17 17:09:15 +01:00
|
|
|
void tabSettingsChanged();
|
2014-01-21 11:26:39 +01:00
|
|
|
void fontSettingsChanged();
|
2017-10-06 14:29:13 +02:00
|
|
|
void markRemoved(TextMark *mark);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-12-13 01:18:33 +02:00
|
|
|
protected:
|
2014-01-22 15:36:06 +01:00
|
|
|
virtual void applyFontSettings();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2015-06-22 09:10:13 +02:00
|
|
|
OpenResult openImpl(QString *errorString, const QString &fileName, const QString &realFileName,
|
|
|
|
|
bool reload);
|
2011-02-21 19:56:51 +01:00
|
|
|
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
|
|
|
|
|
void ensureFinalNewLine(QTextCursor &cursor);
|
2016-10-20 14:45:15 +02:00
|
|
|
void modificationChanged(bool modified);
|
2017-06-20 08:28:10 +02:00
|
|
|
void updateLayout() const;
|
2010-10-29 15:20:10 +02:00
|
|
|
|
2014-09-22 18:43:31 +02:00
|
|
|
TextDocumentPrivate *d;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
typedef QSharedPointer<TextDocument> TextDocumentPtr;
|
2014-08-18 17:49:04 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace TextEditor
|