From 01a49fbe685470f9b989f9efef77ad2d09ad7dc3 Mon Sep 17 00:00:00 2001 From: Michael Van Canneyt Date: Thu, 1 Aug 2024 18:10:24 +0200 Subject: [PATCH] * Some fixes and improvements: refresh tree --- .../src/debug.objectinspector.html.pas | 29 ++++++++- .../src/debug.objectinspector.wasm.pas | 59 ++++++++++++++----- .../src/wasm.debuginspector.shared.pas | 2 +- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/packages/wasm-oi/src/debug.objectinspector.html.pas b/packages/wasm-oi/src/debug.objectinspector.html.pas index 3623264..7f48de8 100644 --- a/packages/wasm-oi/src/debug.objectinspector.html.pas +++ b/packages/wasm-oi/src/debug.objectinspector.html.pas @@ -61,12 +61,15 @@ type private FBuilder: THTMLTreeBuilder; FCaption: String; + FOnRefresh: TNotifyEvent; FOptions: TOTOptions; FParentElement, FCaptionElement : TJSHTMLElement; + FRootObjectID: Integer; function GetOnObjectSelected: TObjectSelectedEvent; function GetParentElement: TJSHTMLElement; function GetParentElementID: String; + procedure HandleRefresh(aEvent: TJSEvent); procedure SetCaption(AValue: String); procedure SetOnObjectSelected(AValue: TObjectSelectedEvent); procedure SetOptions(AValue: TOTOptions); @@ -87,6 +90,8 @@ type Property OnObjectSelected : TObjectSelectedEvent Read GetOnObjectSelected Write SetOnObjectSelected; Property Caption : String Read FCaption Write SetCaption; Property Options : TOTOptions Read FOptions Write SetOptions; + Property OnRefresh : TNotifyEvent Read FOnRefresh Write FOnRefresh; + Property RootObjectID : Integer Read FRootObjectID; end; TPropDataFlag = (pdfNoValue,pdfError); @@ -316,6 +321,12 @@ begin Result:=''; end; +procedure THTMLObjectTree.HandleRefresh(aEvent: TJSEvent); +begin + If Assigned(FOnRefresh) then + FOnRefresh(Self); +end; + procedure THTMLObjectTree.SetCaption(AValue: String); begin if FCaption=AValue then Exit; @@ -345,17 +356,24 @@ end; function THTMLObjectTree.BuildWrapper(aParent : TJSHTMLElement) : TJSHTMLElement; var - DW,DC,DT : TJSHTMLElement; + RI,SC,DW,DC,DT : TJSHTMLElement; begin aParent.InnerHTML:=''; DC:=TJSHTMLElement(document.createElement('div')); DC.className:='ot-caption'; + SC:=TJSHTMLElement(document.createElement('span')); + DC.AppendChild(SC); + RI:=TJSHTMLElement(document.createElement('div')); + RI.className:='ot-icon-btn'; + RI.InnerHTML:='⟳'; + RI.AddEventListener('click',@HandleRefresh); + DC.AppendChild(RI); aParent.AppendChild(DC); - FCaptionElement:=DC; + FCaptionElement:=SC; if Not (otShowCaption in Options) then DC.classList.Add('ot-hidden'); - RenderCaption(DC); + RenderCaption(SC); DT:=TJSHTMLElement(document.createElement('div')); DT.className:='ot-tree'; aParent.AppendChild(DT); @@ -409,12 +427,16 @@ begin if aParentID<>0 then lParent:=FBuilder.FindObjectItem(aParentID) else + begin lParent:=Nil; + FRootObjectID:=AID; + end; FBuilder.AddItem(lParent,aCaption,aID); end; procedure THTMLObjectTree.Clear; begin + FRootObjectID:=0; FBuilder.Clear; end; @@ -711,6 +733,7 @@ begin DC:=TJSHTMLElement(Document.createElement('div')); DC.className:='oi-caption'; CS:=TJSHTMLElement(Document.createElement('span')); + CS.className:='oi-caption-lbl'; DC.AppendChild(CS); RenderCaption(CS); Result.AppendChild(DC); diff --git a/packages/wasm-oi/src/debug.objectinspector.wasm.pas b/packages/wasm-oi/src/debug.objectinspector.wasm.pas index 9bffe46..c6f9068 100644 --- a/packages/wasm-oi/src/debug.objectinspector.wasm.pas +++ b/packages/wasm-oi/src/debug.objectinspector.wasm.pas @@ -34,15 +34,19 @@ type TWasmObjectInspectorApi = class(TImportExtension) private FHandleObjectSelection: Boolean; + FHandleRefresh: Boolean; FInspector: THTMLObjectInspector; FLogAPICalls: Boolean; FObjectTree: THTMLObjectTree; + procedure DoRefreshTree(Sender: TObject); procedure DoSelectObject(Sender: TObject; aObjectId: Integer); procedure RaiseOILastError(const aOperation: String); + procedure SetHandleHandleRefresh(AValue: Boolean); procedure SetHandleObjectSelection(AValue: Boolean); procedure SetInspector(AValue: THTMLObjectInspector); procedure SetLogAPICalls(AValue: Boolean); procedure SetObjectTree(AValue: THTMLObjectTree); + procedure ShowObjectTree(aObjectID: Integer); protected procedure Logcall(Const aMsg : string); procedure LogCall(Const aFmt : string; aArgs : Array of const); @@ -58,7 +62,6 @@ type function TreeAddObject(aInspectorID: TInspectorID; ObjectData : PObjectData): TWasmOIResult; function TreeClear(aInspectorID: TInspectorID) : TWasmOIResult; Procedure HookObjectTree; - Procedure UnhookObjectTree; Function GetTree(aInspectorID : TInspectorID) : THTMLObjectTree; Function GetInspector(aInspectorID : TInspectorID) : THTMLObjectInspector; Public @@ -69,6 +72,7 @@ type Property DefaultObjectTree : THTMLObjectTree Read FObjectTree Write SetObjectTree; property DefaultInspector : THTMLObjectInspector Read FInspector Write SetInspector; Property HandleObjectSelection : Boolean Read FHandleObjectSelection Write SetHandleObjectSelection; + Property HandleTreeRefresh : Boolean Read FHandleRefresh Write SetHandleHandleRefresh; property LogAPICalls : Boolean read FLogAPICalls write SetLogAPICalls; end; @@ -78,6 +82,7 @@ uses rtti; type TGetObjectProperties = function(aInspectorID : TInspectorID; aObjectID : TObjectID; aFlags : Longint) : Longint; + TGetObjectTree = function(aInspectorID : TInspectorID; aObjectID : TObjectID; aFlags : Longint) : Longint; { TWasmObjectInspectorApi } @@ -101,8 +106,7 @@ begin FObjectTree:=AValue; if assigned(FObjectTree) then FObjectTree.Clear; - if FHandleObjectSelection then - HookObjectTree; + HookObjectTree; end; procedure TWasmObjectInspectorApi.Logcall(const aMsg: string); @@ -146,19 +150,44 @@ begin Raise EWasmOI.Create(S); end; +procedure TWasmObjectInspectorApi.SetHandleHandleRefresh(AValue: Boolean); +begin + if FHandleRefresh=AValue then Exit; + FHandleRefresh:=AValue; + HookObjectTree; +end; + procedure TWasmObjectInspectorApi.DoSelectObject(Sender: TObject; aObjectId: Integer); begin GetObjectProperties(aObjectID); end; +procedure TWasmObjectInspectorApi.DoRefreshTree(Sender: TObject); +begin + IF not Assigned(FObjectTree) then + Exit; + if (FObjectTree.RootObjectID=0) then + Exit; + ShowObjectTree(FObjectTree.RootObjectID); +end; + procedure TWasmObjectInspectorApi.SetHandleObjectSelection(AValue: Boolean); begin if FHandleObjectSelection=AValue then Exit; FHandleObjectSelection:=AValue; - if FHandleObjectSelection then - HookObjectTree - else - UnhookObjectTree; + HookObjectTree +end; + +procedure TWasmObjectInspectorApi.ShowObjectTree(aObjectID: Integer); + +var + Proc : TGetObjectTree; +begin + Proc:=TGetObjectTree(InstanceExports['wasm_oi_get_object_tree']); + if Not Assigned(Proc) then + Raise EWasmOI.Create('No wasm_oi_get_object_tree entry point'); + if not Proc(0,aObjectID,0)=WASMOI_SUCCESS then + RaiseOILastError('GetObjectProperties'); end; procedure TWasmObjectInspectorApi.GetObjectProperties(aObjectID: Integer); @@ -272,14 +301,14 @@ procedure TWasmObjectInspectorApi.HookObjectTree; begin if not Assigned(FObjectTree) then Exit; - FObjectTree.OnObjectSelected:=@DoSelectObject; -end; - -procedure TWasmObjectInspectorApi.UnhookObjectTree; -begin - if not Assigned(FObjectTree) then - Exit; - FObjectTree.OnObjectSelected:=Nil; + if HandleObjectSelection then + FObjectTree.OnObjectSelected:=@DoSelectObject + else + FObjectTree.OnObjectSelected:=Nil; + if HandleTreeRefresh then + FObjectTree.OnRefresh:=@DoRefreshTree + else + FObjectTree.OnRefresh:=Nil; end; function TWasmObjectInspectorApi.InspectorClear(aInspectorID: TInspectorID): TWasmOIResult; diff --git a/packages/wasm-oi/src/wasm.debuginspector.shared.pas b/packages/wasm-oi/src/wasm.debuginspector.shared.pas index ad7a0f3..c34e3a1 100644 --- a/packages/wasm-oi/src/wasm.debuginspector.shared.pas +++ b/packages/wasm-oi/src/wasm.debuginspector.shared.pas @@ -20,7 +20,7 @@ unit wasm.debuginspector.shared; interface {$IFDEF PAS2JS} -uses rtti; +uses typinfo, rtti; {$ENDIF} Const