forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -195,6 +195,7 @@ VCSBase::VCSBaseEditor
|
||||
rc->setCodec(VCSBase::VCSBaseEditor::getCodec(source));
|
||||
}
|
||||
m_core->editorManager()->activateEditor(outputEditor);
|
||||
rc->setForceReadOnly(true);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -586,6 +586,7 @@ VCSBase::VCSBaseEditor *MercurialClient::createVCSEditor(const QString &kind, QS
|
||||
}
|
||||
|
||||
core->editorManager()->activateEditor(outputEditor);
|
||||
baseEditor->setForceReadOnly(true);
|
||||
return baseEditor;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ public:
|
||||
|
||||
bool isReadOnly() const;
|
||||
bool isModified() const;
|
||||
|
||||
void setForceReadOnly(bool b);
|
||||
bool isForceReadOnly() const;
|
||||
|
||||
private:
|
||||
bool m_forceReadOnly;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user