mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 20:59:08 +02:00
IDE: Code-Templates, add version and file-version
git-svn-id: trunk@62274 -
This commit is contained in:
parent
8f520dbc50
commit
524c8b9565
@ -2331,13 +2331,16 @@ end;
|
|||||||
|
|
||||||
const
|
const
|
||||||
EditOptsConfFileName = 'editoroptions.xml';
|
EditOptsConfFileName = 'editoroptions.xml';
|
||||||
|
DciFileVersion = 1;
|
||||||
|
DciFileVersionName = '!FileVersion';
|
||||||
|
DciVersionName = '!Version';
|
||||||
|
|
||||||
function BuildBorlandDCIFile(
|
function BuildBorlandDCIFile(
|
||||||
ACustomSynAutoComplete: TCustomSynAutoComplete): Boolean;
|
ACustomSynAutoComplete: TCustomSynAutoComplete): Boolean;
|
||||||
// returns if something has changed
|
// returns if something has changed
|
||||||
var
|
var
|
||||||
sl: TStringList;
|
sl: TStringList;
|
||||||
i, sp, ep: Integer;
|
i, sp, ep, v: Integer;
|
||||||
Token, Comment, Value: String;
|
Token, Comment, Value: String;
|
||||||
Attributes: TStrings;
|
Attributes: TStrings;
|
||||||
begin
|
begin
|
||||||
@ -2351,6 +2354,14 @@ begin
|
|||||||
Value := ACustomSynAutoComplete.CompletionValues[i];
|
Value := ACustomSynAutoComplete.CompletionValues[i];
|
||||||
sl.Add('[' + Token + ' | ' + Comment + ']');
|
sl.Add('[' + Token + ' | ' + Comment + ']');
|
||||||
Attributes:=ACustomSynAutoComplete.CompletionAttributes[i];
|
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
|
if (Attributes<>nil) and (Attributes.Count>0) then begin
|
||||||
sl.Add(CodeTemplateAttributesStartMagic);
|
sl.Add(CodeTemplateAttributesStartMagic);
|
||||||
sl.AddStrings(Attributes);
|
sl.AddStrings(Attributes);
|
||||||
@ -5216,10 +5227,27 @@ end;
|
|||||||
|
|
||||||
function TEditorOptions.LoadCodeTemplates(AnAutoComplete: TSynEditAutoComplete
|
function TEditorOptions.LoadCodeTemplates(AnAutoComplete: TSynEditAutoComplete
|
||||||
): TModalResult;
|
): TModalResult;
|
||||||
var
|
|
||||||
s: String;
|
function ResourceDCIAsText: String;
|
||||||
|
var
|
||||||
data: TResourceStream;
|
data: TResourceStream;
|
||||||
i: Int64;
|
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
|
begin
|
||||||
s := CodeTemplateFileNameExpand;
|
s := CodeTemplateFileNameExpand;
|
||||||
Result := mrAbort;
|
Result := mrAbort;
|
||||||
@ -5227,19 +5255,47 @@ begin
|
|||||||
try
|
try
|
||||||
LoadStringsFromFileUTF8(AnAutoComplete.AutoCompleteList, s);
|
LoadStringsFromFileUTF8(AnAutoComplete.AutoCompleteList, s);
|
||||||
Result := mrOK;
|
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
|
except
|
||||||
Result := mrAbort;
|
Result := mrAbort;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
data := TResourceStream.Create(HInstance, PChar('lazarus_dci_file'), PChar(RT_RCDATA));
|
AnAutoComplete.AutoCompleteList.Text := ResourceDCIAsText;
|
||||||
i := data.Size;
|
|
||||||
if i > 0 then begin
|
|
||||||
SetLength(s, i);
|
|
||||||
data.Read(s[1], i);
|
|
||||||
AnAutoComplete.AutoCompleteList.Text := s;
|
|
||||||
end;
|
|
||||||
data.Free;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user