using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.ExtendedControls;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.CMSHelper;
public partial class CMSAdminControls_UI_Macros_MacroTreeEditor : FormEngineUserControl
{
#region "Variables"
private bool mShowMacroTreeAbove = false;
#endregion
#region "Properties"
///
/// Gets client ID of the editor.
///
public override string ValueElementID
{
get
{
return editorElem.Editor.ClientID;
}
}
///
/// Gets or sets text in the editor.
///
public override string Text
{
get
{
return editorElem.Editor.Text;
}
set
{
editorElem.Editor.Text = value;
}
}
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
editorElem.Editor.Enabled = value;
btnShowTree.Enabled = false;
}
}
///
/// Name of the resolver to use.
///
public override string ResolverName
{
get
{
return editorElem.ResolverName;
}
set
{
editorElem.ResolverName = value;
treeElem.ResolverName = value;
}
}
///
/// Resolver to use.
///
public ContextResolver Resolver
{
get
{
return editorElem.Resolver;
}
set
{
editorElem.Resolver = value;
treeElem.ContextResolver = value;
}
}
///
/// Gets the ExtendedTextArea control.
///
public ExtendedTextArea Editor
{
get
{
return editorElem.Editor;
}
}
///
/// If true, tree is shown above the editor, otherwise it is below (default position is below).
///
public bool ShowMacroTreeAbove
{
get
{
return mShowMacroTreeAbove;
}
set
{
mShowMacroTreeAbove = value;
}
}
///
/// Gets or sets the left offset of the autocomplete control (to position it correctly).
///
public int LeftOffset
{
get
{
return editorElem.LeftOffset;
}
set
{
editorElem.LeftOffset = value;
}
}
///
/// Gets or sets the top offset of the autocomplete control (to position it correctly).
///
public int TopOffset
{
get
{
return editorElem.TopOffset;
}
set
{
editorElem.TopOffset = value;
}
}
///
/// Gets the name of java script object of the auto completion extender.
///
public string AutoCompletionObject
{
get
{
return editorElem.AutoCompletionObject;
}
}
///
/// Indicates wheter the control is on live site or not
///
public override bool IsLiveSite
{
get
{
return base.IsLiveSite;
}
set
{
base.IsLiveSite = value;
treeElem.IsLiveSite = value;
editorElem.IsLiveSite = value;
}
}
///
/// Gets or sets field value. You need to override this method to make the control work properly with the form.
///
public override object Value
{
get
{
return Editor.Text;
}
set
{
Editor.Text = ValidationHelper.GetString(value, "");
}
}
///
/// If true, Tree element is wrapped in the div with position:absolute.
///
public bool AbsolutePosition
{
get;
set;
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
editorElem.Editor.ShowToolbar = false;
editorElem.Editor.DynamicHeight = true;
editorElem.ShowAutoCompletionAbove = ShowMacroTreeAbove;
treeElem.OnNodeClickHandler = "nodeClick_" + ClientID;
btnShowTree.ToolTip = GetString("macros.editor.showhidetree");
btnShowTree.ImageUrl = GetImageUrl("General/Code.png");
btnShowTree.OnClientClick = GetShowHideScript();
pnlMacroTree.Style.Add("position", "absolute");
pnlMacroTree.Style.Add("display", "none");
pnlMacroTree.Attributes.Add("onmouseover", "macroTreeHasFocus = true;");
pnlMacroTree.Attributes.Add("onmouseout", "macroTreeHasFocus = false;");
if (AbsolutePosition)
{
pnlTreeWrapper.Style.Add("position", "absolute");
}
else
{
pnlTreeWrapper.Style.Add("position", "relative");
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// Register the main script
ScriptHelper.RegisterScriptFile(this.Page, "Macros/MacroTreeEditor.js");
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
// We need to generate this script on Render since extended area does that that late as well
// and editor object is not available before
string script = null;
if (this.editorElem.Editor.SyntaxHighlightingEnabled)
{
script = "function nodeClick_" + this.ClientID + "(macro) { nodeClick(macro, " + this.editorElem.Editor.EditorID + ", '" + this.pnlMacroTree.ClientID + "', '" + this.editorElem.Editor.ClientID + "'); }";
}
else
{
script = "function nodeClick_" + this.ClientID + "(macro) { nodeClick(macro, null, '" + this.pnlMacroTree.ClientID + "', '" + this.editorElem.Editor.ClientID + "'); }";
}
ScriptHelper.RegisterStartupScript(Page, typeof(string), "MacroTreeEditorScript_" + ClientID, script, true);
}
private string GetShowHideScript()
{
if (this.editorElem.Editor.SyntaxHighlightingEnabled)
{
return "showHideMacroTree('" + this.pnlMacroTree.ClientID + "', " + this.editorElem.Editor.EditorID + ", " + this.editorElem.AutoCompletionObject + ", " + this.LeftOffset + ", " + this.TopOffset + ", " + (this.ShowMacroTreeAbove ? "true" : "false") + ", false); return false;";
}
else
{
return "showHideMacroTree('" + this.pnlMacroTree.ClientID + "', null, null, " + this.LeftOffset + ", " + this.TopOffset + ", " + (this.ShowMacroTreeAbove ? "true" : "false") + ", false); return false;";
}
}
}