fresnel.dsgninspector.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. unit Fresnel.DsgnInspector;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls,
  6. IDECommands, IDEWindowIntf, LazIDEIntf, MenuIntf, PropEdits, LazLoggerBase,
  7. Fresnel.Controls, Fresnel.CSSStyleInspector, Fresnel.DOM, Fresnel.LCLControls;
  8. const
  9. CSSInspectorWindowName = 'IDEFresnelCSSInspectorWindow';
  10. type
  11. { TFresnelCSSInspectorWnd }
  12. TFresnelCSSInspectorWnd = class(TForm)
  13. procedure FormCreate(Sender: TObject);
  14. procedure FormDestroy(Sender: TObject);
  15. private
  16. procedure OnSetSelection(const ASelection: TPersistentSelectionList);
  17. public
  18. FrlControl: TFresnelLCLControl;
  19. CSSStyleInspector: TCSSStyleInspector;
  20. end;
  21. var
  22. CSSInspectorWnd: TFresnelCSSInspectorWnd;
  23. ViewCSSInspectorCmd: TIDECommand;
  24. ViewCSSInspectorMenuCmd: TIDEMenuCommand;
  25. procedure ViewCSSInspector(Sender: TObject);
  26. procedure CreateCSSInspectorWindow(Sender: TObject; aFormName: string;
  27. var AForm: TCustomForm; DoDisableAutoSizing: boolean);
  28. implementation
  29. {$R *.lfm}
  30. procedure ViewCSSInspector(Sender: TObject);
  31. begin
  32. IDEWindowCreators.ShowForm(CSSInspectorWindowName,true);
  33. end;
  34. procedure CreateCSSInspectorWindow(Sender: TObject; aFormName: string; var AForm: TCustomForm;
  35. DoDisableAutoSizing: boolean);
  36. begin
  37. if aFormName='' then ;
  38. IDEWindowCreators.CreateForm(CSSInspectorWnd,TFresnelCSSInspectorWnd,DoDisableAutoSizing,
  39. LazarusIDE.OwningComponent);
  40. AForm:=CSSInspectorWnd;
  41. end;
  42. { TFresnelCSSInspectorWnd }
  43. procedure TFresnelCSSInspectorWnd.FormCreate(Sender: TObject);
  44. var
  45. aSelection: TPersistentSelectionList;
  46. begin
  47. FrlControl:=TFresnelLCLControl.Create(Self);
  48. FrlControl.Name:='FrlControl';
  49. FrlControl.Align:=alClient;
  50. FrlControl.Parent:=Self;
  51. FrlControl.Viewport.Stylesheet.Text:=':root { background-color: #222; }';
  52. CSSStyleInspector:=TCSSStyleInspector.Create(Self);
  53. CSSStyleInspector.Name:='CSSStyleInspector';
  54. CSSStyleInspector.Parent:=FrlControl.Viewport;
  55. GlobalDesignHook.AddHandlerSetSelection(@OnSetSelection);
  56. aSelection:=TPersistentSelectionList.Create;
  57. try
  58. GlobalDesignHook.GetSelection(aSelection);
  59. OnSetSelection(aSelection);
  60. finally
  61. aSelection.Free;
  62. end;
  63. end;
  64. procedure TFresnelCSSInspectorWnd.FormDestroy(Sender: TObject);
  65. begin
  66. GlobalDesignHook.RemoveHandlerSetSelection(@OnSetSelection);
  67. end;
  68. procedure TFresnelCSSInspectorWnd.OnSetSelection(const ASelection: TPersistentSelectionList);
  69. var
  70. aPersistent: TPersistent;
  71. NewTarget: TFresnelElement;
  72. begin
  73. NewTarget:=nil;
  74. if (ASelection<>nil) and (ASelection.Count>0) then
  75. begin
  76. aPersistent:=ASelection[0];
  77. if aPersistent is TFresnelElement then
  78. NewTarget:=TFresnelElement(aPersistent);
  79. end;
  80. CSSStyleInspector.Target:=NewTarget;
  81. end;
  82. end.