From f98686d9f4a09b69bff28321c961cbb115e6b65e Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 8 Jan 2017 23:59:36 +0100 Subject: [PATCH] Add some functions for future use --- PowerEditor/src/Notepad_plus.cpp | 73 ++++++++++++++++++++-- PowerEditor/src/Notepad_plus.h | 5 ++ PowerEditor/src/Notepad_plus_Window.cpp | 6 +- PowerEditor/visual.net/notepadPlus.vcxproj | 4 +- 4 files changed, 75 insertions(+), 13 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 8e0c0f9a..b5830889 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -714,6 +714,8 @@ LRESULT Notepad_plus::init(HWND hwnd) _dockingManager.setActiveTab(cti._cont, cti._activeTab); } + retrieveDefaultWordChars(); + //Load initial docs into doctab loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); @@ -721,6 +723,7 @@ LRESULT Notepad_plus::init(HWND hwnd) activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); //::SetFocus(_mainEditView.getHSelf()); _mainEditView.getFocus(); + return TRUE; } @@ -3617,8 +3620,6 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne) } notifyBufferActivated(id, whichOne); - - //scnN.nmhdr.code = NPPN_DOCSWITCHINGIN; //superseeded by NPPN_BUFFERACTIVATED return true; } @@ -3838,7 +3839,7 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode) if (buf->isReadOnly()) return false; - //--LS: BlockToStreamComment: + //-- BlockToStreamComment: const TCHAR *commentStart; const TCHAR *commentEnd; generic_string symbolStart; @@ -6467,7 +6468,7 @@ DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/) #pragma warning( disable : 4127 ) -//--FLS: undoStreamComment: New function to undo stream comment around or within selection end-points. +//-- undoStreamComment: New function to undo stream comment around or within selection end-points. bool Notepad_plus::undoStreamComment() { const TCHAR *commentStart; @@ -6481,7 +6482,7 @@ bool Notepad_plus::undoStreamComment() bool retVal = false; Buffer * buf = _pEditView->getCurrentBuffer(); - //--LS: Avoid side-effects (e.g. cursor moves number of comment-characters) when file is read-only. + //-- Avoid side-effects (e.g. cursor moves number of comment-characters) when file is read-only. if (buf->isReadOnly()) return false; if (buf->getLangType() == L_USER) @@ -6661,5 +6662,65 @@ bool Notepad_plus::undoStreamComment() } while(1); //do as long as stream-comments are within selection //return retVal; -} //----- undoStreamComment() ------------------------------- +} +void Notepad_plus::retrieveDefaultWordChars() +{ + auto defaultCharListLen = _mainEditView.execute(SCI_GETWORDCHARS); + char *defaultCharList = new char[defaultCharListLen + 1]; + _mainEditView.execute(SCI_GETWORDCHARS, 0, reinterpret_cast(defaultCharList)); + _defaultCharList = defaultCharList; + delete[] defaultCharList; +} + +void Notepad_plus::restoreDefaultWordChars() +{ + _mainEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(_defaultCharList.c_str())); + _subEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(_defaultCharList.c_str())); +} + +void Notepad_plus::addWordChars(const char *chars2add) +{ + size_t chars2addLen = strlen(chars2add); + if (not chars2addLen) + return; + + auto oldCharListLen = _mainEditView.execute(SCI_GETWORDCHARS); + char *oldCharList = new char[oldCharListLen + 1]; + + _mainEditView.execute(SCI_GETWORDCHARS, 0, reinterpret_cast(oldCharList)); + string chars2addStr; + + for (size_t i = 0; i < chars2addLen; ++i) + { + bool found = false; + char char2check = chars2add[i]; + for (auto j = 0; j < oldCharListLen; ++j) + { + char wordChar = oldCharList[j]; + if (char2check == wordChar) + { + found = true; + break; + } + } + if (not found) + { + chars2addStr.push_back(char2check); + } + } + + if (not chars2addStr.empty()) + { + string newCharList = oldCharList; + newCharList += chars2addStr; + //MessageBoxA(NULL, oldCharList, "AVANT", MB_OK); + _mainEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(newCharList.c_str())); + _subEditView.execute(SCI_SETWORDCHARS, 0, reinterpret_cast(newCharList.c_str())); + + //_mainEditView.execute(SCI_GETWORDCHARS, 0, (LPARAM)charList); + //MessageBoxA(NULL, charList, "APRES", MB_OK); + } + + delete[] oldCharList; +} diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index f665aa07..22c326d2 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -643,6 +643,11 @@ private: static bool deleteForward(ScintillaEditView *pCurrentView, BufferID targetBufID); static bool selectBack(ScintillaEditView *pCurrentView, BufferID targetBufID); + void retrieveDefaultWordChars(); + std::string _defaultCharList; + void addWordChars(const char *chars2add); + void restoreDefaultWordChars(); + static int getRandomNumber(int rangeMax = -1) { int randomNumber = rand(); diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 92b1c54d..59e48038 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -148,11 +148,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin ::SetWindowPlacement(_hSelf,&posInfo); } - - // avoid useless drawing - //PaintLocker paintLocker(_hSelf); - - if (0 != (nppGUI._tabStatus & TAB_MULTILINE)) + if ((nppGUI._tabStatus & TAB_MULTILINE) != 0) ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0); if (!nppGUI._menuBarShow) diff --git a/PowerEditor/visual.net/notepadPlus.vcxproj b/PowerEditor/visual.net/notepadPlus.vcxproj index 14f08cd4..d92c60bb 100755 --- a/PowerEditor/visual.net/notepadPlus.vcxproj +++ b/PowerEditor/visual.net/notepadPlus.vcxproj @@ -103,7 +103,7 @@ true ProgramDatabase true - true + false /fixed:no %(AdditionalOptions) @@ -138,7 +138,7 @@ true ProgramDatabase true - true + false /fixed:no %(AdditionalOptions)