Add context menu to jobset list items

This commit is contained in:
Marek Roszko 2024-10-03 08:02:21 -04:00
parent a055d95f0c
commit e61d1c771d
4 changed files with 75 additions and 4 deletions

View File

@ -173,6 +173,13 @@ void JOBSET::MoveJobDown( size_t aJobIdx )
} }
void JOBSET::RemoveJob( size_t aJobIdx )
{
m_jobs.erase( m_jobs.begin() + aJobIdx );
SetDirty();
}
bool JOBSET::SaveToFile( const wxString& aDirectory, bool aForce ) bool JOBSET::SaveToFile( const wxString& aDirectory, bool aForce )
{ {
bool success = JSON_SETTINGS::SaveToFile( aDirectory, aForce ); bool success = JSON_SETTINGS::SaveToFile( aDirectory, aForce );

View File

@ -97,6 +97,7 @@ public:
void RemoveOutput( JOBSET_OUTPUT* aOutput ); void RemoveOutput( JOBSET_OUTPUT* aOutput );
void MoveJobUp( size_t aJobIdx ); void MoveJobUp( size_t aJobIdx );
void MoveJobDown( size_t aJobIdx ); void MoveJobDown( size_t aJobIdx );
void RemoveJob( size_t aJobIdx );
protected: protected:
wxString getFileExt() const override; wxString getFileExt() const override;

View File

@ -315,11 +315,21 @@ PANEL_JOBS::PANEL_JOBS( wxAuiNotebook* aParent, KICAD_MANAGER_FRAME* aFrame,
m_buttonDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) ); m_buttonDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
m_buttonOutputAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) ); m_buttonOutputAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
m_jobList->Connect( wxEVT_MENU, wxCommandEventHandler( PANEL_JOBS::onJobListMenu ),
nullptr, this );
rebuildJobList(); rebuildJobList();
buildOutputList(); buildOutputList();
} }
PANEL_JOBS::~PANEL_JOBS()
{
m_jobList->Disconnect( wxEVT_MENU, wxCommandEventHandler( PANEL_JOBS::onJobListMenu ),
nullptr, this );
}
void PANEL_JOBS::RemoveOutput( JOBSET_OUTPUT* aOutput ) void PANEL_JOBS::RemoveOutput( JOBSET_OUTPUT* aOutput )
{ {
auto it = m_outputPanelMap.find( aOutput ); auto it = m_outputPanelMap.find( aOutput );
@ -396,13 +406,11 @@ void PANEL_JOBS::buildOutputList()
} }
void PANEL_JOBS::OnJobListDoubleClicked( wxListEvent& aEvent ) void PANEL_JOBS::openJobOptionsForListItem( size_t aItemIndex )
{ {
EnsurePcbSchFramesOpen(); EnsurePcbSchFramesOpen();
long item = aEvent.GetIndex(); JOBSET_JOB& job = m_jobsFile->GetJobs()[aItemIndex];
JOBSET_JOB& job = m_jobsFile->GetJobs()[item];
KIWAY::FACE_T iface = JOB_REGISTRY::GetKifaceType( job.m_type ); KIWAY::FACE_T iface = JOB_REGISTRY::GetKifaceType( job.m_type );
@ -410,6 +418,56 @@ void PANEL_JOBS::OnJobListDoubleClicked( wxListEvent& aEvent )
} }
void PANEL_JOBS::OnJobListDoubleClicked( wxListEvent& aEvent )
{
long item = aEvent.GetIndex();
openJobOptionsForListItem( item );
}
void PANEL_JOBS::OnJobListItemRightClick( wxListEvent& event )
{
wxMenu menu;
menu.Append( wxID_EDIT, _( "Edit..." ) );
menu.Append( wxID_DELETE, _( "Delete" ) );
m_jobList->PopupMenu( &menu, event.GetPoint() );
}
void PANEL_JOBS::onJobListMenu( wxCommandEvent& aEvent )
{
switch( aEvent.GetId() )
{
case wxID_EDIT:
{
long item = m_jobList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
if( item == -1 )
return;
openJobOptionsForListItem( item );
}
break;
case wxID_DELETE:
{
long item = m_jobList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
if( item == -1 )
return;
m_jobsFile->RemoveJob( item );
rebuildJobList();
break;
}
default: wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
}
}
void PANEL_JOBS::OnSaveButtonClick( wxCommandEvent& aEvent ) void PANEL_JOBS::OnSaveButtonClick( wxCommandEvent& aEvent )
{ {
m_jobsFile->SaveToFile(); m_jobsFile->SaveToFile();

View File

@ -35,6 +35,8 @@ public:
PANEL_JOBS( wxAuiNotebook* aParent, KICAD_MANAGER_FRAME* aFrame, PANEL_JOBS( wxAuiNotebook* aParent, KICAD_MANAGER_FRAME* aFrame,
std::unique_ptr<JOBSET> aJobsFile ); std::unique_ptr<JOBSET> aJobsFile );
~PANEL_JOBS();
void RemoveOutput( JOBSET_OUTPUT* aOutput ); void RemoveOutput( JOBSET_OUTPUT* aOutput );
void EnsurePcbSchFramesOpen(); void EnsurePcbSchFramesOpen();
@ -43,6 +45,7 @@ protected:
virtual void OnAddJobClick( wxCommandEvent& aEvent ) override; virtual void OnAddJobClick( wxCommandEvent& aEvent ) override;
virtual void OnAddOutputClick( wxCommandEvent& aEvent ) override; virtual void OnAddOutputClick( wxCommandEvent& aEvent ) override;
virtual void OnJobListDoubleClicked( wxListEvent& aEvent ) override; virtual void OnJobListDoubleClicked( wxListEvent& aEvent ) override;
virtual void OnJobListItemRightClick( wxListEvent& event ) override;
virtual void OnSaveButtonClick( wxCommandEvent& aEvent ) override; virtual void OnSaveButtonClick( wxCommandEvent& aEvent ) override;
virtual void OnJobButtonUp( wxCommandEvent& aEvent ) override; virtual void OnJobButtonUp( wxCommandEvent& aEvent ) override;
virtual void OnJobButtonDown( wxCommandEvent& aEvent ) override; virtual void OnJobButtonDown( wxCommandEvent& aEvent ) override;
@ -54,6 +57,8 @@ private:
void updateTitle(); void updateTitle();
void buildOutputList(); void buildOutputList();
void addJobOutputPanel( JOBSET_OUTPUT* aOutput ); void addJobOutputPanel( JOBSET_OUTPUT* aOutput );
void onJobListMenu( wxCommandEvent& aEvent );
void openJobOptionsForListItem( size_t aItemIndex );
wxAuiNotebook* m_parentBook; wxAuiNotebook* m_parentBook;
KICAD_MANAGER_FRAME* m_frame; KICAD_MANAGER_FRAME* m_frame;