- possibility to change the sorting: directories first, then files
looks like wxtreectrl is a bit iffy on win32. I'm having trouble getting oncompareitems to overload properly... (i've tried to copy from the wxwidgets treectrl sample, whose overload is supposed to work)
Yep, I've had a hell of a time figuring that out too. But ArtoJ does it just fine.
Look at CodeSnippets. CodeSnippetsTreeCtrl::OnCompareItems.
ArtoJ has this criptic statement in the header:
private:
// Must use this so overridden OnCompareItems() works on MSW,
// see wxWidgets Samples -> TreeCtrl sample
//
// Yes, again, ugly way to solve wxWidgets' weirdness
DECLARE_DYNAMIC_CLASS(CodeSnippetsTreeCtrl)
}
and this in the cpp
IMPLEMENT_DYNAMIC_CLASS(CodeSnippetsTreeCtrl, wxTreeCtrl)
here's the class spec (all public to keep things simple):
class FileTreeCtrl: public wxTreeCtrl
{
public: //wxTR_HIDE_ROOT|/*wxTAB_TRAVERSAL|*//*|wxTR_HAS_BUTTONS*//*wxTR_MULTIPLE|*/
FileTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxTR_DEFAULT_STYLE|wxTR_NO_LINES,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = _T("treeCtrl"));
FileTreeCtrl();
FileTreeCtrl(wxWindow *parent);
virtual ~FileTreeCtrl();
void DoSortChildren(const wxTreeItemId& ti);
int OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2);
DECLARE_DYNAMIC_CLASS(FileTreeCtrl)
DECLARE_EVENT_TABLE()
};
I've tried calling sortchildren from its owner or calling dosortchildren, which calls the wxTreeCtrl::SortChildren to no avail...
I did a svn checkout of cbilplugin.
I compiled it with MSW wxWidgets-2.8.4 (had to cast two ints and add #include <wx/notebook.h> to define wxNB_TOP).
I added traps at:
asm("int3");
m_Tree->SortChildren(ti);
return true;
and
int FileTreeCtrl::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
{
asm("int3");
if(GetItemImage(item1)>GetItemImage(item2))
return -1;
if(GetItemImage(item1)<GetItemImage(item2))
return 1;
return (GetItemText(item1).Cmp(GetItemText(item2)));
}
and then ran CB under gdb.
Both traps occurred, and the second trap got a bazillion hits as the plugin initalized. So your code is being called just fine.
You just have to code the sort correctly.
See ArtoJ's code in CodeSnippets. CodeSnippetsTreeCtrl::OnCompareItems.