871,12 → 871,12 |
|
private void recentMenuItem_Click(object sender, EventArgs e) |
{ |
int n = 0; |
int n = recentItems.Count-1; |
foreach(MenuItem menuItem in recentListeningMenu.MenuItems) { |
if(sender == menuItem) break; |
n++; |
n--; |
} |
if(n >= recentItems.Count) |
if(n < 0) |
throw new Exception("Unknown sender"); |
|
RecentItem recentItem = (RecentItem)recentItems[n]; |
936,16 → 936,11 |
{ |
int existingIdx = recentItems.IndexOf(recentItem); |
if(existingIdx >= 0) { |
// update timestamp of the old item and move it to the top |
((RecentItem)recentItems[existingIdx]).UpdateTimestamp(recentItem); |
MenuItem oldMenuItem = this.recentListeningMenu.MenuItems[existingIdx]; |
this.recentListeningMenu.MenuItems.RemoveAt(existingIdx); |
this.recentListeningMenu.MenuItems.Add(0, oldMenuItem); |
|
return; |
recentItems.RemoveAt(existingIdx); |
this.recentListeningMenu.MenuItems.RemoveAt(recentItems.Count - existingIdx); |
} |
|
if(recentItems.Count == 0) |
if(recentItems.Count == 0 && this.recentListeningMenu.MenuItems.Count == 1) |
this.recentListeningMenu.MenuItems.RemoveAt(0); |
|
recentItems.Add(recentItem); |
955,7 → 950,13 |
menuItem.Text = string.Format("{0} to {1}:{2}", |
recentItem.ListenPort, recentItem.ResendHost, recentItem.ResendPort); |
menuItem.Click += new System.EventHandler(recentMenuItem_Click); |
|
// check overflow |
if(recentItems.Count > RECENT_LENGTH) { |
recentItems.RemoveAt(0); |
this.recentListeningMenu.MenuItems.RemoveAt(RECENT_LENGTH-1); |
} |
} |
|
#endregion windows forms methods |
|