Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: daniloz on October 27, 2011, 02:57:09 pm

Title: Workspace loading and Active Project
Post by: daniloz 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...
Title: Re: Workspace loading and Active Project
Post by: MortenMacFly 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.
Title: Re: Workspace loading and Active Project
Post by: Jenna 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();
}
Title: Re: Workspace loading and Active Project
Post by: Jenna 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().
Title: Re: Workspace loading and Active Project
Post by: daniloz 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?

Title: Re: Workspace loading and Active Project
Post by: daniloz 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:
Title: Re: Workspace loading and Active Project
Post by: Jenna 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.
Title: Re: Workspace loading and Active Project
Post by: daniloz 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.
Title: Re: Workspace loading and Active Project
Post by: MortenMacFly 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.
Title: Re: Workspace loading and Active Project
Post by: daniloz 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....
Title: Re: Workspace loading and Active Project
Post by: frithjofh 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
Title: Re: Workspace loading and Active Project
Post by: MortenMacFly 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. ;-)
Title: Re: Workspace loading and Active Project
Post by: MortenMacFly 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.
Title: Re: Workspace loading and Active Project
Post by: Alpha 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 (http://wiki.codeblocks.org/index.php?title=DisplayEvents_plugin) in the plugins page (http://wiki.codeblocks.org/index.php?title=Code::Blocks_Plugins#3rd_Party_Plugins) about a month ago.
Title: Re: Workspace loading and Active Project
Post by: daniloz 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
Title: Re: Workspace loading and Active Project
Post by: daniloz on October 28, 2011, 08:37:47 am
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 (http://wiki.codeblocks.org/index.php?title=DisplayEvents_plugin) in the plugins page (http://wiki.codeblocks.org/index.php?title=Code::Blocks_Plugins#3rd_Party_Plugins) about a month ago.

And here is the patch for the DisplayEvents plugin, so we also see the new event...
(sorry about the "hardcoded" paths, I don't know how to do it better - suggestions are welcome)
Title: Re: Workspace loading and Active Project
Post by: oBFusCATed on October 28, 2011, 10:16:12 am
You're mixing tabs and spaces, C::B source is all spaces and you've not increased the SDK version numbers,
but you've changed the API/ABI for the ProjectManager. The SDK version numbers are in cbplugin.h.


Edit:
For the patch generation, goto the root of the working copy and execute "svn diff > my.patch".
This is the most robust way to generate patches. I've seen tortoisesvn mess up the patches it creates.
Title: Re: Workspace loading and Active Project
Post by: MortenMacFly on October 28, 2011, 10:18:39 am
If you do what I said here:

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.

You wouldn't even need to change the API interface. I think putting this event in WorkspaceChanged is the wrong place.
Title: Re: Workspace loading and Active Project
Post by: daniloz on October 28, 2011, 04:37:10 pm
If you do what I said here:

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.

You wouldn't even need to change the API interface. I think putting this event in WorkspaceChanged is the wrong place.

Hey, Morten, sorry.... I haven't really understood what you've suggested. Now I do...
I'll change my implementation on Monday (hopefully) and provide a new patch as soon as available...
And maybe I'll change the event name to cbEVT_WORKSPACE_LOADING_COMPLETE, that would be more uniform with the other events names...
Title: Re: Workspace loading and Active Project
Post by: MortenMacFly on October 28, 2011, 05:05:24 pm
And maybe I'll change the event name to cbEVT_WORKSPACE_LOADING_COMPLETE, that would be more uniform with the other events names...
True... I'll wait patiently...
Title: Re: Workspace loading and Active Project
Post by: daniloz on October 28, 2011, 11:52:56 pm
And maybe I'll change the event name to cbEVT_WORKSPACE_LOADING_COMPLETE, that would be more uniform with the other events names...
True... I'll wait patiently...
I don't want to keep you wanting, so here it is...
The patch for cbEVT_WORKSPACE_LOADING_COMPLETE and for the DisplayEvents plugin.

@jens: any better way do do a patch for DisplayEvents than having a strange path for the original and patched versions?