From c8b70dacd7a25642c336b560194ab99cb7279b18 Mon Sep 17 00:00:00 2001 From: Don HO Date: Tue, 17 Dec 2019 22:40:46 +0100 Subject: [PATCH] Make for loop conform to C++11 style --- .../WinControls/FileBrowser/fileBrowser.cpp | 63 +++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index e83b3b11..76f47ebd 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -58,10 +58,10 @@ FileBrowser::~FileBrowser() { - for (size_t i = 0; i < _folderUpdaters.size(); ++i) + for (const auto folder : _folderUpdaters) { - _folderUpdaters[i]->stopWatcher(); - delete _folderUpdaters[i]; + folder->stopWatcher(); + delete folder; } } @@ -526,7 +526,7 @@ void FileBrowser::notified(LPNMHDR notification) openSelectFile(); } break; - + case TVN_ENDLABELEDIT: { LPNMTVDISPINFO tvnotif = (LPNMTVDISPINFO)notification; @@ -967,17 +967,16 @@ void FileBrowser::addRootFolder(generic_string rootFolderPath) rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } - size_t nbFolderUpdaters = _folderUpdaters.size(); - for (size_t i = 0; i < nbFolderUpdaters; ++i) + for (const auto f : _folderUpdaters) { - if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) + if (f->_rootFolder._rootPath == rootFolderPath) return; else { - if (isRelatedRootFolder(_folderUpdaters[i]->_rootFolder._rootPath, rootFolderPath)) + if (isRelatedRootFolder(f->_rootFolder._rootPath, rootFolderPath)) { //do nothing, go down to select the dir - generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath; + generic_string rootPath = f->_rootFolder._rootPath; generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size()); vector linarPathArray = split(pathSuffix, '\\'); @@ -987,7 +986,7 @@ void FileBrowser::addRootFolder(generic_string rootFolderPath) return; } - if (isRelatedRootFolder(rootFolderPath, _folderUpdaters[i]->_rootFolder._rootPath)) + if (isRelatedRootFolder(rootFolderPath, f->_rootFolder._rootPath)) { NppParameters::getInstance().getNativeLangSpeaker()->messageBox("FolderAsWorspaceSubfolderExists", _hParent, @@ -1036,15 +1035,16 @@ HTREEITEM FileBrowser::createFolderItemsFromDirStruct(HTREEITEM hParentItem, con hFolderItem = _treeView.addItem(directoryStructure._name.c_str(), hParentItem, INDEX_CLOSE_NODE); } - for (size_t i = 0; i < directoryStructure._subFolders.size(); ++i) + for (const auto& folder : directoryStructure._subFolders) { - createFolderItemsFromDirStruct(hFolderItem, directoryStructure._subFolders[i]); + createFolderItemsFromDirStruct(hFolderItem, folder); } - for (size_t i = 0; i < directoryStructure._files.size(); ++i) + for (const auto& file : directoryStructure._files) { - _treeView.addItem(directoryStructure._files[i]._name.c_str(), hFolderItem, INDEX_LEAF); + _treeView.addItem(file._name.c_str(), hFolderItem, INDEX_LEAF); } + _treeView.fold(hParentItem); return hFolderItem; @@ -1249,10 +1249,9 @@ bool FolderInfo::addToStructure(generic_string & fullpath, std::vector linarPathArrayFro { if (linarPathArrayFrom.size() == 1) // could be file or folder { - for (size_t i = 0; i < _files.size(); ++i) + for (auto& file : _files) { - if (_files[i].getName() == linarPathArrayFrom[0]) + if (file.getName() == linarPathArrayFrom[0]) { // rename this file - _files[i].setName(linarPathArrayTo[0]); + file.setName(linarPathArrayTo[0]); return true; } } - for (size_t i = 0; i < _subFolders.size(); ++i) + for (auto& folder : _subFolders) { - if (_subFolders[i].getName() == linarPathArrayFrom[0]) + if (folder.getName() == linarPathArrayFrom[0]) { // rename this folder - _subFolders[i].setName(linarPathArrayTo[0]); + folder.setName(linarPathArrayTo[0]); return true; } } @@ -1353,13 +1350,13 @@ bool FolderInfo::renameInStructure(std::vector linarPathArrayFro } else // folder { - for (size_t i = 0; i < _subFolders.size(); ++i) + for (auto& folder : _subFolders) { - if (_subFolders[i].getName() == linarPathArrayFrom[0]) + if (folder.getName() == linarPathArrayFrom[0]) { linarPathArrayFrom.erase(linarPathArrayFrom.begin()); linarPathArrayTo.erase(linarPathArrayTo.begin()); - return _subFolders[i].renameInStructure(linarPathArrayFrom, linarPathArrayTo); + return folder.renameInStructure(linarPathArrayFrom, linarPathArrayTo); } } return false;