From f8f0b8b50ca9803398eff2582e2bd170cdc1e419 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 5 Apr 2021 16:18:41 +0200 Subject: [PATCH] Remove public wxFileHistory::RefreshLabels() Replace it with a private DoRefreshLabels() and call it ourselves from SetMenuPathStyle() to make the class simpler (and less error-prone, as it's now impossible to forget to call RefreshLabels() any more) to use. --- include/wx/filehistory.h | 7 ++++--- interface/wx/filehistory.h | 9 --------- samples/menu/menu.cpp | 2 -- src/common/filehistorycmn.cpp | 13 +++++++++++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/wx/filehistory.h b/include/wx/filehistory.h index e5bf059ea7..a5756a7e09 100644 --- a/include/wx/filehistory.h +++ b/include/wx/filehistory.h @@ -67,11 +67,9 @@ public: void SetBaseId(wxWindowID baseId) { m_idBase = baseId; } wxWindowID GetBaseId() const { return m_idBase; } - void SetMenuPathStyle(wxFileHistoryMenuPathStyle style) { m_menuPathStyle = style; } + void SetMenuPathStyle(wxFileHistoryMenuPathStyle style); wxFileHistoryMenuPathStyle GetMenuPathStyle() const { return m_menuPathStyle; } - void RefreshLabels(); - protected: // Last n files wxArrayString m_fileHistory; @@ -86,6 +84,9 @@ protected: wxFileHistoryMenuPathStyle m_menuPathStyle; private: + void DoRefreshLabels(); + + // The ID of the first history menu item (Doesn't have to be wxID_FILE1) wxWindowID m_idBase; diff --git a/interface/wx/filehistory.h b/interface/wx/filehistory.h index 7cc92718b8..21d38b686b 100644 --- a/interface/wx/filehistory.h +++ b/interface/wx/filehistory.h @@ -125,14 +125,6 @@ public: */ virtual void Load(const wxConfigBase& config); - /** - Refresh the labels on all the menu items in the menus used by this - file history. - - @since 3.1.5 - */ - void RefreshLabels(); - /** Removes the specified file from the history. */ @@ -169,7 +161,6 @@ public: By default, the menu item label style is ::wxFH_PATH_SHOW_IF_DIFFERENT. - @remarks Use RefreshLabels() to update any existing menu items to the new style. @since 3.1.5 */ void SetMenuPathStyle(wxFileHistoryMenuPathStyle style); diff --git a/samples/menu/menu.cpp b/samples/menu/menu.cpp index 6113f8de77..53f3c0deb5 100644 --- a/samples/menu/menu.cpp +++ b/samples/menu/menu.cpp @@ -1403,8 +1403,6 @@ void MyFrame::OnFileHistoryStyleItem(wxCommandEvent& event) m_fileHistory->SetMenuPathStyle(wxFH_PATH_SHOW_ALWAYS); break; } - - m_fileHistory->RefreshLabels(); } #endif diff --git a/src/common/filehistorycmn.cpp b/src/common/filehistorycmn.cpp index d49fb2b39b..a0cf56efd1 100644 --- a/src/common/filehistorycmn.cpp +++ b/src/common/filehistorycmn.cpp @@ -136,10 +136,10 @@ void wxFileHistoryBase::AddFileToHistory(const wxString& file) m_fileHistory.insert(m_fileHistory.begin(), file); numFiles++; - RefreshLabels(); + DoRefreshLabels(); } -void wxFileHistoryBase::RefreshLabels() +void wxFileHistoryBase::DoRefreshLabels() { size_t i; size_t numFiles = m_fileHistory.size(); @@ -187,6 +187,15 @@ void wxFileHistoryBase::RefreshLabels() } } +void wxFileHistoryBase::SetMenuPathStyle(wxFileHistoryMenuPathStyle style) +{ + if ( style != m_menuPathStyle ) + { + m_menuPathStyle = style; + DoRefreshLabels(); + } +} + void wxFileHistoryBase::RemoveFileFromHistory(size_t i) { size_t numFiles = m_fileHistory.size();