Remove ugly coding style

This commit is contained in:
Don HO 2019-03-16 05:33:50 +01:00
parent 6dfd22d52f
commit 52a4e21af5
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
26 changed files with 176 additions and 132 deletions

View File

@ -1033,7 +1033,8 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
std::vector<int>::const_iterator itIndexesEnd = krvecBufferIndexes.end(); std::vector<int>::const_iterator itIndexesEnd = krvecBufferIndexes.end();
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) { for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex)
{
BufferID id = _pDocTab->getBufferByIndex(*itIndex); BufferID id = _pDocTab->getBufferByIndex(*itIndex);
Buffer * buf = MainFileManager->getBufferByID(id); Buffer * buf = MainFileManager->getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0) if (buf->isUntitled() && buf->docLength() == 0)
@ -1069,7 +1070,8 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
// Now we close. // Now we close.
bool isSnapshotMode = NppParameters::getInstance()->getNppGUI().isSnapshotMode(); bool isSnapshotMode = NppParameters::getInstance()->getNppGUI().isSnapshotMode();
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) { for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex)
{
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isSnapshotMode); doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isSnapshotMode);
} }
@ -1081,7 +1083,8 @@ bool Notepad_plus::fileCloseAllToLeft()
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining // Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
// indexes (smaller than the one just closed) will point to the wrong tab. // indexes (smaller than the one just closed) will point to the wrong tab.
std::vector<int> vecIndexesToClose; std::vector<int> vecIndexesToClose;
for(int i = _pDocTab->getCurrentTabIndex() - 1; i >= 0; i--) { for (int i = _pDocTab->getCurrentTabIndex() - 1; i >= 0; i--)
{
vecIndexesToClose.push_back(i); vecIndexesToClose.push_back(i);
} }
return fileCloseAllGiven(vecIndexesToClose); return fileCloseAllGiven(vecIndexesToClose);
@ -1093,7 +1096,8 @@ bool Notepad_plus::fileCloseAllToRight()
// indexes (smaller than the one just closed) will point to the wrong tab. // indexes (smaller than the one just closed) will point to the wrong tab.
const int kiActive = _pDocTab->getCurrentTabIndex(); const int kiActive = _pDocTab->getCurrentTabIndex();
std::vector<int> vecIndexesToClose; std::vector<int> vecIndexesToClose;
for(int i = int(_pDocTab->nbItem()) - 1; i > kiActive; i--) { for (int i = int(_pDocTab->nbItem()) - 1; i > kiActive; i--)
{
vecIndexesToClose.push_back(i); vecIndexesToClose.push_back(i);
} }
return fileCloseAllGiven(vecIndexesToClose); return fileCloseAllGiven(vecIndexesToClose);

View File

