From 0870f213df057a7213d55de47a4e5a8caed12e5c Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 27 Aug 2015 19:05:15 +0200 Subject: [PATCH] Do not attempt to change colours of properties which are not present on the current page (in propgrid sample). Test executed from 'Category Specific Colours' menu is designed to work only for specific category properties which are present only on 'Standard Items' page. Display a message if current page is not this one and therefore test cannot be executed properly. Also make menu item non-checkable if it is accessed from improper page. --- samples/propgrid/propgrid.cpp | 23 +++++++++++++++++++++++ samples/propgrid/propgrid.h | 1 + 2 files changed, 24 insertions(+) diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index cc6f0fa168..76c25f1af0 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -558,6 +558,8 @@ wxBEGIN_EVENT_TABLE(FormMain, wxFrame) EVT_MENU( ID_RUNMINIMAL, FormMain::OnRunMinimalClick ) + EVT_UPDATE_UI( ID_CATCOLOURS, FormMain::OnCatColoursUpdateUI ) + EVT_CONTEXT_MENU( FormMain::OnContextMenu ) EVT_BUTTON(ID_SHOWPOPUP, FormMain::OnShowPopup) wxEND_EVENT_TABLE() @@ -2789,9 +2791,30 @@ void FormMain::OnColourScheme( wxCommandEvent& event ) // ----------------------------------------------------------------------- +void FormMain::OnCatColoursUpdateUI(wxUpdateUIEvent& WXUNUSED(event)) +{ + // Prevent menu item from being checked + // if it is selected from imroper page. + const wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); + m_itemCatColours->SetCheckable( + pg->GetPropertyByName("Appearance") && + pg->GetPropertyByName("PositionCategory") && + pg->GetPropertyByName("Environment") && + pg->GetPropertyByName("More Examples") ); +} + void FormMain::OnCatColours( wxCommandEvent& event ) { wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); + if ( !pg->GetPropertyByName("Appearance") || + !pg->GetPropertyByName("PositionCategory") || + !pg->GetPropertyByName("Environment") || + !pg->GetPropertyByName("More Examples") ) + { + wxMessageBox("First switch to 'Standard Items' page!"); + return; + } + m_pPropGridManager->Freeze(); if ( event.IsChecked() ) diff --git a/samples/propgrid/propgrid.h b/samples/propgrid/propgrid.h index 15d9bf4ddb..8ed65a21aa 100644 --- a/samples/propgrid/propgrid.h +++ b/samples/propgrid/propgrid.h @@ -195,6 +195,7 @@ public: void OnShowHeader( wxCommandEvent& event ); #endif void OnDumpList( wxCommandEvent& event ); + void OnCatColoursUpdateUI( wxUpdateUIEvent& event ); void OnCatColours( wxCommandEvent& event ); void OnSetColumns( wxCommandEvent& event ); void OnMisc( wxCommandEvent& event );