<commit_before>/* Copyright 2014 Yorba Foundation
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

namespace California.Host {

/**
 * Primary application window.
 */

public class MainWindow : Gtk.ApplicationWindow {
    /**
     * Minimum width of the main window (to be usable).
     */
    public const int MIN_WIDTH = 800;
    
    /**
     * Default width of the main window (to be usable).
     *
     * This value is also set in the GSettings XML file.
     */
    public const int DEFAULT_WIDTH = 1024;
    
    /**
     * Minimum height of the main window (to be usable).
     */
    public const int MIN_HEIGHT = 600;
    
    /**
     * Default height of the main window (to be usable).
     *
     * This value is also set in the GSettings XML file.
     */
    public const int DEFAULT_HEIGHT = 768;
    
    private const string PROP_FIRST_OF_WEEK = "first-of-week";
    
    private const string DETAILED_ACTION_QUICK_CREATE_EVENT = "win.quick-create-event";
    private const string ACTION_QUICK_CREATE_EVENT = "quick-create-event";
    private const string ACCEL_QUICK_CREATE_EVENT = "<Primary>n";
    
    private const string DETAILED_ACTION_JUMP_TO_TODAY = "win.jump-to-today";
    private const string ACTION_JUMP_TO_TODAY = "jump-to-today";
    private const string ACCEL_JUMP_TO_TODAY = "<Primary>t";
    
    private const string DETAILED_ACTION_NEXT = "win.next";
    private const string ACTION_NEXT = "next";
    private const string ACCEL_NEXT = "<Alt>Right";
    
    private const string DETAILED_ACTION_PREVIOUS = "win.previous";
    private const string ACTION_PREVIOUS = "previous";
    private const string ACCEL_PREVIOUS = "<Alt>Left";
    
    private const string DETAILED_ACTION_MONTH = "win.view-month";
    private const string ACTION_MONTH = "view-month";
    private const string ACCEL_MONTH = "<Ctrl>M";
    
    private const string DETAILED_ACTION_WEEK = "win.view-week";
    private const string ACTION_WEEK = "view-week";
    private const string ACCEL_WEEK = "<Ctrl>W";
    
    private const string DETAILED_ACTION_INCREASE_FONT = "win.increase-font";
    private const string ACTION_INCREASE_FONT = "increase-font";
    private const string ACCEL_INCREASE_FONT = "KP_Add";
    
    private const string DETAILED_ACTION_DECREASE_FONT = "win.decrease-font";
    private const string ACTION_DECREASE_FONT = "decrease-font";
    private const string ACCEL_DECREASE_FONT = "KP_Subtract";
    
    private const string DETAILED_ACTION_RESET_FONT = "win.reset-font";
    private const string ACTION_RESET_FONT = "reset-font";
    private const string ACCEL_RESET_FONT = "KP_Multiply";
    
    private static const ActionEntry[] action_entries = {
        { ACTION_QUICK_CREATE_EVENT, on_quick_create_event },
        { ACTION_JUMP_TO_TODAY, on_jump_to_today },
        { ACTION_NEXT, on_next },
        { ACTION_PREVIOUS, on_previous },
        { ACTION_MONTH, on_view_month },
        { ACTION_WEEK, on_view_week },
        { ACTION_INCREASE_FONT, on_increase_font },
        { ACTION_DECREASE_FONT, on_decrease_font },
        { ACTION_RESET_FONT, on_reset_font }
    };
    
    // Set as a property so it can be bound to the current View.Controllable
    public Calendar.FirstOfWeek first_of_week { get; set; }
    
    private Gtk.Button quick_add_button;
    private View.Palette palette;
    private View.Controllable month_view;
    private View.Controllable week_view;
    private View.Controllable? current_controller = null;
    private Gee.HashSet<Binding> current_bindings = new Gee.HashSet<Binding>();
    private Gtk.Stack view_stack = new Gtk.Stack();
    private Gtk.HeaderBar headerbar = new Gtk.HeaderBar();
    private Gtk.Button today = new Gtk.Button.with_label(_("_Today"));
    private Binding view_stack_binding;
    private Gee.HashSet<string> view_stack_ids = new Gee.HashSet<string>();
    private int window_width = -1;
    private int window_height = -1;
    
