forked from qt-creator/qt-creator
VCS: Fix auto-opening on files in VCS
Fix auto-opening of files under version control for VCSes that need it (e.g. Perforce). Task-number: QTCREATORBUG-5312 Change-Id: Ifc26d062c0f2a92a06d83ccc8664640699e5dc5d Reviewed-on: http://codereview.qt.nokia.com/2450 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
committed by
Oswald Buddenhagen
parent
dd5ccf3d85
commit
7efb3c35a5
@@ -1581,6 +1581,23 @@ void EditorManager::makeCurrentEditorWritable()
|
|||||||
makeFileWritable(curEditor->file());
|
makeFileWritable(curEditor->file());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorManager::vcsOpenCurrentEditor()
|
||||||
|
{
|
||||||
|
IEditor *curEditor = currentEditor();
|
||||||
|
if (!curEditor)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QString directory = QFileInfo(curEditor->file()->fileName()).absolutePath();
|
||||||
|
IVersionControl *versionControl = m_d->m_core->vcsManager()->findVersionControlForDirectory(directory);
|
||||||
|
if (!versionControl || !versionControl->supportsOperation(IVersionControl::OpenOperation))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!versionControl->vcsOpen(curEditor->file()->fileName())) {
|
||||||
|
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Cannot Open File"),
|
||||||
|
tr("Cannot open the file for editing with VCS."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditorManager::updateWindowTitle()
|
void EditorManager::updateWindowTitle()
|
||||||
{
|
{
|
||||||
QString windowTitle = tr("Qt Creator");
|
QString windowTitle = tr("Qt Creator");
|
||||||
@@ -1635,12 +1652,35 @@ void EditorManager::updateActions()
|
|||||||
bool ww = curEditor->file()->isModified() && curEditor->file()->isReadOnly();
|
bool ww = curEditor->file()->isModified() && curEditor->file()->isReadOnly();
|
||||||
if (ww != curEditor->file()->hasWriteWarning()) {
|
if (ww != curEditor->file()->hasWriteWarning()) {
|
||||||
curEditor->file()->setWriteWarning(ww);
|
curEditor->file()->setWriteWarning(ww);
|
||||||
|
|
||||||
|
// Do this after setWriteWarning so we don't re-evaluate this part even
|
||||||
|
// if we do not really show a warning.
|
||||||
|
bool promptVCS = false;
|
||||||
|
const QString directory = QFileInfo(curEditor->file()->fileName()).absolutePath();
|
||||||
|
IVersionControl *versionControl = m_d->m_core->vcsManager()->findVersionControlForDirectory(directory);
|
||||||
|
if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation)) {
|
||||||
|
if (versionControl->settingsFlags() & IVersionControl::AutoOpen) {
|
||||||
|
vcsOpenCurrentEditor();
|
||||||
|
ww = false;
|
||||||
|
} else {
|
||||||
|
promptVCS = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ww) {
|
if (ww) {
|
||||||
// we are about to change a read-only file, warn user
|
// we are about to change a read-only file, warn user
|
||||||
InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"),
|
if (promptVCS) {
|
||||||
tr("<b>Warning:</b> You are changing a read-only file."));
|
InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"),
|
||||||
info.setCustomButtonInfo(tr("Make writable"), this, SLOT(makeCurrentEditorWritable()));
|
tr("<b>Warning:</b> This file was not opened in %1 yet.")
|
||||||
curEditor->file()->infoBar()->addInfo(info);
|
.arg(versionControl->displayName()));
|
||||||
|
info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor()));
|
||||||
|
curEditor->file()->infoBar()->addInfo(info);
|
||||||
|
} else {
|
||||||
|
InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"),
|
||||||
|
tr("<b>Warning:</b> You are changing a read-only file."));
|
||||||
|
info.setCustomButtonInfo(tr("Make writable"), this, SLOT(makeCurrentEditorWritable()));
|
||||||
|
curEditor->file()->infoBar()->addInfo(info);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
curEditor->file()->infoBar()->removeInfo(QLatin1String("Core.EditorManager.MakeWritable"));
|
curEditor->file()->infoBar()->removeInfo(QLatin1String("Core.EditorManager.MakeWritable"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,6 +213,7 @@ private slots:
|
|||||||
void handleContextChange(Core::IContext *context);
|
void handleContextChange(Core::IContext *context);
|
||||||
void updateActions();
|
void updateActions();
|
||||||
void makeCurrentEditorWritable();
|
void makeCurrentEditorWritable();
|
||||||
|
void vcsOpenCurrentEditor();
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
void handleEditorStateChange();
|
void handleEditorStateChange();
|
||||||
void updateVariable(const QString &variable);
|
void updateVariable(const QString &variable);
|
||||||
|
|||||||
Reference in New Issue
Block a user