IDE+synedit: TSynHighlighterAttributes: added Caption:PString for non fixed resourcestring, fixed IDE to use Caption and StoredName correct

git-svn-id: trunk@41720 -
This commit is contained in:
mattias 2013-06-14 21:28:58 +00:00
parent 362f050d90
commit 8014b98269
4 changed files with 66 additions and 42 deletions

View File

@ -121,7 +121,8 @@ type
FStyleDefault: TFontStyles;
FStyleMaskDefault: TFontStyles;
FStoredName: string;
FName: string;
FConstName: string;
FCaption: PString;
FOnChange: TNotifyEvent;
function GetBackgroundColorStored: boolean;
function GetFontStyleMaskStored : boolean;
@ -140,6 +141,7 @@ type
public
constructor Create;
constructor Create(attribName: string; aStoredName: String = '');
constructor Create(attribName: PString; aStoredName: String);
procedure InternalSaveDefaultValues; virtual;
function LoadFromBorlandRegistry(rootKey: HKEY; attrKey, attrName: string;
oldStyle: boolean): boolean; virtual;
@ -150,8 +152,9 @@ type
public
property IntegerStyle: integer read GetStyleFromInt write SetStyleFromInt;
property IntegerStyleMask: integer read GetStyleMaskFromInt write SetStyleMaskFromInt;
property Name: string read fName;
property StoredName: string read FStoredName write FStoredName;
property Name: string read FConstName; // value of Caption at creation, use Caption instead, kept for compatibility
property Caption: PString read FCaption; // is never nil
property StoredName: string read FStoredName write FStoredName; // the identifier
property OnChange: TNotifyEvent read fOnChange write fOnChange;
published
property Background stored GetBackgroundColorStored;
@ -850,14 +853,32 @@ end;
{ TSynHighlighterAttributes }
constructor TSynHighlighterAttributes.Create(attribName: string; aStoredName: String = '');
constructor TSynHighlighterAttributes.Create(attribName: string;
aStoredName: String = '');
begin
Create;
fName := attribName;
FConstName := attribName;
FCaption := @FConstName;
if aStoredName = '' then
FStoredName := attribName
else
FStoredName := aStoredName;;
aStoredName := FConstName;
FStoredName := aStoredName;;
end;
constructor TSynHighlighterAttributes.Create(attribName: PString;
aStoredName: String);
begin
Create;
if attribName<>nil then begin
FConstName := attribName^;
FCaption := attribName;
end
else begin
FConstName := '';
FCaption := @FConstName;
end;
if aStoredName = '' then
aStoredName := FConstName;
FStoredName := aStoredName;;
end;
function TSynHighlighterAttributes.GetBackgroundColorStored: boolean;
@ -1194,7 +1215,7 @@ procedure TSynHighlighterAttributes.AssignFrom(Src: TLazSynCustomTextAttributes)
begin
inherited AssignFrom(Src);
if not (Src is TSynHighlighterAttributes) then exit;
FName := TSynHighlighterAttributes(Src).FName;
FConstName := TSynHighlighterAttributes(Src).FConstName;
FStoredName:= TSynHighlighterAttributes(Src).FStoredName;
Changed; {TODO: only if really changed}
end;
@ -1279,17 +1300,17 @@ procedure TSynCustomHighlighter.Assign(Source: TPersistent);
var
Src: TSynCustomHighlighter;
i, j: integer;
AttriName: string;
SrcAttri: TSynHighlighterAttributes;
StoredName: String;
begin
if (Source <> nil) and (Source is TSynCustomHighlighter) then begin
Src := TSynCustomHighlighter(Source);
for i := 0 to AttrCount - 1 do begin
// assign first attribute with the same name
AttriName := Attribute[i].Name;
StoredName := Attribute[i].StoredName;
for j := 0 to Src.AttrCount - 1 do begin
SrcAttri := Src.Attribute[j];
if AttriName = SrcAttri.Name then begin
if StoredName = SrcAttri.StoredName then begin
Attribute[i].Assign(SrcAttri);
continue;
end;

View File