    public MainWindow(Application app) {
        Object (application: app);
        
        title = Application.TITLE;
        set_size_request(MIN_WIDTH, MIN_HEIGHT);
        set_default_icon_name(Application.ICON_NAME);
        
        set_default_size(Settings.instance.window_width, Settings.instance.window_height);
        if (Settings.instance.window_maximized)
            maximize();
        
        bool rtl = get_direction() == Gtk.TextDirection.RTL;
        
        add_action_entries(action_entries, this);
        Application.instance.add_accelerator(ACCEL_QUICK_CREATE_EVENT, DETAILED_ACTION_QUICK_CREATE_EVENT,
            null);
        Application.instance.add_accelerator(ACCEL_JUMP_TO_TODAY, DETAILED_ACTION_JUMP_TO_TODAY,
            null);
        Application.instance.add_accelerator(rtl ? ACCEL_PREVIOUS : ACCEL_NEXT, DETAILED_ACTION_NEXT,
            null);
        Application.instance.add_accelerator(rtl ? ACCEL_NEXT : ACCEL_PREVIOUS, DETAILED_ACTION_PREVIOUS,
            null);
        Application.instance.add_accelerator(ACCEL_MONTH, DETAILED_ACTION_MONTH, null);
        Application.instance.add_accelerator(ACCEL_WEEK, DETAILED_ACTION_WEEK, null);
        Application.instance.add_accelerator(ACCEL_INCREASE_FONT, DETAILED_ACTION_INCREASE_FONT, null);
        Application.instance.add_accelerator(ACCEL_DECREASE_FONT, DETAILED_ACTION_DECREASE_FONT, null);
        Application.instance.add_accelerator(ACCEL_RESET_FONT, DETAILED_ACTION_RESET_FONT, null);
        
        // view stack settings
        view_stack.homogeneous = true;
        view_stack.transition_duration = Toolkit.DEFAULT_STACK_TRANSITION_DURATION_MSEC;
        view_stack.transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;
        
        // subscribe before adding so first add to initialize UI
        view_stack.notify["visible-child"].connect(on_view_changed);
        
        // create a View.Palette for all the hosted views ...
        palette = new View.Palette(this);
        
        // ... then create the hosted views
        month_view = new View.Month.Controller(palette);
        week_view = new View.Week.Controller(palette);
        
        // add views to view stack, first added is first shown
        add_controller(month_view);
        add_controller(week_view);
        
        // if not on Unity, use headerbar as the titlebar (removes window chrome) and provide close
        // button for users who might have trouble finding it otherwise
#if !ENABLE_UNITY
        // Unity doesn't support GtkHeaderBar-as-title-bar very well yet; when set, the main
        // window can't be resized no matter what additional GtkWindow properties are set
        set_titlebar(headerbar);
#endif
        
        today.valign = Gtk.Align.CENTER;
        today.use_underline = true;
        today.tooltip_text = _("Jump to today's date (Ctrl+T)");
        today.set_action_name(DETAILED_ACTION_JUMP_TO_TODAY);
        
        Gtk.Button prev = new Gtk.Button.from_icon_name(rtl ? "go-previous-rtl-symbolic" : "go-previous-symbolic",
            Gtk.IconSize.MENU);
        prev.valign = Gtk.Align.CENTER;
        prev.tooltip_text = _("Previous (Alt+Left)");
        prev.set_action_name(DETAILED_ACTION_PREVIOUS);
        
        Gtk.Button next = new Gtk.Button.from_icon_name(rtl ? "go-next-rtl-symbolic" : "go-next-symbolic",
            Gtk.IconSize.MENU);
        next.valign = Gtk.Align.CENTER;
        next.tooltip_text = _("Next (Alt+Right)");
        next.set_action_name(DETAILED_ACTION_NEXT);
        
        Gtk.Box nav_buttons = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
        nav_buttons.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED);
        nav_buttons.get_style_context().add_class(Gtk.STYLE_CLASS_RAISED);
        nav_buttons.pack_start(prev);
        nav_buttons.pack_end(next);
        
