summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/components/PrimaryPanes/index.js
blob: a8f6bc9a335d1e8d3a50b393a4fdf1b9bb449256 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* 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 <http://mozilla.org/MPL/2.0/>. */

import React, { Component } from "devtools/client/shared/vendor/react";
import PropTypes from "devtools/client/shared/vendor/react-prop-types";

import actions from "../../actions/index";
import { getSelectedPrimaryPaneTab } from "../../selectors/index";
import { prefs } from "../../utils/prefs";
import { connect } from "devtools/client/shared/vendor/react-redux";
import { primaryPaneTabs } from "../../constants";

import Outline from "./Outline";
import SourcesTree from "./SourcesTree";
import ProjectSearch from "./ProjectSearch";

const {
  TabPanel,
  Tabs,
} = require("resource://devtools/client/shared/components/tabs/Tabs.js");

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 {
      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();
    }
  };

  render() {
    const { selectedTab } = this.props;
    return React.createElement(
      "aside",
      {
        className: "tab-panel sources-panel",
      },
      React.createElement(
        Tabs,
        {
          activeTab: tabs.indexOf(selectedTab),
          onAfterChange: this.onActivateTab,
        },
        React.createElement(
          TabPanel,
          {
            id: "sources-tab",
            key: `sources-tab${
              selectedTab === primaryPaneTabs.SOURCES ? "-selected" : ""
            }`,
            className: "tab sources-tab",
            title: L10N.getStr("sources.header"),
          },
          React.createElement(SourcesTree, null)
        ),
        React.createElement(
          TabPanel,
          {
            id: "outline-tab",
            key: `outline-tab${
              selectedTab === primaryPaneTabs.OUTLINE ? "-selected" : ""
            }`,
            className: "tab outline-tab",
            title: L10N.getStr("outline.header"),
          },
          React.createElement(Outline, {
            alphabetizeOutline: this.state.alphabetizeOutline,
            onAlphabetizeClick: this.onAlphabetizeClick,
          })
        ),
        React.createElement(
          TabPanel,
          {
            id: "search-tab",
            key: `search-tab${
              selectedTab === primaryPaneTabs.PROJECT_SEARCH ? "-selected" : ""
            }`,
            className: "tab search-tab",
            title: L10N.getStr("search.header"),
          },
          React.createElement(ProjectSearch, null)
        )
      )
    );
  }
}

const mapStateToProps = state => {
  return {
    selectedTab: getSelectedPrimaryPaneTab(state),
  };
};

const connector = connect(mapStateToProps, {
  setPrimaryPaneTab: actions.setPrimaryPaneTab,
  setActiveSearch: actions.setActiveSearch,
  closeActiveSearch: actions.closeActiveSearch,
});

export default connector(PrimaryPanes);