forked from qt-creator/qt-creator
TextEditor: reduce complexity of bookmark requests
Since the book mark support is nowadays part of the text editor plugin we can directly access the bookmark manager from within the editor without the indirection over the TextEditorPluginPrivate. Change-Id: I5c04679d6583c06d615d489d3891431adcb64834 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "autocompleter.h"
|
||||
#include "basehoverhandler.h"
|
||||
#include "behaviorsettings.h"
|
||||
#include "bookmarkmanager.h"
|
||||
#include "circularclipboard.h"
|
||||
#include "circularclipboardassist.h"
|
||||
#include "codeassist/assistinterface.h"
|
||||
@@ -6429,6 +6430,9 @@ void TextEditorWidget::extraAreaContextMenuEvent(QContextMenuEvent *e)
|
||||
if (d->m_marksVisible) {
|
||||
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
|
||||
auto contextMenu = new QMenu(this);
|
||||
bookmarkManager().requestContextMenu(textDocument()->filePath(),
|
||||
cursor.blockNumber() + 1,
|
||||
contextMenu);
|
||||
emit markContextMenuRequested(this, cursor.blockNumber() + 1, contextMenu);
|
||||
if (!contextMenu->isEmpty())
|
||||
contextMenu->exec(e->globalPos());
|
||||
@@ -6621,13 +6625,12 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||
}
|
||||
}
|
||||
int line = n + 1;
|
||||
TextMarkRequestKind kind;
|
||||
if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
|
||||
kind = BookmarkRequest;
|
||||
else
|
||||
kind = BreakpointRequest;
|
||||
|
||||
emit markRequested(this, line, kind);
|
||||
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
|
||||
if (!textDocument()->isTemporary())
|
||||
bookmarkManager().toggleBookmark(textDocument()->filePath(), line);
|
||||
} else {
|
||||
emit markRequested(this, line, BreakpointRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -67,13 +67,7 @@ const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor"
|
||||
class TextEditorPluginPrivate : public QObject
|
||||
{
|
||||
public:
|
||||
TextEditorPluginPrivate();
|
||||
|
||||
void updateActions(bool enableToggle, int stateMask);
|
||||
void editorOpened(Core::IEditor *editor);
|
||||
void editorAboutToClose(Core::IEditor *editor);
|
||||
|
||||
void requestContextMenu(TextEditorWidget *widget, int lineNumber, QMenu *menu);
|
||||
|
||||
void extensionsInitialized();
|
||||
void updateSearchResultsFont(const FontSettings &);
|
||||
@@ -95,46 +89,6 @@ public:
|
||||
JsonEditorFactory jsonEditorFactory;
|
||||
};
|
||||
|
||||
TextEditorPluginPrivate::TextEditorPluginPrivate()
|
||||
{
|
||||
// EditorManager
|
||||
connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
|
||||
this, &TextEditorPluginPrivate::editorAboutToClose);
|
||||
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
||||
this, &TextEditorPluginPrivate::editorOpened);
|
||||
}
|
||||
|
||||
void TextEditorPluginPrivate::editorOpened(IEditor *editor)
|
||||
{
|
||||
if (auto widget = TextEditorWidget::fromEditor(editor)) {
|
||||
connect(widget, &TextEditorWidget::markRequested,
|
||||
this, [editor](TextEditorWidget *, int line, TextMarkRequestKind kind) {
|
||||
if (kind == BookmarkRequest && !editor->document()->isTemporary())
|
||||
bookmarkManager().toggleBookmark(editor->document()->filePath(), line);
|
||||
});
|
||||
|
||||
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
||||
this, &TextEditorPluginPrivate::requestContextMenu);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorPluginPrivate::editorAboutToClose(IEditor *editor)
|
||||
{
|
||||
if (auto widget = TextEditorWidget::fromEditor(editor)) {
|
||||
disconnect(widget, &TextEditorWidget::markContextMenuRequested,
|
||||
this, &TextEditorPluginPrivate::requestContextMenu);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorPluginPrivate::requestContextMenu(TextEditorWidget *widget,
|
||||
int lineNumber, QMenu *menu)
|
||||
{
|
||||
if (widget->textDocument()->isTemporary())
|
||||
return;
|
||||
|
||||
bookmarkManager().requestContextMenu(widget->textDocument()->filePath(), lineNumber, menu);
|
||||
}
|
||||
|
||||
class TextEditorPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Reference in New Issue
Block a user