Skip to content

Commit

Permalink
fix persistency of PS-console visibility after Notepad++ relaunch (#315)
Browse files Browse the repository at this point in the history
* fix persistency of PS-console visibility after Notepad++ relaunch
  • Loading branch information
xomx authored Nov 15, 2023
1 parent 9256580 commit cc5575d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions PythonScript/src/ConsoleDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions PythonScript/src/PythonConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<WPARAM>(pluginName), reinterpret_cast<LPARAM>(&commInfo));
commInfo.srcModuleName = PLUGIN_MODULE_NAME;
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(PLUGIN_MODULE_NAME), reinterpret_cast<LPARAM>(&commInfo));
}
else
{
Expand Down
29 changes: 20 additions & 9 deletions PythonScript/src/PythonScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -36,6 +34,7 @@ static AboutDialog aboutDlg;
static ShortcutDlg *g_shortcutDlg = NULL;

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

// Paths
static char g_pluginDir[MAX_PATH];
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"))
{
Expand Down Expand Up @@ -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);
}

}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions PythonScript/src/PythonScript.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions PythonScript/src/ScintillaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "MutexHolder.h"
#include "ScintillaCallbackCounter.h"
#include "NotAllowedInCallbackException.h"
#include "PythonScript.h"

namespace NppPythonScript
{
Expand Down Expand Up @@ -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<void*>(&replacementContainer);
GILRelease release;
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(pluginName), reinterpret_cast<LPARAM>(&commInfo));
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(PLUGIN_MODULE_NAME), reinterpret_cast<LPARAM>(&commInfo));

EndUndoAction();

Expand Down

0 comments on commit cc5575d

Please sign in to comment.