forked from qt-creator/qt-creator
Move IEditor::createNew to IDocument::setContents
The method is for setting the contents, so it belongs to the document, and should be named correspondingly. Change-Id: I40363dc08f11268f530885b512e4a88e8b10d096 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -195,6 +195,14 @@ public:
|
||||
return QLatin1String(Constants::C_BINEDITOR_MIMETYPE);
|
||||
}
|
||||
|
||||
bool setContents(const QByteArray &contents)
|
||||
{
|
||||
if (!contents.isEmpty())
|
||||
return false;
|
||||
m_widget->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool save(QString *errorString, const QString &fn, bool autoSave)
|
||||
{
|
||||
QTC_ASSERT(!autoSave, return true); // bineditor does not support autosave - it would be a bit expensive
|
||||
@@ -342,11 +350,6 @@ public:
|
||||
delete m_widget;
|
||||
}
|
||||
|
||||
bool createNew(const QString & /* contents */ = QString()) {
|
||||
m_widget->clear();
|
||||
m_file->setFilePath(QString());
|
||||
return true;
|
||||
}
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName) {
|
||||
QTC_ASSERT(fileName == realFileName, return false); // The bineditor can do no autosaving
|
||||
return m_file->open(errorString, fileName);
|
||||
|
@@ -929,7 +929,7 @@ void ClearCasePlugin::ccDiffWithPred(const QString &workingDir, const QStringLis
|
||||
if (files.count() == 1) {
|
||||
// Show in the same editor if diff has been executed before
|
||||
if (Core::IEditor *existingEditor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
existingEditor->createNew(result);
|
||||
existingEditor->document()->setContents(result.toUtf8());
|
||||
Core::EditorManager::activateEditor(existingEditor);
|
||||
setDiffBaseDirectory(existingEditor, workingDir);
|
||||
return;
|
||||
@@ -1189,7 +1189,7 @@ void ClearCasePlugin::history(const QString &workingDir,
|
||||
const QString id = VcsBase::VcsBaseEditorWidget::getTitleId(workingDir, files);
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::LogOutput, workingDir, files);
|
||||
if (Core::IEditor *editor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(response.stdOut);
|
||||
editor->document()->setContents(response.stdOut.toUtf8());
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
const QString title = QString::fromLatin1("cc history %1").arg(id);
|
||||
@@ -1301,7 +1301,7 @@ void ClearCasePlugin::vcsAnnotate(const QString &workingDir, const QString &file
|
||||
const QStringList files = QStringList(file);
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::AnnotateOutput, workingDir, files);
|
||||
if (Core::IEditor *editor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(res);
|
||||
editor->document()->setContents(res.toUtf8());
|
||||
VcsBase::VcsBaseEditorWidget::gotoLineOfEditor(editor, lineNumber);
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
@@ -1338,7 +1338,7 @@ void ClearCasePlugin::describe(const QString &source, const QString &changeNr)
|
||||
// the common usage pattern of continuously changing and diffing a file
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::DiffOutput, source, QStringList(), changeNr);
|
||||
if (Core::IEditor *editor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(description);
|
||||
editor->document()->setContents(description.toUtf8());
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
const QString title = QString::fromLatin1("cc describe %1").arg(id);
|
||||
@@ -1397,7 +1397,7 @@ Core::IEditor *ClearCasePlugin::showOutputInEditor(const QString& title, const Q
|
||||
qDebug() << "ClearCasePlugin::showOutputInEditor" << title << id.name()
|
||||
<< "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
|
||||
QString s = title;
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(id, &s, output);
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(id, &s, output.toUtf8());
|
||||
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
|
||||
this, SLOT(annotateVersion(QString,QString,int)));
|
||||
ClearCaseEditor *e = qobject_cast<ClearCaseEditor*>(editor->widget());
|
||||
|
@@ -1627,7 +1627,7 @@ QStringList EditorManager::getOpenFileNames() const
|
||||
|
||||
IEditor *EditorManager::openEditorWithContents(const Id &editorId,
|
||||
QString *titlePattern,
|
||||
const QString &contents)
|
||||
const QByteArray &contents)
|
||||
{
|
||||
if (debugEditorManager)
|
||||
qDebug() << Q_FUNC_INFO << editorId.name() << titlePattern << contents;
|
||||
@@ -1669,7 +1669,7 @@ IEditor *EditorManager::openEditorWithContents(const Id &editorId,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!edt->createNew(contents)) {
|
||||
if (!edt->document()->setContents(contents)) {
|
||||
QApplication::restoreOverrideCursor();
|
||||
delete edt;
|
||||
edt = 0;
|
||||
|
@@ -115,7 +115,7 @@ public:
|
||||
const Id &editorId = Id(), OpenEditorFlags flags = 0,
|
||||
bool *newEditor = 0);
|
||||
static IEditor *openEditorWithContents(const Id &editorId,
|
||||
QString *titlePattern = 0, const QString &contents = QString());
|
||||
QString *titlePattern = 0, const QByteArray &contents = QByteArray());
|
||||
|
||||
static bool openExternalEditor(const QString &fileName, const Id &editorId);
|
||||
|
||||
|
@@ -47,7 +47,6 @@ public:
|
||||
IEditor(QObject *parent = 0) : IContext(parent) {}
|
||||
virtual ~IEditor() {}
|
||||
|
||||
virtual bool createNew(const QString &contents = QString()) = 0;
|
||||
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName) = 0;
|
||||
virtual IDocument *document() = 0;
|
||||
virtual Core::Id id() const = 0;
|
||||
|
@@ -57,6 +57,18 @@ IDocument::~IDocument()
|
||||
delete m_infoBar;
|
||||
}
|
||||
|
||||
/*!
|
||||
Used for example by EditorManager::openEditorWithContents() to set the contents
|
||||
of this document.
|
||||
Returns if setting the contents was successful.
|
||||
The base implementation does nothing and returns false.
|
||||
*/
|
||||
bool IDocument::setContents(const QByteArray &contents)
|
||||
{
|
||||
Q_UNUSED(contents)
|
||||
return false;
|
||||
}
|
||||
|
||||
IDocument::ReloadBehavior IDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
||||
{
|
||||
if (type == TypePermissions)
|
||||
|
@@ -82,6 +82,8 @@ public:
|
||||
virtual ~IDocument();
|
||||
|
||||
virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false) = 0;
|
||||
virtual bool setContents(const QByteArray &contents);
|
||||
|
||||
QString filePath() const { return m_filePath; }
|
||||
virtual void setFilePath(const QString &filePath);
|
||||
QString displayName() const;
|
||||
|
@@ -591,7 +591,7 @@ void CvsPlugin::cvsDiff(const CvsDiffParameters &p)
|
||||
// Show in the same editor if diff has been executed before
|
||||
const QString tag = VcsBaseEditorWidget::editorTag(DiffOutput, p.workingDir, p.files);
|
||||
if (IEditor *existingEditor = VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
existingEditor->createNew(output);
|
||||
existingEditor->document()->setContents(output.toUtf8());
|
||||
EditorManager::activateEditor(existingEditor);
|
||||
setDiffBaseDirectory(existingEditor, p.workingDir);
|
||||
return;
|
||||
@@ -859,7 +859,7 @@ void CvsPlugin::filelog(const QString &workingDir,
|
||||
// the common usage pattern of continuously changing and diffing a file
|
||||
const QString tag = VcsBaseEditorWidget::editorTag(LogOutput, workingDir, files);
|
||||
if (Core::IEditor *editor = VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(response.stdOut);
|
||||
editor->document()->setContents(response.stdOut.toUtf8());
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
const QString title = QString::fromLatin1("cvs log %1").arg(id);
|
||||
@@ -1001,7 +1001,7 @@ void CvsPlugin::annotate(const QString &workingDir, const QString &file,
|
||||
|
||||
const QString tag = VcsBaseEditorWidget::editorTag(AnnotateOutput, workingDir, QStringList(file), revision);
|
||||
if (IEditor *editor = VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(response.stdOut);
|
||||
editor->document()->setContents(response.stdOut.toUtf8());
|
||||
VcsBaseEditorWidget::gotoLineOfEditor(editor, lineNumber);
|
||||
EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
@@ -1197,7 +1197,7 @@ bool CvsPlugin::describe(const QString &repositoryPath,
|
||||
// the common usage pattern of continuously changing and diffing a file
|
||||
const QString commitId = entries.front().revisions.front().commitId;
|
||||
if (IEditor *editor = VcsBaseEditorWidget::locateEditorByTag(commitId)) {
|
||||
editor->createNew(output);
|
||||
editor->document()->setContents(output.toUtf8());
|
||||
EditorManager::activateEditor(editor);
|
||||
setDiffBaseDirectory(editor, repositoryPath);
|
||||
} else {
|
||||
@@ -1270,7 +1270,7 @@ IEditor *CvsPlugin::showOutputInEditor(const QString& title, const QString &outp
|
||||
qDebug() << "CVSPlugin::showOutputInEditor" << title << id.name()
|
||||
<< "source=" << source << "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
|
||||
QString s = title;
|
||||
IEditor *editor = EditorManager::openEditorWithContents(id, &s, output);
|
||||
IEditor *editor = EditorManager::openEditorWithContents(id, &s, output.toUtf8());
|
||||
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
|
||||
this, SLOT(vcsAnnotate(QString,QString,int)));
|
||||
CvsEditor *e = qobject_cast<CvsEditor*>(editor->widget());
|
||||
|
@@ -2530,7 +2530,7 @@ void DebuggerPluginPrivate::openTextEditor(const QString &titlePattern0,
|
||||
return;
|
||||
QString titlePattern = titlePattern0;
|
||||
IEditor *editor = EditorManager::openEditorWithContents(
|
||||
CC::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, contents);
|
||||
CC::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, contents.toUtf8());
|
||||
QTC_ASSERT(editor, return);
|
||||
EditorManager::activateEditor(editor, EditorManager::IgnoreNavigationHistory);
|
||||
}
|
||||
|
@@ -115,7 +115,7 @@ void SourceAgent::setContent(const QString &filePath, const QString &content)
|
||||
d->editor = qobject_cast<ITextEditor *>(
|
||||
EditorManager::openEditorWithContents(
|
||||
CppEditor::Constants::CPPEDITOR_ID,
|
||||
&titlePattern, content));
|
||||
&titlePattern, content.toUtf8()));
|
||||
QTC_ASSERT(d->editor, return);
|
||||
d->editor->document()->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
|
||||
|
||||
|
@@ -38,16 +38,10 @@
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
# include <QDesignerFormWindowInterface>
|
||||
# include <QBuffer>
|
||||
#else
|
||||
# include "qt_private/formwindowbase_p.h"
|
||||
#endif
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QDesignerFormWindowInterface>
|
||||
#include <QFileInfo>
|
||||
#include <QApplication>
|
||||
|
||||
namespace Designer {
|
||||
|
||||
@@ -74,47 +68,6 @@ FormWindowEditor::~FormWindowEditor()
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool FormWindowEditor::createNew(const QString &contents)
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "FormWindowEditor::createNew" << contents.size();
|
||||
|
||||
syncXmlEditor(QString());
|
||||
|
||||
QDesignerFormWindowInterface *form = d->m_widget->formWindowFile()->formWindow();
|
||||
QTC_ASSERT(form, return false);
|
||||
|
||||
if (contents.isEmpty())
|
||||
return false;
|
||||
|
||||
// If we have an override cursor, reset it over Designer loading,
|
||||
// should it pop up messages about missing resources or such.
|
||||
const bool hasOverrideCursor = QApplication::overrideCursor();
|
||||
QCursor overrideCursor;
|
||||
if (hasOverrideCursor) {
|
||||
overrideCursor = QCursor(*QApplication::overrideCursor());
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
const bool success = form->setContents(contents);
|
||||
#else
|
||||
form->setContents(contents);
|
||||
const bool success = form->mainContainer() != 0;
|
||||
#endif
|
||||
|
||||
if (hasOverrideCursor)
|
||||
QApplication::setOverrideCursor(overrideCursor);
|
||||
|
||||
if (!success)
|
||||
return false;
|
||||
|
||||
syncXmlEditor(contents);
|
||||
d->m_widget->formWindowFile()->setFilePath(QString());
|
||||
d->m_widget->formWindowFile()->setShouldAutoSave(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FormWindowEditor::slotOpen(QString *errorString, const QString &fileName)
|
||||
{
|
||||
open(errorString, fileName, fileName);
|
||||
@@ -152,7 +105,7 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
|
||||
return false;
|
||||
#endif
|
||||
form->setDirty(fileName != realFileName);
|
||||
syncXmlEditor(contents);
|
||||
d->m_widget->formWindowFile()->syncXmlFromFormWindow();
|
||||
|
||||
d->m_widget->formWindowFile()->setFilePath(absfileName);
|
||||
d->m_widget->formWindowFile()->setShouldAutoSave(false);
|
||||
@@ -167,12 +120,7 @@ void FormWindowEditor::syncXmlEditor()
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "FormWindowEditor::syncXmlEditor" << d->m_widget->formWindowFile()->filePath();
|
||||
syncXmlEditor(contents());
|
||||
}
|
||||
|
||||
void FormWindowEditor::syncXmlEditor(const QString &contents)
|
||||
{
|
||||
editorWidget()->document()->setPlainText(contents);
|
||||
d->m_widget->formWindowFile()->syncXmlFromFormWindow();
|
||||
}
|
||||
|
||||
Core::Id FormWindowEditor::id() const
|
||||
@@ -187,17 +135,7 @@ QWidget *FormWindowEditor::toolBar()
|
||||
|
||||
QString FormWindowEditor::contents() const
|
||||
{
|
||||
#if QT_VERSION >= 0x050000 // TODO: No warnings about spacers here
|
||||
const QDesignerFormWindowInterface *fw = d->m_widget->formWindowFile()->formWindow();
|
||||
QTC_ASSERT(fw, return QString());
|
||||
return fw->contents();
|
||||
#else
|
||||
// No warnings about spacers here
|
||||
const qdesigner_internal::FormWindowBase *fw =
|
||||
qobject_cast<const qdesigner_internal::FormWindowBase *>(d->m_widget->formWindowFile()->formWindow());
|
||||
QTC_ASSERT(fw, return QString());
|
||||
return fw->fileContents();
|
||||
#endif
|
||||
return d->m_widget->formWindowFile()->formWindowContents();
|
||||
}
|
||||
|
||||
bool FormWindowEditor::isDesignModePreferred() const
|
||||
|
@@ -66,7 +66,6 @@ public:
|
||||
virtual ~FormWindowEditor();
|
||||
|
||||
// IEditor
|
||||
virtual bool createNew(const QString &contents = QString());
|
||||
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
virtual Core::Id id() const;
|
||||
|
||||
@@ -84,8 +83,6 @@ private slots:
|
||||
void slotOpen(QString *errorString, const QString &fileName);
|
||||
|
||||
private:
|
||||
void syncXmlEditor(const QString &contents);
|
||||
|
||||
FormWindowEditorPrivate *d;
|
||||
};
|
||||
|
||||
|
@@ -32,13 +32,16 @@
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesignerFormWindowInterface>
|
||||
#include <QDesignerFormWindowManagerInterface>
|
||||
#include <QDesignerFormEditorInterface>
|
||||
#if QT_VERSION < 0x050000
|
||||
# include "qt_private/qsimpleresource_p.h"
|
||||
# include "qt_private/formwindowbase_p.h"
|
||||
#endif
|
||||
|
||||
#include <QTextDocument>
|
||||
#include <QUndoStack>
|
||||
|
||||
#include <QFileInfo>
|
||||
@@ -103,6 +106,45 @@ bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSa
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FormWindowFile::setContents(const QByteArray &contents)
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << Q_FUNC_INFO << contents.size();
|
||||
|
||||
document()->setPlainText(QString());
|
||||
|
||||
QTC_ASSERT(m_formWindow, return false);
|
||||
|
||||
if (contents.isEmpty())
|
||||
return false;
|
||||
|
||||
// If we have an override cursor, reset it over Designer loading,
|
||||
// should it pop up messages about missing resources or such.
|
||||
const bool hasOverrideCursor = QApplication::overrideCursor();
|
||||
QCursor overrideCursor;
|
||||
if (hasOverrideCursor) {
|
||||
overrideCursor = QCursor(*QApplication::overrideCursor());
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
const bool success = m_formWindow->setContents(QString::fromUtf8(contents));
|
||||
#else
|
||||
m_formWindow->setContents(QString::fromUtf8(contents));
|
||||
const bool success = m_formWindow->mainContainer() != 0;
|
||||
#endif
|
||||
|
||||
if (hasOverrideCursor)
|
||||
QApplication::setOverrideCursor(overrideCursor);
|
||||
|
||||
if (!success)
|
||||
return false;
|
||||
|
||||
syncXmlFromFormWindow();
|
||||
setShouldAutoSave(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FormWindowFile::setFilePath(const QString &newName)
|
||||
{
|
||||
m_formWindow->setFileName(newName);
|
||||
@@ -184,6 +226,25 @@ QDesignerFormWindowInterface *FormWindowFile::formWindow() const
|
||||
return m_formWindow;
|
||||
}
|
||||
|
||||
void FormWindowFile::syncXmlFromFormWindow()
|
||||
{
|
||||
document()->setPlainText(formWindowContents());
|
||||
}
|
||||
|
||||
QString FormWindowFile::formWindowContents() const
|
||||
{
|
||||
#if QT_VERSION >= 0x050000 // TODO: No warnings about spacers here
|
||||
QTC_ASSERT(m_formWindow, return QString());
|
||||
return m_formWindow->contents();
|
||||
#else
|
||||
// No warnings about spacers here
|
||||
const qdesigner_internal::FormWindowBase *fw =
|
||||
qobject_cast<const qdesigner_internal::FormWindowBase *>(m_formWindow);
|
||||
QTC_ASSERT(fw, return QString());
|
||||
return fw->fileContents();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FormWindowFile::slotFormWindowRemoved(QDesignerFormWindowInterface *w)
|
||||
{
|
||||
// Release formwindow as soon as the FormWindowManager removes
|
||||
|
@@ -51,14 +51,15 @@ public:
|
||||
~FormWindowFile() { }
|
||||
|
||||
// IDocument
|
||||
virtual bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
virtual bool shouldAutoSave() const;
|
||||
virtual bool isModified() const;
|
||||
virtual bool isSaveAsAllowed() const;
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
bool setContents(const QByteArray &contents);
|
||||
bool shouldAutoSave() const;
|
||||
bool isModified() const;
|
||||
bool isSaveAsAllowed() const;
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
|
||||
virtual QString defaultPath() const;
|
||||
virtual QString suggestedFileName() const;
|
||||
virtual QString mimeType() const;
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
QString mimeType() const;
|
||||
|
||||
// Internal
|
||||
void setSuggestedFileName(const QString &fileName);
|
||||
@@ -66,6 +67,8 @@ public:
|
||||
bool writeFile(const QString &fileName, QString *errorString) const;
|
||||
|
||||
QDesignerFormWindowInterface *formWindow() const;
|
||||
void syncXmlFromFormWindow();
|
||||
QString formWindowContents() const;
|
||||
|
||||
signals:
|
||||
// Internal
|
||||
|
@@ -67,12 +67,6 @@ DiffEditor::~DiffEditor()
|
||||
delete m_widget;
|
||||
}
|
||||
|
||||
bool DiffEditor::createNew(const QString &contents)
|
||||
{
|
||||
Q_UNUSED(contents)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DiffEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
|
@@ -60,7 +60,6 @@ public:
|
||||
void clear(const QString &message);
|
||||
|
||||
// Core::IEditor
|
||||
bool createNew(const QString &contents);
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
|
@@ -46,6 +46,12 @@ DiffEditorFile::DiffEditorFile(const QString &mimeType, QObject *parent) :
|
||||
setTemporary(true);
|
||||
}
|
||||
|
||||
bool DiffEditorFile::setContents(const QByteArray &contents)
|
||||
{
|
||||
Q_UNUSED(contents);
|
||||
return false;
|
||||
}
|
||||
|
||||
void DiffEditorFile::setModified(bool modified)
|
||||
{
|
||||
if (m_modified == modified)
|
||||
|
@@ -48,6 +48,7 @@ public:
|
||||
explicit DiffEditorFile(const QString &mimeType,
|
||||
QObject *parent = 0);
|
||||
|
||||
bool setContents(const QByteArray &contents);
|
||||
QString defaultPath() const { return QString(); }
|
||||
QString suggestedFileName() const { return QString(); }
|
||||
|
||||
|
@@ -103,7 +103,7 @@ void DiffEditorPlugin::diff()
|
||||
//: Editor title
|
||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||
DiffEditor *editor = qobject_cast<DiffEditor *>
|
||||
(Core::EditorManager::openEditorWithContents(editorId, &title, QString()));
|
||||
(Core::EditorManager::openEditorWithContents(editorId, &title));
|
||||
|
||||
if (!editor)
|
||||
return;
|
||||
|
@@ -42,10 +42,6 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
namespace Internal {
|
||||
class DiffEditorFile;
|
||||
}
|
||||
|
||||
class DIFFEDITOR_EXPORT DiffShowEditor : public DiffEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@@ -867,7 +867,7 @@ VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *regis
|
||||
|
||||
// Exists already
|
||||
Core::EditorManager::activateEditor(outputEditor);
|
||||
outputEditor->createNew(m_msgWait);
|
||||
outputEditor->document()->setContents(m_msgWait.toUtf8());
|
||||
rc = VcsBase::VcsBaseEditorWidget::getVcsBaseEditor(outputEditor);
|
||||
|
||||
return rc;
|
||||
@@ -880,14 +880,14 @@ DiffEditor::DiffEditor *GitClient::findExistingOrOpenNewDiffEditor(const char *r
|
||||
if (outputEditor) {
|
||||
// Exists already
|
||||
Core::EditorManager::activateEditor(outputEditor);
|
||||
outputEditor->createNew(m_msgWait);
|
||||
outputEditor->document()->setContents(m_msgWait.toUtf8());
|
||||
}
|
||||
|
||||
DiffEditor::DiffEditor *editor = qobject_cast<DiffEditor::DiffEditor *>(outputEditor);
|
||||
if (!editor) {
|
||||
QString title = titlePattern;
|
||||
editor = qobject_cast<DiffEditor::DiffEditor *>(
|
||||
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait));
|
||||
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait.toUtf8()));
|
||||
editor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue);
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
}
|
||||
@@ -913,7 +913,8 @@ VcsBase::VcsBaseEditorWidget *GitClient::createVcsEditor(const Core::Id &id,
|
||||
QTC_CHECK(!findExistingVCSEditor(registerDynamicProperty, dynamicPropertyValue));
|
||||
|
||||
// Create new, set wait message, set up with source and codec
|
||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(id, &title, m_msgWait);
|
||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(id, &title,
|
||||
m_msgWait.toUtf8());
|
||||
outputEditor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue);
|
||||
rc = VcsBase::VcsBaseEditorWidget::getVcsBaseEditor(outputEditor);
|
||||
connect(rc, SIGNAL(annotateRevisionRequested(QString,QString,int)),
|
||||
|
@@ -119,12 +119,6 @@ ImageViewer::~ImageViewer()
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool ImageViewer::createNew(const QString &contents)
|
||||
{
|
||||
Q_UNUSED(contents)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImageViewer::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
{
|
||||
if (!d->imageView->openFile(realFileName)) {
|
||||
|
@@ -54,7 +54,6 @@ public:
|
||||
explicit ImageViewer(QWidget *parent = 0);
|
||||
~ImageViewer();
|
||||
|
||||
bool createNew(const QString &contents = QString());
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
|
@@ -72,6 +72,12 @@ bool ImageViewerFile::save(QString *errorString, const QString &fileName, bool a
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImageViewerFile::setContents(const QByteArray &contents)
|
||||
{
|
||||
Q_UNUSED(contents);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ImageViewerFile::defaultPath() const
|
||||
{
|
||||
return QString();
|
||||
|
@@ -46,6 +46,7 @@ public:
|
||||
explicit ImageViewerFile(ImageViewer *parent = 0);
|
||||
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
bool setContents(const QByteArray &contents);
|
||||
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
|
@@ -1166,7 +1166,7 @@ Core::IEditor *PerforcePlugin::showOutputInEditor(const QString &title, const QS
|
||||
qDebug() << "PerforcePlugin::showOutputInEditor" << title << id.name()
|
||||
<< "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
|
||||
QString s = title;
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(id, &s, output);
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(id, &s, output.toUtf8());
|
||||
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
|
||||
this, SLOT(vcsAnnotate(QString,QString,int)));
|
||||
PerforceEditor *e = qobject_cast<PerforceEditor*>(editor->widget());
|
||||
@@ -1260,7 +1260,7 @@ void PerforcePlugin::p4Diff(const PerforceDiffParameters &p)
|
||||
return;
|
||||
|
||||
if (existingEditor) {
|
||||
existingEditor->createNew(result.stdOut);
|
||||
existingEditor->document()->setContents(result.stdOut.toUtf8());
|
||||
Core::EditorManager::activateEditor(existingEditor);
|
||||
return;
|
||||
}
|
||||
|
@@ -71,11 +71,11 @@ QByteArray PerforceSubmitEditor::fileContents() const
|
||||
return text.toLocal8Bit();
|
||||
}
|
||||
|
||||
bool PerforceSubmitEditor::setFileContents(const QString &contents)
|
||||
bool PerforceSubmitEditor::setFileContents(const QByteArray &contents)
|
||||
{
|
||||
if (Perforce::Constants::debug)
|
||||
qDebug() << Q_FUNC_INFO << contents;
|
||||
if (!parseText(contents))
|
||||
if (!parseText(QString::fromUtf8(contents)))
|
||||
return false;
|
||||
updateFields();
|
||||
return true;
|
||||
|
@@ -67,7 +67,7 @@ public:
|
||||
|
||||
protected:
|
||||
QByteArray fileContents() const;
|
||||
bool setFileContents(const QString &contents);
|
||||
bool setFileContents(const QByteArray &contents);
|
||||
|
||||
private:
|
||||
inline PerforceSubmitEditorWidget *submitEditorWidget();
|
||||
|
@@ -82,12 +82,6 @@ BarDescriptorEditor::BarDescriptorEditor(BarDescriptorEditorWidget *editorWidget
|
||||
generalAction->setChecked(true);
|
||||
}
|
||||
|
||||
bool BarDescriptorEditor::createNew(const QString &contents)
|
||||
{
|
||||
Q_UNUSED(contents);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BarDescriptorEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
{
|
||||
QTC_ASSERT(fileName == realFileName, return false);
|
||||
|
@@ -63,7 +63,6 @@ public:
|
||||
|
||||
explicit BarDescriptorEditor(BarDescriptorEditorWidget *editorWidget);
|
||||
|
||||
bool createNew(const QString &contents = QString());
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
|
@@ -134,21 +134,6 @@ ResourceEditorW::~ResourceEditorW()
|
||||
delete m_toolBar;
|
||||
}
|
||||
|
||||
bool ResourceEditorW::createNew(const QString &contents)
|
||||
{
|
||||
Utils::TempFileSaver saver;
|
||||
saver.write(contents.toUtf8());
|
||||
if (!saver.finalize(Core::ICore::mainWindow()))
|
||||
return false;
|
||||
|
||||
const bool rc = m_resourceEditor->load(saver.fileName());
|
||||
m_resourceDocument->setFilePath(QString());
|
||||
m_shouldAutoSave = false;
|
||||
if (debugResourceEditorW)
|
||||
qDebug() << "ResourceEditorW::createNew: " << contents << " (" << saver.fileName() << ") returns " << rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool ResourceEditorW::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
{
|
||||
if (debugResourceEditorW)
|
||||
@@ -206,6 +191,20 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResourceEditorDocument::setContents(const QByteArray &contents)
|
||||
{
|
||||
Utils::TempFileSaver saver;
|
||||
saver.write(contents);
|
||||
if (!saver.finalize(Core::ICore::mainWindow()))
|
||||
return false;
|
||||
|
||||
const bool rc = m_parent->m_resourceEditor->load(saver.fileName());
|
||||
m_parent->m_shouldAutoSave = false;
|
||||
if (debugResourceEditorW)
|
||||
qDebug() << "ResourceEditorW::createNew: " << contents << " (" << saver.fileName() << ") returns " << rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ResourceEditorDocument::setFilePath(const QString &newName)
|
||||
{
|
||||
if (newName != m_parent->m_resourceEditor->fileName())
|
||||
|
@@ -55,6 +55,7 @@ public:
|
||||
|
||||
//IDocument
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
bool setContents(const QByteArray &contents);
|
||||
bool shouldAutoSave() const;
|
||||
bool isModified() const;
|
||||
bool isSaveAsAllowed() const;
|
||||
@@ -85,7 +86,6 @@ public:
|
||||
~ResourceEditorW();
|
||||
|
||||
// IEditor
|
||||
bool createNew(const QString &contents);
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document() { return m_resourceDocument; }
|
||||
Core::Id id() const;
|
||||
|
@@ -588,7 +588,7 @@ void SubversionPlugin::svnDiff(const Subversion::Internal::SubversionDiffParamet
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::DiffOutput, p.workingDir, p.files);
|
||||
// Show in the same editor if diff has been executed before
|
||||
if (Core::IEditor *existingEditor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
existingEditor->createNew(response.stdOut);
|
||||
existingEditor->document()->setContents(response.stdOut.toUtf8());
|
||||
Core::EditorManager::activateEditor(existingEditor);
|
||||
setDiffBaseDirectory(existingEditor, p.workingDir);
|
||||
return;
|
||||
@@ -899,7 +899,7 @@ void SubversionPlugin::filelog(const QString &workingDir,
|
||||
const QString id = VcsBase::VcsBaseEditorWidget::getTitleId(workingDir, files);
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::LogOutput, workingDir, files);
|
||||
if (Core::IEditor *editor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(response.stdOut);
|
||||
editor->document()->setContents(response.stdOut.toUtf8());
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
const QString title = QString::fromLatin1("svn log %1").arg(id);
|
||||
@@ -976,7 +976,7 @@ void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &fil
|
||||
const QString id = VcsBase::VcsBaseEditorWidget::getTitleId(workingDir, files, revision);
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::AnnotateOutput, workingDir, files);
|
||||
if (Core::IEditor *editor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(response.stdOut);
|
||||
editor->document()->setContents(response.stdOut.toUtf8());
|
||||
VcsBase::VcsBaseEditorWidget::gotoLineOfEditor(editor, lineNumber);
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
@@ -1042,7 +1042,7 @@ void SubversionPlugin::describe(const QString &source, const QString &changeNr)
|
||||
const QString id = diffArg + source;
|
||||
const QString tag = VcsBase::VcsBaseEditorWidget::editorTag(VcsBase::DiffOutput, source, QStringList(), changeNr);
|
||||
if (Core::IEditor *editor = VcsBase::VcsBaseEditorWidget::locateEditorByTag(tag)) {
|
||||
editor->createNew(description);
|
||||
editor->document()->setContents(description.toUtf8());
|
||||
Core::EditorManager::activateEditor(editor);
|
||||
} else {
|
||||
const QString title = QString::fromLatin1("svn describe %1#%2").arg(fi.fileName(), changeNr);
|
||||
@@ -1174,7 +1174,7 @@ Core::IEditor *SubversionPlugin::showOutputInEditor(const QString &title, const
|
||||
qDebug() << "SubversionPlugin::showOutputInEditor" << title << id.name()
|
||||
<< "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
|
||||
QString s = title;
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(id, &s, output);
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(id, &s, output.toUtf8());
|
||||
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
|
||||
this, SLOT(annotateVersion(QString,QString,int)));
|
||||
SubversionEditor *e = qobject_cast<SubversionEditor*>(editor->widget());
|
||||
|
@@ -294,6 +294,18 @@ bool BaseTextDocument::save(QString *errorString, const QString &saveFileName, b
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseTextDocument::setContents(const QByteArray &contents)
|
||||
{
|
||||
if (contents.size() > Core::EditorManager::maxTextFileSize()) {
|
||||
document()->setPlainText(BaseTextEditorWidget::msgTextTooLarge(contents.size()));
|
||||
document()->setModified(false);
|
||||
return false;
|
||||
}
|
||||
document()->setPlainText(QString::fromUtf8(contents));
|
||||
document()->setModified(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseTextDocument::shouldAutoSave() const
|
||||
{
|
||||
return d->m_autoSaveRevision != d->m_document->revision();
|
||||
|
@@ -75,19 +75,20 @@ public:
|
||||
ITextMarkable *documentMarker() const;
|
||||
|
||||
// IDocument implementation.
|
||||
virtual bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
virtual bool shouldAutoSave() const;
|
||||
virtual bool isFileReadOnly() const;
|
||||
virtual bool isModified() const;
|
||||
virtual bool isSaveAsAllowed() const;
|
||||
virtual void checkPermissions();
|
||||
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
bool setContents(const QByteArray &contents);
|
||||
bool shouldAutoSave() const;
|
||||
bool isFileReadOnly() const;
|
||||
bool isModified() const;
|
||||
bool isSaveAsAllowed() const;
|
||||
void checkPermissions();
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
|
||||
virtual QString mimeType() const;
|
||||
QString mimeType() const;
|
||||
void setMimeType(const QString &mt);
|
||||
void setFilePath(const QString &newName);
|
||||
|
||||
virtual QString defaultPath() const;
|
||||
virtual QString suggestedFileName() const;
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
|
||||
void setDefaultPath(const QString &defaultPath);
|
||||
void setSuggestedFileName(const QString &suggestedFileName);
|
||||
|
@@ -539,18 +539,6 @@ QString BaseTextEditorWidget::msgTextTooLarge(quint64 size)
|
||||
arg(size >> 20);
|
||||
}
|
||||
|
||||
bool BaseTextEditorWidget::createNew(const QString &contents)
|
||||
{
|
||||
if (contents.size() > Core::EditorManager::maxTextFileSize()) {
|
||||
setPlainText(msgTextTooLarge(contents.size()));
|
||||
document()->setModified(false);
|
||||
return false;
|
||||
}
|
||||
setPlainText(contents);
|
||||
document()->setModified(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::updateCannotDecodeInfo()
|
||||
{
|
||||
setReadOnly(d->m_document->hasDecodingError());
|
||||
|
@@ -136,7 +136,6 @@ public:
|
||||
|
||||
// EditorInterface
|
||||
Core::IDocument *editorDocument() const;
|
||||
bool createNew(const QString &contents);
|
||||
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
QByteArray saveState() const;
|
||||
bool restoreState(const QByteArray &state);
|
||||
@@ -243,6 +242,8 @@ public:
|
||||
AssistReason assistReason) const;
|
||||
QMimeData *duplicateMimeData(const QMimeData *source) const;
|
||||
|
||||
static QString msgTextTooLarge(quint64 size);
|
||||
|
||||
public slots:
|
||||
virtual void copy();
|
||||
virtual void paste();
|
||||
@@ -352,7 +353,6 @@ protected:
|
||||
virtual bool selectionVisible(int blockNumber) const;
|
||||
virtual bool replacementVisible(int blockNumber) const;
|
||||
virtual QColor replacementPenColor(int blockNumber) const;
|
||||
static QString msgTextTooLarge(quint64 size);
|
||||
|
||||
private:
|
||||
void maybeSelectLine();
|
||||
@@ -612,7 +612,6 @@ public:
|
||||
|
||||
// IEditor
|
||||
Core::IDocument *document() { return m_editorWidget->editorDocument(); }
|
||||
bool createNew(const QString &contents) { return m_editorWidget->createNew(contents); }
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
|
||||
QByteArray saveState() const { return m_editorWidget->saveState(); }
|
||||
|
@@ -54,6 +54,11 @@ SubmitEditorFile::SubmitEditorFile(const QString &mimeType, VcsBaseSubmitEditor
|
||||
setTemporary(true);
|
||||
}
|
||||
|
||||
bool SubmitEditorFile::setContents(const QByteArray &contents)
|
||||
{
|
||||
return m_editor->setFileContents(contents);
|
||||
}
|
||||
|
||||
void SubmitEditorFile::setModified(bool modified)
|
||||
{
|
||||
if (m_modified == modified)
|
||||
|
@@ -44,6 +44,7 @@ public:
|
||||
explicit SubmitEditorFile(const QString &mimeType,
|
||||
VcsBaseSubmitEditor *parent = 0);
|
||||
|
||||
bool setContents(const QByteArray &contents);
|
||||
QString defaultPath() const { return QString(); }
|
||||
QString suggestedFileName() const { return QString(); }
|
||||
|
||||
|
@@ -560,11 +560,11 @@ VcsBase::VcsBaseEditorWidget *VcsBaseClient::createVcsEditor(Core::Id kind, QStr
|
||||
const QString progressMsg = tr("Working...");
|
||||
if (outputEditor) {
|
||||
// Exists already
|
||||
outputEditor->createNew(progressMsg);
|
||||
outputEditor->document()->setContents(progressMsg.toUtf8());
|
||||
baseEditor = VcsBase::VcsBaseEditorWidget::getVcsBaseEditor(outputEditor);
|
||||
QTC_ASSERT(baseEditor, return 0);
|
||||
} else {
|
||||
outputEditor = Core::EditorManager::openEditorWithContents(kind, &title, progressMsg);
|
||||
outputEditor = Core::EditorManager::openEditorWithContents(kind, &title, progressMsg.toUtf8());
|
||||
outputEditor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue);
|
||||
baseEditor = VcsBase::VcsBaseEditorWidget::getVcsBaseEditor(outputEditor);
|
||||
connect(baseEditor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
|
||||
|
@@ -349,12 +349,6 @@ void VcsBaseSubmitEditor::slotDescriptionChanged()
|
||||
{
|
||||
}
|
||||
|
||||
bool VcsBaseSubmitEditor::createNew(const QString &contents)
|
||||
{
|
||||
setFileContents(contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VcsBaseSubmitEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
@@ -365,7 +359,7 @@ bool VcsBaseSubmitEditor::open(QString *errorString, const QString &fileName, co
|
||||
return false;
|
||||
|
||||
const QString text = QString::fromLocal8Bit(reader.data());
|
||||
if (!createNew(text))
|
||||
if (!setFileContents(text.toUtf8()))
|
||||
return false;
|
||||
|
||||
d->m_file->setFilePath(QFileInfo(fileName).absoluteFilePath());
|
||||
@@ -518,9 +512,9 @@ QByteArray VcsBaseSubmitEditor::fileContents() const
|
||||
return d->m_widget->descriptionText().toLocal8Bit();
|
||||
}
|
||||
|
||||
bool VcsBaseSubmitEditor::setFileContents(const QString &contents)
|
||||
bool VcsBaseSubmitEditor::setFileContents(const QByteArray &contents)
|
||||
{
|
||||
d->m_widget->setDescriptionText(contents);
|
||||
d->m_widget->setDescriptionText(QString::fromUtf8(contents));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -112,7 +112,6 @@ public:
|
||||
void setCheckScriptWorkingDirectory(const QString &);
|
||||
|
||||
// Core::IEditor
|
||||
bool createNew(const QString &contents);
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
@@ -156,7 +155,7 @@ protected:
|
||||
* the file. The default implementation uses the text
|
||||
* of the description editor. */
|
||||
virtual QByteArray fileContents() const;
|
||||
virtual bool setFileContents(const QString &contents);
|
||||
virtual bool setFileContents(const QByteArray &contents);
|
||||
|
||||
void setDescriptionMandatory(bool v);
|
||||
bool isDescriptionMandatory() const;
|
||||
|
Reference in New Issue
Block a user