diff options
author | hjk <hjk@qt.io> | 2023-09-22 18:05:03 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-09-28 11:03:02 +0000 |
commit | 963ff4381d5a3b2edb27c1d538299e23d15d8fa1 (patch) | |
tree | 50eea853ef50889b801e8e8b38a6a7ae9ce87bb7 /src/plugins/texteditor/bookmarkmanager.h | |
parent | 776c8670d7e8124c8b78dc505b85a94d51372e54 (diff) |
Bookmarks: Merge plugin into TextEditor
Change-Id: I4c9438f3596daff2c18680a731764bf5010e1e25
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/bookmarkmanager.h')
-rw-r--r-- | src/plugins/texteditor/bookmarkmanager.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/plugins/texteditor/bookmarkmanager.h b/src/plugins/texteditor/bookmarkmanager.h new file mode 100644 index 00000000000..4df91094e3d --- /dev/null +++ b/src/plugins/texteditor/bookmarkmanager.h @@ -0,0 +1,113 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include <utils/itemviews.h> +#include <utils/fileutils.h> +#include <coreplugin/inavigationwidgetfactory.h> + +#include <QAbstractItemModel> +#include <QMultiMap> +#include <QList> +#include <QListView> +#include <QPixmap> +#include <QStyledItemDelegate> + +namespace Core { class IContext; } + +namespace TextEditor::Internal { + +class Bookmark; +class BookmarksPlugin; +class BookmarkContext; + +class BookmarkManager final : public QAbstractItemModel +{ + Q_OBJECT + +public: + BookmarkManager(); + ~BookmarkManager() final; + + void updateBookmark(Bookmark *bookmark); + void updateBookmarkFileName(Bookmark *bookmark, const Utils::FilePath &oldFilePath); + void deleteBookmark(Bookmark *bookmark); // Does not remove the mark + void removeAllBookmarks(); + Bookmark *bookmarkForIndex(const QModelIndex &index) const; + + enum State { NoBookMarks, HasBookMarks, HasBookmarksInDocument }; + State state() const; + + // Model stuff + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const final; + QModelIndex parent(const QModelIndex &child) const final; + int rowCount(const QModelIndex &parent = QModelIndex()) const final; + int columnCount(const QModelIndex &parent = QModelIndex()) const final; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final; + Qt::ItemFlags flags(const QModelIndex &index) const final; + + Qt::DropActions supportedDragActions() const final; + QStringList mimeTypes() const final; + QMimeData *mimeData(const QModelIndexList &indexes) const final; + + // this QItemSelectionModel is shared by all views + QItemSelectionModel *selectionModel() const; + + bool hasBookmarkInPosition(const Utils::FilePath &fileName, int lineNumber); + + enum Roles { + Filename = Qt::UserRole, + LineNumber = Qt::UserRole + 1, + Directory = Qt::UserRole + 2, + LineText = Qt::UserRole + 3, + Note = Qt::UserRole + 4 + }; + + void toggleBookmark(const Utils::FilePath &fileName, int lineNumber); + void nextInDocument(); + void prevInDocument(); + void next(); + void prev(); + void moveUp(); + void moveDown(); + void edit(); + void editByFileAndLine(const Utils::FilePath &fileName, int lineNumber); + bool gotoBookmark(const Bookmark *bookmark) const; + +signals: + void updateActions(bool enableToggle, int state); + void currentIndexChanged(const QModelIndex &); + +private: + void updateActionStatus(); + void loadBookmarks(); + bool isAtCurrentBookmark() const; + + void documentPrevNext(bool next); + + Bookmark *findBookmark(const Utils::FilePath &filePath, int lineNumber); + void insertBookmark(int index, Bookmark *bookmark, bool userset = true); + void addBookmark(Bookmark *bookmark, bool userset = true); + void addBookmark(const QString &s); + static QString bookmarkToString(const Bookmark *b); + void saveBookmarks(); + + QMap<Utils::FilePath, QVector<Bookmark *>> m_bookmarksMap; + + QList<Bookmark *> m_bookmarksList; + QItemSelectionModel *m_selectionModel; +}; + +class BookmarkViewFactory : public Core::INavigationWidgetFactory +{ +public: + BookmarkViewFactory(BookmarkManager *bm); + +private: + Core::NavigationView createWidget() override; + + BookmarkManager *m_manager; +}; + +} // Bookmarks::Internal |