diff --git a/core/bookmarkmanager.cpp b/core/bookmarkmanager.cpp index d63ae75d7..fec608ff2 100644 --- a/core/bookmarkmanager.cpp +++ b/core/bookmarkmanager.cpp @@ -37,12 +37,27 @@ class OkularBookmarkAction : public KBookmarkAction public: OkularBookmarkAction( const Okular::DocumentViewport& vp, const KBookmark& bk, KBookmarkOwner* owner, QObject *parent ) : KBookmarkAction( bk, owner, parent ) + , m_pageNumber( vp.pageNumber + 1 ) { if ( vp.isValid() ) setText( QString::number( vp.pageNumber + 1 ) + " - " + text() ); } + + inline int pageNumber() const + { + return m_pageNumber; + } + + private: + const int m_pageNumber; }; +inline bool okularBookmarkActionLessThan( QAction * a1, QAction * a2 ) +{ + return static_cast< OkularBookmarkAction * >( a1 )->pageNumber() + < static_cast< OkularBookmarkAction * >( a2 )->pageNumber(); +} + class BookmarkManager::Private : public KBookmarkOwner { public: @@ -356,6 +371,7 @@ QList< QAction * > BookmarkManager::actionsForUrl( const KUrl& url ) const } break; } + qSort( ret.begin(), ret.end(), okularBookmarkActionLessThan ); return ret; } diff --git a/ui/bookmarklist.cpp b/ui/bookmarklist.cpp index dd88e6b2c..7f4363bc9 100644 --- a/ui/bookmarklist.cpp +++ b/ui/bookmarklist.cpp @@ -351,6 +351,8 @@ void BookmarkList::selectiveUrlUpdate( const KUrl& url, QTreeWidgetItem*& item ) else { const QString fileString = url.isLocalFile() ? url.path() : url.prettyUrl(); + bool fileitem_created = false; + if ( item ) { for ( int i = item->childCount() - 1; i >= 0; --i ) @@ -363,6 +365,7 @@ void BookmarkList::selectiveUrlUpdate( const KUrl& url, QTreeWidgetItem*& item ) item = new QTreeWidgetItem( m_tree, FileItemType ); item->setText( 0, fileString ); item->setData( 0, UrlRole, qVariantFromValue( url ) ); + fileitem_created = true; } if ( m_document->isOpened() && url == m_document->currentDocument() ) { @@ -374,6 +377,13 @@ void BookmarkList::selectiveUrlUpdate( const KUrl& url, QTreeWidgetItem*& item ) { item->setToolTip( 0, i18ncp( "%1 is the file name", "%1\n\nOne bookmark", "%1\n\n%2 bookmarks", fileString, item->childCount() ) ); } + if ( fileitem_created ) + { + // we need to sort also the parent of the new file item, + // so it can be properly shown in the correct place + m_tree->invisibleRootItem()->sortChildren( 0, Qt::AscendingOrder ); + } + item->sortChildren( 0, Qt::AscendingOrder ); } connect( m_tree, SIGNAL( itemChanged( QTreeWidgetItem *, int ) ), this, SLOT( slotChanged( QTreeWidgetItem * ) ) );