forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameMenu.js
More file actions
89 lines (72 loc) · 2.39 KB
/
Copy pathFrameMenu.js
File metadata and controls
89 lines (72 loc) · 2.39 KB
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
/* 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/>. */
// @flow
import { showMenu } from "devtools-contextmenu";
import { copyToTheClipboard } from "../../../utils/clipboard";
import type { LocalFrame } from "./types";
import type { ContextMenuItem } from "../../../types";
import { kebabCase } from "lodash";
const blackboxString = "sourceFooter.blackbox";
const unblackboxString = "sourceFooter.unblackbox";
function formatMenuElement(
labelString: string,
click: Function,
disabled: boolean = false
): ContextMenuItem {
const label = L10N.getStr(labelString);
const accesskey = L10N.getStr(`${labelString}.accesskey`);
const id = `node-menu-${kebabCase(label)}`;
return {
id,
label,
accesskey,
disabled,
click
};
}
function copySourceElement(url) {
return formatMenuElement("copySourceUri2", () => copyToTheClipboard(url));
}
function copyStackTraceElement(copyStackTrace) {
return formatMenuElement("copyStackTrace", () => copyStackTrace());
}
function toggleFrameworkGroupingElement(
toggleFrameworkGrouping,
frameworkGroupingOn
) {
const actionType = frameworkGroupingOn
? "framework.disableGrouping"
: "framework.enableGrouping";
return formatMenuElement(actionType, () => toggleFrameworkGrouping());
}
function blackBoxSource(source, toggleBlackBox) {
const toggleBlackBoxString = source.isBlackBoxed
? unblackboxString
: blackboxString;
return formatMenuElement(toggleBlackBoxString, () => toggleBlackBox(source));
}
export default function FrameMenu(
frame: LocalFrame,
frameworkGroupingOn: boolean,
callbacks: Object,
event: SyntheticKeyboardEvent<HTMLElement>
) {
event.stopPropagation();
event.preventDefault();
const menuOptions = [];
const source = frame.source;
const toggleFrameworkElement = toggleFrameworkGroupingElement(
callbacks.toggleFrameworkGrouping,
frameworkGroupingOn
);
menuOptions.push(toggleFrameworkElement);
if (source) {
const copySourceUri2 = copySourceElement(source.url);
menuOptions.push(copySourceUri2);
menuOptions.push(blackBoxSource(source, callbacks.toggleBlackBox));
}
const copyStackTraceItem = copyStackTraceElement(callbacks.copyStackTrace);
menuOptions.push(copyStackTraceItem);
showMenu(event, menuOptions);
}