Code enhancement: remove obsolete code

The removed code in this commit were added for working around Microsoft ReadDirectoryChanges notification issue:
1a97d3c854
Apparently the issue has been fixed. The following issue has been tested with this commit, no issue found:
https://github.com/notepad-plus-plus/notepad-plus-plus/pull/5591#issuecomment-487313886

This commit could remedy #15819 partially.

Close #15967
This commit is contained in:
Don Ho 2024-12-19 05:44:30 +01:00
parent de1a04038b
commit f535087e5d
27 changed files with 73 additions and 30 deletions

View File

@ -165,6 +165,7 @@ bool IsColorSchemeChangeMessage(LPARAM lParam)
_RefreshImmersiveColorPolicyState();
is = true;
}
if (_GetIsImmersiveColorUsingHighContrast)
_GetIsImmersiveColorUsingHighContrast(IHCM_REFRESH);
return is;
@ -209,10 +210,13 @@ bool IsWindowOrParentUsingDarkScrollBar(HWND hwnd)
HWND hwndRoot = GetAncestor(hwnd, GA_ROOT);
std::lock_guard<std::mutex> lock(g_darkScrollBarMutex);
if (g_darkScrollBarWindows.count(hwnd)) {
if (g_darkScrollBarWindows.count(hwnd))
{
return true;
}
if (hwnd != hwndRoot && g_darkScrollBarWindows.count(hwndRoot)) {
if (hwnd != hwndRoot && g_darkScrollBarWindows.count(hwndRoot))
{
return true;
}
@ -233,7 +237,8 @@ void FixDarkScrollBar()
auto MyOpenThemeData = [](HWND hWnd, LPCWSTR classList) WINAPI_LAMBDA_RETURN(HTHEME) {
if (wcscmp(classList, L"ScrollBar") == 0)
{
if (IsWindowOrParentUsingDarkScrollBar(hWnd)) {
if (IsWindowOrParentUsingDarkScrollBar(hWnd))
{
hWnd = nullptr;
classList = L"Explorer::ScrollBar";
}

View File

@ -859,17 +859,20 @@ bool str2Clipboard(const wstring &str2cpy, HWND hwnd)
{
return false;
}
if (!::OpenClipboard(hwnd))
{
::GlobalFree(hglbCopy);
return false;
}
if (!::EmptyClipboard())
{
::GlobalFree(hglbCopy);
::CloseClipboard();
return false;
}
// Lock the handle and copy the text to the buffer.
wchar_t *pStr = (wchar_t *)::GlobalLock(hglbCopy);
if (!pStr)
@ -878,6 +881,7 @@ bool str2Clipboard(const wstring &str2cpy, HWND hwnd)
::CloseClipboard();
return false;
}
wcscpy_s(pStr, len2Allocate / sizeof(wchar_t), str2cpy.c_str());
::GlobalUnlock(hglbCopy);
// Place the handle on the clipboard.
@ -888,6 +892,7 @@ bool str2Clipboard(const wstring &str2cpy, HWND hwnd)
::CloseClipboard();
return false;
}
if (!::CloseClipboard())
{
return false;
@ -907,9 +912,11 @@ bool buf2Clipboard(const std::vector<Buffer*>& buffers, bool isFullPath, HWND hw
if (fileName)
selection += fileName;
}
if (!selection.empty() && !selection.ends_with(crlf))
selection += crlf;
}
if (!selection.empty())
return str2Clipboard(selection, hwnd);
return false;

View File

@ -303,6 +303,7 @@ public:
{
aNumIndex++;
}
if (b[bNumIndex] == L'-')
{
bNumIndex++;
@ -471,6 +472,7 @@ public:
{
aNumIndex++;
}
if (b[bNumIndex] == L'-')
{
bNumIndex++;

View File

@ -513,8 +513,10 @@ bool PluginsManager::loadPlugins(const wchar_t* dir, const PluginViewList* plugi
}
}
if (hFindFolder && (hFindFolder != INVALID_HANDLE_VALUE))
::FindClose(hFindFolder);
if (hFindDll && (hFindDll != INVALID_HANDLE_VALUE))
::FindClose(hFindDll);

View File

@ -2176,17 +2176,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_CHECKDOCSTATUS:
{
// This is an workaround to deal with Microsoft issue in ReadDirectoryChanges notification
// If command prompt is used to write file continuously (e.g. ping -t 8.8.8.8 > ping.log)
// Then ReadDirectoryChanges does not detect the change.
// Fortunately, notification is sent if right click or double click happens on that file
// Let's leverage this as workaround to enhance npp file monitoring functionality.
// So calling "doesFileExist" is a workaround here.
Buffer* currBuf = getCurrentBuffer();
if (currBuf && currBuf->isMonitoringOn())
doesFileExist(currBuf->getFullPathName());
const NppGUI & nppgui = nppParam.getNppGUI();
if (nppgui._fileAutoDetection != cdDisabled)
{

View File

@ -209,6 +209,7 @@ void Buffer::updateTimeStamp()
//sprintf_s(buf, _countof(buf) - 1, " in updateTimeStamp(): timeStampLive (%lu/%lu) > _timeStamp (%lu/%lu)",
// timeStampLive.dwLowDateTime, timeStampLive.dwHighDateTime, _timeStamp.dwLowDateTime, _timeStamp.dwHighDateTime);
}
if (buf[0] != '\0')
{
wstring issueFn = nppLogNetworkDriveIssue;
@ -220,6 +221,7 @@ void Buffer::updateTimeStamp()
writeLog(nppIssueLog.c_str(), msg.c_str());
}
}
_timeStamp = timeStampLive;
doNotify(BufferChangeTimestamp);
}
@ -343,6 +345,7 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it
{
msg += "FALSE";
}
if (bWorkerThreadTerminated)
{
msg += ", its worker thread had to be forcefully terminated due to timeout reached!";
@ -423,6 +426,7 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it
//sprintf_s(buf, _countof(buf) - 1, " in checkFileState(): attributes.ftLastWriteTime (%lu/%lu) > _timeStamp (%lu/%lu)",
// attributes.ftLastWriteTime.dwLowDateTime, attributes.ftLastWriteTime.dwHighDateTime, _timeStamp.dwLowDateTime, _timeStamp.dwHighDateTime);
}
if (buf[0] != '\0')
{
wstring issueFn = nppLogNetworkDriveIssue;
@ -1196,6 +1200,7 @@ bool FileManager::backupCurrentBuffer()
grabSize -= incompleteMultibyteChar;
isWrittenSuccessful = UnicodeConvertor.writeFile(newData, newDataLen);
}
if (lengthDoc == 0)
isWrittenSuccessful = true;
}
@ -1461,6 +1466,7 @@ size_t FileManager::nextUntitledNewNumber() const
break;
}
}
if (!numberAvailable)
newNumber++;
@ -1730,6 +1736,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
PathRemoveFileSpec(dir);
isNetworkDirDisconnected = !doesDirectoryExist(dir);
}
if (isNetworkDirDisconnected)
return false; // If network ressource is not reachable, we stop here for not having hanging issue because of _wfopen
@ -1793,6 +1800,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
success = false;
break;
}
if (lenFile == 0) break;
if (isFirstTime)
@ -1888,6 +1896,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
_stprintf_s(szException, _countof(szException), L"%d (Scintilla)", sciStatus);
break;
}
if (sciStatus != SC_STATUS_BADALLOC)
{
pNativeSpeaker->messageBox("FileLoadingException",

View File

@ -257,6 +257,7 @@ bool FunctionCallTip::getCursorFunction()
valueVec.pop_back();
}
}
if (curValue.lastFunctionIdentifier > -1)
{
Token funcToken = tokenVector.at(curValue.lastFunctionIdentifier);
@ -271,6 +272,7 @@ bool FunctionCallTip::getCursorFunction()
else
same = wcsncmp(_funcName, funcToken.token, lstrlen(_funcName)) == 0;
}
if (!same)
{ //check if we need to reload data
delete [] _funcName;

View File

@ -124,6 +124,7 @@ vector< pair<intptr_t, intptr_t> > XmlMatchedTagsHighlighter::getAttributesPos(i
state = attr_invalid;
}
}
if (state == attr_value)
attributes.push_back(pair<intptr_t, intptr_t>(start+startPos, start+i-1));

