Provide some user hints on editing fields.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/17781
This commit is contained in:
parent
0e0ada8e4e
commit
a4073c2ace
|
@ -281,7 +281,7 @@ static std::vector<KICAD_T> nonFields =
|
|||
int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
|
||||
std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection( nonFields ).GetItems();
|
||||
std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection().GetItems();
|
||||
SCH_COMMIT commit( m_frame );
|
||||
|
||||
if( items.empty() )
|
||||
|
@ -293,6 +293,8 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
|||
commit.Modify( symbol, m_frame->GetScreen() );
|
||||
|
||||
std::set<SCH_ITEM*> toDelete;
|
||||
int fieldsHidden = 0;
|
||||
int fieldsAlreadyHidden = 0;
|
||||
|
||||
for( EDA_ITEM* item : items )
|
||||
{
|
||||
|
@ -338,16 +340,44 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else if( item->Type() == SCH_FIELD_T )
|
||||
{
|
||||
toDelete.insert( (SCH_ITEM*) item );
|
||||
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
|
||||
|
||||
// Hide "deleted" fields
|
||||
if( field->IsVisible() )
|
||||
{
|
||||
field->SetVisible( false );
|
||||
fieldsHidden++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldsAlreadyHidden++;
|
||||
}
|
||||
}
|
||||
else if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
|
||||
{
|
||||
toDelete.insert( schItem );
|
||||
}
|
||||
}
|
||||
|
||||
for( SCH_ITEM* item : toDelete )
|
||||
symbol->RemoveDrawItem( item );
|
||||
|
||||
commit.Push( _( "Delete" ) );
|
||||
if( toDelete.size() == 0 )
|
||||
{
|
||||
if( fieldsHidden == 1 )
|
||||
commit.Push( _( "Hide Field" ) );
|
||||
else if( fieldsHidden > 1 )
|
||||
commit.Push( _( "Hide Fields" ) );
|
||||
else if( fieldsAlreadyHidden > 0 )
|
||||
m_frame->ShowInfoBarError( _( "Use the Symbol Properties dialog to remove fields." ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
commit.Push( _( "Delete" ) );
|
||||
}
|
||||
|
||||
m_frame->RebuildView();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2264,7 +2264,8 @@ void EDIT_TOOL::removeNonRootItems( std::unordered_set<EDA_ITEM*>& items )
|
|||
|
||||
void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
||||
{
|
||||
BOARD_COMMIT commit( this );
|
||||
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
||||
BOARD_COMMIT commit( this );
|
||||
|
||||
// As we are about to remove items, they have to be removed from the selection first
|
||||
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
||||
|
@ -2274,6 +2275,10 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
std::unordered_set<EDA_ITEM*> rootItems( aItems.begin(), aItems.end() );
|
||||
removeNonRootItems( rootItems );
|
||||
|
||||
int itemsDeleted = 0;
|
||||
int fieldsHidden = 0;
|
||||
int fieldsAlreadyHidden = 0;
|
||||
|
||||
for( EDA_ITEM* item : rootItems )
|
||||
{
|
||||
BOARD_ITEM* board_item = dynamic_cast<BOARD_ITEM*>( item );
|
||||
|
@ -2287,11 +2292,25 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
switch( item->Type() )
|
||||
{
|
||||
case PCB_FIELD_T:
|
||||
{
|
||||
PCB_FIELD* field = static_cast<PCB_FIELD*>( board_item );
|
||||
|
||||
wxASSERT( parentFP );
|
||||
commit.Modify( parentFP );
|
||||
static_cast<PCB_TEXT*>( board_item )->SetVisible( false );
|
||||
|
||||
if( field->IsVisible() )
|
||||
{
|
||||
field->SetVisible( false );
|
||||
fieldsHidden++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldsAlreadyHidden++;
|
||||
}
|
||||
|
||||
getView()->Update( board_item );
|
||||
break;
|
||||
}
|
||||
|
||||
case PCB_TEXT_T:
|
||||
case PCB_SHAPE_T:
|
||||
|
@ -2305,12 +2324,14 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
case PCB_DIM_RADIAL_T:
|
||||
case PCB_DIM_ORTHOGONAL_T:
|
||||
commit.Remove( board_item );
|
||||
itemsDeleted++;
|
||||
break;
|
||||
|
||||
case PCB_TABLECELL_T:
|
||||
// Clear contents of table cell
|
||||
commit.Modify( board_item );
|
||||
static_cast<PCB_TABLECELL*>( board_item )->SetText( wxEmptyString );
|
||||
itemsDeleted++;
|
||||
break;
|
||||
|
||||
case PCB_GROUP_T:
|
||||
|
@ -2327,6 +2348,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
} );
|
||||
|
||||
commit.Remove( board_item );
|
||||
itemsDeleted++;
|
||||
break;
|
||||
|
||||
case PCB_PAD_T:
|
||||
|
@ -2335,6 +2357,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
commit.Modify( parentFP );
|
||||
getView()->Remove( board_item );
|
||||
parentFP->Remove( board_item );
|
||||
itemsDeleted++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -2372,6 +2395,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
|
||||
// Remove the entire zone otherwise
|
||||
commit.Remove( board_item );
|
||||
itemsDeleted++;
|
||||
break;
|
||||
|
||||
case PCB_GENERATOR_T:
|
||||
|
@ -2395,6 +2419,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
commit.Remove( board_item );
|
||||
}
|
||||
|
||||
itemsDeleted++;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -2411,9 +2436,22 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
m_selectionTool->ExitGroup();
|
||||
|
||||
if( aIsCut )
|
||||
{
|
||||
commit.Push( _( "Cut" ) );
|
||||
}
|
||||
else if( itemsDeleted == 0 )
|
||||
{
|
||||
if( fieldsHidden == 1 )
|
||||
commit.Push( _( "Hide Field" ) );
|
||||
else if( fieldsHidden > 1 )
|
||||
commit.Push( _( "Hide Fields" ) );
|
||||
else if( fieldsAlreadyHidden > 0 )
|
||||
editFrame->ShowInfoBarError( _( "Use the Footprint Properties dialog to remove fields." ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
commit.Push( _( "Delete" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue