Author Topic: Puzzling cbEVT_EDITOR_* event behavior  (Read 9204 times)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Puzzling cbEVT_EDITOR_* event behavior
« on: December 10, 2009, 06:04:35 am »
Stuff I learned while playing with EditorTweaks...

When an editor is opened, C::B generates cbEVT_EDITOR_DEACTIVATED if already open editor, then cbEVT_EDITOR_ACTIVATED then cbEVT_EDITOR_OPEN
switching between editors: cbEVT_EDITOR_DEACTIVATED then cbEVT_EDITOR_ACTIVATED
When an editor is closed cbEVT_EDITOR_ACTIVATED for any new editor then cbEVT_EDITOR_CLOSED, but no cbEVT_EDITOR_DEACTIVATED!

Is this right? (disclaimer: the C::B on this box is a few of months out of date -- I'll test again on an up to date copy)

In particular,
1/ why no cbEVT_EDITOR_DEACTIVATED on close?
2/ why activated before open/close?


A slightly related issue. Might it be good to send some sort of notification after changing editor/environment settings?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #1 on: December 10, 2009, 06:44:32 am »
When an editor is opened, C::B generates cbEVT_EDITOR_DEACTIVATED if already open editor, then cbEVT_EDITOR_ACTIVATED then cbEVT_EDITOR_OPEN
Yes, Deactivated means "editor still open, but another one got active".

switching between editors: cbEVT_EDITOR_DEACTIVATED then cbEVT_EDITOR_ACTIVATED
Logical here, too.

When an editor is closed cbEVT_EDITOR_ACTIVATED for any new editor then cbEVT_EDITOR_CLOSED, but no cbEVT_EDITOR_DEACTIVATED!
Correct here, too as the editor closed is not "de-activated" (meaning still accessible), but truly destroyed.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #2 on: December 10, 2009, 01:58:29 pm »
When an editor is opened, C::B generates cbEVT_EDITOR_DEACTIVATED if already open editor, then cbEVT_EDITOR_ACTIVATED then cbEVT_EDITOR_OPEN
Yes, Deactivated means "editor still open, but another one got active".

I was expecting: cbEVT_EDITOR_DEACTIVATED if already open editor, cbEVT_EDITOR_OPEN then cbEVT_EDITOR_ACTIVATED

Quote
When an editor is closed cbEVT_EDITOR_ACTIVATED for any new editor then cbEVT_EDITOR_CLOSED, but no cbEVT_EDITOR_DEACTIVATED!
Correct here, too as the editor closed is not "de-activated" (meaning still accessible), but truly destroyed.

I expected: cbEVT_EDITOR_DEACTIVATED, cbEVT_EDITOR_CLOSED then cbEVT_EDITOR_ACTIVATED

You might be "legally"/"factually" right about these things, but this isn't very convenient behavior for a plugin developer. e.g. plugin wants to change menus depending on which editor is active, deactivating items if the editor closes. I would expect to only have to trap [DE]ACTIVATED events. Instead we have to trap the CLOSE event as well and to make it more difficult the CLOSE event comes after the ACTIVATE event, which requires a check to see if there is anything still open after the close (instead of just relying on the ACTIVATE event). You can work around it, but it takes extra work and is VERY confusing.

Maybe I just don't see the problem the current behavior solves.
« Last Edit: December 10, 2009, 03:36:46 pm by dmoore »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #3 on: December 10, 2009, 02:25:39 pm »
When an editor is opened, C::B generates cbEVT_EDITOR_DEACTIVATED if already open editor, then cbEVT_EDITOR_ACTIVATED then cbEVT_EDITOR_OPEN
Yes, Deactivated means "editor still open, but another one got active".

I was expecting: cbEVT_EDITOR_DEACTIVATED if already open editor, cbEVT_EDITOR_OPEN then cbEVT_EDITOR_ACTIVATED


example 1 , we have three files, A, B and C.
Now, A is already opened and the only active editor. B and C are not opened, so there is only one tab.

Action: If B is opened and activated, I expect the command sequence is:

cbEVT_EDITOR_DEACTIVATED of A
cbEVT_EDITOR_OPEN of B
cbEVT_EDITOR_ACTIVATED of B

example 2 , we have three files, A, B and C.
Now, A and B is already opened and A is the active editor. C are not opened.

Action: If B is activated, I expect the command sequence is:

cbEVT_EDITOR_DEACTIVATED of A
cbEVT_EDITOR_ACTIVATED of B

Am I right??



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #4 on: December 10, 2009, 03:35:11 pm »
example 1 , we have three files, A, B and C.
Now, A is already opened and the only active editor. B and C are not opened, so there is only one tab.

Action: If B is opened and activated, I expect the command sequence is:

cbEVT_EDITOR_DEACTIVATED of A
cbEVT_EDITOR_OPEN of B
cbEVT_EDITOR_ACTIVATED of B

not quite: cbEVT_EDITOR_DEACTIVATED of A, cbEVT_EDITOR_ACTIVATED of B then cbEVT_EDITOR_OPEN of B

so cbEVT_EDITOR_OPEN really means open and fully loaded?

Quote
Action: If B is activated, I expect the command sequence is:

cbEVT_EDITOR_DEACTIVATED of A
cbEVT_EDITOR_ACTIVATED of B

Am I right??

yes.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #5 on: December 10, 2009, 03:41:44 pm »
When an editor is closed cbEVT_EDITOR_ACTIVATED for any new editor then cbEVT_EDITOR_CLOSED, but no cbEVT_EDITOR_DEACTIVATED!
Correct here, too as the editor closed is not "de-activated" (meaning still accessible), but truly destroyed.

If this is correct, then I don't see why we need a DEACTIVATED event at all. Just include pointers to the editors we switched to and from (or NULL if one of those doesn't exist) in the ACTIVATED event. It would then make sense to rename the ACTIVATED event to SWITCHED event. I still think we should send a switch event on close, however, even if there are no more open files. This is just more usable for the end user.
« Last Edit: December 10, 2009, 04:00:01 pm by dmoore »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #6 on: December 10, 2009, 04:18:38 pm »
Not much time to look into this any closer but did you consider that loading / opening an editor might fail (thus there is no deactivated/activated event at all) and selecting another editor tab (meaning without opening) has to be considered, too?

