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 14:09:21 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "core_global.h"
|
2020-06-26 13:59:38 +02:00
|
|
|
|
|
|
|
|
#include <utils/id.h>
|
2014-12-21 21:54:30 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-06-17 12:23:44 +02:00
|
|
|
namespace Utils {
|
|
|
|
|
class FilePath;
|
|
|
|
|
class InfoBar;
|
|
|
|
|
} // namespace Utils
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-02-26 13:38:54 +01:00
|
|
|
namespace Core {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-01-11 23:32:51 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
class IDocumentPrivate;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
class CORE_EXPORT IDocument : public QObject
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2015-06-04 15:21:02 +02:00
|
|
|
enum class OpenResult {
|
|
|
|
|
Success,
|
|
|
|
|
ReadError,
|
|
|
|
|
CannotHandle
|
|
|
|
|
};
|
|
|
|
|
|
2009-07-13 15:00:20 +02:00
|
|
|
// This enum must match the indexes of the reloadBehavior widget
|
|
|
|
|
// in generalsettings.ui
|
2010-03-19 10:28:05 +01:00
|
|
|
enum ReloadSetting {
|
|
|
|
|
AlwaysAsk = 0,
|
2009-07-13 15:00:20 +02:00
|
|
|
ReloadUnmodified = 1,
|
2010-03-19 10:28:05 +01:00
|
|
|
IgnoreAll = 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ChangeTrigger {
|
|
|
|
|
TriggerInternal,
|
|
|
|
|
TriggerExternal
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ChangeType {
|
|
|
|
|
TypeContents,
|
|
|
|
|
TypeRemoved
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ReloadBehavior {
|
|
|
|
|
BehaviorAsk,
|
|
|
|
|
BehaviorSilent
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ReloadFlag {
|
|
|
|
|
FlagReload,
|
|
|
|
|
FlagIgnore
|
2009-07-13 15:00:20 +02:00
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-05-07 17:34:42 +02:00
|
|
|
IDocument(QObject *parent = nullptr);
|
2015-06-04 15:54:10 +02:00
|
|
|
~IDocument() override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
void setId(Utils::Id id);
|
|
|
|
|
Utils::Id id() const;
|
2014-03-05 15:58:12 +01:00
|
|
|
|
2015-06-04 15:21:02 +02:00
|
|
|
virtual OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName);
|
2015-06-02 17:14:48 +02:00
|
|
|
|
2016-03-16 20:52:48 +02:00
|
|
|
virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false);
|
2016-01-15 15:24:49 +01:00
|
|
|
|
|
|
|
|
virtual QByteArray contents() const;
|
2013-07-15 15:14:10 +02:00
|
|
|
virtual bool setContents(const QByteArray &contents);
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const Utils::FilePath &filePath() const;
|
|
|
|
|
virtual void setFilePath(const Utils::FilePath &filePath);
|
2013-07-04 22:25:15 +02:00
|
|
|
QString displayName() const;
|
2015-02-25 14:36:03 +02:00
|
|
|
void setPreferredDisplayName(const QString &name);
|
2016-06-13 12:59:35 +02:00
|
|
|
QString preferredDisplayName() const;
|
2015-02-25 14:36:03 +02:00
|
|
|
QString plainDisplayName() const;
|
|
|
|
|
void setUniqueDisplayName(const QString &name);
|
2016-06-13 12:59:35 +02:00
|
|
|
QString uniqueDisplayName() const;
|
2013-07-04 22:25:15 +02:00
|
|
|
|
2021-01-13 16:27:02 +01:00
|
|
|
bool isFileReadOnly() const;
|
2013-07-12 15:36:29 +02:00
|
|
|
bool isTemporary() const;
|
|
|
|
|
void setTemporary(bool temporary);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-14 15:01:05 +01:00
|
|
|
virtual QString fallbackSaveAsPath() const;
|
|
|
|
|
virtual QString fallbackSaveAsFileName() const;
|
2014-06-26 02:15:34 +02:00
|
|
|
|
2015-01-11 23:32:51 +02:00
|
|
|
QString mimeType() const;
|
2014-06-26 02:15:34 +02:00
|
|
|
void setMimeType(const QString &mimeType);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-05-10 20:43:03 +02:00
|
|
|
virtual bool shouldAutoSave() const;
|
2016-10-20 08:34:55 +00:00
|
|
|
virtual bool isModified() const;
|
2016-03-16 20:52:48 +02:00
|
|
|
virtual bool isSaveAsAllowed() const;
|
2016-06-13 12:59:35 +02:00
|
|
|
bool isSuspendAllowed() const;
|
|
|
|
|
void setSuspendAllowed(bool value);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-15 11:53:46 +02:00
|
|
|
virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
|
2016-03-16 20:52:48 +02:00
|
|
|
virtual bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-01-13 16:27:02 +01:00
|
|
|
void checkPermissions();
|
2009-05-08 15:48:00 +02:00
|
|
|
|
2013-07-04 13:30:26 +02:00
|
|
|
bool autoSave(QString *errorString, const QString &filePath);
|
2011-05-10 20:43:03 +02:00
|
|
|
void setRestoredFrom(const QString &name);
|
|
|
|
|
void removeAutoSaveFile();
|
|
|
|
|
|
2015-01-11 23:32:51 +02:00
|
|
|
bool hasWriteWarning() const;
|
|
|
|
|
void setWriteWarning(bool has);
|
2011-05-06 12:48:44 +02:00
|
|
|
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBar *infoBar();
|
2011-05-06 12:48:44 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
2016-01-15 15:24:49 +01:00
|
|
|
// For meta data changes: file name, modified state, ...
|
2008-12-02 12:01:29 +01:00
|
|
|
void changed();
|
2016-01-15 15:24:49 +01:00
|
|
|
|
|
|
|
|
// For changes in the contents of the document
|
|
|
|
|
void contentsChanged();
|
|
|
|
|
|
2014-06-26 02:15:34 +02:00
|
|
|
void mimeTypeChanged();
|
2010-05-28 14:06:57 +02:00
|
|
|
|
|
|
|
|
void aboutToReload();
|
2013-06-20 12:49:19 +02:00
|
|
|
void reloadFinished(bool success);
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void filePathChanged(const Utils::FilePath &oldName, const Utils::FilePath &newName);
|
2011-05-06 12:48:44 +02:00
|
|
|
|
|
|
|
|
private:
|
2015-01-11 23:32:51 +02:00
|
|
|
Internal::IDocumentPrivate *d;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
} // namespace Core
|