| 1706 | // --------------------------------------------------------------------- |
| 1707 | |
| 1708 | void MyFrame::AddRecentPattern(const wxString& inpath) |
| 1709 | { |
| 1710 | if (inpath.IsEmpty()) return; |
| 1711 | wxString path = inpath; |
| 1712 | if (path.StartsWith(readydir)) { |
| 1713 | // remove readydir from start of path |
| 1714 | path.erase(0, readydir.length()); |
| 1715 | } |
| 1716 | |
| 1717 | // duplicate any ampersands so they appear in menu |
| 1718 | path.Replace(wxT("&"), wxT("&&")); |
| 1719 | |
| 1720 | // put given path at start of patternSubMenu |
| 1721 | #ifdef __WXGTK__ |
| 1722 | // avoid wxGTK bug in FindItem if path contains underscores |
| 1723 | int id = wxNOT_FOUND; |
| 1724 | for (int i = 0; i < numpatterns; i++) { |
| 1725 | wxMenuItem* item = patternSubMenu->FindItemByPosition(i); |
| 1726 | wxString temp = item->GetText(); |
| 1727 | temp.Replace(wxT("__"), wxT("_")); |
| 1728 | temp.Replace(wxT("&"), wxT("&&")); |
| 1729 | if (temp == path) { |
| 1730 | id = ID::OpenRecent + 1 + i; |
| 1731 | break; |
| 1732 | } |
| 1733 | } |
| 1734 | #else |
| 1735 | int id = patternSubMenu->FindItem(path); |
| 1736 | #endif |
| 1737 | if ( id == wxNOT_FOUND ) { |
| 1738 | if ( numpatterns < maxpatterns ) { |
| 1739 | // add new path |
| 1740 | numpatterns++; |
| 1741 | id = ID::OpenRecent + numpatterns; |
| 1742 | patternSubMenu->Insert(numpatterns - 1, id, path); |
| 1743 | } else { |
| 1744 | // replace last item with new path |
| 1745 | wxMenuItem* item = patternSubMenu->FindItemByPosition(maxpatterns - 1); |
| 1746 | item->SetText(path); |
| 1747 | id = ID::OpenRecent + maxpatterns; |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | // path exists in patternSubMenu |
| 1752 | if ( id > ID::OpenRecent + 1 ) { |
| 1753 | // move path to start of menu |
| 1754 | wxMenuItem* item; |
| 1755 | while ( id > ID::OpenRecent + 1 ) { |
| 1756 | wxMenuItem* previtem = patternSubMenu->FindItem(id - 1); |
| 1757 | wxString prevpath = previtem->GetText(); |
| 1758 | #ifdef __WXGTK__ |
| 1759 | // remove duplicate underscores |
| 1760 | prevpath.Replace(wxT("__"), wxT("_")); |
| 1761 | prevpath.Replace(wxT("&"), wxT("&&")); |
| 1762 | #endif |
| 1763 | item = patternSubMenu->FindItem(id); |
| 1764 | item->SetText(prevpath); |
| 1765 | id--; |