Skip to content

Commit e1313d6

Browse files
committed
Remove deprecated API
1 parent 21450bf commit e1313d6

File tree

2 files changed

+70
-58
lines changed

2 files changed

+70
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ vs.proj/x64
88
vs.proj/ARM64
99
vs.proj/NppPluginDemo.opensdf
1010
vs.proj/NppPluginDemo.sdf
11+
vs.proj/NppPluginDemo/
1112
*.suo
1213
*.sln
1314
vs.proj/NppPluginDemo.exp

src/PluginDefinition.cpp

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include <shlwapi.h>
2727
#include "DockingFeature/GoToLineDlg.h"
2828

29-
const TCHAR sectionName[] = TEXT("Insert Extesion");
30-
const TCHAR keyName[] = TEXT("doCloseTag");
31-
const TCHAR configFileName[] = TEXT("pluginDemo.ini");
29+
const wchar_t sectionName[] = L"Insert Extesion";
30+
const wchar_t keyName[] = L"doCloseTag";
31+
const wchar_t configFileName[] = L"pluginDemo.ini";
3232

3333
DemoDlg _goToLine;
3434

@@ -46,7 +46,7 @@ FuncItem funcItem[nbFunc];
4646
NppData nppData;
4747

4848

49-
TCHAR iniFilePath[MAX_PATH];
49+
wchar_t iniFilePath[MAX_PATH];
5050
bool doCloseTag = false;
5151

5252
#define DOCKABLE_DEMO_INDEX 15
@@ -65,7 +65,7 @@ void pluginInit(HANDLE hModule)
6565
//
6666
void pluginCleanUp()
6767
{
68-
::WritePrivateProfileString(sectionName, keyName, doCloseTag?TEXT("1"):TEXT("0"), iniFilePath);
68+
::WritePrivateProfileString(sectionName, keyName, doCloseTag ? L"1" : L"0", iniFilePath);
6969
}
7070

7171
//
@@ -98,17 +98,17 @@ void commandMenuInit()
9898
//--------------------------------------------//
9999
// with function :
100100
// setCommand(int index, // zero based number to indicate the order of command
101-
// TCHAR *commandName, // the command name that you want to see in plugin menu
101+
// wchar_t *commandName, // the command name that you want to see in plugin menu
102102
// PFUNCPLUGINCMD functionPointer, // the symbol of function (function pointer) associated with this command. The body should be defined below. See Step 4.
103103
// ShortcutKey *shortcut, // optional. Define a shortcut to trigger this command
104104
// bool check0nInit // optional. Make this menu item be checked visually
105105
// );
106-
setCommand(0, TEXT("Hello Notepad++"), hello, NULL, false);
107-
setCommand(1, TEXT("Hello (with FX)"), helloFX, NULL, false);
108-
setCommand(2, TEXT("What is Notepad++?"), WhatIsNpp, NULL, false);
106+
setCommand(0, L"Hello Notepad++", hello, NULL, false);
107+
setCommand(1, L"Hello (with FX)", helloFX, NULL, false);
108+
setCommand(2, L"What is Notepad++?", WhatIsNpp, NULL, false);
109109

110110
// Here you insert a separator
111-
setCommand(3, TEXT("---"), NULL, NULL, false);
111+
setCommand(3, L"---", NULL, NULL, false);
112112

113113
// Shortcut :
114114
// Following code makes the first command
@@ -119,33 +119,33 @@ void commandMenuInit()
119119
shKey->_isShift = false;
120120
shKey->_key = 0x46; //VK_F
121121

122-
setCommand(4, TEXT("Current Full Path"), insertCurrentFullPath, shKey, false);
123-
setCommand(5, TEXT("Current File Name"), insertCurrentFileName, NULL, false);
124-
setCommand(6, TEXT("Current Directory"), insertCurrentDirectory, NULL, false);
125-
setCommand(7, TEXT("Date & Time - short format"), insertShortDateTime, NULL, false);
126-
setCommand(8, TEXT("Date & Time - long format"), insertLongDateTime, NULL, false);
122+
setCommand(4, L"Current Full Path", insertCurrentFullPath, shKey, false);
123+
setCommand(5, L"Current File Name", insertCurrentFileName, NULL, false);
124+
setCommand(6, L"Current Directory", insertCurrentDirectory, NULL, false);
125+
setCommand(7, L"Date & Time - short format", insertShortDateTime, NULL, false);
126+
setCommand(8, L"Date & Time - long format", insertLongDateTime, NULL, false);
127127

