Skip to content
Snippets Groups Projects
Commit 19ba78e4 authored by David Bühler's avatar David Bühler
Browse files

[ivette] New component MultipleSelection: table of multiple selected locations.

parent 52af885d
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import ASTview from './ASTview'; ...@@ -20,6 +20,7 @@ import ASTview from './ASTview';
import ASTinfo from './ASTinfo'; import ASTinfo from './ASTinfo';
import Globals from './Globals'; import Globals from './Globals';
import Properties from './Properties'; import Properties from './Properties';
import MultipleSelection from './MultipleSelection';
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Selection Controls // --- Selection Controls
...@@ -99,6 +100,7 @@ export default (() => { ...@@ -99,6 +100,7 @@ export default (() => {
<Properties /> <Properties />
<ASTview /> <ASTview />
<ASTinfo /> <ASTinfo />
<MultipleSelection />
</Group> </Group>
</LabView> </LabView>
</Splitter> </Splitter>
......
// --------------------------------------------------------------------------
// --- Table of multiple selection
// --------------------------------------------------------------------------
import React from 'react';
import * as States from 'frama-c/states';
import { ArrayModel } from 'dome/table/arrays';
import { Table, Column } from 'dome/table/views';
import { Label } from 'dome/controls/labels';
import * as Toolbar from 'dome/frame/toolbars';
import { Component } from 'frama-c/LabViews';
// --------------------------------------------------------------------------
// --- Multiple Selection Panel
// --------------------------------------------------------------------------
const SelectionTable = () => {
// Hooks
const [selection, updateSelection] = States.useSelection();
const length = selection?.multiple?.length;
const multiple: States.Location[] = selection?.multiple;
const model = React.useMemo(() => new ArrayModel('id'), []);
// Updates [[model]] with the current multiple selection.
React.useEffect(() => {
if (multiple?.length > 0) {
const array = multiple.map((d, i) => ({ ...d, id: i }));
model.replace(array);
} else
model.clear();
}, [multiple, model]);
// Callbacks
const onTableSelection = React.useCallback(
({ id }) => updateSelection({ index: id }),
[updateSelection],
);
const reload = () => {
const location = multiple[selection?.index];
updateSelection({ location });
};
// Component
return (
<>
<Toolbar.ToolBar>
<Toolbar.Button
icon="RELOAD"
onClick={reload}
enabled={length > 1}
title="Reload the current location of the multiple selection"
/>
<Toolbar.ButtonGroup>
<Toolbar.Button
icon="ANGLE.LEFT"
onClick={() => updateSelection('PREV')}
enabled={length > 1 && selection?.index > 0}
title="Previous location of the multiple selection"
/>
<Toolbar.Button
icon="ANGLE.RIGHT"
onClick={() => updateSelection('NEXT')}
enabled={length > 1 && selection?.index < length - 1}
title="Next location of the multiple selection"
/>
</Toolbar.ButtonGroup>
<Label
className="component-info"
title={`${length} selected locations`}
display={length > 1}
>
{selection?.index + 1} / {length}
</Label>
<Toolbar.Filler />
<Toolbar.Button
icon="CIRC.CLOSE"
onClick={() => updateSelection('CLEAR')}
enabled={length > 1}
title="Clear the multiple selection"
/>
</Toolbar.ToolBar>
<Table
model={model}
selection={selection?.index}
onSelection={onTableSelection}
>
<Column
id="id"
label="#"
align="center"
width={25}
getter={(r: {id: number}) => r.id + 1}
/>
<Column id="function" label="Function" width={120} />
<Column id="marker" label="Marker" fill />
</Table>
</>
);
};
// --------------------------------------------------------------------------
// --- Export Component
// --------------------------------------------------------------------------
export default () => (
<Component
id="frama-c.selection"
label="Multiple Selection"
title="Browse a selection of multiple locations"
>
<SelectionTable />
</Component>
);
// --------------------------------------------------------------------------
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