mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 03:30:20 +00:00
Fix problem of saving pdf switches from thumbnail view in sidebar to contents view
Summary: When save/save as functions are called they internally call the openFile() function, in the open file function the side bar item is set to Table of Contents (ToC) item ``` if ( m_document->metaData( QStringLiteral("OpenTOC") ).toBool() && m_sidebar->isItemEnabled( m_toc ) && !m_sidebar->isCollapsed() && m_sidebar->currentItem() != m_toc ) { m_sidebar->setCurrentItem( m_toc, Sidebar::DoNotUncollapseIfCollapsed ); } ``` so I just store the sidebar's item before saving and then set this item back if changed. BUG: 389668 Reviewers: #okular Subscribers: aacid, okular-devel Tags: #okular Differential Revision: https://phabricator.kde.org/D14740
This commit is contained in:
parent
4f06f742f9
commit
5e622484c8
|
@ -17,6 +17,7 @@
|
|||
#include "../core/page.h"
|
||||
#include "../part.h"
|
||||
#include "../ui/toc.h"
|
||||
#include "../ui/sidebar.h"
|
||||
#include "../ui/pageview.h"
|
||||
|
||||
#include "../generators/poppler/config-okular-poppler.h"
|
||||
|
@ -95,6 +96,7 @@ class PartTest
|
|||
void test388288();
|
||||
void testSaveAs();
|
||||
void testSaveAs_data();
|
||||
void testSidebarItemAfterSaving();
|
||||
void testSaveAsUndoStackAnnotations();
|
||||
void testSaveAsUndoStackAnnotations_data();
|
||||
void testSaveAsUndoStackForms();
|
||||
|
@ -939,6 +941,23 @@ void PartTest::testSaveAs_data()
|
|||
QTest::newRow("jpg") << KDESRCDIR "data/potato.jpg" << "jpg" << false << true;
|
||||
}
|
||||
|
||||
void PartTest::testSidebarItemAfterSaving()
|
||||
{
|
||||
QVariantList dummyArgs;
|
||||
Okular::Part part(nullptr, nullptr, dummyArgs);
|
||||
QWidget *currentSidebarItem = part.m_sidebar->currentItem(); // thumbnails
|
||||
openDocument(&part, QStringLiteral(KDESRCDIR "data/tocreload.pdf"));
|
||||
// since it has TOC it changes to TOC
|
||||
QVERIFY(currentSidebarItem != part.m_sidebar->currentItem());
|
||||
// now change back to thumbnails
|
||||
part.m_sidebar->setCurrentItem(currentSidebarItem);
|
||||
|
||||
part.saveAs(QUrl::fromLocalFile(QStringLiteral(KDESRCDIR "data/tocreload.pdf")));
|
||||
|
||||
// Check it is still thumbnails after saving
|
||||
QCOMPARE(currentSidebarItem, part.m_sidebar->currentItem());
|
||||
}
|
||||
|
||||
void PartTest::testSaveAsUndoStackAnnotations()
|
||||
{
|
||||
QFETCH(QString, file);
|
||||
|
|
4
part.cpp
4
part.cpp
|
@ -2730,6 +2730,7 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
|
|||
// Make the generator use the new new file instead of the old one
|
||||
if ( m_document->canSwapBackingFile() && !m_documentOpenWithPassword )
|
||||
{
|
||||
QWidget *currentSidebarItem = m_sidebar->currentItem();
|
||||
// this calls openFile internally, which in turn actually calls
|
||||
// m_document->swapBackingFile() instead of the regular loadDocument
|
||||
if ( openUrl( saveUrl, true /* swapInsteadOfOpening */ ) )
|
||||
|
@ -2743,6 +2744,9 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
|
|||
{
|
||||
reloadedCorrectly = false;
|
||||
}
|
||||
|
||||
if ( m_sidebar->currentItem() != currentSidebarItem )
|
||||
m_sidebar->setCurrentItem( currentSidebarItem );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -11,11 +11,12 @@
|
|||
#define _SIDEBAR_H_
|
||||
|
||||
#include <qwidget.h>
|
||||
#include "okularpart_export.h"
|
||||
|
||||
class QIcon;
|
||||
class QListWidgetItem;
|
||||
|
||||
class Sidebar : public QWidget
|
||||
class OKULARPART_EXPORT Sidebar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue