[Lazarus] Format code on Save

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Feb 23 09:41:06 CET 2017


On 2017-02-23 07:52, Mattias Gaertner via Lazarus 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

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp


More information about the Lazarus mailing list