<commit_before>/**
 * Copyright 2016, GeoSolutions Sas.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */

const React = require('react');
const {connect} = require('react-redux');

const {setControlProperty} = require('../actions/controls');
const {changeHelpText, changeHelpwinVisibility} = require('../actions/help');

const {Button, Tooltip, OverlayTrigger, Panel, Collapse} = require('react-bootstrap');

require('./toolbar/assets/css/toolbar.css');

const Message = require('./locale/Message');

const {toggleControl} = require('../actions/controls');

const ReactCSSTransitionGroup = require('react-addons-css-transition-group');

const HelpBadge = connect((state) => ({
    isVisible: state.controls && state.controls.help && state.controls.help.enabled
}), {
    changeHelpText,
    changeHelpwinVisibility
})(require('../components/help/HelpBadge'));

const assign = require('object-assign');
const {partial} = require('lodash');

const Toolbar = React.createClass({
    propTypes: {
        id: React.PropTypes.string,
        tools: React.PropTypes.array,
        mapType: React.PropTypes.string,
        panelStyle: React.PropTypes.object,
        panelClassName: React.PropTypes.string,
        active: React.PropTypes.string,
        items: React.PropTypes.array,
        allVisible: React.PropTypes.bool,
        layout: React.PropTypes.string,
        stateSelector: React.PropTypes.string,
        buttonStyle: React.PropTypes.string,
        pressedButtonStyle: React.PropTypes.string
    },
    contextTypes: {
        messages: React.PropTypes.object,
        router: React.PropTypes.object
    },
    getDefaultProps() {
        return {
            id: "mapstore-toolbar",
            panelStyle: {
                minWidth: "300px",
                right: "52px",
                zIndex: 100,
                position: "absolute",
                overflow: "auto"
            },
            panelClassName: "toolbar-panel",
            items: [],
            allVisible: true,
            layout: "vertical",
            stateSelector: "toolbar",
            buttonStyle: 'default',
            pressedButtonStyle: 'primary'
        };
    },
    getPanel(tool) {
        if (tool.panel === true) {
            return tool.plugin;
        }
        return tool.panel;
    },
    getPanels() {
        return this.getTools()
            .filter((tool) => tool.panel)
            .map((tool) => ({name: tool.name, title: tool.title, cfg: tool.cfg, panel: this.getPanel(tool), items: tool.items, wrap: tool.wrap || false}));
    },
    getTools() {
        const unsorted = this.props.items
            .filter((item) => item.alwaysVisible || this.props.allVisible)
            .map((item, index) => assign({}, item, {position: item.position || index}));
        return unsorted.sort((a, b) => a.position - b.position);
    },
    getTool(tool) {
        if (tool.tool) {
            return tool.tool === true ? tool.plugin : tool.tool;
        }
        let selector = () => ({});
        const actions = {};
        if (tool.exclusive) {
            selector = (state) => ({
                active: state.controls && state.controls[this.props.stateSelector] && state.controls[this.props.stateSelector].active === tool.name
            });
            actions.onClick = setControlProperty.bind(null, this.props.stateSelector, 'active', tool.name, true);
        } else if (tool.toggle) {
            selector = (state) => ({
                bsStyle: state.controls[tool.toggleControl || tool.name] && state.controls[tool.toggleControl || tool.name][tool.toggleProperty || "enabled"] ? this.props.pressedButtonStyle : this.props.buttonStyle
            });
            actions.onClick = toggleControl.bind(null, tool.toggleControl || tool.name, tool.toggleProperty || null);
        } else if (tool.action) {
            actions.onClick = partial(tool.action, this.context);
        }
        return connect(selector, actions)(Button);
    },
    renderButtons() {
        return this.getTools().map((tool) => {
            const help = tool.help ? <HelpBadge className="mapstore-tb-helpbadge" helpText={tool.help}/> : <span/>;
            const tooltip = tool.tooltip ? <Message msgId={tool.tooltip}/> : null;

            const ToolbarButton = this.getTool(tool);

            return this.addTooltip(
                <ToolbarButton tooltip={tooltip} bsStyle={this.props.buttonStyle} help={help} key={tool.name} mapType={this.props.mapType}>
                    {help}{tool.icon}
                </ToolbarButton>,
            tool);
        });
    },
    renderPanels() {
        return this.getPanels().map((panel) => {
            const ToolPanelComponent = panel.panel;
            const ToolPanel = (<ToolPanelComponent<commit_msg>Configurable toolbar button size (#689)<commit_after>/**
 * Copyright 2016, GeoSolutions Sas.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */

const React = require('react');
const {connect} = require('react-redux');

const {setControlProperty} = require('../actions/controls');
const {changeHelpText, changeHelpwinVisibility} = require('../actions/help');

const {Button, Tooltip, OverlayTrigger, Panel, Collapse} = require('react-bootstrap');

require('./toolbar/assets/css/toolbar.css');

const Message = require('./locale/Message');

const {toggleControl} = require('../actions/controls');

const ReactCSSTransitionGroup = require('react-addons-css-transition-group');

const HelpBadge = connect((state) => ({
    isVisible: state.controls && state.controls.help && state.controls.help.enabled
}), {
    changeHelpText,
    changeHelpwinVisibility
})(require('../components/help/HelpBadge'));

const assign = require('object-assign');
const {partial} = require('lodash');

const Toolbar = React.createClass({
    propTypes: {
        id: React.PropTypes.string,
        tools: React.PropTypes.array,
        mapType: React.PropTypes.string,
        panelStyle: React.PropTypes.object,
        panelClassName: React.PropTypes.string,
        active: React.PropTypes.string,
        items: React.PropTypes.array,
        allVisible: React.PropTypes.bool,
        layout: React.PropTypes.string,
        stateSelector: React.PropTypes.string,
        buttonStyle: React.PropTypes.string,
        buttonSize: React.PropTypes.string,
        pressedButtonStyle: React.PropTypes.string
    },
    contextTypes: {
        messages: React.PropTypes.object,
        router: React.PropTypes.object
    },
    getDefaultProps() {
        return {
            id: "mapstore-toolbar",
            panelStyle: {
                minWidth: "300px",
                right: "52px",
                zIndex: 100,
                position: "absolute",
                overflow: "auto"
            },
            panelClassName: "toolbar-panel",
            items: [],
            allVisible: true,
            layout: "vertical",
            stateSelector: "toolbar",
            buttonStyle: 'default',
            buttonSize: null,
            pressedButtonStyle: 'primary'
        };
    },
    getPanel(tool) {
        if (tool.panel === true) {
            return tool.plugin;
        }
        return tool.panel;
    },
    getPanels() {
        return this.getTools()
            .filter((tool) => tool.panel)
            .map((tool) => ({name: tool.name, title: tool.title, cfg: tool.cfg, panel: this.getPanel(tool), items: tool.items, wrap: tool.wrap || false}));
    },
    getTools() {
        const unsorted = this.props.items
            .filter((item) => item.alwaysVisible || this.props.allVisible)
            .map((item, index) => assign({}, item, {position: item.position || index}));
        return unsorted.sort((a, b) => a.position - b.position);
    },
    getTool(tool) {
        if (tool.tool) {
            return tool.tool === true ? tool.plugin : tool.tool;
        }
        let selector = () => ({});
        const actions = {};
        if (tool.exclusive) {
            selector = (state) => ({
                active: state.controls && state.controls[this.props.stateSelector] && state.controls[this.props.stateSelector].active === tool.name
            });
            actions.onClick = setControlProperty.bind(null, this.props.stateSelector, 'active', tool.name, true);
        } else if (tool.toggle) {
            selector = (state) => ({
                bsStyle: state.controls[tool.toggleControl || tool.name] && state.controls[tool.toggleControl || tool.name][tool.toggleProperty || "enabled"] ? this.props.pressedButtonStyle : this.props.buttonStyle
            });
            actions.onClick = toggleControl.bind(null, tool.toggleControl || tool.name, tool.toggleProperty || null);
        } else if (tool.action) {
            actions.onClick = partial(tool.action, this.context);
        }
        return connect(selector, actions)(Button);
    },
    renderButtons() {
        return this.getTools().map((tool) => {
            const help = tool.help ? <HelpBadge className="mapstore-tb-helpbadge" helpText={tool.help}/> : <span/>;
            const tooltip = tool.tooltip ? <Message msgId={tool.tooltip}/> : null;

            const ToolbarButton = this.getTool(tool);

            return this.addTooltip(
                <ToolbarButton tooltip={tooltip} btnSize={this.props.buttonSize} bsStyle={this.props.buttonStyle} help={help} key={tool.name} mapType={this.props.mapType}>
                    {help}{tool.icon}
                </ToolbarButton>,
            tool);
        });
    },
    renderPanels() {
        return this.getPanels().map((panel) => {
            const ToolPanelComponent = panel.panel;
            const ToolPanel = (<ToolPanelComponent
{'fraction_non_alphanumeric': 0.13976098845452703, 'fraction_numerical': 0.002734454121936399, 'mean_word_length': 2.3749145591250853, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, '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': '1054519', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2677, 'n_words': 562}