SynEdit: TextAttributes refactor/cleanup: move some properties to highlighter / move "feature" property to IDE

git-svn-id: trunk@41180 -
This commit is contained in:
martin 2013-05-13 18:36:20 +00:00
parent 3cef71b547
commit 655de9221e
4 changed files with 86 additions and 42 deletions

View File

@ -66,13 +66,6 @@ type
property NeedsReScanRealStartIndex: Integer read GetNeedsReScanRealStartIndex; property NeedsReScanRealStartIndex: Integer read GetNeedsReScanRealStartIndex;
end; end;
TSynHighlighterAttrFeature =
( hafBackColor, hafForeColor, hafFrameColor,
hafStyle, hafStyleMask,
hafFrameStyle, hafFrameEdges
);
TSynHighlighterAttrFeatures = set of TSynHighlighterAttrFeature;
{ TLazSynCustomTextAttributes } { TLazSynCustomTextAttributes }
TLazSynCustomTextAttributes = class(TPersistent) TLazSynCustomTextAttributes = class(TPersistent)
@ -127,7 +120,6 @@ type
FFrameStyleDefault: TSynLineStyle; FFrameStyleDefault: TSynLineStyle;
FStyleDefault: TFontStyles; FStyleDefault: TFontStyles;
FStyleMaskDefault: TFontStyles; FStyleMaskDefault: TFontStyles;
FFeatures: TSynHighlighterAttrFeatures;
FStoredName: string; FStoredName: string;
FName: string; FName: string;
FOnChange: TNotifyEvent; FOnChange: TNotifyEvent;
@ -149,7 +141,7 @@ type
public public
constructor Create; constructor Create;
constructor Create(attribName: string; aStoredName: String = ''); constructor Create(attribName: string; aStoredName: String = '');
procedure InternalSaveDefaultValues; procedure InternalSaveDefaultValues; virtual;
function LoadFromBorlandRegistry(rootKey: HKEY; attrKey, attrName: string; function LoadFromBorlandRegistry(rootKey: HKEY; attrKey, attrName: string;
oldStyle: boolean): boolean; virtual; oldStyle: boolean): boolean; virtual;
function LoadFromRegistry(Reg: TRegistry): boolean; function LoadFromRegistry(Reg: TRegistry): boolean;
@ -162,7 +154,6 @@ type
property Name: string read fName; property Name: string read fName;
property StoredName: string read FStoredName write FStoredName; property StoredName: string read FStoredName write FStoredName;
property OnChange: TNotifyEvent read fOnChange write fOnChange; property OnChange: TNotifyEvent read fOnChange write fOnChange;
property Features: TSynHighlighterAttrFeatures read FFeatures write FFeatures;
published published
property Background stored GetBackgroundColorStored; property Background stored GetBackgroundColorStored;
property Foreground stored GetForegroundColorStored; property Foreground stored GetForegroundColorStored;
@ -170,17 +161,33 @@ type
property FrameStyle stored GetFrameStyleStored; property FrameStyle stored GetFrameStyleStored;
property FrameEdges stored GetFrameEdgesStored; property FrameEdges stored GetFrameEdgesStored;
property Style stored GetFontStyleStored; property Style stored GetFontStyleStored;
// TODO: StyleMask move to TSynHighlighterAttributesModifier
property StyleMask stored GetFontStyleMaskStored; property StyleMask stored GetFontStyleMaskStored;
// FStyle = [], FStyleMask = [] ==> no modification
// FStyle = [fsBold], FStyleMask = [] ==> invert fsBold
// FStyle = [], FStyleMask = [fsBold] ==> clear fsBold
// FStyle = [fsBold], FStyleMask = [fsBold] ==> set fsBold
end; end;
{ TSynHighlighterAttributesModifier } { TSynHighlighterAttributesModifier }
TSynHighlighterAttributesModifier = class(TSynHighlighterAttributes) TSynHighlighterAttributesModifier = class(TSynHighlighterAttributes)
{strict} private private
FBackPriority: integer; FBackPriority: integer;
FForePriority: integer; FForePriority: integer;
FFramePriority: integer; FFramePriority: integer;
FStylePriority: Array [TFontStyle] of integer; FStylePriority: Array [TFontStyle] of integer;
FBackPriorityDefault: integer;
FForePriorityDefault: integer;
FFramePriorityDefault: integer;
FStylePriorityDefault: Array [TFontStyle] of integer;
function GetBackPriorityStored: Boolean;
function GetForePriorityStored: Boolean;
function GetFramePriorityStored: Boolean;
function GetStylePriorityStored(Index: TFontStyle): Boolean;
function GetStylePriority(Index: TFontStyle): integer; function GetStylePriority(Index: TFontStyle): integer;
procedure SetBackPriority(AValue: integer); procedure SetBackPriority(AValue: integer);
procedure SetForePriority(AValue: integer); procedure SetForePriority(AValue: integer);
@ -191,15 +198,16 @@ type
procedure DoClear; override; procedure DoClear; override;
procedure InitPriorities; procedure InitPriorities;
public public
procedure InternalSaveDefaultValues; override;
procedure SetAllPriorities(APriority: integer); procedure SetAllPriorities(APriority: integer);
property StylePriority[Index: TFontStyle]: integer read GetStylePriority write SetStylePriority; property StylePriority[Index: TFontStyle]: integer read GetStylePriority write SetStylePriority;
published published
property BackPriority: integer read FBackPriority write SetBackPriority; property BackPriority: integer read FBackPriority write SetBackPriority stored GetBackPriorityStored;
property ForePriority: integer read FForePriority write SetForePriority; property ForePriority: integer read FForePriority write SetForePriority stored GetForePriorityStored;
property FramePriority: integer read FFramePriority write SetFramePriority; property FramePriority: integer read FFramePriority write SetFramePriority stored GetFramePriorityStored;
property BoldPriority: integer index fsBold read GetStylePriority write SetStylePriority default 0; property BoldPriority: integer index fsBold read GetStylePriority write SetStylePriority stored GetStylePriorityStored;
property ItalicPriority: integer index fsItalic read GetStylePriority write SetStylePriority default 0; property ItalicPriority: integer index fsItalic read GetStylePriority write SetStylePriority stored GetStylePriorityStored;
property UnderlinePriority: integer index fsUnderline read GetStylePriority write SetStylePriority default 0; property UnderlinePriority: integer index fsUnderline read GetStylePriority write SetStylePriority stored GetStylePriorityStored;
end; end;
TSynHighlighterCapability = ( TSynHighlighterCapability = (
@ -443,6 +451,26 @@ begin
Result := FStylePriority[Index]; Result := FStylePriority[Index];
end; end;
function TSynHighlighterAttributesModifier.GetBackPriorityStored: Boolean;
begin
Result := FBackPriority <> FBackPriorityDefault;
end;
function TSynHighlighterAttributesModifier.GetForePriorityStored: Boolean;
begin
Result := FForePriority <> FForePriorityDefault;
end;
function TSynHighlighterAttributesModifier.GetFramePriorityStored: Boolean;
begin
Result := FFramePriority <> FFramePriorityDefault;
end;
function TSynHighlighterAttributesModifier.GetStylePriorityStored(Index: TFontStyle): Boolean;
begin
Result := FStylePriority[Index] <> FStylePriorityDefault[Index];
end;
procedure TSynHighlighterAttributesModifier.SetBackPriority(AValue: integer); procedure TSynHighlighterAttributesModifier.SetBackPriority(AValue: integer);
begin begin
if FBackPriority = AValue then Exit; if FBackPriority = AValue then Exit;
@ -510,6 +538,18 @@ begin
EndUpdate; EndUpdate;
end; end;
procedure TSynHighlighterAttributesModifier.InternalSaveDefaultValues;
var
i: TFontStyle;
begin
inherited InternalSaveDefaultValues;
FBackPriorityDefault := FBackPriority;
FForePriorityDefault := FForePriority;
FFramePriorityDefault := FFramePriority;
for i := Low(TFontStyle) to High(TFontStyle) do
FStylePriorityDefault[i] := FStylePriority[i];
end;
procedure TSynHighlighterAttributesModifier.SetAllPriorities(APriority: integer); procedure TSynHighlighterAttributesModifier.SetAllPriorities(APriority: integer);
var var
i: TFontStyle; i: TFontStyle;
@ -1098,7 +1138,6 @@ begin
if not (Src is TSynHighlighterAttributes) then exit; if not (Src is TSynHighlighterAttributes) then exit;
FName := TSynHighlighterAttributes(Src).FName; FName := TSynHighlighterAttributes(Src).FName;
FStoredName:= TSynHighlighterAttributes(Src).FStoredName; FStoredName:= TSynHighlighterAttributes(Src).FStoredName;
FFeatures := TSynHighlighterAttributes(Src).FFeatures;
Changed; {TODO: only if really changed} Changed; {TODO: only if really changed}
end; end;
@ -1117,7 +1156,6 @@ begin
FFrameColorDefault := clNone; FFrameColorDefault := clNone;
FFrameStyleDefault := slsSolid; FFrameStyleDefault := slsSolid;
FFrameEdgesDefault := sfeAround; FFrameEdgesDefault := sfeAround;
FFeatures := [hafBackColor, hafForeColor, hafFrameColor, hafStyle, hafFrameStyle, hafFrameEdges];
end; end;
constructor TSynHighlighterAttributes.Create; constructor TSynHighlighterAttributes.Create;

View File

@ -228,24 +228,6 @@ type
function GetModifiedStyle(aStyle: TFontStyles): TFontStyles; // deprecated; function GetModifiedStyle(aStyle: TFontStyles): TFontStyles; // deprecated;
procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor; procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor;
var AStyle: TFontStyles; var AFrameStyle: TSynLineStyle); deprecated; var AStyle: TFontStyles; var AFrameStyle: TSynLineStyle); deprecated;
published
property Background default clHighLight;
property Foreground default clHighLightText;
property FrameColor default clNone;
property FrameStyle default slsSolid;
property FrameEdges default sfeAround;
// FStyle = [], FStyleMask = [] ==> no modification
// FStyle = [fsBold], FStyleMask = [] ==> invert fsBold
// FStyle = [], FStyleMask = [fsBold] ==> clear fsBold
// FStyle = [fsBold], FStyleMask = [fsBold] ==> set fsBold
property Style default [];
property StyleMask default [];
property BackPriority default 0;
property ForePriority default 0;
property FramePriority default 0;
property BoldPriority default 0;
property ItalicPriority default 0;
property UnderlinePriority default 0;
end; end;
{ TSynSelectedColorMergeResult } { TSynSelectedColorMergeResult }
@ -922,6 +904,10 @@ begin
inherited Init; inherited Init;
Background := clHighLight; Background := clHighLight;
Foreground := clHighLightText; Foreground := clHighLightText;
FrameColor := clNone;
FrameStyle := slsSolid;
FrameEdges := sfeAround;
InternalSaveDefaultValues;
end; end;
procedure TSynSelectedColor.SetFrameBoundsPhys(AStart, AEnd: Integer); procedure TSynSelectedColor.SetFrameBoundsPhys(AStart, AEnd: Integer);

