/// <summary> /// Refresh the discovered feeds menu item container. It sync. automatically with the /// main UI thread, if required. /// </summary> private void RefreshDiscoveredItemContainer() { if (app == null || app.MainForm == null || app.MainForm.Disposing) { return; } GuiInvoker.InvokeAsync(app.MainForm, delegate { while (newDiscoveredFeeds.Count > 0) { AppButtonToolCommand item; lock (newDiscoveredFeeds.SyncRoot) { item = (AppButtonToolCommand)newDiscoveredFeeds.Dequeue(); } lock (SyncItemDropdownTools) { if (itemDropdown.Tools.Contains(item)) { itemDropdown.Tools.Remove(item); } itemDropdown.Tools.Insert(1, item); } } lock (SyncItemDropdownTools) { foreach (AppButtonToolCommand m in itemDropdown.Tools) { if (m.InstanceProps != null) { m.InstanceProps.IsFirstInGroup = false; } } } lock (SyncItemDropdownTools) { if (itemDropdown.Tools.Count > 1) { itemDropdown.Tools[1].InstanceProps.IsFirstInGroup = true; } // refresh appearances/images: int cnt = itemDropdown.Tools.Count; if (cnt <= 1) { itemDropdown.SharedProps.AppearancesSmall.Appearance = this.discoveredAppearance[0]; itemDropdown.SharedProps.AppearancesLarge.Appearance = this.discoveredAppearance[1]; } else { itemDropdown.SharedProps.AppearancesSmall.Appearance = this.discoveredAppearance[2]; itemDropdown.SharedProps.AppearancesLarge.Appearance = this.discoveredAppearance[3]; if (!itemDropdown.Enabled) { itemDropdown.Enabled = true; } } } }); }
/// <summary> /// Will add a DiscoveredFeedsInfo entry to the managed tool dropdown. /// </summary> /// <param name="info">DiscoveredFeedsInfo instance</param> public void Add(DiscoveredFeedsInfo info) { if (info == null) { return; } // detect duplicates: AppButtonToolCommand duplicateItem = FindYetDiscoveredFeedMenuItem(info); if (duplicateItem != null) { // update title/desc: duplicateItem.SharedProps.Caption = StripAndShorten(info.Title); duplicateItem.SharedProps.StatusText = info.FeedLinks[0]; lock (SyncRoot) { // refresh the existing info item to the new one discoveredFeeds.Remove(duplicateItem); discoveredFeeds.Add(duplicateItem, info); } } else { // new entry: WinGuiMain guiMain = (WinGuiMain)app.MainForm; GuiInvoker.InvokeAsync(guiMain, delegate { //guiMain.AddAutoDiscoveredUrl(info); AppButtonToolCommand newItem = new AppButtonToolCommand( String.Concat("cmdDiscoveredFeed_", ++(cmdKeyPostfix)), mediator, OnDiscoveredItemClick, StripAndShorten(info.Title), info.FeedLinks[0]); if (itemDropdown.ToolbarsManager.Tools.Exists(newItem.Key)) { itemDropdown.ToolbarsManager.Tools.Remove(newItem); } itemDropdown.ToolbarsManager.Tools.Add(newItem); newItem.SharedProps.StatusText = info.SiteBaseUrl; newItem.SharedProps.ShowInCustomizer = false; lock (SyncRoot) { // add a fresh version of info discoveredFeeds.Add(newItem, info); } lock (newDiscoveredFeeds.SyncRoot) { // re-order to top of list, in RefreshItemContainer() newDiscoveredFeeds.Enqueue(newItem); } RaiseNewFeedsDiscovered(info); }); } RefreshDiscoveredItemContainer(); }