X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a0219e4580a925de871080b703d14504c96ad3d6..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/common/filehistorycmn.cpp diff --git a/src/common/filehistorycmn.cpp b/src/common/filehistorycmn.cpp index 59898ba52b..5493146337 100644 --- a/src/common/filehistorycmn.cpp +++ b/src/common/filehistorycmn.cpp @@ -62,21 +62,42 @@ wxString GetMRUEntryLabel(int n, const wxString& path) IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject) -wxFileHistory::wxFileHistory(size_t maxFiles, wxWindowID idBase) +wxFileHistoryBase::wxFileHistoryBase(size_t maxFiles, wxWindowID idBase) { m_fileMaxFiles = maxFiles; m_idBase = idBase; } -void wxFileHistory::AddFileToHistory(const wxString& file) +/* static */ +wxString wxFileHistoryBase::NormalizeFileName(const wxFileName& fn) { - // check if we don't already have this file + // We specifically exclude wxPATH_NORM_LONG here as it can take a long time + // (several seconds) for network file paths under MSW, resulting in huge + // delays when opening a program using wxFileHistory. We also exclude + // wxPATH_NORM_ENV_VARS as the file names here are supposed to be "real" + // file names and not have any environment variables in them. + wxFileName fnNorm(fn); + fnNorm.Normalize(wxPATH_NORM_DOTS | + wxPATH_NORM_TILDE | + wxPATH_NORM_CASE | + wxPATH_NORM_ABSOLUTE); + return fnNorm.GetFullPath(); +} + +void wxFileHistoryBase::AddFileToHistory(const wxString& file) +{ + // Check if we don't already have this file. Notice that we avoid + // wxFileName::operator==(wxString) here as it converts the string to + // wxFileName and then normalizes it using all normalizations which is too + // slow (see the comment above), so we use our own quick normalization + // functions and a string comparison. const wxFileName fnNew(file); + const wxString newFile = NormalizeFileName(fnNew); size_t i, numFiles = m_fileHistory.size(); for ( i = 0; i < numFiles; i++ ) { - if ( fnNew == m_fileHistory[i] ) + if ( newFile == NormalizeFileName(m_fileHistory[i]) ) { // we do have it, move it to the top of the history RemoveFileFromHistory(i); @@ -138,11 +159,11 @@ void wxFileHistory::AddFileToHistory(const wxString& file) } } -void wxFileHistory::RemoveFileFromHistory(size_t i) +void wxFileHistoryBase::RemoveFileFromHistory(size_t i) { size_t numFiles = m_fileHistory.size(); wxCHECK_RET( i < numFiles, - wxT("invalid index in wxFileHistory::RemoveFileFromHistory") ); + wxT("invalid index in wxFileHistoryBase::RemoveFileFromHistory") ); // delete the element from the array m_fileHistory.RemoveAt(i); @@ -181,19 +202,19 @@ void wxFileHistory::RemoveFileFromHistory(size_t i) } } -void wxFileHistory::UseMenu(wxMenu *menu) +void wxFileHistoryBase::UseMenu(wxMenu *menu) { if ( !m_fileMenus.Member(menu) ) m_fileMenus.Append(menu); } -void wxFileHistory::RemoveMenu(wxMenu *menu) +void wxFileHistoryBase::RemoveMenu(wxMenu *menu) { m_fileMenus.DeleteObject(menu); } #if wxUSE_CONFIG -void wxFileHistory::Load(const wxConfigBase& config) +void wxFileHistoryBase::Load(const wxConfigBase& config) { m_fileHistory.Clear(); @@ -213,7 +234,7 @@ void wxFileHistory::Load(const wxConfigBase& config) AddFilesToMenu(); } -void wxFileHistory::Save(wxConfigBase& config) +void wxFileHistoryBase::Save(wxConfigBase& config) { size_t i; for (i = 0; i < m_fileMaxFiles; i++) @@ -228,7 +249,7 @@ void wxFileHistory::Save(wxConfigBase& config) } #endif // wxUSE_CONFIG -void wxFileHistory::AddFilesToMenu() +void wxFileHistoryBase::AddFilesToMenu() { if ( m_fileHistory.empty() ) return; @@ -241,7 +262,7 @@ void wxFileHistory::AddFilesToMenu() } } -void wxFileHistory::AddFilesToMenu(wxMenu* menu) +void wxFileHistoryBase::AddFilesToMenu(wxMenu* menu) { if ( m_fileHistory.empty() ) return;