View File

@ -2263,7 +2263,6 @@ begin
fCommentAttri.Style:= [fsItalic]; fCommentAttri.Style:= [fsItalic];
AddAttribute(fCommentAttri); AddAttribute(fCommentAttri);
FIDEDirectiveAttri := TSynHighlighterAttributesModifier.Create(SYNS_AttrIDEDirective, SYNS_XML_AttrIDEDirective); FIDEDirectiveAttri := TSynHighlighterAttributesModifier.Create(SYNS_AttrIDEDirective, SYNS_XML_AttrIDEDirective);
FIDEDirectiveAttri.Features := FIDEDirectiveAttri.Features + [hafStyleMask];
AddAttribute(FIDEDirectiveAttri); AddAttribute(FIDEDirectiveAttri);
// FCurIDEDirectiveAttri, FCurCaseLabelAttri // FCurIDEDirectiveAttri, FCurCaseLabelAttri
// They are not available through the "Attribute" property (not added via AddAttribute // They are not available through the "Attribute" property (not added via AddAttribute
@ -2283,7 +2282,6 @@ begin
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol, SYNS_XML_AttrSymbol); fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol, SYNS_XML_AttrSymbol);
AddAttribute(fSymbolAttri); AddAttribute(fSymbolAttri);
FCaseLabelAttri := TSynHighlighterAttributesModifier.Create(SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel); FCaseLabelAttri := TSynHighlighterAttributesModifier.Create(SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel);
FCaseLabelAttri.Features := FCaseLabelAttri.Features + [hafStyleMask];
AddAttribute(FCaseLabelAttri); AddAttribute(FCaseLabelAttri);
FCurCaseLabelAttri := TSynSelectedColorMergeResult.Create(SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel); FCurCaseLabelAttri := TSynSelectedColorMergeResult.Create(SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel);
fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective, SYNS_XML_AttrDirective); fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective, SYNS_XML_AttrDirective);

