Author Topic: Workspace loading and Active Project  (Read 16297 times)

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Workspace loading and Active Project
« on: October 27, 2011, 02:57:09 pm »
Hi All,

I'm working in a plugin and I'd like to know, when the user loads a workspace with several projects, after all projects are loaded, which is the active project.

Any ideas? I haven't found any event defined for that...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Workspace loading and Active Project
« Reply #1 on: October 27, 2011, 04:15:01 pm »
Any ideas? I haven't found any event defined for that...
A loading complete event does not exist.

However, you can use the project activated event.

If you really need an event for the case "workspace completely loaded", provide a patch accordingly. It should be really simple to implement. Create an event in sdk_events{.cpp/.h} and instrument the method "ProjectManager::LoadWorkspace" accordingly.
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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Workspace loading and Active Project
« Reply #2 on: October 27, 2011, 04:19:38 pm »
There is an event:
cbEVT_PROJECT_ACTIVATE
The event provides the active project as pointer:

Code
void MyPlugin::OnProjectActivated(CodeBlocksEvent& event)
{
    // project will be apointer to the active project
    cbProject* project = event.GetProject();
    // first check if project is not NULL
    if (project)
    {
        // do something meaningful here
    }
    event.Skip();
}

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Workspace loading and Active Project
« Reply #3 on: October 27, 2011, 04:23:38 pm »
Any ideas? I haven't found any event defined for that...
A loading complete event does not exist.

However, you can use the project activated event.

If you really need an event for the case "workspace completely loaded", provide a patch accordingly. It should be really simple to implement. Create an event in sdk_events{.cpp/.h} and instrument the method "ProjectManager::LoadWorkspace" accordingly.
If I see it right, cbEVT_WORKSPACE_CHANGED is send from EndLoadingWorkspace().

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Workspace loading and Active Project
« Reply #4 on: October 27, 2011, 04:25:36 pm »
There is an event:
cbEVT_PROJECT_ACTIVATE
The event provides the active project as pointer:

Hi jens,

I am aware of it and I'm using it for the case when the use changes the project. And I was also assuming that this event got triggered after a workspace loading, but it's not, actually.

Is this a feature or a bug?


Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Workspace loading and Active Project
« Reply #5 on: October 27, 2011, 04:29:27 pm »
However, you can use the project activated event.

If you really need an event for the case "workspace completely loaded", provide a patch accordingly. It should be really simple to implement. Create an event in sdk_events{.cpp/.h} and instrument the method "ProjectManager::LoadWorkspace" accordingly.
If I see it right, cbEVT_WORKSPACE_CHANGED is send from EndLoadingWorkspace().

I bumped into this event, but I thought that it was related to changes done to the Workspace, like projects added or removed, rather than Finishing Loading. So maybe  that's what I'm looking for...

