Skip to content

Commit 61576ff

Browse files
committed
Console Support for Tabbing between input and output windows
Tab to/from the Scintilla control in the console was previously not supported. Requested for better support for blind users. Many thanks to Ralf V. for the suggestion, and I hope it helps!
1 parent 39e45af commit 61576ff

File tree

6 files changed

+87
-13
lines changed

6 files changed

+87
-13
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ Debug/
2424
Release/
2525
ipch/
2626
*.pyc
27+
_ReSharper.*/
28+
Debug-ANSI2/
29+
Debug2/
30+
Debug-ANSI/
31+
DebugStartup2/
2732
docs/build/
33+
Release_Archive/
34+

PythonScript/project/PythonScript2010.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
<ShowProgress>LinkVerbose</ShowProgress>
133133
</Link>
134134
<PostBuildEvent>
135-
<Command>copy $(OutDir)$(TargetFileName) "C:\Program Files (x86)\Notepad++5.8\plugins"</Command>
135+
<Command>copy $(OutDir)$(TargetFileName) "e:\notepadtest\unicode\plugins"</Command>
136136
</PostBuildEvent>
137137
</ItemDefinitionGroup>
138138
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugStartup|Win32'">

PythonScript/project/PythonSettings.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ImportGroup Label="PropertySheets" />
44
<PropertyGroup Label="UserMacros">
5+
<BoostBase>E:\libs\boost</BoostBase>
56
<PythonBase>E:\work\Python-2.7</PythonBase>
67
<PythonLibPath>$(PythonBase)\PCbuild</PythonLibPath>
78
<BoostPythonLibPath>$(BoostBase)\bin.v2\libs\python\build\msvc-10.0\$(Configuration)\link-static\runtime-link-static\threading-multi</BoostPythonLibPath>
89
<HtmlHelpBase>C:\Program Files (x86)\HTML Help Workshop</HtmlHelpBase>
9-
<BoostBase>E:\libs\boost</BoostBase>
1010
</PropertyGroup>
1111
<PropertyGroup />
1212
<ItemDefinitionGroup />
1313
<ItemGroup>
14+
<BuildMacro Include="BoostBase">
15+
<Value>$(BoostBase)</Value>
16+
</BuildMacro>
1417
<BuildMacro Include="PythonBase">
1518
<Value>$(PythonBase)</Value>
1619
</BuildMacro>
@@ -23,8 +26,5 @@
2326
<BuildMacro Include="HtmlHelpBase">
2427
<Value>$(HtmlHelpBase)</Value>
2528
</BuildMacro>
26-
<BuildMacro Include="BoostBase">
27-
<Value>$(BoostBase)</Value>
28-
</BuildMacro>
2929
</ItemGroup>
3030
</Project>

PythonScript/src/ConsoleDialog.cpp

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,18 @@ ConsoleDialog::~ConsoleDialog()
7979

8080
}
8181

82+
WNDPROC ConsoleDialog::s_originalScintillaWndProc;
83+
8284

8385
void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterface* console)
8486
{
8587
DockingDlgInterface::init(hInst, nppData._nppHandle);
8688

8789
//Window::init(hInst, nppData._nppHandle);
8890
createOutputWindow(nppData._nppHandle);
89-
m_console = console;
91+
92+
93+
m_console = console;
9094
m_hContext = CreatePopupMenu();
9195
MENUITEMINFO mi;
9296
mi.cbSize = sizeof(mi);
@@ -106,6 +110,10 @@ void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterfa
106110
mi.dwTypeData = _T("Clear");
107111
InsertMenuItem(m_hContext, 3, TRUE, &mi);
108112

113+
mi.wID = 4;
114+
mi.dwTypeData = _T("To Input");
115+
InsertMenuItem(m_hContext, 4, TRUE, &mi);
116+
109117
}
110118

111119
BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
@@ -127,8 +135,10 @@ BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam,
127135
// Subclass the Input box
128136
::SetWindowLongPtr(::GetDlgItem(_hSelf, IDC_INPUT), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
129137
m_originalInputWndProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(::GetDlgItem(_hSelf, IDC_INPUT), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ConsoleDialog::inputWndProc)));
130-
131-
return TRUE;
138+
// Subclass Scintilla
139+
s_originalScintillaWndProc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(m_scintilla, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&ConsoleDialog::scintillaWndProc)));
140+
::SetFocus(m_hInput);
141+
return FALSE;
132142
}
133143
case WM_SIZE:
134144
MoveWindow(m_scintilla, 0, 0, LOWORD(lParam), HIWORD(lParam)-30, TRUE);
@@ -176,6 +186,10 @@ BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam,
176186
clearText();
177187
break;
178188

189+
case 4: // To input (TODO: TEST only!)
190+
giveInputFocus();
191+
break;
192+
179193
default:
180194
break;
181195
}
@@ -201,6 +215,24 @@ BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam,
201215
}
202216
break;
203217

