<commit_before>/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

class AlertDialog : Object {
    private Gtk.MessageDialog dialog;
    
    public AlertDialog(Gtk.Window? parent, Gtk.MessageType message_type, string title, string? description,
        string? ok_button, string? cancel_button, string? tertiary_button,
        Gtk.ResponseType tertiary_response_type, string? ok_action_type) {
        dialog = new Gtk.MessageDialog(parent, Gtk.DialogFlags.DESTROY_WITH_PARENT, message_type,
            Gtk.ButtonsType.NONE, "");
        
        dialog.text = title;
        dialog.secondary_text = description;
        
        if (!Geary.String.is_empty_or_whitespace(tertiary_button))
            dialog.add_button(tertiary_button, tertiary_response_type);
        
        if (!Geary.String.is_empty_or_whitespace(cancel_button))
            dialog.add_button(cancel_button, Gtk.ResponseType.CANCEL);
        
        if (!Geary.String.is_empty_or_whitespace(ok_button)) {
            Gtk.Widget? button = dialog.add_button(ok_button, Gtk.ResponseType.OK);
            if (!Geary.String.is_empty_or_whitespace(ok_action_type)) {
                button.get_style_context().add_class(ok_action_type);
            }
        }
    }
    
    public void use_secondary_markup(bool markup) {
        dialog.secondary_use_markup = markup;
    }
    
    public Gtk.Box get_message_area() {
        return (Gtk.Box) dialog.get_message_area();
    }

    public void set_focus_response(Gtk.ResponseType response) {
        Gtk.Widget? to_focus = dialog.get_widget_for_response(response);
        if (to_focus != null)
            to_focus.grab_focus();
    }
    
    // Runs dialog, destroys it, and returns selected response
    public Gtk.ResponseType run() {
        Gtk.ResponseType response = (Gtk.ResponseType) dialog.run();
        
        dialog.destroy();
        
        return response;
    }
}

class ConfirmationDialog : AlertDialog {
    public ConfirmationDialog(Gtk.Window? parent, string title, string? description, 
        string? ok_button, string? ok_action_type = "") {
        base (parent, Gtk.MessageType.WARNING, title, description, ok_button, Stock._CANCEL,
            null, Gtk.ResponseType.NONE, ok_action_type);
    }
}

class TernaryConfirmationDialog : AlertDialog {
    public TernaryConfirmationDialog(Gtk.Window? parent, string title, string? description,
        string? ok_button, string? tertiary_button, Gtk.ResponseType tertiary_response_type, string? ok_action_type = "") {
        base (parent, Gtk.MessageType.WARNING, title, description, ok_button, tertiary_button, Stock._CANCEL,<commit_msg>TernaryConfirmationDialog: Fix inversion between cancel and ternary action labels<commit_after>/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

class AlertDialog : Object {
    private Gtk.MessageDialog dialog;
    
    public AlertDialog(Gtk.Window? parent, Gtk.MessageType message_type, string title, string? description,
        string? ok_button, string? cancel_button, string? tertiary_button,
        Gtk.ResponseType tertiary_response_type, string? ok_action_type) {
        dialog = new Gtk.MessageDialog(parent, Gtk.DialogFlags.DESTROY_WITH_PARENT, message_type,
            Gtk.ButtonsType.NONE, "");
        
        dialog.text = title;
        dialog.secondary_text = description;
        
        if (!Geary.String.is_empty_or_whitespace(tertiary_button))
            dialog.add_button(tertiary_button, tertiary_response_type);
        
        if (!Geary.String.is_empty_or_whitespace(cancel_button))
            dialog.add_button(cancel_button, Gtk.ResponseType.CANCEL);
        
        if (!Geary.String.is_empty_or_whitespace(ok_button)) {
            Gtk.Widget? button = dialog.add_button(ok_button, Gtk.ResponseType.OK);
            if (!Geary.String.is_empty_or_whitespace(ok_action_type)) {
                button.get_style_context().add_class(ok_action_type);
            }
        }
    }
    
    public void use_secondary_markup(bool markup) {
        dialog.secondary_use_markup = markup;
    }
    
    public Gtk.Box get_message_area() {
        return (Gtk.Box) dialog.get_message_area();
    }

    public void set_focus_response(Gtk.ResponseType response) {
        Gtk.Widget? to_focus = dialog.get_widget_for_response(response);
        if (to_focus != null)
            to_focus.grab_focus();
    }
    
    // Runs dialog, destroys it, and returns selected response
    public Gtk.ResponseType run() {
        Gtk.ResponseType response = (Gtk.ResponseType) dialog.run();
        
        dialog.destroy();
        
        return response;
    }
}

class ConfirmationDialog : AlertDialog {
    public ConfirmationDialog(Gtk.Window? parent, string title, string? description, 
        string? ok_button, string? ok_action_type = "") {
        base (parent, Gtk.MessageType.WARNING, title, description, ok_button, Stock._CANCEL,
            null, Gtk.ResponseType.NONE, ok_action_type);
    }
}

class TernaryConfirmationDialog : AlertDialog {
    public TernaryConfirmationDialog(Gtk.Window? parent, string title, string? description,
        string? ok_button, string? tertiary_button, Gtk.ResponseType tertiary_response_type, string? ok_action_type = "") {
        base (parent, Gtk.MessageType.WARNING, title, description, ok_button, Stock._CANCEL, tertiary_button,
{'fraction_non_alphanumeric': 0.08970276008492568, 'fraction_numerical': 0.0021231422505307855, 'mean_word_length': 3.063982746225737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6421986', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1653, 'n_words': 351}