/// <summary> /// Gets the overview item. /// </summary> /// <param name="character">The character.</param> /// <returns></returns> private OverviewItem GetOverviewItem(Character character) { OverviewItem overviewItem; OverviewItem tempOverviewItem = null; try { // Creates a new page tempOverviewItem = new OverviewItem(character); tempOverviewItem.Click += item_Click; tempOverviewItem.Clickable = true; tempOverviewItem.Tag = character; // Ensure that the control gets created before we add it, // (when Overview is created and then we hide a character, // the control gets created after the custom layout has been performed, // causing the controls to get misplaced) tempOverviewItem.CreateControl(); overviewItem = tempOverviewItem; tempOverviewItem = null; } finally { tempOverviewItem?.Dispose(); } return(overviewItem); }
/// <summary> /// When an item has been clicked, fires the appropriate event to notify the main window. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void item_Click(object sender, EventArgs e) { OverviewItem item = sender as OverviewItem; if (item != null) { CharacterClicked?.ThreadSafeInvoke(this, new CharacterChangedEventArgs(item.Character)); } }
/// <summary> /// Gets the overview item. /// </summary> /// <param name="character">The character.</param> /// <returns></returns> private static OverviewItem GetOverviewItem(Character character) { OverviewItem overviewItem; OverviewItem tempOverviewItem = null; try { // Creates a new page tempOverviewItem = new OverviewItem(character, true); tempOverviewItem.Tag = character; tempOverviewItem.CreateControl(); overviewItem = tempOverviewItem; tempOverviewItem = null; } finally { tempOverviewItem?.Dispose(); } return overviewItem; }
/// <summary> /// Gets the overview item. /// </summary> /// <param name="character">The character.</param> /// <returns></returns> private OverviewItem GetOverviewItem(Character character) { OverviewItem overviewItem; OverviewItem tempOverviewItem = null; try { // Creates a new page tempOverviewItem = new OverviewItem(character); tempOverviewItem.Click += item_Click; tempOverviewItem.Clickable = true; tempOverviewItem.Tag = character; // Ensure that the control gets created before we add it, // (when Overview is created and then we hide a character, // the control gets created after the custom layout has been performed, // causing the controls to get misplaced) tempOverviewItem.CreateControl(); overviewItem = tempOverviewItem; tempOverviewItem = null; } finally { tempOverviewItem?.Dispose(); } return overviewItem; }
/// <summary> /// Updates the overview content. /// </summary> private void UpdateContent() { // User has disabled the Overview if (!Settings.UI.MainWindow.ShowOverview || EveMonClient.MonitoredCharacters == null) { return; } List <OverviewItem> overviewItems = Controls.OfType <OverviewItem>().ToList(); // Updates the visibility of the label for when no characters are loaded if (!EveMonClient.MonitoredCharacters.Any()) { if (overviewItems.Count > 0) { CleanUp(overviewItems); } labelNoCharacters.Show(); return; } // Collect the existing overview items var items = overviewItems.ToDictionary(page => (Character)page.Tag); // Create the order we will layout the controls List <Character> characters = new List <Character>(); if (m_grouping) { characters.AddRange(EveMonClient.MonitoredCharacters.Where(x => x.IsTraining)); characters.AddRange(EveMonClient.MonitoredCharacters.Where(x => !x.IsTraining)); } else { characters.AddRange(EveMonClient.MonitoredCharacters); } int index = 0; foreach (Character character in characters) { // Retrieve the current overview item, or null if we're past the limits OverviewItem currentOverviewItem = index < overviewItems.Count ? overviewItems[index] : null; // Does the overview item match with the character ? if ((Character)currentOverviewItem?.Tag != character) { // Retrieve the overview item when it was previously created // Is the overview item later in the collection ? OverviewItem overviewItem; if (items.TryGetValue(character, out overviewItem)) { overviewItems.Remove(overviewItem); // Remove the overview item from old location } else { overviewItem = GetOverviewItem(character); // Create a new overview item } // Inserts the overview item in the proper location overviewItems.Insert(index, overviewItem); } // Remove processed character from the dictionary and move forward if (character != null) { items.Remove(character); } index++; } // Remove the remaining items CleanUp(items.Values); foreach (OverviewItem item in items.Values) { overviewItems.Remove(item); } // Add the created items to the Overview Controls.AddRange(overviewItems.ToArray <Control>()); PerformCustomLayout(); }