Commit f566d7ea authored by hjk's avatar hjk

TextEditor: Make mark requests operate on widgets, not editor

Removes some widget->editor->signal->slot->widget indirection.

Change-Id: I7951d62ad3b7477e4693798d85c53c932b86c95e
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent af23e254
......@@ -826,7 +826,7 @@ void BookmarkManager::saveBookmarks()
SessionManager::setValue(QLatin1String("Bookmarks"), list);
}
void BookmarkManager::operateTooltip(BaseTextEditor *textEditor, const QPoint &pos, Bookmark *mark)
void BookmarkManager::operateTooltip(TextEditorWidget *widget, const QPoint &pos, Bookmark *mark)
{
if (!mark)
return;
......@@ -834,7 +834,7 @@ void BookmarkManager::operateTooltip(BaseTextEditor *textEditor, const QPoint &p
if (mark->note().isEmpty())
ToolTip::hide();
else
ToolTip::show(pos, TextContent(mark->note()), textEditor->widget());
ToolTip::show(pos, TextContent(mark->note()), widget);
}
/* Loads the bookmarks from the session settings. */
......@@ -848,20 +848,19 @@ void BookmarkManager::loadBookmarks()
updateActionStatus();
}
void BookmarkManager::handleBookmarkRequest(BaseTextEditor *textEditor,
int line,
void BookmarkManager::handleBookmarkRequest(TextEditorWidget *widget, int line,
BaseTextEditor::MarkRequestKind kind)
{
if (kind == BaseTextEditor::BookmarkRequest && textEditor->document())
toggleBookmark(textEditor->document()->filePath(), line);
if (kind == BaseTextEditor::BookmarkRequest && widget->textDocument())
toggleBookmark(widget->textDocument()->filePath(), line);
}
void BookmarkManager::handleBookmarkTooltipRequest(BaseTextEditor *textEditor, const QPoint &pos,
int line)
void BookmarkManager::handleBookmarkTooltipRequest(TextEditorWidget *widget,
const QPoint &pos, int line)
{
if (textEditor->document()) {
Bookmark *mark = findBookmark(textEditor->document()->filePath(), line);
operateTooltip(textEditor, pos, mark);
if (widget->textDocument()) {
Bookmark *mark = findBookmark(widget->textDocument()->filePath(), line);
operateTooltip(widget, pos, mark);
}
}
......
......@@ -93,6 +93,12 @@ public:
Note = Qt::UserRole + 4
};
void handleBookmarkRequest(TextEditor::TextEditorWidget *widget, int line,
TextEditor::BaseTextEditor::MarkRequestKind kind);
void handleBookmarkTooltipRequest(TextEditor::TextEditorWidget *widget,
const QPoint &pos, int line);
public slots:
void toggleBookmark();
void toggleBookmark(const QString &fileName, int lineNumber);
......@@ -113,12 +119,6 @@ signals:
private slots:
void updateActionStatus();
void loadBookmarks();
void handleBookmarkRequest(TextEditor::BaseTextEditor * textEditor,
int line,
TextEditor::BaseTextEditor::MarkRequestKind kind);
void handleBookmarkTooltipRequest(TextEditor::BaseTextEditor *textEditor,
const QPoint &pos,
int line);
private:
void documentPrevNext(bool next);
......@@ -128,7 +128,7 @@ private:
void addBookmark(const QString &s);
static QString bookmarkToString(const Bookmark *b);
void saveBookmarks();
void operateTooltip(TextEditor::BaseTextEditor *textEditor, const QPoint &pos, Bookmark *mark);
void operateTooltip(TextEditor::TextEditorWidget *widget, const QPoint &pos, Bookmark *mark);
typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
......
......@@ -152,40 +152,35 @@ void BookmarksPlugin::updateActions(int state)
void BookmarksPlugin::editorOpened(Core::IEditor *editor)
{
if (qobject_cast<BaseTextEditor *>(editor)) {
connect(editor, SIGNAL(markContextMenuRequested(TextEditor::BaseTextEditor*,int,QMenu*)),
this, SLOT(requestContextMenu(TextEditor::BaseTextEditor*,int,QMenu*)));
connect(editor,
SIGNAL(markRequested(TextEditor::BaseTextEditor*,int,
TextEditor::BaseTextEditor::MarkRequestKind)),
m_bookmarkManager,
SLOT(handleBookmarkRequest(TextEditor::BaseTextEditor*,int,
TextEditor::BaseTextEditor::MarkRequestKind)));
connect(editor,
SIGNAL(markTooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)),
m_bookmarkManager,
SLOT(handleBookmarkTooltipRequest(TextEditor::BaseTextEditor*,QPoint,int)));
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
connect(widget, &TextEditorWidget::markRequested,
m_bookmarkManager, &BookmarkManager::handleBookmarkRequest);
connect(widget, &TextEditorWidget::markTooltipRequested,
m_bookmarkManager, &BookmarkManager::handleBookmarkTooltipRequest);
connect(widget, &TextEditorWidget::markContextMenuRequested,
this, &BookmarksPlugin::requestContextMenu);
}
}
void BookmarksPlugin::editorAboutToClose(Core::IEditor *editor)
{
if (qobject_cast<BaseTextEditor *>(editor)) {
disconnect(editor, SIGNAL(markContextMenuRequested(TextEditor::BaseTextEditor*,int,QMenu*)),
this, SLOT(requestContextMenu(TextEditor::BaseTextEditor*,int,QMenu*)));
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
connect(widget, &TextEditorWidget::markContextMenuRequested,
this, &BookmarksPlugin::requestContextMenu);
}
}
void BookmarksPlugin::requestContextMenu(TextEditor::BaseTextEditor *editor,
void BookmarksPlugin::requestContextMenu(TextEditorWidget *widget,
int lineNumber, QMenu *menu)
{
// Don't set bookmarks in disassembler views.
if (editor->document()->property("DisassemblerView").toBool())
if (widget->textDocument()->property("DisassemblerView").toBool())
return;
m_bookmarkMarginActionLineNumber = lineNumber;
m_bookmarkMarginActionFileName = editor->document()->filePath();
m_bookmarkMarginActionFileName = widget->textDocument()->filePath();
menu->addAction(m_bookmarkMarginAction);
if (m_bookmarkManager->hasBookmarkInPosition(m_bookmarkMarginActionFileName, m_bookmarkMarginActionLineNumber))
......
......@@ -42,7 +42,7 @@ QT_END_NAMESPACE
namespace Core { class IEditor; }
namespace TextEditor { class BaseTextEditor; }
namespace TextEditor { class TextEditorWidget; }
namespace Bookmarks {
namespace Internal {
......@@ -67,12 +67,13 @@ public slots:
private slots:
void editorOpened(Core::IEditor *editor);
void editorAboutToClose(Core::IEditor *editor);
void requestContextMenu(TextEditor::BaseTextEditor *editor,
int lineNumber, QMenu *menu);
void bookmarkMarginActionTriggered();
void editBookmarkActionTriggered();
private:
void requestContextMenu(TextEditor::TextEditorWidget *widget,
int lineNumber, QMenu *menu);
BookmarkManager *m_bookmarkManager;
QAction *m_toggleAction;
......
......@@ -665,7 +665,7 @@ static bool currentTextEditorPosition(ContextData *data)
BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor();
if (!textEditor)
return false;
const IDocument *document = textEditor->document();
const TextDocument *document = textEditor->textDocument();
QTC_ASSERT(document, return false);
data->fileName = document->filePath();
if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) {
......@@ -835,11 +835,10 @@ public slots:
void editorOpened(Core::IEditor *editor);
void updateBreakMenuItem(Core::IEditor *editor);
void setBusyCursor(bool busy);
void requestMark(TextEditor::BaseTextEditor *editor,
int lineNumber,
void requestMark(TextEditor::TextEditorWidget *widget, int lineNumber,
TextEditor::BaseTextEditor::MarkRequestKind kind);
void requestContextMenu(TextEditor::BaseTextEditor *editor,
int lineNumber, QMenu *menu);
void requestContextMenu(TextEditor::TextEditorWidget *widget,
int lineNumber, QMenu *menu);
void activatePreviousMode();
void activateDebugMode();
......@@ -1851,15 +1850,13 @@ void DebuggerPluginPrivate::runScheduled()
void DebuggerPluginPrivate::editorOpened(IEditor *editor)
{
BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
if (!textEditor)
return;
connect(textEditor,
SIGNAL(markRequested(TextEditor::BaseTextEditor*,int,TextEditor::BaseTextEditor::MarkRequestKind)),
SLOT(requestMark(TextEditor::BaseTextEditor*,int,TextEditor::BaseTextEditor::MarkRequestKind)));
connect(textEditor,
SIGNAL(markContextMenuRequested(TextEditor::BaseTextEditor*,int,QMenu*)),
SLOT(requestContextMenu(TextEditor::BaseTextEditor*,int,QMenu*)));
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
connect(widget, &TextEditorWidget::markRequested,
this, &DebuggerPluginPrivate::requestMark);
connect(widget, &TextEditorWidget::markContextMenuRequested,
this, &DebuggerPluginPrivate::requestContextMenu);
}
}
void DebuggerPluginPrivate::updateBreakMenuItem(IEditor *editor)
......@@ -1868,7 +1865,7 @@ void DebuggerPluginPrivate::updateBreakMenuItem(IEditor *editor)
m_breakAction->setEnabled(textEditor != 0);
}
void DebuggerPluginPrivate::requestContextMenu(BaseTextEditor *editor,
void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget,
int lineNumber, QMenu *menu)
{
BreakpointMenuContextData args;
......@@ -1876,7 +1873,7 @@ void DebuggerPluginPrivate::requestContextMenu(BaseTextEditor *editor,
bool contextUsable = true;
BreakpointModelId id = BreakpointModelId();
TextDocument *document = editor->textDocument();
TextDocument *document = widget->textDocument();
args.fileName = document->filePath();
if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) {
QString line = document->plainText()
......@@ -2041,22 +2038,20 @@ void DebuggerPluginPrivate::toggleBreakpointByAddress(quint64 address,
}
}
void DebuggerPluginPrivate::requestMark(BaseTextEditor *editor,
int lineNumber,
void DebuggerPluginPrivate::requestMark(TextEditorWidget *widget, int lineNumber,
BaseTextEditor::MarkRequestKind kind)
{
if (kind != BaseTextEditor::BreakpointRequest)
return;
if (IDocument *document = editor->document()) {
if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) {
QString line = editor->textDocument()->plainText()
TextDocument *document = widget->textDocument();
if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) {
QString line = document->plainText()
.section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1);
quint64 address = DisassemblerLine::addressFromDisassemblyLine(line);
toggleBreakpointByAddress(address);
} else {
toggleBreakpointByFileAndLine(document->filePath(), lineNumber);
}
quint64 address = DisassemblerLine::addressFromDisassemblyLine(line);
toggleBreakpointByAddress(address);
} else {
toggleBreakpointByFileAndLine(document->filePath(), lineNumber);
}
}
......
......@@ -4928,7 +4928,7 @@ void TextEditorWidget::extraAreaContextMenuEvent(QContextMenuEvent *e)
if (d->m_marksVisible) {
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
QMenu * contextMenu = new QMenu(this);
emit markContextMenuRequested(cursor.blockNumber() + 1, contextMenu);
emit markContextMenuRequested(this, cursor.blockNumber() + 1, contextMenu);
if (!contextMenu->isEmpty())
contextMenu->exec(e->globalPos());
delete contextMenu;
......@@ -4976,7 +4976,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
if (inMarkArea) {
//Find line by cursor position
int line = cursor.blockNumber() + 1;
emit markTooltipRequested(mapToGlobal(e->pos()), line);
emit markTooltipRequested(this, mapToGlobal(e->pos()), line);
}
if (e->buttons() & Qt::LeftButton && !d->m_markDragStart.isNull()) {
......@@ -5094,7 +5094,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
else
kind = BaseTextEditor::BreakpointRequest;
emit markRequested(line, kind);
emit markRequested(this, line, kind);
}
}
}
......@@ -7346,21 +7346,6 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc
widget->d->m_codeAssistant.configure(widget);
widget->d->m_commentDefinition.setStyle(m_commentStyle);
connect(widget, &TextEditorWidget::markRequested, editor,
[editor](int line, BaseTextEditor::MarkRequestKind kind) {
editor->markRequested(editor, line, kind);
});
connect(widget, &TextEditorWidget::markContextMenuRequested, editor,
[editor](int line, QMenu *menu) {
editor->markContextMenuRequested(editor, line, menu);
});
connect(widget, &TextEditorWidget::markTooltipRequested, editor,
[editor](const QPoint &globalPos, int line) {
editor->markTooltipRequested(editor, globalPos, line);
});
connect(widget, &TextEditorWidget::activateEditor,
[editor]() { Core::EditorManager::activateEditor(editor); });
......
......@@ -195,11 +195,6 @@ public:
/*! Selects text between current cursor position and \a toPos. */
virtual void select(int toPos);
signals:
void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu);
void markTooltipRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int line);
private:
friend class TextEditorFactory;
Internal::BaseTextEditorPrivate *d;
......@@ -599,12 +594,15 @@ protected:
signals:
void markRequested(int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
void markContextMenuRequested(int line, QMenu *menu);
void tooltipOverrideRequested(TextEditor::TextEditorWidget *editorWidget,
void markRequested(TextEditor::TextEditorWidget *widget,
int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
void markContextMenuRequested(TextEditor::TextEditorWidget *widget,
int line, QMenu *menu);
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
const QPoint &globalPos, int position, bool *handled);
void tooltipRequested(const QPoint &globalPos, int position);
void markTooltipRequested(const QPoint &globalPos, int line);
void markTooltipRequested(TextEditor::TextEditorWidget *widget,
const QPoint &globalPos, int line);
void activateEditor();
protected slots:
......
......@@ -92,6 +92,7 @@
using namespace Analyzer;
using namespace Core;
using namespace Valgrind::Callgrind;
using namespace TextEditor;
using namespace ProjectExplorer;
namespace Valgrind {
......@@ -167,7 +168,7 @@ public slots:
void engineFinished();
void editorOpened(Core::IEditor *);
void requestContextMenu(TextEditor::BaseTextEditor *editor, int line, QMenu *menu);
void requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu);
public:
CallgrindTool *q;
......@@ -864,21 +865,18 @@ void CallgrindToolPrivate::showParserResults(const ParseData *data)
void CallgrindToolPrivate::editorOpened(IEditor *editor)
{
TextEditor::BaseTextEditor *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
if (!textEditor)
return;
connect(textEditor,
SIGNAL(markContextMenuRequested(TextEditor::BaseTextEditor*,int,QMenu*)),
SLOT(requestContextMenu(TextEditor::BaseTextEditor*,int,QMenu*)));
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
connect(widget, &TextEditorWidget::markContextMenuRequested,
this, &CallgrindToolPrivate::requestContextMenu);
}
}
void CallgrindToolPrivate::requestContextMenu(TextEditor::BaseTextEditor *editor, int line, QMenu *menu)
void CallgrindToolPrivate::requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu)
{
// find callgrind text mark that corresponds to this editor's file and line number
const Function *func = 0;
foreach (CallgrindTextMark *textMark, m_textMarks) {
if (textMark->fileName() == editor->document()->filePath() && textMark->lineNumber() == line) {
if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) {
func = textMark->function();
break;
}
......
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