From f6822120b3e507cd2c691b21c28979f0bd6f4f9e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 3 Dec 2022 22:34:47 +0000 Subject: [PATCH] Enable tab and return commit in property grid. --- common/widgets/properties_panel.cpp | 30 +++++++++++++++++-------- common/widgets/properties_panel.h | 2 ++ pcbnew/widgets/pcb_properties_panel.cpp | 16 +++++-------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/common/widgets/properties_panel.cpp b/common/widgets/properties_panel.cpp index 9b2ad01224..4553ab0785 100644 --- a/common/widgets/properties_panel.cpp +++ b/common/widgets/properties_panel.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2020 CERN + * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -50,14 +51,15 @@ PROPERTIES_PANEL::PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame ) delete wxPGGlobalVars->m_defaultRenderer; wxPGGlobalVars->m_defaultRenderer = new PG_CELL_RENDERER(); - m_caption = new wxStaticText( this, wxID_ANY, _( "No objects selected" ), wxDefaultPosition, - wxDefaultSize, 0 ); + m_caption = new wxStaticText( this, wxID_ANY, _( "No objects selected" ) ); mainSizer->Add( m_caption, 0, wxALL | wxEXPAND, 5 ); m_grid = new wxPropertyGrid( this, wxID_ANY, wxDefaultPosition, wxSize( 300, 400 ), wxPG_DEFAULT_STYLE ); m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT( "<...>" ) ) ); m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS ); + m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN ); + m_grid->DedicateKey( WXK_RETURN ); mainSizer->Add( m_grid, 1, wxALL | wxEXPAND, 5 ); m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) ); @@ -72,9 +74,10 @@ PROPERTIES_PANEL::PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame ) m_grid->CenterSplitter(); - Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( PROPERTIES_PANEL::valueChanged ), NULL, this ); - Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( PROPERTIES_PANEL::valueChanging ), NULL, this ); - Connect( wxEVT_SHOW, wxShowEventHandler( PROPERTIES_PANEL::onShow ), NULL, this ); + Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( PROPERTIES_PANEL::onCharHook ), nullptr, this ); + Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( PROPERTIES_PANEL::valueChanged ), nullptr, this ); + Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( PROPERTIES_PANEL::valueChanging ), nullptr, this ); + Connect( wxEVT_SHOW, wxShowEventHandler( PROPERTIES_PANEL::onShow ), nullptr, this ); Bind( wxEVT_PG_COL_END_DRAG, [&]( wxPropertyGridEvent& ) @@ -146,7 +149,7 @@ void PROPERTIES_PANEL::update( const SELECTION& aSelection ) std::map> pgPropGroups; // Get all possible properties - for( const auto& type : types ) + for( const TYPE_ID& type : types ) { const PROPERTY_LIST& itemProps = propMgr.GetProperties( type ); @@ -176,7 +179,7 @@ void PROPERTIES_PANEL::update( const SELECTION& aSelection ) } // Find a set of properties that is common to all selected items - for( const auto& property : commonProps ) + for( PROPERTY_BASE* property : commonProps ) { if( property->IsInternal() ) continue; @@ -249,8 +252,8 @@ void PROPERTIES_PANEL::update( const SELECTION& aSelection ) std::vector& properties = pgPropGroups[groupName]; - auto groupItem = new wxPropertyCategory( groupName == wxEmptyString ? - unspecifiedGroupCaption : groupName ); + auto groupItem = new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption + : groupName ); m_grid->Append( groupItem ); @@ -275,6 +278,15 @@ void PROPERTIES_PANEL::onShow( wxShowEvent& aEvent ) } +void PROPERTIES_PANEL::onCharHook( wxKeyEvent& aEvent ) +{ + if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() ) + m_grid->CommitChangesFromEditor(); + else + aEvent.Skip(); +} + + void PROPERTIES_PANEL::RecalculateSplitterPos() { if( m_splitter_key_proportion < 0 ) diff --git a/common/widgets/properties_panel.h b/common/widgets/properties_panel.h index 6065d62eca..049fed0c38 100644 --- a/common/widgets/properties_panel.h +++ b/common/widgets/properties_panel.h @@ -69,8 +69,10 @@ protected: // Event handlers virtual void valueChanging( wxPropertyGridEvent& aEvent ) {} virtual void valueChanged( wxPropertyGridEvent& aEvent ) {} + void onCharHook( wxKeyEvent& aEvent ); void onShow( wxShowEvent& aEvent ); +protected: std::vector m_displayed; wxPropertyGrid* m_grid; EDA_BASE_FRAME* m_frame; diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index ea04ee9a91..9457bae4af 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2020 CERN + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -59,8 +60,6 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* a delete new_editor; else m_editor = static_cast( wxPropertyGrid::RegisterEditorClass( new_editor ) ); - - } @@ -88,8 +87,8 @@ wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProp { wxASSERT( aProperty->HasChoices() ); - PGPROPERTY_COLORENUM* ret = new PGPROPERTY_COLORENUM( wxPG_LABEL, wxPG_LABEL, - const_cast( aProperty->Choices() ) ); + auto ret = new PGPROPERTY_COLORENUM( wxPG_LABEL, wxPG_LABEL, + const_cast( aProperty->Choices() ) ); ret->SetColorFunc( [&]( const wxString& aChoice ) -> wxColour @@ -157,12 +156,9 @@ void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard ) m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Bottom" ) )->SetChoices( layersCu ); // Regenerate nets - for( const auto& netinfo : aBoard->GetNetInfo().NetsByNetcode() ) - { - nets.Add( UnescapeString( netinfo.second->GetNetname() ), netinfo.first ); - } + for( const auto& [ netCode, netInfo ] : aBoard->GetNetInfo().NetsByNetcode() ) + nets.Add( UnescapeString( netInfo->GetNetname() ), netCode ); - auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), - _HKI( "Net" ) ); + auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) ); netProperty->SetChoices( nets ); }