Page 1 of 1

Controlling the editor

Posted: Wed 26 Jun, 2013 07:13
by pepak
FAR3 build 3367: I am trying to open a file in the editor and get its EditorID for future use. I thought I would use this sequence:

Code: Select all

  Flags := EF_NONMODAL or EF_IMMEDIATERETURN or EF_DELETEONLYFILEONCLOSE;
  if FarApi.Editor(FileName, Title, 0, 0, -1, -1, Flags, 0, 1, CP_UTF8) = EEC_MODIFIED then
    if FarApi.EditorControl(-1, ECTL_GETINFO, 0, @EditorInfo) <> 0 then
      EditorID := EditorInfo.EditorID;
Unfortunately, the FarApi.EditorControl call always returns a zero (FALSE). So what is the correct way of opening an editor and getting its ID? Thanks.

Re: Controlling the editor

Posted: Wed 26 Jun, 2013 07:28
by pepak
On an unrelated note: If I open an editor in this way and intercept EE_CLOSE in ProcessEditorEventW, can I either:
a) Stop the close and keep the file in the editor, or
b) Override the EF_DELETEONLYFILEONCLOSE so that the file doesn't get deleted?
Thanks.

Re: Controlling the editor

Posted: Wed 26 Jun, 2013 13:11
by Shmuel
pepak wrote:FAR3 build 3367: I am trying to open a file in the editor and get its EditorID for future use. I thought I would use this sequence:

Code: Select all

  Flags := EF_NONMODAL or EF_IMMEDIATERETURN or EF_DELETEONLYFILEONCLOSE;
  if FarApi.Editor(FileName, Title, 0, 0, -1, -1, Flags, 0, 1, CP_UTF8) = EEC_MODIFIED then
    if FarApi.EditorControl(-1, ECTL_GETINFO, 0, @EditorInfo) <> 0 then
      EditorID := EditorInfo.EditorID;
Unfortunately, the FarApi.EditorControl call always returns a zero (FALSE). So what is the correct way of opening an editor and getting its ID? Thanks.
This same code translated to Lua works correctly, I get different ID's every time the code is run.
Check whether "or" is a bitwise operator in your version of Pascal (it's not so for all Pascal implementations).
pepak wrote:On an unrelated note: If I open an editor in this way and intercept EE_CLOSE in ProcessEditorEventW, can I either:
a) Stop the close and keep the file in the editor, or
b) Override the EF_DELETEONLYFILEONCLOSE so that the file doesn't get deleted?
Thanks.
As far as I know: NO to both questions.

Re: Controlling the editor

Posted: Wed 26 Jun, 2013 13:19
by pepak
Shmuel wrote:This same code translated to Lua works correctly, I get different ID's every time the code is run.
The problem was that I was using an uninitialized EditorInfo. Apparently I need to set its StructSize correctly.