Skip to content

Commit cc5575d

Browse files
authored
fix persistency of PS-console visibility after Notepad++ relaunch (#315)
* fix persistency of PS-console visibility after Notepad++ relaunch
1 parent 9256580 commit cc5575d

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

PythonScript/src/ConsoleDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ void ConsoleDialog::doDialog()
564564
rc.right = 0;
565565
m_hTabIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_PYTHON8), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
566566
m_data->hIconTab = m_hTabIcon;
567-
m_data->pszModuleName = _T("Python Script");
568-
m_data->dlgID = -1; /* IDD_CONSOLE */
567+
m_data->pszModuleName = PLUGIN_MODULE_NAME; // the plugin filename
568+
m_data->dlgID = 1; // zero based index of the plugin's published funcs array command (here the "Show Console" in the getGeneratedFuncItemArray exported func)
569569
m_data->pszAddInfo = NULL; //_pExProp->szCurrentPath;
570570
m_data->iPrevCont = -1;
571571
m_data->hClient = _hSelf;

PythonScript/src/PythonConsole.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "PythonScript/NppPythonScript.h"
1010
#include "scintilla.h"
1111
#include "GILManager.h"
12+
#include "PythonScript.h"
1213

1314
// Sad, but we need to know if we're in an event handler when running an external command
1415
// Not sure how I can extrapolate this info and not tie PythonConsole and NotepadPlusWrapper together.
@@ -129,9 +130,8 @@ void PythonConsole::pythonShowDialog()
129130
{
130131
CommunicationInfo commInfo{};
131132
commInfo.internalMsg = PYSCR_SHOWCONSOLE;
132-
commInfo.srcModuleName = _T("PythonScript.dll");
133-
TCHAR pluginName[] = _T("PythonScript.dll");
134-
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(pluginName), reinterpret_cast<LPARAM>(&commInfo));
133+
commInfo.srcModuleName = PLUGIN_MODULE_NAME;
134+
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(PLUGIN_MODULE_NAME), reinterpret_cast<LPARAM>(&commInfo));
135135
}
136136
else
137137
{

PythonScript/src/PythonScript.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#define CHECK_INITIALISED() if (!g_initialised) initialisePython()
2424

2525
/* Info for Notepad++ */
26-
CONST TCHAR PLUGIN_NAME[] = _T("Python Script");
27-
2826
static FuncItem *funcItem = NULL;
2927

3028
/* Global data */
@@ -36,6 +34,7 @@ static AboutDialog aboutDlg;
3634
static ShortcutDlg *g_shortcutDlg = NULL;
3735

3836
static boost::shared_ptr<NppPythonScript::PythonConsole> g_console(NULL);
37+
static bool g_bToggleConsoleFlag = false;
3938

4039
// Paths
4140
static char g_pluginDir[MAX_PATH];
@@ -110,7 +109,7 @@ extern "C" __declspec(dllexport) void setInfo(NppData notepadPlusData)
110109
{
111110
nppData = notepadPlusData;
112111
#ifdef DEBUG_STARTUP
113-
MessageBox(NULL, _T("setInfo"), _T("Python Script"), 0);
112+
MessageBox(NULL, _T("setInfo"), PLUGIN_NAME, 0);
114113
#endif
115114

116115

@@ -139,14 +138,14 @@ extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF)
139138
if (g_infoSet)
140139
{
141140
#ifdef DEBUG_STARTUP
142-
MessageBox(NULL, _T("Python GetFuncsArray"), _T("Python Script"), 0);
141+
MessageBox(NULL, _T("Python GetFuncsArray"), PLUGIN_NAME, 0);
143142
#endif
144143

145144
funcItem = getGeneratedFuncItemArray(nbF);
146145
}
147146
else
148147
{
149-
MessageBox(NULL, _T("A fatal error has occurred. Notepad++ has incorrectly called getFuncsArray() before setInfo(). No menu items will be available for PythonScript."), _T("Python Script"), 0);
148+
MessageBox(NULL, _T("A fatal error has occurred. Notepad++ has incorrectly called getFuncsArray() before setInfo(). No menu items will be available for PythonScript."), PLUGIN_NAME, 0);
150149
funcItem = (FuncItem*) malloc(sizeof(FuncItem));
151150
memset(funcItem, 0, sizeof(FuncItem));
152151
_tcscpy_s(funcItem[0]._itemName, 64, _T("About - Python Script Disabled"));
@@ -262,7 +261,7 @@ static void initialisePython()
262261
static void registerToolbarIcons()
263262
{
264263
#ifdef DEBUG_STARTUP
265-
MessageBox(NULL, _T("Register toolbar icons"), _T("Python Script"), 0);
264+
MessageBox(NULL, _T("Register toolbar icons"), PLUGIN_NAME, 0);
266265
#endif
267266
MenuManager* menuManager = MenuManager::getInstance();
268267
menuManager->idsInitialised();
@@ -294,9 +293,13 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode)
294293
case NPPN_READY:
295294
{
296295
#ifdef DEBUG_STARTUP
297-
MessageBox(NULL, _T("NPPN_READY"), _T("Python Script"), 0);
296+
MessageBox(NULL, _T("NPPN_READY"), PLUGIN_NAME, 0);
298297
#endif
299298
initialise();
299+
300+
if (g_bToggleConsoleFlag)
301+
toggleConsole(); // fix possible missing PS console (Notepad++ DockingManager-init calls the PS toggleConsole() published func before the PS init...)
302+
300303
ConfigFile *config = ConfigFile::getInstance();
301304
if (config->getSetting(_T("STARTUP")) == _T("ATSTARTUP"))
302305
{
@@ -500,7 +503,7 @@ static void runStatement(const TCHAR *statement, bool synchronous, HANDLE comple
500503
MenuManager::getInstance()->stopScriptEnabled(true);
501504
if (!pythonHandler->runScript(statement, synchronous, allowQueuing, completedEvent, true))
502505
{
503-
MessageBox(NULL, _T("Another script is currently running. Running two scripts at the same time could produce unpredicable results, and is therefore disabled."), _T("Python Script"), 0);
506+
MessageBox(NULL, _T("Another script is currently running. Running two scripts at the same time could produce unpredicable results, and is therefore disabled."), PLUGIN_NAME, 0);
504507
}
505508

506509
}
@@ -553,7 +556,7 @@ static void runScript(const TCHAR *filename, bool synchronous, HANDLE completedE
553556

554557
if (!pythonHandler->runScript(filename, synchronous, allowQueuing, completedEvent))
555558
{
556-
MessageBox(NULL, _T("Another script is currently running. Running two scripts at the same time could produce unpredicable results, and is therefore disabled."), _T("Python Script"), 0);
559+
MessageBox(NULL, _T("Another script is currently running. Running two scripts at the same time could produce unpredicable results, and is therefore disabled."), PLUGIN_NAME, 0);
557560
}
558561
}
559562

@@ -577,12 +580,20 @@ static void toggleConsole()
577580
if (MenuManager::getInstance()->s_menuItemConsoleChecked)
578581
{
579582
g_console->hideDialog();
583+
g_bToggleConsoleFlag = false; // this is not necessary but maybe for a future use...
580584
}
581585
else
582586
{
583587
g_console->showDialog();
588+
g_bToggleConsoleFlag = true; // this is not necessary but maybe for a future use...
584589
}
585590
}
591+
else
592+
{
593+
// track the PS console showing/hiding requests even without the full PS initialization
594+
// - this fixes the Notepad++ DockingManager-init as it calls this func even before the PS plugin full init at its NPPN_READY
595+
g_bToggleConsoleFlag = !g_bToggleConsoleFlag;
596+
}
586597
}
587598

588599
static void ensurePathExists(const tstring& path)

PythonScript/src/PythonScript.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _PYTHONSCRIPT_H
22
#define _PYTHONSCRIPT_H
33

4+
#define PLUGIN_NAME _T("Python Script")
5+
#define PLUGIN_MODULE_NAME _T("PythonScript.dll")
46
#define PLUGINTEMPLATE_INI _T("\\PythonScript.ini")
57

68
#define MAX_MENU_SCRIPTS 50

PythonScript/src/ScintillaWrapper.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "MutexHolder.h"
1818
#include "ScintillaCallbackCounter.h"
1919
#include "NotAllowedInCallbackException.h"
20+
#include "PythonScript.h"
2021

2122
namespace NppPythonScript
2223
{
@@ -867,12 +868,10 @@ void ScintillaWrapper::replaceImpl(boost::python::object searchStr, boost::pytho
867868

868869
CommunicationInfo commInfo{};
869870
commInfo.internalMsg = PYSCR_RUNREPLACE;
870-
commInfo.srcModuleName = _T("PythonScript.dll");
871-
TCHAR pluginName[] = _T("PythonScript.dll");
872-
871+
commInfo.srcModuleName = PLUGIN_MODULE_NAME;
873872
commInfo.info = reinterpret_cast<void*>(&replacementContainer);
874873
GILRelease release;
875-
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(pluginName), reinterpret_cast<LPARAM>(&commInfo));
874+
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(PLUGIN_MODULE_NAME), reinterpret_cast<LPARAM>(&commInfo));
876875

877876
EndUndoAction();
878877

0 commit comments

Comments
 (0)