Applied coding style / cleanup

This commit is contained in:
Damien GERARD 2015-07-15 14:09:31 +02:00
parent 0cd514de13
commit 23cd144198
26 changed files with 898 additions and 744 deletions

View File

@ -44,12 +44,14 @@ void printInt(int int2print)
TCHAR str[32];
wsprintf(str, TEXT("%d"), int2print);
::MessageBox(NULL, str, TEXT(""), MB_OK);
};
}
void printStr(const TCHAR *str2print)
{
::MessageBox(NULL, str2print, TEXT(""), MB_OK);
};
}
std::string getFileContent(const TCHAR *file2read)
{
@ -59,7 +61,8 @@ std::string getFileContent(const TCHAR *file2read)
FILE *fp = generic_fopen(file2read, TEXT("rb"));
size_t lenFile = 0;
do {
do
{
lenFile = fread(data, 1, blockSize - 1, fp);
if (lenFile <= 0) break;
@ -69,8 +72,8 @@ std::string getFileContent(const TCHAR *file2read)
data[lenFile] = '\0';
wholeFileContent += data;
} while (lenFile > 0);
}
while (lenFile > 0);
fclose(fp);
return wholeFileContent;
@ -90,6 +93,7 @@ char getDriveLetter()
return drive;
}
generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath)
{
generic_string fullFilePathName = TEXT("");
@ -114,6 +118,7 @@ generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath)
return fullFilePathName;
}
void writeFileContent(const TCHAR *file2write, const char *content2write)
{
FILE *f = generic_fopen(file2write, TEXT("w+"));
@ -122,6 +127,7 @@ void writeFileContent(const TCHAR *file2write, const char *content2write)
fclose(f);
}
void writeLog(const TCHAR *logFileName, const char *log2write)
{
FILE *f = generic_fopen(logFileName, TEXT("a+"));
@ -131,6 +137,7 @@ void writeLog(const TCHAR *logFileName, const char *log2write)
fclose(f);
}
// Set a call back with the handle after init to set the path.
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/callbackfunctions/browsecallbackproc.asp
static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM pData)
@ -140,6 +147,7 @@ static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM pDa
return 0;
};
void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr)
{
// This code was copied and slightly modifed from:
@ -245,9 +253,11 @@ void ClientRectToScreenRect(HWND hWnd, RECT* rect)
::ClientToScreen( hWnd, &pt );
rect->right = pt.x;
rect->bottom = pt.y;
};
}
std::vector<generic_string> tokenizeString(const generic_string & tokenString, const char delim) {
std::vector<generic_string> tokenizeString(const generic_string & tokenString, const char delim)
{
//Vector is created on stack and copied on return
std::vector<generic_string> tokens;
@ -268,6 +278,7 @@ std::vector<generic_string> tokenizeString(const generic_string & tokenString, c
return tokens;
}
void ScreenRectToClientRect(HWND hWnd, RECT* rect)
{
POINT pt;
@ -283,7 +294,8 @@ void ScreenRectToClientRect(HWND hWnd, RECT* rect)
::ScreenToClient( hWnd, &pt );
rect->right = pt.x;
rect->bottom = pt.y;
};
}
int filter(unsigned int code, struct _EXCEPTION_POINTERS *)
{
@ -293,7 +305,9 @@ int filter(unsigned int code, struct _EXCEPTION_POINTERS *)
return EXCEPTION_CONTINUE_SEARCH;
}
bool isInList(const TCHAR *token, const TCHAR *list) {
bool isInList(const TCHAR *token, const TCHAR *list)
{
if ((!token) || (!list))
return false;
TCHAR word[64];
@ -347,7 +361,8 @@ generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand
}
cleanedName[j] = 0;
return cleanedName;
};
}
const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT codepage, int lenMbcs, int *pLenWc, int *pBytesNotProcessed)
{
@ -409,6 +424,7 @@ const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT c
return _wideCharStr;
}
// "mstart" and "mend" are pointers to indexes in mbcs2Convert,
// which are converted to the corresponding indexes in the returned wchar_t string.
const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT codepage, int *mstart, int *mend)
@ -442,6 +458,7 @@ const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT c
return _wideCharStr;
}
const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UINT codepage, int lenWc, int *pLenMbcs)
{
// Do not process NULL pointer
@ -456,10 +473,12 @@ const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UI
else
_multiByteStr.empty();
if(pLenMbcs) *pLenMbcs = lenMbcs;
if (pLenMbcs)
*pLenMbcs = lenMbcs;
return _multiByteStr;
}
const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UINT codepage, long *mstart, long *mend)
{
// Do not process NULL pointer
@ -488,6 +507,7 @@ const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UI
return _multiByteStr;
}
std::wstring string2wstring(const std::string & rString, UINT codepage)
{
int len = MultiByteToWideChar(codepage, 0, rString.c_str(), -1, NULL, 0);
@ -614,6 +634,7 @@ generic_string BuildMenuFileName(int filenameLen, unsigned int pos, const generi
return strTemp;
}
generic_string PathRemoveFileSpec(generic_string & path)
{
generic_string::size_type lastBackslash = path.find_last_of(TEXT('\\'));
@ -636,6 +657,7 @@ generic_string PathRemoveFileSpec(generic_string & path)
return path;
}
generic_string PathAppend(generic_string &strDest, const generic_string & str2append)
{
if (strDest == TEXT("") && str2append == TEXT("")) // "" + ""
@ -671,6 +693,7 @@ generic_string PathAppend(generic_string &strDest, const generic_string & str2ap
return strDest;
}
COLORREF getCtrlBgColor(HWND hWnd)
{
COLORREF crRet = CLR_INVALID;
@ -709,12 +732,14 @@ COLORREF getCtrlBgColor(HWND hWnd)
return crRet;
}
generic_string stringToUpper(generic_string strToConvert)
{
std::transform(strToConvert.begin(), strToConvert.end(), strToConvert.begin(), ::toupper);
return strToConvert;
}
generic_string stringReplace(generic_string subject, const generic_string& search, const generic_string& replace)
{
size_t pos = 0;
@ -726,6 +751,7 @@ generic_string stringReplace(generic_string subject, const generic_string& searc
return subject;
}
std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter)
{
auto start = 0U;
@ -742,6 +768,7 @@ std::vector<generic_string> stringSplit(const generic_string& input, const gener
return output;
}
generic_string stringJoin(const std::vector<generic_string>& strings, const generic_string& separator)
{
generic_string joined;
@ -757,6 +784,7 @@ generic_string stringJoin(const std::vector<generic_string>& strings, const gene
return joined;
}
generic_string stringTakeWhileAdmissable(const generic_string& input, const generic_string& admissable)
{
// Find first non-admissable character in "input", and remove everything after it.
@ -771,6 +799,7 @@ generic_string stringTakeWhileAdmissable(const generic_string& input, const gene
}
}
double stodLocale(const generic_string& str, _locale_t loc, size_t* idx)
{
// Copied from the std::stod implementation but uses _wcstod_l instead of wcstod.
@ -833,3 +862,6 @@ bool str2Clipboard(const generic_string &str2cpy, HWND hwnd)
}
return true;
}

View File

@ -134,19 +134,20 @@ public:
};
protected:
WcharMbcsConvertor() {
};
~WcharMbcsConvertor() {
};
WcharMbcsConvertor() {}
~WcharMbcsConvertor() {}
static WcharMbcsConvertor * _pSelf;
template <class T>
class StringBuffer {
class StringBuffer
{
public:
StringBuffer() : _str(0), _allocLen(0) { }
~StringBuffer() { if(_allocLen) delete [] _str; }
void sizeTo(size_t size) {
void sizeTo(size_t size)
{
if(_allocLen < size)
{
if(_allocLen) delete[] _str;
@ -154,7 +155,8 @@ protected:
_str = new T[_allocLen];
}
}
void empty() {
void empty()
{
static T nullStr = 0; // routines may return an empty string, with null terminator, without allocating memory; a pointer to this null character will be returned in that case
if(_allocLen == 0)
_str = &nullStr;
@ -176,9 +178,10 @@ protected:
private:
// Since there's no public ctor, we need to void the default assignment operator.
WcharMbcsConvertor& operator= (const WcharMbcsConvertor&);
};
#define MACRO_RECORDING_IN_PROGRESS 1
#define MACRO_RECORDING_HAS_STOPPED 2

View File

@ -35,11 +35,13 @@
#include "Win32Exception.h"
Win32Exception::Win32Exception(EXCEPTION_POINTERS * info) {
Win32Exception::Win32Exception(EXCEPTION_POINTERS * info)
{
_location = info->ExceptionRecord->ExceptionAddress;
_code = info->ExceptionRecord->ExceptionCode;
_info = info;
switch (_code) {
switch (_code)
{
case EXCEPTION_ACCESS_VIOLATION:
_event = "Access violation";
break;
@ -52,17 +54,21 @@ Win32Exception::Win32Exception(EXCEPTION_POINTERS * info) {
}
}
void Win32Exception::installHandler() {
void Win32Exception::installHandler()
{
_set_se_translator(Win32Exception::translate);
}
void Win32Exception::removeHandler() {
void Win32Exception::removeHandler()
{
_set_se_translator(NULL);
}
void Win32Exception::translate(unsigned code, EXCEPTION_POINTERS * info) {
void Win32Exception::translate(unsigned code, EXCEPTION_POINTERS * info)
{
// Windows guarantees that *(info->ExceptionRecord) is valid
switch (code) {
switch (code)
{
case EXCEPTION_ACCESS_VIOLATION:
throw Win32AccessViolation(info);
break;
@ -71,7 +77,12 @@ void Win32Exception::translate(unsigned code, EXCEPTION_POINTERS * info) {
}
}
Win32AccessViolation::Win32AccessViolation(EXCEPTION_POINTERS * info) : Win32Exception(info) {
Win32AccessViolation::Win32AccessViolation(EXCEPTION_POINTERS * info)
: Win32Exception(info)
{
_isWrite = info->ExceptionRecord->ExceptionInformation[0] == 1;
_badAddress = reinterpret_cast<ExceptionAddress>(info->ExceptionRecord->ExceptionInformation[1]);
}

View File

@ -44,10 +44,10 @@ class Win32Exception : public std::exception
public:
static void installHandler();
static void removeHandler();
virtual const char* what() const throw() { return _event; };
ExceptionAddress where() const { return _location; };
unsigned int code() const { return _code; };
EXCEPTION_POINTERS* info() const { return _info; };
virtual const char* what() const throw() { return _event; }
ExceptionAddress where() const { return _location; }
unsigned int code() const { return _code; }
EXCEPTION_POINTERS* info() const { return _info; }
protected:
Win32Exception(EXCEPTION_POINTERS * info); //Constructor only accessible by exception handler
@ -61,11 +61,12 @@ private:
EXCEPTION_POINTERS * _info;
};
class Win32AccessViolation: public Win32Exception
{
public:
bool isWrite() const { return _isWrite; };
ExceptionAddress badAddress() const { return _badAddress; };
bool isWrite() const { return _isWrite; }
ExceptionAddress badAddress() const { return _badAddress; }
private:
Win32AccessViolation(EXCEPTION_POINTERS * info);

View File

@ -31,10 +31,13 @@
typedef std::vector<generic_string> stringVector;
class FileNameStringSplitter
{
public:
FileNameStringSplitter(const TCHAR *fileNameStr) {
FileNameStringSplitter(const TCHAR *fileNameStr)
{
//if (!fileNameStr) return;
TCHAR *pStr = NULL;
bool isInsideQuotes = false;
@ -43,6 +46,7 @@ public :
TCHAR str[filePathLength];
int i = 0;
bool fini = false;
for (pStr = (TCHAR *)fileNameStr ; !fini ; )
{
if (i >= filePathLength)
@ -51,6 +55,7 @@ public :
switch (*pStr)
{
case '"':
{
if (isInsideQuotes)
{
str[i] = '\0';
@ -61,8 +66,10 @@ public :
isInsideQuotes = !isInsideQuotes;
pStr++;
break;
}
case ' ':
{
if (isInsideQuotes)
{
str[i] = *pStr;
@ -77,34 +84,41 @@ public :
}
pStr++;
break;
}
case '\0':
{
str[i] = *pStr;
if (str[0])
_fileNames.push_back(generic_string(str));
fini = true;
break;
}
default :
{
str[i] = *pStr;
i++; pStr++;
break;
}
}
};
}
}
const TCHAR * getFileName(size_t index) const {
if (index >= _fileNames.size())
return NULL;
return _fileNames[index].c_str();
};
}
int size() const {
return int(_fileNames.size());
};
}
private :
stringVector _fileNames;
};
#endif //FILENAME_STRING_SPLITTER_H

View File

@ -41,7 +41,8 @@ const int nbChar = 64;
typedef const TCHAR * (__cdecl * PFUNCGETNAME)();
struct NppData {
struct NppData
{
HWND _nppHandle;
HWND _scintillaMainHandle;
HWND _scintillaSecondHandle;
@ -53,14 +54,16 @@ typedef void (__cdecl * PBENOTIFIED)(SCNotification *);
typedef LRESULT (__cdecl * PMESSAGEPROC)(UINT Message, WPARAM wParam, LPARAM lParam);
struct ShortcutKey {
struct ShortcutKey
{
bool _isCtrl;
bool _isAlt;
bool _isShift;
UCHAR _key;
};
struct FuncItem {
struct FuncItem
{
TCHAR _itemName[nbChar];
PFUNCPLUGINCMD _pFunc;
int _cmdID;

View File

@ -35,6 +35,10 @@ using namespace std;
const TCHAR * USERMSG = TEXT("This plugin is not compatible with current version of Notepad++.\n\n\
Do you want to remove this plugin from plugins directory to prevent this message from the next launch time?");
bool PluginsManager::unloadPlugin(int index, HWND nppHandle)
{
SCNotification scnN;
@ -58,6 +62,7 @@ bool PluginsManager::unloadPlugin(int index, HWND nppHandle)
return true;
}
int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_string> & dll2Remove)
{
const TCHAR *pluginFileName = ::PathFindFileName(pluginFilePath);
@ -65,7 +70,8 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin
return 0;
PluginInfo *pi = new PluginInfo;
try {
try
{
pi->_moduleName = PathFindFileName(pluginFilePath);
pi->_hLib = ::LoadLibrary(pluginFilePath);
@ -175,8 +181,10 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin
}
for (int x = 0; x < numLexers; ++x) // postpone adding in case the xml is missing/corrupt
{
if (containers[x] != NULL)
nppParams->addExternalLangToEnd(containers[x]);
}
nppParams->getExternalLexerFromXmlTree(pXmlDoc);
nppParams->getExternalLexerDoc()->push_back(pXmlDoc);
@ -187,10 +195,14 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin
addInLoadedDlls(pluginFileName);
_pluginInfos.push_back(pi);
return (_pluginInfos.size() - 1);
} catch(std::exception e) {
}
catch (std::exception e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
return -1;
} catch(generic_string s) {
}
catch (generic_string s)
{
s += TEXT("\n\n");
s += USERMSG;
if (::MessageBox(NULL, s.c_str(), pluginFilePath, MB_YESNO) == IDYES)
@ -199,7 +211,9 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector<generic_strin
}
delete pi;
return -1;
} catch(...) {
}
catch (...)
{
generic_string msg = TEXT("Failed to load");
msg += TEXT("\n\n");
msg += USERMSG;
@ -366,11 +380,16 @@ void PluginsManager::runPluginCommand(size_t i)
{
if (_pluginsCommands[i]._pFunc != NULL)
{
try {
try
{
_pluginsCommands[i]._pFunc();
} catch(std::exception e) {
}
catch (std::exception e)
{
::MessageBoxA(NULL, e.what(), "PluginsManager::runPluginCommand Exception", MB_OK);
} catch (...) {
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("runPluginCommand(size_t i : %d)"), i);
pluginCrashAlert(_pluginsCommands[i]._pluginName.c_str(), funcInfo);
@ -388,11 +407,16 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
{
if (_pluginsCommands[i]._funcID == commandID)
{
try {
try
{
_pluginsCommands[i]._pFunc();
} catch(std::exception e) {
}
catch (std::exception e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
} catch (...) {
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("runPluginCommand(const TCHAR *pluginName : %s, int commandID : %d)"), pluginName, commandID);
pluginCrashAlert(_pluginsCommands[i]._pluginName.c_str(), funcInfo);
@ -402,6 +426,7 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
}
}
void PluginsManager::notify(const SCNotification *notification)
{
for (size_t i = 0, len = _pluginInfos.size() ; i < len ; ++i)
@ -411,11 +436,16 @@ void PluginsManager::notify(const SCNotification *notification)
// To avoid the plugin change the data in SCNotification
// Each notification to pass to a plugin is a copy of SCNotification instance
SCNotification scNotif = *notification;
try {
try
{
_pluginInfos[i]->_pBeNotified(&scNotif);
} catch(std::exception e) {
}
catch (std::exception e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
} catch (...) {
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("notify(SCNotification *notification) : \r notification->nmhdr.code == %d\r notification->nmhdr.hwndFrom == %p\r notification->nmhdr.idFrom == %d"),\
scNotif.nmhdr.code, scNotif.nmhdr.hwndFrom, scNotif.nmhdr.idFrom);
@ -425,17 +455,23 @@ void PluginsManager::notify(const SCNotification *notification)
}
}
void PluginsManager::relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam)
{
for (size_t i = 0, len = _pluginInfos.size(); i < len ; ++i)
{
if (_pluginInfos[i]->_hLib)
{
try {
try
{
_pluginInfos[i]->_pMessageProc(Message, wParam, lParam);
} catch(std::exception e) {
}
catch (std::exception e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
} catch (...) {
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("relayNppMessages(UINT Message : %d, WPARAM wParam : %d, LPARAM lParam : %d)"), Message, wParam, lParam);
pluginCrashAlert(_pluginsCommands[i]._pluginName.c_str(), TEXT(""));
@ -444,6 +480,7 @@ void PluginsManager::relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam
}
}
bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam)
{
const TCHAR * moduleName = (const TCHAR *)wParam;
@ -456,11 +493,16 @@ bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lPa
{
if (_pluginInfos[i]->_hLib)
{
try {
try
{
_pluginInfos[i]->_pMessageProc(Message, wParam, lParam);
} catch(std::exception e) {
}
catch (std::exception e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
} catch (...) {
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("relayPluginMessages(UINT Message : %d, WPARAM wParam : %d, LPARAM lParam : %d)"), Message, wParam, lParam);
pluginCrashAlert(_pluginsCommands[i]._pluginName.c_str(), funcInfo);
@ -498,3 +540,4 @@ bool PluginsManager::allocateMarker(int numberRequired, int *start)
}
return retVal;
}

View File

@ -47,24 +47,27 @@
typedef BOOL (__cdecl * PFUNCISUNICODE)();
struct PluginCommand {
struct PluginCommand
{
generic_string _pluginName;
int _funcID;
PFUNCPLUGINCMD _pFunc;
PluginCommand(const TCHAR *pluginName, int funcID, PFUNCPLUGINCMD pFunc): _funcID(funcID), _pFunc(pFunc), _pluginName(pluginName){};
};
struct PluginInfo {
struct PluginInfo
{
PluginInfo() :_hLib(NULL), _pluginMenu(NULL), _pFuncSetInfo(NULL),\
_pFuncGetFuncsArray(NULL), _pFuncGetName(NULL), _funcItems(NULL),\
_nbFuncItem(0){};
~PluginInfo(){
_nbFuncItem(0){}
~PluginInfo()
{
if (_pluginMenu)
::DestroyMenu(_pluginMenu);
if (_hLib)
::FreeLibrary(_hLib);
};
}
HINSTANCE _hLib;
HMENU _pluginMenu;
@ -81,21 +84,24 @@ struct PluginInfo {
generic_string _moduleName;
};
class PluginsManager {
class PluginsManager
{
public:
PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false), _dynamicIDAlloc(ID_PLUGINS_CMD_DYNAMIC, ID_PLUGINS_CMD_DYNAMIC_LIMIT),
_markerAlloc(MARKER_PLUGINS, MARKER_PLUGINS_LIMIT) {};
~PluginsManager() {
_markerAlloc(MARKER_PLUGINS, MARKER_PLUGINS_LIMIT) {}
~PluginsManager()
{
for (size_t i = 0, len = _pluginInfos.size(); i < len; ++i)
delete _pluginInfos[i];
if (_hPluginsMenu)
DestroyMenu(_hPluginsMenu);
};
void init(const NppData & nppData) {
}
void init(const NppData & nppData)
{
_nppData = nppData;
};
}
int loadPlugin(const TCHAR *pluginFilePath, std::vector<generic_string> & dll2Remove);
bool loadPlugins(const TCHAR *dir = NULL);
@ -113,12 +119,10 @@ public:
void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam);
bool relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam);
HMENU getMenuHandle() {
return _hPluginsMenu;
};
HMENU getMenuHandle() const { return _hPluginsMenu; }
void disable() {_isDisabled = true;};
bool hasPlugins(){return (_pluginInfos.size()!= 0);};
void disable() {_isDisabled = true;}
bool hasPlugins() {return (_pluginInfos.size()!= 0);}
bool allocateCmdID(int numberRequired, int *start);
bool inDynamicRange(int id) { return _dynamicIDAlloc.isInRange(id); }
@ -135,22 +139,26 @@ private:
bool _isDisabled;
IDAllocator _dynamicIDAlloc;
IDAllocator _markerAlloc;
void pluginCrashAlert(const TCHAR *pluginName, const TCHAR *funcSignature) {
void pluginCrashAlert(const TCHAR *pluginName, const TCHAR *funcSignature)
{
generic_string msg = pluginName;
msg += TEXT(" just crash in\r");
msg += funcSignature;
::MessageBox(NULL, msg.c_str(), TEXT(" just crash in\r"), MB_OK|MB_ICONSTOP);
};
bool isInLoadedDlls(const TCHAR *fn) const {
}
bool isInLoadedDlls(const TCHAR *fn) const
{
for (size_t i = 0; i < _loadedDlls.size(); ++i)
if (generic_stricmp(fn, _loadedDlls[i].c_str()) == 0)
return true;
return false;
};
}
void addInLoadedDlls(const TCHAR *fn) {
_loadedDlls.push_back(fn);
};
}
};
#define EXT_LEXER_DECL __stdcall

View File

@ -35,7 +35,7 @@ class Process
{
public:
Process(const TCHAR *cmd, const TCHAR *args, const TCHAR *cDir)
:_command(cmd), _args(args), _curDir(cDir){};
:_command(cmd), _args(args), _curDir(cDir){}
void run();

View File

@ -30,6 +30,9 @@
#include "process.h"
//#include "SysMsg.h"
BOOL Process::run()
{
BOOL result = TRUE;
@ -47,7 +50,8 @@ BOOL Process::run()
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; // inheritable handle
try {
try
{
// Create stdout pipe
if (!::CreatePipe(&_hPipeOutR, &hPipeOutW, &sa, 0))
error(TEXT("CreatePipe"), result, 1000);
@ -101,7 +105,9 @@ BOOL Process::run()
::WaitForSingleObject(_hProcess, INFINITE);
::WaitForMultipleObjects(2, hListenerEvent, TRUE, INFINITE);
} catch (int /*coderr*/){}
}
catch (int /*coderr*/)
{}
// on va fermer toutes les handles
if (hPipeOutW)
@ -250,9 +256,11 @@ void Process::listenerStdErr()
}
}
void Process::error(const TCHAR *txt2display, BOOL & returnCode, int errCode)
{
systemMessage(txt2display);
returnCode = FALSE;
throw int(errCode);
}

View File

@ -36,36 +36,36 @@ using namespace std;
class Process
{
public:
Process() {};
Process() {}
Process(const TCHAR *cmd, const TCHAR *cDir)
: _stdoutStr(TEXT("")), _stderrStr(TEXT("")), _hPipeOutR(NULL),
_hPipeErrR(NULL), _hProcess(NULL), _hProcessThread(NULL) {
_hPipeErrR(NULL), _hProcess(NULL), _hProcessThread(NULL)
{
lstrcpy(_command, cmd);
lstrcpy(_curDir, cDir);
};
}
BOOL run();
const TCHAR * getStdout() const {
return _stdoutStr.c_str();
};
}
const TCHAR * getStderr() const {
return _stderrStr.c_str();
};
}
int getExitCode() const {
return _exitCode;
};
}
bool hasStdout() {
return (_stdoutStr.compare(TEXT("")) != 0);
};
}
bool hasStderr() {
return (_stderrStr.compare(TEXT("")) != 0);
};
}
protected:
// LES ENTREES

View File

@ -34,13 +34,16 @@
class ProcessThread
{
public:
ProcessThread(const TCHAR *appName, const TCHAR *cmd, const TCHAR *cDir, HWND hwnd) : _hwnd(hwnd) {
ProcessThread(const TCHAR *appName, const TCHAR *cmd, const TCHAR *cDir, HWND hwnd)
: _hwnd(hwnd)
{
lstrcpy(_appName, appName);
lstrcpy(_command, cmd);
lstrcpy(_curDir, cDir);
};
}
BOOL run(){
BOOL run()
{
HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, TEXT("localVarProcessEvent"));
_hProcessThread = ::CreateThread(NULL, 0, staticLauncher, this, 0, NULL);
@ -49,7 +52,8 @@ public :
::CloseHandle(hEvent);
return TRUE;
};
}
protected:
// ENTREES
@ -59,12 +63,14 @@ protected :
HWND _hwnd;
HANDLE _hProcessThread;
static DWORD WINAPI staticLauncher(void *myself) {
static DWORD WINAPI staticLauncher(void *myself)
{
((ProcessThread *)myself)->launch();
return TRUE;
};
}
bool launch() {
bool launch()
{
HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("localVarProcessEvent"));
HWND hwnd = _hwnd;
TCHAR appName[256];
@ -74,9 +80,7 @@ protected :
Process process(_command, _curDir);
if (!::SetEvent(hEvent))
{
systemMessage(TEXT("Thread launcher"));
}
process.run();
@ -90,7 +94,7 @@ protected :
::CloseHandle(hMyself);
return true;
};
}
};
#endif PROCESS_THREAD_H

View File

@ -24,11 +24,12 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "Common.h"
#include "regExtDlg.h"
#include "resource.h"
const TCHAR* nppName = TEXT("Notepad++_file");
const TCHAR* nppBackup = TEXT("Notepad++_backup");
const TCHAR* nppDoc = TEXT("Notepad++ Document");
@ -84,14 +85,15 @@ void RegExtDlg::doDialog(bool isRTL)
{
if (isRTL)
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
DLGTEMPLATE *pMyDlgTemplate = nullptr;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_REGEXT_BOX, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, (LPARAM)this);
::GlobalFree(hMyDlgTemplate);
}
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, dlgProc, (LPARAM)this);
};
}
INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
@ -105,7 +107,6 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false);
::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false);
::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETLIMITTEXT, extNameMax-1, 0);
return TRUE;
}
@ -173,9 +174,10 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
}
case IDCANCEL:
{
::EndDialog(_hSelf, 0);
return TRUE;
}
}
if (HIWORD(wParam) == EN_CHANGE)
@ -224,6 +226,7 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, count, 0);
for (int j = 1 ; j < nbExtMax ; ++j)
{
if (lstrcmp(TEXT(""), defExtArray[i][j]))
{
int index = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, (LPARAM)defExtArray[i][j]);
@ -231,31 +234,33 @@ INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, (LPARAM)defExtArray[i][j]);
}
}
}
::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false);
}
}
else if (LOWORD(wParam) == IDC_REGEXT_LANGEXT_LIST)
{
if (i != LB_ERR)
::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), true);
}
else if (LOWORD(wParam) == IDC_REGEXT_REGISTEREDEXTS_LIST)
{
if (i != LB_ERR)
::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), true);
}
}
// break; // no break here
}
default :
return FALSE;
}
//return FALSE;
}
void RegExtDlg::getRegisteredExts()
{
int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT);
@ -264,7 +269,7 @@ void RegExtDlg::getRegisteredExts()
TCHAR extName[extNameLen];
//FILETIME fileTime;
int extNameActualLen = extNameLen;
int res = ::RegEnumKeyEx(HKEY_CLASSES_ROOT, i, extName, (LPDWORD)&extNameActualLen, NULL, NULL, NULL, NULL);
int res = ::RegEnumKeyEx(HKEY_CLASSES_ROOT, i, extName, (LPDWORD)&extNameActualLen, nullptr, nullptr, nullptr, nullptr);
if ((res == ERROR_SUCCESS) && (extName[0] == '.'))
{
//TCHAR valName[extNameLen];
@ -274,8 +279,8 @@ void RegExtDlg::getRegisteredExts()
HKEY hKey2Check;
extNameActualLen = extNameLen;
::RegOpenKeyEx(HKEY_CLASSES_ROOT, extName, 0, KEY_ALL_ACCESS, &hKey2Check);
::RegQueryValueEx(hKey2Check, TEXT(""), NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen);
//::RegEnumValue(hKey2Check, 0, valName, (LPDWORD)&extNameActualLen, NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen);
::RegQueryValueEx(hKey2Check, TEXT(""), nullptr, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen);
//::RegEnumValue(hKey2Check, 0, valName, (LPDWORD)&extNameActualLen, nullptr, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen);
if ((valType == REG_SZ) && (!lstrcmp(valData, nppName)))
::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_ADDSTRING, 0, (LPARAM)extName);
::RegCloseKey(hKey2Check);
@ -283,6 +288,7 @@ void RegExtDlg::getRegisteredExts()
}
}
void RegExtDlg::getDefSupportedExts()
{
for (int i = 0 ; i < nbSupportedLang ; ++i)
@ -296,15 +302,7 @@ void RegExtDlg::addExt(TCHAR *ext)
DWORD dwDisp;
long nRet;
nRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT,
ext,
0,
NULL,
0,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisp);
nRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, ext, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisp);
if (nRet == ERROR_SUCCESS)
{
@ -313,16 +311,17 @@ void RegExtDlg::addExt(TCHAR *ext)
if (dwDisp == REG_OPENED_EXISTING_KEY)
{
int res = ::RegQueryValueEx(hKey, TEXT(""), NULL, NULL, (LPBYTE)valData, (LPDWORD)&valDataLen);
int res = ::RegQueryValueEx(hKey, TEXT(""), nullptr, nullptr, (LPBYTE)valData, (LPDWORD)&valDataLen);
if (res == ERROR_SUCCESS)
::RegSetValueEx(hKey, nppBackup, 0, REG_SZ, (LPBYTE)valData, valDataLen);
}
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppName, (lstrlen(nppName)+1)*sizeof(TCHAR));
::RegSetValueEx(hKey, nullptr, 0, REG_SZ, (LPBYTE)nppName, (lstrlen(nppName)+1)*sizeof(TCHAR));
::RegCloseKey(hKey);
}
}
bool RegExtDlg::deleteExts(const TCHAR *ext2Delete)
{
HKEY hKey;
@ -342,20 +341,21 @@ bool RegExtDlg::deleteExts(const TCHAR *ext2Delete)
TCHAR valData[extNameLen];
int valDataLen = extNameLen*sizeof(TCHAR);
int valType;
int res = ::RegQueryValueEx(hKey, nppBackup, NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen);
int res = ::RegQueryValueEx(hKey, nppBackup, nullptr, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen);
if (res == ERROR_SUCCESS)
{
::RegSetValueEx(hKey, NULL, 0, valType, (LPBYTE)valData, valDataLen);
::RegSetValueEx(hKey, nullptr, 0, valType, (LPBYTE)valData, valDataLen);
::RegDeleteValue(hKey, nppBackup);
}
else
::RegDeleteValue(hKey, NULL);
::RegDeleteValue(hKey, nullptr);
}
return true;
}
void RegExtDlg::writeNppPath()
{
HKEY hKey, hRootKey;
@ -364,16 +364,7 @@ void RegExtDlg::writeNppPath()
generic_string regStr(nppName);
regStr += TEXT("\\shell\\open\\command");
nRet = ::RegCreateKeyEx(
HKEY_CLASSES_ROOT,
regStr.c_str(),
0,
NULL,
0,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisp);
nRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, regStr.c_str(), 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisp);
if (nRet == ERROR_SUCCESS)
@ -382,7 +373,7 @@ void RegExtDlg::writeNppPath()
{
// Write the value for new document
::RegOpenKeyEx(HKEY_CLASSES_ROOT, nppName, 0, KEY_ALL_ACCESS, &hRootKey);
::RegSetValueEx(hRootKey, NULL, 0, REG_SZ, (LPBYTE)nppDoc, (lstrlen(nppDoc)+1)*sizeof(TCHAR));
::RegSetValueEx(hRootKey, nullptr, 0, REG_SZ, (LPBYTE)nppDoc, (lstrlen(nppDoc)+1)*sizeof(TCHAR));
RegCloseKey(hRootKey);
TCHAR nppPath[MAX_PATH];
@ -391,7 +382,7 @@ void RegExtDlg::writeNppPath()
TCHAR nppPathParam[MAX_PATH] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\" \"%1\""));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
::RegSetValueEx(hKey, nullptr, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
}
RegCloseKey(hKey);
}
@ -399,16 +390,7 @@ void RegExtDlg::writeNppPath()
//Set default icon value
regStr = nppName;
regStr += TEXT("\\DefaultIcon");
nRet = ::RegCreateKeyEx(
HKEY_CLASSES_ROOT,
regStr.c_str(),
0,
NULL,
0,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisp);
nRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, regStr.c_str(), 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisp);
if (nRet == ERROR_SUCCESS)
{
@ -420,8 +402,10 @@ void RegExtDlg::writeNppPath()
TCHAR nppPathParam[MAX_PATH] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0"));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
::RegSetValueEx(hKey, nullptr, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
}
RegCloseKey(hKey);
}
}

