X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a0219e4580a925de871080b703d14504c96ad3d6..931d6a47c32a5b4c283243cb553ce71ee2b535d5:/src/common/filehistorycmn.cpp diff --git a/src/common/filehistorycmn.cpp b/src/common/filehistorycmn.cpp index 59898ba52b..c27ed12c0f 100644 --- a/src/common/filehistorycmn.cpp +++ b/src/common/filehistorycmn.cpp @@ -3,7 +3,6 @@ // Purpose: wxFileHistory class // Author: Julian Smart, Vaclav Slavik, Vadim Zeitlin // Created: 2010-05-03 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -62,21 +61,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 +158,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 +201,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 +233,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 +248,7 @@ void wxFileHistory::Save(wxConfigBase& config) } #endif // wxUSE_CONFIG -void wxFileHistory::AddFilesToMenu() +void wxFileHistoryBase::AddFilesToMenu() { if ( m_fileHistory.empty() ) return; @@ -241,7 +261,7 @@ void wxFileHistory::AddFilesToMenu() } } -void wxFileHistory::AddFilesToMenu(wxMenu* menu) +void wxFileHistoryBase::AddFilesToMenu(wxMenu* menu) { if ( m_fileHistory.empty() ) return;