Quote
1. Launch Code::Blocks and open project with some files.
2. Open two random files from the project.
3. Now try to open these files again in the project view. When clicking those files the tab right activates, but the application title bar shows only one file name and opened files list selection remains the same.
#1403642 App title bar / Open files list show wrong selected file
Okay flks, I have found the cause of the poblem and I have a solution (proposal). I did NOT specify it as a patch, because a second opinion is need from the devs. They might have a better solution for this.
Let's take as an example the Keybinder plug-in project.
What is the corect behaviour : In the project tree you double click on a file nod, and an aeditor should open up in the editors pane showing the contents of that file, AND !!! the title of the Cb window should say :
file.cpp [Project] - Code::Blocks v1.0
Now let's start our excursion. Open up the keybinder project, double click on cbkeybinder.cpp i nthe project tree. It opens up [see REMARK 1 (below)] and look at the title bar (yes, I know, but hold your breath, wait till REMARK 1). What happened behind the scenes : at a given moment we ended up at :
cbEditor* EditorManager::Open(const wxString& filename, int pos,ProjectFile* data) which in the case the file is not open yet in CB ends up in the following :
ed = new cbEditor(m_pNotebook, fname, m_Theme);
This cbEditor constructor will call the Open function :
bool cbEditor::Open()
and this function will do the following at the end :
NotifyPlugins(cbEVT_EDITOR_OPEN);
Thie Notify function loops over all plug-ins, and already the first plug-in it looked at result in a call to :
void MainFrame::DoUpdateAppTitle()
And this method sets the (new) title.
-- >So apart from the REMARK1 we made it.
Next double click keybinder.cpp in the project tree, and the story repeats.
Alrighty, time fo the instrumental break which instruments do you want u to break Cliff ... ).
Double click on cbkeybinder.cpp, the story 'nearly repeats' itself. Again we end up at :
cbEditor* EditorManager::Open(const wxString& filename, int pos,ProjectFile* data) which in the case the
BUT .... This time the opening tests ome to the conclusion that this 'to construct' cbEditor already exists, so no need to the new call --> woops, the rest of the story remains untold, no cookies,no drinks, no MainFrame::DoUpdateAppTitle() :-(
So my first experiments was to change :
if (eb->IsBuiltinEditor())
ed = (cbEditor*)eb;
into :
if (eb->IsBuiltinEditor())
{
ed = (cbEditor*)eb;
ed->NotifyPlugins(cbEVT_EDITOR_OPEN);
}
No luck : we notify a little bit to early,in the MainFrame::DoUpdateAppTitle() they ask for the active editor, but out reopend file did not receive the state of active editor yet. SO be patient, let's just signal that we want to update the plug-ins as follows :
bool bNotifyPlugIns = false;
if (eb)
{
if (eb->IsBuiltinEditor())
{
ed = (cbEditor*)eb;
bNotifyPlugIns = true;
}
else
return 0; // is open but not a builtin editor
}
And at the end of our EditorManager::Open(), when the reopened editor has achieved the active editor state, we check our flag and act accordingly :
if(bNotifyPlugIns)
{
ed->NotifyPlugins(cbEVT_EDITOR_OPEN);
}
// we 're done
s_CanShutdown = true;
return ed;
With this adjustments ....... Problem fixed, and and and it shows in the title :
cbkeybinder.cpp [C::B KeyBinder] - Code::Blocks v1.0 :-) :-) :-) :-)
Well it is time for that remark :
REMARK 1 :
Ater opening that cbkeybinder.cpp for the first time, you will notice that the project name i no shown, it only shows :
cbkeybinder.cpp - Code::Blocks v1.0 :-( :-(
Why ? Well I know why, didn't find a solution yet, Yiannis, this is where you come in ;-)
Look at this code (from MainFrame::DoUpdateAppTitle() ):
EditorBase* ed = Manager::Get()->GetEditorManager() ? Manager::Get()->GetEditorManager()->GetActiveEditor() : 0L;
cbProject* prj = 0;
if(ed && ed->IsBuiltinEditor())
{
ProjectFile* prjf = ((cbEditor*)ed)->GetProjectFile();
if(prjf)
prj = prjf->GetParentProject();
}
else
prj = Manager::Get()->GetProjectManager() ? Manager::Get()->GetProjectManager()->GetActiveProject() : 0L;
We have an active editor (ourfile), but it seems that the editor doe not have a projectfile associated to it yet -> so no parent project -> no project name. So that's the problem my dear Watson, elementary ...
How come it worked in our fixed 'reopen' path, well then the project file was associated. So it seems, we have something like this :
- open in editor
- notify plug-ins -> app title adjustements
- ...
- somewhere now the projectfile is associated
- ...
Voila,
time to go back to the debugger ;-)
Lieven
[EDIT] back from debugger : solution for the rmark 1 :
In EditorManager::Open() :
Change :
if(data)
ed->SetProjectFile(data,true);
By :
if(data)
{
ed->SetProjectFile(data,true);
ed->NotifyPlugins(cbEVT_EDITOR_OPEN);
}
:-) :-) :-) :-)
PS : lot of Notifying ;-)