View File

@ -57,13 +57,13 @@ private :
int nbSubKey;
long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, (LPDWORD)&nbSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
return (result == ERROR_SUCCESS)?nbSubKey:0;
};
}
int getNbSubValue(HKEY hKey) const {
int nbSubValue;
long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, (LPDWORD)&nbSubValue, NULL, NULL, NULL, NULL);
return (result == ERROR_SUCCESS)?nbSubValue:0;
};
}
};
#endif //REG_EXT_DLG_H

View File

@ -119,10 +119,13 @@ ToolBarButtonUnit toolBarIcons[] = {
{IDM_MACRO_PLAYBACKRECORDEDMACRO, IDI_PLAYRECORD_OFF_ICON, IDI_PLAYRECORD_ON_ICON, IDI_PLAYRECORD_DISABLE_ICON, IDR_PLAYRECORD},
{IDM_MACRO_RUNMULTIMACRODLG, IDI_MMPLAY_OFF_ICON, IDI_MMPLAY_ON_ICON, IDI_MMPLAY_DIS_ICON, IDR_M_PLAYRECORD},
{IDM_MACRO_SAVECURRENTMACRO, IDI_SAVERECORD_OFF_ICON, IDI_SAVERECORD_ON_ICON, IDI_SAVERECORD_DISABLE_ICON, IDR_SAVERECORD}
};
Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(NULL),
_pMainSplitter(NULL),
_recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _pFileSwitcherPanel(NULL),
@ -175,48 +178,28 @@ Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(N
_isAdministrator = is_admin ? true : false;
}
Notepad_plus::~Notepad_plus()
{
// ATTENTION : the order of the destruction is very important
// because if the parent's window handle is destroyed before
// the destruction of its children windows' handles,
// its children windows' handles will be destroyed automatically!
Notepad_plus::~Notepad_plus()
{
(NppParameters::getInstance())->destroyInstance();
MainFileManager->destroyInstance();
(WcharMbcsConvertor::getInstance())->destroyInstance();
if (_pTrayIco)
delete _pTrayIco;
if (_pAnsiCharPanel)
delete _pAnsiCharPanel;
if (_pClipboardHistoryPanel)
delete _pClipboardHistoryPanel;
if (_pFileSwitcherPanel)
delete _pFileSwitcherPanel;
if (_pProjectPanel_1)
{
delete _pProjectPanel_1;
}
if (_pProjectPanel_2)
{
delete _pProjectPanel_2;
}
if (_pProjectPanel_3)
{
delete _pProjectPanel_3;
}
if (_pDocMap)
{
delete _pDocMap;
}
if (_pFuncList)
{
delete _pFuncList;
}
}
@ -451,6 +434,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
::InsertMenu(hMacroMenu, posBase + nbMacro + 1, MF_BYPOSITION, (unsigned int)-1, 0);
::InsertMenu(hMacroMenu, posBase + nbMacro + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_MACRO, TEXT("Modify Shortcut/Delete Macro..."));
}
// Run Menu
std::vector<UserCommand> & userCommands = pNppParam->getUserCommandList();
HMENU hRunMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_RUN);
@ -458,6 +442,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
size_t nbUserCommand = userCommands.size();
if (nbUserCommand >= 1)
::InsertMenu(hRunMenu, runPosBase - 1, MF_BYPOSITION, (unsigned int)-1, 0);
for (size_t i = 0 ; i < nbUserCommand ; ++i)
{
::InsertMenu(hRunMenu, runPosBase + i, MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str());
@ -5226,6 +5211,7 @@ bool Notepad_plus::reloadLang()
return true;
}
void Notepad_plus::launchClipboardHistoryPanel()
{
if (!_pClipboardHistoryPanel)
@ -5267,6 +5253,7 @@ void Notepad_plus::launchClipboardHistoryPanel()
_pClipboardHistoryPanel->display();
}
void Notepad_plus::launchFileSwitcherPanel()
{
if (!_pFileSwitcherPanel)
@ -5308,12 +5295,12 @@ void Notepad_plus::launchFileSwitcherPanel()
_pFileSwitcherPanel->display();
}
void Notepad_plus::launchAnsiCharPanel()
{
if (!_pAnsiCharPanel)
{
_pAnsiCharPanel = new AnsiCharPanel();
_pAnsiCharPanel->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), &_pEditView);
tTbData data = {0};
@ -5350,6 +5337,7 @@ void Notepad_plus::launchAnsiCharPanel()
_pAnsiCharPanel->display();
}
void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID)
{
if (!(*pProjPanel))
@ -5396,6 +5384,7 @@ void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int
(*pProjPanel)->display();
}
void Notepad_plus::launchDocMap()
{
if (!(NppParameters::getInstance())->isTransparentAvailable())
@ -5441,6 +5430,7 @@ void Notepad_plus::launchDocMap()
_pEditView->getFocus();
}
void Notepad_plus::launchFunctionList()
{
if (!_pFuncList)
@ -5486,7 +5476,13 @@ void Notepad_plus::launchFunctionList()
_pEditView->getFocus();
}
struct TextPlayerParams {
struct TextPlayerParams
{
HWND _nppHandle;
ScintillaEditView *_pCurrentView;
const char *_text2display;
@ -5494,20 +5490,26 @@ struct TextPlayerParams {
bool _shouldBeTrolling;
};
struct TextTrollerParams {
struct TextTrollerParams
{
ScintillaEditView *_pCurrentView;
const char *_text2display;
BufferID _targetBufID;
HANDLE _mutex;
};
struct Quote{
struct Quote
{
const char *_quoter;
const char *_quote;
};
const int nbQuote = 203;
Quote quotes[nbQuote] = {
Quote quotes[nbQuote] =
{
{"Notepad++", "Good programmers use Notepad++ to code.\nExtreme programmers use MS Word to code, in Comic Sans, center aligned."},
{"Martin Golding", "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."},
{"L. Peter Deutsch", "To iterate is human, to recurse divine."},
@ -5720,7 +5722,8 @@ Quote quotes[nbQuote] = {
const int nbWtf = 6;
char *wtf[nbWtf] = {
char* wtf[nbWtf] =
{
"WTF?!",
"lol",
"FAP FAP FAP",
@ -5740,11 +5743,13 @@ const int nbAct = 30;
int actionArray[nbAct] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0};
const int maxRange = 200;
int Notepad_plus::getRandomAction(int ranNum)
{
return actionArray[ranNum % nbAct];
}
bool isInList(int elem, vector<int> elemList)
{
for (size_t i = 0, len = elemList.size(); i < len; ++i)
@ -5755,6 +5760,7 @@ bool isInList(int elem, vector<int> elemList)
return false;
}
DWORD WINAPI Notepad_plus::threadTextPlayer(void *params)
{
// random seed generation needs only one time.
@ -5781,10 +5787,10 @@ DWORD WINAPI Notepad_plus::threadTextPlayer(void *params)
int nbTrolling = 0;
vector<int> generatedRans;
char previousChar = '\0';
for (size_t i = 0, len = strlen(text2display); i < len ; ++i)
{
int ranNum = getRandomNumber(maxRange);
int action = act_doNothing;
if (shouldBeTrolling && (i > 20 && previousChar == ' ') && nbTrolling < nbMaxTrolling)
@ -5836,6 +5842,7 @@ DWORD WINAPI Notepad_plus::threadTextPlayer(void *params)
//sprintf(ch, "writting char == %c", text2display[i]);
//writeLog(TEXT("c:\\tmp\\log.txt"), ch);
}
//writeLog(TEXT("c:\\tmp\\log.txt"), "\n\n\n\n");
const char * quoter = ((TextPlayerParams *)params)->_quoter;
string quoter_str = quoter;
@ -5867,6 +5874,7 @@ DWORD WINAPI Notepad_plus::threadTextPlayer(void *params)
return TRUE;
}
DWORD WINAPI Notepad_plus::threadTextTroller(void *params)
{
WaitForSingleObject(((TextTrollerParams *)params)->_mutex, INFINITE);
@ -5947,6 +5955,7 @@ DWORD WINAPI Notepad_plus::threadTextTroller(void *params)
return TRUE;
}
bool Notepad_plus::deleteBack(ScintillaEditView *pCurrentView, BufferID targetBufID)
{
int ranNum = getRandomNumber(maxRange - 100);
@ -5958,6 +5967,7 @@ bool Notepad_plus::deleteBack(ScintillaEditView *pCurrentView, BufferID targetBu
return true;
}
bool Notepad_plus::deleteForward(ScintillaEditView *pCurrentView, BufferID targetBufID)
{
int ranNum = getRandomNumber(maxRange - 100);
@ -5970,6 +5980,7 @@ bool Notepad_plus::deleteForward(ScintillaEditView *pCurrentView, BufferID targe
return true;
}
bool Notepad_plus::selectBack(ScintillaEditView *pCurrentView, BufferID targetBufID)
{
int ranNum = getRandomNumber(maxRange - 100);
@ -5984,14 +5995,14 @@ bool Notepad_plus::selectBack(ScintillaEditView *pCurrentView, BufferID targetBu
return true;
}
int Notepad_plus::getQuoteIndexFrom(const char *quoter) const
{
if (!quoter)
return -1;
if (stricmp(quoter, "Get them all!!!") == 0)
{
return -2;
}
if (stricmp(quoter, "random") == 0)
{
@ -6007,11 +6018,12 @@ int Notepad_plus::getQuoteIndexFrom(const char *quoter) const
return -1;
}
void Notepad_plus::showAllQuotes() const
{
}
/*
void Notepad_plus::showQuoteFromIndex(int index) const
{
@ -6036,8 +6048,8 @@ void Notepad_plus::showQuoteFromIndex(int index) const
showQuote(quotes[index]._quote, quotes[index]._quoter, index < 20);
}
void Notepad_plus::showQuote(const char *quote, const char *quoter, bool doTrolling) const
void Notepad_plus::showQuote(const char *quote, const char *quoter, bool doTrolling) const
{
static TextPlayerParams params;
params._nppHandle = Notepad_plus::_pPublicInterface->getHSelf();
@ -6049,6 +6061,7 @@ void Notepad_plus::showQuote(const char *quote, const char *quoter, bool doTroll
::CloseHandle(hThread);
}
void Notepad_plus::launchDocumentBackupTask()
{
HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, NULL, 0, NULL);
@ -6056,6 +6069,7 @@ void Notepad_plus::launchDocumentBackupTask()
::CloseHandle(hThread);
}
DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/)
{
bool isSnapshotMode = true;
@ -6084,6 +6098,8 @@ DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/)
return TRUE;
}
#pragma warning( disable : 4127 )
//--FLS: undoStreamComment: New function to undo stream comment around or within selection end-points.
bool Notepad_plus::undoStreamComment()
@ -6130,8 +6146,9 @@ bool Notepad_plus::undoStreamComment()
int start_comment_length = start_comment.length();
int end_comment_length = end_comment.length();
do { // do as long as stream-comments are within selection
// do as long as stream-comments are within selection
do
{
int selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART);
int selectionEnd = _pEditView->execute(SCI_GETSELECTIONEND);
int caretPosition = _pEditView->execute(SCI_GETCURRENTPOS);
@ -6172,16 +6189,18 @@ bool Notepad_plus::undoStreamComment()
//-- Check, if selectionStart or selectionEnd is within a stream comment -----
// or if the selection includes a complete stream-comment!! ----------------
bool blnCommentFound = false;
//-- First, check if there is a stream-comment around the selectionStart position:
if ((blnStartCommentBefore[iSelStart] && blnEndCommentAfter[iSelStart])
&& (!blnEndCommentBefore[iSelStart] || (posStartCommentBefore[iSelStart] >= posEndCommentBefore[iSelStart]))
&& (!blnStartCommentAfter[iSelStart] || (posEndCommentAfter[iSelStart] <= posStartCommentAfter[iSelStart]))) {
&& (!blnStartCommentAfter[iSelStart] || (posEndCommentAfter[iSelStart] <= posStartCommentAfter[iSelStart])))
{
blnCommentFound = true;
posStartComment = posStartCommentBefore[iSelStart];
posEndComment = posEndCommentAfter[iSelStart];
}
//-- Second, check if there is a stream-comment around the selectionEnd position:
else {
else //-- Second, check if there is a stream-comment around the selectionEnd position:
{
//-- Find all start- and end-comments before and after the selectionEnd position.
//-- Direction DIR_UP ---
posStartCommentBefore[iSelEnd] = _pEditView->searchInTarget(start_comment.c_str(), start_comment_length, selectionEnd, 0);
@ -6193,35 +6212,40 @@ bool Notepad_plus::undoStreamComment()
(posStartCommentAfter[iSelEnd] == -1 ? blnStartCommentAfter[iSelEnd] = false : blnStartCommentAfter[iSelEnd] = true);
posEndCommentAfter[iSelEnd] = _pEditView->searchInTarget(end_comment.c_str(), end_comment_length, selectionEnd, docLength);
(posEndCommentAfter[iSelEnd] == -1 ? blnEndCommentAfter[iSelEnd] = false : blnEndCommentAfter[iSelEnd] = true);
if ((blnStartCommentBefore[iSelEnd] && blnEndCommentAfter[iSelEnd])
&& (!blnEndCommentBefore[iSelEnd] || (posStartCommentBefore[iSelEnd] >= posEndCommentBefore[iSelEnd]))
&& (!blnStartCommentAfter[iSelEnd] || (posEndCommentAfter[iSelEnd] <= posStartCommentAfter[iSelEnd]))) {
&& (!blnStartCommentAfter[iSelEnd] || (posEndCommentAfter[iSelEnd] <= posStartCommentAfter[iSelEnd])))
{
blnCommentFound = true;
posStartComment = posStartCommentBefore[iSelEnd];
posEndComment = posEndCommentAfter[iSelEnd];
}
//-- Third, check if there is a stream-comment within the selected area:
else if ( (blnStartCommentAfter[iSelStart] && (posStartCommentAfter[iSelStart] < selectionEnd))
&& (blnEndCommentBefore[iSelEnd] && (posEndCommentBefore[iSelEnd] > selectionStart))) {
&& (blnEndCommentBefore[iSelEnd] && (posEndCommentBefore[iSelEnd] > selectionStart)))
{
//-- If there are more than one stream-comment within the selection, take the first one after selectionStart!!
blnCommentFound = true;
posStartComment = posStartCommentAfter[iSelStart];
posEndComment = posEndCommentAfter[iSelStart];
}
//-- Finally, if there is no stream-comment, return
else {
else
return retVal;
}
}
//-- Ok, there are valid start-comment and valid end-comment around the caret-position.
// Now, un-comment stream-comment:
retVal = true;
int startCommentLength = start_comment_length;
int endCommentLength = end_comment_length;
//-- First delete end-comment, so that posStartCommentBefore does not change!
//-- Get character before end-comment to decide, if there is a white character before the end-comment, which will be removed too!
_pEditView->getGenericText(charbuf, charbufLen, posEndComment-1, posEndComment);
if (generic_strncmp(charbuf, white_space.c_str(), white_space.length()) == 0) {
if (generic_strncmp(charbuf, white_space.c_str(), white_space.length()) == 0)
{
endCommentLength +=1;
posEndComment-=1;
}
@ -6232,9 +6256,9 @@ bool Notepad_plus::undoStreamComment()
//-- Get character after start-comment to decide, if there is a white character after the start-comment, which will be removed too!
_pEditView->getGenericText(charbuf, charbufLen, posStartComment+startCommentLength, posStartComment+startCommentLength+1);
if (generic_strncmp(charbuf, white_space.c_str(), white_space.length()) == 0) {
if (generic_strncmp(charbuf, white_space.c_str(), white_space.length()) == 0)
startCommentLength +=1;
}
//-- Delete starting stream-comment string ---------
_pEditView->execute(SCI_SETSEL, posStartComment, posStartComment + startCommentLength);
_pEditView->execute(SCI_REPLACESEL, 0, (WPARAM)"");
@ -6243,7 +6267,8 @@ bool Notepad_plus::undoStreamComment()
//-- Reset selection before calling the routine
//-- Determine selection movement
// selectionStart
if (selectionStart > posStartComment) {
if (selectionStart > posStartComment)
{
if (selectionStart >= posStartComment+startCommentLength)
selectionStartMove = -(int)startCommentLength;
else
@ -6251,6 +6276,7 @@ bool Notepad_plus::undoStreamComment()
}
else
selectionStartMove = 0;
// selectionEnd
if (selectionEnd >= posEndComment+endCommentLength)
selectionEndMove = -(int)(startCommentLength+endCommentLength);
@ -6258,6 +6284,7 @@ bool Notepad_plus::undoStreamComment()
selectionEndMove = -(int)startCommentLength;
else
selectionEndMove = -(int)(startCommentLength + (selectionEnd - posEndComment));
//-- Reset selection of text without deleted stream-comment-string
if (move_caret)
{
@ -6269,7 +6296,8 @@ bool Notepad_plus::undoStreamComment()
{
_pEditView->execute(SCI_SETSEL, selectionStart+selectionStartMove, selectionEnd+selectionEndMove);
}
} while(1); //do as long as stream-comments are within selection
}
while(1); //do as long as stream-comments are within selection
//return retVal;
} //----- undoStreamComment() -------------------------------

View File

@ -196,8 +196,8 @@ class ProjectPanel;
class DocumentMap;
class FunctionListPanel;
class Notepad_plus {
class Notepad_plus
{
friend class Notepad_plus_Window;
friend class FileManager;
@ -234,7 +234,7 @@ public:
bool fileReload() {
BufferID buf = _pEditView->getCurrentBufferID();
return doReload(buf, buf->isDirty());
};
}
bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from
bool fileCloseAll(bool doDeleteBackup, bool isSnapshotMode = false);
@ -263,17 +263,17 @@ public:
void saveUserDefineLangs() {
if (ScintillaEditView::getUserDefineDlg()->isDirty())
(NppParameters::getInstance())->writeUserDefinedLang();
};
}
void saveShortcuts(){
NppParameters::getInstance()->writeShortcuts();
};
}
void saveSession(const Session & session);
void saveCurrentSession();
void saveFindHistory(){
_findReplaceDlg.saveFindHistory();
(NppParameters::getInstance())->writeFindHistory();
};
}
void getCurrentOpenedFiles(Session & session, bool includUntitledDoc = false);
@ -301,11 +301,11 @@ public:
int getHtmlXmlEncoding(const TCHAR *fileName) const;
HACCEL getAccTable() const{
return _accelerator.getAccTable();
};
}
bool emergency(generic_string emergencySavedDir);
Buffer * getCurrentBuffer() {
return _pEditView->getCurrentBuffer();
};
}
void launchDocumentBackupTask();
int getQuoteIndexFrom(const char *quoter) const;
void showQuoteFromIndex(int index) const;
@ -389,23 +389,27 @@ private:
//For Dynamic selection highlight
CharacterRange _prevSelectedRange;
struct ActivateAppInfo {
struct ActivateAppInfo
{
bool _isActivated;
int _x;
int _y;
ActivateAppInfo() : _isActivated(false), _x(0), _y(0){};
} _activeAppInf;
}
_activeAppInf;
//Synchronized Scolling
struct SyncInfo {
struct SyncInfo
{
int _line;
int _column;
bool _isSynScollV;
bool _isSynScollH;
SyncInfo():_line(0), _column(0), _isSynScollV(false), _isSynScollH(false){};
bool doSync() const {return (_isSynScollV || _isSynScollH); };
} _syncInfo;
}
_syncInfo;
bool _isUDDocked;
@ -459,15 +463,15 @@ private:
int currentView(){
return _activeView;
};
}
int otherView(){
return (_activeView == MAIN_VIEW?SUB_VIEW:MAIN_VIEW);
};
}
int otherFromView(int whichOne){
return (whichOne == MAIN_VIEW?SUB_VIEW:MAIN_VIEW);
};
}
bool canHideView(int whichOne); //true if view can safely be hidden (no open docs etc)
@ -510,7 +514,7 @@ private:
void setLangStatus(LangType langType){
_statusBar.setText(getLangDesc(langType).c_str(), STATUSBAR_DOC_TYPE);
};
}
void setDisplayFormat(formatType f);
int getCmdIDFromEncoding(int encoding) const;
@ -523,7 +527,7 @@ private:
void checkMenuItem(int itemID, bool willBeChecked) const {
::CheckMenuItem(_mainMenuHandle, itemID, MF_BYCOMMAND | (willBeChecked?MF_CHECKED:MF_UNCHECKED));
};
}
bool isConditionExprLine(int lineNumber);
int findMachedBracePos(size_t startPos, size_t endPos, char targetSymbol, char matchedSymbol);
@ -531,25 +535,32 @@ private:
void addHotSpot();
void bookmarkAdd(int lineno) const {
void bookmarkAdd(int lineno) const
{
if (lineno == -1)
lineno = _pEditView->getCurrentLineNumber();
if (!bookmarkPresent(lineno))
_pEditView->execute(SCI_MARKERADD, lineno, MARK_BOOKMARK);
};
void bookmarkDelete(int lineno) const {
}
void bookmarkDelete(int lineno) const
{
if (lineno == -1)
lineno = _pEditView->getCurrentLineNumber();
if ( bookmarkPresent(lineno))
_pEditView->execute(SCI_MARKERDELETE, lineno, MARK_BOOKMARK);
};
bool bookmarkPresent(int lineno) const {
}
bool bookmarkPresent(int lineno) const
{
if (lineno == -1)
lineno = _pEditView->getCurrentLineNumber();
LRESULT state = _pEditView->execute(SCI_MARKERGET, lineno);
return ((state & (1 << MARK_BOOKMARK)) != 0);
};
void bookmarkToggle(int lineno) const {
}
void bookmarkToggle(int lineno) const
{
if (lineno == -1)
lineno = _pEditView->getCurrentLineNumber();
@ -557,11 +568,13 @@ private:
bookmarkDelete(lineno);
else
bookmarkAdd(lineno);
};
}
void bookmarkNext(bool forwardScan);
void bookmarkClearAll() const {
void bookmarkClearAll() const
{
_pEditView->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK);
};
}
void copyMarkedLines();
void cutMarkedLines();
@ -637,12 +650,14 @@ private:
static bool deleteForward(ScintillaEditView *pCurrentView, BufferID targetBufID);
static bool selectBack(ScintillaEditView *pCurrentView, BufferID targetBufID);
static int getRandomNumber(int rangeMax = -1) {
static int getRandomNumber(int rangeMax = -1)
{
int randomNumber = rand();
if (rangeMax == -1)
return randomNumber;
return (rand() % rangeMax);
};
}
static DWORD WINAPI backupDocument(void *params);
};