Btw, I assume that changing the name of this event to avoid future confusion (to something like cbEVT_WORKSPACE_OPEN) is out of question due to APU compatibility issues, right?  :oops:

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Workspace loading and Active Project
« Reply #6 on: October 27, 2011, 04:34:33 pm »
I just looked into the events with my DisplayEvents-plugin, and I see it being triggered.
Here is a snippet of the log, if a workspace with two projects is loaded, each project has several targets (win, linux, debug, release ...)
No files are opened.
Code
16:29:19,888  =>  cbEVT_APP_ACTIVATED
16:29:19,891  =>  cbEVT_EDITOR_SWITCHED
16:29:19,891  =>  cbEVT_EDITOR_ACTIVATED
16:29:21,481  =>  cbEVT_WORKSPACE_CHANGED
16:29:21,507  =>  cbEVT_EDITOR_CLOSE
Loading workspace "/home/jens/src/src/SPS_Log.workspace"
Loading project file...
Parsing project file...
16:29:21,512  =>  cbEVT_PROJECT_RENAMED
16:29:21,512  =>  cbEVT_PROJECT_TARGETS_MODIFIED
16:29:21,513  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,513  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Debug
16:29:21,513  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,514  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Release
16:29:21,516  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,516  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target WinRelease
16:29:21,517  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,517  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target WinDebug
16:29:21,518  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,518  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Release gcc-4.4
16:29:21,518  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,519  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target clang++ Debug
Loading project files...
16:29:21,519  =>  cbEVT_PROJECT_BEGIN_ADD_FILES
16:29:21,520  =>  cbEVT_PROJECT_END_ADD_FILES
2 files loaded
Done loading project in 10ms
Project's base path: /home/jens/src/src/libbeckhoff/
Project's common toplevel path: /home/jens/src/src/libbeckhoff/
16:29:21,522  =>  cbEVT_BUILDTARGET_SELECTED
Loading project file...
Parsing project file...
16:29:21,524  =>  cbEVT_PROJECT_RENAMED
16:29:21,525  =>  cbEVT_PROJECT_TARGETS_MODIFIED
16:29:21,525  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,525  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Debug
16:29:21,526  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,526  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Release
16:29:21,526  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,527  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target WinRelease
16:29:21,527  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,527  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target WinDebug
16:29:21,528  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,528  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Release gcc-4.4
16:29:21,529  =>  cbEVT_BUILDTARGET_ADDED
16:29:21,529  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target clang++ Debug
Loading project files...
16:29:21,530  =>  cbEVT_PROJECT_BEGIN_ADD_FILES
16:29:21,531  =>  cbEVT_PROJECT_END_ADD_FILES
13 files loaded
Done loading project in 9ms
Project's base path: /home/jens/src/src/
Project's common toplevel path: /home/jens/src/src/
16:29:21,533  =>  cbEVT_BUILDTARGET_SELECTED
SPS_Log now depends on libbeckhoff (1 deps)
16:29:21,538  =>  cbEVT_PROJECT_ACTIVATE
16:29:21,539  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,541  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,541  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,542  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,542  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,548  =>  cbEVT_PROJECT_OPEN
16:29:21,548  =>  cbEVT_PROJECT_OPEN
16:29:21,549  =>  cbEVT_WORKSPACE_CHANGED
Passing list of files to batch-parser.
Header to parse with priority: '/usr/include/c++/4.6/cstddef'
Header to parse with priority: '/usr/include/wx-2.8/wx/defs.h'
Header to parse with priority: '/usr/include/wx-2.8/wx/dlimpexp.h'
Header to parse with priority: '/usr/include/wx-2.8/wx/toplevel.h'
Header to parse with priority: '/usr/include/boost/config.hpp'
Header to parse with priority: '/usr/include/boost/filesystem/config.hpp'
Add 6 priority parsing file(s) for project 'SPS_Log'...
Added 9 file(s) for project 'SPS_Log' to batch-parser...
Create new parser for project 'SPS_Log'
Starting batch parsing for project 'SPS_Log'...
Project 'SPS_Log' parsing stage done!
Project 'SPS_Log' parsing stage done (512 total parsed files, 26463 tokens in 0 minute(s), 2.260 seconds).
Updating class browser...
Class browser updated.
16:29:24,607  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:24,609  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:24,610  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:24,610  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:24,611  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:24,612  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
Add project (libbeckhoff) to parser
Done adding 1 files of project (libbeckhoff) to parser.
Add next project to parser.
Starting batch parsing for project 'libbeckhoff'...
Project 'libbeckhoff' parsing stage done!
Project 'libbeckhoff' parsing stage done (513 total parsed files, 26463 tokens in 0 minute(s), 0.021 seconds).
Updating class browser...
Class browser updated.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Workspace loading and Active Project
« Reply #7 on: October 27, 2011, 04:43:07 pm »
I just looked into the events with my DisplayEvents-plugin, and I see it being triggered.

Ok, but the interesting part from your log is:
Code
16:29:21,538  =>  cbEVT_PROJECT_ACTIVATE
16:29:21,539  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,541  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,541  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,542  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,542  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
16:29:21,548  =>  cbEVT_PROJECT_OPEN
16:29:21,548  =>  cbEVT_PROJECT_OPEN
16:29:21,549  =>  cbEVT_WORKSPACE_CHANGED

It shows that the cbEVT_PROJECT_ACTIVATE event is triggered *before* both cbEVT_PROJECT_OPEN events. That's what I was referring to. I was expecting it to be triggered *after* ALL projects have been loaded.

