diff --git a/ivette/src/frama-c/kernel/ASTview.tsx b/ivette/src/frama-c/kernel/ASTview.tsx index 31dc6fd65b1ee9093d73ea72d0444595374661c6..e98cb526378526a9edc93cfa001493d4c42ee5ce 100644 --- a/ivette/src/frama-c/kernel/ASTview.tsx +++ b/ivette/src/frama-c/kernel/ASTview.tsx @@ -35,8 +35,8 @@ import * as Utils from 'frama-c/utils'; import * as Dome from 'dome'; import { RichTextBuffer } from 'dome/text/buffers'; import { Text } from 'dome/text/editors'; -import { TitleBar } from 'ivette'; import * as Preferences from 'ivette/prefs'; +import * as Settings from 'dome/data/settings'; import * as Ast from 'frama-c/kernel/api/ast'; import * as Properties from 'frama-c/kernel/api/properties'; @@ -164,12 +164,7 @@ export default function ASTview() { const multipleSelections = selection?.multiple.allSelections; const theFunction = selection?.current?.fct; const theMarker = selection?.current?.marker; - const { buttons: editorButtons, fontSize, wrapText } = - Preferences.useEditorButtons({ - fontSize: Preferences.AstFontSize, - wrapText: Preferences.AstWrapText, - disabled: !theFunction, - }); + const [fontSize] = Settings.useGlobalSettings(Preferences.EditorFontSize); const markersInfo = States.useSyncArray(Ast.markerInfo); const deadCode = States.useRequest(getDeadCode, theFunction); @@ -303,14 +298,10 @@ export default function ASTview() { // Component return ( <> - <TitleBar> - {editorButtons} - </TitleBar> <Text buffer={buffer} mode="text/x-csrc" fontSize={fontSize} - lineWrapping={wrapText} selection={theMarker} onSelection={onSelection} onContextMenu={onContextMenu} diff --git a/ivette/src/frama-c/kernel/SourceCode.tsx b/ivette/src/frama-c/kernel/SourceCode.tsx index a178a293277744671eec245f2ee2d0805ceceaa7..ee222433767d50953af8b5cbd2388ab532db0633 100644 --- a/ivette/src/frama-c/kernel/SourceCode.tsx +++ b/ivette/src/frama-c/kernel/SourceCode.tsx @@ -79,13 +79,8 @@ export default function SourceCode(): JSX.Element { const line = sloc ? sloc.line : 0; const filename = Path.parse(file).base; - // Title bar buttons, along with the parameters for our text. - const { buttons: editorButtons, fontSize, wrapText } = - Preferences.useEditorButtons({ - fontSize: Preferences.SourceFontSize, - wrapText: Preferences.AstWrapText, - disabled: !theFunction, - }); + // Global Font Size + const [fontSize] = Settings.useGlobalSettings(Preferences.EditorFontSize); // Updating the buffer content. const text = React.useMemo(async () => { @@ -194,15 +189,13 @@ export default function SourceCode(): JSX.Element { onClick={launchEditor} title={externalEditorTitle} /> - <Code title={file} style={{ padding: '5px' }}>{filename}</Code> + <Code title={file}>{filename}</Code> <Hfill /> - {editorButtons} </TitleBar> <Text buffer={buffer} mode="text/x-csrc" fontSize={fontSize} - lineWrapping={wrapText} selection={theMarker} lineNumbers={!!theFunction} styleActiveLine={!!theFunction} diff --git a/ivette/src/ivette/prefs.tsx b/ivette/src/ivette/prefs.tsx index 4ae1a9b2c009410f81c2af6449fe57eedcee3277..75d501a8378c761683f88103d3790ad41b3a51f4 100644 --- a/ivette/src/ivette/prefs.tsx +++ b/ivette/src/ivette/prefs.tsx @@ -34,23 +34,13 @@ import * as Dome from 'dome'; import * as Themes from 'dome/themes'; import * as Toolbar from 'dome/frame/toolbars'; import * as Settings from 'dome/data/settings'; -import { IconButton } from 'dome/controls/buttons'; import 'codemirror/mode/clike/clike'; -// -------------------------------------------------------------------------- -// --- AST View Preferences -// -------------------------------------------------------------------------- - -export const AstFontSize = new Settings.GNumber('ASTview.fontSize', 12); -export const AstWrapText = new Settings.GFalse('ASTview.wrapText'); -export const SourceFontSize = new Settings.GNumber('SourceCode.fontSize', 12); -export const SourceWrapText = new Settings.GFalse('SourceCode.wrapText'); - /* -------------------------------------------------------------------------- */ /* --- Theme Switcher Button --- */ /* -------------------------------------------------------------------------- */ -export function ThemeSwitch(): JSX.Element { +export function ThemeSwitchTool(): JSX.Element { const [theme, setTheme] = Themes.useColorTheme(); const other = theme === 'dark' ? 'light' : 'dark'; const position = theme === 'dark' ? 'left' : 'right'; @@ -66,70 +56,40 @@ export function ThemeSwitch(): JSX.Element { ); } -// -------------------------------------------------------------------------- -// --- Editor Icon Buttons -// -------------------------------------------------------------------------- - -export interface EditorProps { - fontSize: Settings.GlobalSettings<number>; - wrapText: Settings.GlobalSettings<boolean>; - disabled?: boolean; -} - -export interface EditorControls { - buttons: React.ReactNode; - fontSize: number; - wrapText: boolean; -} +/* -------------------------------------------------------------------------- */ +/* --- Font Size Buttons Group --- */ +/* -------------------------------------------------------------------------- */ -export function useEditorButtons(props: EditorProps): EditorControls { - const { disabled = false } = props; - const [fontSize, setFontSize] = Settings.useGlobalSettings(props.fontSize); - const [wrapText, setWrapText] = Settings.useGlobalSettings(props.wrapText); +export function FontTools(): JSX.Element { + const [fontSize, setFontSize] = Settings.useGlobalSettings(EditorFontSize); const zoomIn = (): void => setFontSize(fontSize + 2); const zoomOut = (): void => setFontSize(fontSize - 2); - const flipWrapText = (): void => setWrapText(!wrapText); - return { - fontSize, - wrapText, - buttons: [ - <IconButton - key="zoom.out" + return ( + <Toolbar.ButtonGroup> + <Toolbar.Button icon="ZOOM.OUT" onClick={zoomOut} enabled={fontSize > 4} - disabled={disabled} title="Decrease font size" - />, - <IconButton - key="zoom.in" + /> + <Toolbar.Button icon="ZOOM.IN" onClick={zoomIn} enabled={fontSize < 48} - disabled={disabled} title="Increase font size" - />, - <IconButton - key="wrap" - icon="WRAPTEXT" - selected={wrapText} - disabled={disabled} - onClick={flipWrapText} - title="Wrap text" - />, - ], - }; + /> + </Toolbar.ButtonGroup> + ); } // -------------------------------------------------------------------------- -// --- Editor configuration +// --- AST View Preferences // -------------------------------------------------------------------------- +export const EditorFontSize = + new Settings.GNumber('Editor.fontSize', 12); + export const EditorCommand = new Settings.GString('Editor.Command', 'emacs +%n:%c %s'); -export interface EditorCommandProps { - command: Settings.GlobalSettings<string>; -} - // -------------------------------------------------------------------------- diff --git a/ivette/src/renderer/Application.tsx b/ivette/src/renderer/Application.tsx index ea4a07a1a0b540a7c66cc3708816d31926a9c692..b3ead33936b44072cc8e0354aaa068020574a3ff 100644 --- a/ivette/src/renderer/Application.tsx +++ b/ivette/src/renderer/Application.tsx @@ -70,7 +70,8 @@ export default function Application(): JSX.Element { onHint={Extensions.onSearchHint} onSelect={onSelectedHints} /> - <IvettePrefs.ThemeSwitch /> + <IvettePrefs.ThemeSwitchTool /> + <IvettePrefs.FontTools /> <Toolbar.Button icon="ITEMS.GRID" title="Customize Main View" diff --git a/ivette/src/renderer/Preferences.tsx b/ivette/src/renderer/Preferences.tsx index 8056ec84f5ffae3c5f2b6f2d03afc5e77a00185a..1a2ee3750afae6c72dd903444c552a9070c70bbb 100644 --- a/ivette/src/renderer/Preferences.tsx +++ b/ivette/src/renderer/Preferences.tsx @@ -69,53 +69,36 @@ function ThemeFields(): JSX.Element { // --- Editor Fields // -------------------------------------------------------------------------- -interface EditorFieldProps extends IvettePrefs.EditorProps { - target: string; -} - -function EditorFields(props: EditorFieldProps) { +function EditorFields() { const fontsize = Forms.useValid( - Settings.useGlobalSettings(props.fontSize), - ); - const wraptext = Forms.useValid( - Settings.useGlobalSettings(props.wrapText), + Settings.useGlobalSettings(IvettePrefs.EditorFontSize) ); - const { target } = props; + const cmd = Forms.useDefined(Forms.useValid( + Settings.useGlobalSettings(IvettePrefs.EditorCommand) + )); + const titleCmd = + 'Command to open an external editor on Ctrl-click in the source code view.' + + '\nUse %s for the file name, %n for the line number' + + ' and %c for the selected character.'; return ( <> <Forms.SliderField state={fontsize} label="Font Size" - title={`Set the font size of ${target}`} + title={`Set the font size of editors`} min={8} max={32} step={2} /> - <Forms.CheckboxField - state={wraptext} - label="Wrap Text" - title={`Set long line wrapping mode of ${target}`} + <Forms.TextCodeField + state={cmd} + label="Command" + title={titleCmd} /> </> ); } - - -// -------------------------------------------------------------------------- -// --- Editor Command Forms -// -------------------------------------------------------------------------- -function EditorCommandFields(props: IvettePrefs.EditorCommandProps) { - const cmd = Forms.useDefined(Forms.useValid( - Settings.useGlobalSettings(props.command), - )); - const title = - 'Command to open an external editor on Ctrl-click in the source code view.' - + '\nUse %s for the file name, %n for the line number' - + ' and %c for the selected character.'; - return (<Forms.TextCodeField state={cmd} label="Command" title={title} />); -} - // -------------------------------------------------------------------------- // --- Export Components // -------------------------------------------------------------------------- @@ -126,22 +109,8 @@ export default function Preferences() { <Forms.Section label="Theme" unfold> <ThemeFields /> </Forms.Section> - <Forms.Section label="AST View" unfold> - <EditorFields - target="Internal AST" - fontSize={IvettePrefs.AstFontSize} - wrapText={IvettePrefs.AstWrapText} - /> - </Forms.Section> - <Forms.Section label="Source View" unfold> - <EditorFields - target="Source Code" - fontSize={IvettePrefs.SourceFontSize} - wrapText={IvettePrefs.SourceWrapText} - /> - </Forms.Section> - <Forms.Section label="Editor Command" unfold> - <EditorCommandFields command={IvettePrefs.EditorCommand} /> + <Forms.Section label="Editors" unfold> + <EditorFields /> </Forms.Section> </Forms.Page> );