mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
Add a way to rename the current page bookmark from the menu
Comes with some api additions to bookmarkmanager
This commit is contained in:
parent
fc58c9824f
commit
880dae2e19
|
@ -225,6 +225,25 @@ KBookmark::List BookmarkManager::bookmarks( const KUrl& url ) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KBookmark::List BookmarkManager::bookmarks() const
|
||||||
|
{
|
||||||
|
return bookmarks( d->url );
|
||||||
|
}
|
||||||
|
|
||||||
|
KBookmark BookmarkManager::bookmark( int page ) const
|
||||||
|
{
|
||||||
|
const KBookmark::List bmarks = bookmarks();
|
||||||
|
foreach( const KBookmark &bm, bmarks )
|
||||||
|
{
|
||||||
|
DocumentViewport vp( bm.url().htmlRef() );
|
||||||
|
if ( vp.isValid() && vp.pageNumber == page )
|
||||||
|
{
|
||||||
|
return bm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return KBookmark();
|
||||||
|
}
|
||||||
|
|
||||||
void BookmarkManager::save() const
|
void BookmarkManager::save() const
|
||||||
{
|
{
|
||||||
d->manager->emitChanged();
|
d->manager->emitChanged();
|
||||||
|
@ -334,6 +353,18 @@ void BookmarkManager::removeBookmark( int n )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarkManager::renameBookmark( KBookmark* bm, const QString& newName)
|
||||||
|
{
|
||||||
|
KBookmarkGroup thebg;
|
||||||
|
QHash<KUrl, QString>::iterator it = d->bookmarkFind( d->url, false, &thebg );
|
||||||
|
Q_ASSERT ( it != d->knownFiles.end() );
|
||||||
|
if ( it == d->knownFiles.end() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
bm->setFullText( newName );
|
||||||
|
d->manager->emitChanged( thebg );
|
||||||
|
}
|
||||||
|
|
||||||
int BookmarkManager::removeBookmark( const KUrl& referurl, const KBookmark& bm )
|
int BookmarkManager::removeBookmark( const KUrl& referurl, const KBookmark& bm )
|
||||||
{
|
{
|
||||||
if ( !referurl.isValid() || bm.isNull() || bm.isGroup() || bm.isSeparator() )
|
if ( !referurl.isValid() || bm.isNull() || bm.isGroup() || bm.isSeparator() )
|
||||||
|
|
|
@ -40,11 +40,24 @@ class OKULAR_EXPORT BookmarkManager : public QObject
|
||||||
* Returns the list of documents with bookmarks.
|
* Returns the list of documents with bookmarks.
|
||||||
*/
|
*/
|
||||||
KUrl::List files() const;
|
KUrl::List files() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of bookmarks for the specified @p url.
|
* Returns the list of bookmarks for the specified @p url.
|
||||||
*/
|
*/
|
||||||
KBookmark::List bookmarks( const KUrl& url ) const;
|
KBookmark::List bookmarks( const KUrl& url ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of bookmarks for document
|
||||||
|
* @since 0.14 (KDE 4.8)
|
||||||
|
*/
|
||||||
|
KBookmark::List bookmarks() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the bookmark for the given page of the document
|
||||||
|
* @since 0.14 (KDE 4.8)
|
||||||
|
*/
|
||||||
|
KBookmark bookmark( int page ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces to save the list of bookmarks.
|
* Forces to save the list of bookmarks.
|
||||||
*/
|
*/
|
||||||
|
@ -82,6 +95,12 @@ class OKULAR_EXPORT BookmarkManager : public QObject
|
||||||
*/
|
*/
|
||||||
void removeBookmarks( const KUrl& referurl, const KBookmark::List& list );
|
void removeBookmarks( const KUrl& referurl, const KBookmark::List& list );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the bookmark given bookmark of the document
|
||||||
|
* @since 0.14 (KDE 4.8)
|
||||||
|
*/
|
||||||
|
void renameBookmark( KBookmark* bm, const QString& newName );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given @p page is bookmarked.
|
* Returns whether the given @p page is bookmarked.
|
||||||
*/
|
*/
|
||||||
|
|
24
part.cpp
24
part.cpp
|
@ -41,6 +41,7 @@
|
||||||
#include <kstandardaction.h>
|
#include <kstandardaction.h>
|
||||||
#include <kpluginfactory.h>
|
#include <kpluginfactory.h>
|
||||||
#include <kfiledialog.h>
|
#include <kfiledialog.h>
|
||||||
|
#include <kinputdialog.h>
|
||||||
#include <kmessagebox.h>
|
#include <kmessagebox.h>
|
||||||
#include <knuminput.h>
|
#include <knuminput.h>
|
||||||
#include <kio/netaccess.h>
|
#include <kio/netaccess.h>
|
||||||
|
@ -457,6 +458,12 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
|
||||||
m_addBookmarkText = m_addBookmark->text();
|
m_addBookmarkText = m_addBookmark->text();
|
||||||
m_addBookmarkIcon = m_addBookmark->icon();
|
m_addBookmarkIcon = m_addBookmark->icon();
|
||||||
|
|
||||||
|
m_renameBookmark = ac->addAction("rename_bookmark");
|
||||||
|
m_renameBookmark->setText(i18n( "Rename Bookmark" ));
|
||||||
|
m_renameBookmark->setIcon(KIcon( "edit-rename" ));
|
||||||
|
m_renameBookmark->setWhatsThis( i18n( "Rename the current page bookmark" ) );
|
||||||
|
connect( m_renameBookmark, SIGNAL(triggered()), this, SLOT(slotRenameBookmark()) );
|
||||||
|
|
||||||
m_prevBookmark = ac->addAction("previous_bookmark");
|
m_prevBookmark = ac->addAction("previous_bookmark");
|
||||||
m_prevBookmark->setText(i18n( "Previous Bookmark" ));
|
m_prevBookmark->setText(i18n( "Previous Bookmark" ));
|
||||||
m_prevBookmark->setIcon(KIcon( "go-up-search" ));
|
m_prevBookmark->setIcon(KIcon( "go-up-search" ));
|
||||||
|
@ -1377,11 +1384,13 @@ void Part::updateBookmarksActions()
|
||||||
{
|
{
|
||||||
m_addBookmark->setText( i18n( "Remove Bookmark" ) );
|
m_addBookmark->setText( i18n( "Remove Bookmark" ) );
|
||||||
m_addBookmark->setIcon( KIcon( "edit-delete-bookmark" ) );
|
m_addBookmark->setIcon( KIcon( "edit-delete-bookmark" ) );
|
||||||
|
m_renameBookmark->setEnabled( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_addBookmark->setText( m_addBookmarkText );
|
m_addBookmark->setText( m_addBookmarkText );
|
||||||
m_addBookmark->setIcon( m_addBookmarkIcon );
|
m_addBookmark->setIcon( m_addBookmarkIcon );
|
||||||
|
m_renameBookmark->setEnabled( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1389,6 +1398,7 @@ void Part::updateBookmarksActions()
|
||||||
m_addBookmark->setEnabled( false );
|
m_addBookmark->setEnabled( false );
|
||||||
m_addBookmark->setText( m_addBookmarkText );
|
m_addBookmark->setText( m_addBookmarkText );
|
||||||
m_addBookmark->setIcon( m_addBookmarkIcon );
|
m_addBookmark->setIcon( m_addBookmarkIcon );
|
||||||
|
m_renameBookmark->setEnabled( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1531,6 +1541,20 @@ void Part::slotAddBookmark()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Part::slotRenameBookmark()
|
||||||
|
{
|
||||||
|
const uint current = m_document->currentPage();
|
||||||
|
Q_ASSERT(m_document->bookmarkManager()->isBookmarked( current ));
|
||||||
|
if ( m_document->bookmarkManager()->isBookmarked( current ) )
|
||||||
|
{
|
||||||
|
KBookmark bookmark = m_document->bookmarkManager()->bookmark( current );
|
||||||
|
const QString newName = KInputDialog::getText( i18n( "Rename Bookmark" ), i18n( "Enter the new name of the bookmark:" ), bookmark.fullText(), 0, widget());
|
||||||
|
if (!newName.isEmpty())
|
||||||
|
{
|
||||||
|
m_document->bookmarkManager()->renameBookmark(&bookmark, newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Part::slotPreviousBookmark()
|
void Part::slotPreviousBookmark()
|
||||||
{
|
{
|
||||||
|
|
2
part.h
2
part.h
|
@ -138,6 +138,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
|
||||||
void slotHistoryBack();
|
void slotHistoryBack();
|
||||||
void slotHistoryNext();
|
void slotHistoryNext();
|
||||||
void slotAddBookmark();
|
void slotAddBookmark();
|
||||||
|
void slotRenameBookmark();
|
||||||
void slotPreviousBookmark();
|
void slotPreviousBookmark();
|
||||||
void slotNextBookmark();
|
void slotNextBookmark();
|
||||||
void slotFindNext();
|
void slotFindNext();
|
||||||
|
@ -234,6 +235,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
|
||||||
KAction *m_historyBack;
|
KAction *m_historyBack;
|
||||||
KAction *m_historyNext;
|
KAction *m_historyNext;
|
||||||
KAction *m_addBookmark;
|
KAction *m_addBookmark;
|
||||||
|
KAction *m_renameBookmark;
|
||||||
KAction *m_prevBookmark;
|
KAction *m_prevBookmark;
|
||||||
KAction *m_nextBookmark;
|
KAction *m_nextBookmark;
|
||||||
KAction *m_copy;
|
KAction *m_copy;
|
||||||
|
|
3
part.rc
3
part.rc
|
@ -1,5 +1,5 @@
|
||||||
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
|
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
|
||||||
<kpartgui name="okular_part" version="31">
|
<kpartgui name="okular_part" version="32">
|
||||||
<MenuBar>
|
<MenuBar>
|
||||||
<Menu name="file"><text>&File</text>
|
<Menu name="file"><text>&File</text>
|
||||||
<Action name="get_new_stuff" group="file_open"/>
|
<Action name="get_new_stuff" group="file_open"/>
|
||||||
|
@ -58,6 +58,7 @@
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu name="bookmarks"><text>&Bookmarks</text>
|
<Menu name="bookmarks"><text>&Bookmarks</text>
|
||||||
<Action name="bookmark_add"/>
|
<Action name="bookmark_add"/>
|
||||||
|
<Action name="rename_bookmark"/>
|
||||||
<Action name="previous_bookmark"/>
|
<Action name="previous_bookmark"/>
|
||||||
<Action name="next_bookmark" />
|
<Action name="next_bookmark" />
|
||||||
<Separator/>
|
<Separator/>
|
||||||
|
|
Loading…
Reference in a new issue