Custom Tree - Can't figure out how to add child nodes
Hello All, I am workign with Tim Geyssens on a new package called Optimus. A bundle & transfomer package.
In this package we have a custom tree for SASS & LESS dynamic CSS files. I have these items listing out in the tree perfectly fine, howver if I am trying to a child node/s to one of those items I cannot seem to be able to do it.
Can anyone please give me some guidance on where I am going wrong.
publicoverridevoid RenderJS(refStringBuilder Javascript)
{
Javascript.Append(
@" function openDyanmicCSSFileEditor(fileName, compiled) { UmbClientMgr.contentFrame('../App_Plugins/Optimus/Pages/FileEditor.aspx?file='+ fileName + '&path=/css/&compiled=' + compiled); }");
}
publicoverridevoid Render(refXmlTree tree)
{
if (String.IsNullOrEmpty(this.NodeKey))
{
//Create Top Level SASS or LESS nodes
TopLevelCSSNodes(ref tree);
}
else
{
//A SASS or LESS file has been selected with child static CSS file
CreateChildNodes(ref tree);
}
}
protectedvoid TopLevelCSSNodes(refXmlTree tree)
{
string orgPath = string.Empty;
string path = string.Empty;
string FilePath = "/css/";
path = IOHelper.MapPath(FilePath);
DirectoryInfo dirInfo = newDirectoryInfo(path);
DirectoryInfo[] dirInfos = dirInfo.GetDirectories();
var args = newTreeEventArgs(tree);
OnBeforeTreeRender(dirInfo, args);
//Loop through filesvar fileInfo = dirInfo.GetFilesByExtensions(new Translation.Core().GetPossibleExtensions(Enums.TranslatorType.StyleSheet).ToArray());
foreach (FileInfo file in fileInfo)
{
if ((file.Attributes & FileAttributes.Hidden) == 0)
{
XmlTreeNode xFileNode = XmlTreeNode.Create(this);
xFileNode.NodeID = orgPath + file.Name;
xFileNode.Text = file.Name;
xFileNode.OpenIcon = "doc.gif";
xFileNode.Menu = newList<IAction> { ActionDelete.Instance };
xFileNode.NodeType = "initstylesheetsNew";
xFileNode.Icon = new Optimus.Translation.Core().GetTranslatorTreeIconPath(file.Name);
//Check for compiled version of filevar fileName = file.FullName.TrimStart('/');
var staticFileName = fileName.Replace(".scss", ".css").Replace(".sass", ".css").Replace(".less", ".css");
//Check if compileFileName existsif (System.IO.File.Exists(staticFileName))
{
//Add a child node to the current node to display the static CSS file
xFileNode.HasChildren = true;
var functionToCall = "javascript:openDyanmicCSSFileEditor('" + orgPath + staticFileName + "', true')";
var nodeSourceURL = TreeUrlGenerator.GetServiceUrl(-1, "stylesheetsNew", false, false, "settings", orgPath + staticFileName, functionToCall);
xFileNode.Source = nodeSourceURL;
}
//CSS Action link...//Only run/set an action if it's empty (as in not been set above as static/compiled file)if (string.IsNullOrEmpty(xFileNode.Action))
{
if (orgPath != string.Empty)
{
xFileNode.Action = "javascript:openDyanmicCSSFileEditor('" + orgPath + file.Name + "', false');";
}
else
{
xFileNode.Action = "javascript:openDyanmicCSSFileEditor('" + file.Name + "', 'false');";
}
}
//OnRenderFileNode(ref xFileNode);
OnBeforeNodeRender(ref tree, ref xFileNode, EventArgs.Empty);
if (xFileNode != null)
{
tree.Add(xFileNode);
OnAfterNodeRender(ref tree, ref xFileNode, EventArgs.Empty);
}
}
}
//After TREE Rendering
OnAfterTreeRender(dirInfo, args);
}
protectedvoid CreateChildNodes(refXmlTree tree)
{
if (!string.IsNullOrEmpty(this.NodeKey))
{
string orgPath = string.Empty;
string path = string.Empty;
string FilePath = "/css/";
path = IOHelper.MapPath(FilePath);
XmlTreeNode xFileNode = XmlTreeNode.Create(this);
xFileNode.NodeID = orgPath + this.NodeKey;
xFileNode.Text = "BADGER";
xFileNode.OpenIcon = "doc.gif";
xFileNode.Menu = null;
xFileNode.NodeType = "initstylesheetsNew-Compiled";
xFileNode.Icon = new Optimus.Translation.Core().GetTranslatorTreeIconPath(this.NodeKey);
xFileNode.Action = "javascript:openDyanmicCSSFileEditor('" + orgPath + this.NodeKey + "', true');";
OnBeforeNodeRender(ref tree, ref xFileNode, EventArgs.Empty);
//Y U NO Add Child Node?!if (xFileNode != null)
{
tree.Add(xFileNode);
OnAfterNodeRender(ref tree, ref xFileNode, EventArgs.Empty);
}
}
}
protectedoverridevoid CreateRootNode(refXmlTreeNode rootNode)
{
rootNode.Icon = ".sprTreeFolder";
rootNode.OpenIcon = ".sprTreeFolder_o";
rootNode.NodeID = "init";
rootNode.NodeType = rootNode.NodeID + TreeAlias;
rootNode.Menu = newList<IAction> { ActionNew.Instance, ActionRefresh.Instance };
}
Hi Kevin, Yes I am using the TreeServiceURL call to generate the URL for this. See this bit of code for that:
var nodeSourceURL =TreeUrlGenerator.GetServiceUrl(-1,"stylesheetsNew",false,false,"settings", orgPath + staticFileName, functionToCall); xFileNode.Source= nodeSourceURL;
The tree knows it has to render out child nodes and the Render() event re-fires when the tree is expanded for the new levels and then runs the stub CreateChildNodes() which is simailar to TopLevelCSSNodes() and uses the Tree.Add(xFileNode) call but in the case for rendering out the child level it does not work, which I find highly odd.
Then in the render method, you can check for these IDs:
if (NodeKey == "less") { // the main less node } else if (NodeKey.StartsWith("less/") && NodeKey.EndsWith(".less")) { // do something for a less file } else if (NodeKey.StartsWith("less/")) { // must be a folder then }
I don't think I've seen TreeUrlGenerator.GetServiceUrl used before :) But assuming you're class is inheriting from BaseTree it's much easier to do as Anders suggested above:
Custom Tree - Can't figure out how to add child nodes
Hello All,
I am workign with Tim Geyssens on a new package called Optimus. A bundle & transfomer package.
In this package we have a custom tree for SASS & LESS dynamic CSS files. I have these items listing out in the tree perfectly fine, howver if I am trying to a child node/s to one of those items I cannot seem to be able to do it.
Can anyone please give me some guidance on where I am going wrong.
Thanks,
Warren :)
Comment author was deleted
Is it possible to add children to tree items you have to use a tree service? Just speculating.
The only trees I've made are one level deep. When I added a MNTP type deal into one of my projects, I had to use a tree service to get children.
Hi Kevin,
Yes I am using the TreeServiceURL call to generate the URL for this. See this bit of code for that:
The tree knows it has to render out child nodes and the Render() event re-fires when the tree is expanded for the new levels and then runs the stub CreateChildNodes() which is simailar to TopLevelCSSNodes() and uses the Tree.Add(xFileNode) call but in the case for rendering out the child level it does not work, which I find highly odd.
Warren
I think you're pretty close to nailing it. It seems that your main problem is, that you never modify orgPath, but still use the value for the NodeID.
If you you try to build your IDs like this, I believe you're close at nailing it:
-- LESS (id: "less")
-- Some folder (id: "less/Some folder")
-- Nested folder (id: "less/Some folder/Nested folder")
-- epic.less (id: "less/Some folder/Nested folder/epic.less")
Then in the render method, you can check for these IDs:
And here is the some code:
I don't think I've seen TreeUrlGenerator.GetServiceUrl used before :) But assuming you're class is inheriting from BaseTree it's much easier to do as Anders suggested above:
- Morten
is working on a reply...