@@ -49,12 +49,13 @@ def __init__(self):
49
49
self .args = argparse .ArgumentParser (prog = 'devdocs-desktop' )
50
50
self .args .add_argument ('s' , metavar = 'STR' , help = 'the string to search' , nargs = '?' , default = '' )
51
51
52
- self .app_url = 'https://devdocs.io'
53
- self .search = self .args .parse_args ().s .strip ()
54
- self .filter = ''
55
- self .options = self .read_settings_json ('cookies' )
56
- self .prefs = self .read_settings_json ('prefs' )
57
- self .globals = Gtk .Settings .get_default ()
52
+ self .app_url = 'https://devdocs.io'
53
+ self .search = self .args .parse_args ().s .strip ()
54
+ self .filter = ''
55
+ self .open_link = False
56
+ self .options = self .read_settings_json ('cookies' )
57
+ self .prefs = self .read_settings_json ('prefs' )
58
+ self .globals = Gtk .Settings .get_default ()
58
59
59
60
self .main = Gtk .Builder ()
60
61
self .main .add_from_file (self .file_path ('ui/main.ui' ))
@@ -424,8 +425,11 @@ def on_webview_decide_policy(self, _widget, decision, dtype):
424
425
if dtype == WebKit2 .PolicyDecisionType .NAVIGATION_ACTION :
425
426
nav = decision .get_navigation_action ()
426
427
uri = nav .get_request ().get_uri ()
428
+ usr = self .open_link or nav .is_user_gesture ()
427
429
428
- if not uri .startswith (self .app_url ):
430
+ self .open_link = False
431
+
432
+ if usr and not uri .startswith (self .app_url ):
429
433
decision .ignore ()
430
434
webbrowser .open (uri )
431
435
@@ -446,13 +450,20 @@ def on_history_changed(self, _list, _added, _removed):
446
450
forward = self .webview .can_go_forward ()
447
451
self .header_forward .set_sensitive (forward )
448
452
453
+ def on_webview_open_link (self , _action , _variant ):
454
+ self .open_link = True
455
+
449
456
def on_webview_context_menu (self , _widget , menu , _coords , _keyboard ):
450
457
for item in menu .get_items ():
451
458
action = item .get_stock_action ()
452
459
453
460
if not item .is_separator () and not action in CTX_MENU :
454
461
menu .remove (item )
455
462
463
+ if action == WebKit2 .ContextMenuAction .OPEN_LINK :
464
+ gaction = item .get_gaction ()
465
+ gaction .connect ('activate' , self .on_webview_open_link )
466
+
456
467
457
468
class DevdocsDesktopService (dbus .service .Object ):
458
469
0 commit comments