[CODE_ENHANCEMENT] Code enhancement.

This commit is contained in:
Don Ho 2015-05-28 01:22:28 +02:00
parent c123fd1a01
commit 7f6dd17f03
13 changed files with 115 additions and 102 deletions

View File

@ -129,16 +129,11 @@ BOOL Process::run()
void Process::listenerStdOut()
{
//BOOL Result = 0;
//DWORD size = 0;
DWORD bytesAvail = 0;
BOOL result = 0;
HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerEvent"));
//FILE *fp = NULL;
int taille = 0;
TCHAR bufferOut[MAX_LINE_LENGTH + 1];
//TCHAR bufferErr[MAX_LINE_LENGTH + 1];
int nExitCode = STILL_ACTIVE;
@ -150,8 +145,7 @@ void Process::listenerStdOut()
while (goOn)
{ // got data
memset(bufferOut,0x00,MAX_LINE_LENGTH + 1);
//memset(bufferErr,0x00,MAX_LINE_LENGTH + 1);
taille = sizeof(bufferOut) - sizeof(TCHAR);
int taille = sizeof(bufferOut) - sizeof(TCHAR);
Sleep(50);
@ -171,7 +165,7 @@ void Process::listenerStdOut()
break;
}
}
//outbytesRead = strlen(bufferOut);
bufferOut[outbytesRead] = '\0';
generic_string s;
s.assign(bufferOut);
@ -198,20 +192,14 @@ void Process::listenerStdOut()
void Process::listenerStdErr()
{
//BOOL Result = 0;
//DWORD size = 0;
DWORD bytesAvail = 0;
BOOL result = 0;
HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerStdErrEvent"));
int taille = 0;
//TCHAR bufferOut[MAX_LINE_LENGTH + 1];
TCHAR bufferErr[MAX_LINE_LENGTH + 1];
int nExitCode = STILL_ACTIVE;
DWORD errbytesRead;
::ResumeThread(_hProcessThread);
bool goOn = true;
@ -221,7 +209,7 @@ void Process::listenerStdErr()
taille = sizeof(bufferErr) - sizeof(TCHAR);
Sleep(50);
DWORD errbytesRead;
if (!::PeekNamedPipe(_hPipeErrR, bufferErr, taille, &errbytesRead, &bytesAvail, NULL))
{
bytesAvail = 0;
@ -238,7 +226,6 @@ void Process::listenerStdErr()
break;
}
}
//outbytesRead = strlen(bufferOut);
bufferErr[errbytesRead] = '\0';
generic_string s;
s.assign(bufferErr);

View File

@ -606,7 +606,7 @@ private:
int getLangFromMenuName(const TCHAR * langName);
generic_string getLangFromMenu(const Buffer * buf);
generic_string Notepad_plus::exts2Filters(generic_string exts) const;
generic_string exts2Filters(generic_string exts) const;
int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1);
void markSelectedTextInc(bool enable);
Style * getStyleFromName(const TCHAR *styleName);

View File

@ -86,7 +86,7 @@ public:
::DestroyWindow(_hSelf);
};
static const TCHAR * Notepad_plus_Window::getClassName() {
static const TCHAR * getClassName() {
return _className;
};
static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant

View File

@ -306,7 +306,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe
if (isWow64Off)
{
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
isWow64Off = false;
//isWow64Off = false;
}
return buffer;
}
@ -439,7 +439,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
if (isWow64Off)
{
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
isWow64Off = false;
//isWow64Off = false;
}
}

View File

