Skip to content

Commit ebe36f4

Browse files
committed
Lazy startup, fixes, and helper funcs
- Lazy / Immediate start implemented - Bugs fixed with Scripts menu not refreshing properly - Multithreading bugs fixed for callbacks - Objects renamed (Editor/editor, Notepad/notepad) - Helper functions added (deleteLine, replaceLine, replace, rereplace etc) - Config dialog bug fixed with ListViews not clearing - FindText Scintilla changed to object from str - Notepad helper functions added (messageBox, prompt) - About Dialog copyrights added - Version number now comes from header
1 parent 3018f79 commit ebe36f4

34 files changed

+1733
-259
lines changed

PythonScript/project/PythonScript2010.vcxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@
8585
<GenerateDebugInformation>true</GenerateDebugInformation>
8686
<EnableCOMDATFolding>true</EnableCOMDATFolding>
8787
<OptimizeReferences>true</OptimizeReferences>
88-
<AdditionalDependencies>python26.lib;NppPlugin.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
88+
<AdditionalDependencies>python26.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
8989
</Link>
9090
</ItemDefinitionGroup>
9191
<ItemGroup>
92+
<None Include="..\..\..\nppexec\src\bitmap1.bmp" />
9293
<None Include="..\..\..\NppExec\src\ConsoleIcon.ico" />
9394
<None Include="..\..\..\nppexec\src\icon2.ico" />
9495
<None Include="..\src\bitmap2.bmp" />
@@ -119,6 +120,7 @@
119120
<ClCompile Include="..\src\MenuManager.cpp" />
120121
<ClCompile Include="..\src\NotepadPlusWrapper.cpp" />
121122
<ClCompile Include="..\src\NotepadPython.cpp" />
123+
<ClCompile Include="..\src\PromptDialog.cpp" />
122124
<ClCompile Include="..\src\PyProducerConsumer.cpp" />
123125
<ClCompile Include="..\src\PythonConsole.cpp" />
124126
<ClCompile Include="..\src\PythonHandler.cpp" />
@@ -141,10 +143,12 @@
141143
<ClInclude Include="..\src\NotepadPlusBuffer.h" />
142144
<ClInclude Include="..\src\NotepadPlusWrapper.h" />
143145
<ClInclude Include="..\src\NotepadPython.h" />
146+
<ClInclude Include="..\src\PromptDialog.h" />
144147
<ClInclude Include="..\src\PyProducerConsumer.h" />
145148
<ClInclude Include="..\src\PythonConsole.h" />
146149
<ClInclude Include="..\src\PythonHandler.h" />
147150
<ClInclude Include="..\src\PythonScript.h" />
151+
<ClInclude Include="..\src\PythonScriptVersion.h" />
148152
<ClInclude Include="..\src\resource.h" />
149153
<ClInclude Include="..\src\ScintillaCells.h" />
150154
<ClInclude Include="..\src\ScintillaNotifications.h" />
@@ -153,9 +157,11 @@
153157
<ClInclude Include="..\src\ShortcutDlg.h" />
154158
<ClInclude Include="..\src\stdafx.h" />
155159
<ClInclude Include="..\src\WcharMbcsConverter.h" />
160+
<ClInclude Include="..\src\resource1.h" />
156161
</ItemGroup>
157162
<ItemGroup>
158163
<ResourceCompile Include="..\src\PythonScript.rc" />
164+
<ResourceCompile Include="..\src\PythonScriptVersion.rc" />
159165
</ItemGroup>
160166
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
161167
<ImportGroup Label="ExtensionTargets">

PythonScript/project/PythonScript2010.vcxproj.filters

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
<None Include="..\src\python2.ico">
6868
<Filter>Resource Files</Filter>
6969
</None>
70+
<None Include="..\..\..\nppexec\src\bitmap1.bmp">
71+
<Filter>Resource Files</Filter>
72+
</None>
7073
</ItemGroup>
7174
<ItemGroup>
7275
<ClCompile Include="..\src\PythonHandler.cpp">
@@ -123,6 +126,9 @@
123126
<ClCompile Include="..\src\ConfigFile.cpp">
124127
<Filter>Source Files</Filter>
125128
</ClCompile>
129+
<ClCompile Include="..\src\PromptDialog.cpp">
130+
<Filter>Source Files</Filter>
131+
</ClCompile>
126132
</ItemGroup>
127133
<ItemGroup>
128134
<ClInclude Include="..\src\AboutDialog.h">
@@ -188,10 +194,22 @@
188194
<ClInclude Include="..\src\ConfigFile.h">
189195
<Filter>Header Files</Filter>
190196
</ClInclude>
197+
<ClInclude Include="..\src\PromptDialog.h">
198+
<Filter>Header Files</Filter>
199+
</ClInclude>
200+
<ClInclude Include="..\src\PythonScriptVersion.h">
201+
<Filter>Header Files</Filter>
202+
</ClInclude>
203+
<ClInclude Include="..\src\resource1.h">
204+
<Filter>Header Files</Filter>
205+
</ClInclude>
191206
</ItemGroup>
192207
<ItemGroup>
193208
<ResourceCompile Include="..\src\PythonScript.rc">
194209
<Filter>Resource Files</Filter>
195210
</ResourceCompile>
211+
<ResourceCompile Include="..\src\PythonScriptVersion.rc">
212+
<Filter>Resource Files</Filter>
213+
</ResourceCompile>
196214
</ItemGroup>
197215
</Project>

