52 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
54#if !wxCHECK_VERSION( 3, 3, 0 )
58 wxPGInitResourceModule();
65 wxPGEditor_TextCtrl =
nullptr;
66 wxPGEditor_Choice =
nullptr;
67 wxPGEditor_ComboBox =
nullptr;
68 wxPGEditor_TextCtrlAndButton =
nullptr;
69 wxPGEditor_CheckBox =
nullptr;
70 wxPGEditor_ChoiceAndButton =
nullptr;
71 wxPGEditor_SpinCtrl =
nullptr;
72 wxPGEditor_DatePickerCtrl =
nullptr;
75 if( !
Pgm().m_PropertyGridInitialized )
82 m_caption =
new wxStaticText(
this, wxID_ANY,
_(
"No objects selected" ) );
83 mainSizer->Add(
m_caption, 0, wxALL | wxEXPAND, 5 );
85 m_grid =
new wxPropertyGrid(
this );
86 m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT(
"<...>" ) ) );
87 m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
89#if wxCHECK_VERSION( 3, 3, 0 )
90 m_grid->SetValidationFailureBehavior( wxPGVFBFlags::MarkCell );
92 m_grid->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL );
95#if wxCHECK_VERSION( 3, 3, 0 )
96 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
97 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
98 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_DOWN );
99 m_grid->AddActionTrigger( wxPGKeyboardAction::PrevProperty, WXK_UP );
100 m_grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_SPACE );
102 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
103 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
104 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
105 m_grid->AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
106 m_grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_SPACE );
109 m_grid->DedicateKey( WXK_RETURN );
110 m_grid->DedicateKey( WXK_NUMPAD_ENTER );
111 m_grid->DedicateKey( WXK_DOWN );
112 m_grid->DedicateKey( WXK_UP );
113 mainSizer->Add(
m_grid, 1, wxEXPAND, 5 );
115 m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
119 m_grid->SetCaptionTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_CAPTIONTEXT ) );
124 SetSizer( mainSizer );
134 Bind( wxEVT_PG_COL_END_DRAG,
135 [&]( wxPropertyGridEvent& )
141 [&]( wxSizeEvent& aEvent )
200 if(
m_grid->IsEditorFocused() )
201 m_grid->CommitChangesFromEditor();
207 if( aSelection.
Empty() )
209 m_caption->SetLabel(
_(
"No objects selected" ) );
213 else if( aSelection.
Size() == 1 )
219 m_caption->SetLabel( wxString::Format(
_(
"%d objects selected" ), aSelection.
Size() ) );
223 std::set<TYPE_ID> types;
228 wxCHECK( !types.empty(), );
231 std::map<wxString, PROPERTY_BASE*> commonProps;
232 const std::vector<PROPERTY_BASE*>& allProperties = propMgr.
GetProperties( *types.begin() );
235 commonProps.emplace( property->Name(), property );
237 std::map<wxString, int> displayOrder;
239 displayOrder.emplace( entry.first->Name(), entry.second );
242 std::set<wxString> groups( groupDisplayOrder.begin(), groupDisplayOrder.end() );
245 for(
auto itType = std::next( types.begin() ); itType != types.end(); ++itType )
251 if( !groups.count(
group ) )
253 groupDisplayOrder.emplace_back(
group );
254 groups.insert(
group );
258 for(
auto it = commonProps.begin(); it != commonProps.end(); )
261 it = commonProps.erase( it );
273 std::set<wxString> availableProps;
276 for(
auto& [
name, property] : commonProps )
278 if( property->IsHiddenFromPropertiesManager() )
281 if( isLibraryEditor && property->IsHiddenFromLibraryEditors() )
284 if( isDesignEditor && property->IsHiddenFromDesignEditors() )
292 availableProps.insert(
name );
295 bool writeable =
true;
296 std::set<wxString> existingProps;
298 for( wxPropertyGridIterator it =
m_grid->GetIterator(); !it.AtEnd(); it.Next() )
300 wxPGProperty* pgProp = it.GetProperty();
301 wxString
name = pgProp->GetName();
305 existingProps.insert(
name );
307 if( !availableProps.count(
name ) )
315 if( choices.GetCount() > 0 )
316 pgProp->SetChoices( choices );
318 pgProp->SetValue( commonVal );
319 pgProp->Enable( writeable );
322 if( !existingProps.empty() && existingProps == availableProps )
328 std::map<wxPGProperty*, int> pgPropOrders;
329 std::map<wxString, std::vector<wxPGProperty*>> pgPropGroups;
331 for(
const wxString&
name : availableProps )
343 if( choices.GetCount() )
344 pgProp->SetChoices( choices );
346 pgProp->SetValue( commonVal );
347 pgProp->Enable( writeable );
350 wxASSERT( displayOrder.count(
name ) );
351 pgPropOrders[pgProp] = displayOrder[
name];
352 pgPropGroups[
property->Group()].emplace_back( pgProp );
356 const wxString unspecifiedGroupCaption =
_(
"Basic Properties" );
358 for(
const wxString& groupName : groupDisplayOrder )
360 if( !pgPropGroups.count( groupName ) )
363 std::vector<wxPGProperty*>& properties = pgPropGroups[groupName];
364 wxString groupCaption = wxGetTranslation( groupName );
366 auto groupItem =
new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption
369 m_grid->Append( groupItem );
371 std::sort( properties.begin(), properties.end(),
372 [&]( wxPGProperty*& aFirst, wxPGProperty*& aSecond )
374 return pgPropOrders[aFirst] < pgPropOrders[aSecond];
377 for( wxPGProperty* property : properties )
378 m_grid->Append( property );
417 wxVariant& aValue,
bool& aWritable, wxPGChoices& aChoices )
420 bool different =
false;
435 if( property->IsHiddenFromPropertiesManager() )
438 wxPGChoices choices =
property->
GetChoices( item );
447 wxArrayString labels = choices.GetLabels();
448 wxArrayInt values = choices.GetValuesForStrings( labels );
450 if( labels != aChoices.GetLabels() || values != aChoices.GetValuesForStrings( labels ) )
463 if( !different && !aValue.IsNull() && value != aValue )
468 else if( !different )
496 if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() )
500 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
501 oldValue = prop->GetValue();
503 m_grid->CommitChangesFromEditor();
506 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
508 if( prop->GetValue() == oldValue )
515 if( aEvent.GetKeyCode() == WXK_SPACE )
517 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
519 if( prop->GetValueType() == wxT(
"bool" ) )
521 m_grid->SetPropertyValue( prop, !prop->GetValue().GetBool() );
527 if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER
528 || aEvent.GetKeyCode() == WXK_DOWN || aEvent.GetKeyCode() == WXK_UP )
530 m_grid->CommitChangesFromEditor();
534 m_grid->SelectProperty(
m_grid->GetSelectedProperty(),
true );