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 {
|
||||
|
||||
/*!
|
||||
Returns the Link to \a fileName.
|
||||
Returns the Link to \a filePath.
|
||||
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},
|
||||
\c{filepath.txt:19:12}, \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)
|
||||
return {filePath};
|
||||
int postfixPos = -1;
|
||||
QString fileName = filePath.path();
|
||||
const LineColumn lineColumn = LineColumn::extractFromFileName(fileName, postfixPos);
|
||||
if (postfix && postfixPos >= 0)
|
||||
*postfix = fileName.mid(postfixPos);
|
||||
return Link{filePath.withNewPath(fileName.left(postfixPos)), lineColumn.line, lineColumn.column};
|
||||
Link link;
|
||||
if (!canContainLineNumber) {
|
||||
link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers);
|
||||
} else {
|
||||
int postfixPos = -1;
|
||||
const LineColumn lineColumn = LineColumn::extractFromFileName(filePathWithNumbers, postfixPos);
|
||||
if (postfix && postfixPos >= 0)
|
||||
*postfix = filePathWithNumbers.mid(postfixPos);
|
||||
link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers.left(postfixPos));
|
||||
link.targetLine = lineColumn.line;
|
||||
link.targetColumn = lineColumn.column;
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -23,12 +23,9 @@ public:
|
||||
, 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,
|
||||
QString *postfix = nullptr);
|
||||
|
||||
bool hasValidTarget() const
|
||||
{ return !targetFilePath.isEmpty(); }
|
||||
|
@@ -1000,7 +1000,7 @@ IDocument *MainWindow::openFiles(const FilePaths &filePaths,
|
||||
emFlags |= EditorManager::SwitchSplitIfAlreadyVisible;
|
||||
IEditor *editor = nullptr;
|
||||
if (flags & ICore::CanContainLineAndColumnNumbers) {
|
||||
const Link &link = Link::fromFilePath(absoluteFilePath, true);
|
||||
const Link &link = Link::fromString(absoluteFilePath.toString(), true);
|
||||
editor = EditorManager::openEditorAt(link, {}, emFlags);
|
||||
} else {
|
||||
editor = EditorManager::openEditor(absoluteFilePath, {}, emFlags);
|
||||
|
@@ -791,7 +791,7 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
}
|
||||
|
||||
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.linkTextEnd = literal->literalToken.end();
|
||||
processLinkCallback(link);
|
||||
|
Reference in New Issue
Block a user