Skip to content
Snippets Groups Projects
Commit a5991611 authored by Maxime Jacquemin's avatar Maxime Jacquemin
Browse files

Merge branch 'feature/ivette/global-editor-fontsize' into 'master'

[ivette] use global font size buttons

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