Skip to content

Commit 0731ae5

Browse files
author
Adrià Arrufat
committed
Add button to open PDF with default viewer
1 parent 233ca8a commit 0731ae5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main.vala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class Pdftag : ApplicationWindow {
3434
private string date_format = "%Y-%m-%d";
3535

3636
private Button tag_btn;
37+
private Button view_btn;
38+
private AppInfo viewer;
3739

3840
public Pdftag (ref unowned string[] args) {
3941

@@ -217,6 +219,13 @@ public class Pdftag : ApplicationWindow {
217219
check.toggled.connect (on_toggled);
218220
grid.attach (this.check, 1, row, 1, 1);
219221

222+
/* view button */
223+
viewer = AppInfo.get_default_for_type ("image/pdf", true);
224+
var viewer_name = viewer.get_name ();
225+
this.view_btn = new Gtk.Button.with_label ("Open with " + viewer_name);
226+
this.view_btn.clicked.connect (view_document);
227+
grid.attach (view_btn, 3, row, 2, 1);
228+
220229
/* tag button */
221230
this.tag_btn = new Gtk.Button.with_label ("Tag");
222231
this.tag_btn.clicked.connect (write_information);
@@ -338,6 +347,20 @@ public class Pdftag : ApplicationWindow {
338347
}
339348
}
340349

350+
private void view_document () {
351+
if (this.pdf_file != null) {
352+
var pdf_list = new List<File> ();
353+
pdf_list.append (this.pdf_file);
354+
try {
355+
this.viewer.launch (pdf_list, null);
356+
} catch (Error e) {
357+
message (e.message);
358+
}
359+
} else {
360+
message ("No document was selected!");
361+
}
362+
}
363+
341364
private void write_information () {
342365
if (this.pdf_file != null) {
343366
this.document.title = this.title_entry.text;

0 commit comments

Comments
 (0)