From d4cb035721ee2c398887afb74317b785c4e6f81a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr>
Date: Fri, 22 Oct 2021 09:47:44 +0200
Subject: [PATCH] [ivette] Sets the initial size of foldable splitter panels.

In the messages and properties components.
---
 ivette/src/dome/renderer/layout/splitters.tsx | 10 ++++++++--
 ivette/src/frama-c/kernel/Messages.tsx        |  1 +
 ivette/src/frama-c/kernel/Properties.tsx      |  1 +
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ivette/src/dome/renderer/layout/splitters.tsx b/ivette/src/dome/renderer/layout/splitters.tsx
index 37063fbfd12..95c90d24bb7 100644
--- a/ivette/src/dome/renderer/layout/splitters.tsx
+++ b/ivette/src/dome/renderer/layout/splitters.tsx
@@ -42,6 +42,10 @@ import { AutoSizer, Size } from 'react-virtualized';
 export interface SplitterBaseProps {
   /** Window settings to store the splitter position. */
   settings?: string;
+  /** Ratio or size depending of the splitter:
+     - for 'horizontal' or 'vertical' split, ratio between the two panels;
+     - for other splits, size of the foldable component. */
+  defaultPosition?: number;
   /** Minimal margin from container edges (minimum `32`). */
   margin?: number;
   /** Splitter children components. */
@@ -195,7 +199,9 @@ interface SplitterLayoutProps extends SplitterFoldProps { layout: Layout }
 interface SplitterEngineProps extends SplitterLayoutProps { size: Size }
 
 function SplitterEngine(props: SplitterEngineProps) {
-  const [settings, setSettings] = Dome.useNumberSettings(props.settings, 0);
+  const defaultPosition = props.defaultPosition ?? 0;
+  const [settings, setSettings] =
+    Dome.useNumberSettings(props.settings, defaultPosition);
   const [dragging, setDragging] = React.useState<Dragging>(undefined);
   const { size, margin = 32, layout } = props;
   const { hsplit } = layout;
@@ -245,7 +251,7 @@ function SplitterEngine(props: SplitterEngineProps) {
   const onStop: DraggableEventHandler =
     (evt, _data) => {
       if (evt.metaKey || evt.altKey || evt.ctrlKey) {
-        setSettings(0);
+        setSettings(defaultPosition);
       } else if (unfold && dragging) {
         const offsetPos = dragging.position + dragging.offset - dragging.anchor;
         const newPos = inRange(M, D, offsetPos);
diff --git a/ivette/src/frama-c/kernel/Messages.tsx b/ivette/src/frama-c/kernel/Messages.tsx
index 27dd2e84de7..f6ec62770ba 100644
--- a/ivette/src/frama-c/kernel/Messages.tsx
+++ b/ivette/src/frama-c/kernel/Messages.tsx
@@ -469,6 +469,7 @@ export default function RenderMessages() {
       </TitleBar>
       <RSplit
         settings="ivette.messages.filterSplit"
+        defaultPosition={225}
         unfold={showFilter}
       >
         <Table<string, Message>
diff --git a/ivette/src/frama-c/kernel/Properties.tsx b/ivette/src/frama-c/kernel/Properties.tsx
index ca92fa63777..9e7b3ca97db 100644
--- a/ivette/src/frama-c/kernel/Properties.tsx
+++ b/ivette/src/frama-c/kernel/Properties.tsx
@@ -656,6 +656,7 @@ export default function RenderProperties() {
       </TitleBar>
       <RSplit
         settings="ivette.properties.filterSplit"
+        defaultPosition={200}
         unfold={showFilter}
       >
         <Table<string, Property>
-- 
GitLab