forked from qt-creator/qt-creator
BookMarks: Fix line contents display
This really needs the dynamic type for the update. Also using the IEditor interface is sufficient for most parts. Change-Id: Ic9806f39077065c43b6325b2345ef5d8bab4ff34 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -32,11 +32,9 @@
|
||||
#define BOOKMARKMANAGER_H
|
||||
|
||||
#include <utils/itemviews.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/inavigationwidgetfactory.h>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QMultiMap>
|
||||
#include <QList>
|
||||
@@ -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<QString, Bookmark *> FileNameBookmarksMap;
|
||||
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
|
||||
|
||||
@@ -162,11 +162,18 @@ void BookmarksPlugin::updateActions(int state)
|
||||
void BookmarksPlugin::editorOpened(IEditor *editor)
|
||||
{
|
||||
if (auto widget = qobject_cast<TextEditorWidget *>(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);
|
||||
|
||||
Reference in New Issue
Block a user