Make DoRefreshLabels() code more obviously correct

Use switch over enum instead of a series of chained ifs.

This has the same effect, but can be read and understood more easily.

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-04-05 16:30:51 +02:00
parent d46ba0b435
commit 979c1bccc9

View File

@@ -147,8 +147,8 @@ void wxFileHistoryBase::DoRefreshLabels()
if ( numFiles == 0 ) if ( numFiles == 0 )
return; return;
// Use the first file as the current path // Remember the path in case we need to compare with it below.
wxFileName firstFn(m_fileHistory[0]); const wxString firstPath(wxFileName(m_fileHistory[0]).GetPath());
// Update the labels in all menus // Update the labels in all menus
for ( size_t i = 0; i < numFiles; i++ ) for ( size_t i = 0; i < numFiles; i++ )
@@ -156,23 +156,24 @@ void wxFileHistoryBase::DoRefreshLabels()
const wxFileName currFn(m_fileHistory[i]); const wxFileName currFn(m_fileHistory[i]);
wxString pathInMenu; wxString pathInMenu;
switch ( m_menuPathStyle )
{
case wxFH_PATH_SHOW_IF_DIFFERENT:
if ( currFn.HasName() && currFn.GetPath() == firstPath )
pathInMenu = currFn.GetFullName();
else
pathInMenu = currFn.GetFullPath();
break;
if ( m_menuPathStyle == wxFH_PATH_SHOW_NEVER ) case wxFH_PATH_SHOW_NEVER:
{ // Only show the filename + extension and not the path.
// Only show the filename + extension and not the path pathInMenu = currFn.GetFullName();
pathInMenu = currFn.GetFullName(); break;
}
else if ( ( m_menuPathStyle == wxFH_PATH_SHOW_IF_DIFFERENT ) && case wxFH_PATH_SHOW_ALWAYS:
( currFn.GetPath() == firstFn.GetPath() ) && currFn.HasName() ) // Always show full path.
{ pathInMenu = currFn.GetFullPath();
// Hide the path if it is in the same folder as the first file break;
pathInMenu = currFn.GetFullName();
}
else
{
// Either has wxFH_PATH_SHOW_ALWAYS menu style, or the file is in a different directory
// from the first file
pathInMenu = m_fileHistory[i];
} }
for ( wxList::compatibility_iterator node = m_fileMenus.GetFirst(); for ( wxList::compatibility_iterator node = m_fileMenus.GetFirst();