Skip to content

Commit f501727

Browse files
committed
fix a crash when a view is closed
in multi split class, the previous focus pane was badly determined
1 parent 3d6b65b commit f501727

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

Console/TabView.cpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,9 @@ void TabView::Split(CMultiSplitPane::SPLITTYPE splitType)
493493
HWND hwndConsoleView = CreateNewConsole(&consoleViewCreate, strCurrentDirectory, wstring(L""), activeConsoleView->GetBasePriority());
494494
if( hwndConsoleView )
495495
{
496-
multisplitClass::SetDefaultFocusPane(multisplitClass::defaultFocusPane->split(
496+
multisplitClass::Split(
497497
hwndConsoleView,
498-
splitType));
498+
splitType);
499499

500500
CRect clientRect(0, 0, 0, 0);
501501
AdjustRectAndResize(ADJUSTSIZE_WINDOW, clientRect, WMSZ_BOTTOM);
@@ -529,18 +529,7 @@ bool TabView::CloseView(HWND hwnd, bool boolDetach, bool& boolTabClosed)
529529
iter->second->DestroyWindow();
530530
m_views.erase(iter);
531531

532-
#ifdef _DEBUG
533-
ATLTRACE(L"%p-TabView::CloseView tree\n",
534-
::GetCurrentThreadId());
535-
multisplitClass::tree.dump(0, 0);
536-
ATLTRACE(L"%p-TabView::CloseView defaultFocusPane\n",
537-
::GetCurrentThreadId());
538-
if( multisplitClass::defaultFocusPane )
539-
multisplitClass::defaultFocusPane->dump(0, multisplitClass::defaultFocusPane->parent);
540-
#endif
541-
542-
if( multisplitClass::defaultFocusPane )
543-
multisplitClass::SetDefaultFocusPane(multisplitClass::defaultFocusPane->remove());
532+
multisplitClass::Remove();
544533

545534
if( m_views.empty() )
546535
boolTabClosed = true;

wtl/wtl/include/multisplit.h

+39-9
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,7 @@ namespace WTL
951951
bool boolNotify = newDefaultPane != this->defaultFocusPane;
952952

953953
if( boolNotify )
954-
{
955-
// if defaultFocusPane is not a window
956-
// then defaultFocusPane has been split
957-
// pane0 is used as new previousFocusPane
958-
if( this->defaultFocusPane->pane0 )
959-
this->previousFocusPane = this->defaultFocusPane->pane0;
960-
else
961-
this->previousFocusPane = this->defaultFocusPane;
962-
}
954+
this->previousFocusPane = this->defaultFocusPane;
963955

964956
this->defaultFocusPane = newDefaultPane;
965957
if( bAppActive && newDefaultPane && ::IsWindow(newDefaultPane->window) )
@@ -994,6 +986,44 @@ namespace WTL
994986
return false;
995987
}
996988

989+
bool Split(HWND windowPane1, CMultiSplitPane::SPLITTYPE splitType)
990+
{
991+
if( this->defaultFocusPane == nullptr )
992+
return false;
993+
994+
CMultiSplitPane* pane1 = this->defaultFocusPane->split(
995+
windowPane1,
996+
splitType);
997+
998+
if( pane1 == nullptr )
999+
return false;
1000+
1001+
// defaultFocusPane has been split
1002+
// pane0 must be used as new previousFocusPane
1003+
this->defaultFocusPane = this->defaultFocusPane->pane0;
1004+
this->SetDefaultFocusPane(pane1);
1005+
1006+
return true;
1007+
}
1008+
1009+
bool Remove()
1010+
{
1011+
#ifdef _DEBUG
1012+
ATLTRACE(L"%p-TabView::CloseView tree\n", ::GetCurrentThreadId());
1013+
this->tree.dump(0, 0);
1014+
ATLTRACE(L"%p-TabView::CloseView defaultFocusPane\n", ::GetCurrentThreadId());
1015+
if( this->defaultFocusPane )
1016+
this->defaultFocusPane->dump(0, this->defaultFocusPane->parent);
1017+
#endif
1018+
1019+
if( this->defaultFocusPane )
1020+
this->SetDefaultFocusPane(this->defaultFocusPane->remove());
1021+
else
1022+
return false;
1023+
1024+
return true;
1025+
}
1026+
9971027
virtual void OnPaneChanged(void)
9981028
{
9991029
}

0 commit comments

Comments
 (0)