From 36ebd0a23de2452554ec57e54d001c8b7f786156 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr>
Date: Thu, 21 May 2020 15:37:03 +0200
Subject: [PATCH] [ivette] ASTview: new contextual menu to go to a function
 definition.

Uses a synchronized array to get the kind of each marker. Only creates the menu
on function varinfos.
---
 ivette/src/renderer/ASTview.tsx | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/ivette/src/renderer/ASTview.tsx b/ivette/src/renderer/ASTview.tsx
index d21a73b27ea..b308be9465a 100644
--- a/ivette/src/renderer/ASTview.tsx
+++ b/ivette/src/renderer/ASTview.tsx
@@ -89,6 +89,7 @@ const ASTview = () => {
   const [theme, setTheme] = Dome.useGlobalSetting('ASTview.theme', 'default');
   const [fontSize, setFontSize] = Dome.useGlobalSetting('ASTview.fontSize', 12);
   const [wrapText, setWrapText] = Dome.useSwitch('ASTview.wrapText', false);
+  const markers = States.useSyncArray('kernel.ast.markerKind');
 
   const theFunction = select && select.function;
   const theMarker = select && select.marker;
@@ -111,6 +112,17 @@ const ASTview = () => {
   const zoomOut = () => fontSize > 4 && setFontSize(fontSize - 2);
   const onSelection = (marker: any) => setSelect({ marker });
 
+  function contextMenu(id: string) {
+    const marker = markers[id];
+    if (marker && marker.kind === 'function') {
+      const item1 = {
+        label: `Go to definition of ${marker.name}`,
+        onClick: () => setSelect({ function: marker.name }),
+      };
+      Dome.popupMenu([item1]);
+    }
+  }
+
   // Theme Popup
 
   const selectTheme = (id?: string) => id && setTheme(id);
@@ -155,6 +167,7 @@ const ASTview = () => {
         lineWrapping={wrapText}
         selection={theMarker}
         onSelection={onSelection}
+        onContextMenu={contextMenu}
         readOnly
       />
     </>
-- 
GitLab