// change string to lower-case variant void rtypes::rutil_to_lower_ref(generic_string& sobj) { for (size_type i = 0;i<sobj.length();i++) if (sobj[i]>='A' && sobj[i]<='Z') sobj[i] -= 'A', sobj[i] += 'a'; }
static bool isDirectory(generic_string path) { DWORD type = ::GetFileAttributes(path.c_str()); return type != INVALID_FILE_ATTRIBUTES && (type & FILE_ATTRIBUTE_DIRECTORY); }
generic_string stringToUpper(generic_string strToConvert) { std::transform(strToConvert.begin(), strToConvert.end(), strToConvert.begin(), ::toupper); return strToConvert; }
void SmartHighlighter::highlightViewWithWord(ScintillaEditView * pHighlightView, const generic_string & word2Hilite) { // save target locations for other search functions auto originalStartPos = pHighlightView->execute(SCI_GETTARGETSTART); auto originalEndPos = pHighlightView->execute(SCI_GETTARGETEND); // Get the range of text visible and highlight everything in it auto firstLine = static_cast<int>(pHighlightView->execute(SCI_GETFIRSTVISIBLELINE)); auto nbLineOnScreen = pHighlightView->execute(SCI_LINESONSCREEN); auto nbLines = min(nbLineOnScreen, MAXLINEHIGHLIGHT) + 1; auto lastLine = firstLine + nbLines; int startPos = 0; int endPos = 0; auto currentLine = firstLine; int prevDocLineChecked = -1; //invalid start // Determine mode for SmartHighlighting bool isWordOnly = true; bool isCaseSensentive = true; const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); if (nppGUI._smartHiliteUseFindSettings) { // fetch find dialog's setting NppParameters *nppParams = NppParameters::getInstance(); FindHistory &findHistory = nppParams->getFindHistory(); isWordOnly = findHistory._isMatchWord; isCaseSensentive = findHistory._isMatchCase; } else { isWordOnly = nppGUI._smartHiliteWordOnly; isCaseSensentive = nppGUI._smartHiliteCaseSensitive; } FindOption fo; fo._isMatchCase = isCaseSensentive; fo._isWholeWord = isWordOnly; FindReplaceInfo frInfo; frInfo._txt2find = word2Hilite.c_str(); for (; currentLine < lastLine; ++currentLine) { int docLine = static_cast<int>(pHighlightView->execute(SCI_DOCLINEFROMVISIBLE, currentLine)); if (docLine == prevDocLineChecked) continue; //still on same line (wordwrap) prevDocLineChecked = docLine; startPos = static_cast<int>(pHighlightView->execute(SCI_POSITIONFROMLINE, docLine)); endPos = static_cast<int>(pHighlightView->execute(SCI_POSITIONFROMLINE, docLine + 1)); frInfo._startRange = startPos; frInfo._endRange = endPos; if (endPos == -1) { //past EOF frInfo._endRange = pHighlightView->getCurrentDocLen() - 1; _pFRDlg->processRange(ProcessMarkAll_2, frInfo, NULL, &fo, -1, pHighlightView); break; } else { _pFRDlg->processRange(ProcessMarkAll_2, frInfo, NULL, &fo, -1, pHighlightView); } } // restore the original targets to avoid conflicts with the search/replace functions pHighlightView->execute(SCI_SETTARGETRANGE, originalStartPos, originalEndPos); }
file_entry::file_entry(const generic_string& sname) { _load(sname.c_str()); }
bool filename::rename(const generic_string& name,bool keepNewName,bool overwrite) { return rename(name.c_str(),keepNewName,overwrite); }
bool filename::copy(const generic_string& toFile,bool overwrite) const { return copy(toFile.c_str(),overwrite); }
void FileBrowser::notified(LPNMHDR notification) { if ((notification->hwndFrom == _treeView.getHSelf())) { TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; tvItem.mask = TVIF_TEXT | TVIF_PARAM; tvItem.pszText = textBuffer; tvItem.cchTextMax = MAX_PATH; switch (notification->code) { case NM_DBLCLK: { openSelectFile(); } break; case TVN_ENDLABELEDIT: { LPNMTVDISPINFO tvnotif = (LPNMTVDISPINFO)notification; if (!tvnotif->item.pszText) return; if (getNodeType(tvnotif->item.hItem) == browserNodeType_root) return; // Processing for only File case if (tvnotif->item.lParam) { // Get the old label tvItem.hItem = _treeView.getSelection(); ::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); size_t len = lstrlen(tvItem.pszText); // Find the position of old label in File path generic_string *filePath = (generic_string *)tvnotif->item.lParam; size_t found = filePath->rfind(tvItem.pszText); // If found the old label, replace it with the modified one if (found != generic_string::npos) filePath->replace(found, len, tvnotif->item.pszText); // Check the validity of modified file path tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; if (::PathFileExists(filePath->c_str())) { tvItem.iImage = INDEX_LEAF; tvItem.iSelectedImage = INDEX_LEAF; } else { //TODO: remove it } TreeView_SetItem(_treeView.getHSelf(), &tvItem); } // For File, Folder and Project ::SendMessage(_treeView.getHSelf(), TVM_SETITEM, 0,(LPARAM)(&(tvnotif->item))); } break; case TVN_GETINFOTIP: { LPNMTVGETINFOTIP lpGetInfoTip = (LPNMTVGETINFOTIP)notification; static generic_string tipStr; BrowserNodeType nType = getNodeType(lpGetInfoTip->hItem); if (nType == browserNodeType_root) { tipStr = *((generic_string *)lpGetInfoTip->lParam); } else if (nType == browserNodeType_file) { tipStr = getNodePath(lpGetInfoTip->hItem); } else return; lpGetInfoTip->pszText = (LPTSTR)tipStr.c_str(); lpGetInfoTip->cchTextMax = tipStr.size(); } break; case TVN_KEYDOWN: { LPNMTVKEYDOWN ptvkd = (LPNMTVKEYDOWN)notification; if (ptvkd->wVKey == VK_RETURN) { HTREEITEM hItem = _treeView.getSelection(); BrowserNodeType nType = getNodeType(hItem); if (nType == browserNodeType_file) openSelectFile(); else _treeView.toggleExpandCollapse(hItem); } /* else if (ptvkd->wVKey == VK_DELETE) { HTREEITEM hItem = _treeView.getSelection(); BrowserNodeType nType = getNodeType(hItem); if (nType == browserNodeType_folder) popupMenuCmd(IDM_FILEBROWSER_DELETEFOLDER); else if (nType == browserNodeType_file) popupMenuCmd(IDM_FILEBROWSER_DELETEFILE); } else if (ptvkd->wVKey == VK_UP) { if (0x80 & GetKeyState(VK_CONTROL)) { popupMenuCmd(IDM_FILEBROWSER_MOVEUP); } } else if (ptvkd->wVKey == VK_DOWN) { if (0x80 & GetKeyState(VK_CONTROL)) { popupMenuCmd(IDM_FILEBROWSER_MOVEDOWN); } } else if (ptvkd->wVKey == VK_F2) popupMenuCmd(IDM_FILEBROWSER_RENAME); */ } break; case TVN_ITEMEXPANDED: { LPNMTREEVIEW nmtv = (LPNMTREEVIEW)notification; tvItem.hItem = nmtv->itemNew.hItem; tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; if (getNodeType(nmtv->itemNew.hItem) == browserNodeType_folder) { if (nmtv->action == TVE_COLLAPSE) { _treeView.setItemImage(nmtv->itemNew.hItem, INDEX_CLOSE_NODE, INDEX_CLOSE_NODE); } else if (nmtv->action == TVE_EXPAND) { _treeView.setItemImage(nmtv->itemNew.hItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE); } } else if (getNodeType(nmtv->itemNew.hItem) == browserNodeType_root) { if (nmtv->action == TVE_COLLAPSE) { _treeView.setItemImage(nmtv->itemNew.hItem, INDEX_CLOSE_ROOT, INDEX_CLOSE_ROOT); } else if (nmtv->action == TVE_EXPAND) { _treeView.setItemImage(nmtv->itemNew.hItem, INDEX_OPEN_ROOT, INDEX_OPEN_ROOT); } } } break; case TVN_BEGINDRAG: { //printStr(TEXT("hello")); _treeView.beginDrag((LPNMTREEVIEW)notification); } break; } } }
DWORD WINAPI FolderUpdater::watching(void *params) { FolderUpdater *thisFolderUpdater = (FolderUpdater *)params; generic_string dir2Watch = (thisFolderUpdater->_rootFolder)._rootPath; if (dir2Watch[dir2Watch.length() - 1] != '\\') dir2Watch += TEXT("\\"); // CReadDirectoryChanges will add another '\' so we will get "\\" as a separator (of monitored root) in the notification const DWORD dwNotificationFlags = FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME; // Create the monitor and add directory to watch. CReadDirectoryChanges changes; changes.AddDirectory(dir2Watch.c_str(), true, dwNotificationFlags); HANDLE changeHandles[] = { thisFolderUpdater->_EventHandle, changes.GetWaitHandle() }; bool toBeContinued = true; while (toBeContinued) { DWORD waitStatus = ::WaitForMultipleObjects(_countof(changeHandles), changeHandles, FALSE, INFINITE); switch (waitStatus) { case WAIT_OBJECT_0 + 0: // Mutex was signaled. User removes this folder or file browser is closed toBeContinued = false; break; case WAIT_OBJECT_0 + 1: // We've received a notification in the queue. { DWORD dwAction; CStringW wstrFilename; if (changes.CheckOverflow()) printStr(L"Queue overflowed."); else { changes.Pop(dwAction, wstrFilename); static generic_string oldName; static std::vector<generic_string> file2Change; file2Change.clear(); switch (dwAction) { case FILE_ACTION_ADDED: file2Change.push_back(wstrFilename.GetString()); //thisFolderUpdater->updateTree(dwAction, file2Change); ::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_ADDFILE, (WPARAM)nullptr, (LPARAM)&file2Change); oldName = TEXT(""); break; case FILE_ACTION_REMOVED: file2Change.push_back(wstrFilename.GetString()); //thisFolderUpdater->updateTree(dwAction, file2Change); ::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RMFILE, (WPARAM)nullptr, (LPARAM)&file2Change); oldName = TEXT(""); break; case FILE_ACTION_MODIFIED: oldName = TEXT(""); break; case FILE_ACTION_RENAMED_OLD_NAME: oldName = wstrFilename.GetString(); break; case FILE_ACTION_RENAMED_NEW_NAME: if (not oldName.empty()) { file2Change.push_back(oldName); file2Change.push_back(wstrFilename.GetString()); //thisFolderUpdater->updateTree(dwAction, file2Change); ::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RNFILE, (WPARAM)nullptr, (LPARAM)&file2Change); } oldName = TEXT(""); break; default: oldName = TEXT(""); break; } } } break; case WAIT_IO_COMPLETION: // Nothing to do. break; } } // Just for sample purposes. The destructor will // call Terminate() automatically. changes.Terminate(); //printStr(L"Quit watching thread"); return EXIT_SUCCESS; }