# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL-B license and that you accept its terms.
# ------------------------------------------------------------------------
-*/
+ */
/*
* modelCDMIProjectTreeNode.cpp
* Author: Daniel Felipe Gonzalez Obando
*/
#include "modelCDMIProjectTreeNode.h"
+#include <algorithm>
+
+#include "CDMUtilities.h"
-bool modelCDMIProjectTreeNode::CompareNodeItem(const modelCDMIProjectTreeNode& x, const modelCDMIProjectTreeNode& y)
+#include "wx/dir.h"
+
+bool modelCDMIProjectTreeNode::CompareNodeItem(const modelCDMIProjectTreeNode* x, const modelCDMIProjectTreeNode* y)
{
bool returnValue;
bool noWinner = true;
unsigned int i = 0;
- std::string xName = x.GetName();
- std::string yName = y.GetName();
- unsigned char xType = x.GetType();
- unsigned char yType = y.GetType();
+ std::string xName = x->GetName();
+ std::string yName = y->GetName();
+ unsigned char xType = x->GetType();
+ unsigned char yType = y->GetType();
while ((i < xName.length()) && (i < yName.length()))
- {
- if (tolower (xName[i]) < tolower (yName[i]))
{
- noWinner = false;
- returnValue = true;
- break;
+ if (tolower (xName[i]) < tolower (yName[i]))
+ {
+ noWinner = false;
+ returnValue = true;
+ break;
+ }
+ else if (tolower (xName[i]) > tolower (yName[i]))
+ {
+ noWinner = false;
+ returnValue = false;
+ break;
+ }
+ i++;
}
- else if (tolower (xName[i]) > tolower (yName[i]))
- {
- noWinner = false;
- returnValue = false;
- break;
- }
- i++;
- }
if(noWinner)
- {
- if (xName.length() < yName.length())
- returnValue = true;
- else
- returnValue = false;
- }
+ {
+ if (xName.length() < yName.length())
+ returnValue = true;
+ else
+ returnValue = false;
+ }
if(xType != yType)
- {
- if(xType == DT_DIR)
- returnValue = true;
- else
- returnValue = false;
- }
+ {
+ if(xType == wxDIR_DIRS)
+ returnValue = true;
+ else
+ returnValue = false;
+ }
return returnValue;
}
-const wxTreeItemId& modelCDMIProjectTreeNode::GetId() const
+const wxCDMTreeItemId& modelCDMIProjectTreeNode::GetId() const
{
return this->id;
}
return this->level;
}
+modelCDMIProjectTreeNode* modelCDMIProjectTreeNode::GetParent() const
+{
+ return this->parent;
+}
+
+std::vector<modelCDMIProjectTreeNode*> modelCDMIProjectTreeNode::GetParents() const
+{
+ std::vector<modelCDMIProjectTreeNode*> family;
+ modelCDMIProjectTreeNode* someFamily = this->parent;
+ while(someFamily != NULL)
+ {
+ family.push_back(someFamily);
+ someFamily = someFamily->GetParent();
+ }
+ return family;
+
+}
+
const std::vector<modelCDMIProjectTreeNode*>& modelCDMIProjectTreeNode::GetChildren() const
{
return this->children;
}
-void modelCDMIProjectTreeNode::SetId(const wxTreeItemId& id)
+void modelCDMIProjectTreeNode::SetId(const wxCDMTreeItemId& id)
{
this->id = id;
}
+void modelCDMIProjectTreeNode::SortChildren()
+{
+ std::sort(this->children.begin(), this->children.end(), CompareNodeItem);
+}
+
void modelCDMIProjectTreeNode::SetChildren(
const std::vector<modelCDMIProjectTreeNode*>& children)
{
return false;
}
+const int& modelCDMIProjectTreeNode::GetLength()
+{
+ return this->length;
+}
+
const bool modelCDMIProjectTreeNode::OpenInFileExplorer(std::string*& result) const
{
- //TODO: implement method
- return false;
+ if (!CDMUtilities::openFileExplorer(this->GetPath()))
+ return true;
+ else
+ {
+ result = new std::string("Couldn't open file.");
+ return false;
+ }
}