50 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
52#if !wxCHECK_VERSION( 3, 3, 0 )
56 wxPGInitResourceModule();
63 wxPGEditor_TextCtrl =
nullptr;
64 wxPGEditor_Choice =
nullptr;
65 wxPGEditor_ComboBox =
nullptr;
66 wxPGEditor_TextCtrlAndButton =
nullptr;
67 wxPGEditor_CheckBox =
nullptr;
68 wxPGEditor_ChoiceAndButton =
nullptr;
69 wxPGEditor_SpinCtrl =
nullptr;
70 wxPGEditor_DatePickerCtrl =
nullptr;
73 if( !
Pgm().m_PropertyGridInitialized )
80 m_caption =
new wxStaticText(
this, wxID_ANY,
_(
"No objects selected" ) );
81 mainSizer->Add(
m_caption, 0, wxALL | wxEXPAND, 5 );
83 m_grid =
new wxPropertyGrid(
this );
84 m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT(
"<...>" ) ) );
85 m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
87#if wxCHECK_VERSION( 3, 3, 0 )
88 m_grid->SetValidationFailureBehavior( wxPGVFBFlags::MarkCell );
90 m_grid->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL );
93#if wxCHECK_VERSION( 3, 3, 0 )
94 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
95 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
96 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_DOWN );
97 m_grid->AddActionTrigger( wxPGKeyboardAction::PrevProperty, WXK_UP );
98 m_grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_SPACE );
100 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
101 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
102 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
103 m_grid->AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
104 m_grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_SPACE );
107 m_grid->DedicateKey( WXK_RETURN );
108 m_grid->DedicateKey( WXK_NUMPAD_ENTER );
109 m_grid->DedicateKey( WXK_DOWN );
110 m_grid->DedicateKey( WXK_UP );
111 mainSizer->Add(
m_grid, 1, wxEXPAND, 5 );
113 m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
117 m_grid->SetCaptionTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_CAPTIONTEXT ) );
122 SetSizer( mainSizer );
132 Bind( wxEVT_PG_COL_END_DRAG,
133 [&]( wxPropertyGridEvent& )
139 [&]( wxSizeEvent& aEvent )
198 if(
m_grid->IsEditorFocused() )
199 m_grid->CommitChangesFromEditor();
205 if( aSelection.
Empty() )
207 m_caption->SetLabel(
_(
"No objects selected" ) );
211 else if( aSelection.
Size() == 1 )
217 m_caption->SetLabel( wxString::Format(
_(
"%d objects selected" ), aSelection.
Size() ) );
221 std::set<TYPE_ID> types;
226 wxCHECK( !types.empty(), );
229 std::map<wxString, PROPERTY_BASE*> commonProps;
230 const std::vector<PROPERTY_BASE*>& allProperties = propMgr.
GetProperties( *types.begin() );
233 commonProps.emplace( property->Name(), property );
235 std::map<wxString, int> displayOrder;
237 displayOrder.emplace( entry.first->Name(), entry.second );
240 std::set<wxString> groups( groupDisplayOrder.begin(), groupDisplayOrder.end() );
243 for(
auto itType = std::next( types.begin() ); itType != types.end(); ++itType )
249 if( !groups.count(
group ) )
251 groupDisplayOrder.emplace_back(
group );
252 groups.insert(
group );
256 for(
auto it = commonProps.begin(); it != commonProps.end(); )
259 it = commonProps.erase( it );
271 std::set<wxString> availableProps;
274 for(
auto& [
name, property] : commonProps )
276 if( property->IsHiddenFromPropertiesManager() )
279 if( isLibraryEditor && property->IsHiddenFromLibraryEditors() )
282 if( isDesignEditor && property->IsHiddenFromDesignEditors() )
290 availableProps.insert(
name );
293 bool writeable =
true;
294 std::set<wxString> existingProps;
296 for( wxPropertyGridIterator it =
m_grid->GetIterator(); !it.AtEnd(); it.Next() )
298 wxPGProperty* pgProp = it.GetProperty();
299 wxString
name = pgProp->GetName();
303 existingProps.insert(
name );
305 if( !availableProps.count(
name ) )
313 if( choices.GetCount() > 0 )
314 pgProp->SetChoices( choices );
316 pgProp->SetValue( commonVal );
317 pgProp->Enable( writeable );
320 if( !existingProps.empty() && existingProps == availableProps )
326 std::map<wxPGProperty*, int> pgPropOrders;
327 std::map<wxString, std::vector<wxPGProperty*>> pgPropGroups;
329 for(
const wxString&
name : availableProps )
341 if( choices.GetCount() )
342 pgProp->SetChoices( choices );
344 pgProp->SetValue( commonVal );
345 pgProp->Enable( writeable );
348 wxASSERT( displayOrder.count(
name ) );
349 pgPropOrders[pgProp] = displayOrder[
name];
350 pgPropGroups[
property->Group()].emplace_back( pgProp );
354 const wxString unspecifiedGroupCaption =
_(
"Basic Properties" );
356 for(
const wxString& groupName : groupDisplayOrder )
358 if( !pgPropGroups.count( groupName ) )
361 std::vector<wxPGProperty*>& properties = pgPropGroups[groupName];
362 wxString groupCaption = wxGetTranslation( groupName );
364 auto groupItem =
new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption
367 m_grid->Append( groupItem );
369 std::sort( properties.begin(), properties.end(),
370 [&]( wxPGProperty*& aFirst, wxPGProperty*& aSecond )
372 return pgPropOrders[aFirst] < pgPropOrders[aSecond];
375 for( wxPGProperty* property : properties )
376 m_grid->Append( property );
415 wxVariant& aValue,
bool& aWritable, wxPGChoices& aChoices )
418 bool different =
false;
433 if( property->IsHiddenFromPropertiesManager() )
436 wxPGChoices choices =
property->
GetChoices( item );
445 wxArrayString labels = choices.GetLabels();
446 wxArrayInt values = choices.GetValuesForStrings( labels );
448 if( labels != aChoices.GetLabels() || values != aChoices.GetValuesForStrings( labels ) )
461 if( !different && !aValue.IsNull() && value != aValue )
466 else if( !different )
494 if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() )
498 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
499 oldValue = prop->GetValue();
501 m_grid->CommitChangesFromEditor();
504 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
506 if( prop->GetValue() == oldValue )
513 if( aEvent.GetKeyCode() == WXK_SPACE )
515 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
517 if( prop->GetValueType() == wxT(
"bool" ) )
519 m_grid->SetPropertyValue( prop, !prop->GetValue().GetBool() );
525 if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER
526 || aEvent.GetKeyCode() == WXK_DOWN || aEvent.GetKeyCode() == WXK_UP )
528 m_grid->CommitChangesFromEditor();
532 m_grid->SelectProperty(
m_grid->GetSelectedProperty(),
true );