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

[ivette] introduce global selection object

parent a162dae6
No related branches found
No related tags found
No related merge requests found
......@@ -534,7 +534,6 @@ export class Table extends React.Component {
selectRow({event, index, rowData:{item}}) {
this.focus = item ;
window.getSelection().empty();
if (item) {
const { model, multipleSelection , selection, onSelection } = this.props ;
if (multipleSelection) {
......
......@@ -37,7 +37,8 @@ export const STATE = 'frama-c.state.' ;
// --------------------------------------------------------------------------
var currentProject = undefined ;
var states = {} ;
var states = {};
var stateDefaults = {};
Server.onReady(() => {
Server.sendGET('kernel.project.getCurrent')
......@@ -89,16 +90,25 @@ export function setProject(project)
function getValue(id,project) {
if (!project) return undefined;
return _.get( states, [project,id] );
return _.get( states, [project,id], stateDefaults[id] );
}
function setValue(id,project,value) {
const theProject = project || currentProject ;
if (!theProject) return ;
if (!project) return ;
_.set( states, [project,id], value );
Dome.emit( STATE + id , value );
}
/**
@summary Define the default state value.
@param {string} id - the state identifier (mandatory)
@param {any} value - the new default state
*/
export function setStateDefault(id,value)
{
stateDefaults[id] = value;
}
/**
@summary Projectified State (Custom React Hook).
@param {string} id - the state identifier (mandatory)
......@@ -413,11 +423,34 @@ export function useSyncArray(id)
return a.getItems() ;
}
// --------------------------------------------------------------------------
// --- Selection
// --------------------------------------------------------------------------
const SELECTION = 'kernel.selection' ;
setStateDefault( SELECTION , {} );
/**
@sumamry Current selection state.
@return {array} `[selection,update]` for the current selection
@description
The selection is an object with many independant fields.
You update it by providing only some fields, the other ones being kept unchanged,
like the `setState()` behaviour of React components.
*/
export function useSelection()
{
const [ state, setState ] = useState( SELECTION );
return [ state, (upd) => setState(Object.assign( {}, state, upd )) ];
}
// --------------------------------------------------------------------------
export default {
useProject,
setProject,
setStateDefault,
useState,
useSyncState,
useSyncValue,
......@@ -425,6 +458,7 @@ export default {
reloadArray,
useRequest,
useDictionary,
useSelection,
PROJECT, STATE
};
......
......@@ -57,6 +57,7 @@ export default (function() {
<Group id='frama-c' label='Frama-C' title='Frama-C Kernel Components'>
<Controller.Console/>
<Properties.PropTable/>
<Properties/>
</Group>
</LabView>
</Splitter>
......
......@@ -12,7 +12,7 @@ import { Table, Column, DefineColumn } from 'dome/table/views' ;
import { Component } from 'frama-c/labviews' ;
// --------------------------------------------------------------------------
// --- Properties Array
// --- Property Columns
// --------------------------------------------------------------------------
const ColumnCode = DefineColumn({ renderValue: (text) => <Code>{text}</Code> });
......@@ -21,36 +21,56 @@ const ColumnTag = DefineColumn({ renderValue: ({ label, descr }) => (
)});
// --------------------------------------------------------------------------
// --- Columns
// --- Properties Table
// -------------------------------------------------------------------------
const RenderTable = () => {
// Hooks
const model = React.useMemo( () => new ArrayModel() , [] );
const items = States.useSyncArray('kernel.properties');
const status = States.useDictionary('kernel.dictionary.propstatus');
const [select,setSelect] = States.useSelection();
React.useEffect( () => {
model.setData( _.toArray( items ) );
}, [ model, items ]);
// Callbacks
const getStatus = ({status:st}) => status[st] || { label:st } ;
model.setData( _.toArray( items ) );
const selection = select ? items[ select.marker ] : undefined ;
const onSelection = (item) => item && setSelect({
marker: item.key,
function: item.function
});
// Rendering
return (
<Table model={model}>
<ColumnCode id='function' label='Function' width={120} />
<ColumnCode id='descr' label='Description' fill />
<ColumnTag id='status' label='Status' fixed width={80} align='center' getValue={getStatus} />
</Table>
<React.Fragment>
<Table model={model}
selection={selection}
onSelection={onSelection}
scrollTo={selection}
>
<ColumnCode id='function' label='Function' width={120} />
<ColumnCode id='descr' label='Description' fill />
<ColumnTag id='status' label='Status'
fixed width={80} align='center'
getValue={getStatus} />
</Table>
</React.Fragment>
);
};
const PropTable = () => (
// --------------------------------------------------------------------------
// --- Export Component
// -------------------------------------------------------------------------
export default () => (
<Component id='frama-c.properties'
label='Properties'
title='Registered Frama-C Property Status' >
title='Registered ACSL properties status' >
<RenderTable/>
</Component>
);
// --------------------------------------------------------------------------
// --- Exports
// --------------------------------------------------------------------------
export default { PropTable };
// --------------------------------------------------------------------------
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