Debian Codegraph @

ivette/src/renderer/Preferences.tsx

raw
1 /* ************************************************************************ */
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /* ************************************************************************ */
22
23 /* eslint-disable @typescript-eslint/explicit-function-return-type */
24
25 // --------------------------------------------------------------------------
26 // --- Main React Component rendered by './index.js'
27 // --------------------------------------------------------------------------
28
29 /*
30 Template from $(DOME)/template/Settings.js
31
32 This module shall export a React Component that
33 will be rendered (with empty props and children)
34 in the settings window of your application.
35
36 */
37
38 import React from 'react';
39
40 import * as Settings from 'dome/data/settings';
41 import * as Forms from 'dome/layout/forms';
42 import * as Themes from 'dome/themes';
43 import * as IvettePrefs from 'ivette/prefs';
44
45 // --------------------------------------------------------------------------
46 // --- Theme Fields
47 // --------------------------------------------------------------------------
48
49 const themeOptions: Forms.MenuFieldOption<Themes.ColorSettings>[] = [
50 { value: 'light', label: 'Light Theme' },
51 { value: 'dark', label: 'Dark Theme' },
52 { value: 'system', label: 'System Defaults' },
53 ];
54
55 function ThemeFields(): JSX.Element {
56 const state = Forms.useValid(Themes.useColorThemeSettings());
57 return (
58 <Forms.MenuField<Themes.ColorSettings>
59 label="Color Theme"
60 title="Select global color theme for the application"
61 state={state}
62 defaultValue='system'
63 options={themeOptions}
64 />
65 );
66 }
67
68 // --------------------------------------------------------------------------
69 // --- Editor Fields
70 // --------------------------------------------------------------------------
71
72 function EditorFields() {
73 const fontsize = Forms.useValid(
74 Settings.useGlobalSettings(IvettePrefs.EditorFontSize)
75 );
76 const cmd = Forms.useDefined(Forms.useValid(
77 Settings.useGlobalSettings(IvettePrefs.EditorCommand)
78 ));
79 const titleCmd =
80 'Command to open an external editor on Ctrl-click in the source code view.'
81 + '\nUse %s for the file name, %n for the line number'
82 + ' and %c for the selected character.';
83 return (
84 <>
85 <Forms.SliderField
86 state={fontsize}
87 label="Font Size"
88 title={`Set the font size of editors`}
89 min={8}
90 max={32}
91 step={2}
92 />
93 <Forms.TextCodeField
94 state={cmd}
95 label="Command"
96 title={titleCmd}
97 />
98 </>
99 );
100 }
101
102 // --------------------------------------------------------------------------
103 // --- Console Scrollback Forms
104 // --------------------------------------------------------------------------
105 function ConsoleScrollbackFields(props: IvettePrefs.ConsoleScrollbackProps) {
106 const scrollback = Forms.useDefined(Forms.useValid(
107 Settings.useGlobalSettings(props.scrollback),
108 ));
109 const title = 'Maximum number of lines in the console window';
110 return (<Forms.NumberField state={scrollback} label="Lines" title={title} />);
111 }
112
113 // --------------------------------------------------------------------------
114 // --- Export Components
115 // --------------------------------------------------------------------------
116
117 export default function Preferences() {
118 return (
119 <Forms.Page>
120 <Forms.Section label="Theme" unfold>
121 <ThemeFields />
122 </Forms.Section>
123 <Forms.Section label="Editors" unfold>
124 <EditorFields />
125 </Forms.Section>
126 <Forms.Section label="Console Scrollback" unfold>
127 <ConsoleScrollbackFields scrollback={IvettePrefs.ConsoleScrollback} />
128 </Forms.Section>
129 </Forms.Page>
130 );
131 }
132
133 // --------------------------------------------------------------------------