From d671130aa20f71fd879ac56bc5778175baee4691 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Mon, 11 Jan 2021 12:11:27 +0100
Subject: [PATCH] [ivette/frama-c] move to new API

---
 ivette/src/frama-c/index.tsx              | 69 +++++++++++++++++++++++
 ivette/src/frama-c/kernel/ASTinfo.tsx     | 19 +------
 ivette/src/frama-c/kernel/ASTview.tsx     | 20 +------
 ivette/src/frama-c/kernel/Locations.tsx   | 20 +------
 ivette/src/frama-c/kernel/Properties.tsx  | 21 ++-----
 ivette/src/frama-c/kernel/SourceCode.tsx  | 20 +------
 ivette/src/frama-c/plugins/dive/index.tsx | 30 +++++-----
 ivette/src/frama-c/plugins/eva/index.tsx  | 26 ++++-----
 ivette/src/renderer/Application.tsx       | 46 ++++-----------
 ivette/src/renderer/Controller.tsx        | 19 +++----
 ivette/src/renderer/LabView.tsx           |  1 -
 ivette/src/renderer/PackageLoader.tsx     |  9 +++
 12 files changed, 137 insertions(+), 163 deletions(-)
 create mode 100644 ivette/src/frama-c/index.tsx
 create mode 100644 ivette/src/renderer/PackageLoader.tsx

diff --git a/ivette/src/frama-c/index.tsx b/ivette/src/frama-c/index.tsx
new file mode 100644
index 00000000000..a63e1225775
--- /dev/null
+++ b/ivette/src/frama-c/index.tsx
@@ -0,0 +1,69 @@
+/* --------------------------------------------------------------------------*/
+/* --- Frama-C Registry                                                   ---*/
+/* --------------------------------------------------------------------------*/
+
+import React from 'react';
+import * as Ivette from 'ivette';
+
+import History from 'frama-c/kernel/History';
+import Globals from 'frama-c/kernel/Globals';
+import ASTview from 'frama-c/kernel/ASTview';
+import ASTinfo from 'frama-c/kernel/ASTinfo';
+import SourceCode from 'frama-c/kernel/SourceCode';
+import Locations from 'frama-c/kernel/Locations';
+import Properties from 'frama-c/kernel/Properties';
+
+import 'frama-c/kernel/style.css';
+
+/* --------------------------------------------------------------------------*/
+/* --- Frama-C Kernel Groups                                              ---*/
+/* --------------------------------------------------------------------------*/
+
+Ivette.registerGroup({
+  id: 'frama-c.kernel',
+  label: 'Frama-C Kernel',
+}, () => {
+  Ivette.registerSidebar({ id: 'frama-c.globals', children: <Globals /> });
+  Ivette.registerToolbar({ id: 'frama-c.history', children: <History /> });
+  Ivette.registerComponent({
+    id: 'frama-c.astview',
+    label: 'AST',
+    title: 'Normalized C/ACSL Source Code',
+    children: <ASTview />,
+  });
+  Ivette.registerComponent({
+    id: 'frama-c.astinfo',
+    label: 'Informations',
+    title: 'Informations on currently selected item',
+    children: <ASTinfo />,
+  });
+  Ivette.registerComponent({
+    id: 'frama-c.sourcecode',
+    label: 'Source Code',
+    title: 'C/ASCL Source Code',
+    children: <SourceCode />,
+  });
+  Ivette.registerComponent({
+    id: 'frama-c.locations',
+    label: 'Locations',
+    title: 'Selected list of locations',
+    children: <Locations />,
+  });
+  Ivette.registerComponent({
+    id: 'frama-c.properties',
+    label: 'Properties',
+    title: 'Status of ASCL Properties',
+    children: <Properties />,
+  });
+});
+
+/* --------------------------------------------------------------------------*/
+/* --- Frama-C Plug-ins Group                                             ---*/
+/* --------------------------------------------------------------------------*/
+
+Ivette.registerGroup({
+  id: 'frama-c.plugins',
+  label: 'Frama-C Plug-ins',
+});
+
+/* --------------------------------------------------------------------------*/
diff --git a/ivette/src/frama-c/kernel/ASTinfo.tsx b/ivette/src/frama-c/kernel/ASTinfo.tsx
index dedaf8985ea..75e85684bdb 100644
--- a/ivette/src/frama-c/kernel/ASTinfo.tsx
+++ b/ivette/src/frama-c/kernel/ASTinfo.tsx
@@ -9,14 +9,13 @@ import * as Utils from 'frama-c/utils';
 import { Vfill } from 'dome/layout/boxes';
 import { RichTextBuffer } from 'dome/text/buffers';
 import { Text } from 'dome/text/editors';
