diff --git a/components/synedit/syneditfoldedview.pp b/components/synedit/syneditfoldedview.pp index a632156e20..21ce7122eb 100644 --- a/components/synedit/syneditfoldedview.pp +++ b/components/synedit/syneditfoldedview.pp @@ -425,7 +425,7 @@ type private FFoldView: TSynEditFoldedView; FLineState: integer; - FTokenAttr: TSynHighlighterAttributes; + FTokenAttr: TSynHighlighterAttributesModifier; public constructor Create(AFoldView: TSynEditFoldedView); destructor Destroy; override; @@ -783,7 +783,7 @@ constructor TLazSynDisplayFold.Create(AFoldView: TSynEditFoldedView); begin inherited Create; FFoldView := AFoldView; - FTokenAttr := TSynHighlighterAttributes.Create(''); + FTokenAttr := TSynHighlighterAttributesModifier.Create(''); end; destructor TLazSynDisplayFold.Destroy; diff --git a/components/synedit/synedithighlighter.pp b/components/synedit/synedithighlighter.pp index 6faa73031a..4e8b29fc68 100644 --- a/components/synedit/synedithighlighter.pp +++ b/components/synedit/synedithighlighter.pp @@ -87,34 +87,24 @@ type FFrameStyle: TSynLineStyle; fStyle: TFontStyles; fStyleMask: TFontStyles; - FBackPriority: integer; - FForePriority: integer; - FFramePriority: integer; - FStylePriority: Array [TFontStyle] of integer; - function GetStylePriority(Index: TFontStyle): integer; procedure SetBackground(AValue: TColor); - procedure SetBackPriority(AValue: integer); procedure SetForeground(AValue: TColor); - procedure SetForePriority(AValue: integer); procedure SetFrameColor(AValue: TColor); procedure SetFrameEdges(AValue: TSynFrameEdges); - procedure SetFramePriority(AValue: integer); procedure SetFrameStyle(AValue: TSynLineStyle); procedure SetStyle(AValue: TFontStyles); procedure SetStyleMask(AValue: TFontStyles); - procedure SetStylePriority(Index: TFontStyle; AValue: integer); protected procedure AssignFrom(Src: TLazSynCustomTextAttributes); virtual; + procedure DoClear; virtual; procedure Changed; procedure DoChange; virtual; - procedure InitPriorities; public constructor Create; - procedure Clear; virtual; + procedure Clear; procedure Assign(aSource: TPersistent); override; procedure BeginUpdate; procedure EndUpdate; - procedure SetAllPriorities(APriority: integer); public property Background: TColor read FBackground write SetBackground; property Foreground: TColor read FForeground write SetForeground; @@ -123,13 +113,6 @@ type property FrameEdges: TSynFrameEdges read FFrameEdges write SetFrameEdges; property Style: TFontStyles read fStyle write SetStyle; property StyleMask: TFontStyles read fStyleMask write SetStyleMask; - property BackPriority: integer read FBackPriority write SetBackPriority; - property ForePriority: integer read FForePriority write SetForePriority; - property FramePriority: integer read FFramePriority write SetFramePriority; - property StylePriority[Index: TFontStyle]: integer read GetStylePriority write SetStylePriority; - property BoldPriority: integer index fsBold read GetStylePriority write SetStylePriority default 0; - property ItalicPriority: integer index fsItalic read GetStylePriority write SetStylePriority default 0; - property UnderlinePriority: integer index fsUnderline read GetStylePriority write SetStylePriority default 0; end; { TSynHighlighterAttributes } @@ -187,6 +170,35 @@ type property StyleMask stored GetFontStyleMaskStored; end; + { TSynHighlighterAttributesModifier } + + TSynHighlighterAttributesModifier = class(TSynHighlighterAttributes) + {strict} private + FBackPriority: integer; + FForePriority: integer; + FFramePriority: integer; + FStylePriority: Array [TFontStyle] of integer; + function GetStylePriority(Index: TFontStyle): integer; + procedure SetBackPriority(AValue: integer); + procedure SetForePriority(AValue: integer); + procedure SetFramePriority(AValue: integer); + procedure SetStylePriority(Index: TFontStyle; AValue: integer); + protected + procedure AssignFrom(Src: TLazSynCustomTextAttributes); override; + procedure DoClear; override; + procedure InitPriorities; + public + procedure SetAllPriorities(APriority: integer); + property StylePriority[Index: TFontStyle]: integer read GetStylePriority write SetStylePriority; + published + property BackPriority: integer read FBackPriority write SetBackPriority; + property ForePriority: integer read FForePriority write SetForePriority; + property FramePriority: integer read FFramePriority write SetFramePriority; + property BoldPriority: integer index fsBold read GetStylePriority write SetStylePriority default 0; + property ItalicPriority: integer index fsItalic read GetStylePriority write SetStylePriority default 0; + property UnderlinePriority: integer index fsUnderline read GetStylePriority write SetStylePriority default 0; + end; + TSynHighlighterCapability = ( hcUserSettings, // supports Enum/UseUserSettings hcRegistry, // supports LoadFrom/SaveToRegistry @@ -420,6 +432,94 @@ implementation const IDLE_SCAN_CHUNK_SIZE = 2500; +{ TSynHighlighterAttributesModifier } + +function TSynHighlighterAttributesModifier.GetStylePriority(Index: TFontStyle + ): integer; +begin + Result := FStylePriority[Index]; +end; + +procedure TSynHighlighterAttributesModifier.SetBackPriority(AValue: integer); +begin + if FBackPriority = AValue then Exit; + FBackPriority := AValue; + Changed; +end; + +procedure TSynHighlighterAttributesModifier.SetForePriority(AValue: integer); +begin + if FForePriority = AValue then Exit; + FForePriority := AValue; + Changed; +end; + +procedure TSynHighlighterAttributesModifier.SetFramePriority(AValue: integer); +begin + if FFramePriority = AValue then Exit; + FFramePriority := AValue; + Changed; +end; + +procedure TSynHighlighterAttributesModifier.SetStylePriority(Index: TFontStyle; + AValue: integer); +begin + if FStylePriority[Index] = AValue then Exit; + FStylePriority[Index] := AValue; + Changed; +end; + +procedure TSynHighlighterAttributesModifier.AssignFrom( + Src: TLazSynCustomTextAttributes); +var + Source: TSynHighlighterAttributesModifier; + j: TFontStyle; +begin + inherited AssignFrom(Src); + if Src is TSynHighlighterAttributesModifier then begin + Source := TSynHighlighterAttributesModifier(Src); + ForePriority := Source.ForePriority; + BackPriority := Source.BackPriority; + FramePriority := Source.FramePriority; + for j := Low(TFontStyle) to High(TFontStyle) do + StylePriority[j] := Source.StylePriority[j]; + end + else + InitPriorities; +end; + +procedure TSynHighlighterAttributesModifier.DoClear; +begin + inherited DoClear; + InitPriorities; +end; + +procedure TSynHighlighterAttributesModifier.InitPriorities; +var + i: TFontStyle; +begin + BeginUpdate; + ForePriority := 0; + BackPriority := 0; + FramePriority := 0; + for i := Low(TFontStyle) to High(TFontStyle) do + StylePriority[i] := 0; + EndUpdate; +end; + +procedure TSynHighlighterAttributesModifier.SetAllPriorities(APriority: integer); +var + i: TFontStyle; +begin + BeginUpdate; + ForePriority := APriority; + BackPriority := APriority; + FramePriority := APriority; + for i := Low(TFontStyle) to High(TFontStyle) do + StylePriority[i] := APriority; + EndUpdate; +end; + {$IFDEF _Gp_MustEnhanceRegistry} function IsRelative(const Value: string): Boolean; begin @@ -520,18 +620,6 @@ begin Changed; end; -function TLazSynCustomTextAttributes.GetStylePriority(Index: TFontStyle): integer; -begin - Result := FStylePriority[Index]; -end; - -procedure TLazSynCustomTextAttributes.SetBackPriority(AValue: integer); -begin - if FBackPriority = AValue then Exit; - FBackPriority := AValue; - Changed; -end; - procedure TLazSynCustomTextAttributes.SetForeground(AValue: TColor); begin if FForeground = AValue then Exit; @@ -539,13 +627,6 @@ begin Changed; end; -procedure TLazSynCustomTextAttributes.SetForePriority(AValue: integer); -begin - if FForePriority = AValue then Exit; - FForePriority := AValue; - Changed; -end; - procedure TLazSynCustomTextAttributes.SetFrameColor(AValue: TColor); begin if FFrameColor = AValue then Exit; @@ -560,13 +641,6 @@ begin Changed; end; -procedure TLazSynCustomTextAttributes.SetFramePriority(AValue: integer); -begin - if FFramePriority = AValue then Exit; - FFramePriority := AValue; - Changed; -end; - procedure TLazSynCustomTextAttributes.SetFrameStyle(AValue: TSynLineStyle); begin if FFrameStyle = AValue then Exit; @@ -588,13 +662,6 @@ begin Changed; end; -procedure TLazSynCustomTextAttributes.SetStylePriority(Index: TFontStyle; AValue: integer); -begin - if FStylePriority[Index] = AValue then Exit; - FStylePriority[Index] := AValue; - Changed; -end; - procedure TLazSynCustomTextAttributes.Changed; begin FWasChanged := True; @@ -609,24 +676,22 @@ begin // end; +procedure TLazSynCustomTextAttributes.DoClear; +begin + Background := clNone; + Foreground := clNone; + FrameColor := clNone; + FrameStyle := slsSolid; + FrameEdges := sfeAround; + Style := []; + StyleMask := []; +end; + procedure TLazSynCustomTextAttributes.DoChange; begin // end; -procedure TLazSynCustomTextAttributes.InitPriorities; -var - i: TFontStyle; -begin - BeginUpdate; - ForePriority := 0; - BackPriority := 0; - FramePriority := 0; - for i := Low(TFontStyle) to High(TFontStyle) do - StylePriority[i] := 0; - EndUpdate; -end; - constructor TLazSynCustomTextAttributes.Create; begin inherited; @@ -638,26 +703,17 @@ end; procedure TLazSynCustomTextAttributes.Clear; begin BeginUpdate; - Background := clNone; - Foreground := clNone; - FrameColor := clNone; - FrameStyle := slsSolid; - FrameEdges := sfeAround; - Style := []; - StyleMask := []; - InitPriorities; + DoClear; EndUpdate; end; procedure TLazSynCustomTextAttributes.Assign(aSource: TPersistent); var Source : TLazSynCustomTextAttributes; - j: TFontStyle; begin if Assigned(aSource) and (aSource is TLazSynCustomTextAttributes) then begin BeginUpdate; - InitPriorities; Source := TLazSynCustomTextAttributes(aSource); Foreground := Source.Foreground; Background := Source.Background; @@ -666,11 +722,6 @@ begin FrameEdges := Source.FrameEdges; Style := Source.FStyle; StyleMask := Source.FStyleMask; - ForePriority := Source.ForePriority; - BackPriority := Source.BackPriority; - FramePriority := Source.FramePriority; - for j := Low(TFontStyle) to High(TFontStyle) do - StylePriority[j] := Source.StylePriority[j]; AssignFrom(Source); EndUpdate; end @@ -690,19 +741,6 @@ begin Changed; end; -procedure TLazSynCustomTextAttributes.SetAllPriorities(APriority: integer); -var - i: TFontStyle; -begin - BeginUpdate; - ForePriority := APriority; - BackPriority := APriority; - FramePriority := APriority; - for i := Low(TFontStyle) to High(TFontStyle) do - StylePriority[i] := APriority; - EndUpdate; -end; - { TSynHighlighterAttributes } constructor TSynHighlighterAttributes.Create(attribName: string; aStoredName: String = ''); diff --git a/components/synedit/syneditmiscclasses.pp b/components/synedit/syneditmiscclasses.pp index f7ee53d285..5c8d939a14 100644 --- a/components/synedit/syneditmiscclasses.pp +++ b/components/synedit/syneditmiscclasses.pp @@ -209,7 +209,7 @@ type { TSynSelectedColor } - TSynSelectedColor = class(TLazSynCustomTextAttributes) + TSynSelectedColor = class(TSynHighlighterAttributesModifier) private FCurrentStartX: TLazSynDisplayTokenBound; FCurrentEndX: TLazSynDisplayTokenBound; @@ -228,6 +228,7 @@ type function IsMatching(ABound1, ABound2: TLazSynDisplayTokenBound): Boolean; protected procedure DoChange; override; + procedure DoClear; override; procedure AssignFrom(Src: TLazSynCustomTextAttributes); override; property FrameSidePriority[Side: TLazSynBorderSide]: integer read GetFrameSidePriority; property FrameSideOrigin[Side: TLazSynBorderSide]: TSynFrameEdges read GetFrameSideOrigin; @@ -250,7 +251,6 @@ type property CurrentEndX: TLazSynDisplayTokenBound read FCurrentEndX write FCurrentEndX; public constructor Create; - procedure Clear; override; function IsEnabled: boolean; function GetModifiedStyle(aStyle: TFontStyles): TFontStyles; procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor; @@ -624,7 +624,7 @@ end; constructor TSynSelectedColor.Create; begin - inherited Create; + inherited Create('', ''); Clear; MergeFinalStyle := False; Background := clHighLight; @@ -726,6 +726,31 @@ begin OnChange(Self); end; +procedure TSynSelectedColor.DoClear; +var + i: TLazSynBorderSide; +begin + inherited DoClear; + FFrameSidesInitialized := False; + for i := low(TLazSynBorderSide) to high(TLazSynBorderSide) do begin + FFrameSideColors[i] := clNone; + FFrameSideStyles[i] := slsSolid; + FFrameSideOrigin[i] := sfeNone; + end; + FStartX.Physical := -1; + FEndX.Physical := -1; + FStartX.Logical := -1; + FEndX.Logical := -1; + FStartX.Offset := 0; + FEndX.Offset := 0; + FCurrentStartX.Physical := -1; + FCurrentEndX.Physical := -1; + FCurrentStartX.Logical := -1; + FCurrentEndX.Logical := -1; + FCurrentStartX.Offset := 0; + FCurrentEndX.Offset := 0; +end; + procedure TSynSelectedColor.AssignFrom(Src: TLazSynCustomTextAttributes); var i: TLazSynBorderSide; @@ -881,33 +906,6 @@ begin FEndX.Offset := AEndOffs; end; -procedure TSynSelectedColor.Clear; -var - i: TLazSynBorderSide; -begin - BeginUpdate; - inherited Clear; - FFrameSidesInitialized := False; - for i := low(TLazSynBorderSide) to high(TLazSynBorderSide) do begin - FFrameSideColors[i] := clNone; - FFrameSideStyles[i] := slsSolid; - FFrameSideOrigin[i] := sfeNone; - end; - FStartX.Physical := -1; - FEndX.Physical := -1; - FStartX.Logical := -1; - FEndX.Logical := -1; - FStartX.Offset := 0; - FEndX.Offset := 0; - FCurrentStartX.Physical := -1; - FCurrentEndX.Physical := -1; - FCurrentStartX.Logical := -1; - FCurrentEndX.Logical := -1; - FCurrentStartX.Offset := 0; - FCurrentEndX.Offset := 0; - EndUpdate; -end; - function TSynSelectedColor.IsEnabled: boolean; begin Result := (Background <> clNone) or (Foreground <> clNone) or (FrameColor <> clNone) or diff --git a/ide/editoroptions.pp b/ide/editoroptions.pp index da33315054..0d04b0276f 100644 --- a/ide/editoroptions.pp +++ b/ide/editoroptions.pp @@ -218,7 +218,7 @@ type { TColorSchemeAttribute } - TColorSchemeAttribute = class(TSynHighlighterAttributes) + TColorSchemeAttribute = class(TSynHighlighterAttributesModifier) private FGroup: TAhaGroupName; FOwner: TColorSchemeLanguage; @@ -227,8 +227,7 @@ type function OldAdditionalAttributeName(NewAha: String): string; public constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: string; aStoredName: String = ''); - procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute); - procedure ApplyTo(aDest: TSynSelectedColor); + procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute = nil); procedure Assign(Src: TPersistent); override; function Equals(Other: TColorSchemeAttribute): Boolean; reintroduce; function GetSchemeGlobal: TColorSchemeAttribute; @@ -5583,49 +5582,39 @@ begin aDest.FrameEdges := Src.FrameEdges; aDest.FrameStyle := Src.FrameStyle; aDest.Style := Src.Style; - aDest.StyleMask := Src.StyleMask; - aDest.Features := Src.Features; - if aDefault <> nil then begin - if aDefault.IsUsingSchemeGlobals then - aDefault := aDefault.GetSchemeGlobal; - if Background = clDefault then - aDest.Background := aDefault.Background; - if Foreground = clDefault then - aDest.Foreground := aDefault.Foreground; - if FrameColor = clDefault then begin - aDest.FrameColor := aDefault.FrameColor; - aDest.FrameEdges := aDefault.FrameEdges; - aDest.FrameStyle := aDefault.FrameStyle; + if hafStyleMask in Src.Features then + aDest.StyleMask := Src.StyleMask + else + aDest.StyleMask := [low(TFontStyle)..high(TFontStyle)]; + + if not (aDest is TSynSelectedColor) then begin + aDest.Features := Src.Features; + + if aDefault <> nil then begin + if aDefault.IsUsingSchemeGlobals then + aDefault := aDefault.GetSchemeGlobal; + if Background = clDefault then + aDest.Background := aDefault.Background; + if Foreground = clDefault then + aDest.Foreground := aDefault.Foreground; + if FrameColor = clDefault then begin + aDest.FrameColor := aDefault.FrameColor; + aDest.FrameEdges := aDefault.FrameEdges; + aDest.FrameStyle := aDefault.FrameStyle; + end; end; + + //if aDest is TSynHighlighterAttributesModifier then begin + //end + + if aDest is TColorSchemeAttribute then + TColorSchemeAttribute(aDest).Group := Src.Group; end; - if aDest is TColorSchemeAttribute then - TColorSchemeAttribute(aDest).Group := Src.Group; finally aDest.EndUpdate; end; end; -procedure TColorSchemeAttribute.ApplyTo(aDest: TSynSelectedColor); -var - Src: TColorSchemeAttribute; -begin - Src := Self; - if IsUsingSchemeGlobals then - Src := GetSchemeGlobal; - aDest.BeginUpdate; - aDest.Foreground := Src.Foreground; - aDest.Background := Src.Background; - aDest.FrameColor := Src.FrameColor; - aDest.FrameEdges := Src.FrameEdges; - aDest.FrameStyle := Src.FrameStyle; - aDest.Style := Src.Style; - if hafStyleMask in Src.Features then - aDest.StyleMask := Src.StyleMask - else - aDest.StyleMask := [low(TFontStyle)..high(TFontStyle)]; - aDest.EndUpdate; -end; - procedure TColorSchemeAttribute.Assign(Src: TPersistent); begin inherited Assign(Src);