128128
ShortcutKey *pShKey = new ShortcutKey;
129129
pShKey->_isAlt = true;
130130
pShKey->_isCtrl = false;
131131
pShKey->_isShift = false;
132132
pShKey->_key = 0x51; //VK_Q
133-
setCommand(9, TEXT("Close HTML/XML tag automatically"), insertHtmlCloseTag, pShKey, doCloseTag);
133+
setCommand(9, L"Close HTML/XML tag automatically", insertHtmlCloseTag, pShKey, doCloseTag);
134134

135-
setCommand(10, TEXT("---"), NULL, NULL, false);
135+
setCommand(10, L"---", NULL, NULL, false);
136136

137-
setCommand(11, TEXT("Get File Names Demo"), getFileNamesDemo, NULL, false);
138-
setCommand(12, TEXT("Get Session File Names Demo"), getSessionFileNamesDemo, NULL, false);
139-
setCommand(13, TEXT("Save Current Session Demo"), saveCurrentSessionDemo, NULL, false);
137+
setCommand(11, L"Get File Names Demo", getFileNamesDemo, NULL, false);
138+
setCommand(12, L"Get Session File Names Demo", getSessionFileNamesDemo, NULL, false);
139+
setCommand(13, L"Save Current Session Demo", saveCurrentSessionDemo, NULL, false);
140140

141-
setCommand(14, TEXT("---"), NULL, NULL, false);
141+
setCommand(14, L"---", NULL, NULL, false);
142142

143-
setCommand(DOCKABLE_DEMO_INDEX, TEXT("Dockable Dialog Demo"), DockableDlgDemo, NULL, false);
143+
setCommand(DOCKABLE_DEMO_INDEX, L"Dockable Dialog Demo", DockableDlgDemo, NULL, false);
144144

145-
setCommand(16, TEXT("---"), NULL, NULL, false);
145+
setCommand(16, L"---", NULL, NULL, false);
146146

147-
setCommand(17, TEXT("Plugin Communication Guide"), goToPluginCommunicationGuide, NULL, false);
148-
setCommand(18, TEXT("Get Plugin Demo Source Code"), goToPluginDemoRepo, NULL, false);
147+
setCommand(17, L"Plugin Communication Guide", goToPluginCommunicationGuide, NULL, false);
148+
setCommand(18, L"Get Plugin Demo Source Code", goToPluginDemoRepo, NULL, false);
149149
}
150150

151151