-import { Component } from 'ivette';
 import { getInfo } from 'frama-c/api/kernel/ast';
 
 // --------------------------------------------------------------------------
 // --- Information Panel
 // --------------------------------------------------------------------------
 
-const ASTinfo = () => {
+export default function ASTinfo() {
 
   const buffer = React.useMemo(() => new RichTextBuffer(), []);
   const [selection, updateSelection] = States.useSelection();
@@ -51,20 +50,6 @@ const ASTinfo = () => {
       </Vfill>
     </>
   );
-};
-
-// --------------------------------------------------------------------------
-// --- Export Component
-// --------------------------------------------------------------------------
-
-export default () => (
-  <Component
-    id="frama-c.astinfo"
-    label="Information"
-    title="AST Information"
-  >
-    <ASTinfo />
-  </Component>
-);
+}
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/frama-c/kernel/ASTview.tsx b/ivette/src/frama-c/kernel/ASTview.tsx
index 423a87859cb..7bf897426b5 100644
--- a/ivette/src/frama-c/kernel/ASTview.tsx
+++ b/ivette/src/frama-c/kernel/ASTview.tsx
@@ -11,7 +11,7 @@ import * as Utils from 'frama-c/utils';
 import * as Dome from 'dome';
 import { RichTextBuffer } from 'dome/text/buffers';
 import { Text } from 'dome/text/editors';
-import { Component, TitleBar } from 'ivette';
+import { TitleBar } from 'ivette';
 import * as Preferences from 'ivette/prefs';
 
 import * as Ast from 'frama-c/api/kernel/ast';
