forked from qt-creator/qt-creator
Core: filepathify IDocument
Change-Id: I364a80d070c5f90433309c281c4906ee101a1a1a Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -47,10 +47,10 @@ AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *ed
|
||||
this, &Core::IDocument::changed);
|
||||
}
|
||||
|
||||
bool AndroidManifestDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||
bool AndroidManifestDocument::save(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
{
|
||||
m_editorWidget->preSave();
|
||||
bool result = TextDocument::save(errorString, fileName, autoSave);
|
||||
bool result = TextDocument::save(errorString, filePath, autoSave);
|
||||
m_editorWidget->postSave();
|
||||
return result;
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ class AndroidManifestDocument : public TextEditor::TextDocument
|
||||
{
|
||||
public:
|
||||
explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget);
|
||||
bool save(QString *errorString, const QString &fileName = QString(),
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath,
|
||||
bool autoSave = false) override;
|
||||
|
||||
bool isModified() const override;
|
||||
|
@@ -230,28 +230,27 @@ public:
|
||||
return type == TypeRemoved ? BehaviorSilent : IDocument::reloadBehavior(state, type);
|
||||
}
|
||||
|
||||
bool save(QString *errorString, const QString &fn, bool autoSave) override
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override
|
||||
{
|
||||
QTC_ASSERT(!autoSave, return true); // bineditor does not support autosave - it would be a bit expensive
|
||||
const FilePath fileNameToUse = fn.isEmpty() ? filePath() : FilePath::fromString(fn);
|
||||
if (m_widget->save(errorString, filePath().toString(), fileNameToUse.toString())) {
|
||||
const FilePath &fileNameToUse = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
if (m_widget->save(errorString, this->filePath().toString(), fileNameToUse.toString())) {
|
||||
setFilePath(fileNameToUse);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override
|
||||
{
|
||||
QTC_CHECK(fileName == realFileName); // The bineditor can do no autosaving
|
||||
return openImpl(errorString, fileName);
|
||||
QTC_CHECK(filePath == realFilePath); // The bineditor can do no autosaving
|
||||
return openImpl(errorString, filePath);
|
||||
}
|
||||
|
||||
OpenResult openImpl(QString *errorString, const QString &fileName, quint64 offset = 0)
|
||||
OpenResult openImpl(QString *errorString, const Utils::FilePath &filePath, quint64 offset = 0)
|
||||
{
|
||||
QFile file(fileName);
|
||||
QFile file(filePath.toString());
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
file.close();
|
||||
quint64 size = static_cast<quint64>(file.size());
|
||||
@@ -274,12 +273,11 @@ public:
|
||||
}
|
||||
if (offset >= size)
|
||||
return OpenResult::CannotHandle;
|
||||
setFilePath(FilePath::fromString(fileName));
|
||||
setFilePath(filePath);
|
||||
m_widget->setSizes(offset, file.size());
|
||||
return OpenResult::Success;
|
||||
}
|
||||
QString errStr = tr("Cannot open %1: %2").arg(
|
||||
QDir::toNativeSeparators(fileName), file.errorString());
|
||||
QString errStr = tr("Cannot open %1: %2").arg(filePath.toUserOutput(), file.errorString());
|
||||
if (errorString)
|
||||
*errorString = errStr;
|
||||
else
|
||||
@@ -312,7 +310,7 @@ public:
|
||||
void provideNewRange(quint64 offset)
|
||||
{
|
||||
if (filePath().exists())
|
||||
openImpl(nullptr, filePath().toString(), offset);
|
||||
openImpl(nullptr, filePath(), offset);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -332,7 +330,7 @@ public:
|
||||
emit aboutToReload();
|
||||
int cPos = m_widget->cursorPosition();
|
||||
m_widget->clear();
|
||||
const bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success);
|
||||
const bool success = (openImpl(errorString, filePath()) == OpenResult::Success);
|
||||
m_widget->setCursorPosition(cPos);
|
||||
emit reloadFinished(success);
|
||||
return success;
|
||||
|
@@ -69,7 +69,7 @@ void VirtualFileSystemOverlay::update()
|
||||
.pathAppended(doc->filePath().fileName() + ".auto");
|
||||
while (saved.path.exists())
|
||||
saved.path = saved.path + ".1";
|
||||
if (!doc->save(&error, saved.path.toString(), true)) {
|
||||
if (!doc->save(&error, saved.path, true)) {
|
||||
qCDebug(LOG) << error;
|
||||
continue;
|
||||
}
|
||||
|
@@ -744,17 +744,19 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
|
||||
return notSaved.isEmpty();
|
||||
}
|
||||
|
||||
bool DocumentManager::saveDocument(IDocument *document, const QString &fileName, bool *isReadOnly)
|
||||
bool DocumentManager::saveDocument(IDocument *document,
|
||||
const Utils::FilePath &filePath,
|
||||
bool *isReadOnly)
|
||||
{
|
||||
bool ret = true;
|
||||
QString effName = fileName.isEmpty() ? document->filePath().toString() : fileName;
|
||||
expectFileChange(effName); // This only matters to other IDocuments which refer to this file
|
||||
const Utils::FilePath &savePath = filePath.isEmpty() ? document->filePath() : filePath;
|
||||
expectFileChange(savePath.toString()); // This only matters to other IDocuments which refer to this file
|
||||
bool addWatcher = removeDocument(document); // So that our own IDocument gets no notification at all
|
||||
|
||||
QString errorString;
|
||||
if (!document->save(&errorString, fileName, false)) {
|
||||
if (!document->save(&errorString, filePath, false)) {
|
||||
if (isReadOnly) {
|
||||
QFile ofi(effName);
|
||||
QFile ofi(savePath.toString());
|
||||
// Check whether the existing file is writable
|
||||
if (!ofi.open(QIODevice::ReadWrite) && ofi.open(QIODevice::ReadOnly)) {
|
||||
*isReadOnly = true;
|
||||
@@ -769,7 +771,7 @@ bool DocumentManager::saveDocument(IDocument *document, const QString &fileName,
|
||||
}
|
||||
|
||||
addDocument(document, addWatcher);
|
||||
unexpectFileChange(effName);
|
||||
unexpectFileChange(savePath.toString());
|
||||
m_instance->updateSaveAll();
|
||||
return ret;
|
||||
}
|
||||
@@ -1314,7 +1316,7 @@ void DocumentManager::checkForReload()
|
||||
// handle deleted files
|
||||
EditorManager::closeDocuments(documentsToClose, false);
|
||||
for (auto it = documentsToSave.cbegin(), end = documentsToSave.cend(); it != end; ++it) {
|
||||
saveDocument(it.key(), it.value());
|
||||
saveDocument(it.key(), Utils::FilePath::fromString(it.value()));
|
||||
it.key()->checkPermissions();
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <coreplugin/core_global.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QObject>
|
||||
@@ -79,7 +80,7 @@ public:
|
||||
static QString filePathKey(const QString &filePath, ResolveMode resolveMode);
|
||||
|
||||
static bool saveDocument(IDocument *document,
|
||||
const QString &fileName = QString(),
|
||||
const Utils::FilePath &filePath = Utils::FilePath(),
|
||||
bool *isReadOnly = nullptr);
|
||||
|
||||
static QString allDocumentFactoryFiltersString(QString *allFilesFilter);
|
||||
|
@@ -861,6 +861,9 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
|
||||
IEditor *editor = nullptr;
|
||||
auto overrideCursor = Utils::OverrideCursor(QCursor(Qt::WaitCursor));
|
||||
|
||||
auto fp = Utils::FilePath::fromString(fn);
|
||||
auto realFp = Utils::FilePath::fromString(realFn);
|
||||
|
||||
IEditorFactory *factory = factories.takeFirst();
|
||||
while (factory) {
|
||||
editor = createEditor(factory, fn);
|
||||
@@ -870,7 +873,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
|
||||
}
|
||||
|
||||
QString errorString;
|
||||
IDocument::OpenResult openResult = editor->document()->open(&errorString, fn, realFn);
|
||||
IDocument::OpenResult openResult = editor->document()->open(&errorString, fp, realFp);
|
||||
if (openResult == IDocument::OpenResult::Success)
|
||||
break;
|
||||
|
||||
@@ -933,7 +936,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
|
||||
return nullptr;
|
||||
|
||||
if (realFn != fn)
|
||||
editor->document()->setRestoredFrom(realFn);
|
||||
editor->document()->setRestoredFrom(realFp);
|
||||
addEditor(editor);
|
||||
|
||||
if (newEditor)
|
||||
@@ -2351,7 +2354,7 @@ void EditorManagerPrivate::autoSave()
|
||||
|| !QFileInfo(savePath).isWritable()) // FIXME: save them to a dedicated directory
|
||||
continue;
|
||||
QString errorString;
|
||||
if (!document->autoSave(&errorString, saveName))
|
||||
if (!document->autoSave(&errorString, Utils::FilePath::fromUserInput(saveName)))
|
||||
errors << errorString;
|
||||
}
|
||||
if (!errors.isEmpty())
|
||||
@@ -2463,7 +2466,7 @@ bool EditorManagerPrivate::saveDocument(IDocument *document)
|
||||
|
||||
emit m_instance->aboutToSave(document);
|
||||
// try saving, no matter what isReadOnly tells us
|
||||
success = DocumentManager::saveDocument(document, QString(), &isReadOnly);
|
||||
success = DocumentManager::saveDocument(document, FilePath(), &isReadOnly);
|
||||
|
||||
if (!success && isReadOnly) {
|
||||
MakeWritableResult answer = makeFileWritable(document);
|
||||
@@ -2503,7 +2506,7 @@ bool EditorManagerPrivate::saveDocumentAs(IDocument *document)
|
||||
}
|
||||
|
||||
emit m_instance->aboutToSave(document);
|
||||
const bool success = DocumentManager::saveDocument(document, absoluteFilePath.toString());
|
||||
const bool success = DocumentManager::saveDocument(document, absoluteFilePath);
|
||||
document->checkPermissions();
|
||||
|
||||
// TODO: There is an issue to be treated here. The new file might be of a different mime
|
||||
|
@@ -224,7 +224,7 @@ public:
|
||||
Utils::FilePath filePath;
|
||||
QString preferredDisplayName;
|
||||
QString uniqueDisplayName;
|
||||
QString autoSaveName;
|
||||
Utils::FilePath autoSavePath;
|
||||
Utils::InfoBar *infoBar = nullptr;
|
||||
Id id;
|
||||
optional<bool> fileIsReadOnly;
|
||||
@@ -291,14 +291,14 @@ Id IDocument::id() const
|
||||
The open() method is used to load the contents of a file when a document is
|
||||
opened in an editor.
|
||||
|
||||
If the document is opened from an auto save file, \a realFileName is the
|
||||
name of the auto save file that should be loaded, and \a fileName is the
|
||||
If the document is opened from an auto save file, \a realFilePath is the
|
||||
name of the auto save file that should be loaded, and \a filePath is the
|
||||
file name of the resulting file. In that case, the contents of the auto
|
||||
save file should be loaded, the file name of the IDocument should be set to
|
||||
\a fileName, and the document state be set to modified.
|
||||
\a filePath, and the document state be set to modified.
|
||||
|
||||
If the editor is opened from a regular file, \a fileName and \a
|
||||
realFileName are the same.
|
||||
If the editor is opened from a regular file, \a filePath and \a
|
||||
filePath are the same.
|
||||
|
||||
Use \a errorString to return an error message if this document cannot
|
||||
handle the file contents.
|
||||
@@ -312,16 +312,16 @@ Id IDocument::id() const
|
||||
\sa shouldAutoSave()
|
||||
\sa setFilePath()
|
||||
*/
|
||||
IDocument::OpenResult IDocument::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
IDocument::OpenResult IDocument::open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
Q_UNUSED(fileName)
|
||||
Q_UNUSED(realFileName)
|
||||
Q_UNUSED(filePath)
|
||||
Q_UNUSED(realFilePath)
|
||||
return OpenResult::CannotHandle;
|
||||
}
|
||||
|
||||
/*!
|
||||
Saves the contents of the document to the \a fileName on disk.
|
||||
Saves the contents of the document to the \a filePath on disk.
|
||||
|
||||
If \a autoSave is \c true, the saving is done for an auto-save, so the
|
||||
document should avoid cleanups or other operations that it does for
|
||||
@@ -335,10 +335,10 @@ IDocument::OpenResult IDocument::open(QString *errorString, const QString &fileN
|
||||
|
||||
\sa shouldAutoSave()
|
||||
*/
|
||||
bool IDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||
bool IDocument::save(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
Q_UNUSED(fileName)
|
||||
Q_UNUSED(filePath)
|
||||
Q_UNUSED(autoSave)
|
||||
return false;
|
||||
}
|
||||
@@ -613,11 +613,11 @@ void IDocument::setMimeType(const QString &mimeType)
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
bool IDocument::autoSave(QString *errorString, const QString &fileName)
|
||||
bool IDocument::autoSave(QString *errorString, const FilePath &filePath)
|
||||
{
|
||||
if (!save(errorString, fileName, true))
|
||||
if (!save(errorString, filePath, true))
|
||||
return false;
|
||||
d->autoSaveName = fileName;
|
||||
d->autoSavePath = filePath;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -626,9 +626,9 @@ static const char kRestoredAutoSave[] = "RestoredAutoSave";
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void IDocument::setRestoredFrom(const QString &name)
|
||||
void IDocument::setRestoredFrom(const Utils::FilePath &path)
|
||||
{
|
||||
d->autoSaveName = name;
|
||||
d->autoSavePath = path;
|
||||
d->restored = true;
|
||||
Utils::InfoBarEntry info(Id(kRestoredAutoSave),
|
||||
tr("File was restored from auto-saved copy. "
|
||||
@@ -641,9 +641,9 @@ void IDocument::setRestoredFrom(const QString &name)
|
||||
*/
|
||||
void IDocument::removeAutoSaveFile()
|
||||
{
|
||||
if (!d->autoSaveName.isEmpty()) {
|
||||
QFile::remove(d->autoSaveName);
|
||||
d->autoSaveName.clear();
|
||||
if (!d->autoSavePath.isEmpty()) {
|
||||
QFile::remove(d->autoSavePath.toString());
|
||||
d->autoSavePath.clear();
|
||||
if (d->restored) {
|
||||
d->restored = false;
|
||||
infoBar()->removeInfo(Id(kRestoredAutoSave));
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QObject>
|
||||
@@ -87,9 +88,9 @@ public:
|
||||
void setId(Utils::Id id);
|
||||
Utils::Id id() const;
|
||||
|
||||
virtual OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
virtual OpenResult open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
||||
|
||||
virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false);
|
||||
virtual bool save(QString *errorString, const Utils::FilePath &filePath = Utils::FilePath(), bool autoSave = false);
|
||||
|
||||
virtual QByteArray contents() const;
|
||||
virtual bool setContents(const QByteArray &contents);
|
||||
@@ -124,8 +125,8 @@ public:
|
||||
|
||||
void checkPermissions();
|
||||
|
||||
bool autoSave(QString *errorString, const QString &filePath);
|
||||
void setRestoredFrom(const QString &name);
|
||||
bool autoSave(QString *errorString, const Utils::FilePath &filePath);
|
||||
void setRestoredFrom(const Utils::FilePath &path);
|
||||
void removeAutoSaveFile();
|
||||
|
||||
bool hasWriteWarning() const;
|
||||
|
@@ -82,7 +82,7 @@ QByteArray BaseTextDocument::decodingErrorSample() const
|
||||
}
|
||||
|
||||
/*!
|
||||
Writes out the contents (\a data) of the text file \a fileName.
|
||||
Writes out the contents (\a data) of the text file \a filePath.
|
||||
Uses the format obtained from the last read() of the file.
|
||||
|
||||
If an error occurs while writing the file, \a errorMessage is set to the
|
||||
@@ -91,13 +91,15 @@ QByteArray BaseTextDocument::decodingErrorSample() const
|
||||
Returns whether the operation was successful.
|
||||
*/
|
||||
|
||||
bool BaseTextDocument::write(const QString &fileName, const QString &data, QString *errorMessage) const
|
||||
bool BaseTextDocument::write(const Utils::FilePath &filePath,
|
||||
const QString &data,
|
||||
QString *errorMessage) const
|
||||
{
|
||||
return write(fileName, format(), data, errorMessage);
|
||||
return write(filePath, format(), data, errorMessage);
|
||||
}
|
||||
|
||||
/*!
|
||||
Writes out the contents (\a data) of the text file \a fileName.
|
||||
Writes out the contents (\a data) of the text file \a filePath.
|
||||
Uses the custom format \a format.
|
||||
|
||||
If an error occurs while writing the file, \a errorMessage is set to the
|
||||
@@ -106,11 +108,14 @@ bool BaseTextDocument::write(const QString &fileName, const QString &data, QStri
|
||||
Returns whether the operation was successful.
|
||||
*/
|
||||
|
||||
bool BaseTextDocument::write(const QString &fileName, const Utils::TextFileFormat &format, const QString &data, QString *errorMessage) const
|
||||
bool BaseTextDocument::write(const Utils::FilePath &filePath,
|
||||
const Utils::TextFileFormat &format,
|
||||
const QString &data,
|
||||
QString *errorMessage) const
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << this << fileName;
|
||||
return format.writeFile(Utils::FilePath::fromString(fileName), data, errorMessage);
|
||||
qDebug() << Q_FUNC_INFO << this << filePath;
|
||||
return format.writeFile(filePath, data, errorMessage);
|
||||
}
|
||||
|
||||
void BaseTextDocument::setSupportsUtf8Bom(bool value)
|
||||
@@ -124,7 +129,7 @@ void BaseTextDocument::setLineTerminationMode(Utils::TextFileFormat::LineTermina
|
||||
}
|
||||
|
||||
/*!
|
||||
Autodetects file format and reads the text file specified by \a fileName
|
||||
Autodetects file format and reads the text file specified by \a filePath
|
||||
into a list of strings specified by \a plainTextList.
|
||||
|
||||
If an error occurs while writing the file, \a errorString is set to the
|
||||
@@ -133,16 +138,21 @@ void BaseTextDocument::setLineTerminationMode(Utils::TextFileFormat::LineTermina
|
||||
Returns whether the operation was successful.
|
||||
*/
|
||||
|
||||
BaseTextDocument::ReadResult BaseTextDocument::read(const QString &fileName, QStringList *plainTextList, QString *errorString)
|
||||
BaseTextDocument::ReadResult BaseTextDocument::read(const Utils::FilePath &filePath,
|
||||
QStringList *plainTextList,
|
||||
QString *errorString)
|
||||
{
|
||||
d->m_readResult =
|
||||
Utils::TextFileFormat::readFile(Utils::FilePath::fromString(fileName), codec(),
|
||||
plainTextList, &d->m_format, errorString, &d->m_decodingErrorSample);
|
||||
d->m_readResult = Utils::TextFileFormat::readFile(filePath,
|
||||
codec(),
|
||||
plainTextList,
|
||||
&d->m_format,
|
||||
errorString,
|
||||
&d->m_decodingErrorSample);
|
||||
return d->m_readResult;
|
||||
}
|
||||
|
||||
/*!
|
||||
Autodetects file format and reads the text file specified by \a fileName
|
||||
Autodetects file format and reads the text file specified by \a filePath
|
||||
into \a plainText.
|
||||
|
||||
If an error occurs while writing the file, \a errorString is set to the
|
||||
@@ -151,11 +161,16 @@ BaseTextDocument::ReadResult BaseTextDocument::read(const QString &fileName, QSt
|
||||
Returns whether the operation was successful.
|
||||
*/
|
||||
|
||||
BaseTextDocument::ReadResult BaseTextDocument::read(const QString &fileName, QString *plainText, QString *errorString)
|
||||
BaseTextDocument::ReadResult BaseTextDocument::read(const Utils::FilePath &filePath,
|
||||
QString *plainText,
|
||||
QString *errorString)
|
||||
{
|
||||
d->m_readResult =
|
||||
Utils::TextFileFormat::readFile(Utils::FilePath::fromString(fileName), codec(),
|
||||
plainText, &d->m_format, errorString, &d->m_decodingErrorSample);
|
||||
d->m_readResult = Utils::TextFileFormat::readFile(filePath,
|
||||
codec(),
|
||||
plainText,
|
||||
&d->m_format,
|
||||
errorString,
|
||||
&d->m_decodingErrorSample);
|
||||
return d->m_readResult;
|
||||
}
|
||||
|
||||
|
@@ -50,14 +50,14 @@ public:
|
||||
bool supportsUtf8Bom() const;
|
||||
Utils::TextFileFormat::LineTerminationMode lineTerminationMode() const;
|
||||
|
||||
ReadResult read(const QString &fileName, QStringList *plainTextList, QString *errorString);
|
||||
ReadResult read(const QString &fileName, QString *plainText, QString *errorString);
|
||||
ReadResult read(const Utils::FilePath &filePath, QStringList *plainTextList, QString *errorString);
|
||||
ReadResult read(const Utils::FilePath &filePath, QString *plainText, QString *errorString);
|
||||
|
||||
bool hasDecodingError() const;
|
||||
QByteArray decodingErrorSample() const;
|
||||
|
||||
bool write(const QString &fileName, const QString &data, QString *errorMessage) const;
|
||||
bool write(const QString &fileName, const Utils::TextFileFormat &format, const QString &data, QString *errorMessage) const;
|
||||
bool write(const Utils::FilePath &filePath, const QString &data, QString *errorMessage) const;
|
||||
bool write(const Utils::FilePath &filePath, const Utils::TextFileFormat &format, const QString &data, QString *errorMessage) const;
|
||||
|
||||
void setSupportsUtf8Bom(bool value);
|
||||
void setLineTerminationMode(Utils::TextFileFormat::LineTerminationMode mode);
|
||||
|
@@ -447,7 +447,7 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
|
||||
return indenter()->tabSettings().value_or(TextEditor::TextDocument::tabSettings());
|
||||
}
|
||||
|
||||
bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||
bool CppEditorDocument::save(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Utils::ExecuteOnDestruction resetSettingsOnScopeExit;
|
||||
|
||||
@@ -490,7 +490,7 @@ bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool
|
||||
setStorageSettings(settings);
|
||||
}
|
||||
|
||||
return TextEditor::TextDocument::save(errorString, fileName, autoSave);
|
||||
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -71,7 +71,7 @@ public:
|
||||
TextEditor::TabSettings tabSettings() const override;
|
||||
|
||||
bool save(QString *errorString,
|
||||
const QString &fileName = QString(),
|
||||
const Utils::FilePath &filePath = Utils::FilePath(),
|
||||
bool autoSave = false) override;
|
||||
|
||||
signals:
|
||||
|
@@ -106,7 +106,9 @@ public:
|
||||
QScopedPointer<TextEditor::BaseTextEditor> editor(
|
||||
TextEditor::PlainTextEditorFactory::createPlainTextEditor());
|
||||
QString error;
|
||||
editor->document()->open(&error, document->fileName(), document->fileName());
|
||||
editor->document()->open(&error,
|
||||
Utils::FilePath::fromString(document->fileName()),
|
||||
Utils::FilePath::fromString(document->fileName()));
|
||||
QVERIFY(error.isEmpty());
|
||||
|
||||
// Set cursor position
|
||||
|
@@ -65,51 +65,51 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
|
||||
m_resourceHandler, &ResourceHandler::updateResources);
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult FormWindowFile::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
Core::IDocument::OpenResult FormWindowFile::open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "FormWindowFile::open" << fileName;
|
||||
qDebug() << "FormWindowFile::open" << filePath.toUserOutput();
|
||||
|
||||
QDesignerFormWindowInterface *form = formWindow();
|
||||
QTC_ASSERT(form, return OpenResult::CannotHandle);
|
||||
|
||||
if (fileName.isEmpty())
|
||||
if (filePath.isEmpty())
|
||||
return OpenResult::ReadError;
|
||||
|
||||
const QFileInfo fi(fileName);
|
||||
const QString absfileName = fi.absoluteFilePath();
|
||||
|
||||
QString contents;
|
||||
Utils::TextFileFormat::ReadResult readResult = read(absfileName, &contents, errorString);
|
||||
Utils::TextFileFormat::ReadResult readResult = read(filePath.absoluteFilePath(),
|
||||
&contents,
|
||||
errorString);
|
||||
if (readResult == Utils::TextFileFormat::ReadEncodingError)
|
||||
return OpenResult::CannotHandle;
|
||||
if (readResult != Utils::TextFileFormat::ReadSuccess)
|
||||
return OpenResult::ReadError;
|
||||
|
||||
form->setFileName(absfileName);
|
||||
form->setFileName(filePath.absoluteFilePath().toString());
|
||||
const QByteArray contentsBA = contents.toUtf8();
|
||||
QBuffer str;
|
||||
str.setData(contentsBA);
|
||||
str.open(QIODevice::ReadOnly);
|
||||
if (!form->setContents(&str, errorString))
|
||||
return OpenResult::CannotHandle;
|
||||
form->setDirty(fileName != realFileName);
|
||||
form->setDirty(filePath != realFilePath);
|
||||
|
||||
syncXmlFromFormWindow();
|
||||
setFilePath(Utils::FilePath::fromString(absfileName));
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setShouldAutoSave(false);
|
||||
resourceHandler()->updateProjectResources();
|
||||
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave)
|
||||
bool FormWindowFile::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
const FilePath actualName = name.isEmpty() ? filePath() : FilePath::fromString(name);
|
||||
const FilePath &actualName = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << Q_FUNC_INFO << name << "->" << actualName;
|
||||
qDebug() << Q_FUNC_INFO << filePath << "->" << actualName;
|
||||
|
||||
QTC_ASSERT(m_formWindow, return false);
|
||||
|
||||
@@ -119,7 +119,7 @@ bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSa
|
||||
const QString oldFormName = m_formWindow->fileName();
|
||||
if (!autoSave)
|
||||
m_formWindow->setFileName(actualName.toString());
|
||||
const bool writeOK = writeFile(actualName.toString(), errorString);
|
||||
const bool writeOK = writeFile(actualName, errorString);
|
||||
m_shouldAutoSave = false;
|
||||
if (autoSave)
|
||||
return writeOK;
|
||||
@@ -228,7 +228,7 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
|
||||
} else {
|
||||
emit aboutToReload();
|
||||
const bool success
|
||||
= (open(errorString, filePath().toString(), filePath().toString()) == OpenResult::Success);
|
||||
= (open(errorString, filePath(), filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
return success;
|
||||
}
|
||||
@@ -247,11 +247,11 @@ QString FormWindowFile::fallbackSaveAsFileName() const
|
||||
return m_suggestedName;
|
||||
}
|
||||
|
||||
bool FormWindowFile::writeFile(const QString &fn, QString *errorString) const
|
||||
bool FormWindowFile::writeFile(const Utils::FilePath &filePath, QString *errorString) const
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << Q_FUNC_INFO << filePath() << fn;
|
||||
return write(fn, format(), m_formWindow->contents(), errorString);
|
||||
qDebug() << Q_FUNC_INFO << this->filePath() << filePath;
|
||||
return write(filePath, format(), m_formWindow->contents(), errorString);
|
||||
}
|
||||
|
||||
QDesignerFormWindowInterface *FormWindowFile::formWindow() const
|
||||
|
@@ -48,9 +48,9 @@ public:
|
||||
~FormWindowFile() override { }
|
||||
|
||||
// IDocument
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
QByteArray contents() const override;
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
bool shouldAutoSave() const override;
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
// Internal
|
||||
void setFallbackSaveAsFileName(const QString &fileName);
|
||||
|
||||
bool writeFile(const QString &fileName, QString *errorString) const;
|
||||
bool writeFile(const Utils::FilePath &filePath, QString *errorString) const;
|
||||
|
||||
QDesignerFormWindowInterface *formWindow() const;
|
||||
void syncXmlFromFormWindow();
|
||||
|
@@ -265,7 +265,7 @@ bool DiffEditorDocument::isSaveAsAllowed() const
|
||||
return state() == LoadOK;
|
||||
}
|
||||
|
||||
bool DiffEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||
bool DiffEditorDocument::save(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
Q_UNUSED(autoSave)
|
||||
@@ -273,7 +273,7 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
|
||||
if (state() != LoadOK)
|
||||
return false;
|
||||
|
||||
const bool ok = write(fileName, format(), plainText(), errorString);
|
||||
const bool ok = write(filePath, format(), plainText(), errorString);
|
||||
|
||||
if (!ok)
|
||||
return false;
|
||||
@@ -282,9 +282,8 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
|
||||
setDescription(QString());
|
||||
Core::EditorManager::clearUniqueId(this);
|
||||
|
||||
const QFileInfo fi(fileName);
|
||||
setTemporary(false);
|
||||
setFilePath(FilePath::fromString(fi.absoluteFilePath()));
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setPreferredDisplayName(QString());
|
||||
emit temporaryStateChanged();
|
||||
|
||||
@@ -306,16 +305,16 @@ bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeTyp
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return true;
|
||||
return open(errorString, filePath().toString(), filePath().toString()) == OpenResult::Success;
|
||||
return open(errorString, filePath(), filePath()) == OpenResult::Success;
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
QTC_CHECK(fileName == realFileName); // does not support autosave
|
||||
QTC_CHECK(filePath == realFilePath); // does not support autosave
|
||||
beginReload();
|
||||
QString patch;
|
||||
ReadResult readResult = read(fileName, &patch, errorString);
|
||||
ReadResult readResult = read(filePath, &patch, errorString);
|
||||
if (readResult == TextFileFormat::ReadIOError
|
||||
|| readResult == TextFileFormat::ReadMemoryAllocationError) {
|
||||
return OpenResult::ReadError;
|
||||
@@ -326,13 +325,12 @@ Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const
|
||||
if (!ok) {
|
||||
*errorString = tr("Could not parse patch file \"%1\". "
|
||||
"The content is not of unified diff format.")
|
||||
.arg(fileName);
|
||||
.arg(filePath.toUserOutput());
|
||||
} else {
|
||||
const QFileInfo fi(fileName);
|
||||
setTemporary(false);
|
||||
emit temporaryStateChanged();
|
||||
setFilePath(FilePath::fromString(fi.absoluteFilePath()));
|
||||
setDiffFiles(fileDataList, fi.absolutePath());
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setDiffFiles(fileDataList, filePath.absoluteFilePath().toString());
|
||||
}
|
||||
endReload(ok);
|
||||
if (!ok && readResult == TextFileFormat::ReadEncodingError)
|
||||
|
@@ -81,11 +81,11 @@ public:
|
||||
QString fallbackSaveAsFileName() const override;
|
||||
|
||||
bool isSaveAsAllowed() const override;
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
void reload();
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
bool selectEncoding();
|
||||
State state() const { return m_state; }
|
||||
|
||||
|
@@ -202,7 +202,7 @@ void DiffEditorWidgetController::patch(bool revert, int fileIndex, int chunkInde
|
||||
if (PatchTool::runPatch(EditorManager::defaultTextCodec()->fromUnicode(patch),
|
||||
contentsCopyDir, 0, revert)) {
|
||||
QString errorString;
|
||||
if (textDocument->reload(&errorString, contentsCopyFileName))
|
||||
if (textDocument->reload(&errorString, FilePath::fromString(contentsCopyFileName)))
|
||||
m_document->reload();
|
||||
}
|
||||
}
|
||||
|
@@ -283,14 +283,14 @@ void GitEditorWidget::addDiffActions(QMenu *menu, const DiffChunk &chunk)
|
||||
});
|
||||
}
|
||||
|
||||
void GitEditorWidget::aboutToOpen(const QString &fileName, const QString &realFileName)
|
||||
void GitEditorWidget::aboutToOpen(const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
Q_UNUSED(realFileName)
|
||||
Q_UNUSED(realFilePath)
|
||||
Utils::Id editorId = textDocument()->id();
|
||||
if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID
|
||||
|| editorId == Git::Constants::GIT_REBASE_EDITOR_ID) {
|
||||
QFileInfo fi(fileName);
|
||||
const QString gitPath = fi.absolutePath();
|
||||
const QString gitPath = filePath.absolutePath().toString();
|
||||
setSource(gitPath);
|
||||
textDocument()->setCodec(
|
||||
GitClient::instance()->encoding(gitPath, "i18n.commitEncoding"));
|
||||
|
@@ -59,7 +59,7 @@ private:
|
||||
|
||||
void init() override;
|
||||
void addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk) override;
|
||||
void aboutToOpen(const QString &fileName, const QString &realFileName) override;
|
||||
void aboutToOpen(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath) override;
|
||||
QString changeUnderCursor(const QTextCursor &) const override;
|
||||
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const override;
|
||||
QString decorateVersion(const QString &revision) const override;
|
||||
|
@@ -80,22 +80,25 @@ ImageViewerFile::~ImageViewerFile()
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult ImageViewerFile::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
Core::IDocument::OpenResult ImageViewerFile::open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realfilePath)
|
||||
{
|
||||
QTC_CHECK(fileName == realFileName); // does not support auto save
|
||||
OpenResult success = openImpl(errorString, fileName);
|
||||
QTC_CHECK(filePath == realfilePath); // does not support auto save
|
||||
OpenResult success = openImpl(errorString, filePath);
|
||||
emit openFinished(success == OpenResult::Success);
|
||||
return success;
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString, const QString &fileName)
|
||||
Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath)
|
||||
{
|
||||
cleanUp();
|
||||
|
||||
if (!QFileInfo(fileName).isReadable())
|
||||
if (!filePath.isReadableFile())
|
||||
return OpenResult::ReadError;
|
||||
|
||||
const QString &fileName = filePath.toString();
|
||||
QByteArray format = QImageReader::imageFormat(fileName);
|
||||
// if it is impossible to recognize a file format - file will not be open correctly
|
||||
if (format.isEmpty()) {
|
||||
@@ -141,7 +144,7 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString, cons
|
||||
emit imageSizeChanged(m_pixmap->size());
|
||||
}
|
||||
|
||||
setFilePath(Utils::FilePath::fromString(fileName));
|
||||
setFilePath(filePath);
|
||||
setMimeType(Utils::mimeTypeForFile(fileName).name());
|
||||
return OpenResult::Success;
|
||||
}
|
||||
@@ -163,7 +166,7 @@ bool ImageViewerFile::reload(QString *errorString,
|
||||
if (flag == FlagIgnore)
|
||||
return true;
|
||||
emit aboutToReload();
|
||||
bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success);
|
||||
bool success = (openImpl(errorString, filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
return success;
|
||||
}
|
||||
|
@@ -57,8 +57,8 @@ public:
|
||||
ImageViewerFile();
|
||||
~ImageViewerFile() override;
|
||||
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
|
||||
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
||||
@@ -78,7 +78,7 @@ signals:
|
||||
|
||||
private:
|
||||
void cleanUp();
|
||||
OpenResult openImpl(QString *errorString, const QString &fileName);
|
||||
OpenResult openImpl(QString *errorString, const Utils::FilePath &filePath);
|
||||
|
||||
ImageType m_type = TypeInvalid;
|
||||
#ifndef QT_NO_SVG
|
||||
|
@@ -66,26 +66,25 @@ ModelDocument::~ModelDocument()
|
||||
delete d;
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult ModelDocument::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
Q_UNUSED(fileName)
|
||||
Q_UNUSED(filePath)
|
||||
|
||||
OpenResult result = load(errorString, realFileName);
|
||||
OpenResult result = load(errorString, realFilePath.toString());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ModelDocument::save(QString *errorString, const QString &name, bool autoSave)
|
||||
bool ModelDocument::save(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (!d->documentController) {
|
||||
*errorString = tr("No model loaded. Cannot save.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QString actualName = filePath().toString();
|
||||
if (!name.isEmpty())
|
||||
actualName = name;
|
||||
d->documentController->projectController()->setFileName(actualName);
|
||||
const Utils::FilePath actualName = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
d->documentController->projectController()->setFileName(actualName.toString());
|
||||
try {
|
||||
d->documentController->projectController()->save();
|
||||
} catch (const qmt::Exception &ex) {
|
||||
|
@@ -48,9 +48,10 @@ signals:
|
||||
void contentSet();
|
||||
|
||||
public:
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
OpenResult open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
bool shouldAutoSave() const override;
|
||||
bool isModified() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
|
@@ -120,15 +120,15 @@ ResourceEditorW::~ResourceEditorW()
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
|
||||
const QString &fileName,
|
||||
const QString &realFileName)
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
if (debugResourceEditorW)
|
||||
qDebug() << "ResourceEditorW::open: " << fileName;
|
||||
qDebug() << "ResourceEditorW::open: " << filePath;
|
||||
|
||||
setBlockDirtyChanged(true);
|
||||
|
||||
m_model->setFileName(realFileName);
|
||||
m_model->setFileName(realFilePath.toString());
|
||||
|
||||
OpenResult openResult = m_model->reload();
|
||||
if (openResult != OpenResult::Success) {
|
||||
@@ -138,22 +138,21 @@ Core::IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
|
||||
return openResult;
|
||||
}
|
||||
|
||||
setFilePath(FilePath::fromString(fileName));
|
||||
setFilePath(filePath);
|
||||
setBlockDirtyChanged(false);
|
||||
m_model->setDirty(fileName != realFileName);
|
||||
m_model->setDirty(filePath != realFilePath);
|
||||
m_shouldAutoSave = false;
|
||||
|
||||
emit loaded(true);
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool ResourceEditorDocument::save(QString *errorString, const QString &name, bool autoSave)
|
||||
bool ResourceEditorDocument::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (debugResourceEditorW)
|
||||
qDebug(">ResourceEditorW::save: %s", qPrintable(name));
|
||||
qDebug() << ">ResourceEditorW::save: " << filePath;
|
||||
|
||||
const FilePath oldFileName = filePath();
|
||||
const FilePath actualName = name.isEmpty() ? oldFileName : FilePath::fromString(name);
|
||||
const FilePath &actualName = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
if (actualName.isEmpty())
|
||||
return false;
|
||||
|
||||
@@ -161,14 +160,14 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo
|
||||
m_model->setFileName(actualName.toString());
|
||||
if (!m_model->save()) {
|
||||
*errorString = m_model->errorMessage();
|
||||
m_model->setFileName(oldFileName.toString());
|
||||
m_model->setFileName(this->filePath().toString());
|
||||
m_blockDirtyChanged = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shouldAutoSave = false;
|
||||
if (autoSave) {
|
||||
m_model->setFileName(oldFileName.toString());
|
||||
m_model->setFileName(this->filePath().toString());
|
||||
m_model->setDirty(true);
|
||||
m_blockDirtyChanged = false;
|
||||
return true;
|
||||
@@ -272,8 +271,7 @@ bool ResourceEditorDocument::reload(QString *errorString, ReloadFlag flag, Chang
|
||||
if (flag == FlagIgnore)
|
||||
return true;
|
||||
emit aboutToReload();
|
||||
QString fn = filePath().toString();
|
||||
const bool success = (open(errorString, fn, fn) == OpenResult::Success);
|
||||
const bool success = (open(errorString, filePath(), filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
return success;
|
||||
}
|
||||
|
@@ -51,9 +51,9 @@ public:
|
||||
ResourceEditorDocument(QObject *parent = nullptr);
|
||||
|
||||
//IDocument
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
QString plainText() const;
|
||||
QByteArray contents() const override;
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
|
@@ -57,32 +57,33 @@ ScxmlEditorDocument::ScxmlEditorDocument(MainWidget *designWidget, QObject *pare
|
||||
});
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
Q_UNUSED(realFileName)
|
||||
Q_UNUSED(realFilePath)
|
||||
|
||||
if (fileName.isEmpty())
|
||||
if (filePath.isEmpty())
|
||||
return OpenResult::ReadError;
|
||||
|
||||
if (!m_designWidget)
|
||||
return OpenResult::ReadError;
|
||||
|
||||
const QFileInfo fi(fileName);
|
||||
const QString absfileName = fi.absoluteFilePath();
|
||||
if (!m_designWidget->load(absfileName)) {
|
||||
const FilePath &absoluteFilePath = filePath.absoluteFilePath();
|
||||
if (!m_designWidget->load(absoluteFilePath.toString())) {
|
||||
*errorString = m_designWidget->errorMessage();
|
||||
return OpenResult::ReadError;
|
||||
}
|
||||
|
||||
setFilePath(Utils::FilePath::fromString(absfileName));
|
||||
setFilePath(absoluteFilePath);
|
||||
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool ScxmlEditorDocument::save(QString *errorString, const QString &name, bool autoSave)
|
||||
bool ScxmlEditorDocument::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
const FilePath oldFileName = filePath();
|
||||
const FilePath actualName = name.isEmpty() ? oldFileName : FilePath::fromString(name);
|
||||
const FilePath oldFileName = this->filePath();
|
||||
const FilePath actualName = filePath.isEmpty() ? oldFileName : filePath;
|
||||
if (actualName.isEmpty())
|
||||
return false;
|
||||
bool dirty = m_designWidget->isDirty();
|
||||
|
@@ -49,8 +49,10 @@ public:
|
||||
explicit ScxmlEditorDocument(Common::MainWidget *designWidget, QObject *parent = nullptr);
|
||||
|
||||
// IDocument
|
||||
OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName) override;
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
OpenResult open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
bool shouldAutoSave() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
bool isModified() const override;
|
||||
|
@@ -600,7 +600,7 @@ SyntaxHighlighter *TextDocument::syntaxHighlighter() const
|
||||
* If \a autoSave is true, the cursor will be restored and some signals suppressed
|
||||
* and we do not clean up the text file (cleanWhitespace(), ensureFinalNewLine()).
|
||||
*/
|
||||
bool TextDocument::save(QString *errorString, const QString &saveFileName, bool autoSave)
|
||||
bool TextDocument::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTextCursor cursor(&d->m_document);
|
||||
|
||||
@@ -638,11 +638,9 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool
|
||||
if (d->m_storageSettings.m_addFinalNewLine)
|
||||
ensureFinalNewLine(cursor);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
}
|
||||
|
||||
QString fName = filePath().toString();
|
||||
if (!saveFileName.isEmpty())
|
||||
fName = saveFileName;
|
||||
const Utils::FilePath &savePath = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
|
||||
// check if UTF8-BOM has to be added or removed
|
||||
Utils::TextFileFormat saveFormat = format();
|
||||
@@ -659,7 +657,7 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool
|
||||
}
|
||||
}
|
||||
|
||||
const bool ok = write(fName, saveFormat, d->m_document.toPlainText(), errorString);
|
||||
const bool ok = write(savePath, saveFormat, d->m_document.toPlainText(), errorString);
|
||||
|
||||
// restore text cursor and scroll bar positions
|
||||
if (autoSave && undos < d->m_document.availableUndoSteps()) {
|
||||
@@ -681,9 +679,8 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool
|
||||
return true;
|
||||
|
||||
// inform about the new filename
|
||||
const QFileInfo fi(fName);
|
||||
d->m_document.setModified(false); // also triggers update of the block revisions
|
||||
setFilePath(Utils::FilePath::fromUserInput(fi.absoluteFilePath()));
|
||||
setFilePath(savePath.absoluteFilePath());
|
||||
emit changed();
|
||||
return true;
|
||||
}
|
||||
@@ -715,33 +712,35 @@ bool TextDocument::isModified() const
|
||||
return d->m_document.isModified();
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult TextDocument::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
Core::IDocument::OpenResult TextDocument::open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
emit aboutToOpen(fileName, realFileName);
|
||||
OpenResult success = openImpl(errorString, fileName, realFileName, /*reload =*/ false);
|
||||
emit aboutToOpen(filePath, realFilePath);
|
||||
OpenResult success = openImpl(errorString, filePath, realFilePath, /*reload =*/ false);
|
||||
if (success == OpenResult::Success) {
|
||||
setMimeType(Utils::mimeTypeForFile(fileName).name());
|
||||
setMimeType(Utils::mimeTypeForFile(filePath.toString()).name());
|
||||
emit openFinishedSuccessfully();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName, bool reload)
|
||||
Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath,
|
||||
bool reload)
|
||||
{
|
||||
QStringList content;
|
||||
|
||||
ReadResult readResult = Utils::TextFileFormat::ReadIOError;
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
const QFileInfo fi(fileName);
|
||||
readResult = read(realFileName, &content, errorString);
|
||||
if (!filePath.isEmpty()) {
|
||||
readResult = read(realFilePath, &content, errorString);
|
||||
const int chunks = content.size();
|
||||
|
||||
// Don't call setUndoRedoEnabled(true) when reload is true and filenames are different,
|
||||
// since it will reset the undo's clear index
|
||||
if (!reload || fileName == realFileName)
|
||||
if (!reload || filePath == realFilePath)
|
||||
d->m_document.setUndoRedoEnabled(reload);
|
||||
|
||||
QTextCursor c(&d->m_document);
|
||||
@@ -775,7 +774,7 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString, const Q
|
||||
|
||||
// Don't call setUndoRedoEnabled(true) when reload is true and filenames are different,
|
||||
// since it will reset the undo's clear index
|
||||
if (!reload || fileName == realFileName)
|
||||
if (!reload || filePath == realFilePath)
|
||||
d->m_document.setUndoRedoEnabled(true);
|
||||
|
||||
auto documentLayout =
|
||||
@@ -783,8 +782,8 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString, const Q
|
||||
QTC_ASSERT(documentLayout, return OpenResult::CannotHandle);
|
||||
documentLayout->lastSaveRevision = d->m_autoSaveRevision = d->m_document.revision();
|
||||
d->updateRevisions();
|
||||
d->m_document.setModified(fileName != realFileName);
|
||||
setFilePath(Utils::FilePath::fromUserInput(fi.absoluteFilePath()));
|
||||
d->m_document.setModified(filePath != realFilePath);
|
||||
setFilePath(filePath);
|
||||
}
|
||||
if (readResult == Utils::TextFileFormat::ReadIOError)
|
||||
return OpenResult::ReadError;
|
||||
@@ -800,10 +799,10 @@ bool TextDocument::reload(QString *errorString, QTextCodec *codec)
|
||||
|
||||
bool TextDocument::reload(QString *errorString)
|
||||
{
|
||||
return reload(errorString, filePath().toString());
|
||||
return reload(errorString, filePath());
|
||||
}
|
||||
|
||||
bool TextDocument::reload(QString *errorString, const QString &realFileName)
|
||||
bool TextDocument::reload(QString *errorString, const FilePath &realFilePath)
|
||||
{
|
||||
emit aboutToReload();
|
||||
auto documentLayout =
|
||||
@@ -812,8 +811,8 @@ bool TextDocument::reload(QString *errorString, const QString &realFileName)
|
||||
if (documentLayout)
|
||||
marks = documentLayout->documentClosing(); // removes text marks non-permanently
|
||||
|
||||
const QString &file = filePath().toString();
|
||||
bool success = openImpl(errorString, file, realFileName, /*reload =*/ true) == OpenResult::Success;
|
||||
bool success = openImpl(errorString, filePath(), realFilePath, /*reload =*/true)
|
||||
== OpenResult::Success;
|
||||
|
||||
if (documentLayout)
|
||||
documentLayout->documentReloaded(marks, this); // re-adds text marks
|
||||
|
@@ -112,7 +112,7 @@ public:
|
||||
void removeMarkFromMarksCache(TextMark *mark);
|
||||
|
||||
// IDocument implementation.
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
QByteArray contents() const override;
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
bool shouldAutoSave() const override;
|
||||
@@ -127,10 +127,10 @@ public:
|
||||
void setFallbackSaveAsPath(const QString &fallbackSaveAsPath);
|
||||
void setFallbackSaveAsFileName(const QString &fallbackSaveAsFileName);
|
||||
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
virtual bool reload(QString *errorString);
|
||||
bool reload(QString *errorString, const QString &realFileName);
|
||||
bool reload(QString *errorString, const Utils::FilePath &realFilePath);
|
||||
|
||||
bool setPlainText(const QString &text);
|
||||
QTextDocument *document() const;
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
const std::function<Utils::FilePath()> &filePath);
|
||||
|
||||
signals:
|
||||
void aboutToOpen(const QString &fileName, const QString &realFileName);
|
||||
void aboutToOpen(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
||||
void openFinishedSuccessfully();
|
||||
void contentsChangedWithPosition(int position, int charsRemoved, int charsAdded);
|
||||
void tabSettingsChanged();
|
||||
@@ -167,7 +167,9 @@ protected:
|
||||
virtual void applyFontSettings();
|
||||
|
||||
private:
|
||||
OpenResult openImpl(QString *errorString, const QString &fileName, const QString &realFileName,
|
||||
OpenResult openImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFileName,
|
||||
bool reload);
|
||||
void cleanWhitespace(QTextCursor &cursor, bool inEntireDocument, bool cleanIndentation);
|
||||
void ensureFinalNewLine(QTextCursor &cursor);
|
||||
|
@@ -1464,10 +1464,10 @@ TextDocument *TextEditorWidget::textDocument() const
|
||||
return d->m_document.data();
|
||||
}
|
||||
|
||||
void TextEditorWidget::aboutToOpen(const QString &fileName, const QString &realFileName)
|
||||
void TextEditorWidget::aboutToOpen(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath)
|
||||
{
|
||||
Q_UNUSED(fileName)
|
||||
Q_UNUSED(realFileName)
|
||||
Q_UNUSED(filePath)
|
||||
Q_UNUSED(realFilePath)
|
||||
}
|
||||
|
||||
void TextEditorWidget::openFinishedSuccessfully()
|
||||
|
@@ -186,7 +186,7 @@ public:
|
||||
TextDocument *textDocument() const;
|
||||
QSharedPointer<TextDocument> textDocumentPtr() const;
|
||||
|
||||
virtual void aboutToOpen(const QString &fileName, const QString &realFileName);
|
||||
virtual void aboutToOpen(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
||||
virtual void openFinishedSuccessfully();
|
||||
// IEditor
|
||||
QByteArray saveState() const;
|
||||
|
@@ -51,22 +51,23 @@ SubmitEditorFile::SubmitEditorFile(VcsBaseSubmitEditor *editor) :
|
||||
this, &Core::IDocument::contentsChanged);
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult SubmitEditorFile::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
Core::IDocument::OpenResult SubmitEditorFile::open(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
if (filePath.isEmpty())
|
||||
return OpenResult::ReadError;
|
||||
|
||||
FileReader reader;
|
||||
if (!reader.fetch(Utils::FilePath::fromString(realFileName), QIODevice::Text, errorString))
|
||||
if (!reader.fetch(realFilePath, QIODevice::Text, errorString))
|
||||
return OpenResult::ReadError;
|
||||
|
||||
const QString text = QString::fromLocal8Bit(reader.data());
|
||||
if (!m_editor->setFileContents(text.toUtf8()))
|
||||
return OpenResult::CannotHandle;
|
||||
|
||||
setFilePath(FilePath::fromString(fileName));
|
||||
setModified(fileName != realFileName);
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setModified(filePath != realFilePath);
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
@@ -88,16 +89,16 @@ void SubmitEditorFile::setModified(bool modified)
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool SubmitEditorFile::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||
bool SubmitEditorFile::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
const FilePath fName = fileName.isEmpty() ? filePath() : FilePath::fromString(fileName);
|
||||
const FilePath &fName = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
FileSaver saver(fName, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
saver.write(m_editor->fileContents());
|
||||
if (!saver.finalize(errorString))
|
||||
return false;
|
||||
if (autoSave)
|
||||
return true;
|
||||
setFilePath(FilePath::fromUserInput(fName.toFileInfo().absoluteFilePath()));
|
||||
setFilePath(fName.absoluteFilePath());
|
||||
setModified(false);
|
||||
if (!errorString->isEmpty())
|
||||
return false;
|
||||
|
@@ -39,13 +39,13 @@ class SubmitEditorFile : public Core::IDocument
|
||||
public:
|
||||
explicit SubmitEditorFile(VcsBaseSubmitEditor *editor);
|
||||
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
QByteArray contents() const override;
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
|
||||
bool isModified() const override { return m_modified; }
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
|
||||
|
||||
void setModified(bool modified = true);
|
||||
|
Reference in New Issue
Block a user