Commit 871a8cd0 authored by Eike Ziller's avatar Eike Ziller

Work with documents instead of editors where possible in debugger

And where using editors is necessary, take *all* editors into account,
not a random set of what previously was called "original" editors (when
using splits).

Change-Id: Id6bbad08f3083b6744fc2edcf0b87ba504d3257b
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 354cd410
......@@ -582,20 +582,13 @@ void DebuggerEngine::gotoLocation(const Location &loc)
const QString file = loc.fileName();
const int line = loc.lineNumber();
QList<IEditor *> editors = EditorManager::instance()->editorsForFileName(file);
IEditor *editor = 0;
if (editors.isEmpty()) {
editor = EditorManager::openEditor(file, Core::Id(),
EditorManager::IgnoreNavigationHistory);
QTC_ASSERT(editor, return); // Unreadable file?
editor->setProperty(Constants::OPENED_BY_DEBUGGER, true);
} else {
editor = editors.back();
}
ITextEditor *texteditor = qobject_cast<ITextEditor *>(editor);
if (texteditor)
texteditor->gotoLine(line, 0);
bool newEditor = false;
IEditor *editor = EditorManager::openEditor(file, Core::Id(),
EditorManager::IgnoreNavigationHistory, &newEditor);
QTC_ASSERT(editor, return); // Unreadable file?
editor->gotoLine(line, 0);
if (newEditor)
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true);
if (loc.needsMarker()) {
d->m_locationMark.reset(new TextEditor::BaseTextMark(file, line));
......@@ -604,9 +597,6 @@ void DebuggerEngine::gotoLocation(const Location &loc)
d->m_locationMark->init();
}
// FIXME: Breaks with split views.
if (!d->m_memoryAgent.hasVisibleEditor() || loc.needsRaise())
EditorManager::activateEditor(editor);
//qDebug() << "MEMORY: " << d->m_memoryAgent.hasVisibleEditor();
}
......
......@@ -2119,29 +2119,26 @@ void DebuggerPluginPrivate::cleanupViews()
if (!boolSetting(CloseBuffersOnExit))
return;
EditorManager *editorManager = EditorManager::instance();
QTC_ASSERT(editorManager, return);
QList<IEditor *> toClose;
foreach (IEditor *editor, editorManager->openedEditors()) {
if (editor->property(Constants::OPENED_BY_DEBUGGER).toBool()) {
IDocument *doc = editor->document();
QList<IDocument *> toClose;
foreach (IDocument *document, EditorManager::documentModel()->openedDocuments()) {
if (document->property(Constants::OPENED_BY_DEBUGGER).toBool()) {
bool keepIt = true;
if (editor->property(Constants::OPENED_WITH_DISASSEMBLY).toBool())
if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool())
keepIt = false;
else if (doc->isModified())
else if (document->isModified())
keepIt = true;
else if (doc->filePath().contains(_("qeventdispatcher")))
else if (document->filePath().contains(_("qeventdispatcher")))
keepIt = false;
else
keepIt = (editor == EditorManager::currentEditor());
keepIt = (document == EditorManager::currentDocument());
if (keepIt)
editor->setProperty(Constants::OPENED_BY_DEBUGGER, false);
document->setProperty(Constants::OPENED_BY_DEBUGGER, false);
else
toClose.append(editor);
toClose.append(document);
}
}
editorManager->closeEditors(toClose);
EditorManager::closeDocuments(toClose);
}
void DebuggerPluginPrivate::setBusyCursor(bool busy)
......
......@@ -36,6 +36,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <texteditor/basetexteditor.h>
#include <utils/tooltip/tooltip.h>
......@@ -1372,7 +1373,8 @@ void DebuggerToolTipManager::debugModeEntered()
this, SLOT(slotUpdateVisibleToolTips()));
connect(em, SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(slotEditorOpened(Core::IEditor*)));
foreach (IEditor *e, em->openedEditors())
DocumentModel *documentModel = EditorManager::documentModel();
foreach (IEditor *e, documentModel->editorsForDocuments(documentModel->openedDocuments()))
slotEditorOpened(e);
// Position tooltips delayed once all the editor placeholder layouting is done.
if (!m_tooltips.isEmpty())
......@@ -1391,15 +1393,14 @@ void DebuggerToolTipManager::leavingDebugMode()
hide();
if (QWidget *topLevel = ICore::mainWindow()->topLevelWidget())
topLevel->removeEventFilter(this);
if (EditorManager *em = EditorManager::instance()) {
foreach (IEditor *e, em->openedEditors()) {
if (DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor(e)) {
toolTipEditor.baseTextEditor->verticalScrollBar()->disconnect(this);
toolTipEditor.textEditor->disconnect(this);
}
DocumentModel *documentModel = EditorManager::documentModel();
foreach (IEditor *e, documentModel->editorsForDocuments(documentModel->openedDocuments())) {
if (DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor(e)) {
toolTipEditor.baseTextEditor->verticalScrollBar()->disconnect(this);
toolTipEditor.textEditor->disconnect(this);
}
em->disconnect(this);
}
EditorManager::instance()->disconnect(this);
m_lastToolTipEditor = 0;
m_lastToolTipPoint = QPoint(-1, -1);
}
......
......@@ -310,8 +310,9 @@ void DisassemblerAgent::setContentsToEditor(const DisassemblerLines &contents)
Core::Constants::K_DEFAULT_TEXT_EDITOR_ID,
&titlePattern));
QTC_ASSERT(d->editor, return);
d->editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
d->editor->setProperty(Debugger::Constants::OPENED_WITH_DISASSEMBLY, true);
IDocument *document = d->editor->document();
document->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
document->setProperty(Debugger::Constants::OPENED_WITH_DISASSEMBLY, true);
d->configureMimeType();
BaseTextEditorWidget *baseTextEdit =
......
......@@ -140,7 +140,7 @@ static void openImageViewer(const QImage &image)
temporaryFile.close();
}
if (Core::IEditor *e = Core::EditorManager::instance()->openEditor(fileName))
e->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, QVariant(true));
e->document()->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, QVariant(true));
}
void ImageViewer::contextMenuEvent(QContextMenuEvent *ev)
......
......@@ -181,8 +181,8 @@ bool MemoryAgent::doCreateBinEditor(quint64 addr, unsigned flags,
Core::Constants::K_DEFAULT_BINARY_EDITOR_ID, &title);
if (!editor)
return false;
editor->setProperty(Constants::OPENED_BY_DEBUGGER, QVariant(true));
editor->setProperty(Constants::OPENED_WITH_MEMORY, QVariant(true));
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, QVariant(true));
editor->document()->setProperty(Constants::OPENED_WITH_MEMORY, QVariant(true));
QWidget *editorBinEditor = editor->widget();
connectBinEditorWidget(editorBinEditor);
MemoryView::setBinEditorReadOnly(editorBinEditor, readOnly);
......
......@@ -53,7 +53,7 @@
#include <utils/qtcassert.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetextdocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/icore.h>
......@@ -528,28 +528,25 @@ void QmlEngine::gotoLocation(const Location &location)
if (QUrl(fileName).isLocalFile()) {
// internal file from source files -> show generated .js
QTC_ASSERT(m_sourceDocuments.contains(fileName), return);
Core::IEditor *editor = 0;
Core::EditorManager *editorManager = Core::EditorManager::instance();
QString titlePattern = tr("JS Source for %1").arg(fileName);
//Check if there are open editors with the same title
QList<Core::IEditor *> editors = editorManager->openedEditors();
foreach (Core::IEditor *ed, editors) {
if (ed->document()->displayName() == titlePattern) {
editor = ed;
break;
//Check if there are open documents with the same title
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) {
if (document->displayName() == titlePattern) {
Core::EditorManager::instance()->activateEditorForDocument(document);
return;
}
}
if (!editor) {
editor = Core::EditorManager::openEditorWithContents(QmlJSEditor::Constants::C_QMLJSEDITOR_ID,
&titlePattern);
if (editor)
editor->setProperty(Constants::OPENED_BY_DEBUGGER, true);
updateEditor(editor, m_sourceDocuments.value(fileName));
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(
QmlJSEditor::Constants::C_QMLJSEDITOR_ID, &titlePattern);
if (editor) {
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true);
QPlainTextEdit *plainTextEdit =
qobject_cast<QPlainTextEdit *>(editor->widget());
if (plainTextEdit)
plainTextEdit->setReadOnly(true);
updateDocument(editor->document(), m_sourceDocuments.value(fileName));
}
Core::EditorManager::activateEditor(editor);
} else {
DebuggerEngine::gotoLocation(location);
}
......@@ -1299,27 +1296,22 @@ void QmlEngine::updateScriptSource(const QString &fileName, int lineOffset, int
//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->document()->displayName() == titlePattern) {
updateEditor(editor, document);
foreach (Core::IDocument *doc, Core::EditorManager::documentModel()->openedDocuments()) {
if (doc->displayName() == titlePattern) {
updateDocument(doc, document);
break;
}
}
}
void QmlEngine::updateEditor(Core::IEditor *editor, const QTextDocument *document)
void QmlEngine::updateDocument(Core::IDocument *document, const QTextDocument *textDocument)
{
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
if (!textEditor)
TextEditor::BaseTextDocument *baseTextDocument
= qobject_cast<TextEditor::BaseTextDocument *>(document);
if (!baseTextDocument)
return;
QPlainTextEdit *plainTextEdit =
qobject_cast<QPlainTextEdit *>(editor->widget());
if (!plainTextEdit)
return;
plainTextEdit->setPlainText(document->toPlainText());
plainTextEdit->setReadOnly(true);
baseTextDocument->document()->setPlainText(textDocument->toPlainText());
}
bool QmlEngine::canEvaluateScript(const QString &script)
......
......@@ -43,7 +43,7 @@
#include <QTextDocument>
namespace Core {
class IEditor;
class IDocument;
}
namespace Debugger {
......@@ -181,7 +181,7 @@ private:
const QString &oldBasePath, const QString &newBasePath) const;
QString qmlImportPath() const;
void updateEditor(Core::IEditor *editor, const QTextDocument *document);
void updateDocument(Core::IDocument *document, const QTextDocument *textDocument);
bool canEvaluateScript(const QString &script);
bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
quint32 *column, bool *valid);
......
......@@ -117,7 +117,7 @@ void SourceAgent::setContent(const QString &filePath, const QString &content)
CppEditor::Constants::CPPEDITOR_ID,
&titlePattern, content));
QTC_ASSERT(d->editor, return);
d->editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
d->editor->document()->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
BaseTextEditorWidget *baseTextEdit =
qobject_cast<BaseTextEditorWidget *>(d->editor->widget());
......
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