But, I see that I can use the cbEVT_WORKSPACE_CHANGED, as expected.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Workspace loading and Active Project
« Reply #8 on: October 27, 2011, 04:57:18 pm »
But, I see that I can use the cbEVT_WORKSPACE_CHANGED, as expected.
Didn't digged deeper into it, but if this event is really only thrown if the WS is loaded we should consider renaming it, indeed. I would have thought that this event is also triggered in case I change WS settings, like project dependencies.
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 daniloz

  • Regular
  • ***
  • Posts: 268
Re: Workspace loading and Active Project
« Reply #9 on: October 27, 2011, 05:01:03 pm »
But, I see that I can use the cbEVT_WORKSPACE_CHANGED, as expected.
Didn't digged deeper into it, but if this event is really only thrown if the WS is loaded we should consider renaming it, indeed. I would have thought that this event is also triggered in case I change WS settings, like project dependencies.

Ok, I haven't dug into it neither, so I'm also not sure....

Offline frithjofh

  • Regular
  • ***
  • Posts: 376
Re: Workspace loading and Active Project
« Reply #10 on: October 27, 2011, 05:45:14 pm »
@jens

Hello Jens,

you mentioned a plugin you use for developement: "DisplayEvents-plugin". Where do I find this one to use it myself?

Regards

frithjof
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Workspace loading and Active Project
« Reply #11 on: October 27, 2011, 07:26:14 pm »
you mentioned a plugin you use for developement: "DisplayEvents-plugin". Where do I find this one to use it myself?
Search the forums. ;-)
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Workspace loading and Active Project
« Reply #12 on: October 27, 2011, 07:28:08 pm »
Ok, I haven't dug into it neither, so I'm also not sure....
I had a look: I guess for your purpose this event is no good. It really fires several times, whenever a project is closed, all projects are closed, a WS is closed, a project has finished loading and a WS has finished loading. If that' still OK with you - go ahead. However, the most accurate way for your purpose would really be to implement such an event yourself and provide us with a patch.
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 Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Workspace loading and Active Project
« Reply #13 on: October 27, 2011, 11:49:07 pm »
you mentioned a plugin you use for developement: "DisplayEvents-plugin". Where do I find this one to use it myself?
Search the forums. ;-)
I also indexed it in the plugins page about a month ago.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Workspace loading and Active Project
« Reply #14 on: October 28, 2011, 08:31:10 am »
Ok, I haven't dug into it neither, so I'm also not sure....
I had a look: I guess for your purpose this event is no good. It really fires several times, whenever a project is closed, all projects are closed, a WS is closed, a project has finished loading and a WS has finished loading. If that' still OK with you - go ahead. However, the most accurate way for your purpose would really be to implement such an event yourself and provide us with a patch.

Here is the patch for the event EVT_WORKSPACE_FINISH_LOADING...

[Edit]
And here the DisplayEvents plugin log (the end of it, actually):
Code
08:26:30,294  =>  cbEVT_PROJECT_TARGETS_MODIFIED
Loading target Debug
Loading project files...
08:26:30,296  =>  cbEVT_PROJECT_BEGIN_ADD_FILES
08:26:30,297  =>  cbEVT_PROJECT_END_ADD_FILES
2 files loaded
Done loading project in 10ms
08:26:30,302  =>  cbEVT_BUILDTARGET_SELECTED
08:26:30,910  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
08:26:30,911  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
08:26:30,912  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
08:26:30,920  =>  cbEVT_PROJECT_ACTIVATE
EnvVars: Obtained 'default' as active envvar set from config.
EnvVars: Active envvar set is 'default', config path '/sets/default'.
EnvVars: Searching for envvars in path '/sets/default'.
EnvVars: Read 0/0 envvars in path '/sets/default'.
08:26:30,954  =>  cbEVT_PROJECT_OPEN
08:26:31,002  =>  cbEVT_PROJECT_OPEN
08:26:31,004  =>  cbEVT_PROJECT_OPEN
08:26:31,006  =>  cbEVT_PROJECT_OPEN
08:26:31,007  =>  cbEVT_WORKSPACE_CHANGED
08:26:31,007  =>  cbEVT_WORKSPACE_FINISH_LOADING
« Last Edit: October 28, 2011, 11:50:16 pm by daniloz »