@@ -228,7 +228,7 @@ void helloFX()
228228
//
229229
// This function help you to initialize your plugin commands
230230
//
231-
bool setCommand(size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit)
231+
bool setCommand(size_t index, wchar_t *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit)
232232
{
233233
if (index >= nbFunc)
234234
return false;
@@ -294,7 +294,7 @@ void insertCurrentPath(int which)
294294
msg = NPPM_GETCURRENTDIRECTORY;
295295

296296
int currentEdit;
297-
TCHAR path[MAX_PATH];
297+
wchar_t path[MAX_PATH];
298298

299299
// A message to Notepad++ to get a multibyte string (if ANSI mode) or a wide char string (if Unicode mode)
300300
::SendMessage(nppData._nppHandle, msg, 0, (LPARAM)path);
@@ -342,29 +342,25 @@ void insertLongDateTime()
342342

343343
void insertDateTime(bool format)
344344
{
345-
TCHAR date[128];
346-
TCHAR time[128];
347-
TCHAR dateTime[256];
345+
wchar_t date[128];
346+
wchar_t time[128];
347+
wchar_t dateTime[256];
348348

349349
SYSTEMTIME st;
350350
::GetLocalTime(&st);
351351
::GetDateFormat(LOCALE_USER_DEFAULT, (format == shortDate)?DATE_SHORTDATE:DATE_LONGDATE, &st, NULL, date, 128);
352352
::GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, time, 128);
353353

354-
wsprintf(dateTime, TEXT("%s %s"), time, date);
354+
wsprintf(dateTime, L"%s %s", time, date);
355355

356356
int currentEdit;
357357
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&currentEdit);
358358
HWND curScint = (currentEdit == 0)?nppData._scintillaMainHandle:nppData._scintillaSecondHandle;
359-
#ifdef UNICODE
359+
360360
int encoding = (int)::SendMessage(curScint, SCI_GETCODEPAGE, 0, 0);
361361
char dateTimeA[MAX_PATH];
362362
WideCharToMultiByte(encoding, 0, dateTime, -1, dateTimeA, MAX_PATH, NULL, NULL);
363363
::SendMessage(curScint, SCI_REPLACESEL, 0, (LPARAM)dateTimeA);
364-
#else
365-
::SendMessage(curScint, SCI_REPLACESEL, 0, (LPARAM)dateTime);
366-
#endif
367-
368364
}
369365

370366
void insertHtmlCloseTag()
@@ -375,52 +371,67 @@ void insertHtmlCloseTag()
375371

376372
void getFileNamesDemo()
377373
{
378-
int nbFile = (int)::SendMessage(nppData._nppHandle, NPPM_GETNBOPENFILES, 0, 0);
379-
TCHAR toto[10];
380-
::MessageBox(nppData._nppHandle, generic_itoa(nbFile, toto, 10), TEXT("nb opened files"), MB_OK);
374+
int nbMainViewFile = (int)::SendMessage(nppData._nppHandle, NPPM_GETNBOPENFILES, 0, PRIMARY_VIEW);
375+
int nbSubViewFile = (int)::SendMessage(nppData._nppHandle, NPPM_GETNBOPENFILES, 0, SECOND_VIEW);
376+
int nbFile = nbMainViewFile + nbSubViewFile;
377+
wchar_t toto[10];
378+
::MessageBox(nppData._nppHandle, generic_itoa(nbFile, toto, 10), L"nb opened files", MB_OK);
381379

382-
TCHAR **fileNames = (TCHAR **)new TCHAR*[nbFile];
383-
for (int i = 0 ; i < nbFile ; i++)
380+
wchar_t **fileNames = (wchar_t **)new wchar_t*[nbFile];
381+
382+
int i = 0;
383+
for (; i < nbMainViewFile; )
384384
{
385-
fileNames[i] = new TCHAR[MAX_PATH];
385+
LRESULT bufferId = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, i, MAIN_VIEW);
386+
LRESULT len = ::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, bufferId, (WPARAM)nullptr);
387+
fileNames[i] = new wchar_t[len + 1];
388+
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, bufferId, (WPARAM)fileNames[i]);
389+
++i;
386390
}
387391

388-
if (::SendMessage(nppData._nppHandle, NPPM_GETOPENFILENAMES, (WPARAM)fileNames, (LPARAM)nbFile))
392+
393+
for (int j = 0; j < nbSubViewFile; ++j)
389394
{
390-
for (int i = 0 ; i < nbFile ; i++)
391-
::MessageBox(nppData._nppHandle, fileNames[i], TEXT(""), MB_OK);
395+
LRESULT bufferId = ::SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, j, SUB_VIEW);
396+
LRESULT len = ::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, bufferId, (WPARAM)nullptr);
397+
fileNames[i] = new wchar_t[len + 1];
398+
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, bufferId, (WPARAM)fileNames[i]);
399+
++i;
392400
}
393401

394-
for (int i = 0 ; i < nbFile ; i++)
402+
for (int k = 0 ; k < nbFile ; k++)
403+
::MessageBox(nppData._nppHandle, fileNames[k], L"", MB_OK);
404+
405+
for (int k = 0 ; k < nbFile ; k++)
395406
{
396-
delete [] fileNames[i];
407+
delete [] fileNames[k];
397408
}
398409
delete [] fileNames;
399410
}
400411

