aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorTobias Hunger <[email protected]>2011-08-01 16:44:05 +0000
committerOswald Buddenhagen <[email protected]>2011-08-02 12:44:55 +0200
commit7efb3c35a5e50843657815e755efdb4bffaed231 (patch)
treed71958aef7daad281eef61fb0192cf1339ef1e51 /src/plugins
parentdd5ccf3d854912704d9abff68bf63acb1c567937 (diff)
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 <[email protected]> Reviewed-by: Oswald Buddenhagen <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp48
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.h1
2 files changed, 45 insertions, 4 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index bb471a2f299..e05ed776500 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -1581,6 +1581,23 @@ void EditorManager::makeCurrentEditorWritable()
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()
{
QString windowTitle = tr("Qt Creator");
@@ -1635,12 +1652,35 @@ void EditorManager::updateActions()
bool ww = curEditor->file()->isModified() && curEditor->file()->isReadOnly();
if (ww != curEditor->file()->hasWriteWarning()) {
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) {
// we are about to change a read-only file, warn user
- 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);
+ if (promptVCS) {
+ InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"),
+ tr("<b>Warning:</b> This file was not opened in %1 yet.")
+ .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 {
curEditor->file()->infoBar()->removeInfo(QLatin1String("Core.EditorManager.MakeWritable"));
}
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index e9e88978e59..ffaec67a26c 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -213,6 +213,7 @@ private slots:
void handleContextChange(Core::IContext *context);
void updateActions();
void makeCurrentEditorWritable();
+ void vcsOpenCurrentEditor();
void updateWindowTitle();
void handleEditorStateChange();
void updateVariable(const QString &variable);