forked from qt-creator/qt-creator
CMake: Support CMAKE_CURRENT_LIST_DIR and CMAKE_CURRENT_SOURCE_DIR
Support CMAKE_CURRENT_LIST_DIR and CMAKE_CURRENT_SOURCE_DIR as variables in filenames when handling links in the CMake editor. Having a way to find out variable values in CMake would be nice, till that arrives, we have to live with hacks to make the most common variables work:-/ Task-number: QTCREATORBUG-21065 Change-Id: Iffaaae8665e0662226d08b88de37b66d5a5fc4d4 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -130,12 +130,9 @@ void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
|
|
||||||
static bool isValidFileNameChar(const QChar &c)
|
static bool isValidFileNameChar(const QChar &c)
|
||||||
{
|
{
|
||||||
return c.isLetterOrNumber()
|
return c.isLetterOrNumber() || c == QLatin1Char('.') || c == QLatin1Char('_')
|
||||||
|| c == QLatin1Char('.')
|
|| c == QLatin1Char('-') || c == QLatin1Char('/') || c == QLatin1Char('\\') || c == '{'
|
||||||
|| c == QLatin1Char('_')
|
|| c == '}' || c == '$';
|
||||||
|| c == QLatin1Char('-')
|
|
||||||
|| c == QLatin1Char('/')
|
|
||||||
|| c == QLatin1Char('\\');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||||
@@ -185,9 +182,12 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
if (buffer.isEmpty())
|
if (buffer.isEmpty())
|
||||||
return processLinkCallback(link);
|
return processLinkCallback(link);
|
||||||
|
|
||||||
// TODO: Resolve variables
|
|
||||||
|
|
||||||
QDir dir(textDocument()->filePath().toFileInfo().absolutePath());
|
QDir dir(textDocument()->filePath().toFileInfo().absolutePath());
|
||||||
|
buffer.replace("${CMAKE_CURRENT_SOURCE_DIR}", dir.path());
|
||||||
|
buffer.replace("${CMAKE_CURRENT_LIST_DIR}", dir.path());
|
||||||
|
|
||||||
|
// TODO: Resolve more variables
|
||||||
|
|
||||||
QString fileName = dir.filePath(buffer);
|
QString fileName = dir.filePath(buffer);
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
if (fi.exists()) {
|
if (fi.exists()) {
|
||||||
|
Reference in New Issue
Block a user