Check for view presence in wxDocument::RemoveView()

Return false and avoid calling OnChangedViewList() if the view wasn't present
in the first place.

This is not, strictly speaking, backwards compatible, but most of the existing
code doesn't seem to check the return value of RemoveView() at all and it's
hard to imagine that someone would rely on it returning true when removing a
non-existent view, so in practice this changes seems to be safe.

Closes #17888.
This commit is contained in:
Vadim Zeitlin 2017-06-20 15:32:00 +02:00
parent a2af796156
commit e121e8addb
2 changed files with 9 additions and 3 deletions

View File

@ -1530,8 +1530,12 @@ public:
virtual bool OnSaveModified();
/**
Removes the view from the document's list of views, and calls
OnChangedViewList().
Removes the view from the document's list of views.
If the view was really removed, also calls OnChangedViewList().
@return @true if the view was removed or @false if the document didn't
have this view in the first place.
*/
virtual bool RemoveView(wxView* view);

View File

@ -570,7 +570,9 @@ bool wxDocument::AddView(wxView *view)
bool wxDocument::RemoveView(wxView *view)
{
(void)m_documentViews.DeleteObject(view);
if ( !m_documentViews.DeleteObject(view) )
return false;
OnChangedViewList();
return true;
}