[okular] /: Add action in Edit menu to select the text on current page

Albert Astals Cid null at kde.org
Mon Apr 22 00:19:04 BST 2019


Git commit f788b5a384b5445bd08c775e51e4041ca7045da2 by Albert Astals Cid, on behalf of Shubham Jangra.
Committed on 21/04/2019 at 23:11.
Pushed by aacid into branch 'master'.

Add action in Edit menu to select the text on current page

BUG: 358868

Test Plan: Click on "Select All Text on Current Page" entry in Edit menu to select the entire page. The selected text can then be copied via Edit menu item "Copy"

Reviewers: aacid, #vdg, ngraham

Reviewed By: #vdg, ngraham

Subscribers: yurchor, michaelweghorn, kde-doc-english, davidhurka, abetts, loh.tar, alexde, ngraham, okular-devel

Tags: #okular, #documentation

Differential Revision: https://phabricator.kde.org/D18744

M  +15   -0    doc/index.docbook
M  +9    -0    part.cpp
M  +1    -0    part.h
M  +2    -1    part.rc
M  +15   -0    ui/pageview.cpp
M  +2    -0    ui/pageview.h

https://commits.kde.org/okular/f788b5a384b5445bd08c775e51e4041ca7045da2

diff --git a/doc/index.docbook b/doc/index.docbook
index 8b83b422c..886e59365 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -1284,6 +1284,21 @@ Context menu actions like Rename Bookmarks etc.)
 				</varlistentry>
 			</variablelist>
 
+			<variablelist>
+				<varlistentry>
+					<term>
+						<menuchoice>
+							<guimenu>Edit</guimenu>
+							<guimenuitem>Select All Text on Current Page</guimenuitem>
+						</menuchoice>
+					</term>
+					<listitem>
+						<para><action>Selects</action> all the text (if the document provides it) of the current page.
+                        </para>
+					</listitem>
+				</varlistentry>
+			</variablelist>
+
 			<variablelist>
 				<varlistentry>
 					<term>
diff --git a/part.cpp b/part.cpp
index 869ee8a40..c831f8793 100644
--- a/part.cpp
+++ b/part.cpp
@@ -720,6 +720,7 @@ void Part::setupViewerActions()
     m_copy = nullptr;
 
     m_selectAll = nullptr;
+    m_selectCurrentPage = nullptr;
 
     // Find and other actions
     m_find = KStandardAction::find( this, SLOT(slotShowFindBar()), ac );
@@ -843,6 +844,12 @@ void Part::setupActions()
 
     m_selectAll = KStandardAction::selectAll( m_pageView, SLOT(selectAll()), ac );
 
+    // Setup select all action for the current page
+    m_selectCurrentPage = ac->addAction(QStringLiteral("edit_select_all_current_page"));
+    m_selectCurrentPage->setText(i18n("Select All Text on Current Page"));
+    connect( m_selectCurrentPage, &QAction::triggered, m_pageView, &PageView::slotSelectPage );
+    m_selectCurrentPage->setEnabled( false );
+
     m_save = KStandardAction::save( this, [this] { saveFile(); }, ac );
     m_save->setEnabled( false );
 
@@ -2146,6 +2153,7 @@ void Part::updateViewActions()
         m_reload->setEnabled( true );
         if (m_copy) m_copy->setEnabled( true );
         if (m_selectAll) m_selectAll->setEnabled( true );
+        if (m_selectCurrentPage) m_selectCurrentPage->setEnabled( true );
     }
     else
     {
@@ -2159,6 +2167,7 @@ void Part::updateViewActions()
         m_reload->setEnabled( false );
         if (m_copy) m_copy->setEnabled( false );
         if (m_selectAll) m_selectAll->setEnabled( false );
+        if (m_selectCurrentPage) m_selectCurrentPage->setEnabled( false );
     }
 
     if ( factory() )
diff --git a/part.h b/part.h
index 2954e45d6..3cfc5a31d 100644
--- a/part.h
+++ b/part.h
@@ -360,6 +360,7 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
         QAction *m_nextBookmark;
         QAction *m_copy;
         QAction *m_selectAll;
+        QAction *m_selectCurrentPage;
         QAction *m_find;
         QAction *m_findNext;
         QAction *m_findPrev;
diff --git a/part.rc b/part.rc
index c8dc309a0..bf15cac50 100644
--- a/part.rc
+++ b/part.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="okular_part" version="39">
+<kpartgui name="okular_part" version="40">
 <MenuBar>
   <Menu name="file"><text>&File</text>
     <Action name="get_new_stuff" group="file_open"/>
@@ -21,6 +21,7 @@
     <Action name="edit_copy"/>
     <Separator/>
     <Action name="edit_select_all"/>
+    <Action name="edit_select_all_current_page"/>
     <Separator/>
     <Action name="edit_find"/>
     <Action name="edit_find_next"/>
diff --git a/ui/pageview.cpp b/ui/pageview.cpp
index 6369c87e5..59f9565e5 100644
--- a/ui/pageview.cpp
+++ b/ui/pageview.cpp
@@ -5538,6 +5538,21 @@ void PageView::slotFitWindowToPage()
     emit fitWindowToPage( viewportSize, pageSize );
 }
 
+void PageView::slotSelectPage()
+{
+    textSelectionClear();
+    const int currentPage = d->document->viewport().pageNumber;
+    PageViewItem *item = d->items.at( currentPage );
+
+    if ( item )
+    {
+        Okular::RegularAreaRect * area = textSelectionForItem( item );
+        const QString text = item->page()->text( area );
+        d->pagesWithTextSelection.insert( currentPage );
+        d->document->setPageTextSelection( currentPage, area, palette().color( QPalette::Active, QPalette::Highlight ) );
+    }
+}
+
 void PageView::highlightSignatureFormWidget( const Okular::FormFieldSignature *form )
 {
     QVector< PageViewItem * >::const_iterator dIt = d->items.constBegin(), dEnd = d->items.constEnd();
diff --git a/ui/pageview.h b/ui/pageview.h
index 4af4333d9..a892a5bb0 100644
--- a/ui/pageview.h
+++ b/ui/pageview.h
@@ -130,6 +130,8 @@ Q_OBJECT
         void slotToggleChangeColors();
         void slotSetChangeColors(bool active);
 
+        void slotSelectPage();
+
     Q_SIGNALS:
         void rightClick( const Okular::Page *, const QPoint & );
         void mouseBackButtonClick();


More information about the kde-doc-english mailing list