summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordt <qtc-committer@nokia.com>2010-09-23 12:32:22 +0200
committerdt <qtc-committer@nokia.com>2010-09-23 12:36:16 +0200
commitd81d90a67ac34d169019e057f901ade3046f6ff3 (patch)
tree68758f4b15aca55a048d40d75bee46801a337aaa /src
parent034bb72dc416b8a27e87a0976a9e1fac4fa17cea (diff)
downloadqt-creator-d81d90a67ac34d169019e057f901ade3046f6ff3.tar.gz
EditorManager: add a flag for embedded linenumbers
And make use of it to accept on the command line the patterns: "filename" "+45", "filename" ":23", "filename:12" and "filename+42" Task-Nr: QTCREATORBUG-2428
Diffstat (limited to 'src')
-rw-r--r--src/plugins/coreplugin/coreimpl.cpp4
-rw-r--r--src/plugins/coreplugin/coreimpl.h2
-rw-r--r--src/plugins/coreplugin/coreplugin.cpp2
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp38
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.h3
-rw-r--r--src/plugins/coreplugin/editormanager/ieditor.h1
-rw-r--r--src/plugins/coreplugin/icore.h3
-rw-r--r--src/plugins/coreplugin/mainwindow.cpp18
-rw-r--r--src/plugins/coreplugin/mainwindow.h3
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp15
-rw-r--r--src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp2
-rw-r--r--src/plugins/texteditor/itexteditor.h2
12 files changed, 67 insertions, 26 deletions
diff --git a/src/plugins/coreplugin/coreimpl.cpp b/src/plugins/coreplugin/coreimpl.cpp
index b9628e0eb9..5347536a5a 100644
--- a/src/plugins/coreplugin/coreimpl.cpp
+++ b/src/plugins/coreplugin/coreimpl.cpp
@@ -228,9 +228,9 @@ void CoreImpl::removeContextObject(IContext *context)
m_mainwindow->removeContextObject(context);
}
-void CoreImpl::openFiles(const QStringList &arguments, bool switchMode)
+void CoreImpl::openFiles(const QStringList &arguments, ICore::OpenFilesFlags flags)
{
- m_mainwindow->openFiles(arguments, switchMode);
+ m_mainwindow->openFiles(arguments, flags);
}
void CoreImpl::emitNewItemsDialogRequested()
diff --git a/src/plugins/coreplugin/coreimpl.h b/src/plugins/coreplugin/coreimpl.h
index e926c9fdcb..e8e114cbba 100644
--- a/src/plugins/coreplugin/coreimpl.h
+++ b/src/plugins/coreplugin/coreimpl.h
@@ -88,7 +88,7 @@ public:
void addContextObject(IContext *context);
void removeContextObject(IContext *context);
- void openFiles(const QStringList &fileNames, bool switchMode);
+ void openFiles(const QStringList &fileNames, ICore::OpenFilesFlags flags);
void emitNewItemsDialogRequested();
diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp
index 9e8d03bfcc..a855b0d426 100644
--- a/src/plugins/coreplugin/coreplugin.cpp
+++ b/src/plugins/coreplugin/coreplugin.cpp
@@ -100,7 +100,7 @@ void CorePlugin::extensionsInitialized()
void CorePlugin::remoteCommand(const QStringList & /* options */, const QStringList &args)
{
- m_mainWindow->openFiles(args, true);
+ m_mainWindow->openFiles(args, ICore::SwitchMode);
m_mainWindow->activateWindow();
}
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 0ea17b2b9e..cad242bbff 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -1179,31 +1179,53 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito
return openEditor(0, fileName, editorId, flags, newEditor);
}
+int extractLineNumber(QString *fileName)
+{
+ int i = fileName->length() - 1;
+ for (; i >= 0; --i) {
+ if (!fileName->at(i).isNumber())
+ break;
+ }
+ if (i == -1)
+ return -1;
+ if (fileName->at(i) == ':' || fileName->at(i) == '+') {
+ int result = fileName->mid(i+1).toInt();
+ *fileName = fileName->left(i);
+ return result;
+ }
+ return -1;
+}
+
IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName,
const QString &editorId, OpenEditorFlags flags, bool *newEditor)
{
if (debugEditorManager)
qDebug() << Q_FUNC_INFO << fileName << editorId;
- if (fileName.isEmpty())
+ QString fn = fileName;
+ int lineNumber = -1;
+ if (flags && EditorManager::CanContainLineNumber)
+ lineNumber = extractLineNumber(&fn);
+
+ if (fn.isEmpty())
return 0;
if (newEditor)
*newEditor = false;
- const QList<IEditor *> editors = editorsForFileName(fileName);
+ const QList<IEditor *> editors = editorsForFileName(fn);
if (!editors.isEmpty())
return activateEditor(view, editors.first(), flags);
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
- IEditor *editor = createEditor(editorId, fileName);
+ IEditor *editor = createEditor(editorId, fn);
// If we could not open the file in the requested editor, fall
// back to the default editor:
if (!editor)
- editor = createEditor(QString(), fileName);
- if (!editor || !editor->open(fileName)) {
+ editor = createEditor(QString(), fn);
+ if (!editor || !editor->open(fn)) {
QApplication::restoreOverrideCursor();
- QMessageBox::critical(m_d->m_core->mainWindow(), tr("Opening File"), tr("Cannot open file %1!").arg(QDir::toNativeSeparators(fileName)));
+ QMessageBox::critical(m_d->m_core->mainWindow(), tr("Opening File"), tr("Cannot open file %1!").arg(QDir::toNativeSeparators(fn)));
delete editor;
editor = 0;
return 0;
@@ -1216,6 +1238,10 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
IEditor *result = activateEditor(view, editor, flags);
if (editor == result)
restoreEditorState(editor);
+
+ if (flags && EditorManager::CanContainLineNumber)
+ editor->gotoLine(lineNumber, -1);
+
QApplication::restoreOverrideCursor();
return result;
}
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index 68c22f1e34..65a5b1038c 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -109,7 +109,8 @@ public:
enum OpenEditorFlag {
NoActivate = 1,
IgnoreNavigationHistory = 2,
- ModeSwitch = 4
+ ModeSwitch = 4,
+ CanContainLineNumber = 8
};
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
diff --git a/src/plugins/coreplugin/editormanager/ieditor.h b/src/plugins/coreplugin/editormanager/ieditor.h
index 3d8b7eb996..90dad36a99 100644
--- a/src/plugins/coreplugin/editormanager/ieditor.h
+++ b/src/plugins/coreplugin/editormanager/ieditor.h
@@ -60,6 +60,7 @@ public:
virtual int currentLine() const { return 0; }
virtual int currentColumn() const { return 0; }
+ virtual void gotoLine(int line, int column = 0) { Q_UNUSED(line); Q_UNUSED(column); };
virtual bool isTemporary() const = 0;
diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h
index b07ee409ed..ad353f734c 100644
--- a/src/plugins/coreplugin/icore.h
+++ b/src/plugins/coreplugin/icore.h
@@ -119,7 +119,8 @@ public:
virtual void addContextObject(IContext *context) = 0;
virtual void removeContextObject(IContext *context) = 0;
- virtual void openFiles(const QStringList &fileNames, bool switchMode) = 0;
+ enum OpenFilesFlags { None = 0, SwitchMode = 1, CanContainLineNumbers = 2};
+ virtual void openFiles(const QStringList &fileNames, OpenFilesFlags flags = None) = 0;
signals:
void coreAboutToOpen();
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index c7a9c8a074..f32b3b2a18 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -416,7 +416,7 @@ void MainWindow::dropEvent(QDropEvent *event)
QStringList files;
if (isDesktopFileManagerDrop(event->mimeData(), &files)) {
event->accept();
- openFiles(files, true);
+ openFiles(files, ICore::SwitchMode);
} else {
event->ignore();
}
@@ -793,7 +793,7 @@ void MainWindow::newFile()
void MainWindow::openFile()
{
- openFiles(editorManager()->getOpenFileNames(), true);
+ openFiles(editorManager()->getOpenFileNames(), ICore::SwitchMode);
}
static QList<IFileFactory*> getNonEditorFileFactories()
@@ -823,7 +823,7 @@ static IFileFactory *findFileFactory(const QList<IFileFactory*> &fileFactories,
}
// opens either an editor or loads a project
-void MainWindow::openFiles(const QStringList &fileNames, bool switchMode)
+void MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesFlags flags)
{
QList<IFileFactory*> nonEditorFileFactories = getNonEditorFileFactories();
@@ -832,13 +832,15 @@ void MainWindow::openFiles(const QStringList &fileNames, bool switchMode)
const QString absoluteFilePath = fi.absoluteFilePath();
if (IFileFactory *fileFactory = findFileFactory(nonEditorFileFactories, mimeDatabase(), fi)) {
fileFactory->open(absoluteFilePath);
- if (switchMode)
+ if (flags && ICore::SwitchMode)
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
} else {
- EditorManager::OpenEditorFlag flags;
- if (switchMode)
- flags = EditorManager::ModeSwitch;
- editorManager()->openEditor(absoluteFilePath, QString(), flags);
+ QFlags<EditorManager::OpenEditorFlag> emFlags;
+ if (flags && ICore::SwitchMode)
+ emFlags = EditorManager::ModeSwitch;
+ if (flags && ICore::CanContainLineNumbers)
+ emFlags |= EditorManager::CanContainLineNumber;
+ editorManager()->openEditor(absoluteFilePath, QString(), emFlags);
}
}
}
diff --git a/src/plugins/coreplugin/mainwindow.h b/src/plugins/coreplugin/mainwindow.h
index 92adeceda6..bd1708607e 100644
--- a/src/plugins/coreplugin/mainwindow.h
+++ b/src/plugins/coreplugin/mainwindow.h
@@ -32,6 +32,7 @@
#include "core_global.h"
#include "icontext.h"
+#include "icore.h"
#include "dialogs/iwizard.h"
#include "eventfilteringmainwindow.h"
@@ -97,7 +98,7 @@ public:
void removeContextObject(IContext *contex);
void resetContext();
- void openFiles(const QStringList &fileNames, bool switchMode);
+ void openFiles(const QStringList &fileNames, ICore::OpenFilesFlags flags);
Core::ActionManager *actionManager() const;
Core::FileManager *fileManager() const;
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 22cbc2dc83..0d1837596e 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1240,7 +1240,18 @@ void ProjectExplorerPlugin::restoreSession()
connect(d->m_welcomePage, SIGNAL(requestSession(QString)), this, SLOT(loadSession(QString)));
connect(d->m_welcomePage, SIGNAL(requestProject(QString)), this, SLOT(loadProject(QString)));
- Core::ICore::instance()->openFiles(arguments, false);
+ QStringList combinedList;
+ // Converts "filename" "+45" or "filename" ":23"
+ // into "filename+45" and "filename:23"
+ foreach (const QString &str, arguments) {
+ if (!combinedList.isEmpty() && (str.startsWith("+") || str.startsWith(":"))) {
+ combinedList.last().append(str);
+ } else {
+ combinedList << str;
+ }
+ }
+
+ Core::ICore::instance()->openFiles(combinedList, Core::ICore::CanContainLineNumbers);
updateActions();
}
@@ -2375,7 +2386,7 @@ void ProjectExplorerPlugin::openOpenProjectDialog()
const QString path = fileMananger->useProjectsDirectory() ? fileMananger->projectsDirectory() : QString();
const QStringList files = fileMananger->getOpenFileNames(filters, path, &projectFilesFilter);
if (!files.isEmpty())
- Core::ICore::instance()->openFiles(files, true);
+ Core::ICore::instance()->openFiles(files, Core::ICore::SwitchMode);
}
Q_EXPORT_PLUGIN(ProjectExplorerPlugin)
diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp
index 10d3af85ec..7742aa5106 100644
--- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp
+++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp
@@ -335,7 +335,7 @@ void GettingStartedWelcomePageWidget::slotOpenExample()
tryFile = proFileInfo.path() + '/' + proFileInfo.baseName() + ".qml";
if(QFile::exists(tryFile))
files << tryFile;
- Core::ICore::instance()->openFiles(files, true);
+ Core::ICore::instance()->openFiles(files, Core::ICore::SwitchMode);
if (!helpFile.isEmpty())
slotOpenContextHelpPage(helpFile);
}
diff --git a/src/plugins/texteditor/itexteditor.h b/src/plugins/texteditor/itexteditor.h
index 3dbb3e2640..16af52ef1f 100644
--- a/src/plugins/texteditor/itexteditor.h
+++ b/src/plugins/texteditor/itexteditor.h
@@ -99,8 +99,6 @@ public:
virtual int find(const QString &string) const = 0;
- virtual void gotoLine(int line, int column = 0) = 0;
-
virtual int position(PositionOperation posOp = Current, int at = -1) const = 0;
virtual void convertPosition(int pos, int *line, int *column) const = 0;
virtual QRect cursorRect(int pos = -1) const = 0;