View File

@ -240,6 +240,7 @@ intptr_t CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam
addToClipboadHistory(clipboardData);
}
}
if (_hwndNextCbViewer)
::SendMessage(_hwndNextCbViewer, message, wParam, lParam);
return TRUE;

View File

@ -780,6 +780,7 @@ LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
{
dis.itemState |= ODS_FOCUS;
}
if (i == nSelTab)
{
dis.itemState |= ODS_SELECTED;

View File

@ -594,6 +594,7 @@ void Gripper::drawRectangle(const POINT* pPt)
::PatBlt(hdcMem, rcOld.left , rcOld.top , rcOld.right , rcOld.bottom , PATINVERT);
::PatBlt(hdcMem, rcOld.left+3, rcOld.top+3, rcOld.right-6, rcOld.bottom-6, PATINVERT);
}
if (pPt != NULL)
{ // draw the new drag-rectangle
::PatBlt(hdcMem, rcNew.left , rcNew.top , rcNew.right , rcNew.bottom , PATINVERT);

View File

@ -63,9 +63,11 @@ public:
#endif
::ReleaseDC(0, _hdc);
}
if (_hbm) {
::DeleteObject(_hbm);
}
if (_hbrush) {
::DeleteObject(_hbrush);
}

View File

@ -106,11 +106,13 @@ void DocumentPeeker::scrollSnapshotWith(const MapPosition & mapPos, int textZone
_rc.bottom = _rc.top + static_cast<LONG>(mapPos._height);
hasBeenChanged = true;
}
if (mapPos._width != -1 && _rc.right != _rc.left + mapPos._width)
{
_rc.right = _rc.left + static_cast<LONG>(mapPos._width);
hasBeenChanged = true;
}
if (hasBeenChanged)
::MoveWindow(_pPeekerView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE);
//

