2566 {
2567 try
2568 {
2569 if (recentFileToolStripItem == null)
2570 {
2571 throw new OperationCanceledException("recentFileToolStripItem can not be null!");
2572 }
2573
2574
2575 int alreadyIn = GetIndexOfRecentFile(fileName);
2576 if (alreadyIn != -1)
2577 {
2578 Settings.Default.RecentFiles.RemoveAt(alreadyIn);
2579 if (recentFileToolStripItem.DropDownItems.Count > alreadyIn)
2580 {
2581 recentFileToolStripItem.DropDownItems.RemoveAt(alreadyIn);
2582 }
2583 }
2584 else if (alreadyIn == 0)
2585 {
2586 return;
2587 }
2588
2589
2590 Settings.Default.RecentFiles.Insert(0, fileName);
2591 recentFileToolStripItem.DropDownItems.Insert(0, new FileMenuItem(fileName));
2592
2593
2594 while (Settings.Default.RecentFiles.Count > Settings.Default.RecentFilesMax)
2595 {
2596 Settings.Default.RecentFiles.RemoveAt(Settings.Default.RecentFilesMax);
2597 }
2598
2599 while (recentFileToolStripItem.DropDownItems.Count > Settings.Default.RecentFilesMax)
2600 {
2601 recentFileToolStripItem.DropDownItems.RemoveAt(Settings.Default.RecentFilesMax);
2602 }
2603
2604
2605 if (!recentFileToolStripItem.Enabled)
2606 {
2607 recentFileToolStripItem.Enabled = true;
2608 }
2609
2610
2611 Settings.Default.Save();
2612 }
2613 catch
2614 {
2615
2616 }
2617 }