Files
Umbraco-CMS/src/Umbraco.Web/Trees/PartialViewsTree.cs
Shannon Deminick 0762decd92 Fixes up tree syncing for views, stylesheets and partial views. Now ensures we can actually
sync a tree for a file based node that doesn't have a static id. Also ensures that when we change a
Partial view name that we don't end up duplicating some files when we change it twice in the
same session.
2013-05-08 14:18:18 -10:00

78 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using umbraco.BusinessLogic.Actions;
using umbraco.businesslogic;
using umbraco.cms.businesslogic.template;
using umbraco.cms.presentation.Trees;
using umbraco.interfaces;
namespace Umbraco.Web.Trees
{
/// <summary>
/// Tree for displaying partial views in the settings app
/// </summary>
[Tree("settings", "partialViews", "Partial Views", sortOrder: 2)]
public class PartialViewsTree : FileSystemTree
{
public PartialViewsTree(string application) : base(application) { }
public override void RenderJS(ref StringBuilder javascript)
{
//NOTE: Notice the Partials%2f string below, this is a URLEncoded string of "Partials/" so that the editor knows
// to load the file from the correct location
javascript.Append(
@"
function openPartialView(id) {
UmbClientMgr.contentFrame('Settings/Views/EditView.aspx?treeType=partialViews&file=Partials%2f' + id);
}
");
}
protected override void CreateRootNode(ref XmlTreeNode rootNode)
{
rootNode.NodeType = TreeAlias;
rootNode.NodeID = "init";
}
protected override string FilePath
{
get { return SystemDirectories.MvcViews + "/Partials/"; }
}
protected override string FileSearchPattern
{
get { return "*.cshtml"; }
}
/// <summary>
/// Ensures that no folders can be added
/// </summary>
/// <param name="xNode"></param>
protected override void OnRenderFolderNode(ref XmlTreeNode xNode)
{
xNode = null;
}
protected virtual void ChangeNodeAction(XmlTreeNode xNode)
{
xNode.Action = xNode.Action.Replace("openFile", "openPartialView");
}
protected override void OnRenderFileNode(ref XmlTreeNode xNode)
{
ChangeNodeAction(xNode);
xNode.Icon = "settingView.gif";
xNode.OpenIcon = "settingView.gif";
}
}
}