<commit_before>/*
 Copyright (C) 2015 <NAME> <<EMAIL>>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 See the file COPYING for the full license text.
*/

namespace Midori {
    public class Window : Gtk.Window {
        Gtk.Widget? _toolbar = null;
        public Gtk.Widget? toolbar { get {
            if (_toolbar == null) {
#if HAVE_GTK3
                if (strcmp (Environment.get_variable ("GTK_CSD"), "1") == 0) {
                    var toolbar = new Gtk.HeaderBar ();
                    toolbar.show_close_button = true;
                    toolbar.show ();
                    toolbar.get_style_context ().add_class ("midori-titlebar");
                    _toolbar = toolbar;
                    return _toolbar;
                }
#endif
                var toolbar = new Gtk.Toolbar ();
                toolbar.show_arrow = true;
#if HAVE_GTK3
                toolbar.get_style_context ().add_class ("primary-toolbar");
                hide_titlebar_when_maximized = true;
#endif
                toolbar.popup_context_menu.connect ((x, y, button) => {
                    return button == 3 && context_menu (toolbar); });
                _toolbar = toolbar;
            }
            return _toolbar;
        } }

        public string actions { get; set; default = ""; }
        string extra_actions { get; set; default = ""; }
        List<Gtk.ActionGroup> action_groups;
        public signal bool context_menu (Gtk.Widget widget, Gtk.Action? action=null);
        Gtk.Box? box = null;
        List<Gtk.Widget> toolbars;

        Gtk.Widget? _contents = null;
        public Gtk.Widget? contents { get {
            return _contents;
        } set {
            if (_contents != null)
                box.remove (_contents);
            _contents = value;
            _contents.show ();
            if (box != null)
                box.pack_end (_contents, true, true, 0);
        } }

        public void add_action_group (Gtk.ActionGroup action_group) {
            action_groups.append (action_group);
        }

        public bool show_menubar { get; set; default = false; }

        [CCode (type = "GtkWidget*")]
        public Window () {
        }

        Gtk.ToolItem? get_tool_item (string name) {
            /* Name is the empty string if actions has ,, or trailing , */
            if (name == "")
                return null;
            /* Shown in the notebook, no need to include in the toolbar */
            if (name == "TabNew")
                return null;
            foreach (unowned Gtk.ActionGroup action_group in action_groups) {
                var action = action_group.get_action (name);
                if (action != null) {
                    return create_tool_item (action);
                }
            }
            warning ("Action %s not known to Window", name);
            return null;
        }

        Gtk.ToolItem create_tool_item (Gtk.Action action) {
            var toolitem = (Gtk.ToolItem)action.create_tool_item ();
            /* Show label if button has no icon of any kind */
            if (action.icon_name == null && action.stock_id == null && action.gicon == null)
                toolitem.is_important = true;
            toolitem.get_child ().button_press_event.connect ((event) => {
                return event.button == 3 && context_menu (toolitem, action); });
            if (name == "CompactMenu")
                bind_property ("show-menubar", toolitem, "visible");
            return toolitem;
        }

        /**
         * Adds an action to the (browser) window.
         * Typically it will be displayed in the primary toolbar or headerbar.
         *
         * If @action is a ContextAction a menu will be displayed.
         *
         * Since: 0.6.0
         **/
        public void add_action (Gtk.Action action) {
            action_groups.nth_data (0).add_action (action);
            extra_actions += "," + action.name;
            update_toolbar ();
        }