        // TODO:
        // Remove Gtk.StackSwitcher for a few reasons: (a) the buttons are kinda wide and
        // would like to conserve header bar space; (b) want to add tooltips to buttons; and (c)
        // want to move to icons at some point
        Gtk.StackSwitcher view_switcher = new Gtk.StackSwitcher();
        view_switcher.stack = view_stack;
        view_switcher.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED);
        view_switcher.get_style_context().add_class(Gtk.STYLE_CLASS_RAISED);
        
        // pack left-side of window
        headerbar.pack_start(today);
        headerbar.pack_start(nav_buttons);
        headerbar.pack_start(view_switcher);
        
        quick_add_button = new Gtk.Button.from_icon_name("list-add-symbolic", Gtk.IconSize.MENU);
        quick_add_button.valign = Gtk.Align.CENTER;
        quick_add_button.tooltip_text = _("Quick add event (Ctrl+N)");
        quick_add_button.set_action_name(DETAILED_ACTION_QUICK_CREATE_EVENT);
        
        Gtk.Button calendars = new Gtk.Button.from_icon_name("x-office-calendar-symbolic",
            Gtk.IconSize.MENU);
        calendars.valign = Gtk.Align.CENTER;
        calendars.tooltip_text = _("Calendars (Ctrl+L)");
        calendars.set_action_name(Application.DETAILED_ACTION_CALENDAR_MANAGER);
        
        Gtk.MenuButton window_menu = new Gtk.MenuButton();
        window_menu.menu_model = Resource.load<MenuModel>("window-menu.interface", "window-menu");
        window_menu.add(new Gtk.Image.from_icon_name("emblem-system-symbolic", Gtk.IconSize.SMALL_TOOLBAR));
        
        // Vertically center all buttons and put them in a SizeGroup to handle situations where
        // the text button is smaller than the icons buttons due to language (i.e. Hebrew)
        // see https://bugzilla.gnome.org/show_bug.cgi?id=729771
        Gtk.SizeGroup size = new Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL);
        size.add_widget(today);
        size.add_widget(prev);
        size.add_widget(next);
        size.add_widget(quick_add_button);
        size.add_widget(calendars);
        size.add_widget(window_menu);
        
        // pack right-side of window
        headerbar.pack_end(quick_add_button);
        headerbar.pack_end(calendars);
        headerbar.pack_end(window_menu);
        
        Gtk.Box layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
        // if on Unity, since headerbar is not the titlebar, need to pack it like any other widget
#if ENABLE_UNITY
        layout.pack_start(headerbar, false, true, 0);
#endif
        layout.pack_end(view_stack, true, true, 0);<commit_msg>Fix the size of the window menu<commit_after>/* Copyright 2014 <NAME>
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

namespace California.Host {

/**
 * Primary application window.
 */

public class MainWindow : Gtk.ApplicationWindow {
    /**
     * Minimum width of the main window (to be usable).
     */
    public const int MIN_WIDTH = 800;
    
    /**
     * Default width of the main window (to be usable).
     *
     * This value is also set in the GSettings XML file.
     */
    public const int DEFAULT_WIDTH = 1024;
    
    /**
     * Minimum height of the main window (to be usable).
     */
    public const int MIN_HEIGHT = 600;
    
    /**
     * Default height of the main window (to be usable).
     *
     * This value is also set in the GSettings XML file.
     */
    public const int DEFAULT_HEIGHT = 768;
    
    private const string PROP_FIRST_OF_WEEK = "first-of-week";
    
    private const string DETAILED_ACTION_QUICK_CREATE_EVENT = "win.quick-create-event";
    private const string ACTION_QUICK_CREATE_EVENT = "quick-create-event";
    private const string ACCEL_QUICK_CREATE_EVENT = "<Primary>n";
    
    private const string DETAILED_ACTION_JUMP_TO_TODAY = "win.jump-to-today";
    private const string ACTION_JUMP_TO_TODAY = "jump-to-today";
    private const string ACCEL_JUMP_TO_TODAY = "<Primary>t";
    
    private const string DETAILED_ACTION_NEXT = "win.next";
    private const string ACTION_NEXT = "next";
    private const string ACCEL_NEXT = "<Alt>Right";
    
    private const string DETAILED_ACTION_PREVIOUS = "win.previous";
    private const string ACTION_PREVIOUS = "previous";
    private const string ACCEL_PREVIOUS = "<Alt>Left";
    
    private const string DETAILED_ACTION_MONTH = "win.view-month";
    private const string ACTION_MONTH = "view-month";
    private const string ACCEL_MONTH = "<Ctrl>M";
    
    private const string DETAILED_ACTION_WEEK = "win.view-week";
    private const string ACTION_WEEK = "view-week";
    private const string ACCEL_WEEK = "<Ctrl>W";
    
    private const string DETAILED_ACTION_INCREASE_FONT = "win.increase-font";
    private const string ACTION_INCREASE_FONT = "increase-font";
    private const string ACCEL_INCREASE_FONT = "KP_Add";
    
