Web Inspector: RTL: inherit system layout direction by default
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / GeneralSettingsView.js
1 /*
2  * Copyright (C) 2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WebInspector.GeneralSettingsView = class GeneralSettingsView extends WebInspector.SettingsView
27 {
28     constructor()
29     {
30         super("general", WebInspector.UIString("General"));
31     }
32
33     // Protected
34
35     initialLayout()
36     {
37         const indentValues = [WebInspector.UIString("Tabs"), WebInspector.UIString("Spaces")];
38
39         let [/* unused */, indentEditor] = this.addGroupWithCustomSetting(WebInspector.UIString("Prefer indent using:"), WebInspector.SettingEditor.Type.Select, {values: indentValues});
40         indentEditor.value = indentValues[WebInspector.settings.indentWithTabs.value ? 0 : 1];
41         indentEditor.addEventListener(WebInspector.SettingEditor.Event.ValueDidChange, () => {
42             WebInspector.settings.indentWithTabs.value = indentEditor.value === indentValues[0];
43         });
44
45         const widthLabel = WebInspector.UIString("spaces");
46         const widthOptions = {min: 1};
47
48         this.addSetting(WebInspector.UIString("Tab width:"), WebInspector.settings.tabSize, widthLabel, widthOptions);
49         this.addSetting(WebInspector.UIString("Indent width:"), WebInspector.settings.indentUnit, widthLabel, widthOptions);
50
51         this.addSetting(WebInspector.UIString("Line wrapping:"), WebInspector.settings.enableLineWrapping, WebInspector.UIString("Wrap lines to editor width"));
52
53         let showGroup = this.addGroup(WebInspector.UIString("Show:"));
54         showGroup.addSetting(WebInspector.settings.showWhitespaceCharacters, WebInspector.UIString("Whitespace characters"));
55         showGroup.addSetting(WebInspector.settings.showInvalidCharacters, WebInspector.UIString("Invalid characters"));
56
57         this.addSeparator();
58
59         let stylesEditingGroup = this.addGroup(WebInspector.UIString("Styles Editing:"));
60         stylesEditingGroup.addSetting(WebInspector.settings.stylesShowInlineWarnings, WebInspector.UIString("Show inline warnings"));
61         stylesEditingGroup.addSetting(WebInspector.settings.stylesInsertNewline, WebInspector.UIString("Automatically insert newline"));
62         stylesEditingGroup.addSetting(WebInspector.settings.stylesSelectOnFirstClick, WebInspector.UIString("Select text on first click"));
63
64         this.addSeparator();
65
66         this.addSetting(WebInspector.UIString("Network:"), WebInspector.settings.clearNetworkOnNavigate, WebInspector.UIString("Clear when page navigates"));
67
68         this.addSeparator();
69
70         this.addSetting(WebInspector.UIString("Console:"), WebInspector.settings.clearLogOnNavigate, WebInspector.UIString("Clear when page navigates"));
71
72         this.addSeparator();
73
74         this.addSetting(WebInspector.UIString("Debugger:"), WebInspector.settings.showScopeChainOnPause, WebInspector.UIString("Show Scope Chain on pause"));
75
76         this.addSeparator();
77
78         const zoomLevels = [0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.4];
79         const zoomValues = zoomLevels.map((level) => [level, Number.percentageString(level, 0)]);
80
81         let [/* unused */, zoomEditor] = this.addGroupWithCustomSetting(WebInspector.UIString("Zoom:"), WebInspector.SettingEditor.Type.Select, {values: zoomValues});
82         zoomEditor.value = WebInspector.settings.zoomFactor.value;
83         zoomEditor.addEventListener(WebInspector.SettingEditor.Event.ValueDidChange, () => { WebInspector.setZoomFactor(zoomEditor.value); });
84
85         this.addSeparator();
86
87         // This setting is only ever shown in engineering builds, so its strings are unlocalized.
88         const layoutDirectionValues = [
89             [WebInspector.LayoutDirection.System, WebInspector.unlocalizedString("System Default")],
90             [WebInspector.LayoutDirection.LTR, WebInspector.unlocalizedString("Left to Right (LTR)")],
91             [WebInspector.LayoutDirection.RTL, WebInspector.unlocalizedString("Right to Left (RTL)")],
92         ];
93
94         let [layoutDirectionGroup, layoutDirectionEditor] = this.addGroupWithCustomSetting(WebInspector.unlocalizedString("Layout Direction:"), WebInspector.SettingEditor.Type.Select, {values: layoutDirectionValues});
95         this._layoutDirectionGroup = layoutDirectionGroup;
96         layoutDirectionEditor.value = WebInspector.settings.layoutDirection.value;
97         layoutDirectionEditor.addEventListener(WebInspector.SettingEditor.Event.ValueDidChange, () => { WebInspector.setLayoutDirection(layoutDirectionEditor.value); });
98     }
99
100     layout()
101     {
102         this._layoutDirectionGroup.element.classList.toggle("hidden", !WebInspector.isDebugUIEnabled());
103     }
104 };