Change indeterminate checkbox behavior to be more intuitive
Fixes https://gitlab.com/kicad/code/kicad/-/issues/13604
This commit is contained in:
parent
351f668645
commit
09cb222252
|
@ -26,6 +26,7 @@
|
|||
#include <wx/log.h>
|
||||
|
||||
const wxString PG_UNIT_EDITOR::EDITOR_NAME = wxS( "KiCadUnitEditor" );
|
||||
const wxString PG_CHECKBOX_EDITOR::EDITOR_NAME = wxS( "KiCadCheckboxEditor" );
|
||||
|
||||
|
||||
PG_UNIT_EDITOR::PG_UNIT_EDITOR( EDA_DRAW_FRAME* aFrame ) :
|
||||
|
@ -187,3 +188,22 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr
|
|||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
PG_CHECKBOX_EDITOR::PG_CHECKBOX_EDITOR() :
|
||||
wxPGCheckBoxEditor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
wxPGWindowList PG_CHECKBOX_EDITOR::CreateControls( wxPropertyGrid* aGrid, wxPGProperty* aProperty,
|
||||
const wxPoint& aPos, const wxSize& aSize ) const
|
||||
{
|
||||
// Override wx behavior and toggle unspecified checkboxes to "true"
|
||||
// CreateControls for a checkbox editor is only triggered when the user activates the checkbox
|
||||
// Set the value to false here; the base class will then trigger an event setting it true.
|
||||
if( aProperty->IsValueUnspecified() )
|
||||
aProperty->SetValueFromInt( 0 );
|
||||
|
||||
return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
|
||||
}
|
||||
|
|
|
@ -139,8 +139,7 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty )
|
|||
}
|
||||
else if( typeId == TYPE_HASH( bool ) )
|
||||
{
|
||||
ret = new wxBoolProperty();
|
||||
ret->SetAttribute( wxPG_BOOL_USE_CHECKBOX, true );
|
||||
ret = new PGPROPERTY_BOOL();
|
||||
}
|
||||
else if( typeId == TYPE_HASH( wxString ) )
|
||||
{
|
||||
|
@ -348,3 +347,18 @@ bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aStr
|
|||
aVariant = EscapeString( aString, CTX_QUOTED_STR );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
PGPROPERTY_BOOL::PGPROPERTY_BOOL( const wxString& aLabel, const wxString& aName, bool aValue ) :
|
||||
wxBoolProperty( aLabel, aName, aValue )
|
||||
{
|
||||
SetEditor( PG_CHECKBOX_EDITOR::EDITOR_NAME );
|
||||
}
|
||||
|
||||
|
||||
const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
|
||||
{
|
||||
wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox,
|
||||
wxT( "Make sure to set custom editor for PGPROPERTY_BOOL!" ) );
|
||||
return m_customEditor;
|
||||
}
|
||||
|
|
|
@ -64,4 +64,20 @@ protected:
|
|||
std::unique_ptr<PROPERTY_EDITOR_UNIT_BINDER> m_unitBinder;
|
||||
};
|
||||
|
||||
|
||||
class PG_CHECKBOX_EDITOR : public wxPGCheckBoxEditor
|
||||
{
|
||||
public:
|
||||
static const wxString EDITOR_NAME;
|
||||
|
||||
PG_CHECKBOX_EDITOR();
|
||||
|
||||
virtual ~PG_CHECKBOX_EDITOR() {}
|
||||
|
||||
wxString GetName() const override { return EDITOR_NAME; }
|
||||
|
||||
wxPGWindowList CreateControls( wxPropertyGrid* aGrid, wxPGProperty* aProperty,
|
||||
const wxPoint& aPos, const wxSize& aSize ) const override;
|
||||
};
|
||||
|
||||
#endif //KICAD_PG_EDITORS_H
|
||||
|
|
|
@ -169,4 +169,16 @@ public:
|
|||
int aFlags = 0 ) const override;
|
||||
};
|
||||
|
||||
|
||||
class PGPROPERTY_BOOL : public wxBoolProperty
|
||||
{
|
||||
public:
|
||||
PGPROPERTY_BOOL( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
|
||||
bool aValue = false );
|
||||
|
||||
virtual ~PGPROPERTY_BOOL() = default;
|
||||
|
||||
const wxPGEditor* DoGetEditorClass() const override;
|
||||
};
|
||||
|
||||
#endif /* PG_PROPERTIES_H */
|
||||
|
|
|
@ -50,15 +50,23 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* a
|
|||
|
||||
if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
|
||||
{
|
||||
m_editor = static_cast<PG_UNIT_EDITOR*>( it->second );
|
||||
m_editor->UpdateFrame( m_frame );
|
||||
m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( it->second );
|
||||
m_unitEditorInstance->UpdateFrame( m_frame );
|
||||
found = true;
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame );
|
||||
m_editor = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) );
|
||||
m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) );
|
||||
}
|
||||
|
||||
it = wxPGGlobalVars->m_mapEditorClasses.find( PG_CHECKBOX_EDITOR::EDITOR_NAME );
|
||||
|
||||
if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
|
||||
{
|
||||
PG_CHECKBOX_EDITOR* cbEditor = new PG_CHECKBOX_EDITOR();
|
||||
m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( wxPropertyGrid::RegisterEditorClass( cbEditor ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +74,7 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* a
|
|||
|
||||
PCB_PROPERTIES_PANEL::~PCB_PROPERTIES_PANEL()
|
||||
{
|
||||
m_editor->UpdateFrame( nullptr );
|
||||
m_unitEditorInstance->UpdateFrame( nullptr );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ class BOARD;
|
|||
class PCB_EDIT_FRAME;
|
||||
class PROPERTY_MANAGER;
|
||||
class PG_UNIT_EDITOR;
|
||||
class PG_CHECKBOX_EDITOR;
|
||||
|
||||
class PCB_PROPERTIES_PANEL : public PROPERTIES_PANEL
|
||||
{
|
||||
|
@ -52,7 +53,8 @@ protected:
|
|||
|
||||
PCB_EDIT_FRAME* m_frame;
|
||||
PROPERTY_MANAGER& m_propMgr;
|
||||
PG_UNIT_EDITOR* m_editor;
|
||||
PG_UNIT_EDITOR* m_unitEditorInstance;
|
||||
PG_CHECKBOX_EDITOR* m_checkboxEditorInstance;
|
||||
|
||||
wxPGChoices m_nets;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue