summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/src/modules/debug-target-collapsibilities.js
blob: efba47e03af6a7bf766e9ba7bfedad4b4d5a41e1 (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
/* 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/. */

"use strict";

const PREF_PREFIX = "devtools.aboutdebugging.collapsibilities.";
const {
  DEBUG_TARGET_PANE,
} = require("resource://devtools/client/aboutdebugging/src/constants.js");

/**
 * This module provides a collection of helper methods to read and update the debug
 * target pane's collapsibilities.
 */

/**
 * @return {Object}
 *         {
 *           key: constants.DEBUG_TARGET_PANE
 *           value: true - collapsed
 *                  false - expanded
 *         }
 */
function getDebugTargetCollapsibilities() {
  const map = new Map();

  for (const key of Object.values(DEBUG_TARGET_PANE)) {
    const pref = Services.prefs.getBoolPref(PREF_PREFIX + key, false);
    map.set(key, pref);
  }

  return map;
}
exports.getDebugTargetCollapsibilities = getDebugTargetCollapsibilities;

/**
 * @param collapsibilities - Same format to getDebugTargetCollapsibilities.
 */
function setDebugTargetCollapsibilities(collapsibilities) {
  for (const key of Object.values(DEBUG_TARGET_PANE)) {
    const isCollapsed = collapsibilities.get(key);
    Services.prefs.setBoolPref(PREF_PREFIX + key, isCollapsed);
  }
}
exports.setDebugTargetCollapsibilities = setDebugTargetCollapsibilities;