Skip to content

Commit

Permalink
Fixes for Find next and Find previous
Browse files Browse the repository at this point in the history
• Use wxSharedPtr instead of wxWeakRef for the m_findWindow member
variable.

The following is from the *wxWeakRef< T > Class Template Reference* page
of the wxWidgets documentation found at
http://docs.wxwidgets.org/trunk/classwx_weak_ref_3_01_t_01_4.html.

"""
wxWeakRef<T> is a template class for weak references to wxWidgets
objects, such as wxEvtHandler, wxWindow and wxObject.

A weak reference behaves much like an ordinary pointer, but when the
object pointed is destroyed, the weak reference is automatically reset
to a NULL pointer.
"""

What this says is that the moment the Find Frame is destroyed, the weak
reference is set to null as well. This is not what we want. This in fact
prevents the PoeditFrame::OnFindNext and PoeditFrame::OnFindPrev
functions from working properly.

The PoeditFrame::OnFind and PoeditFrame::OnFindAndReplace both
initialize the m_findWindow if necessary. Then they use the m_findWindow
member variable to display the frame by calling either
FindFrame::ShowForFind or FindFrame::ShowForReplace. When the
PoeditFrame::OnFindNext or PoeditFrame::OnFindPrev functions are called
in response to the Find next and Find previous menu items these
functions expect the m_findWindow member variable to be non null.
However, due to the fact that as a side effect of it being a wxWeakRef
the pointer was reset to null the moment the frame was closed by the
wxAppConsoleBase::DeletePendingObjects function, this is not the case.
Thus the PoeditFrame::OnFindNext and PoeditFrame::OnFindPrev functions
do nothing.

• Added missing wxAcceleratorEntry entries for menu_find_next and
menu_find_prev.

• Modified the FindFrame::OnClose function to call Show(false) instead
of calling Destroy().
  • Loading branch information
BenKeyFSI committed Oct 2, 2015
1 parent fbabea5 commit 499cc7b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/edframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ void PoeditFrame::DestroyContentView()
if (m_findWindow)
{
m_findWindow->Destroy();
m_findWindow.Release();
m_findWindow.reset();
}
}

Expand Down Expand Up @@ -920,6 +920,8 @@ void PoeditFrame::SetAccelerators()
{ wxACCEL_CTRL, WXK_F3, XRCID("menu_find_next") },
{ wxACCEL_CTRL | wxACCEL_SHIFT, WXK_F3, XRCID("menu_find_prev") },
#endif
{ wxACCEL_CTRL, wxKeyCode('G'), XRCID("menu_find_next") },
{ wxACCEL_CTRL | wxACCEL_SHIFT, wxKeyCode('G'), XRCID("menu_find_prev") },

{ wxACCEL_CTRL, WXK_PAGEUP, XRCID("go_prev_page") },
{ wxACCEL_CTRL, WXK_NUMPAD_PAGEUP, XRCID("go_prev_page") },
Expand Down
2 changes: 1 addition & 1 deletion src/edframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class PoeditFrame : public wxFrame

AttentionBar *m_attentionBar;
Sidebar *m_sidebar;
wxWeakRef<FindFrame> m_findWindow;
wxSharedPtr<FindFrame> m_findWindow;

bool m_modified;
bool m_hasObsoleteItems;
Expand Down
2 changes: 1 addition & 1 deletion src/findframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void FindFrame::DoShowFor(int mode)

void FindFrame::OnClose(wxCommandEvent&)
{
Destroy();
Show(false);
}


Expand Down

0 comments on commit 499cc7b

Please sign in to comment.