View File

@ -103,6 +103,13 @@ type
TAhaGroupName = (agnDefault, agnLanguage, agnText, agnLine, agnGutter, agnTemplateMode, agnSyncronMode); TAhaGroupName = (agnDefault, agnLanguage, agnText, agnLine, agnGutter, agnTemplateMode, agnSyncronMode);
TColorSchemeAttributeFeature =
( hafBackColor, hafForeColor, hafFrameColor,
hafStyle, hafStyleMask,
hafFrameStyle, hafFrameEdges
);
TColorSchemeAttributeFeatures = set of TColorSchemeAttributeFeature;
const const
SynEditPreviewIncludeOptions = [eoNoCaret, eoNoSelection]; SynEditPreviewIncludeOptions = [eoNoCaret, eoNoSelection];
SynEditPreviewExcludeOptions = [eoDragDropEditing, eoDropFiles, SynEditPreviewExcludeOptions = [eoDragDropEditing, eoDropFiles,
@ -164,7 +171,7 @@ const
{ ahaSpecialVisibleChars } agnText, { ahaSpecialVisibleChars } agnText,
{ ahaTopInfoHint } agnLine { ahaTopInfoHint } agnLine
); );
ahaSupportedFeatures: array[TAdditionalHilightAttribute] of TSynHighlighterAttrFeatures = ahaSupportedFeatures: array[TAdditionalHilightAttribute] of TColorSchemeAttributeFeatures =
( (
{ ahaNone } [hafBackColor, hafForeColor, hafFrameColor, hafFrameStyle, hafFrameEdges, hafStyle, hafStyleMask], { ahaNone } [hafBackColor, hafForeColor, hafFrameColor, hafFrameStyle, hafFrameEdges, hafStyle, hafStyleMask],
{ ahaTextBlock } [hafBackColor, hafForeColor, hafFrameColor, hafFrameStyle, hafFrameEdges, hafStyle, hafStyleMask], { ahaTextBlock } [hafBackColor, hafForeColor, hafFrameColor, hafFrameStyle, hafFrameEdges, hafStyle, hafStyleMask],
@ -220,11 +227,14 @@ type
TColorSchemeAttribute = class(TSynHighlighterAttributesModifier) TColorSchemeAttribute = class(TSynHighlighterAttributesModifier)
private private
FFeatures: TColorSchemeAttributeFeatures;
FGroup: TAhaGroupName; FGroup: TAhaGroupName;
FOwner: TColorSchemeLanguage; FOwner: TColorSchemeLanguage;
FUseSchemeGlobals: Boolean; FUseSchemeGlobals: Boolean;
function GetIsUsingSchemeGlobals: Boolean; function GetIsUsingSchemeGlobals: Boolean;
function OldAdditionalAttributeName(NewAha: String): string; function OldAdditionalAttributeName(NewAha: String): string;
protected
procedure Init; override;
public public
constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: string; aStoredName: String = ''); constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: string; aStoredName: String = '');
procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute = nil); procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute = nil);
@ -239,6 +249,7 @@ type
Defaults: TColorSchemeAttribute); Defaults: TColorSchemeAttribute);
property Group: TAhaGroupName read FGroup write FGroup; property Group: TAhaGroupName read FGroup write FGroup;
property IsUsingSchemeGlobals: Boolean read GetIsUsingSchemeGlobals; property IsUsingSchemeGlobals: Boolean read GetIsUsingSchemeGlobals;
property Features: TColorSchemeAttributeFeatures read FFeatures write FFeatures;
published published
property UseSchemeGlobals: Boolean read FUseSchemeGlobals write FUseSchemeGlobals; property UseSchemeGlobals: Boolean read FUseSchemeGlobals write FUseSchemeGlobals;
end; end;
@ -5541,6 +5552,12 @@ begin
else Result := ahaXmlNames[TAdditionalHilightAttribute(AttriIdx)]; else Result := ahaXmlNames[TAdditionalHilightAttribute(AttriIdx)];
end; end;
procedure TColorSchemeAttribute.Init;
begin
inherited Init;
FFeatures := [hafBackColor, hafForeColor, hafFrameColor, hafStyle, hafFrameStyle, hafFrameEdges];
end;
function TColorSchemeAttribute.GetIsUsingSchemeGlobals: Boolean; function TColorSchemeAttribute.GetIsUsingSchemeGlobals: Boolean;
begin begin
Result := FUseSchemeGlobals and (GetSchemeGlobal <> nil); Result := FUseSchemeGlobals and (GetSchemeGlobal <> nil);
@ -5588,8 +5605,6 @@ begin
aDest.StyleMask := [low(TFontStyle)..high(TFontStyle)]; aDest.StyleMask := [low(TFontStyle)..high(TFontStyle)];
if not (aDest is TSynSelectedColor) then begin if not (aDest is TSynSelectedColor) then begin
aDest.Features := Src.Features;
if aDefault <> nil then begin if aDefault <> nil then begin
if aDefault.IsUsingSchemeGlobals then if aDefault.IsUsingSchemeGlobals then
aDefault := aDefault.GetSchemeGlobal; aDefault := aDefault.GetSchemeGlobal;
@ -5618,10 +5633,17 @@ end;
procedure TColorSchemeAttribute.Assign(Src: TPersistent); procedure TColorSchemeAttribute.Assign(Src: TPersistent);
begin begin
inherited Assign(Src); inherited Assign(Src);
FFeatures := [hafBackColor, hafForeColor, hafFrameColor, hafStyle, hafFrameStyle, hafFrameEdges];
if Src is TSynHighlighterAttributesModifier then
FFeatures := FFeatures + [hafStyleMask];
if Src is TColorSchemeAttribute then begin if Src is TColorSchemeAttribute then begin
FGroup := TColorSchemeAttribute(Src).FGroup; FGroup := TColorSchemeAttribute(Src).FGroup;
FUseSchemeGlobals := TColorSchemeAttribute(Src).FUseSchemeGlobals; FUseSchemeGlobals := TColorSchemeAttribute(Src).FUseSchemeGlobals;
FFeatures := TColorSchemeAttribute(Src).FFeatures;
end; end;
end; end;
function TColorSchemeAttribute.Equals(Other: TColorSchemeAttribute): Boolean; function TColorSchemeAttribute.Equals(Other: TColorSchemeAttribute): Boolean;