Added wxPropertyGridInterface::RemoveProperty()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli 2008-12-11 17:11:35 +00:00
parent 059979d848
commit f915d44b3f
6 changed files with 71 additions and 4 deletions

View File

@ -245,6 +245,16 @@ public:
*/
void DeleteProperty( wxPGPropArg id );
/**
Removes and returns a property.
@param id
Pointer or name of a property.
@remarks Removed property cannot have any children.
*/
wxPGProperty* RemoveProperty( wxPGPropArg id );
/** Disables property. */
bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); }

View File

@ -421,7 +421,7 @@ public:
Override this member function to add custom behavior on property
deletion.
*/
virtual void DoDelete( wxPGProperty* item );
virtual void DoDelete( wxPGProperty* item, bool doDelete = true );
wxSize DoFitColumns( bool allowGridResize = false );

View File

@ -547,6 +547,16 @@ public:
*/
static void RegisterAdditionalEditors();
/**
Removes and returns a property.
@param id
Pointer or name of a property.
@remarks Removed property cannot have any children.
*/
wxPGProperty* RemoveProperty( wxPGPropArg id );
/**
Replaces property with id with newly created one. For example,
this code replaces existing property named "Flags" with one that

View File

@ -918,6 +918,23 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
pgman->EnsureVisible(wxT("Cell Colour"));
}
{
RT_START_TEST(RemoveProperty)
wxPGProperty* p;
wxPGProperty* origParent =
pgman->GetProperty(wxT("Window Styles"))->GetParent();
p = pgman->RemoveProperty(wxT("Window Styles"));
pgman->Refresh();
pgman->Update();
pgman->AppendIn(origParent, p);
pgman->Refresh();
pgman->Update();
}
{
RT_START_TEST(SetPropertyBackgroundColour)
wxCommandEvent evt;

View File

@ -317,13 +317,42 @@ void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id )
if ( grid->GetState() == state )
grid->DoSelectProperty(NULL, wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE);
state->DoDelete( p );
state->DoDelete( p, true );
RefreshGrid(state);
}
// -----------------------------------------------------------------------
wxPGProperty* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id )
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
wxCHECK( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE),
wxNullProperty);
wxPropertyGridPageState* state = p->GetParentState();
wxPropertyGrid* grid = state->GetGrid();
if ( grid->GetState() == state )
{
grid->DoSelectProperty(NULL,
wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE);
}
state->DoDelete( p, false );
// Mark the property as 'unattached'
p->m_parentState = NULL;
p->m_parent = NULL;
RefreshGrid(state);
return p;
}
// -----------------------------------------------------------------------
wxPGProperty* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id, wxPGProperty* property )
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)

View File

@ -1690,7 +1690,7 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index
// -----------------------------------------------------------------------
void wxPropertyGridPageState::DoDelete( wxPGProperty* item )
void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
{
wxCHECK_RET( item->GetParent(),
wxT("this property was already deleted") );
@ -1790,7 +1790,8 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item )
if ( item->GetBaseName().Len() ) m_dictName.erase(item->GetBaseName());
// We can actually delete it now
delete item;
if ( doDelete )
delete item;
m_itemsAdded = 1; // Not a logical assignment (but required nonetheless).