@ -256,7 +256,7 @@ type
protected
procedure Init; override;
public
constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: string; aStoredName: String = '');
constructor Create(ASchemeLang: TColorSchemeLanguage; attribName: PString; aStoredName: String = '');
procedure ApplyTo(aDest: TSynHighlighterAttributes; aDefault: TColorSchemeAttribute = nil);
procedure Assign(Src: TPersistent); override;
function Equals(Other: TColorSchemeAttribute): Boolean; reintroduce;
@ -1983,7 +1983,7 @@ begin
EditorUserDefinedWordsGlobalId := EditorUserDefinedWordsGlobalId + 'a';
inherited Create;
FColorAttr := TColorSchemeAttribute.Create(nil, '');
FColorAttr := TColorSchemeAttribute.Create(nil, nil);
FColorAttr.Features := [hafBackColor, hafForeColor, hafFrameColor, hafAlpha, hafPrior,hafFrameStyle, hafFrameEdges, hafStyle, hafStyleMask];
FColorAttr.Group := agnText;
FColorAttr.SetAllPriorities(MARKUP_USER_DEF_PRIOR);
@ -2040,7 +2040,7 @@ begin
XMLConfig.ReadObject(Path + 'Main/', self, def);
def.Free;
ColorDef := TColorSchemeAttribute.Create(nil, '');
ColorDef := TColorSchemeAttribute.Create(nil, nil);
ColorDef.SetAllPriorities(MARKUP_USER_DEF_PRIOR);
FColorAttr.StoredName := 'c1';
FColorAttr.LoadFromXml(XMLConfig, Path + 'Color/', ColorDef, EditorOptsFormatVersion);
@ -2122,7 +2122,7 @@ begin
XMLConfig.WriteObject(Path + 'Main/', Self, def);
def.Free;
ColorDef := TColorSchemeAttribute.Create(nil, '');
ColorDef := TColorSchemeAttribute.Create(nil, nil);
ColorDef.SetAllPriorities(MARKUP_USER_DEF_PRIOR);
FColorAttr.StoredName := 'c1';
FColorAttr.SaveToXml(XMLConfig, Path + 'Color/', ColorDef);
@ -5629,7 +5629,7 @@ begin
end;
constructor TColorSchemeAttribute.Create(ASchemeLang: TColorSchemeLanguage;
attribName: string; aStoredName: String = '');
attribName: PString; aStoredName: String = '');
begin
inherited Create(attribName, aStoredName);
FOwner := ASchemeLang;
@ -5719,7 +5719,7 @@ function TColorSchemeAttribute.Equals(Other: TColorSchemeAttribute): Boolean;
begin
Result := (FGroup = Other.FGroup) and
(FUseSchemeGlobals = Other.FUseSchemeGlobals) and
(Name = Other.Name) and
// ignore resourcestring Name and Caption
(StoredName = Other.StoredName) and
(Background = Other.Background) and
(Foreground = Other.Foreground) and
@ -5823,8 +5823,8 @@ begin
// FormatVersion = 1 (only pascal colors)
if Defaults = nil then
Defaults := Self;
if Name = '' then exit;
aPath := aPath + StrToValidXMLName(Name) + '/';
if StoredName = '' then exit;
aPath := aPath + StrToValidXMLName(StoredName) + '/';
BackGround := aXMLConfig.GetValue(aPath + 'BackgroundColor', Defaults.Background);
ForeGround := aXMLConfig.GetValue(aPath + 'ForegroundColor', Defaults.Foreground);
FrameColor := aXMLConfig.GetValue(aPath + 'FrameColorColor', Defaults.FrameColor);
@ -5907,7 +5907,7 @@ begin
FHighlighter := LazSyntaxHighlighterClasses[ALang].Create(nil);
FLanguageName := FHighlighter.LanguageName;
end;
FDefaultAttribute := TColorSchemeAttribute.Create(Self, dlgAddHiAttrDefault, 'ahaDefault');
FDefaultAttribute := TColorSchemeAttribute.Create(Self, @dlgAddHiAttrDefault, 'ahaDefault');
FDefaultAttribute.Features := [hafBackColor, hafForeColor];
FDefaultAttribute.Group := agnDefault;
FAttributes.AddObject(UpperCase(FDefaultAttribute.StoredName), FDefaultAttribute);
@ -5928,9 +5928,10 @@ begin
FAttributes.Sorted := False;
if FHighlighter <> nil then begin
for i := 0 to FHighlighter.AttrCount - 1 do begin
csa := TColorSchemeAttribute.Create(Self, FHighlighter.Attribute[i].Name,
FHighlighter.Attribute[i].StoredName
);
csa := TColorSchemeAttribute.Create(Self,
FHighlighter.Attribute[i].Caption,
FHighlighter.Attribute[i].StoredName
);
csa.Assign(FHighlighter.Attribute[i]);
csa.Group := agnLanguage;
FAttributes.AddObject(UpperCase(csa.StoredName), csa);
@ -5939,7 +5940,7 @@ begin
for aha := Low(TAdditionalHilightAttribute) to High(TAdditionalHilightAttribute) do begin
if aha = ahaNone then continue;
csa := TColorSchemeAttribute.Create(Self, AdditionalHighlightAttributes[aha],
csa := TColorSchemeAttribute.Create(Self, @AdditionalHighlightAttributes[aha],
AhaToStoredName(aha)
);
csa.Features := ahaSupportedFeatures[aha];
@ -5991,8 +5992,9 @@ begin
FAttributes.Delete(j);
end
else
Attr := TColorSchemeAttribute.Create(Self, Src.AttributeAtPos[i].Name,
Src.AttributeAtPos[i].StoredName);
Attr := TColorSchemeAttribute.Create(Self,
Src.AttributeAtPos[i].Caption,
Src.AttributeAtPos[i].StoredName);
Attr.Assign(Src.AttributeAtPos[i]);
NewList.AddObject(UpperCase(Attr.StoredName), Attr);
if Src.AttributeAtPos[i] = Src.DefaultAttribute then
@ -6071,7 +6073,7 @@ begin
// Attribute hasn't SchemeDefault => Save diff to empty
if (Defaults = nil) then
// default all colors = clNone
EmptyDef := TColorSchemeAttribute.Create(Self, '', '')
EmptyDef := TColorSchemeAttribute.Create(Self, nil, '')
else
EmptyDef := nil;
@ -6107,13 +6109,13 @@ begin
FreeAndNil(EmptyDef);
// Version 5 and before stored the global background on the Whitespace attribute.
// If a whiespace Attribute was loaded (UseSchemeGlobals=false) then copy it
// If a whitespace Attribute was loaded (UseSchemeGlobals=false) then copy it
if (FormatVersion <= 5) and (DefaultAttribute <> nil) and
(FHighlighter <> nil) and (FHighlighter.WhitespaceAttribute <> nil) and
(Attribute[Highlighter.WhitespaceAttribute.Name] <> nil) and
(not Attribute[Highlighter.WhitespaceAttribute.Name].UseSchemeGlobals)
(Attribute[Highlighter.WhitespaceAttribute.StoredName] <> nil) and
(not Attribute[Highlighter.WhitespaceAttribute.StoredName].UseSchemeGlobals)
then
DefaultAttribute.Background := Attribute[Highlighter.WhitespaceAttribute.Name].Background;
DefaultAttribute.Background := Attribute[Highlighter.WhitespaceAttribute.StoredName].Background;
end;
procedure TColorSchemeLanguage.SaveToXml(aXMLConfig: TRttiXMLConfig; aPath: String;
@ -6140,7 +6142,7 @@ begin
if (Defaults = nil) then
// default all colors = clNone
EmptyDef := TColorSchemeAttribute.Create(Self, '', '')
EmptyDef := TColorSchemeAttribute.Create(Self, nil, '')
else
EmptyDef := nil;

View File

@ -233,9 +233,9 @@ begin
if Attri.IsUsingSchemeGlobals then
Attri := Attri.GetSchemeGlobal;
if FCurrentColorScheme = nil then exit;
AttriIdx := GetEnumValue(TypeInfo(TAdditionalHilightAttribute), Attri.StoredName);
if FCurrentColorScheme = nil then exit;
// Draw node background and name
if cdsSelected in State then begin
@ -478,7 +478,8 @@ begin
if Attri <> nil then begin
NewNode := ColorElementTree.Items.GetFirstNode;
while Assigned(NewNode) do begin
if (NewNode.Data <> nil) and (TColorSchemeAttribute(NewNode.Data).StoredName = Attri.StoredName) then
if (NewNode.Data <> nil)
and (TColorSchemeAttribute(NewNode.Data).StoredName = Attri.StoredName) then
break;
NewNode := NewNode.GetNext;
end;
@ -581,7 +582,7 @@ begin
end;
SetAttrPriorVal(Attr, f, i);
Node.Text := Format('%s%-3d %s', [COLOR_NODE_PREFIX, i, Attr.Name]);
Node.Text := Format('%s%-3d %s', [COLOR_NODE_PREFIX, i, Attr.Caption^]);
i := (Node.Index - List.TopItem.Index);
if (i < 0) or (i >= List.Height div Node.Height) then
@ -606,7 +607,7 @@ procedure TEditorColorOptionsFrame.ForePriorUpDownClick(Sender: TObject; Button:
Prior := NextPrior + 1;
if Prior > MAX_PRIOR then exit;
SetAttrPriorVal(Attr, AField, Prior);
ANode.Text := Format('%s%-3d %s', [COLOR_NODE_PREFIX, Prior, Attr.Name]);
ANode.Text := Format('%s%-3d %s', [COLOR_NODE_PREFIX, Prior, Attr.Caption^]);
ANode := ANode.GetPrev;
Attr := AttrForNode(ANode);
@ -628,7 +629,7 @@ procedure TEditorColorOptionsFrame.ForePriorUpDownClick(Sender: TObject; Button:
Prior := NextPrior - 1;
if Prior < MIN_PRIOR then exit;
SetAttrPriorVal(Attr, AField, Prior);
ANode.Text := Format('%s%-3d %s', [COLOR_NODE_PREFIX, Prior, Attr.Name]);
ANode.Text := Format('%s%-3d %s', [COLOR_NODE_PREFIX, Prior, Attr.Caption^]);
ANode := ANode.GetNext;
Attr := AttrForNode(ANode);
@ -870,7 +871,7 @@ procedure TEditorColorOptionsFrame.FillPriorEditor;
Attr := FCurrentColorScheme.AttributeAtPos[i];
if IsEnabled(Attr, ASelector) then begin
p := GetAttrPriorVal(Attr, ASelector);
AList.Items.Add(nil, Format('%s%-3d %s', [COLOR_NODE_PREFIX, p, Attr.Name])).Data := Attr;
AList.Items.Add(nil, Format('%s%-3d %s', [COLOR_NODE_PREFIX, p, Attr.Caption^])).Data := Attr;
end;
end;
AList.EndUpdate;
@ -1077,7 +1078,7 @@ begin
// Fill Attributes in
for i := 0 to FCurrentColorScheme.AttributeCount - 1 do begin
Attr := FCurrentColorScheme.AttributeAtPos[i];
if Attr.Name <> '' then begin
if Attr.StoredName <> '' then begin
case Attr.Group of
agnDefault, // continue; // default is currently not shown
agnLanguage:
@ -1093,7 +1094,7 @@ begin
ParentNode := ColorElementTree.Items.FindTopLvlNode(ParentName);
if ParentNode = nil then
ParentNode := ColorElementTree.Items.Add(nil, ParentName);
NewNode := ColorElementTree.Items.AddChild(ParentNode, COLOR_NODE_PREFIX + Attr.Name);
NewNode := ColorElementTree.Items.AddChild(ParentNode, COLOR_NODE_PREFIX + Attr.Caption^);
NewNode.Data := Pointer(Attr);
if Attr.Group = agnDefault then
DefNode := NewNode;

View File

@ -10159,7 +10159,7 @@ procedure TSourceEditorManager.OnSourceCompletionTimer(Sender: TObject);
Attri:=nil;
dec(LogCaret.X);
if SrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(LogCaret,Token,Attri)
and (Attri<>nil) and (Attri.Name=SYNS_AttrComment) then
and (Attri<>nil) and (Attri.StoredName=SYNS_XML_AttrComment) then
begin
exit;
end;