Browse Source

* Improvements to object inspector

Michael Van Canneyt 1 year ago
parent
commit
09a24f2b17
2 changed files with 154 additions and 42 deletions
  1. 5 1
      demo/wasienv/wasm-oi/oistyles.css
  2. 149 41
      packages/wasm-oi/src/debug.objectinspector.html.pas

+ 5 - 1
demo/wasienv/wasm-oi/oistyles.css

@@ -17,6 +17,9 @@
   display: flex;
   display: flex;
   align-items: center;  
   align-items: center;  
   justify-content: space-between;
   justify-content: space-between;
+  border-bottom-style: solid;
+  border-bottom-width: 1px;
+
 }
 }
 
 
 ot-hidden {
 ot-hidden {
@@ -34,6 +37,7 @@ li.ot-collapsed ul.ot-tree-nested {
 }
 }
 .ot-tree-item-caption {
 .ot-tree-item-caption {
    user-select: none;
    user-select: none;
+   padding-right: 2em;
 }
 }
 
 
 li.ot-selected > .ot-tree-item-caption {
 li.ot-selected > .ot-tree-item-caption {
@@ -65,7 +69,7 @@ li.ot-expanded > span.ot-tree-item-caption::before {
 .oi-caption {
 .oi-caption {
   padding: 1px;
   padding: 1px;
   font-size: 1rem;
   font-size: 1rem;
-  font-weight: 500;
+/*  font-weight: 500; */
   background-color: rgb(237 238 242);
   background-color: rgb(237 238 242);
   display: flex;
   display: flex;
   align-items: center;  
   align-items: center;  

+ 149 - 41
packages/wasm-oi/src/debug.objectinspector.html.pas

@@ -27,8 +27,14 @@ Type
 
 
   { THTMLTreeBuilder }
   { THTMLTreeBuilder }
   TObjectSelectedEvent = procedure(Sender : TObject; aObjectId : Integer) of object;
   TObjectSelectedEvent = procedure(Sender : TObject; aObjectId : Integer) of object;
+
   TMemberVisibilities = Set of TMemberVisibility;
   TMemberVisibilities = Set of TMemberVisibility;
 
 
+const
+  AllMemberVisibilities = [low(TMemberVisibility)..High(TMemberVisibility)];
+
+type
+
   THTMLTreeBuilder = class(TObject)
   THTMLTreeBuilder = class(TObject)
   private
   private
     FOnObjectSelect: TObjectSelectedEvent;
     FOnObjectSelect: TObjectSelectedEvent;
@@ -123,11 +129,17 @@ Type
     FTableElement : TJSHTMLTableElement;
     FTableElement : TJSHTMLTableElement;
     FCaptionElement : TJSHTMLElement;
     FCaptionElement : TJSHTMLElement;
     FConfigPanel : TJSHTMLElement;
     FConfigPanel : TJSHTMLElement;
+    FWrapperElement : TJSHTMLElement;
+    FProperties : Array of TOIPropData;
     function AppendEl(aParent: TJSHTMLElement; aTag: String; const aID: String; const aInnerText: String=''): TJSHTMLElement;
     function AppendEl(aParent: TJSHTMLElement; aTag: String; const aID: String; const aInnerText: String=''): TJSHTMLElement;
     function AppendSpan(aParent: TJSHTMLElement; const aInnerText: String=''): TJSHTMLElement;
     function AppendSpan(aParent: TJSHTMLElement; const aInnerText: String=''): TJSHTMLElement;
     function CreateEl(aTag: String; const aID: String; const aInnerText: String=''): TJSHTMLElement;
     function CreateEl(aTag: String; const aID: String; const aInnerText: String=''): TJSHTMLElement;
+    function CreateWrapper(aParent: TJSHTMLElement): TJSHTMLElement;
     function GetParentElement: TJSHTMLElement;
     function GetParentElement: TJSHTMLElement;
     function GetParentElementID: String;
     function GetParentElementID: String;
+    procedure HandleColumnVisibility(aEvent: TJSEvent);
+    procedure HandleOptionsClick(aEvent: TJSEvent);
+    procedure HandlePropertyVisibility(aEvent: TJSEvent);
     procedure RenderCaption(aEl: TJSHTMLElement);
     procedure RenderCaption(aEl: TJSHTMLElement);
     procedure SetBorder(AValue: Boolean);
     procedure SetBorder(AValue: Boolean);
     procedure SetCaption(AValue: String);
     procedure SetCaption(AValue: String);
@@ -147,11 +159,12 @@ Type
     function CreateNameCell(aPropData: TOIPropData): TJSHTMLTableCellElement; virtual;
     function CreateNameCell(aPropData: TOIPropData): TJSHTMLTableCellElement; virtual;
     function CreateValueCell(aPropData: TOIPropData; const aKindName: string): TJSHTMLTableCellElement; virtual;
     function CreateValueCell(aPropData: TOIPropData; const aKindName: string): TJSHTMLTableCellElement; virtual;
     function CreateVisibilityCell(aPropData: TOIPropData): TJSHTMLTableCellElement; virtual;
     function CreateVisibilityCell(aPropData: TOIPropData): TJSHTMLTableCellElement; virtual;
+    function ShowProperty(aPropData: TOIPropData): boolean; virtual;
     procedure DoAddProperty(aPropData: TOIPropData); virtual;
     procedure DoAddProperty(aPropData: TOIPropData); virtual;
   Public
   Public
     constructor Create(aOwner : TComponent); override;
     constructor Create(aOwner : TComponent); override;
     destructor destroy; override;
     destructor destroy; override;
-    procedure clear;
+    procedure Clear(ClearData : Boolean = true);
     procedure AddProperty(aIndex : Integer; aVisibility : TMemberVisibility; aKind : TTypeKind; aFlags : TPropDataFlags; const aName,aValue : String);
     procedure AddProperty(aIndex : Integer; aVisibility : TMemberVisibility; aKind : TTypeKind; aFlags : TPropDataFlags; const aName,aValue : String);
     procedure AddProperty(aPropData: TOIPropData);
     procedure AddProperty(aPropData: TOIPropData);
     Property ParentElement : TJSHTMLElement Read GetParentElement Write SetParentElement;
     Property ParentElement : TJSHTMLElement Read GetParentElement Write SetParentElement;
@@ -172,6 +185,8 @@ Type
 
 
 implementation
 implementation
 
 
+uses js;
+
 const
 const
   VisibilityNames : Array[TMemberVisibility] of string = ('Private','Protected','Public','Published');
   VisibilityNames : Array[TMemberVisibility] of string = ('Private','Protected','Public','Published');
 
 
@@ -481,8 +496,14 @@ begin
 end;
 end;
 
 
 procedure THTMLObjectInspector.DisplayChanged;
 procedure THTMLObjectInspector.DisplayChanged;
+
+var
+  PropData : TOIPropData;
+
 begin
 begin
-  Clear;
+  Clear(False);
+  For PropData in FProperties do
+    ShowProperty(PropData);
   Refresh;
   Refresh;
 end;
 end;
 
 
@@ -516,9 +537,77 @@ begin
   aParent.AppendChild(Result);
   aParent.AppendChild(Result);
 end;
 end;
 
 
+
+procedure THTMLObjectInspector.HandleColumnVisibility (aEvent : TJSEvent);
+
+var
+  CB : TJSHTMLInputElement;
+  aOrd : Integer;
+  Col : TOIColumn;
+  Cols : TOIColumns;
+
+begin
+  CB:=TJSHTMLInputElement(aEvent.targetHTMLElement);
+  aOrd:=StrToIntDef(CB.dataset['ord'],-1);
+  if aOrd=-1 then
+    exit;
+  Col:=TOIColumn(aOrd);
+  Cols:=VisibleColumns;
+  If CB.Checked then
+    Include(Cols,Col)
+  else
+    Exclude(Cols,Col);
+  VisibleColumns:=Cols;
+end;
+
+procedure THTMLObjectInspector.HandlePropertyVisibility(aEvent : TJSEvent);
+
+var
+  CB : TJSHTMLInputElement;
+  aOrd : Integer;
+  Vis : TMemberVisibility;
+  Vises : TMemberVisibilities;
+
+begin
+  CB:=TJSHTMLInputElement(aEvent.targetHTMLElement);
+  aOrd:=StrToIntDef(CB.dataset['ord'],-1);
+  if aOrd=-1 then
+    exit;
+  Vis:=TMemberVisibility(aOrd);
+  Writeln('Handling ',VisibilityNames[Vis],', including : ',CB.Checked);
+  Vises:=PropertyVisibilities;
+  If CB.Checked then
+    Include(Vises,Vis)
+  else
+    Exclude(Vises,Vis);
+  PropertyVisibilities:=Vises;
+end;
+
+procedure THTMLObjectInspector.HandleOptionsClick(aEvent : TJSEvent);
+
+var
+  CB : TJSHTMLInputElement;
+  aOrd : Integer;
+  Opt : TOIOption;
+  Opts : TOIOptions;
+
+begin
+  CB:=TJSHTMLInputElement(aEvent.targetHTMLElement);
+  aOrd:=StrToIntDef(CB.dataset['ord'],-1);
+  if aOrd=-1 then
+    exit;
+  Opt:=TOIOption(aOrd);
+  Opts:=Options;
+  If CB.Checked then
+    Include(Opts,Opt)
+  else
+    Exclude(Opts,Opt);
+  Options:=Opts;
+end;
+
 function THTMLObjectInspector.CreateConfigPanel(): TJSHTMLElement;
 function THTMLObjectInspector.CreateConfigPanel(): TJSHTMLElement;
 
 
-  Function AppendCheckbox(aParent : TJSHTMLElement; aName,aLabel : String; aOrd : Integer; isChecked: Boolean) : TJSHTMLInputElement;
+  Function AppendCheckbox(aParent : TJSHTMLElement; aName,aLabel : String; aOrd : Integer; isChecked: Boolean; aHandler : TJSRawEventHandler) : TJSHTMLInputElement;
 
 
   var
   var
     Tmp : TJSHTMLElement;
     Tmp : TJSHTMLElement;
@@ -530,6 +619,7 @@ function THTMLObjectInspector.CreateConfigPanel(): TJSHTMLElement;
     Result.Checked:=isChecked;
     Result.Checked:=isChecked;
     Result._type:='checkbox';
     Result._type:='checkbox';
     Result.dataset['ord']:=IntToStr(aOrd);
     Result.dataset['ord']:=IntToStr(aOrd);
+    Result.AddEventListener('change',aHandler);
     Tmp:=AppendEl(Tmp,'label','',aLabel);
     Tmp:=AppendEl(Tmp,'label','',aLabel);
     Tmp['for']:='cb'+aName;
     Tmp['for']:='cb'+aName;
   end;
   end;
@@ -552,10 +642,10 @@ begin
   CBHead:=AppendEl(CBCol,'div','');
   CBHead:=AppendEl(CBCol,'div','');
   CBHead.ClassName:='oi-checkbox-header';
   CBHead.ClassName:='oi-checkbox-header';
   AppendSpan(CBHead,'Columns');
   AppendSpan(CBHead,'Columns');
-  AppendCheckBox(CBCol,'PropertyName','Property name',Ord(ocName),ocName in VisibleColumns);
-  AppendCheckBox(CBCol,'PropertyVisibility','Visibility',Ord(ocVisibility),ocVisibility in VisibleColumns);
-  AppendCheckBox(CBCol,'PropertyKind','Kind',Ord(ocKind),ocKind in VisibleColumns);
-  AppendCheckBox(CBCol,'PropertyValue','Value',Ord(ocValue),ocValue in VisibleColumns);
+  AppendCheckBox(CBCol,'PropertyName','Property name',Ord(ocName),ocName in VisibleColumns,@HandleColumnVisibility);
+  AppendCheckBox(CBCol,'PropertyVisibility','Visibility',Ord(ocVisibility),ocVisibility in VisibleColumns,@HandleColumnVisibility);
+  AppendCheckBox(CBCol,'PropertyKind','Kind',Ord(ocKind),ocKind in VisibleColumns,@HandleColumnVisibility);
+  AppendCheckBox(CBCol,'PropertyValue','Value',Ord(ocValue),ocValue in VisibleColumns,@HandleColumnVisibility);
   // Col 2
   // Col 2
   CBCol:=appendEl(CBDiv,'div','');
   CBCol:=appendEl(CBDiv,'div','');
   CBCol.ClassName:='oi-checkbox-col';
   CBCol.ClassName:='oi-checkbox-col';
@@ -563,11 +653,10 @@ begin
   CBHead.ClassName:='oi-checkbox-header';
   CBHead.ClassName:='oi-checkbox-header';
   AppendSpan(CBHead,'Visibilities');
   AppendSpan(CBHead,'Visibilities');
   For Vis in TMemberVisibility do
   For Vis in TMemberVisibility do
-    AppendCheckBox(CBCol,'PropVis'+VisibilityNames[Vis],VisibilityNames[Vis],Ord(Vis),Vis in PropertyVisibilities);
+    AppendCheckBox(CBCol,'PropVis'+VisibilityNames[Vis],VisibilityNames[Vis],Ord(Vis),Vis in PropertyVisibilities,@HandlePropertyVisibility);
   Tmp:=AppendEl(Result,'div','');
   Tmp:=AppendEl(Result,'div','');
   Tmp.classname:='oi-checkbox-last';
   Tmp.classname:='oi-checkbox-last';
-  AppendCheckBox(Tmp,'noShowNoValue','Hide properties without value',0,ooHidePropertiesWithoutValue in Options);
-
+  AppendCheckBox(Tmp,'noShowNoValue','Hide properties without value',0,ooHidePropertiesWithoutValue in Options,@HandleOptionsClick);
 
 
 (*
 (*
 
 
@@ -608,33 +697,24 @@ begin
     end
     end
 end;
 end;
 
 
-function THTMLObjectInspector.CreateTable(aParent : TJSHTMLElement): TJSHTMLTableElement;
-
+function THTMLObjectInspector.CreateWrapper(aParent : TJSHTMLElement): TJSHTMLElement;
 
 
 var
 var
-  CS,DP,DC,P,R,C : TJSHTMLElement;
-
-  function AddHeader(aText,aClass : string) : TJSHTMLTableCellElement;
-  begin
-    Result:=TJSHTMLTableCellElement(Document.createElement('TH'));
-    Result.InnerText:=aText;
-    Result.className:=aClass;
-    R.AppendChild(Result);
-  end;
+  CS,DC : TJSHTMLElement;
 
 
 begin
 begin
+  Result:=TJSHTMLElement(Document.createElement('div'));
+  Result.className:='oi-wrapper';
+  aParent.AppendChild(Result);
   if (ooShowCaption in Options) and (Caption<>'') then
   if (ooShowCaption in Options) and (Caption<>'') then
     begin
     begin
-    DP:=TJSHTMLElement(Document.createElement('div'));
-    DP.className:='oi-wrapper';
-    aParent.AppendChild(DP);
     DC:=TJSHTMLElement(Document.createElement('div'));
     DC:=TJSHTMLElement(Document.createElement('div'));
     DC.className:='oi-caption';
     DC.className:='oi-caption';
     CS:=TJSHTMLElement(Document.createElement('span'));
     CS:=TJSHTMLElement(Document.createElement('span'));
     DC.AppendChild(CS);
     DC.AppendChild(CS);
     RenderCaption(CS);
     RenderCaption(CS);
-    DP.AppendChild(DC);
-    FCaptionElement:=DC;
+    Result.AppendChild(DC);
+    FCaptionElement:=CS;
     FConfigPanel:=nil;
     FConfigPanel:=nil;
     if ooShowConfigPanel in Options then
     if ooShowConfigPanel in Options then
       begin
       begin
@@ -644,41 +724,59 @@ begin
       CS.addEventListener('click',@ToggleConfig);
       CS.addEventListener('click',@ToggleConfig);
       DC.AppendChild(CS);
       DC.AppendChild(CS);
       FConfigPanel:=CreateConfigPanel;
       FConfigPanel:=CreateConfigPanel;
-      DP.appendChild(FConfigPanel);
+      Result.appendChild(FConfigPanel);
       end
       end
     end
     end
   else
   else
     begin
     begin
     FConfigPanel:=nil;
     FConfigPanel:=nil;
-    FCaptionElement:=DC;
-    DP:=aParent;
+    FCaptionElement:=Nil;
     end;
     end;
+end;
+
+function THTMLObjectInspector.CreateTable(aParent : TJSHTMLElement): TJSHTMLTableElement;
 
 
+
+var
+  P,R : TJSHTMLElement;
+
+  function AddHeader(aCol : TOIColumn; aText,aClass : string) : TJSHTMLTableCellElement;
+  begin
+    Result:=nil;
+    if not (aCol in VisibleColumns) then exit;
+    Result:=TJSHTMLTableCellElement(Document.createElement('TH'));
+    Result.InnerText:=aText;
+    Result.className:=aClass;
+    R.AppendChild(Result);
+  end;
+
+begin
+  if FWrapperElement=Nil then
+    FWrapperElement:=CreateWrapper(aParent);
   Result:=TJSHTMLTableElement(Document.createElement('TABLE'));
   Result:=TJSHTMLTableElement(Document.createElement('TABLE'));
   Result.ClassName:='oi-table';
   Result.ClassName:='oi-table';
   P:=TJSHTMLTableElement(Document.createElement('THEAD'));
   P:=TJSHTMLTableElement(Document.createElement('THEAD'));
   Result.appendChild(P);
   Result.appendChild(P);
   R:=TJSHTMLTableRowElement(Document.createElement('TR'));
   R:=TJSHTMLTableRowElement(Document.createElement('TR'));
-  if ocName in VisibleColumns then
-    addHeader('Property Name','oi-property-name');
-  if ocVisibility in VisibleColumns then
-    addHeader('Visibility','oi-property-visibility');
-  if ocKind in VisibleColumns then
-    addHeader('Kind','oi-property-kind');
-  if ocValue in VisibleColumns then
-    addHeader('Value','oi-property-value');
+  addHeader(ocName,'Property Name','oi-property-name');
+  addHeader(ocVisibility,'Visibility','oi-property-visibility');
+  addHeader(ocKind, 'Kind','oi-property-kind');
+  addHeader(ocValue,'Value','oi-property-value');
   P.appendChild(R);
   P.appendChild(R);
   P:=TJSHTMLTableElement(Document.createElement('TBODY'));
   P:=TJSHTMLTableElement(Document.createElement('TBODY'));
   Result.border:=IntToStr(Ord(Border));
   Result.border:=IntToStr(Ord(Border));
   Result.appendChild(P);
   Result.appendChild(P);
-  DP.appendChild(Result);
+  FWrapperElement.appendChild(Result);
 end;
 end;
 
 
-procedure THTMLObjectInspector.clear;
+procedure THTMLObjectInspector.Clear(ClearData: Boolean);
 begin
 begin
   if not Assigned(FParentElement) then
   if not Assigned(FParentElement) then
     exit;
     exit;
-  FParentElement.innerHTML:='';
+  if ClearData then
+    FProperties:=[];
+  if Assigned(FTableElement) then
+    FWrapperElement.removeChild(FTableElement);
   FTableElement:=CreateTable(FParentElement);
   FTableElement:=CreateTable(FParentElement);
 end;
 end;
 
 
@@ -736,6 +834,13 @@ end;
 
 
 procedure THTMLObjectInspector.AddProperty(aPropData : TOIPropData);
 procedure THTMLObjectInspector.AddProperty(aPropData : TOIPropData);
 
 
+begin
+  TJSArray(FProperties).Push(aPropData);
+  ShowProperty(aPropData);
+end;
+
+function THTMLObjectInspector.ShowProperty(aPropData : TOIPropData) : boolean;
+
 var
 var
   allow : Boolean;
   allow : Boolean;
 
 
@@ -744,6 +849,8 @@ begin
     allow:=Not (pdfNoValue in aPropdata.Flags)
     allow:=Not (pdfNoValue in aPropdata.Flags)
   else
   else
     allow:=True;
     allow:=True;
+  if Allow then
+    Allow:=aPropData.Visibility in PropertyVisibilities;
   if Assigned(BeforeAddProperty) then
   if Assigned(BeforeAddProperty) then
     BeforeAddProperty(Self,aPropData,allow);
     BeforeAddProperty(Self,aPropData,allow);
   if Allow then
   if Allow then
@@ -752,6 +859,7 @@ begin
     if Assigned(AfterAddProperty) then
     if Assigned(AfterAddProperty) then
       AfterAddProperty(Self,aPropData);
       AfterAddProperty(Self,aPropData);
     end;
     end;
+  Result:=Allow;
 end;
 end;
 
 
 procedure THTMLObjectInspector.DoAddProperty(aPropData : TOIPropData);
 procedure THTMLObjectInspector.DoAddProperty(aPropData : TOIPropData);
@@ -797,7 +905,7 @@ begin
   Caption:='Property inspector';
   Caption:='Property inspector';
   Options:=[ooShowCaption,ooShowConfigPanel,ooHidePropertiesWithoutValue];
   Options:=[ooShowCaption,ooShowConfigPanel,ooHidePropertiesWithoutValue];
   VisibleColumns:=[ocName,ocValue];
   VisibleColumns:=[ocName,ocValue];
-  PropertyVisibilities:=[Low(TMemberVisibility)..High(TMemberVisibility)];
+  PropertyVisibilities:=AllMemberVisibilities;
 end;
 end;
 
 
 destructor THTMLObjectInspector.destroy;
 destructor THTMLObjectInspector.destroy;