~tintou/pantheon-mail/native-view

« back to all changes in this revision

Viewing changes to src/client/conversation-viewer/ConversationWidget.vala

  • Committer: Corentin Noël
  • Date: 2016-03-10 22:05:39 UTC
  • Revision ID: corentin@elementary.io-20160310220539-m0rtdh0l7ux6g8n5
Restore right click menu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
436
436
        webview.expand = true;
437
437
        webview.transparent = true;
438
438
        webview.hovering_over_link.connect (on_hovering_over_link);
439
 
        webview.context_menu.connect(() => { return true; }); // Suppress default context menu.
 
439
        webview.context_menu.connect (context_menu);
440
440
        webview.resource_request_starting.connect (on_resource_request_starting);
441
441
        webview.navigation_policy_decision_requested.connect (on_navigation_policy_decision_requested);
442
442
        webview.new_window_policy_decision_requested.connect (on_navigation_policy_decision_requested);
559
559
 
560
560
                copy_item.activate.connect (() => {
561
561
                    var clipboard = Gtk.Clipboard.get_for_display (copy_item.get_display (), Gdk.SELECTION_CLIPBOARD);
562
 
                    clipboard.set_text (GLib.Uri.unescape_string (value_label.get_current_uri ()).replace ("mailto:", ""), -1);
 
562
                    clipboard.set_text (GLib.Uri.unescape_string (value_label.get_current_uri ()).replace (Geary.ComposedEmail.MAILTO_SCHEME, ""), -1);
563
563
                });
564
564
 
565
565
                menu.add (open_item);
1107
1107
 
1108
1108
        show_images_email (false);
1109
1109
    }
1110
 
    
 
1110
 
1111
1111
    private void email_flags_changed () {
1112
1112
        if (email.is_unread () == Geary.Trillian.TRUE) {
1113
1113
            read_item.label = _("Mark as Read");
1122
1122
            star_image.icon_name = "non-starred-symbolic";
1123
1123
        }
1124
1124
    }
 
1125
 
 
1126
    [CCode (instance_pos = -1)]
 
1127
    private bool context_menu (Gtk.Widget default_menu, WebKit.HitTestResult hit_test_result, bool triggered_with_keyboard) {
 
1128
        var menu = new Gtk.Menu ();
 
1129
        menu.attach_widget = webview;
 
1130
        if (webview.can_copy_clipboard ()) {
 
1131
            // Add a menu item for copying the current selection.
 
1132
            var item = new Gtk.MenuItem.with_mnemonic (_("_Copy"));
 
1133
            menu.append (item);
 
1134
            item.activate.connect (() => webview.copy_clipboard ());
 
1135
        }
 
1136
 
 
1137
        if (WebKit.HitTestResultContext.LINK in hit_test_result.context) {
 
1138
            if (hit_test_result.link_uri.has_prefix (Geary.ComposedEmail.MAILTO_SCHEME)) {
 
1139
                // Add a menu item for copying the address.
 
1140
                var item = new Gtk.MenuItem.with_mnemonic (_("Copy _Email Address"));
 
1141
                menu.append (item);
 
1142
                item.activate.connect (() => {
 
1143
                    var clipboard = Gtk.Clipboard.get (Gdk.SELECTION_CLIPBOARD);
 
1144
                    clipboard.set_text (hit_test_result.link_uri.substring (Geary.ComposedEmail.MAILTO_SCHEME.length, -1), -1);
 
1145
                    clipboard.store ();
 
1146
                });
 
1147
            } else {
 
1148
                // Add a menu item for copying the link.
 
1149
                var item = new Gtk.MenuItem.with_mnemonic (_("Copy _Link"));
 
1150
                menu.append (item);
 
1151
                item.activate.connect (() => {
 
1152
                    var clipboard = Gtk.Clipboard.get (Gdk.SELECTION_CLIPBOARD);
 
1153
                    clipboard.set_text (hit_test_result.link_uri, -1);
 
1154
                    clipboard.store ();
 
1155
                });
 
1156
            }
 
1157
        }
 
1158
 
 
1159
        // Select all.
 
1160
        var select_all_item = new Gtk.MenuItem.with_mnemonic (_("Select _All"));
 
1161
        select_all_item.activate.connect (() => webview.select_all ());
 
1162
        menu.append (select_all_item);
 
1163
 
 
1164
        // Inspect.
 
1165
        if (Args.inspector) {
 
1166
            var inspect_item = new Gtk.MenuItem.with_mnemonic (_("_Inspect"));
 
1167
            inspect_item.activate.connect (() => {webview.web_inspector.show ();});
 
1168
            menu.append (inspect_item);
 
1169
        }
 
1170
 
 
1171
        menu.show_all ();
 
1172
        menu.popup (null, null, null, 0, Gtk.get_current_event_time ());
 
1173
        return true;
 
1174
    }
1125
1175
}