Debugging: Reload Script Scources

Update open editors when internal sources are reloaded.

Change-Id: If0780ac5fbbcd2a19c95dd5647d47cb70a9135e0
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
Aurindam Jana
2011-12-21 10:39:54 +01:00
parent a2d5cb3534
commit 19b539c995
2 changed files with 38 additions and 13 deletions

View File

@@ -349,8 +349,6 @@ void QmlEngine::gotoLocation(const Location &location)
if (QUrl(fileName).scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) == 0) { if (QUrl(fileName).scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) == 0) {
// internal file from source files -> show generated .js // internal file from source files -> show generated .js
QTC_ASSERT(d->m_sourceDocuments.contains(fileName), return); QTC_ASSERT(d->m_sourceDocuments.contains(fileName), return);
const QString jsSource = d->m_sourceDocuments.value(fileName)->toPlainText();
Core::IEditor *editor = 0; Core::IEditor *editor = 0;
Core::EditorManager *editorManager = Core::EditorManager::instance(); Core::EditorManager *editorManager = Core::EditorManager::instance();
@@ -369,19 +367,11 @@ void QmlEngine::gotoLocation(const Location &location)
if (editor) { if (editor) {
editor->setProperty(Constants::OPENED_BY_DEBUGGER, true); editor->setProperty(Constants::OPENED_BY_DEBUGGER, true);
} }
updateEditor(editor, d->m_sourceDocuments.value(fileName));
} }
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
if (!textEditor)
return;
QPlainTextEdit *plainTextEdit =
qobject_cast<QPlainTextEdit *>(editor->widget());
if (!plainTextEdit)
return;
plainTextEdit->setPlainText(jsSource);
plainTextEdit->setReadOnly(true);
editorManager->activateEditor(editor); editorManager->activateEditor(editor);
} else { } else {
DebuggerEngine::gotoLocation(location); DebuggerEngine::gotoLocation(location);
} }
@@ -865,6 +855,8 @@ void QmlEngine::setSourceFiles(const QStringList &fileNames)
} }
sourceFilesHandler()->setSourceFiles(files); sourceFilesHandler()->setSourceFiles(files);
//update open editors
} }
void QmlEngine::updateScriptSource(const QString &fileName, int lineOffset, int columnOffset, void QmlEngine::updateScriptSource(const QString &fileName, int lineOffset, int columnOffset,
@@ -908,6 +900,31 @@ void QmlEngine::updateScriptSource(const QString &fileName, int lineOffset, int
if (!cursor.movePosition(QTextCursor::NextBlock)) if (!cursor.movePosition(QTextCursor::NextBlock))
cursor.insertBlock(); cursor.insertBlock();
} }
//update open editors
QString titlePattern = tr("JS Source for %1").arg(fileName);
//Check if there are open editors with the same title
QList<Core::IEditor *> editors = Core::EditorManager::instance()->openedEditors();
foreach (Core::IEditor *editor, editors) {
if (editor->displayName() == titlePattern) {
updateEditor(editor, document);
break;
}
}
}
void QmlEngine::updateEditor(Core::IEditor *editor, const QTextDocument *document)
{
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
if (!textEditor)
return;
QPlainTextEdit *plainTextEdit =
qobject_cast<QPlainTextEdit *>(editor->widget());
if (!plainTextEdit)
return;
plainTextEdit->setPlainText(document->toPlainText());
plainTextEdit->setReadOnly(true);
} }
QmlAdapter *QmlEngine::adapter() const QmlAdapter *QmlEngine::adapter() const

View File

@@ -39,6 +39,12 @@
#include <QtNetwork/QAbstractSocket> #include <QtNetwork/QAbstractSocket>
class QTextDocument;
namespace Core {
class IEditor;
}
namespace Debugger { namespace Debugger {
class QmlAdapter; class QmlAdapter;
@@ -167,6 +173,8 @@ private:
const QString &oldBasePath, const QString &newBasePath) const; const QString &oldBasePath, const QString &newBasePath) const;
QString qmlImportPath() const; QString qmlImportPath() const;
void updateEditor(Core::IEditor *editor, const QTextDocument *document);
private: private:
friend class QmlCppEngine; friend class QmlCppEngine;
QmlEnginePrivate *d; QmlEnginePrivate *d;