Why didn't I do this sooner?
- Posted by ghaberek (admin) Jun 07, 2011
- 1329 views
Have you ever had one of those epiphanic* moments where you think, "why didn't I do this sooner?" or "where has this been all my life?"
*ep-i-phan-ic adj. of or pertaining to an epiphany.
For me that came this evening while looking at a piece of code in Win32Lib compared to its sibling in wxEuphoria. In Win32Lib, I can create a MenuItem separator by simply passing the text as a single hyphen "-". In wxEuphoria, I have to either insert my separators later using insert_separator() or break my constant block, call append_separator(), then declare a new constant block and continue on.
So I added a few lines to wxMenu.cpp.
parentMenu = (wxMenu *) get_int( params, 1 ); if ( text == wxT("-") ) { /* added this */ item = NULL; parentMenu->AppendSeparator(); } else { /* original code */ item = new wxMenuItem( parentMenu, id, text, helpString, kind, subMenu ); if (use_bitmap) item->SetBitmap( bitmap ); parentMenu->Append( item ); }
And now this...
include "wxeu/wxeud.e" without warning constant frmMain = create( wxFrame, {0, -1, "Menu Demo", -1, -1, 640, 480} ), mbrMain = create( wxMenuBar, {frmMain} ), mnuFile = create( wxMenu, {mbrMain, "&File"} ), mnuFile_Prefs = create( wxMenuItem, {mnuFile, -1, "&Preferences"} ), mnuFile_Exit = create( wxMenuItem, {mnuFile, wxID_EXIT, "E&xit"} ), $ insert_separator( mnuFile, 1 ) wxMain( frmMain )
Becomes this...
include "wxeu/wxeud.e" without warning constant frmMain = create( wxFrame, {0, -1, "Menu Demo", -1, -1, 640, 480} ), mbrMain = create( wxMenuBar, {frmMain} ), mnuFile = create( wxMenu, {mbrMain, "&File"} ), mnuFile_Prefs = create( wxMenuItem, {mnuFile, -1, "&Preferences"} ), mnuFile_Sep1 = create( wxMenuItem, {mnuFile, -1, "-"} ), mnuFile_Exit = create( wxMenuItem, {mnuFile, wxID_EXIT, "E&xit"} ), $ wxMain( frmMain )
-Greg