Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

cbEVT_PROJECT_OPEN and cbEVT_PROJECT_ACTIVATE

(1/2) > >>

daniloz:
Hi All,

I'm observing some unexpected behavior when using cbEVT_PROJECT_OPEN and cbEVT_PROJECT_ACTIVATE. Of course, unexpected from the point of view of what "I" was expecting... ;-)

So, I was expecting that cbEVT_PROJECT_OPEN would be fired up when the projects are opening (if we have more than one in the workspace) and just after all projects were loaded cbEVT_PROJECT_ACTIVATE would fire up...

But in my plugin, I'm seeing that cbEVT_PROJECT_ACTIVATE gets fired up before any hit on cbEVT_PROJECT_OPEN...

Any thoughts? Explanations?

Edit:

I found the following code in projectmanager.cpp:

--- Code: ---        RebuildTree();
        if (m_pActiveProject || m_pProjectToActivate)
        {
            if (m_pProjectToActivate)
            {
                SetProject(m_pProjectToActivate, true);
                m_pProjectToActivate = 0L;
            }
            m_pTree->Expand(m_pActiveProject->GetProjectNode());
        }
        m_pTree->Expand(m_TreeRoot); // make sure the root node is open
        m_pTree->SetItemText(m_TreeRoot, m_pWorkspace->GetTitle());

        UnfreezeTree(true);
        // sort out any global user vars that need to be defined now (in a batch) :)
        Manager::Get()->GetUserVariableManager()->Arrogate();

        int numNotes = 0;

        // and now send the project loaded events
        // since we were loading a workspace, these events were not sent before
        for (size_t i = 0; i < m_pProjects->GetCount(); ++i)
        {
            cbProject* project = m_pProjects->Item(i);

            // notify plugins that the project is loaded
            // moved here from cbProject::Open() because code-completion
            // kicks in too early and the perceived loading time is long...
            CodeBlocksEvent event(cbEVT_PROJECT_OPEN);
            event.SetProject(project);
            Manager::Get()->GetPluginManager()->NotifyPlugins(event);

            // since we 're iterating anyway, let's count the project notes that should be displayed
            if (project->GetShowNotesOnLoad() && !project->GetNotes().IsEmpty())
                ++numNotes;
        }

--- End code ---

So, I was right, the project is first activated (SetProject(m_pProjectToActivate, true)) and then the plugins are notified that the project are loaded.

@devs: Is this intended to be so? Any particular reason? I'd do the other way around: first send the LOAD notification to the plugins and then the ACTIVATE...

Alpha:
I think cbEVT_PROJECT_ACTIVATE is supposed to be triggered whenever anything gets bold-ed in the Projects tab of the Management pane.  (I am far from being a developer, so I could be completely wrong.)

(You could optionally do some detective work with the DisplayEvents plugin.)

daniloz:
Here is the output of the DisplayEvents plugin for a workspace with 4 projects (I just cut off the non-interesting parts):


--- Code: ---08:31:13,688  =>  cbEVT_WORKSPACE_CHANGED
Loading workspace "C:\Data\GPA\FW-DSP\Flexus.workspace"
Loading project file...
Parsing project file...
[...]
Loading project files...
[...]
261 files loaded
Done loading project in 423ms
08:31:14,137  =>  cbEVT_BUILDTARGET_SELECTED
Loading project file...
Parsing project file...
[...]
Loading project files...
[...]
202 files loaded
Done loading project in 379ms
08:31:14,528  =>  cbEVT_BUILDTARGET_SELECTED
Loading project file...
Parsing project file...
[...]
2 files loaded
Done loading project in 8ms
[...]
08:31:14,540  =>  cbEVT_BUILDTARGET_SELECTED
Loading project file...
Parsing project file...
[...]
2 files loaded
Done loading project in 8ms
[...]
08:31:14,553  =>  cbEVT_BUILDTARGET_SELECTED
08:31:15,165  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
08:31:15,166  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
08:31:15,167  =>  cbEVT_COMPILER_SET_BUILD_OPTIONS
08:31:15,184  =>  cbEVT_PROJECT_ACTIVATE
08:31:15,188  =>  cbEVT_PROJECT_OPEN
08:31:15,189  =>  cbEVT_PROJECT_OPEN
08:31:15,190  =>  cbEVT_PROJECT_OPEN
08:31:15,191  =>  cbEVT_PROJECT_OPEN
08:31:15,192  =>  cbEVT_WORKSPACE_CHANGED
08:31:15,193  =>  cbEVT_WORKSPACE_LOADING_COMPLETE

--- End code ---

Note at the end, that as I've reported the cbEVT_PROJECT_ACTIVATE occurs before the four cbEVT_PROJECT_OPEN.

Alpha:
I would guess that the purpose of cbEVT_PROJECT_ACTIVATE is to notify at the beginning of any process that will change which project is the active project.

--- Code: ---[... open workspace, read stuff ...]
14:32:25,785  =>  cbEVT_PROJECT_ACTIVATE
14:32:25,795  =>  cbEVT_PROJECT_OPEN
14:32:25,805  =>  cbEVT_PROJECT_OPEN
14:32:25,805  =>  cbEVT_PROJECT_OPEN
14:32:25,805  =>  cbEVT_PROJECT_OPEN
14:32:25,805  =>  cbEVT_PROJECT_OPEN
14:32:25,805  =>  cbEVT_PROJECT_OPEN
14:32:25,815  =>  cbEVT_WORKSPACE_CHANGED
[... parse files, set compiler options ...]
[... double click on a different project in the workspace ...]
14:33:26,512  =>  cbEVT_PROJECT_ACTIVATE
[... double click on the first project in the workspace ...]
14:37:35,601  =>  cbEVT_PROJECT_ACTIVATE
[... close a project ...]
14:40:57,381  =>  cbEVT_PROJECT_CLOSE
14:40:57,391  =>  cbEVT_BUILDTARGET_SELECTED
14:40:57,391  =>  cbEVT_WORKSPACE_CHANGED
[... close the active project ...]
Removed StringCtrl from all deps
15:01:53,086  =>  cbEVT_PROJECT_CLOSE
15:01:58,134  =>  cbEVT_PROJECT_ACTIVATE
15:01:58,134  =>  cbEVT_BUILDTARGET_SELECTED
15:01:58,134  =>  cbEVT_WORKSPACE_CHANGED
Delete parser for project 'StringCtrl'!

--- End code ---
(Log output has been trimmed.)

daniloz:

--- Quote from: Alpha on December 03, 2011, 09:06:41 pm ---I would guess that the purpose of cbEVT_PROJECT_ACTIVATE is to notify at the beginning of any process that will change which project is the active project.

--- End quote ---
I don't agree, because the event carries the active project, so I'd expect (apart from the name itself) that the event would be triggered when a new project just became active. Moreover, it's trigered from ProjectManager::SetProject() just after a project has become active...

@devs any feedback?

Navigation

[0] Message Index

[#] Next page

Go to full version