<commit_before>/*
 * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 *  
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */

define(function (require, exports, module) {
    "use strict";

    var React = require("react"),
        Fluxxor = require("fluxxor"),
        FluxMixin = Fluxxor.FluxMixin(React),
        StoreWatchMixin = Fluxxor.StoreWatchMixin,
        Immutable = require("immutable"),
        _ = require("lodash");

    var os = require("adapter").os;

    var collection = require("js/util/collection"),
        nls = require("js/util/nls"),
        Datalist = require("js/jsx/shared/Datalist"),
        SVGIcon = require("js/jsx/shared/SVGIcon"),
        headlights = require("js/util/headlights"),
        Button = require("js/jsx/shared/Button");

    /**
     * The ID of the option display when there are no other valid results
     *
     * @const
     * @type {string}
     */
    var PLACEHOLDER_ID = "NO_OPTIONS-placeholder";

    var SearchBar = React.createClass({
        mixins: [FluxMixin, StoreWatchMixin("search", "application")],

        propTypes: {
            dismissDialog: React.PropTypes.func,
            // Function to perform an action when an option is confirmed
            executeOption: React.PropTypes.func.isRequired,
            // Unique identifying string for the search module
            searchID: React.PropTypes.string.isRequired
        },

        getStateFromFlux: function () {
            var flux = this.getFlux(),
                appStore = flux.store("application"),
                searchStore = flux.store("search"),
                searchState = searchStore.getState(this.props.searchID),
                options = searchState.searchItems,

                filterItems = options.filter(function (opt) {
                    return opt.type === "filter";
                }),
                filterIDs = collection.pluck(filterItems, "id").toJS();

            filterIDs.push(PLACEHOLDER_ID);

            return {
                // All possible search options as a flat list
                options: options,
                // All possible search options, grouped in Immutable lists by search type
                groupedOptions: searchState.groupedSearchItems,
                // Broad categories of what SearchBar has as options
                searchTypes: searchState.headers,
                // List of more specific categories that correlate with searchTypes to be used as filters
                // Indicate that there are no categories for a search type with null
                searchCategories: searchState.filters,
                // List of IDs corresponding with the filter options and the placeholder option
                // Gets passed to Datalist as list of option IDs that when selected, should not close the dialog
                filterIDs: filterIDs,
                // Filter names that are user-inputted strings, stored under IDs
                safeFilterNameMap: searchState.safeFilterNameMap,
                // Whether or not there are uninitialized documents waiting to be initialized
                ready: appStore.getUninitializedDocuments().size === 0
            };
        },

        getDefaultProps: function () {
            return {
                dismissDialog: _.identity,
                searchID: "",
                maxOptions: 30
            };
        },

        getInitialState: function () {
            return {
                // The currently applied filter
                filter: [],
                // SVG class for icon for the currently applied filter
                icon: null,
                hasInputValue: null
            };
        },

        /**
         * Explicitly focus the text input of the search datalist when the window is activated.
         *
         * @private
         * @param {{becameActive: boolean}} event
         */
        _handleActivationChanged: function (event) {
            if (this.state.ready && event && event.becameActive) {
                this.refs.datalist.focus();
            }
        },

        /**
         * Initialize search providers for the given searchID.
         *
         * @private
         */
        _initSearchProviders: function () {
            var searchStore = this.getFlux().store("search");<commit_msg>Workaround a Chromium bug (I assume) that is causing the active text input to be blurred when the application window is activated.<commit_after>/*
 * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 *  
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */

define(function (require, exports, module) {
    "use strict";

    var React = require("react"),
        Fluxxor = require("fluxxor"),
        FluxMixin = Fluxxor.FluxMixin(React),
        StoreWatchMixin = Fluxxor.StoreWatchMixin,
        Immutable = require("immutable"),
        _ = require("lodash");

    var os = require("adapter").os;

    var collection = require("js/util/collection"),
        nls = require("js/util/nls"),
        Datalist = require("js/jsx/shared/Datalist"),
        SVGIcon = require("js/jsx/shared/SVGIcon"),
        headlights = require("js/util/headlights"),
        Button = require("js/jsx/shared/Button");

    /**
     * The ID of the option display when there are no other valid results
     *
     * @const
     * @type {string}
     */
    var PLACEHOLDER_ID = "NO_OPTIONS-placeholder";

    var SearchBar = React.createClass({
        mixins: [FluxMixin, StoreWatchMixin("search", "application")],

        propTypes: {
            dismissDialog: React.PropTypes.func,
            // Function to perform an action when an option is confirmed
            executeOption: React.PropTypes.func.isRequired,
            // Unique identifying string for the search module
            searchID: React.PropTypes.string.isRequired
        },

        getStateFromFlux: function () {
            var flux = this.getFlux(),
                appStore = flux.store("application"),
                searchStore = flux.store("search"),
                searchState = searchStore.getState(this.props.searchID),
                options = searchState.searchItems,

                filterItems = options.filter(function (opt) {
                    return opt.type === "filter";
                }),
                filterIDs = collection.pluck(filterItems, "id").toJS();

            filterIDs.push(PLACEHOLDER_ID);

            return {
                // All possible search options as a flat list
                options: options,
                // All possible search options, grouped in Immutable lists by search type
                groupedOptions: searchState.groupedSearchItems,
                // Broad categories of what SearchBar has as options
                searchTypes: searchState.headers,
                // List of more specific categories that correlate with searchTypes to be used as filters
                // Indicate that there are no categories for a search type with null
                searchCategories: searchState.filters,
                // List of IDs corresponding with the filter options and the placeholder option
                // Gets passed to Datalist as list of option IDs that when selected, should not close the dialog
                filterIDs: filterIDs,
                // Filter names that are user-inputted strings, stored under IDs
                safeFilterNameMap: searchState.safeFilterNameMap,
                // Whether or not there are uninitialized documents waiting to be initialized
                ready: appStore.getUninitializedDocuments().size === 0
            };
        },

        getDefaultProps: function () {
            return {
                dismissDialog: _.identity,
                searchID: "",
                maxOptions: 30
            };
        },

        getInitialState: function () {
            return {
                // The currently applied filter
                filter: [],
                // SVG class for icon for the currently applied filter
                icon: null,
                hasInputValue: null
            };
        },

        /**
         * Explicitly focus the text input of the search datalist when the window is activated.
         *
         * @private
         * @param {{becameActive: boolean}} event
         */
        _handleActivationChanged: function (event) {
            if (event.becameActive) {
                // SuperHack: Work around a Chromium bug in which activating the window
                // blurs (at some point) the focused input. See #3519.
                window.setTimeout(function () {
                    if (this.state.ready) {
                        this.refs.datalist.focus();
                    }
                }.bind(this), 100);
            }
        },

        /**
         * Initialize search providers for the given searchID.
         *
         * @private
         */
        _initSearchProviders: function () {
            var searchStore = this.getFlux().store("search");
{'fraction_non_alphanumeric': 0.08029853430446902, 'fraction_numerical': 0.0018883193957377933, 'mean_word_length': 1.996228448275862, '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': '6063415', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2575, 'n_words': 975}