Commit 96b495e4 authored by dt's avatar dt
Browse files

On jumping to invalid bookmarks, delete them.

For next/prev try the next/prev one then.
parent a2bfa610
......@@ -279,7 +279,10 @@ void BookmarkView::setModel(QAbstractItemModel *model)
void BookmarkView::gotoBookmark(const QModelIndex &index)
{
static_cast<BookmarkManager *>(model())->gotoBookmark(index);
BookmarkManager *bm = static_cast<BookmarkManager *>(model());
Bookmark *bk = bm->bookmarkForIndex(index);
if (!bm->gotoBookmark(bk))
bm->removeBookmark(bk);
}
////
......@@ -479,15 +482,14 @@ Bookmark *BookmarkManager::bookmarkForIndex(QModelIndex index)
return m_bookmarksList.at(index.row());
}
void BookmarkManager::gotoBookmark(const QModelIndex &idx)
{
gotoBookmark(m_bookmarksList.at(idx.row()));
}
void BookmarkManager::gotoBookmark(Bookmark* bookmark)
bool BookmarkManager::gotoBookmark(Bookmark* bookmark)
{
TextEditor::BaseTextEditor::openEditorAt(bookmark->filePath(),
bookmark->lineNumber());
if (!TextEditor::BaseTextEditor::openEditorAt(bookmark->filePath(), bookmark->lineNumber())) {
// Could not open editor
return false;
}
return true;
}
void BookmarkManager::nextInDocument()
......@@ -546,12 +548,22 @@ void BookmarkManager::next()
QModelIndex current = selectionModel()->currentIndex();
if (!current.isValid())
return;
int row = current.row() + 1;
if (row == m_bookmarksList.size())
row = 0;
QModelIndex newIndex = current.sibling(row, current.column());
selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select | QItemSelectionModel::Clear);
gotoBookmark(newIndex);
int row = current.row();
++row;
while (true) {
if (row == m_bookmarksList.size())
row = 0;
Bookmark *bk = m_bookmarksList.at(row);
if (gotoBookmark(bk)) {
QModelIndex newIndex = current.sibling(row, current.column());
selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select | QItemSelectionModel::Clear);
return;
}
removeBookmark(bk);
if (m_bookmarksList.isEmpty()) // No bookmarks anymore ...
return;
}
}
void BookmarkManager::prev()
......@@ -559,13 +571,22 @@ void BookmarkManager::prev()
QModelIndex current = selectionModel()->currentIndex();
if (!current.isValid())
return;
int row = current.row();
if (row == 0)
row = m_bookmarksList.size();
--row;
QModelIndex newIndex = current.sibling(row, current.column());
selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select | QItemSelectionModel::Clear);
gotoBookmark(newIndex);
while (true) {
if (row == 0)
row = m_bookmarksList.size();
--row;
Bookmark *bk = m_bookmarksList.at(row);
if (gotoBookmark(bk)) {
QModelIndex newIndex = current.sibling(row, current.column());
selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select | QItemSelectionModel::Clear);
return;
}
removeBookmark(bk);
if (m_bookmarksList.isEmpty())
return;
}
}
TextEditor::ITextEditor *BookmarkManager::currentTextEditor() const
......
......@@ -80,8 +80,6 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void gotoBookmark(const QModelIndex &);
// this QItemSelectionModel is shared by all views
QItemSelectionModel *selectionModel() const;
......@@ -101,6 +99,7 @@ public slots:
void prev();
void moveUp();
void moveDown();
bool gotoBookmark(Bookmark *bookmark);
signals:
void updateActions(int state);
......@@ -108,7 +107,6 @@ signals:
private slots:
void updateActionStatus();
void gotoBookmark(Bookmark *bookmark);
void loadBookmarks();
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment