diff --git a/PythonScript/src/ConsoleDialog.cpp b/PythonScript/src/ConsoleDialog.cpp index 9d6860d4..5d4027e5 100644 --- a/PythonScript/src/ConsoleDialog.cpp +++ b/PythonScript/src/ConsoleDialog.cpp @@ -564,8 +564,8 @@ void ConsoleDialog::doDialog() rc.right = 0; m_hTabIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_PYTHON8), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT); m_data->hIconTab = m_hTabIcon; - m_data->pszModuleName = _T("Python Script"); - m_data->dlgID = -1; /* IDD_CONSOLE */ + m_data->pszModuleName = PLUGIN_MODULE_NAME; // the plugin filename + m_data->dlgID = 1; // zero based index of the plugin's published funcs array command (here the "Show Console" in the getGeneratedFuncItemArray exported func) m_data->pszAddInfo = NULL; //_pExProp->szCurrentPath; m_data->iPrevCont = -1; m_data->hClient = _hSelf; diff --git a/PythonScript/src/PythonConsole.cpp b/PythonScript/src/PythonConsole.cpp index 1c65eada..8cc8fe09 100644 --- a/PythonScript/src/PythonConsole.cpp +++ b/PythonScript/src/PythonConsole.cpp @@ -9,6 +9,7 @@ #include "PythonScript/NppPythonScript.h" #include "scintilla.h" #include "GILManager.h" +#include "PythonScript.h" // Sad, but we need to know if we're in an event handler when running an external command // Not sure how I can extrapolate this info and not tie PythonConsole and NotepadPlusWrapper together. @@ -129,9 +130,8 @@ void PythonConsole::pythonShowDialog() { CommunicationInfo commInfo{}; commInfo.internalMsg = PYSCR_SHOWCONSOLE; - commInfo.srcModuleName = _T("PythonScript.dll"); - TCHAR pluginName[] = _T("PythonScript.dll"); - ::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast(pluginName), reinterpret_cast(&commInfo)); + commInfo.srcModuleName = PLUGIN_MODULE_NAME; + ::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast(PLUGIN_MODULE_NAME), reinterpret_cast(&commInfo)); } else { diff --git a/PythonScript/src/PythonScript.cpp b/PythonScript/src/PythonScript.cpp index a4f9cda5..c890b8df 100644 --- a/PythonScript/src/PythonScript.cpp +++ b/PythonScript/src/PythonScript.cpp @@ -23,8 +23,6 @@ #define CHECK_INITIALISED() if (!g_initialised) initialisePython() /* Info for Notepad++ */ -CONST TCHAR PLUGIN_NAME[] = _T("Python Script"); - static FuncItem *funcItem = NULL; /* Global data */ @@ -36,6 +34,7 @@ static AboutDialog aboutDlg; static ShortcutDlg *g_shortcutDlg = NULL; static boost::shared_ptr g_console(NULL); +static bool g_bToggleConsoleFlag = false; // Paths static char g_pluginDir[MAX_PATH]; @@ -110,7 +109,7 @@ extern "C" __declspec(dllexport) void setInfo(NppData notepadPlusData) { nppData = notepadPlusData; #ifdef DEBUG_STARTUP - MessageBox(NULL, _T("setInfo"), _T("Python Script"), 0); + MessageBox(NULL, _T("setInfo"), PLUGIN_NAME, 0); #endif @@ -139,14 +138,14 @@ extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF) if (g_infoSet) { #ifdef DEBUG_STARTUP - MessageBox(NULL, _T("Python GetFuncsArray"), _T("Python Script"), 0); + MessageBox(NULL, _T("Python GetFuncsArray"), PLUGIN_NAME, 0); #endif funcItem = getGeneratedFuncItemArray(nbF); } else { - 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); + 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); funcItem = (FuncItem*) malloc(sizeof(FuncItem)); memset(funcItem, 0, sizeof(FuncItem)); _tcscpy_s(funcItem[0]._itemName, 64, _T("About - Python Script Disabled")); @@ -262,7 +261,7 @@ static void initialisePython() static void registerToolbarIcons() { #ifdef DEBUG_STARTUP - MessageBox(NULL, _T("Register toolbar icons"), _T("Python Script"), 0); + MessageBox(NULL, _T("Register toolbar icons"), PLUGIN_NAME, 0); #endif MenuManager* menuManager = MenuManager::getInstance(); menuManager->idsInitialised(); @@ -294,9 +293,13 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode) case NPPN_READY: { #ifdef DEBUG_STARTUP - MessageBox(NULL, _T("NPPN_READY"), _T("Python Script"), 0); + MessageBox(NULL, _T("NPPN_READY"), PLUGIN_NAME, 0); #endif initialise(); + + if (g_bToggleConsoleFlag) + toggleConsole(); // fix possible missing PS console (Notepad++ DockingManager-init calls the PS toggleConsole() published func before the PS init...) + ConfigFile *config = ConfigFile::getInstance(); if (config->getSetting(_T("STARTUP")) == _T("ATSTARTUP")) { @@ -500,7 +503,7 @@ static void runStatement(const TCHAR *statement, bool synchronous, HANDLE comple MenuManager::getInstance()->stopScriptEnabled(true); if (!pythonHandler->runScript(statement, synchronous, allowQueuing, completedEvent, true)) { - 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); + 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); } } @@ -553,7 +556,7 @@ static void runScript(const TCHAR *filename, bool synchronous, HANDLE completedE if (!pythonHandler->runScript(filename, synchronous, allowQueuing, completedEvent)) { - 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); + 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); } } @@ -577,12 +580,20 @@ static void toggleConsole() if (MenuManager::getInstance()->s_menuItemConsoleChecked) { g_console->hideDialog(); + g_bToggleConsoleFlag = false; // this is not necessary but maybe for a future use... } else { g_console->showDialog(); + g_bToggleConsoleFlag = true; // this is not necessary but maybe for a future use... } } + else + { + // track the PS console showing/hiding requests even without the full PS initialization + // - this fixes the Notepad++ DockingManager-init as it calls this func even before the PS plugin full init at its NPPN_READY + g_bToggleConsoleFlag = !g_bToggleConsoleFlag; + } } static void ensurePathExists(const tstring& path) diff --git a/PythonScript/src/PythonScript.h b/PythonScript/src/PythonScript.h index ccc9bcbb..1a17afb3 100644 --- a/PythonScript/src/PythonScript.h +++ b/PythonScript/src/PythonScript.h @@ -1,6 +1,8 @@ #ifndef _PYTHONSCRIPT_H #define _PYTHONSCRIPT_H +#define PLUGIN_NAME _T("Python Script") +#define PLUGIN_MODULE_NAME _T("PythonScript.dll") #define PLUGINTEMPLATE_INI _T("\\PythonScript.ini") #define MAX_MENU_SCRIPTS 50 diff --git a/PythonScript/src/ScintillaWrapper.cpp b/PythonScript/src/ScintillaWrapper.cpp index 77cfbad8..12bddfa2 100644 --- a/PythonScript/src/ScintillaWrapper.cpp +++ b/PythonScript/src/ScintillaWrapper.cpp @@ -17,6 +17,7 @@ #include "MutexHolder.h" #include "ScintillaCallbackCounter.h" #include "NotAllowedInCallbackException.h" +#include "PythonScript.h" namespace NppPythonScript { @@ -867,12 +868,10 @@ void ScintillaWrapper::replaceImpl(boost::python::object searchStr, boost::pytho CommunicationInfo commInfo{}; commInfo.internalMsg = PYSCR_RUNREPLACE; - commInfo.srcModuleName = _T("PythonScript.dll"); - TCHAR pluginName[] = _T("PythonScript.dll"); - + commInfo.srcModuleName = PLUGIN_MODULE_NAME; commInfo.info = reinterpret_cast(&replacementContainer); GILRelease release; - ::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast(pluginName), reinterpret_cast(&commInfo)); + ::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast(PLUGIN_MODULE_NAME), reinterpret_cast(&commInfo)); EndUndoAction();