Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
cbEvents
oBFusCATed:
Have you look at how openfilelist plugin is done?
--- Quote from: frithjofh on May 31, 2012, 08:13:17 pm ---Also having to query each time for this :
--- Code: --- if ( !an_editor || !an_editor->VisibleToTree() || !an_editor->IsBuiltinEditor() )
return;
--- End code ---
is quite ugly. I still accept the !an_editor part to check against NULL, but the other two are rather awkward, don't you think?
--- End quote ---
Why do you care for the VisibleToTree? I don't think it is needed...
The second check is if you want to show only text editors. If you want to show all editors you don't need this check, too.
I see no problem here. Keep in mind that there can be non-text kind of editors, like the GUI editors in the wxSmith plugin.
So, I doubt you know a way to make the IsBuiltinEditor check disappear, if you know I'm all ears. :)
p.s. please try to keep your code/text ratio larger (e.g. post more code and less text) :)
p.p.s. can you post the whole snippet that is having the missing project problem or the whole plugin's source?
frithjofh:
Yes, I looked how it is done in the openfilelist plugin. I copied from there. My code:
--- Code: ---Entry::Entry(const EditorBase* editor) :
m_pEditor(editor), // no ownership
m_pAttribute(nullptr), // no ownership
m_AgeIndex(-1),
m_ImageIndex(0), // ascii
m_ShortName(m_pEditor->GetShortName()),
m_FileName(m_pEditor->GetFilename()),
m_ProjectName(wxEmptyString)
{
if (m_pEditor->GetModified()) m_ImageIndex = 1; // modified
else if (m_pEditor->IsReadOnly()) m_ImageIndex = 2; // read only
ProjectFile* prjf((static_cast<const cbEditor*>(m_pEditor))->GetProjectFile());
if(prjf)
{
cbProject* prj = prjf->GetParentProject();
if(prj)
m_ProjectName = prj->GetTitle();
}
}
--- End code ---
Obviously this class is a sort of wrapper for the files information, some retrieved from c::b, other set by my plugin. Resulting behavior as to the moment is: when the plugin is active and I open a project, the projects name does not get caught. If I have the project already open and then enable the plugin the project name does get caught. Construction of Entry is triggered by EVT_EDITOR_OPEN.
I could listen for the EVT_PROJECT_OPEN and then set the project name to the Entries accordingly, that will work, but that seems very clumsy. This is first problem.
Second issue: no, I do not know right now how to avoid check IsBuiltinEditor(), but I think having to do this check raises the question if inheritance is used right here.
Third issue: I care for VisibleToTree() here (as does the openfilelist plugin) because of the presence of the start page.
regards and thank you for the attention :)
oBFusCATed:
1. Are you sure "m_ProjectName = prj->GetTitle();" is executed?
2. What are you using m_ProjectName(wxEmptyString), the default c-tor does a perfect job
3. Why have you posted the code out of it's context
4. Probably inheritance was not used correctly here, but I doubt it could be changed easily. You can volunteer to try to remedy the situation :)
frithjofh:
1. Yes. just ran in debugger and yes, constructor is entered and GetTitle() is executed.
2. I know. I use wxEmptyString here as a more visible reminder to myself.
3. It is not out of context in the sense, that this is the only place in the plugin, where the m_ProjectName member is set.
4. I do. Don't know when. Probably somebody else will be quicker on it. :-\
frithjofh:
Thinking about it: I changed the code a bit to see what happens:
1. in the initializer list of Entry I set m_ProjectName to "wtf" (just some example string)
2. inside the constructor I set m_ProjectName to "some other strg"
result:
case a: plugin enabled and then loading project: just "wtf" shows up as project name. that is in this case there is no project yet and so it stays with the initialization from initializer list
case b: first load project, then enable plugin: "some other strg" shows up as project name. in this case the plugin gets the already open editors from the manager, so there the project exists.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version