Browse Source

design: property editor for stylesheet

mattias 2 years ago
parent
commit
ef17e3ef79
3 changed files with 62 additions and 5 deletions
  1. 39 0
      design/fresnel.register.pas
  2. 23 4
      design/fresnel.stylepropedit.pas
  3. 0 1
      src/fresnel.renderer.pas

+ 39 - 0
design/fresnel.register.pas

@@ -76,6 +76,14 @@ type
     procedure Edit; override;
   end;
 
+  { TFresnelStyleSheetPropertyEditor }
+
+  TFresnelStyleSheetPropertyEditor = class(TClassPropertyEditor)
+  public
+    procedure Edit; override;
+    function GetAttributes: TPropertyAttributes; override;
+  end;
+
 procedure Register;
 
 implementation
@@ -91,6 +99,7 @@ begin
 
   RegisterPropertyEditor(TypeInfo(String), TFresnelElement, 'Style', TFresnelStylePropertyEditor);
   RegisterPropertyEditor(TypeInfo(String), TCustomFresnelForm, 'Style', THiddenPropertyEditor);
+  RegisterPropertyEditor(TypeInfo(TStrings), TCustomFresnelForm, 'Stylesheet', TFresnelStyleSheetPropertyEditor);
 end;
 
 { TFresnelFormMediator }
@@ -336,6 +345,7 @@ begin
 
   TheDialog := TStylePropEditDialog.Create(nil);
   try
+    TheDialog.Caption := 'CSS Inline Style Editor';
     TheDialog.Editor := Self;
     TheDialog.CSSSynEdit.Text := AString;
     TheDialog.CSSSynEditChange(nil);
@@ -348,5 +358,34 @@ begin
   end;
 end;
 
+{ TFresnelStyleSheetPropertyEditor }
+
+procedure TFresnelStyleSheetPropertyEditor.Edit;
+var
+  TheDialog : TStylePropEditDialog;
+  aList: TStrings;
+begin
+  aList := TStrings(GetObjectValue);
+
+  TheDialog := TStylePropEditDialog.Create(nil);
+  try
+    TheDialog.Caption := 'CSS Stylesheet Editor';
+    TheDialog.Editor := Self;
+    TheDialog.CSSSynEdit.Text := aList.Text;
+    TheDialog.CSSSynEditChange(nil);
+    if (TheDialog.ShowModal = mrOK) then
+    begin
+      TheDialog.Apply;
+    end;
+  finally
+    TheDialog.Free;
+  end;
+end;
+
+function TFresnelStyleSheetPropertyEditor.GetAttributes: TPropertyAttributes;
+begin
+  Result := [paMultiSelect, paDialog, paRevertable, paReadOnly];
+end;
+
 end.
 

+ 23 - 4
design/fresnel.stylepropedit.pas

@@ -7,7 +7,7 @@ interface
 uses
   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, StdCtrls,
   PropEdits, ObjInspStrConsts, IDEWindowIntf, TextTools, SynEdit,
-  SynHighlighterCss, LazUTF8;
+  SynHighlighterCss, LazUTF8, LazLoggerBase;
 
 type
 
@@ -32,8 +32,10 @@ type
     procedure SaveButtonClick(Sender: TObject);
     procedure SortButtonClick(Sender: TObject);
   private
+    FEditor: TPropertyEditor;
+    procedure SetEditor(const AValue: TPropertyEditor);
   public
-    Editor: TStringPropertyEditor;
+    property Editor: TPropertyEditor read FEditor write SetEditor;
     procedure Apply; virtual;
   end;
 
@@ -64,7 +66,6 @@ end;
 
 procedure TStylePropEditDialog.FormCreate(Sender: TObject);
 begin
-  Caption := 'CSS Inline Style Editor';
   StatusLabel.Caption := ois0Lines0Chars;
   SortButton.Caption := oisSort;
   ClearButton.Caption := oisClear;
@@ -126,17 +127,35 @@ begin
     CSSSynEdit.Lines.Text := NewSortedText;
 end;
 
+procedure TStylePropEditDialog.SetEditor(const AValue: TPropertyEditor);
+begin
+  if FEditor=AValue then Exit;
+  FEditor:=AValue;
+  if Editor is TStringPropertyEditor then
+  else if Editor is TClassPropertyEditor then
+  else
+    raise Exception.Create('TStylePropEditDialog.SetEditor '+DbgSName(Editor));
+end;
+
 procedure TStylePropEditDialog.Apply;
 var
   AString: String;
   LineEndPos: SizeInt;
+  aList: TStrings;
 begin
   AString := CSSSynEdit.Text;
   LineEndPos := Length(AString) - Length(LineEnding) + 1;
   // erase the last lineending if any
   if Copy(AString, LineEndPos, Length(LineEnding)) = LineEnding then
     Delete(AString, LineEndPos, Length(LineEnding));
-  Editor.SetStrValue(AString);
+
+  if Editor is TStringPropertyEditor then
+    Editor.SetStrValue(AString)
+  else if Editor is TClassPropertyEditor then
+  begin
+    aList := TStrings(Editor.GetObjectValue);
+    aList.Text:=AString;
+  end;
 end;
 
 end.

+ 0 - 1
src/fresnel.renderer.pas

@@ -147,7 +147,6 @@ begin
         aColor:=El.GetRenderedCSString(fcaColor,true);
         if not CSSToFPColor(aColor,aColorFP) then
           aColorFP:=colTransparent;
-        writeln('TFresnelRenderer.DrawElement aColor="',aColor,'" aColorFP=',FPColorToCSS(aColorFP));
         if aColorFP.Alpha<>alphaTransparent then
         begin
           TextOut(aContentBox.Left,aContentBox.Top,El.Font,aColorFP,aCaption);