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

[ivette] global search bar activated

parent 15db4372
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ import * as Controller from './Controller';
import ASTview from './ASTview';
import ASTinfo from './ASTinfo';
import Globals from './Globals';
import Globals, { GlobalHint, useHints } from './Globals';
import Properties from './Properties';
import Locations from './Locations';
import Values from './Values';
......@@ -61,6 +61,14 @@ export default (() => {
Dome.useFlipSettings('frama-c.sidebar.unfold', true);
const [viewbar, flipViewbar] =
Dome.useFlipSettings('frama-c.viewbar.unfold', true);
const [hints, onSearchHint] = useHints();
const [, setSelection] = States.useSelection();
const onGlobalHint = (h: GlobalHint) => {
setSelection({ location: h.value });
};
const onSelectHint = () => {
if (hints.length === 1) onGlobalHint(hints[0]);
};
return (
<Vfill>
......@@ -74,7 +82,13 @@ export default (() => {
<Controller.Control />
<HistorySelectionControls />
<Toolbar.Filler />
<Toolbar.SearchField placeholder="Search…" />
<Toolbar.SearchField
placeholder="Search…"
hints={hints}
onSearch={onSearchHint}
onSelect={onSelectHint}
onHint={onGlobalHint}
/>
<Toolbar.Button
icon="ITEMS.GRID"
title="Customize Main View"
......
......@@ -4,12 +4,41 @@
import React from 'react';
import { Section, Item } from 'dome/frame/sidebars';
import type { Hint } from 'dome/frame/toolbars';
import * as States from 'frama-c/states';
import { alpha } from 'dome/data/compare';
import { functions, functionsData } from 'frama-c/api/kernel/ast';
// --------------------------------------------------------------------------
// --- Globals Section
// --- Global Search Hints
// --------------------------------------------------------------------------
export type GlobalHint = Hint<States.Location>;
const makeHint = (fct: functionsData): GlobalHint => ({
id: fct.key,
label: fct.name,
title: fct.signature,
value: { function: fct.name },
});
export function useHints(): [GlobalHint[], (pattern: string) => void] {
const fcts = States.useSyncArray(functions).getArray();
const [hints, setHints] = React.useState<GlobalHint[]>([]);
const onSearch = (pattern: string) => {
if (pattern === '') setHints([]);
else {
const p = pattern.toLowerCase();
setHints(fcts.filter((fn) => (
0 <= fn.name.toLowerCase().indexOf(p)
)).map(makeHint));
}
};
return [hints, onSearch];
}
// --------------------------------------------------------------------------
// --- Globals Section(s)
// --------------------------------------------------------------------------
export default () => {
......
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