All pastes #196466 Raw Edit

dmoonfire

public text v1 · immutable
·published 2006-10-10 16:42 UTC
rendered paste body
namespace MfGames.Eclectic.Gui
{
	using Gtk;
	using MfGames.Eclectic;
	using System.Collections;

	/// <summary>
	/// Implements a basic selector (ComboBox) that automatically
	/// contains the list of all sources.
	/// </summary>
	public class SourceSelector : ComboBox
	{
		/// <summary>
		/// Constructs the selector with a metric which is used to prevent
		/// any loops.
		/// </summary>
		public SourceSelector()
		{
			// Create the model
			Model = (TreeModel) new ListStore(typeof(Source),
				typeof(string));
			CellRendererText crt = new CellRendererText(); 
			PackStart(crt, true);
			SetAttributes(crt, "text", 1);
			RebuildList();
		}

		#region List
		/// <summary>
		/// Builds up the list of Balance metrics and populates it with
		/// the given value.
		/// </summary>
		private void RebuildList()
		{
			// Clear out the model
			ListStore store = (ListStore) Model;
			store.Clear();

			// Go through the list
			ArrayList list = new ArrayList(Source.Find());
			list.Sort();

			foreach (Source bm in list)
			{
				// Add the values
				store.AppendValues(bm, bm.FullName);
			}

			// Show it
			ShowAll();
		}
		#endregion
	}
}