forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.ts
More file actions
95 lines (79 loc) · 3.17 KB
/
shell.ts
File metadata and controls
95 lines (79 loc) · 3.17 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
90
91
92
93
94
95
namespace pxt.shell {
export enum EditorLayoutType {
IDE,
Sandbox,
Widget,
Controller
}
let layoutType: EditorLayoutType;
let editorReadonly: boolean = false;
let noDefaultProject: boolean = false;
function init() {
if (layoutType !== undefined) return;
if (!pxt.BrowserUtils.hasWindow()) {
layoutType = EditorLayoutType.Sandbox;
} else {
const sandbox = /sandbox=1|#sandbox|#sandboxproject/i.test(window.location.href)
// in iframe
|| pxt.BrowserUtils.isIFrame();
const nosandbox = /nosandbox=1/i.test(window.location.href);
const controller = /controller=1/i.test(window.location.href) && pxt.BrowserUtils.isIFrame();
const readonly = /readonly=1/i.test(window.location.href);
const layout = /editorlayout=(widget|sandbox|ide)/i.exec(window.location.href);
const noproject = /noproject=1/i.test(window.location.href);
layoutType = EditorLayoutType.IDE;
if (nosandbox)
layoutType = EditorLayoutType.Widget;
else if (controller)
layoutType = EditorLayoutType.Controller;
else if (sandbox)
layoutType = EditorLayoutType.Sandbox;
if (controller && readonly) editorReadonly = true;
if (controller && noproject) noDefaultProject = true;
if (layout) {
switch (layout[1].toLowerCase()) {
case "widget": layoutType = EditorLayoutType.Widget; break;
case "sandbox": layoutType = EditorLayoutType.Sandbox; break;
case "ide": layoutType = EditorLayoutType.IDE; break;
}
}
}
pxt.debug(`shell: layout type ${EditorLayoutType[layoutType]}, readonly ${isReadOnly()}`);
}
export function layoutTypeClass(): string {
init();
return pxt.shell.EditorLayoutType[layoutType].toLowerCase();
}
export function isSandboxMode() {
init();
return layoutType == EditorLayoutType.Sandbox;
}
export function isReadOnly() {
return (!pxt.BrowserUtils.hasWindow() || (isSandboxMode()
&& !/[?&]edit=1/i.test(window.location.href)) ||
(isControllerMode() && editorReadonly));
}
export function isNoProject() {
return noDefaultProject;
}
export function isControllerMode() {
init();
return layoutType == EditorLayoutType.Controller;
}
export function isPyLangPref(): boolean {
return pxt.storage.getLocal("editorlangpref") == "py";
}
export function getEditorLanguagePref(): string {
return pxt.storage.getLocal("editorlangpref");
}
export function setEditorLanguagePref(lang: string): void {
if (lang.match(/prj$/)) lang = lang.replace(/prj$/, "")
pxt.storage.setLocal("editorlangpref", lang);
}
export function getToolboxAnimation(): string {
return pxt.storage.getLocal("toolboxanimation");
}
export function setToolboxAnimation(): void {
pxt.storage.setLocal("toolboxanimation", "1");
}
}