diff --git a/src/plugins/bookmarks/bookmark.cpp b/src/plugins/bookmarks/bookmark.cpp index ae117f9c443..7d1ce73c6c2 100644 --- a/src/plugins/bookmarks/bookmark.cpp +++ b/src/plugins/bookmarks/bookmark.cpp @@ -37,8 +37,8 @@ using namespace Bookmarks::Internal; -Bookmark::Bookmark(const QString& fileName, int lineNumber, BookmarkManager *manager) : - TextMark(fileName, lineNumber), +Bookmark::Bookmark(int lineNumber, BookmarkManager *manager) : + TextMark(QString(), lineNumber), m_manager(manager) { setPriority(TextEditor::TextMark::NormalPriority); diff --git a/src/plugins/bookmarks/bookmark.h b/src/plugins/bookmarks/bookmark.h index 57a8f8edcda..c464b9bb375 100644 --- a/src/plugins/bookmarks/bookmark.h +++ b/src/plugins/bookmarks/bookmark.h @@ -41,7 +41,7 @@ class BookmarkManager; class Bookmark : public TextEditor::TextMark { public: - Bookmark(const QString &fileName, int lineNumber, BookmarkManager *manager); + Bookmark(int lineNumber, BookmarkManager *manager); void updateLineNumber(int lineNumber); void move(int line); diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index 03107cc1080..e6430e9b1f5 100644 --- a/src/plugins/bookmarks/bookmarkmanager.cpp +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -62,7 +62,6 @@ Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*) using namespace ProjectExplorer; -using namespace TextEditor; using namespace Core; using namespace Utils; @@ -435,7 +434,7 @@ QMimeData *BookmarkManager::mimeData(const QModelIndexList &indexes) const void BookmarkManager::toggleBookmark(bool) { - BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); + IEditor *editor = EditorManager::currentEditor(); if (!editor) return; @@ -444,7 +443,8 @@ void BookmarkManager::toggleBookmark(bool) void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber) { - const int editorLine = lineNumber; + if (lineNumber <= 0) + return; // Remove any existing bookmark on this line if (Bookmark *mark = findBookmark(fileName, lineNumber)) { @@ -454,7 +454,9 @@ void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber) } // Add a new bookmark if no bookmark existed on this line - addBookmark(new Bookmark(fileName, editorLine, this)); + Bookmark *mark = new Bookmark(lineNumber, this); + mark->updateFileName(fileName); + addBookmark(mark); } void BookmarkManager::updateBookmark(Bookmark *bookmark) @@ -549,8 +551,11 @@ void BookmarkManager::prevInDocument() void BookmarkManager::documentPrevNext(bool next) { - BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); - int editorLine = editor->currentLine(); + IEditor *editor = EditorManager::currentEditor(); + const int editorLine = editor->currentLine(); + if (editorLine <= 0) + return; + QFileInfo fi(editor->document()->filePath()); if (!m_bookmarksMap.contains(fi.path())) return; @@ -638,7 +643,7 @@ BookmarkManager::State BookmarkManager::state() const if (m_bookmarksMap.empty()) return NoBookMarks; - BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); + IEditor *editor = EditorManager::currentEditor(); if (!editor) return HasBookMarks; @@ -790,7 +795,8 @@ void BookmarkManager::addBookmark(const QString &s) const QString ¬e = s.mid(index3 + 1); const int lineNumber = s.mid(index2 + 1, index3 - index2 - 1).toInt(); if (!filePath.isEmpty() && !findBookmark(filePath, lineNumber)) { - Bookmark *b = new Bookmark(filePath, lineNumber, this); + Bookmark *b = new Bookmark(lineNumber, this); + b->updateFileName(filePath); b->setNote(note); addBookmark(b, false); } @@ -820,7 +826,7 @@ void BookmarkManager::saveBookmarks() SessionManager::setValue(QLatin1String("Bookmarks"), list); } -void BookmarkManager::operateTooltip(TextEditorWidget *widget, const QPoint &pos, Bookmark *mark) +void BookmarkManager::operateTooltip(QWidget *widget, const QPoint &pos, Bookmark *mark) { if (!mark) return; @@ -842,20 +848,10 @@ void BookmarkManager::loadBookmarks() updateActionStatus(); } -void BookmarkManager::handleBookmarkRequest(TextEditorWidget *widget, int line, - TextMarkRequestKind kind) +void BookmarkManager::handleBookmarkTooltipRequest(IEditor *editor, const QPoint &pos, int line) { - if (kind == BookmarkRequest && widget->textDocument()) - toggleBookmark(widget->textDocument()->filePath(), line); -} - -void BookmarkManager::handleBookmarkTooltipRequest(TextEditorWidget *widget, - const QPoint &pos, int line) -{ - if (widget->textDocument()) { - Bookmark *mark = findBookmark(widget->textDocument()->filePath(), line); - operateTooltip(widget, pos, mark); - } + Bookmark *mark = findBookmark(editor->document()->filePath(), line); + operateTooltip(editor->widget(), pos, mark); } // BookmarkViewFactory diff --git a/src/plugins/bookmarks/bookmarkmanager.h b/src/plugins/bookmarks/bookmarkmanager.h index 4fabb4e7a37..317776ba4a2 100644 --- a/src/plugins/bookmarks/bookmarkmanager.h +++ b/src/plugins/bookmarks/bookmarkmanager.h @@ -32,11 +32,9 @@ #define BOOKMARKMANAGER_H #include -#include +#include #include -#include - #include #include #include @@ -94,11 +92,7 @@ public: Note = Qt::UserRole + 4 }; - void handleBookmarkRequest(TextEditor::TextEditorWidget *widget, int line, - TextEditor::TextMarkRequestKind kind); - - void handleBookmarkTooltipRequest(TextEditor::TextEditorWidget *widget, - const QPoint &pos, int line); + void handleBookmarkTooltipRequest(Core::IEditor *editor, const QPoint &pos, int line); void toggleBookmark(bool); void toggleBookmark(const QString &fileName, int lineNumber); @@ -127,7 +121,7 @@ private: void addBookmark(const QString &s); static QString bookmarkToString(const Bookmark *b); void saveBookmarks(); - void operateTooltip(TextEditor::TextEditorWidget *widget, const QPoint &pos, Bookmark *mark); + void operateTooltip(QWidget *widget, const QPoint &pos, Bookmark *mark); typedef QMultiMap FileNameBookmarksMap; typedef QMap DirectoryFileBookmarksMap; diff --git a/src/plugins/bookmarks/bookmarksplugin.cpp b/src/plugins/bookmarks/bookmarksplugin.cpp index f95f39c348d..9a5a5f071f8 100644 --- a/src/plugins/bookmarks/bookmarksplugin.cpp +++ b/src/plugins/bookmarks/bookmarksplugin.cpp @@ -162,11 +162,18 @@ void BookmarksPlugin::updateActions(int state) void BookmarksPlugin::editorOpened(IEditor *editor) { if (auto widget = qobject_cast(editor->widget())) { - connect(widget, &TextEditorWidget::markRequested, - m_bookmarkManager, &BookmarkManager::handleBookmarkRequest); + connect(widget, &TextEditorWidget::markRequested, m_bookmarkManager, + [this, editor](TextEditorWidget *, int line, TextMarkRequestKind kind) { + if (kind == BookmarkRequest && editor->document()) + m_bookmarkManager->toggleBookmark(editor->document()->filePath(), line); + }); - connect(widget, &TextEditorWidget::markTooltipRequested, - m_bookmarkManager, &BookmarkManager::handleBookmarkTooltipRequest); + + connect(widget, &TextEditorWidget::markTooltipRequested, m_bookmarkManager, + [this, editor](TextEditorWidget *, const QPoint &pos, int line) { + if (editor->document()) + m_bookmarkManager->handleBookmarkTooltipRequest(editor, pos, line); + }); connect(widget, &TextEditorWidget::markContextMenuRequested, this, &BookmarksPlugin::requestContextMenu);