using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TradeIdeas.TIProGUI;
using TradeIdeas.TIProData;
namespace TradeIdeas.Dashboard
{
public partial class SelectWatchList : Form
{
private readonly IConnectionMaster _connectionMaster;
private static readonly object CREATE_NEW_WATCHLIST = "Create new watchlist";
///
/// This is for use in the list box.
/// We can't use the objects exported by the SymbolListsCache directly because we want to adjust
/// the names before showing the user.
///
private class WindowDescription
{
public int ListId;
public string WindowName;
public override string ToString()
{
return WindowName;
}
}
///
/// The intent is to use this as a dialog box.
/// The window will dispose of itself when the user hits the button.
///
///
public SelectWatchList(IConnectionMaster connectionMaster)
{
_connectionMaster = connectionMaster;
InitializeComponent();
SymbolListsCacheManager cache = GuiEnvironment.GetSymbolListsCacheManager(_connectionMaster);
// TODO Add a "please wait" item?
foreach (SymbolListsCacheManager.SymbolListInfo symbolListInfo in cache.GetSymbolLists())
{
WatchList.ParsedName parsedName = new WatchList.ParsedName(symbolListInfo.Name);
if (parsedName.OneOfOurs)
listBox1.Items.Add(new WindowDescription {ListId = symbolListInfo.Id,
WindowName = parsedName.WindowName + symbolListInfo.SizeSuffix});
}
listBox1.Items.Add(CREATE_NEW_WATCHLIST);
// Simple invariant: Something is always selected.
listBox1.SelectedIndex = 0;
}
private void showWatchlistButton_Click(object sender, EventArgs e)
{
Visible = false;
object selectedObject = listBox1.SelectedItem;
if (selectedObject == CREATE_NEW_WATCHLIST)
WatchList.CreateNew(_connectionMaster);
else
WatchList.Show(_connectionMaster, (selectedObject as WindowDescription).ListId);
Dispose();
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
showWatchlistButton.PerformClick();
}
}
}