Skip to content
Snippets Groups Projects
Commit e9b5fcfd authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[ivette] refactor AST toolbar

parent 5333aa72
No related branches found
No related tags found
No related merge requests found
...@@ -7,17 +7,23 @@ import * as Server from 'frama-c/server'; ...@@ -7,17 +7,23 @@ import * as Server from 'frama-c/server';
import * as States from 'frama-c/states'; import * as States from 'frama-c/states';
import * as Dome from 'dome'; import * as Dome from 'dome';
import { Vfill } from 'dome/layout/boxes';
import { RichTextBuffer } from 'dome/text/buffers'; import { RichTextBuffer } from 'dome/text/buffers';
import { Text } from 'dome/text/editors'; import { Text } from 'dome/text/editors';
import { Select, Switch, IconButton } from 'dome/controls/buttons'; import { Select, IconButton } from 'dome/controls/buttons';
import * as Toolbars from 'dome/frame/toolbars'; import { Space } from 'dome/frame/toolbars';
import { Component, TitleBar } from 'frama-c/LabViews'; import { Component, TitleBar } from 'frama-c/LabViews';
import 'codemirror/mode/clike/clike'; import 'codemirror/mode/clike/clike';
import 'codemirror/theme/ambiance.css'; import 'codemirror/theme/ambiance.css';
import 'codemirror/theme/solarized.css'; import 'codemirror/theme/solarized.css';
const THEMES = [
{ id: "default", label: "Default" },
{ id: "ambiance", label: "Ambiance" },
{ id: "solarized light", label: "Solarized Light" },
{ id: "solarized dark", label: "Solarized Dark" }
];
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Rich Text Printer // --- Rich Text Printer
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -63,21 +69,18 @@ async function loadAST(buffer: any, theFunction?: string, theMarker?: string) { ...@@ -63,21 +69,18 @@ async function loadAST(buffer: any, theFunction?: string, theMarker?: string) {
// --- AST Printer // --- AST Printer
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
function useGlobal(param: string, dft: any) {
return Dome.useGlobalSetting(`ASTview.${param}`, dft);
}
const ASTview = () => { const ASTview = () => {
// Hooks // Hooks
const buffer = React.useMemo(() => new RichTextBuffer(), []); const buffer = React.useMemo(() => new RichTextBuffer(), []);
const printed = React.useRef(); const printed = React.useRef();
const [select, setSelect] = States.useSelection(); const [select, setSelect] = States.useSelection();
const [theme, setTheme] = Dome.useGlobalSetting('AST.theme', 'default');
const [fontSize, setFontSize] = Dome.useGlobalSetting('AST.fontSize', 12);
const [lineWrapping, setLineWrapping] = Dome.useSwitch('ASTview.lineWrapping', false);
const theFunction = select && select.function; const theFunction = select && select.function;
const theMarker = select && select.marker; const theMarker = select && select.marker;
const [theme, setTheme] = useGlobal('theme', 'default');
const [lineWrapping, setLineWrapping] = useGlobal('lineWrapping', false);
const [fontSize, setFontSize] = useGlobal('fontSize', 12);
// Hook: async loading // Hook: async loading
React.useEffect(() => { React.useEffect(() => {
...@@ -93,56 +96,35 @@ const ASTview = () => { ...@@ -93,56 +96,35 @@ const ASTview = () => {
}, [buffer, theMarker]); }, [buffer, theMarker]);
// Callbacks // Callbacks
const zoomIn = () => setFontSize(fontSize + 2);
const zoomOut = () => setFontSize(fontSize - 2);
const onSelection = (marker: any) => setSelect({ marker }); const onSelection = (marker: any) => setSelect({ marker });
const titlebar = ( // Theme Popup
<TitleBar>
<Select const checkTheme = (th: { id: string }) => ({ checked: th.id === theme, ...th });
value={theme} const selectTheme = (id?: string) => id && setTheme(id);
onChange={(name: string) => setTheme(name)} const themePopup = () => Dome.popupMenu(THEMES.map(checkTheme), selectTheme);
>
<option value="default" label="Default" />
<option value="ambiance" label="Ambiance" />
<option value="solarized light" label="Solarized light" />
<option value="solarized dark" label="Solarized dark" />
</Select>
<Toolbars.Space />
<IconButton
icon="MINUS"
title="Decrease the font size"
onClick={() => setFontSize(fontSize - 2)}
/>
<IconButton
icon="PLUS"
title="increase the font size"
onClick={() => setFontSize(fontSize + 2)}
/>
<Toolbars.Space />
<Switch
label="Line wrapping"
title="Change line wrapping mode"
value={lineWrapping}
onChange={() => setLineWrapping(!lineWrapping)}
/>
<Toolbars.Space />
</TitleBar>
);
// Component // Component
return ( return (
<> <>
{titlebar} <TitleBar>
<Vfill style={{ fontSize }}> <IconButton icon="ZOOM.OUT" onClick={zoomOut} />
<Text <IconButton icon="ZOOM.IN" onClick={zoomIn} />
buffer={buffer} <IconButton icon="CODE" onClick={themePopup} />
mode="text/x-csrc" <IconButton icon="WRAPTEXT" selected={lineWrapping} onClick={setLineWrapping} />
theme={theme} </TitleBar>
lineWrapping={lineWrapping} <Text
selection={theMarker} buffer={buffer}
onSelection={onSelection} mode="text/x-csrc"
readOnly theme={theme}
/> fontSize={fontSize}
</Vfill> lineWrapping={lineWrapping}
selection={theMarker}
onSelection={onSelection}
readOnly
/>
</> </>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment