diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 3cf44718532..eb2a3befffb 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -90,6 +90,7 @@ static const char kCurrentDocumentFilePath[] = "CurrentDocument:FilePath"; static const char kCurrentDocumentPath[] = "CurrentDocument:Path"; static const char kCurrentDocumentXPos[] = "CurrentDocument:XPos"; static const char kCurrentDocumentYPos[] = "CurrentDocument:YPos"; +static const char kMakeWritableWarning[] = "Core.EditorManager.MakeWritable"; //===================EditorClosingCoreListener====================== @@ -1686,6 +1687,47 @@ void EditorManager::handleEditorStateChange() } } +void EditorManager::updateMakeWritableWarning() +{ + IEditor *curEditor = currentEditor(); + bool ww = curEditor->document()->isModified() && curEditor->document()->isFileReadOnly(); + if (ww != curEditor->document()->hasWriteWarning()) { + curEditor->document()->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->document()->fileName()).absolutePath(); + IVersionControl *versionControl = ICore::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 + if (promptVCS) { + InfoBarEntry info(QLatin1String(kMakeWritableWarning), + tr("Warning: This file was not opened in %1 yet.") + .arg(versionControl->displayName())); + info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor())); + curEditor->document()->infoBar()->addInfo(info); + } else { + InfoBarEntry info(QLatin1String(kMakeWritableWarning), + tr("Warning: You are changing a read-only file.")); + info.setCustomButtonInfo(tr("Make Writable"), this, SLOT(makeCurrentEditorWritable())); + curEditor->document()->infoBar()->addInfo(info); + } + } else { + curEditor->document()->infoBar()->removeInfo(QLatin1String(kMakeWritableWarning)); + } + } +} + void EditorManager::updateActions() { QString fName; @@ -1703,42 +1745,7 @@ void EditorManager::updateActions() if (HostOsInfo::isMacHost()) window()->setWindowModified(curEditor->document()->isModified()); - bool ww = curEditor->document()->isModified() && curEditor->document()->isFileReadOnly(); - if (ww != curEditor->document()->hasWriteWarning()) { - curEditor->document()->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->document()->fileName()).absolutePath(); - IVersionControl *versionControl = ICore::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 - if (promptVCS) { - InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"), - tr("Warning: This file was not opened in %1 yet.") - .arg(versionControl->displayName())); - info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor())); - curEditor->document()->infoBar()->addInfo(info); - } else { - InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"), - tr("Warning: You are changing a read-only file.")); - info.setCustomButtonInfo(tr("Make Writable"), this, SLOT(makeCurrentEditorWritable())); - curEditor->document()->infoBar()->addInfo(info); - } - } else { - curEditor->document()->infoBar()->removeInfo(QLatin1String("Core.EditorManager.MakeWritable")); - } - } + updateMakeWritableWarning(); } else /* curEditor */ if (HostOsInfo::isMacHost()) { window()->setWindowModified(false); } diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 3dca199892e..55e7b44af8c 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -263,6 +263,7 @@ private: void switchToPreferedMode(); void updateAutoSave(); void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable); + void updateMakeWritableWarning(); EditorManagerPrivate *d;