@ -860,15 +860,14 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (_rebarBottom.getHSelf() == lpnm->hdr.hwndFrom)
notifRebar = &_rebarBottom;
//If N++ ID, use proper object
switch(lpnm->wID) {
case REBAR_BAR_TOOLBAR: {
POINT pt;
pt.x = lpnm->rc.left;
pt.y = lpnm->rc.bottom;
ClientToScreen(notifRebar->getHSelf(), &pt);
_toolBar.doPopop(pt);
return TRUE;
break; }
if (lpnm->wID == REBAR_BAR_TOOLBAR)
{
POINT pt;
pt.x = lpnm->rc.left;
pt.y = lpnm->rc.bottom;
ClientToScreen(notifRebar->getHSelf(), &pt);
_toolBar.doPopop(pt);
return TRUE;
}
//Else forward notification to window of rebarband
REBARBANDINFO rbBand;

View File

@ -222,7 +222,6 @@ static bool getPathsForPathCompletion(generic_string input, generic_string &rawP
}
else
{
locale loc;
size_t last_occurrence = rawPath.rfind(L"\\");
if(last_occurrence == std::string::npos) // No match.
return false;
@ -765,10 +764,10 @@ bool AutoCompletion::setLanguage(LangType language) {
//Cache the keywords
//Iterate through all keywords
TiXmlElement *funcNode = _pXmlKeyword;
const TCHAR * name = NULL;
for (; funcNode; funcNode = funcNode->NextSiblingElement(TEXT("KeyWord")) )
{
name = funcNode->Attribute(TEXT("name"));
const TCHAR *name = funcNode->Attribute(TEXT("name"));
if (name)
{
size_t len = lstrlen(name);

View File

@ -217,7 +217,7 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i
if (isWow64Off)
{
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
isWow64Off = false;
//isWow64Off = false;
}
return isOK;
}
@ -1121,12 +1121,11 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
int FileManager::detectCodepage(char* buf, size_t len)
{
int codepage = -1;
uchardet_t ud = uchardet_new();
uchardet_handle_data(ud, buf, len);
uchardet_data_end(ud);
const char* cs = uchardet_get_charset(ud);
codepage = EncodingMapper::getInstance()->getEncodingFromString(cs);
int codepage = EncodingMapper::getInstance()->getEncodingFromString(cs);
uchardet_delete(ud);
return codepage;
}
@ -1203,7 +1202,7 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Rea
do {
lenFile = fread(data+incompleteMultibyteChar, 1, blockSize-incompleteMultibyteChar, fp) + incompleteMultibyteChar;
if (lenFile <= 0) break;
if (lenFile == 0) break;
// check if file contain any BOM
if (isFirstTime)

View File

@ -38,19 +38,22 @@ FindOption FindReplaceDlg::_options;
#define SHIFTED 0x8000
int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int length) { //query may equal to result, since it always gets smaller
int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int length)
{ //query may equal to result, since it always gets smaller
int i = 0, j = 0;
int charLeft = length;
bool isGood = true;
TCHAR current;
while(i < length) { //because the backslash escape quences always reduce the size of the generic_string, no overflow checks have to be made for target, assuming parameters are correct
while (i < length)
{ //because the backslash escape quences always reduce the size of the generic_string, no overflow checks have to be made for target, assuming parameters are correct
current = query[i];
--charLeft;
if (current == '\\' && charLeft) { //possible escape sequence
if (current == '\\' && charLeft)
{ //possible escape sequence
++i;
--charLeft;
current = query[i];
switch(current) {
switch(current)
{
case 'r':
result[j] = '\r';
break;
@ -70,38 +73,54 @@ int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int
case 'd':
case 'o':
case 'x':
case 'u': {
case 'u':
{
int size = 0, base = 0;
if (current == 'b') { //11111111
if (current == 'b')
{ //11111111
size = 8, base = 2;
} else if (current == 'o') { //377
}
else if (current == 'o')
{ //377
size = 3, base = 8;
} else if (current == 'd') { //255
}
else if (current == 'd')
{ //255
size = 3, base = 10;
} else if (current == 'x') { //0xFF
}
else if (current == 'x')
{ //0xFF
size = 2, base = 16;
} else if (current == 'u') { //0xCDCD
}
else if (current == 'u')
{ //0xCDCD
size = 4, base = 16;
}
if (charLeft >= size) {
if (charLeft >= size)
{
int res = 0;
if (Searching::readBase(query+(i+1), &res, base, size)) {
if (Searching::readBase(query+(i+1), &res, base, size))
{
result[j] = (TCHAR)res;
i+=size;
i += size;
break;
}
}
//not enough chars to make parameter, use default method as fallback
}
default: { //unknown sequence, treat as regular text
}
default:
{ //unknown sequence, treat as regular text
result[j] = '\\';
++j;
result[j] = current;
isGood = false;
break;
}
}
} else {
}
else
{
result[j] = query[i];
}
++i;

View File

@ -269,14 +269,17 @@ bool FunctionCallTip::getCursorFunction()
/*
Find function in XML structure and parse it
*/
bool FunctionCallTip::loadFunction() {
bool FunctionCallTip::loadFunction()
{
reset(); //set everything back to 0
//The functions should be ordered, but linear search because we cant access like array
_curFunction = NULL;
//Iterate through all keywords and find the correct function keyword
TiXmlElement *funcNode = _pXmlKeyword;
const TCHAR * name = NULL;
for (; funcNode; funcNode = funcNode->NextSiblingElement(TEXT("KeyWord")) ) {
for (; funcNode; funcNode = funcNode->NextSiblingElement(TEXT("KeyWord")) )
{
const TCHAR * name = NULL;
name = funcNode->Attribute(TEXT("name"));
if (!name) //malformed node
continue;
@ -356,9 +359,9 @@ void FunctionCallTip::showCalltip()
//Check if the current overload still holds. If the current param exceeds amounti n overload, see if another one fits better (enough params)
stringVec & params = _overloads.at(_currentOverload);
size_t psize = params.size()+1, osize;
size_t psize = params.size()+1;
if ((size_t)_currentParam >= psize) {
osize = _overloads.size();
size_t osize = _overloads.size();
for(size_t i = 0; i < osize; ++i) {
psize = _overloads.at(i).size()+1;
if ((size_t)_currentParam < psize) {

View File

@ -1561,11 +1561,11 @@ BOOL CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
::SetProp(hwnd, TEXT("Styler dialog prop"), (HANDLE)lParam);
dlg = (StylerDlg *)::GetProp(hwnd, TEXT("Styler dialog prop"));
Style & style = SharedParametersDialog::_pUserLang->_styleArray.getStyler(dlg->stylerIndex);
Style & style = SharedParametersDialog::_pUserLang->_styleArray.getStyler(dlg->_stylerIndex);
// move dialog over UDL GUI (position 0,0 of UDL window) so it wouldn't cover the code
RECT wrc;
::GetWindowRect(dlg->parent, &wrc);
::GetWindowRect(dlg->_parent, &wrc);
wrc.left = wrc.left < 0 ? 200 : wrc.left; // if outside of visible area
wrc.top = wrc.top < 0 ? 200 : wrc.top;
::SetWindowPos(hwnd, HWND_TOP, wrc.left, wrc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
@ -1612,10 +1612,10 @@ BOOL CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
if (style._bgColor == COLORREF(-1))
style._bgColor = white;
dlg->pFgColour->init(dlg->hInst, hwnd);
dlg->pFgColour->setColour(style._fgColor);
dlg->pBgColour->init(dlg->hInst, hwnd);
dlg->pBgColour->setColour(style._bgColor);
dlg->_pFgColour->init(dlg->_hInst, hwnd);
dlg->_pFgColour->setColour(style._fgColor);
dlg->_pBgColour->init(dlg->_hInst, hwnd);
dlg->_pBgColour->setColour(style._bgColor);
POINT p1, p2;
RECT rc1, rc2;
@ -1635,24 +1635,24 @@ BOOL CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
p1.x += 10; p2.x += 10;
p1.y -= 6; p2.y -= 6;
::MoveWindow(dlg->pFgColour->getHSelf(), p1.x, p1.y, 30, 30, TRUE);
::MoveWindow(dlg->pBgColour->getHSelf(), p2.x, p2.y, 30, 30, TRUE);
::MoveWindow(dlg->_pFgColour->getHSelf(), p1.x, p1.y, 30, 30, TRUE);
::MoveWindow(dlg->_pBgColour->getHSelf(), p2.x, p2.y, 30, 30, TRUE);
dlg->pFgColour->display();
dlg->pBgColour->display();
dlg->_pFgColour->display();
dlg->_pBgColour->display();
map<int, int>::iterator iter = globalMappper().nestingMapper.begin();
for (; iter != globalMappper().nestingMapper.end(); ++iter)
{
::SendDlgItemMessage(hwnd, iter->first, BM_SETCHECK, style._nesting & iter->second, 0);
::EnableWindow(::GetDlgItem(hwnd, iter->first), dlg->enabledNesters & iter->second);
::EnableWindow(::GetDlgItem(hwnd, iter->first), dlg->_enabledNesters & iter->second);
}
return TRUE;
}
case WM_COMMAND :
{
Style & style = SharedParametersDialog::_pUserLang->_styleArray.getStyler(dlg->stylerIndex);
Style & style = SharedParametersDialog::_pUserLang->_styleArray.getStyler(dlg->_stylerIndex);
if (HIWORD(wParam) == CBN_SELCHANGE)
{
int i = ::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
@ -1691,7 +1691,7 @@ BOOL CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
{
if (wParam == IDCANCEL)
{
style = dlg->initialStyle;
style = dlg->_initialStyle;
// show changes to user, re-color document
if (SharedParametersDialog::_pScintilla->getCurrentBuffer()->getLangType() == L_USER)
@ -1709,14 +1709,14 @@ BOOL CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
return TRUE;
}
style._fgColor = dlg->pFgColour->getColour();
style._bgColor = dlg->pBgColour->getColour();
style._fgColor = dlg->_pFgColour->getColour();
style._bgColor = dlg->_pBgColour->getColour();
if (dlg->pFgColour->isEnabled())
if (dlg->_pFgColour->isEnabled())
style._colorStyle |= COLORSTYLE_FOREGROUND;
else
style._colorStyle &= ~COLORSTYLE_FOREGROUND;
if (dlg->pBgColour->isEnabled())
if (dlg->_pBgColour->isEnabled())
style._colorStyle |= COLORSTYLE_BACKGROUND;
else
style._colorStyle &= ~COLORSTYLE_BACKGROUND;

View File

@ -279,6 +279,7 @@ protected :
bool setPropertyByCheck(HWND hwnd, WPARAM id, bool & bool2set);
virtual void setKeywords2List(int ctrlID) = 0;
};
class FolderStyleDialog : public SharedParametersDialog
{
public:
@ -292,6 +293,7 @@ private :
void retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR *prefix) const;
URLCtrl _pageLink;
};
class KeyWordsStyleDialog : public SharedParametersDialog
{
public:
@ -301,6 +303,7 @@ protected :
BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
void setKeywords2List(int id);
};
class CommentStyleDialog : public SharedParametersDialog
{
public :
@ -313,6 +316,7 @@ private :
void convertTo(TCHAR *dest, const TCHAR *toConvert, TCHAR *prefix) const;
void retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR *prefix) const;
};
class SymbolsStyleDialog : public SharedParametersDialog
{
public :
@ -325,6 +329,7 @@ private :
void convertTo(TCHAR *dest, const TCHAR *toConvert, TCHAR *prefix) const;
void retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR *prefix) const;
};
class UserDefineDialog : public SharedParametersDialog
{
friend class ScintillaEditView;
@ -411,6 +416,7 @@ protected :
void setKeywords2List(int){};
void updateDlg();
};
class StringDlg : public StaticDialog
{
public :
@ -434,34 +440,36 @@ private :
generic_string _static;
int _txtLen;
};
class StylerDlg
{
public:
StylerDlg( HINSTANCE hInst, HWND parent, int stylerIndex = 0, int enabledNesters = -1):
hInst(hInst), parent(parent), stylerIndex(stylerIndex), enabledNesters(enabledNesters)
{
pFgColour = new ColourPicker;
pBgColour = new ColourPicker;
initialStyle = SharedParametersDialog::_pUserLang->_styleArray.getStyler(stylerIndex);
_hInst(hInst), _parent(parent), _stylerIndex(stylerIndex), _enabledNesters(enabledNesters) {
_pFgColour = new ColourPicker;
_pBgColour = new ColourPicker;
_initialStyle = SharedParametersDialog::_pUserLang->_styleArray.getStyler(stylerIndex);
};
~StylerDlg()
{
pFgColour->destroy();
pBgColour->destroy();
delete pFgColour;
delete pBgColour;
}
~StylerDlg() {
_pFgColour->destroy();
_pBgColour->destroy();
delete _pFgColour;
delete _pBgColour;
};
long doDialog() {
return long (::DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_STYLER_POPUP_DLG), parent, (DLGPROC)dlgProc, (LPARAM)this));
return long (::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STYLER_POPUP_DLG), _parent, (DLGPROC)dlgProc, (LPARAM)this));
};
static BOOL CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
HINSTANCE hInst;
HWND parent;
int stylerIndex;
int enabledNesters;
ColourPicker * pFgColour;
ColourPicker * pBgColour;
Style initialStyle;
HINSTANCE _hInst;
HWND _parent;
int _stylerIndex;
int _enabledNesters;
ColourPicker * _pFgColour;
ColourPicker * _pBgColour;
Style _initialStyle;
};
#endif //USER_DEFINE_H

View File

@ -82,7 +82,6 @@ generic_string NativeLangSpeaker::getSpecialMenuEntryName(const char *entryName)
if (!mainMenu) return TEXT("");
TiXmlNodeA *entriesRoot = mainMenu->FirstChild("Entries");
if (!entriesRoot) return TEXT("");
const char *idName = NULL;
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
@ -92,7 +91,7 @@ generic_string NativeLangSpeaker::getSpecialMenuEntryName(const char *entryName)
{
TiXmlElementA *element = childNode->ToElement();
idName = element->Attribute("idName");
const char *idName = element->Attribute("idName");
if (idName)
{
const char *name = element->Attribute("name");
@ -397,11 +396,12 @@ void NativeLangSpeaker::changeLangTabDrapContextMenu(HMENU hCM)
{
const int POS_GO2VIEW = 0;
const int POS_CLONE2VIEW = 1;
const char *goToViewA = NULL;
const char *cloneToViewA = NULL;
if (_nativeLangA)
{
const char *goToViewA = NULL;
const char *cloneToViewA = NULL;
TiXmlNodeA *tabBarMenu = _nativeLangA->FirstChild("Menu");
if (tabBarMenu)
tabBarMenu = tabBarMenu->FirstChild("TabBar");

View File

@ -315,11 +315,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
generic_string quotFileName = TEXT("");
// tell the running instance the FULL path to the new files to load
size_t nrFilesToOpen = params.size();
const TCHAR * currentFile;
for(size_t i = 0; i < nrFilesToOpen; ++i)
{
currentFile = params.at(i);
const TCHAR * currentFile = params.at(i);
if (currentFile[0])
{
//check if relative or full path. Relative paths dont have a colon for driveletter