diff --git a/ivette/src/dome/src/renderer/table/views.js b/ivette/src/dome/src/renderer/table/views.js index 0f19a5960f0d54f0ff95a08fb9d74a27d6245e37..84aedb303861a6578f3cd725c724cc942a1ab72a 100644 --- a/ivette/src/dome/src/renderer/table/views.js +++ b/ivette/src/dome/src/renderer/table/views.js @@ -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) { diff --git a/ivette/src/frama-c/states.js b/ivette/src/frama-c/states.js index 40afcd2290f61c92277e04d1a1c889bea17a4c9c..6bc2b21470fdd77f46cce80ccbbebde28fb6408f 100644 --- a/ivette/src/frama-c/states.js +++ b/ivette/src/frama-c/states.js @@ -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 }; diff --git a/ivette/src/renderer/Application.js b/ivette/src/renderer/Application.js index 61bb9744fe8e87a94022c9e26ed83d77ea4df89b..dc02e42e700aabeac0a917691473118b7d613a81 100644 --- a/ivette/src/renderer/Application.js +++ b/ivette/src/renderer/Application.js @@ -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> diff --git a/ivette/src/renderer/Properties.js b/ivette/src/renderer/Properties.js index 56efbec2c8cbef33c927b493db43a5ead8b7abd8..5b5ce8c0dcc44127fa8b84f6e6cbf010a09ddc47 100644 --- a/ivette/src/renderer/Properties.js +++ b/ivette/src/renderer/Properties.js @@ -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 }; - -// --------------------------------------------------------------------------