Debugger: Use FileInProjectFinder for the console view

All the functionality to guess local files from remote paths is already
there.

Change-Id: I5bffeb0f126efef99edbaf152e1a5e9e1d244699
Task-number: QTCREATORBUG-12008
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Ulf Hermann
2018-06-12 10:44:10 +02:00
parent bf7e749099
commit 451e437afd
5 changed files with 23 additions and 22 deletions

View File

@@ -254,6 +254,11 @@ void Console::setScriptEvaluator(const ScriptEvaluator &evaluator)
setContext(QString()); setContext(QString());
} }
void Console::populateFileFinder()
{
m_consoleView->populateFileFinder();
}
void Console::printItem(ConsoleItem::ItemType itemType, const QString &text) void Console::printItem(ConsoleItem::ItemType itemType, const QString &text)
{ {
printItem(new ConsoleItem(itemType, text)); printItem(new ConsoleItem(itemType, text));

View File

@@ -76,6 +76,7 @@ public:
void setContext(const QString &context); void setContext(const QString &context);
void setScriptEvaluator(const ScriptEvaluator &evaluator); void setScriptEvaluator(const ScriptEvaluator &evaluator);
void populateFileFinder();
void evaluate(const QString &expression); void evaluate(const QString &expression);
void printItem(ConsoleItem *item); void printItem(ConsoleItem *item);

View File

@@ -29,6 +29,7 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/manhattanstyle.h> #include <coreplugin/manhattanstyle.h>
#include <qtsupport/baseqtversion.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <QAction> #include <QAction>
@@ -128,6 +129,11 @@ void ConsoleView::onScrollToBottom()
scrollToBottom(); scrollToBottom();
} }
void ConsoleView::populateFileFinder()
{
QtSupport::BaseQtVersion::populateQmlFileFinder(&m_finder, nullptr);
}
void ConsoleView::mousePressEvent(QMouseEvent *event) void ConsoleView::mousePressEvent(QMouseEvent *event)
{ {
QPoint pos = event->pos(); QPoint pos = event->pos();
@@ -212,17 +218,10 @@ void ConsoleView::onRowActivated(const QModelIndex &index)
if (!index.isValid()) if (!index.isValid())
return; return;
// See if we have file and line Info const QFileInfo fi(m_finder.findFile(model()->data(index, ConsoleItem::FileRole).toString()));
QString filePath = model()->data(index, ConsoleItem::FileRole).toString(); if (fi.exists() && fi.isFile() && fi.isReadable()) {
const QUrl fileUrl = QUrl(filePath); Core::EditorManager::openEditorAt(fi.canonicalFilePath(),
if (fileUrl.isLocalFile()) model()->data(index, ConsoleItem::LineRole).toInt());
filePath = fileUrl.toLocalFile();
if (!filePath.isEmpty()) {
QFileInfo fi(filePath);
if (fi.exists() && fi.isFile() && fi.isReadable()) {
int line = model()->data(index, ConsoleItem::LineRole).toInt();
Core::EditorManager::openEditorAt(fi.canonicalFilePath(), line);
}
} }
} }
@@ -250,17 +249,9 @@ bool ConsoleView::canShowItemInTextEditor(const QModelIndex &index)
if (!index.isValid()) if (!index.isValid())
return false; return false;
// See if we have file and line Info bool success = false;
QString filePath = model()->data(index, ConsoleItem::FileRole).toString(); m_finder.findFile(model()->data(index, ConsoleItem::FileRole).toString(), &success);
const QUrl fileUrl = QUrl(filePath); return success;
if (fileUrl.isLocalFile())
filePath = fileUrl.toLocalFile();
if (!filePath.isEmpty()) {
QFileInfo fi(filePath);
if (fi.exists() && fi.isFile() && fi.isReadable())
return true;
}
return false;
} }
} // Internal } // Internal

View File

@@ -25,6 +25,7 @@
#pragma once #pragma once
#include <utils/fileinprojectfinder.h>
#include <utils/itemviews.h> #include <utils/itemviews.h>
namespace Debugger { namespace Debugger {
@@ -40,6 +41,7 @@ public:
ConsoleView(ConsoleItemModel *model, QWidget *parent); ConsoleView(ConsoleItemModel *model, QWidget *parent);
void onScrollToBottom(); void onScrollToBottom();
void populateFileFinder();
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
@@ -55,6 +57,7 @@ private:
bool canShowItemInTextEditor(const QModelIndex &index); bool canShowItemInTextEditor(const QModelIndex &index);
ConsoleItemModel *m_model; ConsoleItemModel *m_model;
Utils::FileInProjectFinder m_finder;
}; };
} // Internal } // Internal

View File

@@ -265,6 +265,7 @@ QmlEngine::QmlEngine()
connect(&d->applicationLauncher, &ApplicationLauncher::processStarted, connect(&d->applicationLauncher, &ApplicationLauncher::processStarted,
this, &QmlEngine::handleLauncherStarted); this, &QmlEngine::handleLauncherStarted);
debuggerConsole()->populateFileFinder();
debuggerConsole()->setScriptEvaluator([this](const QString &expr) { debuggerConsole()->setScriptEvaluator([this](const QString &expr) {
executeDebuggerCommand(expr, QmlLanguage); executeDebuggerCommand(expr, QmlLanguage);
}); });