how to disable menu item wxID_NEW?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

how to disable menu item wxID_NEW?

Post by cecilio » Thu Feb 16, 2006 9:38 am

I am preparing the release version of a program. As the program has additional features not yet finished I would like to disable these non-finished features but to do it, I wouldn't like to comment/remove/alter the program code related to these features. So I thought about disabling any menu/toolbar item related to these unfinished features.

I tryied the following code:

Code: Select all

    //besides of program logic, here I force to disable any unfinished feature
    //if this is a release version
    if (g_fReleaseVersion || g_fReleaseBehaviour) {
        pMenuBar->Enable(wxID_NEW, false);
        pMenuBar->Enable(wxID_OPEN, false);
        ... more menu bar items ...
        
        pToolBar->EnableTool(wxID_NEW, false);
        pToolBar->EnableTool(wxID_OPEN, false);
        ... more toobar items ...
    }
This works prefectly for any other items but not for wxID_NEW and wxID_OPEN. I supose that as these items are managed by wxDocManager my disable settings are being somehow ignored (probably re-enabled later by wxDocManager)

So, my question: is there a simple way to disable those menubar/toolbar items? can I instruct somehow wxDocManager not to enable these items?

Thanks in advance

Cecilio

DavidHart
Site Admin
Site Admin
Posts: 4045
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Thu Feb 16, 2006 10:03 am

Hi Cecilio,

Why not put:
if (g_fReleaseVersion || g_fReleaseBehaviour) {
wxMessageBox(wxT("Sorry, this feature is not available yet")); return; }

in the wxID_NEW and wxID_OPEN event handlers?

Regards,

David

cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

Post by cecilio » Thu Feb 16, 2006 1:47 pm

Hi DavidHart,

Thanks for your suggestion.

I can not directly put code in wxID_NEW and wxID_OPEN events handlers, as thay are handled directly by wxDocManager but I could use your good idea by inserting the suggested code in OnOpenDocument() and OnNewDocument() at my wxDocument derived class.

Nevertheless, I would prefer to disable the menu items and to have all disabling code located in just one place, and not scatered in diferent places. But if I don't get more ideas in a couple of days I will proceed as you suggest.

Thank you very much.

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Thu Feb 16, 2006 7:15 pm

Unless I'm mistaken, you can create and connect a UI update event handler (EVT_UPDATE_UI(wxID_NEW, FooFrame::OnUpdateFileNew)). This, I believe, would be called before the wxDocManager's handler of the same event/id. In your handler you do your customizations to the behavior. When you want the default behavior you just pass the event to your wxDocManager instance's OnUpdateFileNew() (wxEvent::Skip() would probably work and be the best way to do that). This is just speculation as I've never done it before (anyone feel free to jump in and correct any false statements I've made above).

You could probably also derive a new class for wxDocManager and do customizations in there.

Post Reply