401412
void getSessionFileNamesDemo()
402413
{
403-
const TCHAR *sessionFullPath = TEXT("c:\\test.session");
414+
const wchar_t *sessionFullPath = L"c:\\test.session";
404415
int nbFile = (int)::SendMessage(nppData._nppHandle, NPPM_GETNBSESSIONFILES, 0, (LPARAM)sessionFullPath);
405416

406417
if (!nbFile)
407418
{
408-
::MessageBox(nppData._nppHandle, TEXT("Please modify \"sessionFullPath\" in \"NppInsertPlugin.cpp\" in order to point to a valide session file"), TEXT("Error :"), MB_OK);
419+
::MessageBox(nppData._nppHandle, L"Please modify \"sessionFullPath\" in \"NppInsertPlugin.cpp\" in order to point to a valide session file", L"Error :", MB_OK);
409420
return;
410421
}
411-
TCHAR toto[10];
412-
::MessageBox(nppData._nppHandle, generic_itoa(nbFile, toto, 10), TEXT("nb session files"), MB_OK);
422+
wchar_t toto[10];
423+
::MessageBox(nppData._nppHandle, generic_itoa(nbFile, toto, 10), L"nb session files", MB_OK);
413424

414-
TCHAR **fileNames = (TCHAR **)new TCHAR*[nbFile];
425+
wchar_t **fileNames = (wchar_t **)new wchar_t*[nbFile];
415426
for (int i = 0 ; i < nbFile ; i++)
416427
{
417-
fileNames[i] = new TCHAR[MAX_PATH];
428+
fileNames[i] = new wchar_t[MAX_PATH];
418429
}
419430

420431
if (::SendMessage(nppData._nppHandle, NPPM_GETSESSIONFILES, (WPARAM)fileNames, (LPARAM)sessionFullPath))
421432
{
422433
for (int i = 0 ; i < nbFile ; i++)
423-
::MessageBox(nppData._nppHandle, fileNames[i], TEXT("session file name :"), MB_OK);
434+
::MessageBox(nppData._nppHandle, fileNames[i], L"session file name :", MB_OK);
424435
}
425436

426437
for (int i = 0 ; i < nbFile ; i++)
@@ -432,9 +443,9 @@ void getSessionFileNamesDemo()
432443

433444
void saveCurrentSessionDemo()
434445
{
435-
TCHAR *sessionPath = (TCHAR *)::SendMessage(nppData._nppHandle, NPPM_SAVECURRENTSESSION, 0, 0);
446+
wchar_t *sessionPath = (wchar_t *)::SendMessage(nppData._nppHandle, NPPM_SAVECURRENTSESSION, 0, 0);
436447
if (sessionPath)
437-
::MessageBox(nppData._nppHandle, sessionPath, TEXT("Saved Session File :"), MB_OK);
448+
::MessageBox(nppData._nppHandle, sessionPath, L"Saved Session File :", MB_OK);
438449
}
439450

440451
// Dockable Dialog Demo
@@ -467,10 +478,10 @@ void DockableDlgDemo()
467478

468479
void goToPluginCommunicationGuide()
469480
{
470-
::ShellExecute(NULL, TEXT("open"), TEXT("https://npp-user-manual.org/docs/plugin-communication/"), NULL, NULL, SW_SHOWNORMAL);
481+
::ShellExecute(NULL, L"open", L"https://npp-user-manual.org/docs/plugin-communication/", NULL, NULL, SW_SHOWNORMAL);
471482
}
472483

473484
void goToPluginDemoRepo()
474485
{
475-
::ShellExecute(NULL, TEXT("open"), TEXT("https://github.com/npp-plugins/plugindemo"), NULL, NULL, SW_SHOWNORMAL);
486+
::ShellExecute(NULL, L"open", L"https://github.com/npp-plugins/plugindemo", NULL, NULL, SW_SHOWNORMAL);
476487
}

0 commit comments

Comments
 (0)