After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741780 - Hide "Contents" tab when no TOC is available
Hide "Contents" tab when no TOC is available
Status: RESOLVED FIXED
Product: gnome-documents
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME documents maintainer(s)
GNOME documents maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-12-19 19:26 UTC by Bastien Nocera
Modified: 2015-04-09 08:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to hide the contents tab when there is no TOC to show (1.98 KB, patch)
2015-03-02 22:00 UTC, Muhammet Kara
none Details | Review
Patch to hide TOC tab when there is no TOC (2.13 KB, patch)
2015-04-07 18:04 UTC, Muhammet Kara
none Details | Review
Patch to hide TOC tab when there is no TOC to be displayed (2.12 KB, patch)
2015-04-08 13:25 UTC, Muhammet Kara
committed Details | Review
places-links: Add the placeholer text for PostScript files (1.04 KB, patch)
2015-04-09 08:03 UTC, Debarshi Ray
committed Details | Review

Description Bastien Nocera 2014-12-19 19:26:18 UTC
This is easily reproducible for CBZ/CBR files in gnome-books, but I would expect a number of PDFs not to have TOCs, in which case the "Contents" tab accessible in the preview should be hidden.
Comment 1 Muhammet Kara 2015-03-02 22:00:28 UTC
Created attachment 298349 [details] [review]
Patch to hide the contents tab when there is no TOC to show

I used evince's has_document_links() method to check if there is a TOC available.
Comment 2 Debarshi Ray 2015-03-09 14:20:14 UTC
Review of attachment 298349 [details] [review]:

Thanks for the patch. It is mostly correct, except for a corner case.

::: src/places.js
@@ +64,3 @@
         header.set_custom_title(switcher);
 
+        //Check if the document has table of contents (TOC)

This comment is not needed because it is quite obvious from reading the code. However, it would be nice to have a comment below.

@@ +66,3 @@
+        //Check if the document has table of contents (TOC)
+        let doc = this._model.get_document();
+        let docHasLinks = doc.has_document_links();

The has_document_links method is only available if a EvDocument implements the EvDocumentLinks interface. Documents representing a PS file don't, which leads to this backtrace:

(gnome-documents:709): Gjs-WARNING **: JS ERROR: TypeError: doc.has_document_links is not a function
PlacesDialog<._createWindow@/opt/share/gnome-documents/js/places.js:68
wrapper@resource:///org/gnome/gjs/modules/lang.js:169
PlacesDialog<._init@/opt/share/gnome-documents/js/places.js:41
wrapper@resource:///org/gnome/gjs/modules/lang.js:169
_Base.prototype._construct@resource:///org/gnome/gjs/modules/lang.js:110
Class.prototype._construct/newClass@resource:///org/gnome/gjs/modules/lang.js:204
PreviewView<._showPlaces@/opt/share/gnome-documents/js/preview.js:206
wrapper@resource:///org/gnome/gjs/modules/lang.js:169
start@/opt/share/gnome-documents/js/main.js:30
@<command line>:1

As far as I know, there is no direct equivalent of EV_IS_DOCUMENT_LINKS in gjs. Therefore, you need to enclose this method call in a try / catch block and handle TypeError. It would be nice to have a comment explaining this. You can find a similar (but not exact) example in commit 3c5418c

@@ +67,3 @@
+        let doc = this._model.get_document();
+        let docHasLinks = doc.has_document_links();
+        //If there is no TOC, then don't show the "Contents" tab

This is also obvious, so the comment is not necessary.
Comment 3 Debarshi Ray 2015-03-09 14:25:27 UTC
I noticed a bug in gd_places_links_document_changed_cb. It short circuits the function if EV_IS_DOCUMENT_LINKS is false. Due to this the contents tab for PostScript files does not have the "No table of contents" place holder text. We should remove the check because it is duplicates a more correct version of it that exists a few lines below.

Now that we are going to hide the contents tab for these cases, this is mostly theoretical, but it would still be good to fix this in a separate patch, in case we ever use this code later.
Comment 4 Muhammet Kara 2015-04-07 18:04:37 UTC
Created attachment 301086 [details] [review]
Patch to hide TOC tab when there is no TOC
Comment 5 Debarshi Ray 2015-04-08 12:28:15 UTC
Review of attachment 301086 [details] [review]:

Thanks, Kara. The code looks good now. A few minor issues below:

::: src/places.js
@@ +74,3 @@
+        } catch (e) {
+        }
+

Trailing whitespace alert.

@@ +77,3 @@
+        if (docHasLinks)
+        {
+            this._linksPage = new GdPrivate.PlacesLinks();

The opening brace should be on the previous line. See the rest of the file.
Comment 6 Muhammet Kara 2015-04-08 13:25:56 UTC
Created attachment 301134 [details] [review]
Patch to hide TOC tab when there is no TOC to be displayed

I have corrected the opening brace but couldn't spot the trailing whitespace.
Comment 7 Debarshi Ray 2015-04-09 07:47:21 UTC
Review of attachment 301134 [details] [review]:

Perfect.
Comment 8 Debarshi Ray 2015-04-09 08:02:36 UTC
We now need to sort out the lone button in the stack switcher - it should be turned into a label. We can do that either in gtk+ or in the application itself. Let's use a separate bug for that.
Comment 9 Debarshi Ray 2015-04-09 08:03:31 UTC
Created attachment 301187 [details] [review]
places-links: Add the placeholer text for PostScript files

Addresses the issue in comment 3