    private const string DETAILED_ACTION_DECREASE_FONT = "win.decrease-font";
    private const string ACTION_DECREASE_FONT = "decrease-font";
    private const string ACCEL_DECREASE_FONT = "KP_Subtract";
    
    private const string DETAILED_ACTION_RESET_FONT = "win.reset-font";
    private const string ACTION_RESET_FONT = "reset-font";
    private const string ACCEL_RESET_FONT = "KP_Multiply";
    
    private static const ActionEntry[] action_entries = {
        { ACTION_QUICK_CREATE_EVENT, on_quick_create_event },
        { ACTION_JUMP_TO_TODAY, on_jump_to_today },
        { ACTION_NEXT, on_next },
        { ACTION_PREVIOUS, on_previous },
        { ACTION_MONTH, on_view_month },
        { ACTION_WEEK, on_view_week },
        { ACTION_INCREASE_FONT, on_increase_font },
        { ACTION_DECREASE_FONT, on_decrease_font },
        { ACTION_RESET_FONT, on_reset_font }
    };
    
    // Set as a property so it can be bound to the current View.Controllable
    public Calendar.FirstOfWeek first_of_week { get; set; }
    
    private Gtk.Button quick_add_button;
    private View.Palette palette;
    private View.Controllable month_view;
    private View.Controllable week_view;
    private View.Controllable? current_controller = null;
    private Gee.HashSet<Binding> current_bindings = new Gee.HashSet<Binding>();
    private Gtk.Stack view_stack = new Gtk.Stack();
    private Gtk.HeaderBar headerbar = new Gtk.HeaderBar();
    private Gtk.Button today = new Gtk.Button.with_label(_("_Today"));
    private Binding view_stack_binding;
    private Gee.HashSet<string> view_stack_ids = new Gee.HashSet<string>();
    private int window_width = -1;
    private int window_height = -1;
    
    public MainWindow(Application app) {
        Object (application: app);
        
        title = Application.TITLE;
        set_size_request(MIN_WIDTH, MIN_HEIGHT);
        set_default_icon_name(Application.ICON_NAME);
        
        set_default_size(Settings.instance.window_width, Settings.instance.window_height);
        if (Settings.instance.window_maximized)
            maximize();
        
        bool rtl = get_direction() == Gtk.TextDirection.RTL;
        
        add_action_entries(action_entries, this);
        Application.instance.add_accelerator(ACCEL_QUICK_CREATE_EVENT, DETAILED_ACTION_QUICK_CREATE_EVENT,
            null);
        Application.instance.add_accelerator(ACCEL_JUMP_TO_TODAY, DETAILED_ACTION_JUMP_TO_TODAY,
            null);
        Application.instance.add_accelerator(rtl ? ACCEL_PREVIOUS : ACCEL_NEXT, DETAILED_ACTION_NEXT,
            null);
        Application.instance.add_accelerator(rtl ? ACCEL_NEXT : ACCEL_PREVIOUS, DETAILED_ACTION_PREVIOUS,
            null);
        Application.instance.add_accelerator(ACCEL_MONTH, DETAILED_ACTION_MONTH, null);
        Application.instance.add_accelerator(ACCEL_WEEK, DETAILED_ACTION_WEEK, null);
        Application.instance.add_accelerator(ACCEL_INCREASE_FONT, DETAILED_ACTION_INCREASE_FONT, null);
        Application.instance.add_accelerator(ACCEL_DECREASE_FONT, DETAILED_ACTION_DECREASE_FONT, null);
        Application.instance.add_accelerator(ACCEL_RESET_FONT, DETAILED_ACTION_RESET_FONT, null);
        
        // view stack settings
        view_stack.homogeneous = true;
        view_stack.transition_duration = Toolkit.DEFAULT_STACK_TRANSITION_DURATION_MSEC;
        view_stack.transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;
        
        // subscribe before adding so first add to initialize UI
        view_stack.notify["visible-child"].connect(on_view_changed);
        
        // create a View.Palette for all the hosted views ...
        palette = new View.Palette(this);
        
        // ... then create the hosted views
        month_view = new View.Month.Controller(palette);
        week_view = new View.Week.Controller(palette);
        
        // add views to view stack, first added is first shown
        add_controller(month_view);
        add_controller(week_view);
        
        // if not on Unity, use headerbar as the titlebar (removes window chrome) and provide close
        // button for users who might have trouble finding it otherwise
#if !ENABLE_UNITY
        // Unity doesn't support GtkHeaderBar-as-title-bar very well yet; when set, the main
        // window can't be resized no matter what additional GtkWindow properties are set
        set_titlebar(headerbar);
#endif
        
        today.valign = Gtk.Align.CENTER;
        today.use_underline = true;
        today.tooltip_text = _("Jump to today's date (Ctrl+T)");
        today.set_action_name(DETAILED_ACTION_JUMP_TO_TODAY);
        
        Gtk.Button prev = new Gtk.Button.from_icon_name(rtl ? "go-previous-rtl-symbolic" : "go-previous-symbolic",
            Gtk.IconSize.MENU);
        prev.valign = Gtk.Align.CENTER;
        prev.tooltip_text = _("Previous (Alt+Left)");
        prev.set_action_name(DETAILED_ACTION_PREVIOUS);
        
        Gtk.Button next = new Gtk.Button.from_icon_name(rtl ? "go-next-rtl-symbolic" : "go-next-symbolic",
            Gtk.IconSize.MENU);
        next.valign = Gtk.Align.CENTER;
        next.tooltip_text = _("Next (Alt+Right)");
        next.set_action_name(DETAILED_ACTION_NEXT);
        
        Gtk.Box nav_buttons = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
        nav_buttons.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED);
        nav_buttons.get_style_context().add_class(Gtk.STYLE_CLASS_RAISED);
        nav_buttons.pack_start(prev);
        nav_buttons.pack_end(next);
        
