From cc92f1c4321e968eee24517ad1c928f055c16bbb Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Tue, 10 Jan 2012 22:14:51 +0200 Subject: [PATCH] GUI: Add include paths as relative to project file. When adding a new include path check if the path is relative path to the project file's path. If path is relative then remove the begin of the path making it a relative path in project file. Ticket: #3019 (GUI: Add project include paths as relative paths) --- gui/projectfiledialog.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index 36d6a199e..405e5bdc5 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -204,13 +204,23 @@ void ProjectFileDialog::SetExcludedPaths(const QStringList &paths) void ProjectFileDialog::AddIncludeDir() { - QFileInfo inf(mFilePath); + const QFileInfo inf(mFilePath); const QString rootpath = inf.absolutePath(); QString selectedDir = QFileDialog::getExistingDirectory(this, tr("Select include directory"), rootpath); if (!selectedDir.isEmpty()) { + // Check if the path is relative to project file's path and if so + // make it a relative path instead of absolute path. + const QDir dir(selectedDir); + QString absPath = dir.absolutePath(); + if (absPath.startsWith(rootpath)) { + // Remove also the slash from begin of new relative path + selectedDir = absPath.remove(0, rootpath.length() + 1); + } + if (!selectedDir.endsWith("/")) + selectedDir += '/'; AddIncludeDir(selectedDir); } }