2013-05-07 14:02:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-05-07 14:02:08 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
2013-05-07 14:02:08 +02: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.
|
2013-05-07 14:02:08 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
#include "diffutils.h"
|
|
|
|
|
|
2014-06-30 15:04:36 +02:00
|
|
|
#include <coreplugin/textdocument.h>
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2015-03-10 14:19:38 +01:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
|
|
|
|
|
2013-05-07 14:02:08 +02:00
|
|
|
namespace DiffEditor {
|
|
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
class DiffEditorController;
|
|
|
|
|
|
2015-01-30 14:33:39 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class DiffEditorDocument : public Core::BaseTextDocument
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2014-11-13 09:11:56 +01:00
|
|
|
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
|
2013-05-07 14:02:08 +02:00
|
|
|
public:
|
2015-01-30 11:18:08 +01:00
|
|
|
DiffEditorDocument();
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-02-11 13:00:35 +01:00
|
|
|
DiffEditorController *controller() const;
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2017-07-03 11:26:52 +02:00
|
|
|
enum State {
|
|
|
|
|
LoadOK,
|
|
|
|
|
Reloading,
|
|
|
|
|
LoadFailed
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-19 16:44:25 +02:00
|
|
|
QString makePatch(int fileIndex, int chunkIndex,
|
|
|
|
|
bool revert, bool addPrefix = false,
|
|
|
|
|
const QString &overriddenFileName = QString()) const;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
2015-08-20 16:45:30 +03:00
|
|
|
void setDiffFiles(const QList<FileData> &data, const QString &directory,
|
|
|
|
|
const QString &startupFile = QString());
|
2015-01-30 16:59:25 +01:00
|
|
|
QList<FileData> diffFiles() const;
|
|
|
|
|
QString baseDirectory() const;
|
2015-08-20 16:45:30 +03:00
|
|
|
QString startupFile() const;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
void setDescription(const QString &description);
|
|
|
|
|
QString description() const;
|
|
|
|
|
|
|
|
|
|
void setContextLineCount(int lines);
|
|
|
|
|
int contextLineCount() const;
|
|
|
|
|
void forceContextLineCount(int lines);
|
|
|
|
|
bool isContextLineCountForced() const;
|
|
|
|
|
void setIgnoreWhitespace(bool ignore);
|
|
|
|
|
bool ignoreWhitespace() const;
|
|
|
|
|
|
2015-06-04 15:54:10 +02:00
|
|
|
bool setContents(const QByteArray &contents) override;
|
2016-01-14 14:45:01 +01:00
|
|
|
QString fallbackSaveAsPath() const override;
|
|
|
|
|
QString fallbackSaveAsFileName() const override;
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2017-06-29 12:03:10 +02:00
|
|
|
bool isSaveAsAllowed() const override;
|
2015-06-04 15:54:10 +02:00
|
|
|
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
2015-01-30 16:59:25 +01:00
|
|
|
void reload();
|
2015-06-04 15:54:10 +02:00
|
|
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
|
|
|
|
OpenResult open(QString *errorString, const QString &fileName,
|
|
|
|
|
const QString &realFileName) override;
|
2017-07-03 11:26:52 +02:00
|
|
|
State state() const { return m_state; }
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-11-13 09:11:56 +01:00
|
|
|
QString plainText() const;
|
|
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
signals:
|
|
|
|
|
void temporaryStateChanged();
|
|
|
|
|
void documentChanged();
|
|
|
|
|
void descriptionChanged();
|
|
|
|
|
void chunkActionsRequested(QMenu *menu, int diffFileIndex, int chunkIndex);
|
|
|
|
|
void requestMoreInformation();
|
|
|
|
|
|
2013-05-07 14:02:08 +02:00
|
|
|
private:
|
2017-07-06 11:44:11 +02:00
|
|
|
void beginReload();
|
|
|
|
|
void endReload(bool success);
|
2015-01-30 16:59:25 +01:00
|
|
|
void setController(DiffEditorController *controller);
|
|
|
|
|
|
2017-12-06 21:30:57 +01:00
|
|
|
DiffEditorController *m_controller = nullptr;
|
2015-01-30 16:59:25 +01:00
|
|
|
QList<FileData> m_diffFiles;
|
|
|
|
|
QString m_baseDirectory;
|
2015-08-20 16:45:30 +03:00
|
|
|
QString m_startupFile;
|
2015-01-30 16:59:25 +01:00
|
|
|
QString m_description;
|
2017-12-06 21:30:57 +01:00
|
|
|
int m_contextLineCount = 3;
|
|
|
|
|
bool m_isContextLineCountForced = false;
|
|
|
|
|
bool m_ignoreWhitespace = false;
|
2017-07-03 11:26:52 +02:00
|
|
|
State m_state = LoadOK;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
friend class ::DiffEditor::DiffEditorController;
|
2013-05-07 14:02:08 +02:00
|
|
|
};
|
|
|
|
|
|
2015-01-30 14:33:39 +01:00
|
|
|
} // namespace Internal
|
2013-05-07 14:02:08 +02:00
|
|
|
} // namespace DiffEditor
|