forked from qt-creator/qt-creator
Utils: Consolidate Link::from{FilePath,String}
The input is more unparsed-string-ish in nature, so FilePath is not appropriate. Change-Id: I85efb5813b8f5fbbc4127be1c936d5487637b75c Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -8,37 +8,30 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the Link to \a fileName.
|
Returns the Link to \a filePath.
|
||||||
If \a canContainLineNumber is true the line number, and column number components
|
If \a canContainLineNumber is true the line number, and column number components
|
||||||
are extracted from \a fileName and the found \a postfix is set.
|
are extracted from the \a filePath's \c path() and the found \a postfix is set.
|
||||||
|
|
||||||
The following patterns are supported: \c {filepath.txt:19},
|
The following patterns are supported: \c {filepath.txt:19},
|
||||||
\c{filepath.txt:19:12}, \c {filepath.txt+19},
|
\c{filepath.txt:19:12}, \c {filepath.txt+19},
|
||||||
\c {filepath.txt+19+12}, and \c {filepath.txt(19)}.
|
\c {filepath.txt+19+12}, and \c {filepath.txt(19)}.
|
||||||
*/
|
*/
|
||||||
Link Link::fromString(const QString &fileName, bool canContainLineNumber, QString *postfix)
|
|
||||||
{
|
|
||||||
if (!canContainLineNumber)
|
|
||||||
return {FilePath::fromString(fileName)};
|
|
||||||
int postfixPos = -1;
|
|
||||||
const LineColumn lineColumn = LineColumn::extractFromFileName(fileName, postfixPos);
|
|
||||||
if (postfix && postfixPos >= 0)
|
|
||||||
*postfix = fileName.mid(postfixPos);
|
|
||||||
return {FilePath::fromString(fileName.left(postfixPos)),
|
|
||||||
lineColumn.line,
|
|
||||||
lineColumn.column};
|
|
||||||
}
|
|
||||||
|
|
||||||
Link Link::fromFilePath(const FilePath &filePath, bool canContainLineNumber, QString *postfix)
|
Link Link::fromString(const QString &filePathWithNumbers, bool canContainLineNumber, QString *postfix)
|
||||||
{
|
{
|
||||||
if (!canContainLineNumber)
|
Link link;
|
||||||
return {filePath};
|
if (!canContainLineNumber) {
|
||||||
|
link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers);
|
||||||
|
} else {
|
||||||
int postfixPos = -1;
|
int postfixPos = -1;
|
||||||
QString fileName = filePath.path();
|
const LineColumn lineColumn = LineColumn::extractFromFileName(filePathWithNumbers, postfixPos);
|
||||||
const LineColumn lineColumn = LineColumn::extractFromFileName(fileName, postfixPos);
|
|
||||||
if (postfix && postfixPos >= 0)
|
if (postfix && postfixPos >= 0)
|
||||||
*postfix = fileName.mid(postfixPos);
|
*postfix = filePathWithNumbers.mid(postfixPos);
|
||||||
return Link{filePath.withNewPath(fileName.left(postfixPos)), lineColumn.line, lineColumn.column};
|
link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers.left(postfixPos));
|
||||||
|
link.targetLine = lineColumn.line;
|
||||||
|
link.targetColumn = lineColumn.column;
|
||||||
|
}
|
||||||
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -23,10 +23,7 @@ public:
|
|||||||
, targetColumn(column)
|
, targetColumn(column)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static Link fromString(const QString &fileName,
|
static Link fromString(const QString &filePathWithNumbers,
|
||||||
bool canContainLineNumber = false,
|
|
||||||
QString *postfix = nullptr);
|
|
||||||
static Link fromFilePath(const FilePath &filePath,
|
|
||||||
bool canContainLineNumber = false,
|
bool canContainLineNumber = false,
|
||||||
QString *postfix = nullptr);
|
QString *postfix = nullptr);
|
||||||
|
|
||||||
|
@@ -1000,7 +1000,7 @@ IDocument *MainWindow::openFiles(const FilePaths &filePaths,
|
|||||||
emFlags |= EditorManager::SwitchSplitIfAlreadyVisible;
|
emFlags |= EditorManager::SwitchSplitIfAlreadyVisible;
|
||||||
IEditor *editor = nullptr;
|
IEditor *editor = nullptr;
|
||||||
if (flags & ICore::CanContainLineAndColumnNumbers) {
|
if (flags & ICore::CanContainLineAndColumnNumbers) {
|
||||||
const Link &link = Link::fromFilePath(absoluteFilePath, true);
|
const Link &link = Link::fromString(absoluteFilePath.toString(), true);
|
||||||
editor = EditorManager::openEditorAt(link, {}, emFlags);
|
editor = EditorManager::openEditorAt(link, {}, emFlags);
|
||||||
} else {
|
} else {
|
||||||
editor = EditorManager::openEditor(absoluteFilePath, {}, emFlags);
|
editor = EditorManager::openEditor(absoluteFilePath, {}, emFlags);
|
||||||
|
@@ -791,7 +791,7 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (text.startsWith("https:/") || text.startsWith("http:/")) {
|
if (text.startsWith("https:/") || text.startsWith("http:/")) {
|
||||||
Link link = Link::fromFilePath(FilePath::fromPathPart(text));
|
Link link = Link::fromString(text);
|
||||||
link.linkTextStart = literal->literalToken.begin();
|
link.linkTextStart = literal->literalToken.begin();
|
||||||
link.linkTextEnd = literal->literalToken.end();
|
link.linkTextEnd = literal->literalToken.end();
|
||||||
processLinkCallback(link);
|
processLinkCallback(link);
|
||||||
|
Reference in New Issue
Block a user