Insert new bookmarks after the "current" bookmark

Makes it more useful as a navigation instrument. If new bookmarks are
always added to the end of the list, the "previous" bookmark will have
nothing to do with the context of the bookmark that was previously the
"current" one.

Task-number: QTCREATORBUG-20061
Change-Id: I0ea38391750371dec80872206d97f4934a37f7b4
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-04-30 15:55:38 +02:00
parent 658d5b5d2c
commit 70e27bb8ea
2 changed files with 20 additions and 9 deletions

View File

@@ -455,7 +455,10 @@ void BookmarkManager::toggleBookmark(const FileName &fileName, int lineNumber)
// Add a new bookmark if no bookmark existed on this line
Bookmark *mark = new Bookmark(lineNumber, this);
mark->updateFileName(fileName.toString());
addBookmark(mark);
const QModelIndex currentIndex = selectionModel()->currentIndex();
const int insertionIndex = currentIndex.isValid() ? currentIndex.row() + 1
: m_bookmarksList.size();
insertBookmark(insertionIndex, mark);
}
void BookmarkManager::updateBookmark(Bookmark *bookmark)
@@ -731,23 +734,30 @@ Bookmark *BookmarkManager::findBookmark(const FileName &filePath, int lineNumber
Utils::equal(&Bookmark::lineNumber, lineNumber));
}
/* Adds a bookmark to the internal data structures. The 'userset' parameter
* determines whether action status should be updated and whether the bookmarks
* should be saved to the session settings.
*/
void BookmarkManager::addBookmark(Bookmark *bookmark, bool userset)
void BookmarkManager::insertBookmark(int idx, Bookmark *bookmark, bool userset)
{
beginInsertRows(QModelIndex(), m_bookmarksList.size(), m_bookmarksList.size());
idx = qBound(0, idx, m_bookmarksList.size());
beginInsertRows(QModelIndex(), idx, idx);
m_bookmarksMap[FileName::fromString(bookmark->fileName())].append(bookmark);
m_bookmarksList.append(bookmark);
m_bookmarksList.insert(idx, bookmark);
endInsertRows();
if (userset) {
updateActionStatus();
saveBookmarks();
}
selectionModel()->setCurrentIndex(index(m_bookmarksList.size()-1 , 0, QModelIndex()), QItemSelectionModel::Select | QItemSelectionModel::Clear);
selectionModel()->setCurrentIndex(index(idx, 0, QModelIndex()),
QItemSelectionModel::Select | QItemSelectionModel::Clear);
}
/* Adds a bookmark to the internal data structures. The 'userset' parameter
* determines whether action status should be updated and whether the bookmarks
* should be saved to the session settings.
*/
void BookmarkManager::addBookmark(Bookmark *bookmark, bool userset)
{
insertBookmark(m_bookmarksList.size(), bookmark, userset);
}
/* Adds a new bookmark based on information parsed from the string. */

View File

@@ -110,6 +110,7 @@ private:
void documentPrevNext(bool next);
Bookmark *findBookmark(const Utils::FileName &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);