A failure might happen in every process the event queue describes. And we not only have opening a file, but also just switching a file. I don't see how we can differ between all this stages / failure cases other that as it is implemented now.

But I am tired atm...
« Last Edit: December 10, 2009, 04:20:49 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #7 on: December 10, 2009, 08:59:30 pm »
To illustrate, attached is a patch that implements a SWITCHED event in addition to the ACTIVATED/DEACTIVATED events. SWITCHED fills the event with pointers to the old and new editors, and will be called when an editor is opened, closed or there is a switch between editors. Probably need to put in some checks to prevent emission of redundant events. Ideally, any plugin that wanted to offer editor specific menus only needs to hook into this event.

[attachment deleted by admin]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #8 on: December 11, 2009, 05:18:36 am »
example 1 , we have three files, A, B and C.
Now, A is already opened and the only active editor. B and C are not opened, so there is only one tab.

Action: If B is opened and activated, I expect the command sequence is:

cbEVT_EDITOR_DEACTIVATED of A
cbEVT_EDITOR_OPEN of B
cbEVT_EDITOR_ACTIVATED of B

not quite: cbEVT_EDITOR_DEACTIVATED of A, cbEVT_EDITOR_ACTIVATED of B then cbEVT_EDITOR_OPEN of B

Thanks!!

So, what is the logic of the message sequence when a file is opening?

Why cbEVT_EDITOR_ACTIVATED of B should be sent before cbEVT_EDITOR_OPEN of B

In my opinion, I think an editor should firstly be opened(which means loading the file from hard disk), after that, it has two visible status, "active state"(it is the front tab) or "de-active state" (it is an editor in the background).



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #9 on: December 11, 2009, 02:26:12 pm »
It's because activation comes from wxAuiNotebook.

It means the tab is "activated" before the file is opened and loaded into the wxAuiNotebook page.

It should be called cbEVT_TAB_ACTIVATED. Then it'd make sense.


Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #10 on: December 11, 2009, 05:40:20 pm »
It's because activation comes from wxAuiNotebook.

It means the tab is "activated" before the file is opened and loaded into the wxAuiNotebook page.

It should be called cbEVT_TAB_ACTIVATED. Then it'd make sense.

Instead, I'd say that based on the current behavior the cbEVT_EDITOR_OPEN should be called something like cbEVT_EDITOR_LOADED. cbEVT_EDITOR_ACTIVATED does fill the pointer with a valid editor control so it's not just about the Tab being active (despite the fact the its implementation uses notebook page switching events). And since ACTIVATED is EFFECTIVELY signalling the creation of a new tab/editor (since it comes before the OPEN) I don't see why we wouldn't call DEACTIVATED when a Tab/editor is removed.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #11 on: December 12, 2009, 02:17:39 pm »
Quote from: dmoore link=topic=11663.msg79336#msg79336

... cbEVT_EDITOR_ACTIVATED does fill the pointer with a valid editor control ...

No and Yes.

When a Project is loaded, cbEVT_EDITOR_ACTIVATED has an EditorBase, but no Scintilla control. The editor "control" does not appear until the actual cbEVT_EDITOR_OPEN.

After the cbEVT_EDITOR_OPEN, all subsequent cbEVT_EDITOR_ACTIVATED events will contain the scintilla control.

This has given BrowseTracker no end of grief.


« Last Edit: December 12, 2009, 02:20:16 pm by Pecan »

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Puzzling cbEVT_EDITOR_* event behavior
« Reply #12 on: December 12, 2009, 03:10:46 pm »
When a Project is loaded, cbEVT_EDITOR_ACTIVATED has an EditorBase, but no Scintilla control. The editor "control" does not appear until the actual cbEVT_EDITOR_OPEN.

so ideally CB should defer add and activating the tab until after the control has been instantiated?