Skip to content

Commit f941c7f

Browse files
ClaudiaFrankchcg
authored andcommitted
enhance feature request bruderstein#54 (bruderstein#67)
* enhance feature request bruderstein#54 * another enhancement to bruderstein#54
1 parent b3a1062 commit f941c7f

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

PythonScript/src/ConsoleDialog.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Docking.h"
1010
#include "WcharMbcsConverter.h"
1111
#include "MenuManager.h"
12+
#include "PythonScript.h"
1213

1314

1415
namespace 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

103106
INT_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

633638
void 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)&currentView);
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

639657
void ConsoleDialog::runEnabled(bool enabled)

PythonScript/src/ConsoleDialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ConsoleDialog : public DockingDlgInterface
3636
void giveInputFocus() { SetFocus(m_hInput); }
3737

3838
void runEnabled(bool enabled);
39+
40+
NppData m_nppData;
3941

4042
protected:
4143
virtual INT_PTR CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);

PythonScript/src/MenuManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ WNDPROC MenuManager::s_origWndProc;
1616

1717

1818
bool MenuManager::s_menuItemClicked;
19+
bool MenuManager::s_menuItemConsoleChecked = false;
1920

2021
MenuManager::runScriptIDFunc MenuManager::s_runScript;
2122

@@ -1136,4 +1137,5 @@ bool MenuManager::inFixedRange(idx_t commandID)
11361137
void MenuManager::checkShowConsole(bool checked)
11371138
{
11381139
::SendMessage(m_hNotepad, NPPM_SETMENUITEMCHECK, (WPARAM)m_funcItems[1]._cmdID, (LPARAM)checked);
1140+
s_menuItemConsoleChecked = checked;
11391141
}

PythonScript/src/MenuManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class MenuManager
8282
static WNDPROC s_origWndProc;
8383

8484
void checkShowConsole(bool checked);
85+
static bool s_menuItemConsoleChecked;
8586

8687

8788
private:

PythonScript/src/PythonConsole.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ void PythonConsole::pythonShowDialog()
136136
else
137137
{
138138
mp_consoleDlg->doDialog();
139-
consoleVisible = true;
140139
}
141140
}
142141
}
@@ -148,7 +147,6 @@ void PythonConsole::showDialog()
148147
{
149148
GILRelease release;
150149
mp_consoleDlg->doDialog();
151-
consoleVisible = true;
152150
}
153151
}
154152

@@ -159,7 +157,6 @@ void PythonConsole::hideDialog()
159157
{
160158
GILRelease release;
161159
mp_consoleDlg->hide();
162-
consoleVisible = false;
163160
}
164161
}
165162

PythonScript/src/PythonConsole.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class PythonConsole : public PyProducerConsumer<std::string>, public ConsoleInte
7373

7474
static boost::python::str getEncoding() { return boost::python::str("utf-8"); }
7575

76-
bool consoleVisible = false;
77-
7876
protected:
7977
virtual void consume(std::shared_ptr<std::string> statement);
8078
virtual void queueComplete();

PythonScript/src/PythonScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static void toggleConsole()
573573
if (g_console)
574574
{
575575
CHECK_INITIALISED();
576-
if (g_console->consoleVisible)
576+
if (MenuManager::getInstance()->s_menuItemConsoleChecked)
577577
{
578578
g_console->hideDialog();
579579
}

0 commit comments

Comments
 (0)