Quintiq file version 2.0
#parent: ListRun
Response OnClick (
  structured[LibOpt_Run] selection
) id:Response_ListRun_MenuDeleteRunWithoutFinalize_OnClick
{
  #keys: '[139596.4.1119468922]'
  Body:
  [*
    // Delete a Run
    // Update status of snapshots to ensure that the list that is shown in the messagebox is up to date.
    LibOpt_FormRun.Optimization().UpdateReplannableSnapshots();
    
    // Select the snapshots that were created by the runs that were started from the current dataset 
    datasetsnapshots := selectsortedset( selection,
                                         Elements.Snapshot.astype( LibOpt_SnapshotReplannableCopyDataset ),
                                         snapshot,
                                         not snapshot.IsDatasetDeleted()
                                         and snapshot.Run().MDSIDRun() = snapshot.MDSID(),
                                         not snapshot.IsDatasetLoaded(), // First show the loaded datasets
                                         snapshot.DatasetName() // Then sort on the name of the dataset. 
                                         ); 
    
    message := Translations::LibOpt_Run_MessageBox_DeleteRuns();
    if( datasetsnapshots.Size() > 0 )
    {
      datasetnamessorted := selectvalues( datasetsnapshots, // The sorting order from datasetsnapshots is maintained.
                                          Elements,
                                          snapshot,
                                          true,
                                          snapshot.DatasetName() 
                                          + ifexpr( snapshot.IsDatasetLoaded(), " - Dataset is loaded", "" )
                                          );
    
      // Add a list of all datasets that will be deleted to the message box.
      message := Translations::LibOpt_Run_MessageBox_DeleteRuns_And_Datasets( datasetnamessorted );            
    }
    
    if ( MessageBox::Question( this, message, '&Yes|&No' ) = 0 )
    {
      LibOpt_Run::DeleteWithoutFinalize( selection );
    }
  *]
  CanBindMultiple: false
  DefinitionID => /ListRun/Responsedef_ListRun_Menu_OnClick
  Initiator: 'MenuDeleteRunWithoutFinalize'
}
