summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-02-06 23:06:46 +0200
committerhjk <hjk121@nokiamail.com>2013-02-07 13:37:26 +0100
commitc7ed4556d8cf031537ea78e8e5ca438924204e79 (patch)
tree87c24b9c7105f2fb9dbecd3e2c8f03ebeac0fa3f
parent4aef34e9e0e8a95524ec7a0c15185162605d1b07 (diff)
downloadqt-creator-c7ed4556d8cf031537ea78e8e5ca438924204e79.tar.gz
Show warning when opening a file that is external to the project
Change-Id: I2487c0fe585ae7482a2362b662f2392470bd34e7 Reviewed-by: Daniel Teske <daniel.teske@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp34
-rw-r--r--src/plugins/projectexplorer/projectexplorer.h1
2 files changed, 35 insertions, 0 deletions
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index da3cd5e9a9..72cf0573ad 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -97,6 +97,7 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
+#include <coreplugin/idocument.h>
#include <coreplugin/imode.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
@@ -104,6 +105,7 @@
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/id.h>
+#include <coreplugin/infobar.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/findplaceholder.h>
@@ -154,6 +156,7 @@
namespace {
bool debug = false;
+const char EXTERNAL_FILE_WARNING[] = "ExternalFile";
}
namespace ProjectExplorer {
@@ -1746,6 +1749,36 @@ void ProjectExplorerPlugin::buildQueueFinished(bool success)
d->m_runMode = NoRunMode;
}
+void ProjectExplorerPlugin::showExternalFileWarning()
+{
+ // If m_currentNode is not NULL, the file belongs to (any) project. Do not show the warning
+ if (d->m_currentNode || !d->m_currentProject)
+ return;
+ Core::IEditor *editor = Core::EditorManager::currentEditor();
+ if (!editor)
+ return;
+ Core::IDocument *document = editor->document();
+ if (!document)
+ return;
+ Core::InfoBar *infoBar = document->infoBar();
+ Core::Id externalFileId(EXTERNAL_FILE_WARNING);
+ if (!infoBar->canInfoBeAdded(externalFileId))
+ return;
+ Utils::FileName fileName = Utils::FileName::fromString(document->fileName());
+ Utils::FileName projectDir = Utils::FileName::fromString(d->m_currentProject->projectDirectory());
+ if (fileName.isChildOf(projectDir))
+ return;
+ // External file. Test if it under the same VCS
+ QString topLevel;
+ if (Core::ICore::vcsManager()->findVersionControlForDirectory(projectDir.toString(), &topLevel)
+ && fileName.isChildOf(Utils::FileName::fromString(topLevel))) {
+ return;
+ }
+ infoBar->addInfo(Core::InfoBarEntry(externalFileId,
+ tr("<b>Warning:</b> This file is outside the project directory."),
+ Core::InfoBarEntry::GlobalSuppressionEnabled));
+}
+
void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node *node)
{
if (debug)
@@ -1783,6 +1816,7 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
if (debug)
qDebug() << "ProjectExplorer - currentNodeChanged(" << (node ? node->path() : QLatin1String("0")) << ", " << (project ? project->displayName() : QLatin1String("0")) << ')';
emit currentNodeChanged(d->m_currentNode, project);
+ showExternalFileWarning();
updateContextMenuActions();
}
if (projectChanged) {
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index c42f453940..7f3aabfb0b 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -281,6 +281,7 @@ private:
QPair<bool, QString> buildSettingsEnabled(Project *pro);
bool hasDeploySettings(Project *pro);
+ void showExternalFileWarning();
void setCurrent(Project *project, QString filePath, Node *node);
QStringList allFilesWithDependencies(Project *pro);