Commit 44e7eca5 authored by d3fault's avatar d3fault Committed by hjk
Browse files

Add goto column number command line arg to complement goto line number



When specifying a filename as an argument, you can append a colon (or a
plus) followed by a number to indicate which line the cursor should be
positioned at in that file. This patch adds the same functionality but
for the column position as well. Ex: main.cpp:5:4 would open main.cpp
and put the cursor at line 5 column 4. The column number is optional,
just like the line number before it. It should be noted that specified
column numbers larger than the amount of characters available on that
line are wrapped onto subsequent lines.

Change-Id: I50208500fa43e43a9514d2be21630b3c607119a6
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 2fb9c3c7
......@@ -229,7 +229,7 @@ bool CorePlugin::delayedInitialize()
QObject *CorePlugin::remoteCommand(const QStringList & /* options */, const QStringList &args)
{
IDocument *res = m_mainWindow->openFiles(
args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineNumbers));
args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers));
m_mainWindow->raiseWindow();
return res;
}
......
......@@ -173,7 +173,7 @@ void EditorManagerPlaceHolder::currentModeChanged(IMode *mode)
static EditorManager *m_instance = 0;
static EditorManagerPrivate *d;
static int extractLineNumber(QString *fileName)
static int extractNumericSuffix(QString *fileName)
{
int i = fileName->length() - 1;
for (; i >= 0; --i) {
......@@ -195,6 +195,22 @@ static int extractLineNumber(QString *fileName)
return -1;
}
static void extractLineAndColumnNumbers(QString *fileName, int *lineNumber, int *columnNumber)
{
*lineNumber = -1;
*columnNumber = -1;
int lastSuffix = extractNumericSuffix(fileName);
if (lastSuffix == -1)
return;
int secondToLastSuffix = extractNumericSuffix(fileName);
if (secondToLastSuffix == -1) {
*lineNumber = lastSuffix;
return;
}
*lineNumber = secondToLastSuffix;
*columnNumber = lastSuffix - 1; //column is 0 based, despite line being 1 based
}
static QString autoSaveName(const QString &fileName)
{
return fileName + QLatin1String(".autosave");
......@@ -533,8 +549,9 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
QString fn = fileName;
QFileInfo fi(fn);
int lineNumber = -1;
if ((flags & EditorManager::CanContainLineNumber) && !fi.exists()) {
lineNumber = extractLineNumber(&fn);
int columnNumber = -1;
if ((flags & EditorManager::CanContainLineAndColumnNumber) && !fi.exists()) {
extractLineAndColumnNumbers(&fn, &lineNumber, &columnNumber);
if (lineNumber != -1)
fi.setFile(fn);
}
......@@ -549,8 +566,8 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
if (!editors.isEmpty()) {
IEditor *editor = editors.first();
editor = activateEditor(view, editor, flags);
if (editor && flags & EditorManager::CanContainLineNumber)
editor->gotoLine(lineNumber, -1);
if (editor && flags & EditorManager::CanContainLineAndColumnNumber)
editor->gotoLine(lineNumber, columnNumber);
return editor;
}
......@@ -586,8 +603,8 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
if (editor == result)
restoreEditorState(editor);
if (flags & EditorManager::CanContainLineNumber)
editor->gotoLine(lineNumber, -1);
if (flags & EditorManager::CanContainLineAndColumnNumber)
editor->gotoLine(lineNumber, columnNumber);
QApplication::restoreOverrideCursor();
return result;
......
......@@ -102,7 +102,7 @@ public:
DoNotChangeCurrentEditor = 1,
IgnoreNavigationHistory = 2,
DoNotMakeVisible = 4,
CanContainLineNumber = 8,
CanContainLineAndColumnNumber = 8,
OpenInOtherSplit = 16,
DoNotSwitchToDesignMode = 32
};
......
......@@ -117,7 +117,7 @@ public:
enum OpenFilesFlags {
None = 0,
SwitchMode = 1,
CanContainLineNumbers = 2,
CanContainLineAndColumnNumbers = 2,
/// Stop loading once the first file fails to load
StopOnLoadFail = 4
};
......
......@@ -169,7 +169,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
void BaseFileFilter::accept(LocatorFilterEntry selection) const
{
EditorManager::openEditor(selection.internalData.toString(), Id(),
EditorManager::CanContainLineNumber);
EditorManager::CanContainLineAndColumnNumber);
}
/*!
......
......@@ -162,7 +162,7 @@ void FileSystemFilter::accept(LocatorFilterEntry selection) const
}
const QFileInfo fileInfo(selection.internalData.toString());
const QString cleanedFilePath = QDir::cleanPath(fileInfo.absoluteFilePath());
EditorManager::openEditor(cleanedFilePath, Id(), EditorManager::CanContainLineNumber);
EditorManager::openEditor(cleanedFilePath, Id(), EditorManager::CanContainLineAndColumnNumber);
}
bool FileSystemFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
......
......@@ -122,5 +122,5 @@ void OpenDocumentsFilter::refresh(QFutureInterface<void> &future)
void OpenDocumentsFilter::accept(LocatorFilterEntry selection) const
{
EditorManager::openEditor(selection.internalData.toString(), Id(),
EditorManager::CanContainLineNumber);
EditorManager::CanContainLineAndColumnNumber);
}
......@@ -787,8 +787,8 @@ IDocument *MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesF
}
} else {
QFlags<EditorManager::OpenEditorFlag> emFlags;
if (flags & ICore::CanContainLineNumbers)
emFlags |= EditorManager::CanContainLineNumber;
if (flags & ICore::CanContainLineAndColumnNumbers)
emFlags |= EditorManager::CanContainLineAndColumnNumber;
IEditor *editor = EditorManager::openEditor(absoluteFilePath, Id(), emFlags);
if (!editor) {
if (flags & ICore::StopOnLoadFail)
......
......@@ -1899,7 +1899,7 @@ void ProjectExplorerPluginPrivate::loadSession(const QString &session)
void ProjectExplorerPlugin::restoreSession2()
{
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
ICore::openFiles(dd->m_arguments, ICore::OpenFilesFlags(ICore::CanContainLineNumbers | ICore::SwitchMode));
ICore::openFiles(dd->m_arguments, ICore::OpenFilesFlags(ICore::CanContainLineAndColumnNumbers | ICore::SwitchMode));
}
void ProjectExplorerPluginPrivate::buildStateChanged(Project * pro)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment