// Purpose: wxFileHistory class
// Author: Julian Smart, Vaclav Slavik, Vadim Zeitlin
// Created: 2010-05-03
-// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
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);
}
}
-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);
}
}
-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();
AddFilesToMenu();
}
-void wxFileHistory::Save(wxConfigBase& config)
+void wxFileHistoryBase::Save(wxConfigBase& config)
{
size_t i;
for (i = 0; i < m_fileMaxFiles; i++)
}
#endif // wxUSE_CONFIG
-void wxFileHistory::AddFilesToMenu()
+void wxFileHistoryBase::AddFilesToMenu()
{
if ( m_fileHistory.empty() )
return;
}
}
-void wxFileHistory::AddFilesToMenu(wxMenu* menu)
+void wxFileHistoryBase::AddFilesToMenu(wxMenu* menu)
{
if ( m_fileHistory.empty() )
return;