        // TODO:
        // Remove Gtk.StackSwitcher for a few reasons: (a) the buttons are kinda wide and
        // would like to conserve header bar space; (b) want to add tooltips to buttons; and (c)
        // want to move to icons at some point
        Gtk.StackSwitcher view_switcher = new Gtk.StackSwitcher();
        view_switcher.stack = view_stack;
        view_switcher.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED);
        view_switcher.get_style_context().add_class(Gtk.STYLE_CLASS_RAISED);
        
        // pack left-side of window
        headerbar.pack_start(today);
        headerbar.pack_start(nav_buttons);
        headerbar.pack_start(view_switcher);
        
        quick_add_button = new Gtk.Button.from_icon_name("list-add-symbolic", Gtk.IconSize.MENU);
        quick_add_button.valign = Gtk.Align.CENTER;
        quick_add_button.tooltip_text = _("Quick add event (Ctrl+N)");
        quick_add_button.set_action_name(DETAILED_ACTION_QUICK_CREATE_EVENT);
        
        Gtk.Button calendars = new Gtk.Button.from_icon_name("x-office-calendar-symbolic",
            Gtk.IconSize.MENU);
        calendars.valign = Gtk.Align.CENTER;
        calendars.tooltip_text = _("Calendars (Ctrl+L)");
        calendars.set_action_name(Application.DETAILED_ACTION_CALENDAR_MANAGER);
        
        Gtk.MenuButton window_menu = new Gtk.MenuButton();
        window_menu.valign = Gtk.Align.CENTER;
        window_menu.menu_model = Resource.load<MenuModel>("window-menu.interface", "window-menu");
        window_menu.image = new Gtk.Image.from_icon_name("emblem-system-symbolic", Gtk.IconSize.MENU);
        
        // Vertically center all buttons and put them in a SizeGroup to handle situations where
        // the text button is smaller than the icons buttons due to language (i.e. Hebrew)
        // see https://bugzilla.gnome.org/show_bug.cgi?id=729771
        Gtk.SizeGroup size = new Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL);
        size.add_widget(today);
        size.add_widget(prev);
        size.add_widget(next);
        size.add_widget(quick_add_button);
        size.add_widget(calendars);
        size.add_widget(window_menu);
        
        // pack right-side of window
        headerbar.pack_end(quick_add_button);
        headerbar.pack_end(calendars);
        headerbar.pack_end(window_menu);
        
        Gtk.Box layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
        // if on Unity, since headerbar is not the titlebar, need to pack it like any other widget
#if ENABLE_UNITY
        layout.pack_start(headerbar, false, true, 0);
#endif
        layout.pack_end(view_stack, true, true, 0);
{'fraction_non_alphanumeric': 0.08897963059683776, 'fraction_numerical': 0.0029438298276435117, 'mean_word_length': 2.960511470477623, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 2, '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': '753244', 'n_tokens_mistral': 6819, 'n_tokens_neox': 6497, 'n_words': 1437}