IDE: Code-Templates, add version and file-version

git-svn-id: trunk@62274 -
This commit is contained in:
martin 2019-11-18 22:43:08 +00:00
parent 8f520dbc50
commit 524c8b9565

View File

@ -2331,13 +2331,16 @@ end;
const
EditOptsConfFileName = 'editoroptions.xml';
DciFileVersion = 1;
DciFileVersionName = '!FileVersion';
DciVersionName = '!Version';
function BuildBorlandDCIFile(
ACustomSynAutoComplete: TCustomSynAutoComplete): Boolean;
// returns if something has changed
var
sl: TStringList;
i, sp, ep: Integer;
i, sp, ep, v: Integer;
Token, Comment, Value: String;
Attributes: TStrings;
begin
@ -2351,6 +2354,14 @@ begin
Value := ACustomSynAutoComplete.CompletionValues[i];
sl.Add('[' + Token + ' | ' + Comment + ']');
Attributes:=ACustomSynAutoComplete.CompletionAttributes[i];
// Store DciFileVersion as attribute to first macro
v := Attributes.IndexOfName(DciFileVersionName);
if v >= 0 then
Attributes.Delete(v);
if i = 0 then
Attributes.Values[DciFileVersionName] := IntToStr(DciFileVersion);
if (Attributes<>nil) and (Attributes.Count>0) then begin
sl.Add(CodeTemplateAttributesStartMagic);
sl.AddStrings(Attributes);
@ -5216,10 +5227,27 @@ end;
function TEditorOptions.LoadCodeTemplates(AnAutoComplete: TSynEditAutoComplete
): TModalResult;
var
s: String;
function ResourceDCIAsText: String;
var
data: TResourceStream;
i: Int64;
begin
data := TResourceStream.Create(HInstance, PChar('lazarus_dci_file'), PChar(RT_RCDATA));
i := data.Size;
if i > 0 then begin
SetLength(Result, i);
data.Read(Result[1], i);
end;
data.Free;
end;
var
s: String;
FileVersion, i, j, v: Integer;
NewAutoComplete: TSynEditAutoComplete;
Attr: TStringList;
Added: Boolean;
begin
s := CodeTemplateFileNameExpand;
Result := mrAbort;
@ -5227,19 +5255,47 @@ begin
try
LoadStringsFromFileUTF8(AnAutoComplete.AutoCompleteList, s);
Result := mrOK;
FileVersion := AnAutoComplete.Completions.Count;
if (FileVersion > 0) then begin
FileVersion := AnAutoComplete.CompletionAttributes[0].IndexOfName(DciFileVersionName);
if (FileVersion >= 0) then
FileVersion := StrToIntDef(AnAutoComplete.CompletionAttributes[0][FileVersion], 0);
end;
if FileVersion < DciFileVersion then begin
// Merge new entries
NewAutoComplete := TSynEditAutoComplete.Create(nil);
NewAutoComplete.AutoCompleteList.Text := ResourceDCIAsText;
Added := False;
for i := 0 to NewAutoComplete.Completions.Count - 1 do begin
j := NewAutoComplete.CompletionAttributes[i].IndexOfName(DciVersionName);
if j < 0 then
continue;
v := StrToIntDef(AnAutoComplete.CompletionAttributes[i][j], 0);
if v <= FileVersion then
continue;
if AnAutoComplete.Completions.IndexOf(NewAutoComplete.Completions[i]) >= 0 then
continue;
Attr := TStringList.Create;
Attr.Assign(NewAutoComplete.CompletionAttributes[i]); // will be owned by AnAutoComplete;
AnAutoComplete.AddCompletion(
NewAutoComplete.Completions[i],
NewAutoComplete.CompletionValues[i],
NewAutoComplete.CompletionComments[i],
Attr);
Added := True;
end;
NewAutoComplete.Free;
if Added then
if BuildBorlandDCIFile(AnAutoComplete) then
SaveCodeTemplates(AnAutoComplete);
end;
except
Result := mrAbort;
end;
end
else begin
data := TResourceStream.Create(HInstance, PChar('lazarus_dci_file'), PChar(RT_RCDATA));
i := data.Size;
if i > 0 then begin
SetLength(s, i);
data.Read(s[1], i);
AnAutoComplete.AutoCompleteList.Text := s;
end;
data.Free;
AnAutoComplete.AutoCompleteList.Text := ResourceDCIAsText;
end;
end;