2013-05-07 14:02:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-05-07 14:02:08 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-01-30 13:31:11 +01:00
|
|
|
#include "diffeditordocument.h"
|
2013-07-04 22:25:15 +02:00
|
|
|
#include "diffeditorconstants.h"
|
2014-01-31 09:01:49 +01:00
|
|
|
#include "diffeditorcontroller.h"
|
2014-06-30 15:04:36 +02:00
|
|
|
#include "diffutils.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-07-04 22:25:15 +02:00
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2014-06-30 15:04:36 +02:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTextCodec>
|
2013-05-07 14:02:08 +02:00
|
|
|
|
|
|
|
|
namespace DiffEditor {
|
|
|
|
|
|
2014-03-10 13:28:34 +01:00
|
|
|
DiffEditorDocument::DiffEditorDocument() :
|
2014-06-30 15:04:36 +02:00
|
|
|
Core::TextDocument(),
|
2014-07-07 10:23:11 +02:00
|
|
|
m_controller(new DiffEditorController(this))
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
2014-03-05 15:58:12 +01:00
|
|
|
setId(Constants::DIFF_EDITOR_ID);
|
2014-07-23 23:08:04 +03:00
|
|
|
setMimeType(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE));
|
2013-07-12 15:36:29 +02:00
|
|
|
setTemporary(true);
|
2013-05-07 14:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
DiffEditorDocument::~DiffEditorDocument()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 13:00:35 +01:00
|
|
|
DiffEditorController *DiffEditorDocument::controller() const
|
2014-01-31 09:01:49 +01:00
|
|
|
{
|
2014-07-07 10:23:11 +02:00
|
|
|
return m_controller;
|
2014-01-31 09:01:49 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-30 13:31:11 +01:00
|
|
|
bool DiffEditorDocument::setContents(const QByteArray &contents)
|
2013-07-15 15:14:10 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(contents);
|
2013-07-19 12:37:17 +03:00
|
|
|
return true;
|
2013-07-15 15:14:10 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-30 15:04:36 +02:00
|
|
|
QString DiffEditorDocument::defaultPath() const
|
|
|
|
|
{
|
2014-07-07 10:23:11 +02:00
|
|
|
if (!m_controller)
|
2014-06-30 15:04:36 +02:00
|
|
|
return QString();
|
|
|
|
|
|
2014-07-07 10:23:11 +02:00
|
|
|
return m_controller->workingDirectory();
|
2014-06-30 15:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-30 13:31:11 +01:00
|
|
|
bool DiffEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
2014-01-30 13:06:23 +01:00
|
|
|
Q_UNUSED(errorString)
|
|
|
|
|
Q_UNUSED(autoSave)
|
2014-06-30 15:04:36 +02:00
|
|
|
|
2014-07-07 10:23:11 +02:00
|
|
|
if (!m_controller)
|
2014-06-30 15:04:36 +02:00
|
|
|
return false;
|
|
|
|
|
|
2014-07-07 10:23:11 +02:00
|
|
|
const QString contents = DiffUtils::makePatch(m_controller->diffFiles());
|
2014-06-30 15:04:36 +02:00
|
|
|
|
|
|
|
|
const bool ok = write(fileName, format(), contents, errorString);
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QFileInfo fi(fileName);
|
|
|
|
|
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
|
|
|
|
setDisplayName(QString());
|
|
|
|
|
return true;
|
2013-05-07 14:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-30 13:31:11 +01:00
|
|
|
Core::IDocument::ReloadBehavior DiffEditorDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(state)
|
|
|
|
|
Q_UNUSED(type)
|
|
|
|
|
return BehaviorSilent;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 13:31:11 +01:00
|
|
|
bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(errorString)
|
|
|
|
|
Q_UNUSED(flag)
|
|
|
|
|
Q_UNUSED(type)
|
2014-01-30 13:06:23 +01:00
|
|
|
return false;
|
2013-05-07 14:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace DiffEditor
|