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;
|
using namespace Bookmarks::Internal;
|
||||||
|
|
||||||
Bookmark::Bookmark(const QString& fileName, int lineNumber, BookmarkManager *manager) :
|
Bookmark::Bookmark(int lineNumber, BookmarkManager *manager) :
|
||||||
TextMark(fileName, lineNumber),
|
TextMark(QString(), lineNumber),
|
||||||
m_manager(manager)
|
m_manager(manager)
|
||||||
{
|
{
|
||||||
setPriority(TextEditor::TextMark::NormalPriority);
|
setPriority(TextEditor::TextMark::NormalPriority);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class BookmarkManager;
|
|||||||
class Bookmark : public TextEditor::TextMark
|
class Bookmark : public TextEditor::TextMark
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Bookmark(const QString &fileName, int lineNumber, BookmarkManager *manager);
|
Bookmark(int lineNumber, BookmarkManager *manager);
|
||||||
|
|
||||||
void updateLineNumber(int lineNumber);
|
void updateLineNumber(int lineNumber);
|
||||||
void move(int line);
|
void move(int line);
|
||||||
|
|||||||
@@ -62,7 +62,6 @@
|
|||||||
Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*)
|
Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*)
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace TextEditor;
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -435,7 +434,7 @@ QMimeData *BookmarkManager::mimeData(const QModelIndexList &indexes) const
|
|||||||
|
|
||||||
void BookmarkManager::toggleBookmark(bool)
|
void BookmarkManager::toggleBookmark(bool)
|
||||||
{
|
{
|
||||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -444,7 +443,8 @@ void BookmarkManager::toggleBookmark(bool)
|
|||||||
|
|
||||||
void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber)
|
void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber)
|
||||||
{
|
{
|
||||||
const int editorLine = lineNumber;
|
if (lineNumber <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
// Remove any existing bookmark on this line
|
// Remove any existing bookmark on this line
|
||||||
if (Bookmark *mark = findBookmark(fileName, lineNumber)) {
|
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
|
// 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)
|
void BookmarkManager::updateBookmark(Bookmark *bookmark)
|
||||||
@@ -549,8 +551,11 @@ void BookmarkManager::prevInDocument()
|
|||||||
|
|
||||||
void BookmarkManager::documentPrevNext(bool next)
|
void BookmarkManager::documentPrevNext(bool next)
|
||||||
{
|
{
|
||||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
int editorLine = editor->currentLine();
|
const int editorLine = editor->currentLine();
|
||||||
|
if (editorLine <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
QFileInfo fi(editor->document()->filePath());
|
QFileInfo fi(editor->document()->filePath());
|
||||||
if (!m_bookmarksMap.contains(fi.path()))
|
if (!m_bookmarksMap.contains(fi.path()))
|
||||||
return;
|
return;
|
||||||
@@ -638,7 +643,7 @@ BookmarkManager::State BookmarkManager::state() const
|
|||||||
if (m_bookmarksMap.empty())
|
if (m_bookmarksMap.empty())
|
||||||
return NoBookMarks;
|
return NoBookMarks;
|
||||||
|
|
||||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return HasBookMarks;
|
return HasBookMarks;
|
||||||
|
|
||||||
@@ -790,7 +795,8 @@ void BookmarkManager::addBookmark(const QString &s)
|
|||||||
const QString ¬e = s.mid(index3 + 1);
|
const QString ¬e = s.mid(index3 + 1);
|
||||||
const int lineNumber = s.mid(index2 + 1, index3 - index2 - 1).toInt();
|
const int lineNumber = s.mid(index2 + 1, index3 - index2 - 1).toInt();
|
||||||
if (!filePath.isEmpty() && !findBookmark(filePath, lineNumber)) {
|
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);
|
b->setNote(note);
|
||||||
addBookmark(b, false);
|
addBookmark(b, false);
|
||||||
}
|
}
|
||||||
@@ -820,7 +826,7 @@ void BookmarkManager::saveBookmarks()
|
|||||||
SessionManager::setValue(QLatin1String("Bookmarks"), list);
|
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)
|
if (!mark)
|
||||||
return;
|
return;
|
||||||
@@ -842,20 +848,10 @@ void BookmarkManager::loadBookmarks()
|
|||||||
updateActionStatus();
|
updateActionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::handleBookmarkRequest(TextEditorWidget *widget, int line,
|
void BookmarkManager::handleBookmarkTooltipRequest(IEditor *editor, const QPoint &pos, int line)
|
||||||
TextMarkRequestKind kind)
|
|
||||||
{
|
{
|
||||||
if (kind == BookmarkRequest && widget->textDocument())
|
Bookmark *mark = findBookmark(editor->document()->filePath(), line);
|
||||||
toggleBookmark(widget->textDocument()->filePath(), line);
|
operateTooltip(editor->widget(), pos, mark);
|
||||||
}
|
|
||||||
|
|
||||||
void BookmarkManager::handleBookmarkTooltipRequest(TextEditorWidget *widget,
|
|
||||||
const QPoint &pos, int line)
|
|
||||||
{
|
|
||||||
if (widget->textDocument()) {
|
|
||||||
Bookmark *mark = findBookmark(widget->textDocument()->filePath(), line);
|
|
||||||
operateTooltip(widget, pos, mark);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BookmarkViewFactory
|
// BookmarkViewFactory
|
||||||
|
|||||||
@@ -32,11 +32,9 @@
|
|||||||
#define BOOKMARKMANAGER_H
|
#define BOOKMARKMANAGER_H
|
||||||
|
|
||||||
#include <utils/itemviews.h>
|
#include <utils/itemviews.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/inavigationwidgetfactory.h>
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
|
|
||||||
#include <texteditor/texteditor.h>
|
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QMultiMap>
|
#include <QMultiMap>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@@ -94,11 +92,7 @@ public:
|
|||||||
Note = Qt::UserRole + 4
|
Note = Qt::UserRole + 4
|
||||||
};
|
};
|
||||||
|
|
||||||
void handleBookmarkRequest(TextEditor::TextEditorWidget *widget, int line,
|
void handleBookmarkTooltipRequest(Core::IEditor *editor, const QPoint &pos, int line);
|
||||||
TextEditor::TextMarkRequestKind kind);
|
|
||||||
|
|
||||||
void handleBookmarkTooltipRequest(TextEditor::TextEditorWidget *widget,
|
|
||||||
const QPoint &pos, int line);
|
|
||||||
|
|
||||||
void toggleBookmark(bool);
|
void toggleBookmark(bool);
|
||||||
void toggleBookmark(const QString &fileName, int lineNumber);
|
void toggleBookmark(const QString &fileName, int lineNumber);
|
||||||
@@ -127,7 +121,7 @@ private:
|
|||||||
void addBookmark(const QString &s);
|
void addBookmark(const QString &s);
|
||||||
static QString bookmarkToString(const Bookmark *b);
|
static QString bookmarkToString(const Bookmark *b);
|
||||||
void saveBookmarks();
|
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 QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
|
||||||
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
|
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
|
||||||
|
|||||||
@@ -162,11 +162,18 @@ void BookmarksPlugin::updateActions(int state)
|
|||||||
void BookmarksPlugin::editorOpened(IEditor *editor)
|
void BookmarksPlugin::editorOpened(IEditor *editor)
|
||||||
{
|
{
|
||||||
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
|
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
|
||||||
connect(widget, &TextEditorWidget::markRequested,
|
connect(widget, &TextEditorWidget::markRequested, m_bookmarkManager,
|
||||||
m_bookmarkManager, &BookmarkManager::handleBookmarkRequest);
|
[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,
|
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
||||||
this, &BookmarksPlugin::requestContextMenu);
|
this, &BookmarksPlugin::requestContextMenu);
|
||||||
|
|||||||
Reference in New Issue
Block a user