        /**
         * Remove an action from the (browser) window.
         *
         * Since: 0.6.0
         **/
        public void remove_action (Gtk.Action action) {
            action_groups.nth_data (0).remove_action (action);
            extra_actions = extra_actions.replace ("," + action.name, "");<commit_msg>fix property binding to ensure that exactly one of appmenu button and menubar is always visible<commit_after>/*
 Copyright (C) 2015 <NAME> <<EMAIL>>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 See the file COPYING for the full license text.
*/

namespace Midori {
    public class Window : Gtk.Window {
        Gtk.Widget? _toolbar = null;
        public Gtk.Widget? toolbar { get {
            if (_toolbar == null) {
#if HAVE_GTK3
                if (strcmp (Environment.get_variable ("GTK_CSD"), "1") == 0) {
                    var toolbar = new Gtk.HeaderBar ();
                    toolbar.show_close_button = true;
                    toolbar.show ();
                    toolbar.get_style_context ().add_class ("midori-titlebar");
                    _toolbar = toolbar;
                    return _toolbar;
                }
#endif
                var toolbar = new Gtk.Toolbar ();
                toolbar.show_arrow = true;
#if HAVE_GTK3
                toolbar.get_style_context ().add_class ("primary-toolbar");
                hide_titlebar_when_maximized = true;
#endif
                toolbar.popup_context_menu.connect ((x, y, button) => {
                    return button == 3 && context_menu (toolbar); });
                _toolbar = toolbar;
            }
            return _toolbar;
        } }

        public string actions { get; set; default = ""; }
        string extra_actions { get; set; default = ""; }
        List<Gtk.ActionGroup> action_groups;
        public signal bool context_menu (Gtk.Widget widget, Gtk.Action? action=null);
        Gtk.Box? box = null;
        List<Gtk.Widget> toolbars;

        Gtk.Widget? _contents = null;
        public Gtk.Widget? contents { get {
            return _contents;
        } set {
            if (_contents != null)
                box.remove (_contents);
            _contents = value;
            _contents.show ();
            if (box != null)
                box.pack_end (_contents, true, true, 0);
        } }

        public void add_action_group (Gtk.ActionGroup action_group) {
            action_groups.append (action_group);
        }

        public bool show_menubar { get; set; default = false; }

        [CCode (type = "GtkWidget*")]
        public Window () {
        }

        Gtk.ToolItem? get_tool_item (string name) {
            /* Name is the empty string if actions has ,, or trailing , */
            if (name == "")
                return null;
            /* Shown in the notebook, no need to include in the toolbar */
            if (name == "TabNew")
                return null;
            foreach (unowned Gtk.ActionGroup action_group in action_groups) {
                var action = action_group.get_action (name);
                if (action != null) {
                    return create_tool_item (action);
                }
            }
            warning ("Action %s not known to Window", name);
            return null;
        }

        Gtk.ToolItem create_tool_item (Gtk.Action action) {
            var toolitem = (Gtk.ToolItem)action.create_tool_item ();
            /* Show label if button has no icon of any kind */
            if (action.icon_name == null && action.stock_id == null && action.gicon == null)
                toolitem.is_important = true;
            toolitem.get_child ().button_press_event.connect ((event) => {
                return event.button == 3 && context_menu (toolitem, action); });
            if (action.name == "CompactMenu")
                bind_property ("show-menubar", toolitem, "visible",
                BindingFlags.DEFAULT|BindingFlags.INVERT_BOOLEAN);
            return toolitem;
        }

        /**
         * Adds an action to the (browser) window.
         * Typically it will be displayed in the primary toolbar or headerbar.
         *
         * If @action is a ContextAction a menu will be displayed.
         *
         * Since: 0.6.0
         **/
        public void add_action (Gtk.Action action) {
            action_groups.nth_data (0).add_action (action);
            extra_actions += "," + action.name;
            update_toolbar ();
        }

        /**
         * Remove an action from the (browser) window.
         *
         * Since: 0.6.0
         **/
        public void remove_action (Gtk.Action action) {
            action_groups.nth_data (0).remove_action (action);
            extra_actions = extra_actions.replace ("," + action.name, "");
{'fraction_non_alphanumeric': 0.09928845101258894, 'fraction_numerical': 0.004597701149425287, 'mean_word_length': 1.6854791299235743, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '631130', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2376, 'n_words': 734}