using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; using System.Xml; using TradeIdeas.MiscSupport; using TradeIdeas.TIProData; using TradeIdeas.TIProData.Interfaces; using TradeIdeas.TIProGUI.EnhancedSingleStockWindow; using TradeIdeas.XML; namespace TradeIdeas.TIProGUI { public class makeSendToContextMenu //dynamically creates the dropdown sub-menu for the "Send To" functionality { private ToolStripMenuItem _item; private static RowData _mostRecentRowData; private static string _config; private string _windowType; private ISendManager _sendManager; private AlertForm _alertForm; private TopListForm _topListForm; private MultiStrategy _multiStrategy; private EnhancedSingleStockDockWindow _singleStockWindow; private IConnectionMaster _connectionMaster; private string _symbol; private string _exchange; private List _phrases; private Boolean _isStrategyTradeWindowOrRBIGBI = false; private Boolean _isMultipleRowData = false; private static Form _parentForm; private static readonly int MAX_RECENT_SYMBOL_LISTS = 20; private static int _maxRecentSymbolListCount = MAX_RECENT_SYMBOL_LISTS; private Image _screenShot; List _rowDataList = new List(); public makeSendToContextMenu(object form, Form parentForm, ToolStripMenuItem item, RowData rowData, ISendManager sendManager, string config, IConnectionMaster connectionMaster, Boolean isStrategyTradeWindow = false, Image screenShot = null) { _screenShot = screenShot; _mostRecentRowData = rowData; _config = config; _item = item; _sendManager = sendManager; _connectionMaster = connectionMaster; _isStrategyTradeWindowOrRBIGBI = isStrategyTradeWindow; _phrases = GuiEnvironment.XmlConfig.Node("SEND_TO_DYNAMIC").Node("PHRASES"); _maxRecentSymbolListCount = GuiEnvironment.XmlConfig.Node("SEND_TO_DYNAMIC").Node("MAX_RECENT_SYMBOL_LISTS").Property("VALUE", MAX_RECENT_SYMBOL_LISTS); ; // Return if _mostRecentRowData is null. We are avoiding a possible NullReferenceException when perfoming "_mostRecentRowData.Data". if (_mostRecentRowData == null) return; _exchange = _mostRecentRowData.GetExchange(); _symbol = _mostRecentRowData.GetSymbol(); _parentForm = parentForm; if (form as AlertForm != null) { _alertForm = (AlertForm)form; _windowType = "Alert"; } if (form as TopListForm != null) { _topListForm = (TopListForm)form; _windowType = "TopList"; } if (form as MultiStrategy != null) { _multiStrategy = (MultiStrategy)form; _windowType = "MultiStrategy"; } if (form as EnhancedSingleStockDockWindow != null) { _singleStockWindow = (EnhancedSingleStockDockWindow)form; _windowType = "EnhancedSingleStockDockWindow"; } if (config == "CUSTOM_EOC") { _windowType = "CUSTOM_EOC"; } if (config == "AI_STRATEGY_TRADE") { _windowType = "AI_STRATEGY_TRADE"; } if (config == "CHART") { _windowType = "CHART"; } buildMenu(); hideMenuItemsForOtherForms(); } private void FormatItem(ToolStripMenuItem menuItem, List config) { string configMenuText = config.PropertyForCulture("TEXT", "***"); if (configMenuText == "---") menuItem.Visible = false; else { menuItem.Text = configMenuText; // Add a key to the menuItem for use to delete by key. menuItem.Name = configMenuText; } } private void buildMenu() { ToolStripMenuItem chartkWindowToolStripMenuItem = new ToolStripMenuItem(); FormatItem(chartkWindowToolStripMenuItem, _phrases.Node("CHART_WINDOW")); chartkWindowToolStripMenuItem.Click += new EventHandler(chartkWindowToolStripMenuItem_Click); _item.DropDownItems.Add(chartkWindowToolStripMenuItem); ToolStripMenuItem singleStockWindowToolStripMenuItem = new ToolStripMenuItem(); FormatItem(singleStockWindowToolStripMenuItem, _phrases.Node("SINGLE_STOCK_WINDOW")); singleStockWindowToolStripMenuItem.Click += new EventHandler(singleStockWindowToolStripMenuItem_Click); _item.DropDownItems.Add(singleStockWindowToolStripMenuItem); ToolStripMenuItem sendToTwitterToolStripMenuItem = new ToolStripMenuItem(); FormatItem(sendToTwitterToolStripMenuItem, _phrases.Node("TWITTER")); sendToTwitterToolStripMenuItem.Click += new EventHandler(sendToTwitterToolStripMenuItem_Click); _item.DropDownItems.Add(sendToTwitterToolStripMenuItem); // Sending to Facebook is not allowed anymore. //ToolStripMenuItem sendToFacebookToolStripMenuItem = new ToolStripMenuItem(); //FormatItem(sendToFacebookToolStripMenuItem, _phrases.Node("FACEBOOK")); //sendToFacebookToolStripMenuItem.Click += new EventHandler(sendToFacebookToolStripMenuItem_Click); //_item.DropDownItems.Add(sendToFacebookToolStripMenuItem); // Sending to StockTwits is not allowed anymore. //ToolStripMenuItem sendToStockTwitsToolStripMenuItem = new ToolStripMenuItem(); //FormatItem(sendToStockTwitsToolStripMenuItem, _phrases.Node("STOCK_TWITS")); //sendToStockTwitsToolStripMenuItem.Click += new EventHandler(sendToStockTwitsToolStripMenuItem_Click); //_item.DropDownItems.Add(sendToStockTwitsToolStripMenuItem); ToolStripMenuItem externalLinkingToolStripMenuItem = new ToolStripMenuItem(); FormatItem(externalLinkingToolStripMenuItem, _phrases.Node("EXTERNAL_LINKING")); externalLinkingToolStripMenuItem.Click += new EventHandler(externalLinkingToolStripMenuItem_Click); _item.DropDownItems.Add(externalLinkingToolStripMenuItem); ToolStripMenuItem linkDestinationToolStripMenuItem = new ToolStripMenuItem(); FormatItem(linkDestinationToolStripMenuItem, _phrases.Node("WEB")); linkDestinationToolStripMenuItem.Click += new EventHandler(linkDestinationToolStripMenuItem_Click); linkDestinationToolStripMenuItem.Enabled = true; _item.DropDownItems.Add(linkDestinationToolStripMenuItem); // Create Symbol Lists send to dropdowns makeSymbolListsmenuItems(); } private void makeSymbolListsmenuItems() { // Delete previous symbol lists toolStripMenu String key = _phrases.Node("SYMBOL_LISTS").PropertyForCulture("TEXT", "***"); if (_item.DropDownItems.ContainsKey(key)) _item.DropDownItems.RemoveByKey(key); ToolStripMenuItem SendToSymbolListsToolStripMenuItem = new ToolStripMenuItem(); FormatItem(SendToSymbolListsToolStripMenuItem, _phrases.Node("SYMBOL_LISTS")); SendToSymbolListsToolStripMenuItem.Enabled = true; // Add manage symbol lists window menu item on the top ToolStripMenuItem manageSymbolListsToolStripMenuItem = new ToolStripMenuItem(); FormatItem(manageSymbolListsToolStripMenuItem, _phrases.Node("MANAGE_SYMBOL_LISTS")); manageSymbolListsToolStripMenuItem.Click += new EventHandler(manageSymbolListsToolStripMenuItem_Click); SendToSymbolListsToolStripMenuItem.DropDownItems.Add(manageSymbolListsToolStripMenuItem); // Add separator line ToolStripSeparator toolStripSeparator = new ToolStripSeparator(); SendToSymbolListsToolStripMenuItem.DropDownItems.Add(toolStripSeparator); SymbolListsCacheManager cache = GuiEnvironment.GetSymbolListsCacheManager(_connectionMaster); // Add recent symbol lists in bold font but only add them if they exist. int currentRecentSymbolListsCount = 0; foreach (int symbolListID in GuiEnvironment.RecentSymbolLists.ToList()) { if (!cache.GetListName(symbolListID).Equals("")) { if (currentRecentSymbolListsCount >= _maxRecentSymbolListCount) { GuiEnvironment.RecentSymbolLists.Remove(symbolListID); } else { ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem(); toolStripMenuItem.Text = cache.GetListName(symbolListID); toolStripMenuItem.Tag = symbolListID; toolStripMenuItem.Font = GuiEnvironment.FontSettings; toolStripMenuItem.Font = new System.Drawing.Font(toolStripMenuItem.Font, toolStripMenuItem.Font.Style | System.Drawing.FontStyle.Bold); toolStripMenuItem.Click += new EventHandler(addSymbolToSymbolList_Click); SendToSymbolListsToolStripMenuItem.DropDownItems.Add(toolStripMenuItem); currentRecentSymbolListsCount++; } } else // remove deleted symbol list from recent list GuiEnvironment.RecentSymbolLists.Remove(symbolListID); } if (GuiEnvironment.RecentSymbolLists.Count() > 0) { // Add clear symbol lists window menu item on the top ToolStripMenuItem clearRecentSymbolListsToolStripMenuItem = new ToolStripMenuItem(); FormatItem(clearRecentSymbolListsToolStripMenuItem, _phrases.Node("CLEAR_RECENT_SYMBOL_LISTS")); clearRecentSymbolListsToolStripMenuItem.Click += new EventHandler(clearRecentSymbolListsToolStripMenuItem_Click); SendToSymbolListsToolStripMenuItem.DropDownItems.Add(clearRecentSymbolListsToolStripMenuItem); // Add separator line ToolStripSeparator toolStripSeparator1 = new ToolStripSeparator(); SendToSymbolListsToolStripMenuItem.DropDownItems.Add(toolStripSeparator1); } // Create user's symbol lists as dropdown items in alphabetical order by name. foreach (SymbolListsCacheManager.SymbolListInfo symbolListInfo in cache.GetSymbolLists().OrderBy(o => o.Name).ToList()) { ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem(); toolStripMenuItem.Text = symbolListInfo.Name; // Save Id since it is an unique identifier toolStripMenuItem.Tag = symbolListInfo.Id; toolStripMenuItem.Click += new EventHandler(addSymbolToSymbolList_Click); SendToSymbolListsToolStripMenuItem.DropDownItems.Add(toolStripMenuItem); } _item.DropDownItems.Add(SendToSymbolListsToolStripMenuItem); } private void clearRecentSymbolListsToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("CLEAR_RECENT_SYMBOL_LISTS").PropertyForCulture("use_TEXT", "***"), _sendManager); //Open messagebox to confirm deletion string question = _phrases.Node("CLEAR_RECENT_SYMBOL_LISTS_Q").PropertyForCulture("TEXT", "***"); string caption = _phrases.Node("CLEAR_RECENT_SYMBOL_LISTS_CAPTION").PropertyForCulture("TEXT", "***"); var result = MessageBox.Show(question, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { // clear the recent symbol list GuiEnvironment.RecentSymbolLists.Clear(); } } private void addSymbolToSymbolList_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("SYMBOL_LISTS").PropertyForCulture("use_TEXT", "***"), _sendManager); SymbolListsCacheManager cache = GuiEnvironment.GetSymbolListsCacheManager(_connectionMaster); ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)sender; if (_isMultipleRowData) { foreach (RowData rowData in _rowDataList) { cache.AddSymbol((int)toolStripMenuItem.Tag, rowData.GetSymbol()); } } else cache.AddSymbol((int)toolStripMenuItem.Tag, _symbol); // Remove from recent list if present. var itemToRemove = GuiEnvironment.RecentSymbolLists.SingleOrDefault(r => r == (int)toolStripMenuItem.Tag); GuiEnvironment.RecentSymbolLists.Remove(itemToRemove); // Remove last entry in the list so not to exceed max recent symbol lists. if (GuiEnvironment.RecentSymbolLists.Count == _maxRecentSymbolListCount) GuiEnvironment.RecentSymbolLists.RemoveAt(GuiEnvironment.RecentSymbolLists.Count - 1); // Add symbol list to the top of the recent list. GuiEnvironment.RecentSymbolLists.Insert(0, (int)toolStripMenuItem.Tag); } private void manageSymbolListsToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("MANAGE_SYMBOL_LISTS").PropertyForCulture("use_TEXT", "***"), _sendManager); GuiEnvironment.symbolListForm.WindowState = FormWindowState.Normal; GuiEnvironment.SetWindowOpeningPosition(GuiEnvironment.symbolListForm, _parentForm); GuiEnvironment.symbolListForm.Visible = true; GuiEnvironment.symbolListForm.selectTheFont(); GuiEnvironment.symbolListForm.BringToFront(); } public void setRowData(RowData rowData, string config, string symbol, string exchange, IConnectionMaster connectionMaster, Image screenShot = null) { _screenShot = screenShot; _mostRecentRowData = rowData; _config = config; _symbol = symbol; _exchange = exchange; _connectionMaster = connectionMaster; if (_isMultipleRowData) { _isMultipleRowData = false; restoreMenuItemsForOtherForms(); hideMenuItemsForOtherForms(); } // Update symbol list menu item makeSymbolListsmenuItems(); } /// /// Given a list of RowData, send multiple symbols to a symbol list. /// /// public void setRowDataList(List rowDataList) { _rowDataList = new List(); _isMultipleRowData = true; _rowDataList = rowDataList; restoreMenuItemsForOtherForms(); hideMenuItemsForOtherForms(); makeSymbolListsmenuItems(); } private void chartkWindowToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("CHART_WINDOW").PropertyForCulture("use_TEXT", "***"), _sendManager); if (null != GuiEnvironment.CustomSendToChartCode) GuiEnvironment.CustomSendToChartCode(_symbol); else sendToChartWindow(); } private void sendToChartWindow() { Charts.OpenNewCharts(_symbol, _parentForm); } private void singleStockWindowToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("SINGLE_STOCK_WINDOW").PropertyForCulture("use_TEXT", "***"), _sendManager); if (null != GuiEnvironment.CustomSendToSingleStockCode) GuiEnvironment.CustomSendToSingleStockCode(_symbol); else sendToSingleStockWindow(); } private void sendToSingleStockWindow() { // Call the new Single Stock Window. TIProGUI.EnhancedSingleStockWindow.EnhancedSingleStockDockWindow.OpenNewSingleStockWindow(_symbol, _parentForm); } private void sendToTwitterToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("TWITTER").PropertyForCulture("use_TEXT", "***"), _sendManager); sendToTwitter(_mostRecentRowData, _config, _windowType); } public static void sendToTwitter(RowData mostRecentRowData,string config, string windowType) { SendToForm sendToForm = new SendToForm(AlertForm.SocialNetwork.TWEET, mostRecentRowData, config, windowType); sendToForm.ShowDialog(); GuiEnvironment.SetWindowOpeningPosition(sendToForm, _parentForm); } private void sendToFacebookToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("FACEBOOK").PropertyForCulture("use_TEXT", "***"), _sendManager); sendToFacebook(_mostRecentRowData, _config, _windowType); } public static void sendToFacebook(RowData mostRecentRowData, string config, string windowType) { SendToForm sendToForm = new SendToForm(AlertForm.SocialNetwork.FBOOK, mostRecentRowData, config, windowType); sendToForm.Show(); GuiEnvironment.SetWindowOpeningPosition(sendToForm, _parentForm); } private void sendToStockTwitsToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("STOCK_TWITS").PropertyForCulture("use_TEXT", "***"), _sendManager); if (_windowType.Equals("CHART")) sendToStockTwitsFromCharts(_mostRecentRowData, _config, _windowType, _screenShot); else sendToStockTwits(_mostRecentRowData, _config, _windowType); } public static void sendToStockTwits(RowData mostRecentRowData, string config, string windowType) { SendToForm sendToForm = new SendToForm(AlertForm.SocialNetwork.STWITS, mostRecentRowData, config, windowType); sendToForm.Show(); GuiEnvironment.SetWindowOpeningPosition(sendToForm, _parentForm); } public static void sendToStockTwitsFromCharts(RowData mostRecentRowData, string config, string windowType, Image screenShot) { SendToForm sendToForm = new SendToForm(AlertForm.SocialNetwork.STWITS, mostRecentRowData, "", ""); sendToForm.Chart = screenShot; sendToForm.Show(); GuiEnvironment.SetWindowOpeningPosition(sendToForm, _parentForm); } private void externalLinkingToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("EXTERNAL_LINKING").PropertyForCulture("use_TEXT", "***"), _sendManager); if (_alertForm != null) { _alertForm.SendToExternalLinking(_mostRecentRowData, true); } else if (_topListForm != null) { _topListForm.SendToExternalLinking(_mostRecentRowData, true); } else if (_multiStrategy != null) { _multiStrategy.SendToExternalLinking(_mostRecentRowData, true); } } private void linkDestinationToolStripMenuItem_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase(_windowType + _phrases.Node("WEB").PropertyForCulture("use_TEXT", "***"), _sendManager); WebLink webLink = WebLink.GetInstance(); webLink.updateSymbol(_symbol); // set to link channel for calling form - RVH20211004 ISymbolLinkingChannel symbolLinkingChannel = _parentForm as ISymbolLinkingChannel; if (symbolLinkingChannel != null) webLink.SetLinkChannel(symbolLinkingChannel.GetLinkChannel()); webLink.Show(); // Make the window visible to the user. if (webLink.WindowState != FormWindowState.Normal) { webLink.WindowState = FormWindowState.Normal; webLink.BringToFront(); } GuiEnvironment.SetWindowOpeningPosition(webLink, _parentForm); webLink.navigate(); } private void hideMenuItemsForOtherForms() { // We process other stuff in lieu of strategy configs for StrategyTradeForm or RBG-GBI forms. // We also need to hide the external linking since AIStrategyWindow.StrategyTradesForm and RBIGBI depends on the TIProGUI project if (_isStrategyTradeWindowOrRBIGBI) { foreach (ToolStripMenuItem menuitem in _item.DropDownItems) { string configMenuText = menuitem.Text; if (//configMenuText.Equals(_phrases.Node("TWITTER").PropertyForCulture("TEXT", "***")) || //configMenuText.Equals(_phrases.Node("FACEBOOK").PropertyForCulture("TEXT", "***")) || //configMenuText.Equals(_phrases.Node("STOCK_TWITS").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("EXTERNAL_LINKING").PropertyForCulture("TEXT", "***"))) menuitem.Visible = false; } } if (_isMultipleRowData) { foreach (ToolStripMenuItem menuitem in _item.DropDownItems) { string configMenuText = menuitem.Text; if (configMenuText.Equals(_phrases.Node("TWITTER").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("FACEBOOK").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("STOCK_TWITS").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("CHART_WINDOW").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("SINGLE_STOCK_WINDOW").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("WEB").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("EXTERNAL_LINKING").PropertyForCulture("TEXT", "***"))) menuitem.Visible = false; } } } private void restoreMenuItemsForOtherForms() { foreach (ToolStripMenuItem menuitem in _item.DropDownItems) { string configMenuText = menuitem.Text; if (configMenuText.Equals(_phrases.Node("TWITTER").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("FACEBOOK").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("STOCK_TWITS").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("CHART_WINDOW").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("SINGLE_STOCK_WINDOW").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("WEB").PropertyForCulture("TEXT", "***")) || configMenuText.Equals(_phrases.Node("EXTERNAL_LINKING").PropertyForCulture("TEXT", "***"))) menuitem.Visible = true; } } } }