From 21b90de829df1d205a760102746991bb227aac59 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 26 Jul 2019 15:36:29 -0600 Subject: [PATCH] Another attempt to work around Apple's [NSAlert runModal] bug. Fixes: lp:1837225 * https://bugs.launchpad.net/kicad/+bug/1837225 --- eeschema/tools/sch_edit_tool.cpp | 38 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index bef73c2378..8281a6ca6a 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1016,6 +1016,33 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) void SCH_EDIT_TOOL::editComponentFieldText( SCH_FIELD* aField ) { +#ifdef __WXMAC__ + // This dialog, like no other that we currently know of, sometimes provokes Apple's + // "[NSAlert runModal] may not be invoked inside of transaction begin/commit pair" + // bug. See: https://bugs.launchpad.net/kicad/+bug/1837225 + // + // Note: this bug occurs irrespecitve of whether the dialog is a modal or quasi-modal. + + static bool g_initialized = false; + static bool g_idleSeen = false; + + if( !g_initialized ) + { + g_initialized = true; + m_frame->Bind( wxEVT_IDLE, [&] ( wxIdleEvent& aEvent ) { g_idleSeen = true; } ); + } + + g_idleSeen = false; + while (!g_idleSeen ) + wxSafeYield(); + + // The above should work around the bug, but it doesn't. Doing it again cures most + // instances, but I'm not yet sure whether or not it cures all. + g_idleSeen = false; + while (!g_idleSeen ) + wxSafeYield(); +#endif + SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent(); // Save old component in undo list if not already in edit, or moving. @@ -1026,17 +1053,6 @@ void SCH_EDIT_TOOL::editComponentFieldText( SCH_FIELD* aField ) DIALOG_SCH_EDIT_ONE_FIELD dlg( m_frame, title, aField ); -#ifdef __WXMAC__ - // This dialog, like no other that we currently know of, sometimes provokes Apple's - // "[NSAlert runModal] may not be invoked inside of transaction begin/commit pair" - // bug, and these seem to prevent it. Don't ask. - // Note: this doesn't seem to have anything to do with it being a quasi-modal: the - // bug happens even if it's changed to a normal modal. - wxSafeYield(); // Apple: strike 1 - wxSafeYield(); // Apple: strike 2 - wxSafeYield(); // Apple: strike 3; you're out -#endif - // The footprint field dialog can invoke a KIWAY_PLAYER so we must use a quasi-modal if( dlg.ShowQuasiModal() != wxID_OK ) return;