Mattias Gaertner wrote> But I noticed that with every save (Ctrl+S), the YourEvent gets called
> twice? Any idea why that is, and if it was by design or a bug?
Check parameter SaveStep.
I tried both sefsBeforeWrite and sefsAfterWrite - it made no difference to the issue of the method being called twice.
Also, what does the AddHandlerOnSaveEditorFile()'s "AtLast" parameter mean and do?
I also set the Return result to mrOK.
Here is the whole implementation of the event handler and Register call.
==========================
procedure Register;
begin
LazarusIDE.AddHandlerOnSaveEditorFile(@uJCFHandler.BeforeSaveCallJCF,
False);
end;
function TJCFHandler.BeforeSaveCallJCF(Sender: TObject;
aFile: TLazProjectFile; SaveStep: TSaveEditorFileStep;
TargetFilename: string): TModalResult;
var
cmd: TIDECommand;
begin
SaveStep := sefsBeforeWrite;
Result := mrOk;
cmd := IDECommandList.FindCommandByName('jcfCurrentEditorWindow');
if Assigned(cmd) then
begin
writeln('PASS: We found the JCF command');
ExecuteIDECommand(Sender, cmd.Command);
end;
end;
==========================
I'm using Lazarus 1.7 r54157 FPC 3.0.1 x86_64-freebsd-gtk2.
Regards,
Graeme