Ejemplo n.º 1
0
nglString nuiFileTree::GetFileInfo(const nglPath& rPath)
{
  nglString str;
  nglPathInfo info;
  rPath.GetInfo(info);


  // file modification date
  nglTimeInfo timeInfo;
  nglString timestr;
  nglTime lastMod = info.LastMod;
  lastMod.GetLocalTime(timeInfo);
  timestr.Format(_T("%d/%d/%d, %d:%d"), timeInfo.Year+1900, timeInfo.Month, timeInfo.Day, timeInfo.Hours, timeInfo.Minutes);

  str.Append(timestr);
  
  if (rPath.IsLeaf())
  {
    // file size
    str.Append(_T(" - "));
    FormatFileSize(info.Size, str);
  }

  return str;
}
Ejemplo n.º 2
0
bool nuiFileTree::SetPath(const nglPath& rPath)
{
  mPath = rPath;
  
  nglPath path(rPath);
  path.MakeRelativeTo(GetRootPath());
  std::vector<nglString> tokens;
  path.GetPathName().Tokenize(tokens, _T('/'));
  nuiTreeNodePtr pNode = mpTreeView->GetTree();
  
  if (!tokens.empty())
  {
    // Find start node:
    nuiTreeNodePtr pRes = NULL;
    for (uint32 i = 0; i < pNode->GetChildrenCount() && !pRes; i++)
    {
      nuiTreeNodePtr pBNode = (nuiTreeNodePtr)pNode->GetChild(i);
      bool old = pBNode->IsOpened();
      nglPath p(pBNode->GetProperty(_T("Path")));
      
      
      if (p.GetNodeName() == tokens.at(0))
        pRes = pBNode;
      else
      {
        if (!old)
          pBNode->Open(true);
        for (uint32 j = 0; j < pBNode->GetChildrenCount() && !pRes; j++)
        {
          nuiTreeNodePtr pBNode2 = (nuiTreeNodePtr)pBNode->GetChild(j);
          nglPath p(pBNode2->GetProperty(_T("Path")));
          
          if (p.GetNodeName() == tokens.at(0))
            pRes = pBNode2;
        }
        if (!pRes && !old)
          pBNode->Open(false);
      }
    }
    
    if (!pRes)
      return false;
    
    pNode = pRes;
  }
  else
  {
    pNode = (nuiTreeNodePtr)pNode->GetChild(0);
  }
  
  
  pNode->Select(false);
  nuiColumnTreeView* pColTreeView = dynamic_cast<nuiColumnTreeView*>(mpTreeView);
  
  for (uint i = 0; i < tokens.size(); i++)
  {
    pNode->OpenAllChildren(false);
    pNode->SelectAllChildren(false);
    
    std::vector<nuiTreePtr> children;
    pNode->GetChildren(children);
    for (uint j = 0; j< children.size(); j++)
    {
      nuiFileSelectorNode* pBNode = dynamic_cast<nuiFileSelectorNode*>(children.at(j));
      if (pBNode)
      {
        nglPath p(pBNode->GetProperty(_T("Path")));
        if (p.GetNodeName() == tokens.at(i))
        {
          pNode = pBNode;
          break;
        }
      }
      
    }
    
    if (pNode == mpTreeView->GetSelectedNode()) // Have we found the next node?
      return false; // No next node found: bail out...
    
    nuiTreeNodePtr pParent = pNode;
    while (pParent)
    {
      if (!pParent->IsEmpty())
        pParent->Open(true);
      if (pColTreeView)
        pParent->Select(true);
      pParent = static_cast<nuiTreeNodePtr>(pParent->GetParent());
    }
    
    if (pColTreeView)
      mpTreeView->Select(pNode, true);
    
    if (pNode->IsEmpty()) // Bail out if the last node is a leaf
    {
      PathChanged();
      mpTreeView->SelectionChanged();
      mpTreeView->SetLayout(mpTreeView->GetIdealRect());

      return false;
    }
    
  }
  
  PathChanged();
  mpTreeView->SelectionChanged();
  mpTreeView->SetLayout(mpTreeView->GetIdealRect());
  
  // Update infos and change the edit line:
  nglPathInfo info;
  rPath.GetInfo(info);
    
  mpTreeView->SetHotRect(mpTreeView->GetHotRect());
  
  return true;
}