218+
case WM_SETFOCUS:
219+
//giveInputFocus();
220+
OutputDebugString(_T("ConsoleDialog SetFocus\r\n"));
221+
return FALSE;
222+
223+
case WM_ACTIVATE:
224+
if (wParam == WA_ACTIVE)
225+
{
226+
OutputDebugString(_T("ConsoleDialog WM_ACTIVATE WA_ACTIVE\r\n"));
227+
giveInputFocus();
228+
}
229+
break;
230+
231+
case WM_CHILDACTIVATE:
232+
OutputDebugString(_T("ConsoleDialog WM_CHILDACTIVATE\r\n"));
233+
giveInputFocus();
234+
break;
235+
204236
case WM_NOTIFY:
205237
{
206238
LPNMHDR nmhdr = reinterpret_cast<LPNMHDR>(lParam);
@@ -215,7 +247,7 @@ BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam,
215247
case SCN_HOTSPOTCLICK:
216248
onHotspotClick(reinterpret_cast<SCNotification*>(lParam));
217249
return FALSE;
218-
250+
219251
default:
220252
break;
221253
}
@@ -382,8 +414,11 @@ LRESULT ConsoleDialog::run_inputWndProc(HWND hWnd, UINT message, WPARAM wParam,
382414
default:
383415
return CallWindowProc(m_originalInputWndProc, hWnd, message, wParam, lParam);
384416
}
385-
386-
default:
417+
418+
case WM_SETFOCUS:
419+
OutputDebugString(_T("Input SetFocus\r\n"));
420+
421+
default:
387422
return CallWindowProc(m_originalInputWndProc, hWnd, message, wParam, lParam);
388423
}
389424
}
@@ -431,7 +466,12 @@ void ConsoleDialog::setPrompt(const char *prompt)
431466
void ConsoleDialog::createOutputWindow(HWND hParentWindow)
432467
{
433468
m_scintilla = (HWND)::SendMessage(_hParent, NPPM_CREATESCINTILLAHANDLE, 0, reinterpret_cast<LPARAM>(hParentWindow));
434-
callScintilla(SCI_SETREADONLY, 1, 0);
469+
470+
LONG currentStyle = GetWindowLong(m_scintilla, GWL_STYLE);
471+
SetWindowLong(m_scintilla, GWL_STYLE, currentStyle | WS_TABSTOP);
472+
473+
474+
callScintilla(SCI_SETREADONLY, 1, 0);
435475

436476
/* Style bits
437477
* LSB 0 - stderr = 1
@@ -485,6 +525,26 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
485525

486526
callScintilla(SCI_USEPOPUP, 0);
487527
callScintilla(SCI_SETLEXER, SCLEX_CONTAINER);
528+
529+
530+
}
531+
532+
LRESULT ConsoleDialog::scintillaWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
533+
{
534+
switch(message)
535+
{
536+
case WM_GETDLGCODE:
537+
return DLGC_WANTARROWS | DLGC_WANTCHARS;
538+
539+
case WM_SETFOCUS:
540+
OutputDebugString(_T("Scintilla SetFocus\r\n"));
541+
break;
542+
543+
default:
544+
break;
545+
}
546+
547+
return CallWindowProc(s_originalScintillaWndProc, hWnd, message, wParam, lParam);
488548
}
489549

490550
void ConsoleDialog::writeText(size_t length, const char *text)

PythonScript/src/ConsoleDialog.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class ConsoleDialog : public DockingDlgInterface
2727
void writeError(size_t length, const char *text);
2828
void clearText();
2929
void setPrompt(const char *prompt);
30-
HWND getScintillaHwnd() { return m_scintilla; };
30+
HWND getScintillaHwnd() { return m_scintilla; }
31+
32+
void giveInputFocus() { SetFocus(m_hInput); }
3133

3234
void runEnabled(bool enabled);
3335

@@ -43,6 +45,9 @@ class ConsoleDialog : public DockingDlgInterface
4345

4446
LRESULT run_inputWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
4547
static LRESULT inputWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
48+
static LRESULT scintillaWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
49+
50+
4651
void historyNext();
4752
void historyPrevious();
4853
void historyAdd(const TCHAR *line);
@@ -66,6 +71,7 @@ class ConsoleDialog : public DockingDlgInterface
6671
//HWND m_hNpp;
6772
tTbData* m_data;
6873
HWND m_scintilla;
74+
static WNDPROC s_originalScintillaWndProc;
6975
HWND m_hInput; // Input TextBox
7076
ConsoleInterface *m_console;
7177
std::string m_prompt;

PythonScript/src/PythonConsole.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ void PythonConsole::consume(const std::shared_ptr<std::string>& statement)
265265
if (mp_consoleDlg)
266266
{
267267
mp_consoleDlg->setPrompt(continuePrompt ? "... " : ">>> ");
268+
mp_consoleDlg->giveInputFocus();
268269
}
269270
}
270271

0 commit comments

Comments
 (0)