View File

@ -235,6 +235,7 @@ bool FindCharsInRangeDlg::getRangeFromUI(unsigned char & startRange, unsigned ch
endRange = 255;
return true;
}
if (isCheckedOrNot(IDC_ASCCI_RADIO))
{
startRange = 0;

View File

@ -192,6 +192,7 @@ void FunctionListPanel::addInStateArray(TreeStateNode tree2Update, const wchar_t
found = true;
}
}
if (!found)
{
TreeParams params;

View File

@ -148,6 +148,7 @@ namespace // anonymous
if (SUCCEEDED(hr))
shellItem = parentItem;
}
if (SUCCEEDED(hr))
hr = dialog->SetFolder(shellItem);
return SUCCEEDED(hr);
@ -421,6 +422,7 @@ private:
}
}
}
if (_hwndNameEdit)
s_handleMap[_hwndNameEdit] = this;
}

View File

@ -1142,6 +1142,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
_treeView.removeItem(hTreeItem);
setWorkSpaceDirty(true);
}
if (getNodeType(parent) == nodeType_folder)
_treeView.setItemImage(parent, INDEX_CLOSED_NODE, INDEX_CLOSED_NODE);
}

View File

@ -42,6 +42,7 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize, S
_dwSplitterStyle |= SV_FIXED;
_dwSplitterStyle &= ~SV_RESIZEWTHPERCNT;
}
if (!_isRegistered)
{
WNDCLASS splitterContainerClass{};
@ -133,6 +134,7 @@ void SplitterContainer::rotateTo(DIRECTION direction)
_dwSplitterStyle |= SV_VERTICAL;
doSwitchWindow = (direction == DIRECTION::RIGHT);
}
if (doSwitchWindow)
{
Window *tmp = _pWin0;

View File

@ -123,6 +123,7 @@ void expandNppEnvironmentStrs(const wchar_t *strSrc, wchar_t *stringDest, size_t
}
}
}
if (iBegin != -1)
{
if (iEnd != -1)

View File

@ -74,6 +74,7 @@ bool ControlsTab::renameTab(const wchar_t *internalName, const wchar_t *newName)
break;
}
}
if (!foundIt)
return false;

View File