PythonScript/src/AboutDialog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class AboutDialog : public StaticDialog
1616
Window::init(hInst, nppData._nppHandle);
1717
};
1818

19-
void doDialog();
20-
BOOL CALLBACK AboutDialog::run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
19+
void doDialog();
20+
BOOL CALLBACK AboutDialog::run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
2121

2222
private:
2323
NppData _nppData;

PythonScript/src/AboutDialog2.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "stdafx.h"
2+
#include "AboutDialog.h"
3+
#include "PythonScriptVersion.h"
4+
#include "resource.h"
5+
6+
//using namespace std;
7+
8+
AboutDialog::AboutDialog(void)
9+
{
10+
m_hbrBackground = CreateSolidBrush(RGB(255,255,255));
11+
}
12+
13+
AboutDialog::~AboutDialog(void)
14+
{
15+
}
16+
17+
void AboutDialog::doDialog()
18+
{
19+
if (!isCreated())
20+
create(IDD_ABOUTDLG);
21+
22+
goToCenter();
23+
}
24+
25+
26+
BOOL CALLBACK AboutDialog::run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
27+
{
28+
switch (Message)
29+
{
30+
case WM_INITDIALOG :
31+
{
32+
std::string message("Python ");
33+
message.append(Py_GetVersion());
34+
message.append("\n");
35+
message.append(Py_GetCopyright());
36+
37+
for (size_t pos = 0;(pos = message.find("\n", pos + 1)) != std::string::npos;)
38+
{
39+
message.replace(pos, 1, "\r\n");
40+
++pos;
41+
}
42+
43+
::SetWindowTextA(GetDlgItem(hWnd, IDC_COPYRIGHT), message.c_str());
44+
::SetWindowText(GetDlgItem(hWnd, IDC_VERSION), _T(PYSCR_VERSION_STRING));
45+
return TRUE;
46+
}
47+
48+
case WM_CTLCOLORDLG:
49+
return (LONG)m_hbrBackground;
50+
51+
case WM_CTLCOLORSTATIC:
52+
{
53+
HDC hdcStatic = (HDC)wParam;
54+
SetBkMode(hdcStatic, TRANSPARENT);
55+
return (LONG)m_hbrBackground;
56+
}
57+
58+
case WM_COMMAND :
59+
{
60+
61+
62+
switch (wParam)
63+
{
64+
case IDOK :
65+
case IDCANCEL :
66+
display(FALSE);
67+
return TRUE;
68+
69+
default :
70+
break;
71+
}
72+
73+
}
74+
}
75+
return FALSE;
76+
}

PythonScript/src/ConfigFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@ void ConfigFile::setSetting(const tstring& settingName, const tstring settingVal
142142
{
143143
m_settings[settingName] = settingValue;
144144
}
145+
146+
const tstring& ConfigFile::getSetting(const TCHAR *settingName)
147+
{
148+
return m_settings[tstring(settingName)];
149+
}

PythonScript/src/ConfigFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ConfigFile
1616
static ConfigFile* create(const TCHAR *configDir, const TCHAR *pluginDir, HINSTANCE hInst);
1717
static ConfigFile* getInstance() { return s_instance; };
1818

19-
tstring getSetting(const TCHAR* settingName);
19+
2020

2121
// TODO: Need to make these pointers
2222
MenuItemsTD getMenuItems() { return m_menuItems; };
@@ -26,6 +26,7 @@ class ConfigFile
2626
void addMenuItem(const tstring scriptPath);
2727
void addToolbarItem(const tstring scriptPath, const tstring iconPath);
2828
void setSetting(const tstring& settingName, const tstring settingValue);
29+
const tstring& getSetting(const TCHAR* settingName);
2930

3031
void clearItems();
3132
void save();

PythonScript/src/ConsoleDialog.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,10 @@ void ConsoleDialog::runEnabled(bool enabled)
338338
::SetFocus(m_hInput);
339339
}
340340
}
341+
342+
void ConsoleDialog::clearText()
343+
{
344+
::SendMessage(m_scintilla, SCI_SETREADONLY, 0, 0);
345+
::SendMessage(m_scintilla, SCI_CLEARALL, 0, 0);
346+
::SendMessage(m_scintilla, SCI_SETREADONLY, 1, 0);
347+
}

