forked from qt-creator/qt-creator
Move IEditor::isTemporary to IDocument
It's a property of the document implementation, not of the specific editor instance working on it. Change-Id: I5c3dd054e21b646e2d94b891916a096d045923f8 Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -73,11 +73,6 @@ Core::Id AndroidManifestEditor::id() const
|
||||
return Constants::ANDROID_MANIFEST_EDITOR_ID;
|
||||
}
|
||||
|
||||
bool AndroidManifestEditor::isTemporary() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AndroidManifestEditor::changeEditorPage(QAction *action)
|
||||
{
|
||||
AndroidManifestEditorWidget *editorWidget = static_cast<AndroidManifestEditorWidget *>(widget());
|
||||
|
||||
@@ -51,7 +51,6 @@ public:
|
||||
explicit AndroidManifestEditor(AndroidManifestEditorWidget *editorWidget);
|
||||
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const;
|
||||
|
||||
private slots:
|
||||
void changeEditorPage(QAction *action);
|
||||
|
||||
@@ -1623,11 +1623,6 @@ void BinEditorWidget::asIntegers(int offset, int count, quint64 &bigEndianValue,
|
||||
}
|
||||
}
|
||||
|
||||
bool BinEditorWidget::isMemoryView() const
|
||||
{
|
||||
return editor()->property("MemoryView").toBool();
|
||||
}
|
||||
|
||||
void BinEditorWidget::setMarkup(const QList<Markup> &markup)
|
||||
{
|
||||
m_markup = markup;
|
||||
|
||||
@@ -119,8 +119,6 @@ public:
|
||||
|
||||
QString addressString(quint64 address);
|
||||
|
||||
bool isMemoryView() const; // Is a debugger memory view without file?
|
||||
|
||||
static const int SearchStride = 1024 * 1024;
|
||||
|
||||
QList<Markup> markup() const { return m_markup; }
|
||||
|
||||
@@ -270,11 +270,12 @@ public:
|
||||
|
||||
QString suggestedFileName() const { return QString(); }
|
||||
|
||||
bool isModified() const { return m_widget->isMemoryView() ? false : m_widget->isModified(); }
|
||||
bool isModified() const { return isTemporary()/*e.g. memory view*/ ? false
|
||||
: m_widget->isModified(); }
|
||||
|
||||
bool isFileReadOnly() const {
|
||||
const QString fn = filePath();
|
||||
if (m_widget->isMemoryView() || fn.isEmpty())
|
||||
if (fn.isEmpty())
|
||||
return false;
|
||||
const QFileInfo fi(fn);
|
||||
return !fi.isWritable();
|
||||
@@ -355,8 +356,6 @@ public:
|
||||
|
||||
QWidget *toolBar() { return m_toolBar; }
|
||||
|
||||
bool isTemporary() const { return m_widget->isMemoryView(); }
|
||||
|
||||
private slots:
|
||||
void updateCursorPosition(int position) {
|
||||
m_addressEdit->setText(QString::number(m_widget->baseAddress() + position, 16));
|
||||
|
||||
@@ -58,7 +58,6 @@ public:
|
||||
bool duplicateSupported() const { return true; }
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return false; }
|
||||
|
||||
private slots:
|
||||
void markAsChanged();
|
||||
|
||||
@@ -1035,7 +1035,7 @@ void DocumentManager::syncWithEditor(const QList<Core::IContext *> &context)
|
||||
return;
|
||||
|
||||
Core::IEditor *editor = Core::EditorManager::currentEditor();
|
||||
if (!editor || editor->isTemporary())
|
||||
if (!editor || editor->document()->isTemporary())
|
||||
return;
|
||||
foreach (IContext *c, context) {
|
||||
if (editor->widget() == c->widget()) {
|
||||
|
||||
@@ -278,6 +278,14 @@ int DocumentModel::indexOfDocument(IDocument *document) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document) const
|
||||
{
|
||||
int index = indexOfDocument(document);
|
||||
if (index < 0)
|
||||
return 0;
|
||||
return d->m_documents.at(index);
|
||||
}
|
||||
|
||||
QList<IDocument *> DocumentModel::openedDocuments() const
|
||||
{
|
||||
return d->m_editors.keys();
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
int documentCount() const;
|
||||
QList<Entry *> documents() const;
|
||||
int indexOfDocument(IDocument *document) const;
|
||||
Entry *entryForDocument(IDocument *document) const;
|
||||
QList<IDocument *> openedDocuments() const;
|
||||
|
||||
QList<IEditor *> editorsForDocument(IDocument *document) const;
|
||||
|
||||
@@ -1104,7 +1104,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
||||
foreach (IEditor *editor, acceptedEditors) {
|
||||
emit editorAboutToClose(editor);
|
||||
if (!editor->document()->filePath().isEmpty()
|
||||
&& !editor->isTemporary()) {
|
||||
&& !editor->document()->isTemporary()) {
|
||||
QByteArray state = editor->saveState();
|
||||
if (!state.isEmpty())
|
||||
d->m_editorStates.insert(editor->document()->filePath(), QVariant(state));
|
||||
@@ -1421,7 +1421,7 @@ void EditorManager::addEditor(IEditor *editor)
|
||||
bool isNewDocument = false;
|
||||
d->m_documentModel->addEditor(editor, &isNewDocument);
|
||||
if (isNewDocument) {
|
||||
const bool isTemporary = editor->isTemporary();
|
||||
const bool isTemporary = editor->document()->isTemporary();
|
||||
const bool addWatcher = !isTemporary;
|
||||
DocumentManager::addDocument(editor->document(), addWatcher);
|
||||
if (!isTemporary)
|
||||
@@ -1834,18 +1834,12 @@ bool EditorManager::saveDocumentAs(IDocument *documentParam)
|
||||
/* Adds the file name to the recent files if there is at least one non-temporary editor for it */
|
||||
void EditorManager::addDocumentToRecentFiles(IDocument *document)
|
||||
{
|
||||
bool isTemporary = true;
|
||||
Id editorId;
|
||||
QList<IEditor *> editors = editorsForDocument(document);
|
||||
foreach (IEditor *editor, editors) {
|
||||
if (!editor->isTemporary()) {
|
||||
editorId = editor->id();
|
||||
isTemporary = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isTemporary)
|
||||
DocumentManager::addToRecentFiles(document->filePath(), editorId);
|
||||
if (document->isTemporary())
|
||||
return;
|
||||
DocumentModel::Entry *entry = d->m_documentModel->entryForDocument(document);
|
||||
if (!entry)
|
||||
return;
|
||||
DocumentManager::addToRecentFiles(document->filePath(), entry->id());
|
||||
}
|
||||
|
||||
void EditorManager::gotoNextDocHistory()
|
||||
@@ -2164,7 +2158,7 @@ QByteArray EditorManager::saveState() const
|
||||
QList<IEditor *> editors = openedEditors();
|
||||
foreach (IEditor *editor, editors) {
|
||||
if (!editor->document()->filePath().isEmpty()
|
||||
&& !editor->isTemporary()) {
|
||||
&& !editor->document()->isTemporary()) {
|
||||
QByteArray state = editor->saveState();
|
||||
if (!state.isEmpty())
|
||||
d->m_editorStates.insert(editor->document()->filePath(), QVariant(state));
|
||||
@@ -2176,22 +2170,15 @@ QByteArray EditorManager::saveState() const
|
||||
QList<DocumentModel::Entry *> entries = d->m_documentModel->documents();
|
||||
int entriesCount = 0;
|
||||
foreach (DocumentModel::Entry *entry, entries) {
|
||||
// TODO: isTemporary should move to IDocument
|
||||
IEditor *editor = entry->document
|
||||
? d->m_documentModel->editorsForDocument(entry->document).first()
|
||||
: 0;
|
||||
// The editor may be 0 if it was not loaded yet: In that case it is not temporary
|
||||
if (!editor || !editor->isTemporary())
|
||||
if (!entry->document || !entry->document->isTemporary())
|
||||
++entriesCount;
|
||||
}
|
||||
|
||||
stream << entriesCount;
|
||||
|
||||
foreach (DocumentModel::Entry *entry, entries) {
|
||||
IEditor *editor = entry->document
|
||||
? d->m_documentModel->editorsForDocument(entry->document).first()
|
||||
: 0;
|
||||
if (!editor || !editor->isTemporary())
|
||||
if (!entry->document || !entry->document->isTemporary())
|
||||
stream << entry->fileName() << entry->displayName() << entry->id();
|
||||
}
|
||||
|
||||
|
||||
@@ -737,11 +737,11 @@ QByteArray SplitterOrView::saveState() const
|
||||
IEditor* e = editor();
|
||||
|
||||
// don't save state of temporary or ad-hoc editors
|
||||
if (e && (e->isTemporary() || e->document()->filePath().isEmpty())) {
|
||||
if (e && (e->document()->isTemporary() || e->document()->filePath().isEmpty())) {
|
||||
// look for another editor that is more suited
|
||||
e = 0;
|
||||
foreach (IEditor *otherEditor, editors()) {
|
||||
if (!otherEditor->isTemporary() && !otherEditor->document()->filePath().isEmpty()) {
|
||||
if (!otherEditor->document()->isTemporary() && !otherEditor->document()->filePath().isEmpty()) {
|
||||
e = otherEditor;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ public:
|
||||
virtual int currentColumn() const { return 0; }
|
||||
virtual void gotoLine(int line, int column = 0) { Q_UNUSED(line) Q_UNUSED(column) }
|
||||
|
||||
virtual bool isTemporary() const = 0;
|
||||
|
||||
virtual QWidget *toolBar() = 0;
|
||||
|
||||
virtual bool isDesignModePreferred() const { return false; }
|
||||
|
||||
@@ -43,7 +43,11 @@
|
||||
|
||||
namespace Core {
|
||||
|
||||
IDocument::IDocument(QObject *parent) : QObject(parent), m_infoBar(0), m_hasWriteWarning(false), m_restored(false)
|
||||
IDocument::IDocument(QObject *parent) : QObject(parent),
|
||||
m_temporary(false),
|
||||
m_infoBar(0),
|
||||
m_hasWriteWarning(false),
|
||||
m_restored(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,6 +82,25 @@ bool IDocument::isFileReadOnly() const
|
||||
return !QFileInfo(filePath()).isWritable();
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns if the document is a temporary that should for example not be considered
|
||||
when saving/restoring the session state, recent files, etc. Defaults to false.
|
||||
\sa setTemporary()
|
||||
*/
|
||||
bool IDocument::isTemporary() const
|
||||
{
|
||||
return m_temporary;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets if the document is \a temporary.
|
||||
\sa isTemporary()
|
||||
*/
|
||||
void IDocument::setTemporary(bool temporary)
|
||||
{
|
||||
m_temporary = temporary;
|
||||
}
|
||||
|
||||
bool IDocument::autoSave(QString *errorString, const QString &fileName)
|
||||
{
|
||||
if (!save(errorString, fileName, true))
|
||||
|
||||
@@ -88,6 +88,8 @@ public:
|
||||
void setDisplayName(const QString &name);
|
||||
|
||||
virtual bool isFileReadOnly() const;
|
||||
bool isTemporary() const;
|
||||
void setTemporary(bool temporary);
|
||||
|
||||
virtual QString defaultPath() const = 0;
|
||||
virtual QString suggestedFileName() const = 0;
|
||||
@@ -122,6 +124,7 @@ signals:
|
||||
private:
|
||||
QString m_filePath;
|
||||
QString m_displayName;
|
||||
bool m_temporary;
|
||||
QString m_autoSaveName;
|
||||
InfoBar *m_infoBar;
|
||||
bool m_hasWriteWarning;
|
||||
|
||||
@@ -79,7 +79,6 @@ public:
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
Core::Id id() const;
|
||||
|
||||
bool isTemporary() const { return false; }
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
|
||||
const Utils::CommentDefinition *commentDefinition() const;
|
||||
|
||||
@@ -46,7 +46,6 @@ namespace Internal {
|
||||
|
||||
const char OPENED_BY_DEBUGGER[] = "OpenedByDebugger";
|
||||
const char OPENED_WITH_DISASSEMBLY[] = "DisassemblerView";
|
||||
const char OPENED_WITH_MEMORY[] = "MemoryView";
|
||||
|
||||
// Debug action
|
||||
const char DEBUG[] = "Debugger.Debug";
|
||||
|
||||
@@ -182,7 +182,7 @@ bool MemoryAgent::doCreateBinEditor(quint64 addr, unsigned flags,
|
||||
if (!editor)
|
||||
return false;
|
||||
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, QVariant(true));
|
||||
editor->document()->setProperty(Constants::OPENED_WITH_MEMORY, QVariant(true));
|
||||
editor->document()->setTemporary(true);
|
||||
QWidget *editorBinEditor = editor->widget();
|
||||
connectBinEditorWidget(editorBinEditor);
|
||||
MemoryView::setBinEditorReadOnly(editorBinEditor, readOnly);
|
||||
|
||||
@@ -206,11 +206,6 @@ bool FormWindowEditor::restoreState(const QByteArray &state)
|
||||
return d->m_textEditor.restoreState(state);
|
||||
}
|
||||
|
||||
bool FormWindowEditor::isTemporary() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QWidget *FormWindowEditor::toolBar()
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -75,8 +75,6 @@ public:
|
||||
virtual QByteArray saveState() const;
|
||||
virtual bool restoreState(const QByteArray &state);
|
||||
|
||||
virtual bool isTemporary() const;
|
||||
|
||||
virtual QWidget *toolBar();
|
||||
|
||||
virtual bool isDesignModePreferred() const;
|
||||
|
||||
@@ -64,7 +64,6 @@ public:
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return true; }
|
||||
DiffEditorWidget *editorWidget() const { return m_editorWidget; }
|
||||
|
||||
QWidget *toolBar();
|
||||
|
||||
@@ -43,6 +43,7 @@ DiffEditorFile::DiffEditorFile(const QString &mimeType, QObject *parent) :
|
||||
m_modified(false)
|
||||
{
|
||||
setDisplayName(QCoreApplication::translate("DiffEditor", Constants::DIFF_EDITOR_DISPLAY_NAME));
|
||||
setTemporary(true);
|
||||
}
|
||||
|
||||
void DiffEditorFile::setModified(bool modified)
|
||||
|
||||
@@ -113,7 +113,6 @@ public:
|
||||
}
|
||||
|
||||
Core::Id id() const { return "DiffViewEditor"; }
|
||||
bool isTemporary() const { return false; }
|
||||
|
||||
private slots:
|
||||
void slotTooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPoint, int position);
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
DiffShowEditorWidgetEditable(BaseTextEditorWidget *editorWidget) : BaseTextEditor(editorWidget) {}
|
||||
|
||||
Core::Id id() const { return "DiffShowViewEditor"; }
|
||||
bool isTemporary() const { return false; }
|
||||
};
|
||||
|
||||
class DiffShowEditorWidget : public BaseTextEditorWidget
|
||||
|
||||
@@ -75,7 +75,6 @@ public:
|
||||
Core::Id id() const;
|
||||
bool duplicateSupported() const;
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
bool isTemporary() const { return false; }
|
||||
};
|
||||
|
||||
class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
bool duplicateSupported() const { return true; }
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return false; }
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
};
|
||||
|
||||
|
||||
@@ -148,11 +148,6 @@ Core::Id ImageViewer::id() const
|
||||
return Core::Id(Constants::IMAGEVIEWER_ID);
|
||||
}
|
||||
|
||||
bool ImageViewer::isTemporary() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QWidget *ImageViewer::toolBar()
|
||||
{
|
||||
return d->toolbar;
|
||||
|
||||
@@ -58,7 +58,6 @@ public:
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const;
|
||||
QWidget *toolBar();
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -49,7 +49,6 @@ public:
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return false; }
|
||||
|
||||
/**
|
||||
Opens file for editing, actual work performed by base class
|
||||
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
bool duplicateSupported() const { return true; }
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return false; }
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
bool isDesignModePreferred() const;
|
||||
void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason);
|
||||
|
||||
@@ -104,11 +104,6 @@ Core::Id BarDescriptorEditor::id() const
|
||||
return Constants::QNX_BAR_DESCRIPTOR_EDITOR_ID;
|
||||
}
|
||||
|
||||
bool BarDescriptorEditor::isTemporary() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QWidget *BarDescriptorEditor::toolBar()
|
||||
{
|
||||
return m_toolBar;
|
||||
|
||||
@@ -67,7 +67,6 @@ public:
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const;
|
||||
QWidget *toolBar();
|
||||
|
||||
EditorPage activePage() const;
|
||||
|
||||
@@ -55,7 +55,6 @@ public:
|
||||
bool duplicateSupported() const { return true; }
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return false; }
|
||||
};
|
||||
|
||||
class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
|
||||
@@ -92,7 +92,6 @@ public:
|
||||
QWidget *toolBar();
|
||||
|
||||
void setSuggestedFileName(const QString &fileName);
|
||||
bool isTemporary() const { return false; }
|
||||
|
||||
private slots:
|
||||
void onUndoStackChanged(bool canUndo, bool canRedo);
|
||||
|
||||
@@ -51,7 +51,6 @@ public:
|
||||
|
||||
bool duplicateSupported() const { return true; }
|
||||
Core::IEditor *duplicate(QWidget *parent);
|
||||
bool isTemporary() const { return false; }
|
||||
Core::Id id() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ public:
|
||||
|
||||
bool duplicateSupported() const { return false; }
|
||||
Core::IEditor *duplicate(QWidget * /* parent */ ) { return 0; }
|
||||
bool isTemporary() const { return false; }
|
||||
Core::Id id() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ SubmitEditorFile::SubmitEditorFile(const QString &mimeType, QObject *parent) :
|
||||
m_mimeType(mimeType),
|
||||
m_modified(false)
|
||||
{
|
||||
setTemporary(true);
|
||||
}
|
||||
|
||||
void SubmitEditorFile::setModified(bool modified)
|
||||
|
||||
@@ -151,23 +151,18 @@ public:
|
||||
|
||||
Core::Id id() const { return m_id; }
|
||||
|
||||
bool isTemporary() const { return m_temporary; }
|
||||
void setTemporary(bool t) { m_temporary = t; }
|
||||
|
||||
signals:
|
||||
void describeRequested(const QString &source, const QString &change);
|
||||
void annotateRevisionRequested(const QString &source, const QString &change, int line);
|
||||
|
||||
private:
|
||||
Core::Id m_id;
|
||||
bool m_temporary;
|
||||
};
|
||||
|
||||
VcsBaseEditor::VcsBaseEditor(VcsBaseEditorWidget *widget,
|
||||
const VcsBaseEditorParameters *type) :
|
||||
BaseTextEditor(widget),
|
||||
m_id(type->id),
|
||||
m_temporary(false)
|
||||
m_id(type->id)
|
||||
{
|
||||
setContext(Core::Context(type->context, TextEditor::Constants::C_TEXTEDITOR));
|
||||
}
|
||||
@@ -725,7 +720,7 @@ void VcsBaseEditorWidget::setForceReadOnly(bool b)
|
||||
VcsBaseEditor *eda = qobject_cast<VcsBaseEditor *>(editor());
|
||||
QTC_ASSERT(eda != 0, return);
|
||||
setReadOnly(b);
|
||||
eda->setTemporary(b);
|
||||
eda->document()->setTemporary(b);
|
||||
}
|
||||
|
||||
QString VcsBaseEditorWidget::source() const
|
||||
|
||||
@@ -115,7 +115,6 @@ public:
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
Core::IDocument *document();
|
||||
Core::Id id() const;
|
||||
bool isTemporary() const { return true; }
|
||||
|
||||
QWidget *toolBar();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user