//
// Find a worker by its name (as stored in result file) and select it
// as though it had been dragged.
// 
void CPageDisplay::SelectWorkerByName( int button, const char *wkr_name, const int wkr_id )
{
	Manager *mgr;
	Worker *wkr;

	if ( !wkr_name )
	{
		ErrorMessage( "Invalid string in CPageDisplay::SelectWorkerByName()" );
		return;
	}

	// Get a pointer to the button's currently assigned manager
	mgr = barcharts[button].manager;
	if ( mgr )
	{
		// The specified button already has a manager (probably was just assigned by 
		// the previous line in the config file, but even if not we'll use it anyway).

		if ( strlen( wkr_name ) )
		{
			// The worker name is non-empty; get a pointer to the
			// first worker with the specified name within the current manager
			wkr = mgr->GetWorkerByName( wkr_name, wkr_id );
			
			if ( wkr )
			{
				// A worker with the specified name was found; use it
				SetResultSource( mgr->GetIndex(), wkr->GetIndex(), button );
			}
			else
			{
				// No worker with the specified name was found
				if ( mgr->WorkerCount() == 1 )
				{
					// There is only one worker; use it (ignoring its name)
					SetResultSource( mgr->GetIndex(), 0, button );
				}
				else
				{
					// More than one worker; default to all workers
					SetResultSource( mgr->GetIndex(), IOERROR, button );
				}
			}
		}
		else
		{
			// The worker name is an empty string; use all workers
			SetResultSource( mgr->GetIndex(), IOERROR, button );
		}
	}
	// Else: the specified button does not have a manager, ignore the specified worker name
}