public async Task ExecuteAsync(Session session) { if (session == null) { return; } if (MessageBox.Show($"Are you sure you want to delete session \"{session.Name}\"?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } bool sessionToDeleteIsSelectedSession = session == _sessionManagerToolWindowState.SelectedSession; var sessionToDeleteIndex = _sessionManager.SolutionSettings.Sessions.IndexOf(session); await _sessionManager.DeleteSessionAsync(session); if (sessionToDeleteIsSelectedSession) { if (sessionToDeleteIndex <= 0) { _sessionManagerToolWindowState.SelectedSession = _sessionManager.SolutionSettings.Sessions.FirstOrDefault(); } else if (_sessionManager.SolutionSettings.Sessions.Count - 1 >= sessionToDeleteIndex) { _sessionManagerToolWindowState.SelectedSession = _sessionManager.SolutionSettings.Sessions[sessionToDeleteIndex]; } else { _sessionManagerToolWindowState.SelectedSession = _sessionManager.SolutionSettings.Sessions.Last(); } } }