/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at . */
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Tab, Tabs, TabList, TabPanels } from "react-aria-components/src/tabs";
import actions from "../../actions";
import { getSelectedPrimaryPaneTab, getContext } from "../../selectors";
import { prefs } from "../../utils/prefs";
import { connect } from "../../utils/connect";
import { primaryPaneTabs } from "../../constants";
import { formatKeyShortcut } from "../../utils/text";
import Outline from "./Outline";
import SourcesTree from "./SourcesTree";
import ProjectSearch from "./ProjectSearch";
const classnames = require("devtools/client/shared/classnames.js");
import "./Sources.css";
const tabs = [
primaryPaneTabs.SOURCES,
primaryPaneTabs.OUTLINE,
primaryPaneTabs.PROJECT_SEARCH,
];
class PrimaryPanes extends Component {
constructor(props) {
super(props);
this.state = {
alphabetizeOutline: prefs.alphabetizeOutline,
};
}
static get propTypes() {
return {
cx: PropTypes.object.isRequired,
projectRootName: PropTypes.string.isRequired,
selectedTab: PropTypes.oneOf(tabs).isRequired,
setPrimaryPaneTab: PropTypes.func.isRequired,
setActiveSearch: PropTypes.func.isRequired,
closeActiveSearch: PropTypes.func.isRequired,
};
}
onAlphabetizeClick = () => {
const alphabetizeOutline = !prefs.alphabetizeOutline;
prefs.alphabetizeOutline = alphabetizeOutline;
this.setState({ alphabetizeOutline });
};
onActivateTab = index => {
const tab = tabs.at(index);
this.props.setPrimaryPaneTab(tab);
if (tab == primaryPaneTabs.PROJECT_SEARCH) {
this.props.setActiveSearch(tab);
} else {
this.props.closeActiveSearch();
}
};
renderTabList() {
return [
{formatKeyShortcut(L10N.getStr("sources.header"))}
,
{formatKeyShortcut(L10N.getStr("outline.header"))}
,
{formatKeyShortcut(L10N.getStr("search.header"))}
,
];
}
render() {
const { selectedTab } = this.props;
return (
{this.renderTabList()}
);
}
}
const mapStateToProps = state => {
return {
cx: getContext(state),
selectedTab: getSelectedPrimaryPaneTab(state),
};
};
const connector = connect(mapStateToProps, {
setPrimaryPaneTab: actions.setPrimaryPaneTab,
setActiveSearch: actions.setActiveSearch,
closeActiveSearch: actions.closeActiveSearch,
});
export default connector(PrimaryPanes);