@ -1192,6 +1192,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
{
dis.itemState |= ODS_FOCUS;
}
if (i == nSelTab)
{
dis.itemState |= ODS_SELECTED;

View File

@ -394,6 +394,7 @@ void ToolBar::reset(bool create)
addbmp.nID = reinterpret_cast<UINT_PTR>(hBmp);
::SendMessage(_hSelf, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
}
if (_nbDynButtons > 0)
{
for (size_t j = 0; j < _nbDynButtons; ++j)

View File

@ -190,6 +190,7 @@ LRESULT VerticalFileSwitcher::listViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPA
{
::FillRect(lplvcd->nmcd.hdc, &rcSubItem2, hBrush);
}
if (colCount == 3)
{
::FillRect(lplvcd->nmcd.hdc, &rcSubItem3, hBrush);

View File

@ -69,8 +69,7 @@ void CWinMgr::GetWindowPositions(HWND hWnd)
//////////////////
// Move all the windows. Use DeferWindowPos for speed.
//
void
CWinMgr::SetWindowPositions(HWND hWnd)
void CWinMgr::SetWindowPositions(HWND hWnd)
{
int nWindows = CountWindows();
if (m_map && hWnd && nWindows>0) {
@ -132,8 +131,7 @@ WINRECT* CWinMgr::FindRect(int nID)
// algorithm. If a window is given, it's used to get the min/max size and
// desired size for TOFIT types.
//
void
CWinMgr::CalcGroup(WINRECT* pGroup, HWND hWnd)
void CWinMgr::CalcGroup(WINRECT* pGroup, HWND hWnd)
{
// If this bombs, most likely the first entry in your map is not a group!
assert(pGroup && pGroup->IsGroup());
@ -203,8 +201,7 @@ CWinMgr::CalcGroup(WINRECT* pGroup, HWND hWnd)
// Adjust the size of a single entry upwards to its desired size.
// Decrement hwRemaining by amount increased.
//
void
CWinMgr::AdjustSize(WINRECT* wrc, BOOL bRow,
void CWinMgr::AdjustSize(WINRECT* wrc, BOOL bRow,
int& hwRemaining, HWND hWnd)
{
SIZEINFO szi;
@ -236,8 +233,7 @@ CWinMgr::AdjustSize(WINRECT* wrc, BOOL bRow,
// one below the other; for columns, set each column as tall as rcTotal and
// each to the right of the previous.
//
void
CWinMgr::PositionRects(WINRECT* pGroup, const RECT& rcTotal, BOOL bRow)
void CWinMgr::PositionRects(WINRECT* pGroup, const RECT& rcTotal, BOOL bRow)
{
LONG xoryPos = bRow ? rcTotal.top : rcTotal.left;
@ -269,8 +265,7 @@ CWinMgr::PositionRects(WINRECT* pGroup, const RECT& rcTotal, BOOL bRow)
// the SIZEINFO argument. For a group, calculate size info as aggregate of
// subentries.
//
void
CWinMgr::OnGetSizeInfo(SIZEINFO& szi, WINRECT* wrc, HWND hWnd)
void CWinMgr::OnGetSizeInfo(SIZEINFO& szi, WINRECT* wrc, HWND hWnd)
{
szi.szMin = SIZEZERO; // default min size = zero
szi.szMax = SIZEMAX; // default max size = infinite
@ -321,17 +316,23 @@ CWinMgr::OnGetSizeInfo(SIZEINFO& szi, WINRECT* wrc, HWND hWnd)
BOOL bRow = parent->IsRowGroup();
int hw, hwMin, hwTotal, pct;
switch (wrc->Type()) {
switch (wrc->Type())
{
case WRCT_FIXED:
hw = hwMin = wrc->GetParam(); // ht/wid is parameter
if (hw<0) { // if fixed val is negative:
if (hw<0) // if fixed val is negative:
{
hw = -hw; // use absolute val for desired..
hwMin = 0; // ..and zero for minimum
}
if (bRow) {
if (bRow)
{
szi.szMax.cy = szi.szDesired.cy = hw;
szi.szMin.cy = hwMin;
} else {
}
else
{
szi.szMax.cx = szi.szDesired.cx = hw;
szi.szMin.cx = hwMin;
}
@ -401,8 +402,7 @@ BOOL CWinMgr::SendGetSizeInfo(SIZEINFO& szi, HWND hWnd, UINT nID)
//////////////////
// Get min/max info.
//
void
CWinMgr::GetMinMaxInfo(HWND hWnd, MINMAXINFO* lpMMI)
void CWinMgr::GetMinMaxInfo(HWND hWnd, MINMAXINFO* lpMMI)
{
SIZEINFO szi;
GetMinMaxInfo(hWnd, szi); // call overloaded version
@ -486,6 +486,7 @@ void CWinMgr::MoveRect(WINRECT* pwrcMove, POINT ptMove, HWND pParentWnd)
OffsetRect(pwrcMove->GetRect(), ptMove);
if (prev->IsGroup())
CalcGroup(prev, pParentWnd);
if (next->IsGroup())
CalcGroup(next, pParentWnd);
}

View File

@ -101,6 +101,7 @@ struct NumericStringEquivalence
lcmp = *str1 - *str2;
break;
}
if (_istdigit(*str1) && _istdigit(*str2))
{
lcmp = wcstol(str1, &p1, 10) - wcstol(str2, &p2, 10);
@ -417,6 +418,7 @@ intptr_t CALLBACK WindowsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
string docSizeText = to_string(docSize);
text = wstring(docSizeText.begin(), docSizeText.end());
}
if (static_cast<int>(text.length()) < pLvdi->item.cchTextMax)
{
// Copy the resulting text to destination with a null terminator.

View File

@ -231,8 +231,10 @@ wstring & LastRecentFileList::getItem(int id)
if (_lrfl.at(i)._id == id)
break;
}
if (i == _size)
i = 0;
return _lrfl.at(i)._name; //if not found, return first
}
@ -256,6 +258,7 @@ void LastRecentFileList::setUserMaxNbLRF(int size)
toPop--;
_size--;
}
updateMenu();
_size = _userMax;
}

View File

@ -621,6 +621,7 @@ void NativeLangSpeaker::changeLangTabDropContextMenu(HMENU hCM)
int cmdID = ::GetMenuItemID(hCM, POS_GO2VIEW);
::ModifyMenu(hCM, POS_GO2VIEW, MF_BYPOSITION|MF_STRING, cmdID, goToViewG);
}
if (cloneToViewA && cloneToViewA[0])
{
const wchar_t *cloneToViewG = wmc.char2wchar(cloneToViewA, _nativeLangEncoding);