From 270a9e4915276b628ff4c1aaf263059e1da8b0c1 Mon Sep 17 00:00:00 2001 From: rlazarini <remi.lazarini@cea.fr> Date: Wed, 22 Jan 2025 16:01:53 +0100 Subject: [PATCH] [Ivette] transform FctItem component to function + added infos on file section --- .../src/dome/renderer/controls/gallery.json | 2 +- ivette/src/frama-c/kernel/Globals.tsx | 48 +++++++++---------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/ivette/src/dome/renderer/controls/gallery.json b/ivette/src/dome/renderer/controls/gallery.json index 2f6832c0d66..a88f2cbb674 100644 --- a/ivette/src/dome/renderer/controls/gallery.json +++ b/ivette/src/dome/renderer/controls/gallery.json @@ -193,7 +193,7 @@ "FUNCTION": { "section": "Signs", "viewBox": "0 0 512 512", - "path": "M258.317 237.971h-50.626c3.055-17.94 5.876-34.786 8.06-47.875c7.479-44.859 18.362-89.92 28.792-105.361 c11.671-17.281 34.734-8.966 43.627 14.908c4.946 13.278 19.766 21.026 34.801 20.102c20.039-1.239 35.284-18.485 34.048-38.524 c-0.616-10.03-8.273-23.399-20.487-29.936c-17.264-9.456-37.299-13.859-58.424-13.005c-53.37 2.142-93.577 47.609-108.941 97.773 c-5.796 18.933-14.324 60.825-22.212 101.918h-57.92l-9.092 35.228h60.341c-4.836 25.821-8.952 48.184-11.332 59.977 c-6.975 34.576-16.809 96.653-49.552 100.944c-12.823-4.9-17.614-10.366-22.437-15.678c-6.442-7.104-15.941-11.318-26.254-10.682 c-18.037 1.113-31.759 16.63-30.646 34.668c1.112 18.037 17.257 27.962 34.675 30.65c99.4 8.889 137.624-63.47 152.176-122.985 c3.338-13.655 8.99-44.32 14.702-76.894h47.612L258.317 237.971zM504.553 363.021c-6.206 0-12.41 4.542-11.171 11.36c4.101 22.524-24.638 34.794-47.158 32.953 c-34.776-2.849-45.268-38.504-56.929-74.424c-0.598-1.834-1.186-3.696-1.771-5.564c7.052-12.004 14.146-24.176 19.056-32.778 c11.399-19.977 24.456-39.462 32.106-44.964c-0.479 0.35 18.02-10.128 18.097 14.713c0.022 7.167 5.701 13.439 12.998 15.636 c9.729 2.918 19.98-2.597 22.909-12.326c1.459-4.864 0.168-12.55-4.487-17.793c-6.537-7.51-18.688-15.153-28.861-18.45 c-25.709-8.322-52.747 6.216-68.818 27.333c-4.452 5.851-10.398 15.056-16.589 25.086c-8.85-25.625-19.738-47.385-38.156-53.706 c-42.294-14.523-65.772 19.067-65.772 29.537c0 12.494 34.748-5.676 53.366 39.764c6.134 14.993 10.954 27.619 15.937 41.198 c-8.616 14.838-18.24 31.546-24.392 42.493c-11.269 20.054-24.193 39.624-31.805 45.181c-8.533 6.215-18.069-1.701-18.199-14.594 c-0.066-7.16-5.788-13.396-13.099-15.545c-9.75-2.856-19.966 2.73-22.825 12.473c-1.428 4.886-0.08 12.557 4.61 17.771 c6.586 7.461 18.772 15.048 28.97 18.275c25.757 8.147 52.705-6.565 68.628-27.801c5.112-6.803 14.016-21.166 23.213-36.494 c1.19 3.275 2.408 6.642 3.706 10.212c14.891 40.897 48.061 60.698 85.63 55.665c50.882-6.817 67.012-56.806 68.254-77.258 C512 370.972 510.758 363.021 504.553 363.021z" + "path": "M258.317 237.971h-50.626c3.055-17.94 5.876-34.786 8.06-47.875c7.479-44.859 18.362-89.92 28.792-105.361 c11.671-17.281 34.734-8.966 43.627 14.908c4.946 13.278 19.766 21.026 34.801 20.102c20.039-1.239 35.284-18.485 34.048-38.524 c-0.616-10.03-8.273-23.399-20.487-29.936c-17.264-9.456-37.299-13.859-58.424-13.005c-53.37 2.142-93.577 47.609-108.941 97.773 c-5.796 18.933-14.324 60.825-22.212 101.918h-57.92l-9.092 35.228h60.341c-4.836 25.821-8.952 48.184-11.332 59.977 c-6.975 34.576-16.809 96.653-49.552 100.944c-12.823-4.9-17.614-10.366-22.437-15.678c-6.442-7.104-15.941-11.318-26.254-10.682 c-18.037 1.113-31.759 16.63-30.646 34.668c1.112 18.037 17.257 27.962 34.675 30.65c99.4 8.889 137.624-63.47 152.176-122.985 c3.338-13.655 8.99-44.32 14.702-76.894h47.612L258.317 237.971z" }, "SPINNER": { "section": "Signs", diff --git a/ivette/src/frama-c/kernel/Globals.tsx b/ivette/src/frama-c/kernel/Globals.tsx index 845aca9f3d6..1aa05427617 100644 --- a/ivette/src/frama-c/kernel/Globals.tsx +++ b/ivette/src/frama-c/kernel/Globals.tsx @@ -192,14 +192,12 @@ function List(props: ListProps): JSX.Element { // --- Function items // -------------------------------------------------------------------------- -interface FctItemProps { - fct: functionsData; - current: string | undefined; - icon?: string; -} - -function FctItem(props: FctItemProps): JSX.Element { - const { name, signature, main, stdlib, builtin, defined, decl } = props.fct; +function makeFctItem( + fct: functionsData, + scope: States.Scope, + icon?: string +): JSX.Element { + const { name, signature, main, stdlib, builtin, defined, decl } = fct; const className = classes( main && 'globals-main', (stdlib || builtin) && 'globals-stdlib', @@ -210,11 +208,12 @@ function FctItem(props: FctItemProps): JSX.Element { ); return ( <Item - icon={props.icon} + key={decl} + icon={icon} className={className} label={name} title={signature} - selected={name === props.current} + selected={decl === scope} onSelection={() => States.setCurrentScope(decl)} > {attributes && <span className="globals-attr">{attributes}</span>} @@ -339,22 +338,18 @@ export function useFunctionFilter(): FunctionFilterRet { export function Functions(props: ScrollableParent): JSX.Element { // Hooks const scope = States.useCurrentScope(); - const { kind, name } = States.useDeclaration(scope); const ker = States.useSyncArrayProxy(Ast.functions); const eva = States.useSyncArrayProxy(Eva.functions); const fcts = React.useMemo(() => computeFcts(ker, eva), [ker, eva]); const { showFunction, contextFctMenuItems } = useFunctionFilter(); - // Currently selected function. - const current = (scope && kind === 'FUNCTION') ? name : undefined; - // Filtered const items = fcts .filter(showFunction) .sort((f, g) => alpha(f.name, g.name)) - .map((fct) => <FctItem key={fct.key} fct={fct} current={current} />); + .map((fct) => makeFctItem(fct, scope)); return ( <List @@ -589,7 +584,6 @@ export function Files(props: ScrollableParent): JSX.Element { const { scrollableParent } = props; // Hooks const scope = States.useCurrentScope(); - const { kind, name } = States.useDeclaration(scope); // functions const ker = States.useSyncArrayProxy(Ast.functions); @@ -605,9 +599,6 @@ export function Files(props: ScrollableParent): JSX.Element { const [showVars, flipShowVars] = Dome.useFlipSettings('ivette.files.show.globals', true); - // Currently selected function. - const current = (scope && kind === 'FUNCTION') ? name : undefined; - interface InfosFile { label: string, fcts: functionsData[], @@ -640,17 +631,22 @@ export function Files(props: ScrollableParent): JSX.Element { return newFiles; }, [fcts, showFunction, variables, showVariable]); + const currentSection = React.useMemo(() => { + for( const path of Object.keys(files)) { + if(files[path].fcts.find(e => e.decl === scope) || + files[path].vars.find(e => e.decl === scope) + ) return path; + } + return undefined; + }, [files, scope]); + function getList([path, infos]: [string, InfosFile]): JSX.Element | null { const { label, fcts, vars } = infos; const fctsComp: JSX.Element[] = showFcts ? - fcts.map(elt => <FctItem - key={elt.key} - icon="FUNCTION" - fct={elt} - current={current} />) + fcts.map(fct => makeFctItem(fct, scope, 'FUNCTION')) : []; const varsComp: JSX.Element[] = showVars ? - vars.map((v) => makeVarItem(scope, v, "VARIABLE")) + vars.map((v) => makeVarItem(scope, v, 'VARIABLE')) : []; const items = fctsComp.concat(varsComp); if(items.length === 0) return null; @@ -660,7 +656,7 @@ export function Files(props: ScrollableParent): JSX.Element { key={path} label={label} title={path} - settings={`frama-c.sidebar.files.${path}`} + infos={currentSection === path ? '(active)' : undefined} className='globals-section' > <InfiniteScrollList scrollableParent={scrollableParent} > -- GitLab