Folder as Workspace enhancement

Try to open a sub-folder of an already opened folder will make a new
selection of this sub-folder.
This commit is contained in:
Don Ho 2016-02-11 15:04:29 +01:00
parent 3dbdb52448
commit ae4503ebbe
2 changed files with 29 additions and 52 deletions

View File

@ -228,7 +228,7 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
generic_string pathSuffix2 = file2Change[1].substr(sepPos2 + separator.length(), file2Change[1].length() - 1); generic_string pathSuffix2 = file2Change[1].substr(sepPos2 + separator.length(), file2Change[1].length() - 1);
vector<generic_string> linarPathArray2 = split(pathSuffix2, '\\'); vector<generic_string> linarPathArray2 = split(pathSuffix2, '\\');
bool isRenamed = renameInTree(rootPath, nullptr, linarPathArray, linarPathArray2); bool isRenamed = renameInTree(rootPath, nullptr, linarPathArray, linarPathArray2[linarPathArray2.size() - 1]);
if (not isRenamed) if (not isRenamed)
{ {
//MessageBox(NULL, file2Change[0].c_str(), TEXT("file/folder is not removed"), MB_OK); //MessageBox(NULL, file2Change[0].c_str(), TEXT("file/folder is not removed"), MB_OK);
@ -951,14 +951,21 @@ void FileBrowser::addRootFolder(generic_string rootFolderPath)
size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath);
if (pos == 0) if (pos == 0)
{ {
printStr(TEXT("do nothing, go down to select the dir.")); //do nothing, go down to select the dir
generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath;
generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size());
vector<generic_string> linarPathArray = split(pathSuffix, '\\');
HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray);
if (foundItem)
_treeView.selectItem(foundItem);
return; return;
} }
pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath);
if (pos == 0) if (pos == 0)
{ {
printStr(TEXT("remove old, add this one")); ::MessageBox(_hParent, TEXT("A sub-folder of the folder you want to open exists.\rPlease remove it from the panel before you add this one."), rootFolderPath.c_str(), MB_OK);
return; return;
} }
} }
@ -1144,25 +1151,19 @@ bool FileBrowser::addInTree(generic_string rootPath, generic_string addItemFullP
} }
} }
bool FileBrowser::deleteFromTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray) HTREEITEM FileBrowser::findInTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray)
{ {
if (node == nullptr) // it's a root. Search the right root with rootPath if (node == nullptr) // it's a root. Search the right root with rootPath
{ {
// Search // Search
if ((node = getRootFromFullPath(rootPath)) == nullptr) if ((node = getRootFromFullPath(rootPath)) == nullptr)
return false; return nullptr;
} }
if (linarPathArray.size() == 1) if (linarPathArray.size() == 1)
{ {
// Search // Search
HTREEITEM childNodeFound = findChildNodeFromName(node, linarPathArray[0]); return findChildNodeFromName(node, linarPathArray[0]);
if (childNodeFound == nullptr)
return false;
// found it, delete it
_treeView.removeItem(childNodeFound);
return true;
} }
else else
{ {
@ -1183,59 +1184,34 @@ bool FileBrowser::deleteFromTree(generic_string rootPath, HTREEITEM node, std::v
{ {
// search recursively the node for an action // search recursively the node for an action
linarPathArray.erase(linarPathArray.begin()); linarPathArray.erase(linarPathArray.begin());
return deleteFromTree(rootPath, hItemNode, linarPathArray); return findInTree(rootPath, hItemNode, linarPathArray);
} }
} }
return false; return nullptr;
} }
} }
bool FileBrowser::renameInTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArrayFrom, std::vector<generic_string> linarPathArrayTo) bool FileBrowser::deleteFromTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray)
{ {
if (node == nullptr) // it's a root. Search the right root with rootPath HTREEITEM foundItem = findInTree(rootPath, node, linarPathArray);
{ if (foundItem == nullptr)
// Search
if ((node = getRootFromFullPath(rootPath)) == nullptr)
return false; return false;
// found it, delete it
_treeView.removeItem(foundItem);
return true;
} }
if (linarPathArrayFrom.size() == 1) bool FileBrowser::renameInTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArrayFrom, const generic_string & renameTo)
{ {
// Search HTREEITEM foundItem = findInTree(rootPath, node, linarPathArrayFrom);
HTREEITEM childNodeFound = findChildNodeFromName(node, linarPathArrayFrom[0]); if (foundItem == nullptr)
if (childNodeFound == nullptr)
return false; return false;
// found it, rename it // found it, rename it
_treeView.renameItem(childNodeFound, linarPathArrayTo[0].c_str()); _treeView.renameItem(foundItem, renameTo.c_str());
return true; return true;
} }
else
{
HTREEITEM childNodeFound = nullptr;
for (HTREEITEM hItemNode = _treeView.getChildFrom(node);
hItemNode != NULL && childNodeFound == nullptr;
hItemNode = _treeView.getNextSibling(hItemNode))
{
TCHAR textBuffer[MAX_PATH];
TVITEM tvItem;
tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH;
tvItem.hItem = hItemNode;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0, (LPARAM)&tvItem);
if (linarPathArrayFrom[0] == tvItem.pszText)
{
// search recursively the node for an action
linarPathArrayFrom.erase(linarPathArrayFrom.begin());
linarPathArrayTo.erase(linarPathArrayTo.begin());
return renameInTree(rootPath, hItemNode, linarPathArrayFrom, linarPathArrayTo);
}
}
return false;
}
}
bool FolderInfo::addToStructure(generic_string & fullpath, std::vector<generic_string> linarPathArray) bool FolderInfo::addToStructure(generic_string & fullpath, std::vector<generic_string> linarPathArray)
{ {

View File

@ -161,8 +161,9 @@ public:
HTREEITEM FileBrowser::findChildNodeFromName(HTREEITEM parent, generic_string); HTREEITEM FileBrowser::findChildNodeFromName(HTREEITEM parent, generic_string);
bool addInTree(generic_string rootPath, generic_string addItemFullPath, HTREEITEM node, std::vector<generic_string> linarPathArray); bool addInTree(generic_string rootPath, generic_string addItemFullPath, HTREEITEM node, std::vector<generic_string> linarPathArray);
HTREEITEM findInTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray);
bool deleteFromTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray); bool deleteFromTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray);
bool renameInTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArrayFrom, std::vector<generic_string> linarPathArrayTo); bool renameInTree(generic_string rootPath, HTREEITEM node, std::vector<generic_string> linarPathArrayFrom, const generic_string & renameTo);
std::vector<generic_string> getRoots() const; std::vector<generic_string> getRoots() const;
generic_string getSelectedItemPath() const; generic_string getSelectedItemPath() const;
@ -179,7 +180,7 @@ protected:
void initPopupMenus(); void initPopupMenus();
void destroyMenus(); void destroyMenus();
BOOL setImageList(int root_clean_id, int root_dirty_id, int open_node_id, int closed_node_id, int leaf_id); BOOL setImageList(int root_open_id, int root_close_id, int open_node_id, int closed_node_id, int leaf_id);
HTREEITEM createNewFolder(HTREEITEM hTreeItem, const TCHAR *folderName); HTREEITEM createNewFolder(HTREEITEM hTreeItem, const TCHAR *folderName);