forked from qt-creator/qt-creator
Allow specifying line number when selecting a file with the locator.
When using the file selections locators (OpenDocumentsFilter, FileSystemFilter, and those inherited from BaseFileFilter), allow specifying the line where to open the file: like 'file.cpp:654'. This syntax works for wildcards/incomplete expression as well: toto:423 will match 'toto', and open resulting file at line 423. Also, fix line extraction in editormanager, to support a single semicolon (without number) as well as a line explicitely set to 0. Change-Id: I80e13b59aa9c972f33963cfee81ec04f277fe526 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
committed by
Eike Ziller
parent
69552f01d4
commit
4cac96447d
@@ -1218,7 +1218,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const Id &editorId,
|
||||
return m_instance->openEditor(m_instance->currentEditorView(), fileName, editorId, flags, newEditor);
|
||||
}
|
||||
|
||||
int extractLineNumber(QString *fileName)
|
||||
static int extractLineNumber(QString *fileName)
|
||||
{
|
||||
int i = fileName->length() - 1;
|
||||
for (; i >= 0; --i) {
|
||||
@@ -1229,7 +1229,10 @@ int extractLineNumber(QString *fileName)
|
||||
return -1;
|
||||
const QChar c = fileName->at(i);
|
||||
if (c == QLatin1Char(':') || c == QLatin1Char('+')) {
|
||||
if (const int result = fileName->mid(i + 1).toInt()) {
|
||||
bool ok;
|
||||
const QString suffix = fileName->mid(i + 1);
|
||||
const int result = suffix.toInt(&ok);
|
||||
if (suffix.isEmpty() || ok) {
|
||||
fileName->truncate(i);
|
||||
return result;
|
||||
}
|
||||
@@ -1237,6 +1240,29 @@ int extractLineNumber(QString *fileName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Extract line number suffix. Return the suffix (e.g. ":132") and truncates the filename accordingly.
|
||||
QString EditorManager::splitLineNumber(QString *fileName)
|
||||
{
|
||||
int i = fileName->length() - 1;
|
||||
for (; i >= 0; --i) {
|
||||
if (!fileName->at(i).isNumber())
|
||||
break;
|
||||
}
|
||||
if (i == -1)
|
||||
return QString();
|
||||
const QChar c = fileName->at(i);
|
||||
if (c == QLatin1Char(':') || c == QLatin1Char('+')) {
|
||||
const QString result = fileName->mid(i + 1);
|
||||
bool ok;
|
||||
result.toInt(&ok);
|
||||
if (result.isEmpty() || ok) {
|
||||
fileName->truncate(i);
|
||||
return QString(c) + result;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
static QString autoSaveName(const QString &fileName)
|
||||
{
|
||||
return fileName + QLatin1String(".autosave");
|
||||
|
||||
@@ -117,6 +117,7 @@ public:
|
||||
};
|
||||
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
|
||||
|
||||
static QString splitLineNumber(QString *fileName);
|
||||
static IEditor *openEditor(const QString &fileName, const Id &editorId = Id(),
|
||||
OpenEditorFlags flags = 0, bool *newEditor = 0);
|
||||
static IEditor *openEditorWithContents(const Id &editorId,
|
||||
|
||||
Reference in New Issue
Block a user