PythonScript/src/ConsoleDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConsoleDialog : DockingDlgInterface
2121
BOOL CALLBACK run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
2222

2323
void writeText(int length, const char *text);
24-
24+
void clearText();
2525
void setPrompt(const char *prompt);
2626
HWND getScintillaHwnd() { return m_scintilla; };
2727

PythonScript/src/CreateWrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
typeExplosions = {
6161
#'colour' : lambda name: 'int {0}Red, int {0}Green, int {0}Blue'.format(name),
62-
'findtext' : lambda name: 'int start, int end, boost::python::str {0}'.format(name),
62+
'findtext' : lambda name: 'int start, int end, boost::python::object {0}'.format(name),
6363
'textrange' : lambda name: 'int start, int end'
6464
}
6565

@@ -149,7 +149,7 @@ def findTextBody(v, out):
149149
out.write('\tSci_TextToFind src;\n')
150150
out.write('\tsrc.chrg.cpMin = start;\n')
151151
out.write('\tsrc.chrg.cpMax = end;\n')
152-
out.write('\tsrc.lpstrText = const_cast<char*>((const char *)extract<const char *>({0}));\n'.format(v['Param2Name']))
152+
out.write('\tsrc.lpstrText = const_cast<char*>((const char *)extract<const char *>({0}.attr("__str__")()));\n'.format(v['Param2Name']))
153153
out.write('\tint result = callScintilla({0}, {1}, reinterpret_cast<LPARAM>(&src));\n'.format(symbolName(v), v["Param1Name"]))
154154
out.write('\tif (-1 == result)\n')
155155
out.write('\t{\n\t\treturn object();\n\t}\n')

PythonScript/src/MenuManager.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using namespace std;
1010

1111
// Static instance
12-
MenuManager* MenuManager::s_menuManager;
12+
MenuManager* MenuManager::s_menuManager = NULL;
1313

1414
WNDPROC MenuManager::s_origWndProc;
1515

@@ -27,7 +27,6 @@ bool MenuManager::s_menuItemClicked;
2727
void (*MenuManager::s_runScript)(int);
2828

2929

30-
3130
MenuManager* MenuManager::create(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *))
3231
{
3332
if (NULL == s_menuManager)
@@ -208,29 +207,40 @@ bool MenuManager::populateScriptsMenu()
208207
// Fills the Scripts menu
209208
void MenuManager::refreshScriptsMenu()
210209
{
211-
// This will try to delete all scripts menu items
212-
// - scripts in sub directories will be unsuccessful,
213-
// but less trouble (read: CPU) than trying to work out which ones we should delete (ie. root dir)
214-
for(ScriptCommandsTD::iterator it = m_scriptCommands.begin(); it != m_scriptCommands.end(); ++it)
210+
211+
// Remove all the menu items (or submenus) from the scripts menu
212+
// Remove, not destroy, as we need to destroy all the sub-submenus too
213+
int menuCount = GetMenuItemCount(m_hScriptsMenu);
214+
215+
for(int position = 0; position < menuCount; ++position)
215216
{
216-
DeleteMenu(m_hScriptsMenu, it->first, MF_BYCOMMAND);
217+
RemoveMenu(m_hScriptsMenu, 0, MF_BYPOSITION);
217218
}
218-
219+
220+
219221
m_scriptCommands.erase(m_scriptCommands.begin(), m_scriptCommands.end());
220222
m_machineScriptNames.erase(m_machineScriptNames.begin(), m_machineScriptNames.end());
223+
224+
225+
226+
// Destroy all the menus we've created
221227
for(SubmenusTD::iterator it = m_submenus.begin(); it != m_submenus.end(); ++it)
222228
{
223229
if (it->first != "\\")
224230
{
231+
// Destroy the menu
225232
DestroyMenu(it->second);
226233
}
227234
}
235+
236+
m_submenus.erase(m_submenus.begin(), m_submenus.end());
228237

229238
int nextID = findScripts(m_hScriptsMenu, m_machineScriptsPath.size(), s_startCommandID, m_machineScriptsPath);
230239

231240
s_endCommandID = findScripts(m_hScriptsMenu, m_userScriptsPath.size(), nextID, m_userScriptsPath);
232241

233242

243+
DrawMenuBar(m_hNotepad);
234244
}
235245

236246

@@ -563,4 +573,14 @@ void MenuManager::configureToolbarIcons()
563573

564574
if (currentToolbarID > s_startToolbarID)
565575
s_endToolbarID = currentToolbarID;
576+
}
577+
578+
579+
void MenuManager::deleteInstance()
580+
{
581+
if (s_menuManager)
582+
{
583+
delete s_menuManager;
584+
s_menuManager = NULL;
585+
}
566586
}

0 commit comments

Comments
 (0)