@ -155,12 +155,14 @@ int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int
return j; return j;
} }
bool Searching::readBase(const TCHAR * str, int * value, int base, int size) { bool Searching::readBase(const TCHAR * str, int * value, int base, int size)
{
int i = 0, temp = 0; int i = 0, temp = 0;
*value = 0; *value = 0;
TCHAR max = '0' + static_cast<TCHAR>(base) - 1; TCHAR max = '0' + static_cast<TCHAR>(base) - 1;
TCHAR current; TCHAR current;
while(i < size) { while (i < size)
{
current = str[i]; current = str[i];
if (current >= 'A') if (current >= 'A')
{ {
@ -170,10 +172,13 @@ bool Searching::readBase(const TCHAR * str, int * value, int base, int size) {
else if (current > '9') else if (current > '9')
return false; return false;
if (current >= '0' && current <= max) { if (current >= '0' && current <= max)
{
temp *= base; temp *= base;
temp += (current - '0'); temp += (current - '0');
} else { }
else
{
return false; return false;
} }
++i; ++i;

View File

@ -59,13 +59,16 @@ inline bool match(TCHAR c1, TCHAR c2) {
//test string case insensitive ala Scintilla //test string case insensitive ala Scintilla
//0 if equal, <0 of before, >0 if after (name1 that is) //0 if equal, <0 of before, >0 if after (name1 that is)
int testNameNoCase(const TCHAR * name1, const TCHAR * name2, int len = -1) { int testNameNoCase(const TCHAR * name1, const TCHAR * name2, int len = -1)
{
if (len == -1) { if (len == -1) {
len = 1024; //magic value, but it probably fails way before it reaches this len = 1024; //magic value, but it probably fails way before it reaches this
} }
int i = 0; int i = 0;
while(match(name1[i], name2[i])) { while (match(name1[i], name2[i]))
if (name1[i] == 0 || i == len) { {
if (name1[i] == 0 || i == len)
{
return 0; //equal return 0; //equal
} }
++i; ++i;
@ -77,7 +80,8 @@ int testNameNoCase(const TCHAR * name1, const TCHAR * name2, int len = -1) {
return ( (name1[i]-subs1) - (name2[i]-subs2) ); return ( (name1[i]-subs1) - (name2[i]-subs2) );
} }
void FunctionCallTip::setLanguageXML(TiXmlElement * pXmlKeyword) { void FunctionCallTip::setLanguageXML(TiXmlElement * pXmlKeyword)
{
if (isVisible()) if (isVisible())
close(); close();
_pXmlKeyword = pXmlKeyword; _pXmlKeyword = pXmlKeyword;
@ -108,14 +112,16 @@ bool FunctionCallTip::updateCalltip(int ch, bool needShown)
return true; return true;
} }
void FunctionCallTip::showNextOverload() { void FunctionCallTip::showNextOverload()
{
if (!isVisible()) if (!isVisible())
return; return;
_currentOverload = (_currentOverload+1) % _currentNbOverloads; _currentOverload = (_currentOverload+1) % _currentNbOverloads;
showCalltip(); showCalltip();
} }
void FunctionCallTip::showPrevOverload() { void FunctionCallTip::showPrevOverload()
{
if (!isVisible()) if (!isVisible())
return; return;
_currentOverload = _currentOverload > 0 ? (_currentOverload-1) : (_currentNbOverloads-1); _currentOverload = _currentOverload > 0 ? (_currentOverload-1) : (_currentNbOverloads-1);

View File

@ -491,7 +491,7 @@ public:
} }
delete [] selected; delete [] selected;
return length; return length;
} };
long getLineLength(int line) const { long getLineLength(int line) const {

View File

@ -25,8 +25,6 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdexcept> #include <stdexcept>
#include "ToolBar.h" #include "ToolBar.h"
#include "shortcut.h" #include "shortcut.h"
@ -104,8 +102,7 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot)
} }
} }
bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit *buttonUnitArray, int arraySize)
ToolBarButtonUnit *buttonUnitArray, int arraySize)
{ {
Window::init(hInst, hPere); Window::init(hInst, hPere);
_state = type; _state = type;
@ -149,7 +146,8 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type,
_pTBB[i].iString = 0; _pTBB[i].iString = 0;
} }
if (_nbDynButtons > 0) { if (_nbDynButtons > 0)
{
//add separator //add separator
_pTBB[i].iBitmap = 0; _pTBB[i].iBitmap = 0;
_pTBB[i].idCommand = 0; _pTBB[i].idCommand = 0;
@ -178,8 +176,10 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type,
return true; return true;
} }
void ToolBar::destroy() { void ToolBar::destroy()
if (_pRebar) { {
if (_pRebar)
{
_pRebar->removeBand(_rbBand.wID); _pRebar->removeBand(_rbBand.wID);
_pRebar = NULL; _pRebar = NULL;
} }
@ -189,17 +189,20 @@ void ToolBar::destroy() {
_toolBarIcons.destroy(); _toolBarIcons.destroy();
}; };
int ToolBar::getWidth() const { int ToolBar::getWidth() const
{
RECT btnRect; RECT btnRect;
int totalWidth = 0; int totalWidth = 0;
for(size_t i = 0; i < _nbCurrentButtons; ++i) { for (size_t i = 0; i < _nbCurrentButtons; ++i)
{
::SendMessage(_hSelf, TB_GETITEMRECT, i, reinterpret_cast<LPARAM>(&btnRect)); ::SendMessage(_hSelf, TB_GETITEMRECT, i, reinterpret_cast<LPARAM>(&btnRect));
totalWidth += btnRect.right - btnRect.left; totalWidth += btnRect.right - btnRect.left;
} }
return totalWidth; return totalWidth;
} }
int ToolBar::getHeight() const { int ToolBar::getHeight() const
{
DWORD size = static_cast<DWORD>(SendMessage(_hSelf, TB_GETBUTTONSIZE, 0, 0)); DWORD size = static_cast<DWORD>(SendMessage(_hSelf, TB_GETBUTTONSIZE, 0, 0));
DWORD padding = static_cast<DWORD>(SendMessage(_hSelf, TB_GETPADDING, 0, 0)); DWORD padding = static_cast<DWORD>(SendMessage(_hSelf, TB_GETPADDING, 0, 0));
int totalHeight = HIWORD(size) + HIWORD(padding) - 3; int totalHeight = HIWORD(size) + HIWORD(padding) - 3;
@ -460,7 +463,7 @@ void ReBar::reNew(int id, REBARBANDINFO * rBand)
{ {
auto index = SendMessage(_hSelf, RB_IDTOINDEX, id, 0); auto index = SendMessage(_hSelf, RB_IDTOINDEX, id, 0);
::SendMessage(_hSelf, RB_SETBANDINFO, index, reinterpret_cast<LPARAM>(rBand)); ::SendMessage(_hSelf, RB_SETBANDINFO, index, reinterpret_cast<LPARAM>(rBand));
}; }
void ReBar::removeBand(int id) void ReBar::removeBand(int id)
{ {

View File

@ -81,7 +81,10 @@ inline static BOOL ModifyStyleEx(HWND hWnd, DWORD dwRemove, DWORD dwAdd) {
struct NumericStringEquivalence struct NumericStringEquivalence
{ {
int operator()(const TCHAR* s1, const TCHAR* s2) const int operator()(const TCHAR* s1, const TCHAR* s2) const
{ return numstrcmp(s1, s2); } {
return numstrcmp(s1, s2);
}
static inline int numstrcmp_get(const TCHAR **str, int *length) static inline int numstrcmp_get(const TCHAR **str, int *length)
{ {
const TCHAR *p = *str; const TCHAR *p = *str;
@ -91,13 +94,15 @@ struct NumericStringEquivalence
*str = p; *str = p;
return (value); return (value);
} }
static int numstrcmp(const TCHAR *str1, const TCHAR *str2) static int numstrcmp(const TCHAR *str1, const TCHAR *str2)
{ {
TCHAR *p1, *p2; TCHAR *p1, *p2;
int c1, c2, lcmp = 0; int c1, c2, lcmp = 0;
for (;;) for (;;)
{ {
if (*str1 == 0 || *str2 == 0) { if (*str1 == 0 || *str2 == 0)
{
if (*str1 != *str2) if (*str1 != *str2)
lcmp = *str1 - *str2; lcmp = *str1 - *str2;
break; break;
@ -751,7 +756,8 @@ void WindowsDlg::doClose()
nmdlg.Items = new UINT[nmdlg.nItems]; nmdlg.Items = new UINT[nmdlg.nItems];
vector<int> key; vector<int> key;
key.resize(n, 0x7fffffff); key.resize(n, 0x7fffffff);
for(int i=-1, j=0;; ++j) { for (int i=-1, j=0;; ++j)
{
i = ListView_GetNextItem(_hList, i, LVNI_SELECTED); i = ListView_GetNextItem(_hList, i, LVNI_SELECTED);
if (i == -1) break; if (i == -1) break;
ListView_SetItemState(_hList, i, 0, LVIS_SELECTED); // deselect ListView_SetItemState(_hList, i, 0, LVIS_SELECTED); // deselect

View File

@ -167,16 +167,22 @@ generic_string Shortcut::toString() const
return sc; return sc;
} }
void Shortcut::setName(const TCHAR * name) { void Shortcut::setName(const TCHAR * name)
{
lstrcpyn(_menuName, name, nameLenMax); lstrcpyn(_menuName, name, nameLenMax);
lstrcpyn(_name, name, nameLenMax); lstrcpyn(_name, name, nameLenMax);
int i = 0, j = 0; int i = 0, j = 0;
while(name[j] != 0 && i < nameLenMax) { while (name[j] != 0 && i < nameLenMax)
if (name[j] != '&') { {
if (name[j] != '&')
{
_name[i] = name[j]; _name[i] = name[j];
++i; ++i;
} else { //check if this ampersand is being escaped }
if (name[j+1] == '&') { //escaped ampersand else //check if this ampersand is being escaped
{
if (name[j+1] == '&') //escaped ampersand
{
_name[i] = name[j]; _name[i] = name[j];
++i; ++i;
++j; //skip escaped ampersand ++j; //skip escaped ampersand
@ -187,10 +193,12 @@ void Shortcut::setName(const TCHAR * name) {
_name[i] = 0; _name[i] = 0;
} }
generic_string ScintillaKeyMap::toString() const { generic_string ScintillaKeyMap::toString() const
{
generic_string sc = TEXT(""); generic_string sc = TEXT("");
size_t nbCombos = getSize(); size_t nbCombos = getSize();
for (size_t combo = 0; combo < nbCombos; ++combo){ for (size_t combo = 0; combo < nbCombos; ++combo)
{
sc += toString(combo); sc += toString(combo);
if (combo < nbCombos - 1) if (combo < nbCombos - 1)
sc += TEXT(" or "); sc += TEXT(" or ");
@ -198,7 +206,8 @@ generic_string ScintillaKeyMap::toString() const {
return sc; return sc;
} }
generic_string ScintillaKeyMap::toString(size_t index) const { generic_string ScintillaKeyMap::toString(size_t index) const
{
generic_string sc = TEXT(""); generic_string sc = TEXT("");
if (!isEnabled()) if (!isEnabled())
return sc; return sc;
@ -217,7 +226,8 @@ generic_string ScintillaKeyMap::toString(size_t index) const {
return sc; return sc;
} }
KeyCombo ScintillaKeyMap::getKeyComboByIndex(size_t index) const { KeyCombo ScintillaKeyMap::getKeyComboByIndex(size_t index) const
{
return _keyCombos[index]; return _keyCombos[index];
} }
@ -248,6 +258,7 @@ int ScintillaKeyMap::addKeyCombo(KeyCombo combo)
_keyCombos[0] = combo; _keyCombos[0] = combo;
return 0; return 0;
} }
for (size_t i = 0; i < _size; ++i) for (size_t i = 0; i < _size; ++i)
{ //if already in the list do not add it { //if already in the list do not add it
KeyCombo & kc = _keyCombos[i]; KeyCombo & kc = _keyCombos[i];
@ -259,11 +270,13 @@ int ScintillaKeyMap::addKeyCombo(KeyCombo combo)
return static_cast<int32_t>(_size - 1); return static_cast<int32_t>(_size - 1);
} }
bool ScintillaKeyMap::isEnabled() const { bool ScintillaKeyMap::isEnabled() const
{
return (_keyCombos[0]._key != 0); return (_keyCombos[0]._key != 0);
} }
size_t ScintillaKeyMap::getSize() const { size_t ScintillaKeyMap::getSize() const
{
return _size; return _size;
} }
@ -272,8 +285,10 @@ void getKeyStrFromVal(UCHAR keyVal, generic_string & str)
str = TEXT(""); str = TEXT("");
bool found = false; bool found = false;
int i; int i;
for (i = 0; i < nbKeys; ++i) { for (i = 0; i < nbKeys; ++i)
if (keyVal == namedKeyArray[i].id) { {
if (keyVal == namedKeyArray[i].id)
{
found = true; found = true;
break; break;
} }
@ -586,25 +601,30 @@ void Accelerator::updateShortcuts()
return; return;
} }
void Accelerator::updateFullMenu() { void Accelerator::updateFullMenu()
{
NppParameters * pNppParam = NppParameters::getInstance(); NppParameters * pNppParam = NppParameters::getInstance();
vector<CommandShortcut> commands = pNppParam->getUserShortcuts(); vector<CommandShortcut> commands = pNppParam->getUserShortcuts();
for(size_t i = 0; i < commands.size(); ++i) { for (size_t i = 0; i < commands.size(); ++i)
{
updateMenuItemByCommand(commands[i]); updateMenuItemByCommand(commands[i]);
} }
vector<MacroShortcut> mcommands = pNppParam->getMacroList(); vector<MacroShortcut> mcommands = pNppParam->getMacroList();
for(size_t i = 0; i < mcommands.size(); ++i) { for (size_t i = 0; i < mcommands.size(); ++i)
{
updateMenuItemByCommand(mcommands[i]); updateMenuItemByCommand(mcommands[i]);
} }
vector<UserCommand> ucommands = pNppParam->getUserCommandList(); vector<UserCommand> ucommands = pNppParam->getUserCommandList();
for(size_t i = 0; i < ucommands.size(); ++i) { for (size_t i = 0; i < ucommands.size(); ++i)
{
updateMenuItemByCommand(ucommands[i]); updateMenuItemByCommand(ucommands[i]);
} }
vector<PluginCmdShortcut> pcommands = pNppParam->getPluginCommandList(); vector<PluginCmdShortcut> pcommands = pNppParam->getPluginCommandList();
for(size_t i = 0; i < pcommands.size(); ++i) { for (size_t i = 0; i < pcommands.size(); ++i)
{
updateMenuItemByCommand(pcommands[i]); updateMenuItemByCommand(pcommands[i]);
} }