From c745155191fac756f13b92fbd0b33a458dd67b4d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Mon, 7 Jun 2010 14:53:28 +0200 Subject: [PATCH] VCS/Diff editors: Set readonly attributes correctly. Make VCS-generated editors read-only, enable editing when opening a patch. Make VCS-Editor non-read-only by default, add setter for "Forced read-only" that makes it a temporary, read-only file. Task-number: QTCREATORBUG-1528 Reviewed-by: Thorbjorn Lindeijer <thorbjorn.lindeijer@nokia.com> --- src/plugins/cvs/cvsplugin.cpp | 1 + src/plugins/git/gitclient.cpp | 1 + src/plugins/mercurial/mercurialclient.cpp | 1 + src/plugins/perforce/perforceplugin.cpp | 1 + src/plugins/subversion/subversionplugin.cpp | 1 + src/plugins/vcsbase/vcsbaseeditor.cpp | 31 +++++++++++++++++---- src/plugins/vcsbase/vcsbaseeditor.h | 7 +++++ src/plugins/vcsbase/vcsbasetextdocument.cpp | 21 ++++++++++++-- src/plugins/vcsbase/vcsbasetextdocument.h | 6 ++++ 9 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/plugins/cvs/cvsplugin.cpp b/src/plugins/cvs/cvsplugin.cpp index 147c522ab58..0c2e16d1ebf 100644 --- a/src/plugins/cvs/cvsplugin.cpp +++ b/src/plugins/cvs/cvsplugin.cpp @@ -1075,6 +1075,7 @@ Core::IEditor * CVSPlugin::showOutputInEditor(const QString& title, const QStrin return 0; s.replace(QLatin1Char(' '), QLatin1Char('_')); e->setSuggestedFileName(s); + e->setForceReadOnly(true); if (!source.isEmpty()) e->setSource(source); if (codec) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 15e12d441f9..dd38c8c189a 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -195,6 +195,7 @@ VCSBase::VCSBaseEditor rc->setCodec(VCSBase::VCSBaseEditor::getCodec(source)); } m_core->editorManager()->activateEditor(outputEditor); + rc->setForceReadOnly(true); return rc; } diff --git a/src/plugins/mercurial/mercurialclient.cpp b/src/plugins/mercurial/mercurialclient.cpp index caf4f0bfc0a..85eb7f4b43e 100644 --- a/src/plugins/mercurial/mercurialclient.cpp +++ b/src/plugins/mercurial/mercurialclient.cpp @@ -586,6 +586,7 @@ VCSBase::VCSBaseEditor *MercurialClient::createVCSEditor(const QString &kind, QS } core->editorManager()->activateEditor(outputEditor); + baseEditor->setForceReadOnly(true); return baseEditor; } diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index eef5f6827b1..c9d01fde7bd 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -1180,6 +1180,7 @@ Core::IEditor * PerforcePlugin::showOutputInEditor(const QString& title, const Q PerforceEditor *e = qobject_cast<PerforceEditor*>(editor->widget()); if (!e) return 0; + e->setForceReadOnly(true); e->setSource(source); s.replace(QLatin1Char(' '), QLatin1Char('_')); e->setSuggestedFileName(s); diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp index a29483bd189..60173d28d06 100644 --- a/src/plugins/subversion/subversionplugin.cpp +++ b/src/plugins/subversion/subversionplugin.cpp @@ -1120,6 +1120,7 @@ Core::IEditor * SubversionPlugin::showOutputInEditor(const QString& title, const SubversionEditor *e = qobject_cast<SubversionEditor*>(editor->widget()); if (!e) return 0; + e->setForceReadOnly(true); s.replace(QLatin1Char(' '), QLatin1Char('_')); e->setSuggestedFileName(s); if (!source.isEmpty()) diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 67b3e80901b..ad9745a6b70 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -82,7 +82,8 @@ public: Core::IEditor *duplicate(QWidget * /*parent*/) { return 0; } QString id() const { return m_id; } - bool isTemporary() const { return true; } + bool isTemporary() const { return m_temporary; } + void setTemporary(bool t) { m_temporary = t; } signals: void describeRequested(const QString &source, const QString &change); @@ -91,12 +92,14 @@ signals: private: QString m_id; QList<int> m_context; + bool m_temporary; }; VCSBaseEditorEditable::VCSBaseEditorEditable(VCSBaseEditor *editor, const VCSBaseEditorParameters *type) : BaseTextEditorEditable(editor), - m_id(type->id) + m_id(type->id), + m_temporary(false) { Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance(); m_context << uidm->uniqueIdentifier(QLatin1String(type->context)) @@ -118,8 +121,6 @@ public: virtual QWidget *toolBar() { return m_toolBar; } QComboBox *diffFileBrowseComboBox() const { return m_diffFileBrowseComboBox; } - bool isTemporary() const { return true; } - private: QToolBar *m_toolBar; QComboBox *m_diffFileBrowseComboBox; @@ -181,7 +182,6 @@ VCSBaseEditor::VCSBaseEditor(const VCSBaseEditorParameters *type, QWidget *paren if (VCSBase::Constants::Internal::debug) qDebug() << "VCSBaseEditor::VCSBaseEditor" << type->type << type->id; - setReadOnly(true); viewport()->setMouseTracking(true); setBaseTextDocument(new Internal::VCSBaseTextDocument); setMimeType(QLatin1String(d->m_parameters->mimeType)); @@ -212,6 +212,23 @@ VCSBaseEditor::~VCSBaseEditor() delete d; } +void VCSBaseEditor::setForceReadOnly(bool b) +{ + Internal::VCSBaseTextDocument *vbd = qobject_cast<Internal::VCSBaseTextDocument*>(baseTextDocument()); + VCSBaseEditorEditable *eda = qobject_cast<VCSBaseEditorEditable *>(editableInterface()); + QTC_ASSERT(vbd != 0 && eda != 0, return); + setReadOnly(b); + vbd->setForceReadOnly(b); + eda->setTemporary(b); +} + +bool VCSBaseEditor::isForceReadOnly() const +{ + const Internal::VCSBaseTextDocument *vbd = qobject_cast<const Internal::VCSBaseTextDocument*>(baseTextDocument()); + QTC_ASSERT(vbd, return false); + return vbd->isForceReadOnly(); +} + QString VCSBaseEditor::source() const { return d->m_source; @@ -502,7 +519,9 @@ void VCSBaseEditor::mouseDoubleClickEvent(QMouseEvent *e) void VCSBaseEditor::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { + // Do not intercept return in editable patches. + if (d->m_parameters->type == DiffOutput && isReadOnly() + && (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)) { jumpToChangeFromDiff(textCursor()); return; } diff --git a/src/plugins/vcsbase/vcsbaseeditor.h b/src/plugins/vcsbase/vcsbaseeditor.h index c6062298bd3..19aa82ab7af 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.h +++ b/src/plugins/vcsbase/vcsbaseeditor.h @@ -105,6 +105,13 @@ public: virtual ~VCSBaseEditor(); + /* Force read-only: Make it a read-only, temporary file. + * Should be set to true by version control views. It is not on + * by default since it should not trigger when patches are opened as + * files. */ + void setForceReadOnly(bool b); + bool isForceReadOnly() const; + QString source() const; void setSource(const QString &source); diff --git a/src/plugins/vcsbase/vcsbasetextdocument.cpp b/src/plugins/vcsbase/vcsbasetextdocument.cpp index 3a5590e145d..6a409b8fb38 100644 --- a/src/plugins/vcsbase/vcsbasetextdocument.cpp +++ b/src/plugins/vcsbase/vcsbasetextdocument.cpp @@ -31,16 +31,31 @@ using namespace VCSBase::Internal; -VCSBaseTextDocument::VCSBaseTextDocument() +VCSBaseTextDocument::VCSBaseTextDocument() : + m_forceReadOnly(false) { } bool VCSBaseTextDocument::isReadOnly() const { - return true; + return m_forceReadOnly ? + true : + TextEditor::BaseTextDocument::isReadOnly(); } bool VCSBaseTextDocument::isModified() const { - return false; + return m_forceReadOnly ? + false : + TextEditor::BaseTextDocument::isModified(); +} + +void VCSBaseTextDocument::setForceReadOnly(bool b) +{ + m_forceReadOnly = b; +} + +bool VCSBaseTextDocument::isForceReadOnly() const +{ + return m_forceReadOnly; } diff --git a/src/plugins/vcsbase/vcsbasetextdocument.h b/src/plugins/vcsbase/vcsbasetextdocument.h index f7bdd403f1c..46845f08044 100644 --- a/src/plugins/vcsbase/vcsbasetextdocument.h +++ b/src/plugins/vcsbase/vcsbasetextdocument.h @@ -44,6 +44,12 @@ public: bool isReadOnly() const; bool isModified() const; + + void setForceReadOnly(bool b); + bool isForceReadOnly() const; + +private: + bool m_forceReadOnly; }; } // namespace Internal -- GitLab