99#include " Docking.h"
1010#include " WcharMbcsConverter.h"
1111#include " MenuManager.h"
12+ #include " PythonScript.h"
1213
1314
1415namespace NppPythonScript
@@ -25,7 +26,8 @@ ConsoleDialog::ConsoleDialog() :
2526 m_hTabIcon (NULL ),
2627 m_currentHistory (0 ),
2728 m_runButtonIsRun (true ),
28- m_hContext (NULL )
29+ m_hContext (NULL ),
30+ m_nppData{0 ,0 ,0 }
2931{
3032 m_historyIter = m_history.end ();
3133}
@@ -98,6 +100,7 @@ void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterfa
98100 mi.dwTypeData = _T (" To Input" );
99101 InsertMenuItem (m_hContext, 4 , TRUE , &mi);
100102
103+ m_nppData = nppData;
101104}
102105
103106INT_PTR CALLBACK ConsoleDialog::run_dlgProc (UINT message, WPARAM wParam, LPARAM lParam)
@@ -238,13 +241,16 @@ INT_PTR CALLBACK ConsoleDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
238241 }
239242 break ;
240243 }
244+ case WM_SHOWWINDOW:
245+ {
246+ MenuManager::getInstance ()->checkShowConsole (wParam);
247+ }
241248 default :
242249 break ;
243250
244251 }
245252
246253 return DockingDlgInterface::run_dlgProc (message, wParam, lParam);
247-
248254}
249255
250256
@@ -626,14 +632,26 @@ void ConsoleDialog::doDialog()
626632 callScintilla (SCI_COLOURISE, 0 , -1 );
627633 }
628634 }
629- MenuManager::getInstance ()->checkShowConsole (true );
630635 display (true );
631636}
632637
633638void ConsoleDialog::hide ()
634639{
635- MenuManager::getInstance ()->checkShowConsole (false );
636640 display (false );
641+ HWND current_HWND = ::GetFocus ();
642+ if (m_hInput == current_HWND || m_scintilla == current_HWND)
643+ {
644+ intptr_t currentView = MAIN_VIEW;
645+ ::SendMessage (m_nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0 , (LPARAM)¤tView);
646+ HWND sci = (currentView == MAIN_VIEW) ? m_nppData._scintillaMainHandle : m_nppData._scintillaSecondHandle ;
647+
648+ DWORD currentThreadId = GetCurrentThreadId ();
649+ DWORD otherThreadId = GetWindowThreadProcessId (sci, NULL );
650+
651+ AttachThreadInput (currentThreadId, otherThreadId, TRUE );
652+ SetFocus (sci);
653+ AttachThreadInput (currentThreadId, otherThreadId, FALSE );
654+ }
637655}
638656
639657void ConsoleDialog::runEnabled (bool enabled)
0 commit comments