@@ -131,7 +131,7 @@ function makeBullet(status: States.Tag) {
 // --- AST Printer
 // --------------------------------------------------------------------------
 
-const ASTview = () => {
+export default function ASTview() {
 
   // Hooks
   const buffer = React.useMemo(() => new RichTextBuffer(), []);
@@ -291,20 +291,6 @@ const ASTview = () => {
     </>
   );
 
-};
-
-// --------------------------------------------------------------------------
-// --- Export Component
-// --------------------------------------------------------------------------
-
-export default () => (
-  <Component
-    id="frama-c.astview"
-    label="AST"
-    title="Normalized source code representation"
-  >
-    <ASTview />
-  </Component>
-);
+}
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/frama-c/kernel/Locations.tsx b/ivette/src/frama-c/kernel/Locations.tsx
index bafb5f61590..3d5f9da244b 100644
--- a/ivette/src/frama-c/kernel/Locations.tsx
+++ b/ivette/src/frama-c/kernel/Locations.tsx
@@ -11,7 +11,7 @@ import { Table, Column, Renderer } from 'dome/table/views';
 import { Label } from 'dome/controls/labels';
 import { IconButton } from 'dome/controls/buttons';
 import { Space } from 'dome/frame/toolbars';
-import { Component, TitleBar } from 'ivette';
+import { TitleBar } from 'ivette';
 import { markerInfo } from 'frama-c/api/kernel/ast';
 
 // --------------------------------------------------------------------------
@@ -20,7 +20,7 @@ import { markerInfo } from 'frama-c/api/kernel/ast';
 
 type LocationId = States.Location & { id: number };
 
-const LocationsTable = () => {
+export default function LocationsTable() {
 
   // Hooks
   const [selection, updateSelection] = States.useSelection();
@@ -134,20 +134,6 @@ const LocationsTable = () => {
       </Table>
     </>
   );
-};
-
-// --------------------------------------------------------------------------
-// --- Export Component
-// --------------------------------------------------------------------------
-
-export default () => (
-  <Component
-    id="frama-c.locations"
-    label="Locations"
-    title="Browse multiple locations"
-  >
-    <LocationsTable />
-  </Component>
-);
+}
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/frama-c/kernel/Properties.tsx b/ivette/src/frama-c/kernel/Properties.tsx
index cc71c812c83..5024f12f3e0 100644
--- a/ivette/src/frama-c/kernel/Properties.tsx
+++ b/ivette/src/frama-c/kernel/Properties.tsx
@@ -14,7 +14,7 @@ import { IconButton, Checkbox } from 'dome/controls/buttons';
 import * as Models from 'dome/table/models';
 import * as Arrays from 'dome/table/arrays';
 import { Table, Column, ColumnProps, Renderer } from 'dome/table/views';
-import { TitleBar, Component } from 'ivette';
+import { TitleBar } from 'ivette';
 import { Scroll, Folder } from 'dome/layout/boxes';
 
 import { RSplit } from 'dome/layout/splitters';
@@ -467,7 +467,8 @@ function FilterRatio({ model }: { model: PropertyModel }) {
 // --- Properties Table
 // -------------------------------------------------------------------------
 
-const RenderTable = () => {
+export default function RenderProperties() {
+
   // Hooks
   const model = React.useMemo(() => new PropertyModel(), []);
   const data = States.useSyncArray(Properties.status).getArray();
@@ -528,20 +529,6 @@ const RenderTable = () => {
       </RSplit>
     </>
   );
-};
-
-// --------------------------------------------------------------------------
-// --- Export Component
-// -------------------------------------------------------------------------
-
-export default () => (
-  <Component
-    id="frama-c.properties"
-    label="Properties"
-    title="Registered ACSL properties status"
-  >
-    <RenderTable />
-  </Component>
-);
+}
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/frama-c/kernel/SourceCode.tsx b/ivette/src/frama-c/kernel/SourceCode.tsx
index 8a9f35da7b1..9fb4f2082b3 100644
--- a/ivette/src/frama-c/kernel/SourceCode.tsx
+++ b/ivette/src/frama-c/kernel/SourceCode.tsx
@@ -9,7 +9,7 @@ import * as Dome from 'dome';
 import { readFile } from 'dome/system';
 import { RichTextBuffer } from 'dome/text/buffers';
 import { Text } from 'dome/text/editors';
-import { Component, TitleBar } from 'ivette';
+import { TitleBar } from 'ivette';
 import * as Preferences from 'ivette/prefs';
 import { functions, markerInfo } from 'frama-c/api/kernel/ast';
 import { source } from 'frama-c/api/kernel/services';
@@ -31,7 +31,7 @@ const D = new Dome.Debug('Source Code');
 // --- Source Code Printer
 // --------------------------------------------------------------------------
 
-const SourceCode = () => {
+export default function SourceCode() {
 
   // Hooks
   const buffer = React.useMemo(() => new RichTextBuffer(), []);
@@ -104,20 +104,6 @@ const SourceCode = () => {
     </>
   );
 
-};
-
-// --------------------------------------------------------------------------
-// --- Export Component
-// --------------------------------------------------------------------------
-
-export default () => (
-  <Component
-    id="frama-c.sourcecode"
-    label="Source Code"
-    title="Original source code"
-  >
-    <SourceCode />
-  </Component>
-);
+}
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/frama-c/plugins/dive/index.tsx b/ivette/src/frama-c/plugins/dive/index.tsx
index 840fa2efe0e..607b5065878 100644
--- a/ivette/src/frama-c/plugins/dive/index.tsx
+++ b/ivette/src/frama-c/plugins/dive/index.tsx
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
 import _ from 'lodash';
 import { renderToString } from 'react-dom/server';
 import * as Dome from 'dome';
+import * as Ivette from 'ivette';
 import * as Server from 'frama-c/server';
 import * as States from 'frama-c/states';
 
@@ -20,7 +21,6 @@ import './tippy.css';
 
 import { IconButton } from 'dome/controls/buttons';
 import { Space } from 'dome/frame/toolbars';
-import { Component, TitleBar } from 'ivette';
 
 import '@fortawesome/fontawesome-free/js/all';
 
@@ -495,7 +495,7 @@ class Dive {
   }
 }
 
-const GraphView = () => {
+function GraphView() {
 
   // Hooks
   const [dive, setDive] = useState(() => new Dive());
@@ -565,7 +565,7 @@ const GraphView = () => {
   // Component
   return (
     <>
-      <TitleBar>
+      <Ivette.TitleBar>
         <IconButton
           icon="LOCK"
           onClick={flipLock}
@@ -590,7 +590,7 @@ const GraphView = () => {
           onClick={() => dive.clear()}
           title="Clear the graph"
         />
-      </TitleBar>
+      </Ivette.TitleBar>
       <CytoscapeComponent
         stylesheet={style}
         cy={setCy}
@@ -599,21 +599,21 @@ const GraphView = () => {
     </>
   );
 
-};
+}
 
 // --------------------------------------------------------------------------
 // --- Export Component
 // --------------------------------------------------------------------------
 
-export default () => (
-  <Component
-    id="dive.graph"
-    label="Data-flow graph"
-    title={'Data dependency graph according to an Eva analysis.\nNodes color ' +
-      'represents the precision of the values inferred by Eva.'}
-  >
-    <GraphView />
-  </Component>
-);
+Ivette.registerComponent({
+  id: 'frama-c.plugins.dive',
+  label: 'Data-flow graph',
+  group: 'frama-c.plugins',
+  rank: 2,
+  title:
+    'Data dependency graph according to an Eva analysis.\nNodes color ' +
+    'represents the precision of the values inferred by Eva.',
+  children: <GraphView />,
+});
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/frama-c/plugins/eva/index.tsx b/ivette/src/frama-c/plugins/eva/index.tsx
index cff472e3ca9..91c24dfae8e 100644
--- a/ivette/src/frama-c/plugins/eva/index.tsx
+++ b/ivette/src/frama-c/plugins/eva/index.tsx
@@ -5,15 +5,11 @@
 // React & Dome
 import React from 'react';
 import * as Dome from 'dome';
+import * as Ivette from 'ivette';
 import { Vfill } from 'dome/layout/boxes';
 import { IconButton } from 'dome/controls/buttons';
-
-// External Libs
 import { AutoSizer } from 'react-virtualized';
 
-// Frama-C
-import { Component, TitleBar } from 'ivette';
-
 // Locals
 import { ProbeInfos } from './probeinfos';
 import { Dimension, ValuesPanel } from './valuetable';
@@ -28,7 +24,7 @@ function ValuesComponent() {
   const [zoom, setZoom] = Dome.useNumberSettings('eva-zoom-factor', 0);
   return (
     <>
-      <TitleBar>
+      <Ivette.TitleBar>
         <IconButton
           enabled={zoom > 0}
           icon="ZOOM.OUT"
@@ -39,7 +35,7 @@ function ValuesComponent() {
           icon="ZOOM.IN"
           onClick={() => setZoom(zoom + 1)}
         />
-      </TitleBar>
+      </Ivette.TitleBar>
       <Vfill>
         <ProbeInfos />
         <Vfill>
@@ -63,14 +59,12 @@ function ValuesComponent() {
 // --- Export Component
 // --------------------------------------------------------------------------
 
-export default () => (
-  <Component
-    id="frama-c.values"
-    label="Eva Values"
-    title="Values inferred by the Eva analysis"
-  >
-    <ValuesComponent />
-  </Component>
-);
+Ivette.registerComponent({
+  id: 'frama-c.plugins.values',
+  group: 'frama-c.plugins',
+  label: 'Eva Values',
+  title: 'Values inferred by the Eva analysis',
+  children: <ValuesComponent />,
+});
 
 // --------------------------------------------------------------------------
diff --git a/ivette/src/renderer/Application.tsx b/ivette/src/renderer/Application.tsx
index c32c4000916..7da66a8b13a 100644
--- a/ivette/src/renderer/Application.tsx
+++ b/ivette/src/renderer/Application.tsx
@@ -11,28 +11,11 @@ import { LSplit } from 'dome/layout/splitters';
 import * as Toolbar from 'dome/frame/toolbars';
 import * as Sidebar from 'dome/frame/sidebars';
 import { GridHbox, GridItem } from 'dome/layout/grids';
-
-// --- Ivette
-
-import { View, Group } from 'ivette';
-
-// --- Frama-C
-
-import History from 'frama-c/kernel/History';
-import Globals from 'frama-c/kernel/Globals';
-import ASTview from 'frama-c/kernel/ASTview';
-import ASTinfo from 'frama-c/kernel/ASTinfo';
-import Properties from 'frama-c/kernel/Properties';
-import Locations from 'frama-c/kernel/Locations';
-import SourceCode from 'frama-c/kernel/SourceCode';
-import Values from 'frama-c/plugins/eva';
-import Dive from 'frama-c/plugins/dive';
-
+import { View } from 'ivette';
 import * as Controller from './Controller';
 import * as Extensions from './Extensions';
-import { LabView } from './LabView';
-
-import 'frama-c/kernel/style.css';
+import * as Laboratory from './LabView';
+import './PackageLoader';
 
 // --------------------------------------------------------------------------
 // --- Main View
@@ -58,7 +41,7 @@ export default (() => {
           onClick={flipSidebar}
         />
         <Controller.Control />
-        <History />
+        <Extensions.Toolbar />
         <Toolbar.Filler />
         <Toolbar.SearchField
           placeholder="Search…"
@@ -77,9 +60,9 @@ export default (() => {
       <LSplit settings="frama-c.sidebar.split" unfold={sidebar}>
         <Sidebar.SideBar>
           <div className="sidebar-ruler" />
-          <Globals />
+          <Extensions.Sidebar />
         </Sidebar.SideBar>
-        <LabView
+        <Laboratory.LabView
           customize={viewbar}
           settings="frama-c.labview"
         >
@@ -89,14 +72,14 @@ export default (() => {
           <View id="values" label="Values">
             <GridHbox>
               <GridItem id="frama-c.astview" />
-              <GridItem id="frama-c.values" />
+              <GridItem id="frama-c.plugins.values" />
             </GridHbox>
             <GridItem id="frama-c.properties" />
           </View>
           <View id="dive" label="Dive">
             <GridHbox>
               <GridItem id="frama-c.astview" />
-              <GridItem id="dive.graph" />
+              <GridItem id="frama-c.plugins.dive" />
               <GridItem id="frama-c.locations" />
             </GridHbox>
             <GridHbox>
@@ -104,20 +87,11 @@ export default (() => {
               <GridItem id="frama-c.console" />
             </GridHbox>
           </View>
-          <Group id="frama-c" label="Frama-C" title="Frama-C Kernel Components">
-            <Controller.Console />
-            <Properties />
-            <SourceCode />
-            <ASTview />
-            <ASTinfo />
-            <Locations />
-            <Dive />
-            <Values />
-          </Group>
-        </LabView>
+        </Laboratory.LabView>
       </LSplit>
       <Toolbar.ToolBar>
         <Controller.Status />
+        <Extensions.Statusbar />
         <Toolbar.Filler />
         <Controller.Stats />
       </Toolbar.ToolBar>
diff --git a/ivette/src/renderer/Controller.tsx b/ivette/src/renderer/Controller.tsx
index 8174bf44ae6..bfbc957317e 100644
--- a/ivette/src/renderer/Controller.tsx
+++ b/ivette/src/renderer/Controller.tsx
@@ -14,7 +14,7 @@ import { RichTextBuffer } from 'dome/text/buffers';
 import { Text } from 'dome/text/editors';
 
 import * as Server from 'frama-c/server';
-import { Component, TitleBar } from 'ivette';
+import { registerComponent, TitleBar } from 'ivette';
 
 import 'codemirror/theme/ambiance.css';
 
@@ -311,15 +311,14 @@ const RenderConsole = () => {
   );
 };
 
-export const Console = () => (
-  <Component
-    id="frama-c.console"
-    label="Console"
-    title="Frama-C Server Output & Command Line"
-  >
-    <RenderConsole />
-  </Component>
-);
+registerComponent({
+  id: 'frama-c.console',
+  group: 'frama-c.kernel',
+  label: 'Console',
+  title: 'Frama-C Server Output & Command Line',
+  rank: -1,
+  children: <RenderConsole />,
+});
 
 // --------------------------------------------------------------------------
 // --- Status
diff --git a/ivette/src/renderer/LabView.tsx b/ivette/src/renderer/LabView.tsx
index eb220ac43b5..3218c3e4d70 100644
--- a/ivette/src/renderer/LabView.tsx
+++ b/ivette/src/renderer/LabView.tsx
@@ -145,7 +145,6 @@ export function addLibraryItem(
   { id, ...props }: any,
 ) {
   const itemId = `${fd}.${id}`;
-  console.log('ITEM', itemId, group, order, props);
   LIBRARY.addItem(itemId, group, order, props);
 }
 
diff --git a/ivette/src/renderer/PackageLoader.tsx b/ivette/src/renderer/PackageLoader.tsx
new file mode 100644
index 00000000000..df0c5edbe93
--- /dev/null
+++ b/ivette/src/renderer/PackageLoader.tsx
@@ -0,0 +1,9 @@
+/* --------------------------------------------------------------------------*/
+/* --- This file is intended to be generated                              ---*/
+/* --------------------------------------------------------------------------*/
+
+import 'frama-c';
+import 'frama-c/plugins/eva';
+import 'frama-c/plugins/dive';
+
+/* --------------------------------------------------------------------------*/
-- 
GitLab