123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- unit Fresnel.DsgnInspector;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, Forms, Controls,
- IDECommands, IDEWindowIntf, LazIDEIntf, MenuIntf, PropEdits, LazLoggerBase,
- Fresnel.Controls, Fresnel.CSSStyleInspector, Fresnel.DOM, Fresnel.LCLControls;
- const
- CSSInspectorWindowName = 'IDEFresnelCSSInspectorWindow';
- type
- { TFresnelCSSInspectorWnd }
- TFresnelCSSInspectorWnd = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- procedure OnSetSelection(const ASelection: TPersistentSelectionList);
- public
- FrlControl: TFresnelLCLControl;
- CSSStyleInspector: TCSSStyleInspector;
- end;
- var
- CSSInspectorWnd: TFresnelCSSInspectorWnd;
- ViewCSSInspectorCmd: TIDECommand;
- ViewCSSInspectorMenuCmd: TIDEMenuCommand;
- procedure ViewCSSInspector(Sender: TObject);
- procedure CreateCSSInspectorWindow(Sender: TObject; aFormName: string;
- var AForm: TCustomForm; DoDisableAutoSizing: boolean);
- implementation
- {$R *.lfm}
- procedure ViewCSSInspector(Sender: TObject);
- begin
- IDEWindowCreators.ShowForm(CSSInspectorWindowName,true);
- end;
- procedure CreateCSSInspectorWindow(Sender: TObject; aFormName: string; var AForm: TCustomForm;
- DoDisableAutoSizing: boolean);
- begin
- if aFormName='' then ;
- IDEWindowCreators.CreateForm(CSSInspectorWnd,TFresnelCSSInspectorWnd,DoDisableAutoSizing,
- LazarusIDE.OwningComponent);
- AForm:=CSSInspectorWnd;
- end;
- { TFresnelCSSInspectorWnd }
- procedure TFresnelCSSInspectorWnd.FormCreate(Sender: TObject);
- var
- aSelection: TPersistentSelectionList;
- begin
- FrlControl:=TFresnelLCLControl.Create(Self);
- FrlControl.Name:='FrlControl';
- FrlControl.Align:=alClient;
- FrlControl.Parent:=Self;
- FrlControl.Viewport.Stylesheet.Text:=':root { background-color: #222; }';
- CSSStyleInspector:=TCSSStyleInspector.Create(Self);
- CSSStyleInspector.Name:='CSSStyleInspector';
- CSSStyleInspector.Parent:=FrlControl.Viewport;
- GlobalDesignHook.AddHandlerSetSelection(@OnSetSelection);
- aSelection:=TPersistentSelectionList.Create;
- try
- GlobalDesignHook.GetSelection(aSelection);
- OnSetSelection(aSelection);
- finally
- aSelection.Free;
- end;
- end;
- procedure TFresnelCSSInspectorWnd.FormDestroy(Sender: TObject);
- begin
- GlobalDesignHook.RemoveHandlerSetSelection(@OnSetSelection);
- end;
- procedure TFresnelCSSInspectorWnd.OnSetSelection(const ASelection: TPersistentSelectionList);
- var
- aPersistent: TPersistent;
- NewTarget: TFresnelElement;
- begin
- NewTarget:=nil;
- if (ASelection<>nil) and (ASelection.Count>0) then
- begin
- aPersistent:=ASelection[0];
- if aPersistent is TFresnelElement then
- NewTarget:=TFresnelElement(aPersistent);
- end;
- CSSStyleInspector.Target:=NewTarget;
- end;
- end.
|