Crated InsertMacroSplitButton webforms control instead of the hacky js code used to insert the split button in the template editor.

Have implemented it now in the EditView (will transition over its use in editTemplate soon but is low priority).
Have got the js callbacks working now for inserting a macro for the mvc editor but need to implement the correct syntax. Also need
to migrate and update the editMacro dialog screen to check if we are rendering for MVC or not and if it is MVC then use the correct
syntax.
This commit is contained in:
Shannon Deminick
2012-12-31 18:39:36 +03:00
parent eeabee22bd
commit b292cb3ab3
14 changed files with 436 additions and 133 deletions

View File

@@ -632,6 +632,7 @@
<Content Include="Umbraco_Client\Installer\Images\btn-confirm.png" />
<Content Include="Umbraco_Client\Installer\Images\pbar.gif" />
<Content Include="Umbraco_Client\Installer\Js\PackageInstaller.js" />
<Content Include="Umbraco_Client\Splitbutton\InsertMacroSplitButton.js" />
<Content Include="Umbraco_Client\Splitbutton\jquery.splitbutton.js" />
<Content Include="Umbraco_Client\Tags\Css\jquery.tagsinput.css" />
<Content Include="Umbraco_Client\Tags\Js\jquery.tagsinput.js" />

View File

@@ -1,6 +1,7 @@
<%@ Page MasterPageFile="../masterpages/umbracoPage.Master" Language="c#" CodeBehind="EditTemplate.aspx.cs"
ValidateRequest="false" AutoEventWireup="True" Inherits="Umbraco.Web.UI.Umbraco.Settings.EditTemplate" %>
<%@ Import Namespace="Umbraco.Core.IO" %>
<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>
<%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %>
<asp:Content ContentPlaceHolderID="head" runat="server">
@@ -162,7 +163,7 @@
if(alias != null && alias != ""){
t = "&alias="+alias;
}
UmbClientMgr.openModalWindow('<%= umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) %>/dialogs/editMacro.aspx?objectId=<%= editorSource.ClientID %>' + t, 'Insert Macro', true, 470, 530, 0, 0, '', '');
UmbClientMgr.openModalWindow('<%= IOHelper.ResolveUrl(SystemDirectories.Umbraco) %>/dialogs/editMacro.aspx?objectId=<%= editorSource.ClientID %>' + t, 'Insert Macro', true, 470, 530, 0, 0, '', '');
}
</script>

View File

@@ -3,6 +3,7 @@
ValidateRequest="False" %>
<%@ Import Namespace="Umbraco.Core" %>
<%@ Import Namespace="Umbraco.Core.IO" %>
<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>
<%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %>
<asp:Content ContentPlaceHolderID="head" runat="server">
@@ -10,11 +11,14 @@
<umb:JsInclude ID="JsInclude1" runat="server" FilePath="Editors/EditView.js" PathNameAlias="UmbracoClient" />
<script language="javascript" type="text/javascript">
//we need to have this as a global object since we reference this object with callbacks.
var editViewEditor;
(function ($) {
$(document).ready(function () {
//create a new EditView object
var editView = new Umbraco.Editors.EditView({
//create and assign a new EditView object
editViewEditor = new Umbraco.Editors.EditView({
editorType: "<%= EditorType.ToString() %>",
originalFileName: "<%=OriginalFileName %>",
restServiceLocation: "<%= Url.GetSaveFileServicePath() %>",
@@ -22,10 +26,12 @@
nameTxtBox: $("#<%= NameTxt.ClientID %>"),
aliasTxtBox: $("#<%= AliasTxt.ClientID %>"),
saveButton: $("#<%= ((Control)SaveButton).ClientID %>"),
templateId: '<%= Request.QueryString["templateID"] %>'
templateId: '<%= Request.QueryString["templateID"] %>',
codeEditorElementId: '<%= editorSource.ClientID %>',
modalUrl: "<%= IOHelper.ResolveUrl(SystemDirectories.Umbraco) %>/dialogs/editMacro.aspx"
});
//initialize it.
editView.init();
editViewEditor.init();
//bind save shortcut
UmbClientMgr.appActions().bindSaveShortCut();

View File

@@ -137,7 +137,6 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views
SaveButton = Panel1.Menu.NewIcon();
SaveButton.ImageURL = SystemDirectories.Umbraco + "/images/editor/save.gif";
//SaveButton.OnClickCommand = "doSubmit()";
SaveButton.AltText = ui.Text("save");
SaveButton.ID = "save";
@@ -167,14 +166,13 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views
640, 550);
umbDictionary.AltText = "Insert umbraco dictionary item";
//uicontrols.MenuIconI umbMacro = Panel1.Menu.NewIcon();
//umbMacro.ImageURL = UmbracoPath + "/images/editor/insMacro.gif";
//umbMacro.AltText = ui.Text("template", "insertMacro");
//umbMacro.OnClickCommand = umbraco.BasePages.ClientTools.Scripts.OpenModalWindow(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/dialogs/editMacro.aspx?objectId=" + editorSource.ClientID, ui.Text("template", "insertMacro"), 470, 530);
Panel1.Menu.NewElement("div", "splitButtonMacroPlaceHolder", "sbPlaceHolder", 40);
var macroSplitButton = new Controls.InsertMacroSplitButton
{
ClientCallbackInsertMacroMarkup = "function(alias) {editViewEditor.insertMacroMarkup(alias);}",
ClientCallbackOpenMacroModel = "function(alias) {editViewEditor.openMacroModal(alias);}"
};
Panel1.Menu.InsertNewControl(macroSplitButton, 40);
if (_template == null)
{
InitializeEditorForPartialView();
@@ -184,10 +182,6 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views
InitializeEditorForTemplate();
}
//Spit button
Panel1.Menu.InsertSplitter();
Panel1.Menu.NewElement("div", "splitButtonPlaceHolder", "sbPlaceHolder", 40);
}
protected override void OnPreRender(EventArgs e)
@@ -212,27 +206,28 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views
/// </summary>
private void InitializeEditorForTemplate()
{
if (UmbracoSettings.UseAspNetMasterPages)
{
Panel1.Menu.InsertSplitter();
//TODO: implement content placeholders, etc... just like we had in v5
MenuIconI umbContainer = Panel1.Menu.NewIcon();
umbContainer.ImageURL = UmbracoPath + "/images/editor/masterpagePlaceHolder.gif";
umbContainer.AltText = ui.Text("template", "insertContentAreaPlaceHolder");
umbContainer.OnClickCommand =
ClientTools.Scripts.OpenModalWindow(
IOHelper.ResolveUrl(SystemDirectories.Umbraco) +
"/dialogs/insertMasterpagePlaceholder.aspx?&id=" + _template.Id,
ui.Text("template", "insertContentAreaPlaceHolder"), 470, 320);
//Panel1.Menu.InsertSplitter();
MenuIconI umbContent = Panel1.Menu.NewIcon();
umbContent.ImageURL = UmbracoPath + "/images/editor/masterpageContent.gif";
umbContent.AltText = ui.Text("template", "insertContentArea");
umbContent.OnClickCommand =
ClientTools.Scripts.OpenModalWindow(
IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/dialogs/insertMasterpageContent.aspx?id=" +
_template.Id, ui.Text("template", "insertContentArea"), 470, 300);
}
//MenuIconI umbContainer = Panel1.Menu.NewIcon();
//umbContainer.ImageURL = UmbracoPath + "/images/editor/masterpagePlaceHolder.gif";
//umbContainer.AltText = ui.Text("template", "insertContentAreaPlaceHolder");
//umbContainer.OnClickCommand =
// ClientTools.Scripts.OpenModalWindow(
// IOHelper.ResolveUrl(SystemDirectories.Umbraco) +
// "/dialogs/insertMasterpagePlaceholder.aspx?&id=" + _template.Id,
// ui.Text("template", "insertContentAreaPlaceHolder"), 470, 320);
//MenuIconI umbContent = Panel1.Menu.NewIcon();
//umbContent.ImageURL = UmbracoPath + "/images/editor/masterpageContent.gif";
//umbContent.AltText = ui.Text("template", "insertContentArea");
//umbContent.OnClickCommand =
// ClientTools.Scripts.OpenModalWindow(
// IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/dialogs/insertMasterpageContent.aspx?id=" +
// _template.Id, ui.Text("template", "insertContentArea"), 470, 300);
}
}

View File

@@ -4,28 +4,27 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
(function($) {
Umbraco.Controls.CodeEditor.UmbracoEditor = function(isSimpleEditor, controlId) {
//initialize
var _isSimpleEditor = isSimpleEditor;
var _controlId = controlId;
if (!_isSimpleEditor && typeof(codeEditor) == "undefined") {
throw "CodeMirror editor not found!";
}
throw "CodeMirror editor not found!";
}
//create the inner object
var obj = {
var obj = {
_editor: (typeof(codeEditor) == "undefined" ? null : codeEditor), //the codemirror object
_control: $("#" + _controlId), //the original textbox as a jquery object
_cmSave: null,//the saved selection of the code mirror editor (used for IE)
IsSimpleEditor: typeof(CodeMirror) == "undefined" ? true : typeof(codeEditor) == "undefined" ? true : _isSimpleEditor,
GetCode: function() {
if (this.IsSimpleEditor) {
return this._control.val();
}
}
else {
//this is a wrapper for CodeMirror
return this._editor.getValue();
@@ -48,8 +47,8 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
//this is a wrapper for CodeMirror
this._editor.getSelection();
}
},
Insert: function(open, end, txtEl, arg3) {
},
Insert: function(open, end, txtEl, arg3) {
//arg3 gets appended to open, not actually sure why it's needed but we'll keep it for legacy, it's optional
if (_isSimpleEditor) {
if (navigator.userAgent.match('MSIE')) {
@@ -65,16 +64,16 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
jQuery("#" + txtEl).replaceSelection(replace);
jQuery("#" + txtEl).focus();
this._insertSimple(open, end, txtEl, arg3);
}
}
}
else {
this._editor.focus(); //need to restore the focus to the editor body
//if the saved selection (IE only) is not null, then
if (this._cmSave != null) {
this._editor.selectLines(this._cmSave.start.line, this._cmSave.start.character, this._cmSave.end.line, this._cmSave.end.character);
}
}
var selection = this._editor.getSelection();
var replace = (arg3) ? open + arg3 : open; //concat open and arg3, if arg3 specified
@@ -88,43 +87,48 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
_IEInsertSelection: function(open, end, txtEl) {
var tArea = document.getElementById(txtEl);
tArea.focus();
var open = (open) ? open : "";
var end = (end) ? end : "";
var curSelect = tArea.currRange;
open = (open) ? open : "";
end = (end) ? end : "";
var curSelect = tArea.currRange;
if (arguments[3]) {
if (end == "") {
curSelect.text = open + arguments[3];
} else {
}
else {
curSelect.text = open + arguments[3] + curSelect.text + end;
}
} else {
}
else {
if (end == "") {
curSelect.text = open;
} else {
}
else {
curSelect.text = open + curSelect.text + end;
}
}
curSelect.select();
},
},
_IESelectionHelper: function() {
/// <summary>
/// Because IE is lame, we have to continuously save the selections created by the user
/// in the editors so that when the selections are lost (i.e. the user types in a different text box
/// we'll need to restore the selection when they return focus
/// </summary>
if (document.all) {
/// <summary>
/// Because IE is lame, we have to continuously save the selections created by the user
/// in the editors so that when the selections are lost (i.e. the user types in a different text box
/// we'll need to restore the selection when they return focus
/// </summary>
if (document.all) {
var _this = this;
if (this._editor == null) {
if (this._editor == null) {
function storeCaret(editEl) {
editEl.currRange = document.selection.createRange().duplicate();
editEl.currRange = document.selection.createRange().duplicate();
}
//need to store the selection details on each event while editing content
this._control.select( function() {storeCaret(this)} );
this._control.click( function() {storeCaret(this)} );
this._control.keyup( function() {storeCaret(this)} );
this._control.select(function() { storeCaret(this) });
this._control.click(function() { storeCaret(this) });
this._control.keyup(function() { storeCaret(this) });
}
else {
/*
//Removed as its not needed in codemirror2 apparently
this._editor.options.cursorActivity = function() {
@@ -134,16 +138,16 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
}
}*/
}
}
}
}
};
// obj._IESelectionHelper();
// obj._IESelectionHelper();
// alert(obj);
// alert(obj);
return obj;
}
};
})(jQuery);

View File

@@ -30,6 +30,21 @@
});
},
insertMacroMarkup: function(alias) {
/// <summary>callback used to insert the markup for a macro with no parameters</summary>
UmbEditor.Insert("Helloworld!", "", this._opts.codeEditorElementId);
},
openMacroModal: function (alias) {
/// <summary>callback used to display the modal dialog to insert a macro with parameters</summary>
var t = "";
if (alias != null && alias != "") {
t = "&alias=" + alias;
}
UmbClientMgr.openModalWindow(this._opts.modalUrl + '?objectId=' + this._opts.codeEditorElementId + t, 'Insert Macro', true, 470, 530, 0, 0, '', '');
},
doSubmit: function () {
/// <summary>Submits the data to the server for saving</summary>
var codeVal = UmbClientMgr.contentFrame().UmbEditor.GetCode();

View File

@@ -0,0 +1,57 @@
Umbraco.Sys.registerNamespace("Umbraco.Controls");
(function ($) {
Umbraco.Controls.InsertMacroSplitButton = base2.Base.extend({
//private methods/variables
_opts: null,
// Constructor
constructor: function (opts) {
// Merge options with default
this._opts = $.extend({
// Default options go here
}, opts);
},
//public methods/variables
init: function () {
var self = this;
//the container is the 'scope' of which to find .sbPlaceHolder's, by default it is null so the scope is the whole page
var container = this._opts.container != null ? this._opts.container : null;
//setup the split buttons, find all .sbPlaceHolder's and assign the menu to it which should always
//be the previous element with the class .sbMenu
var splitButtons = $('.sbPlaceHolder', container);
splitButtons.each(function() {
var menu = $(this).prev(".sbMenu;");
$(this).find("a.sbLink").splitbutton({ menu: menu });
});
//assign the click handler to each macro item drop down
$(".sbMenu .macro-item").click(function () {
var alias = $(this).attr("rel");
if ($(this).attr("data-has-params") == "true") {
self._opts.openMacroModel.apply(self, [alias]);
}
else {
self._opts.insertMacroMarkup.apply(self, [alias]);
}
});
//assign the callback for the regular insert macro button (not the drop down)
$(".sbPlaceHolder a.sbLink").click(function() {
self._opts.openMacroModel.apply(self, []); //call the callback with no alias
});
//a fix for scroll issues TODO: put this code in this class and make it flexible (i.e. NOT with ids)
//applySplitButtonOverflow('mcontainer', 'innerc', 'macroMenu', '.macro-item', 'showMoreMacros');
}
});
})(jQuery);

View File

@@ -28,4 +28,5 @@ using System.Security;
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
[assembly: InternalsVisibleTo("Umbraco.Tests")]
[assembly: InternalsVisibleTo("umbraco.MacroEngines")]
[assembly: InternalsVisibleTo("umbraco.MacroEngines")]
[assembly: InternalsVisibleTo("Umbraco.Web.UI")]

View File

@@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using ClientDependency.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using umbraco.DataLayer;
namespace Umbraco.Web.UI.Controls
{
/// <summary>
/// Represents the 'insert macro' button when editing a template which includes the drop down list selector
/// </summary>
/// <remarks>
/// Though this would be nicer to do in a UserControl, unfortunatley the way that the ScrollingMenu control is designed it seems that
/// we have to insert all items via code and loading a UserControl in dynamically is equally ugly.
/// </remarks>
[ClientDependency(ClientDependencyType.Css, "splitbutton/splitbutton.css", "UmbracoClient")]
[ClientDependency(ClientDependencyType.Javascript, "splitbutton/jquery.splitbutton.js", "UmbracoClient", Priority = 100)]
[ClientDependency(ClientDependencyType.Javascript, "splitbutton/InsertMacroSplitButton.js", "UmbracoClient", Priority = 101)]
internal class InsertMacroSplitButton : UmbracoControl
{
protected LiteralControl ListContainer;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}
/// <summary>
/// The JS callback to display the dialog modal screen to customize the macro to be inserted into the editor if the
/// macro has parameters.
/// </summary>
public string ClientCallbackOpenMacroModel { get; set; }
/// <summary>
/// The JS callback method which accepts an 'alias' parameter that is invoked when clicking the macro button
/// to insert a macro that has no parameters.
/// </summary>
public string ClientCallbackInsertMacroMarkup { get; set; }
protected override void CreateChildControls()
{
base.CreateChildControls();
//var menuItemsId = ClientID + "menuitems";
//var placeHolderId = ClientID + "sbPlaceholder";
/*create the list, similar to this, but swap the repeater for real html:
<div id="macroMenu" style="width: 285px">
<asp:Repeater ID="rpt_macros" runat="server">
<ItemTemplate>
<div class="macro" rel="<%# DataBinder.Eval(Container, "DataItem.macroAlias")%>"
data-has-params="<%# DoesMacroHaveSettings(DataBinder.Eval(Container, "DataItem.id").ToString()) %>">
<%# DataBinder.Eval(Container, "DataItem.macroName")%>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
*/
//Create the drop down menu list first (it is hidden)
var divMacroItemContainer = new TagBuilder("div");
divMacroItemContainer.Attributes.Add("style", "width: 285px;display:none;");
divMacroItemContainer.Attributes.Add("class", "sbMenu");
using (var macroReader = SqlHelper.ExecuteReader("select id, macroAlias, macroName from cmsMacro order by macroName"))
{
while (macroReader.Read())
{
var divMacro = new TagBuilder("div");
divMacro.AddCssClass("macro-item");
divMacro.Attributes.Add("rel", macroReader.GetString("macroAlias"));
divMacro.Attributes.Add("data-has-params", DoesMacroHaveParameters(macroReader.GetInt("id")).ToString().ToLower());
divMacro.SetInnerText(macroReader.GetString("macroName"));
divMacroItemContainer.InnerHtml += divMacro.ToString();
}
}
/*create the button itself, similar to this:
<div id="splitButtonMacro" style="display: inline; height: 23px; vertical-align: top;">
<a href="javascript:openMacroModal();" class="sbLink">
<img alt="Insert Macro" src="../images/editor/insMacroSB.png" title="Insert Macro"
style="vertical-align: top;">
</a>
</div>
*/
var divSplitButtonWrapper = new TagBuilder("div");
divSplitButtonWrapper.AddCssClass("sbPlaceHolder");
divSplitButtonWrapper.Attributes.Add("id", ClientID + "sbPlaceholder");
var divButton = new TagBuilder("div");
divButton.Attributes.Add("style", "display: inline; height: 23px; vertical-align: top;");
var aButton = new TagBuilder("a");
aButton.Attributes.Add("href", "#"); //will be bound with jquery
aButton.AddCssClass("sbLink");
var imgButton = new TagBuilder("img");
imgButton.Attributes.Add("alt", "Insert Macro");
imgButton.Attributes.Add("src", this.ResolveUrl(SystemDirectories.Umbraco + "/images/editor/insMacroSB.png"));
imgButton.Attributes.Add("title", "Insert Macro");
imgButton.Attributes.Add("style", "vertical-align: top;");
aButton.InnerHtml = imgButton.ToString();
divButton.InnerHtml = aButton.ToString();
divSplitButtonWrapper.InnerHtml = divButton.ToString();
ListContainer = new LiteralControl(divMacroItemContainer.ToString() + divSplitButtonWrapper.ToString());
Controls.Add(ListContainer);
// Page.ClientScript.RegisterStartupScript(
// typeof(InsertMacroSplitButton),
// ClientID,
// @"jQuery(document).ready(function() {
// jQuery('#" + placeHolderId + " a.sbLink').splitbutton({menu:'#" + menuItemsId + "'}); " +
// "});",
// true);
Page.ClientScript.RegisterStartupScript(
typeof(InsertMacroSplitButton),
typeof(InsertMacroSplitButton).Name, //same key for all instancees, we should only render once
@"jQuery(document).ready(function() {
var splitButton = new Umbraco.Controls.InsertMacroSplitButton({
openMacroModel: " + ClientCallbackOpenMacroModel + @",
insertMacroMarkup: " + ClientCallbackInsertMacroMarkup + @"
});
splitButton.init();
});",
true);
}
private bool DoesMacroHaveParameters(int macroId)
{
return SqlHelper.ExecuteScalar<int>(string.Format("select 1 from cmsMacroProperty where macro = {0}", macroId)) == 1;
}
}
}

View File

@@ -0,0 +1,50 @@
using System.Web.UI;
using Umbraco.Core;
using Umbraco.Core.Services;
using umbraco.BusinessLogic;
using umbraco.DataLayer;
namespace Umbraco.Web.UI.Controls
{
/// <summary>
/// A control that exposes the helpful Umbraco context objects
/// </summary>
internal class UmbracoControl : Control
{
public UmbracoControl(UmbracoContext umbracoContext)
{
_umbracoContext = umbracoContext;
}
public UmbracoControl()
{
}
private UmbracoContext _umbracoContext;
protected UmbracoContext UmbracoContext
{
get { return _umbracoContext ?? (_umbracoContext = UmbracoContext.Current); }
}
protected ApplicationContext ApplicationContext
{
get { return UmbracoContext.Application; }
}
protected DatabaseContext DatabaseContext
{
get { return ApplicationContext.DatabaseContext; }
}
protected ServiceContext Services
{
get { return ApplicationContext.Services; }
}
/// <summary>
/// Returns the legacy SqlHelper
/// </summary>
protected ISqlHelper SqlHelper
{
get { return Application.SqlHelper; }
}
}
}

View File

@@ -335,6 +335,8 @@
<Compile Include="Templates\TemplateUtilities.cs" />
<Compile Include="Trees\PartialViewMacrosTree.cs" />
<Compile Include="Trees\PartialViewsTree.cs" />
<Compile Include="UI\Controls\InsertMacroSplitButton.cs" />
<Compile Include="UI\Controls\UmbracoControl.cs" />
<Compile Include="umbraco.presentation\Default.aspx.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
@@ -1945,7 +1947,9 @@
</Content>
<Content Include="umbraco.presentation\umbraco\dialogs\create.aspx" />
<Content Include="umbraco.presentation\umbraco\dialogs\cruds.aspx" />
<Content Include="umbraco.presentation\umbraco\dialogs\editMacro.aspx" />
<Content Include="umbraco.presentation\umbraco\dialogs\editMacro.aspx">
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="umbraco.presentation\umbraco\dialogs\emptyTrashcan.aspx" />
<Content Include="umbraco.presentation\umbraco\dialogs\exportDocumenttype.aspx" />
<Content Include="umbraco.presentation\umbraco\dialogs\imageViewer.aspx" />

View File

@@ -5,7 +5,8 @@ using ClientDependency.Core;
namespace umbraco.uicontrols {
[ClientDependency(ClientDependencyType.Css, "menuicon/style.css", "UmbracoClient")]
internal class MenuIcon : System.Web.UI.WebControls.Image, MenuIconI {
internal class MenuIcon : System.Web.UI.WebControls.Image, MenuIconI
{
private string _OnClickCommand = "";
private string _AltText = "init";

View File

@@ -18,3 +18,4 @@ using System.Runtime.InteropServices;
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1292737a-7e2d-464a-9850-9380792f668e")]
[assembly: InternalsVisibleTo("Umbraco.Web.UI")]

View File

@@ -9,7 +9,7 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ClientDependency.Core;
using umbraco.IO;
using Umbraco.Core.IO;
namespace umbraco.uicontrols {
@@ -17,53 +17,74 @@ namespace umbraco.uicontrols {
[ToolboxData("<{0}:ScrollingMenu runat=server></{0}:ScrollingMenu>")]
[ClientDependency(ClientDependencyType.Javascript, "scrollingmenu/javascript.js", "UmbracoClient")]
[ClientDependency(ClientDependencyType.Css, "scrollingmenu/style.css", "UmbracoClient")]
public class ScrollingMenu : System.Web.UI.WebControls.WebControl {
private ArrayList Icons = new ArrayList();
private string iconIds;
private int extraMenuWidth = 0;
private string _ClientFilesPath = IOHelper.ResolveUrl( SystemDirectories.Umbraco_client) + "/scrollingmenu/";
public class ScrollingMenu : System.Web.UI.WebControls.WebControl
{
private readonly ArrayList _icons = new ArrayList();
private string _iconIds;
private int _extraMenuWidth = 0;
private readonly string _clientFilesPath = IOHelper.ResolveUrl( SystemDirectories.UmbracoClient) + "/scrollingmenu/";
public MenuIconI NewIcon(int Index) {
MenuIcon Icon = new MenuIcon();
Icons.Insert(Index, Icon);
return Icon;
}
public MenuIconI NewIcon() {
public MenuIconI NewIcon(int index)
{
MenuIcon icon = new MenuIcon();
Icons.Add(icon);
_icons.Insert(index, icon);
return icon;
}
public MenuImageButton NewImageButton() {
public MenuIconI NewIcon()
{
MenuIcon icon = new MenuIcon();
_icons.Add(icon);
return icon;
}
public MenuImageButton NewImageButton()
{
MenuImageButton icon = new MenuImageButton();
Icons.Add(icon);
_icons.Add(icon);
return icon;
}
public MenuImageButton NewImageButton(int Index) {
public MenuImageButton NewImageButton(int index)
{
MenuImageButton icon = new MenuImageButton();
Icons.Insert(Index, icon);
_icons.Insert(index, icon);
return icon;
}
public System.Web.UI.WebControls.DropDownList NewDropDownList() {
DropDownList Icon = new DropDownList();
Icons.Add(Icon);
return Icon;
public DropDownList NewDropDownList()
{
DropDownList icon = new DropDownList();
_icons.Add(icon);
return icon;
}
public void NewElement(string ElementName, string ElementId, string ElementClass, int ExtraWidth) {
Icons.Add(new LiteralControl("<" + ElementName + " class=\"" + ElementClass + "\" id=\"" + ElementId + "\"></" + ElementName + ">"));
extraMenuWidth = extraMenuWidth + ExtraWidth;
public void NewElement(string elementName, string elementId, string elementClass, int extraWidth)
{
_icons.Add(new LiteralControl("<" + elementName + " class=\"" + elementClass + "\" id=\"" + elementId + "\"></" + elementName + ">"));
_extraMenuWidth = _extraMenuWidth + extraWidth;
}
public void InsertSplitter() {
/// <summary>
/// Inserts a new web control into the scrolling menu
/// </summary>
/// <param name="control"></param>
/// <param name="extraWidth">The additional width to extend the scrolling menu by if the control being inserted is wider than the standard</param>
public void InsertNewControl(Control control, int extraWidth = 0)
{
_icons.Add(control);
_extraMenuWidth = _extraMenuWidth + extraWidth;
}
public void InsertSplitter()
{
Splitter icon = new Splitter();
Icons.Add(icon);
_icons.Add(icon);
}
public void InsertSplitter(int Index) {
public void InsertSplitter(int index)
{
Splitter icon = new Splitter();
Icons.Insert(Index, icon);
_icons.Insert(index, icon);
}
/// <summary>
@@ -74,9 +95,9 @@ namespace umbraco.uicontrols {
public int FindSplitter(int n)
{
var count = 0;
for(var i=0; i<Icons.Count; i++)
for(var i=0; i<_icons.Count; i++)
{
if (Icons[i].GetType() == typeof(Splitter))
if (_icons[i].GetType() == typeof(Splitter))
{
count++;
@@ -88,17 +109,17 @@ namespace umbraco.uicontrols {
return -1;
}
protected override void OnLoad(System.EventArgs EventArguments) {
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (base.Visible)
{
SetupMenu();
SetupMenu();
}
}
private System.Web.UI.WebControls.Image scrollImage() {
private static System.Web.UI.WebControls.Image ScrollImage()
{
System.Web.UI.WebControls.Image functionReturnValue = null;
functionReturnValue = new System.Web.UI.WebControls.Image();
functionReturnValue.Width = Unit.Pixel(7);
@@ -110,22 +131,23 @@ namespace umbraco.uicontrols {
return functionReturnValue;
}
private void SetupMenu() {
private void SetupMenu()
{
// Calculate innerlayer max width 32 pixel per icon
int ScrollingLayerWidth = Icons.Count * 26 + extraMenuWidth;
var scrollingLayerWidth = _icons.Count * 26 + _extraMenuWidth;
Table Container = new Table();
Container.ID = String.Format("{0}_tableContainer", this.ID);
Table container = new Table();
container.ID = String.Format("{0}_tableContainer", this.ID);
TableRow tr = new TableRow();
tr.ID = String.Format("{0}_tableContainerRow", this.ID);
Container.Rows.Add(tr);
container.Rows.Add(tr);
// // scroll-left image
TableCell td = new TableCell();
td.ID = String.Format("{0}_tableContainerLeft", this.ID);
System.Web.UI.WebControls.Image scrollL = scrollImage();
scrollL.ImageUrl = _ClientFilesPath + "images/arrawBack.gif";
scrollL.Attributes.Add("onMouseOver", "this.className = 'editorArrowOver'; scrollR('" + this.ClientID + "_sl','" + this.ClientID + "_slh'," + ScrollingLayerWidth + ");");
System.Web.UI.WebControls.Image scrollL = ScrollImage();
scrollL.ImageUrl = _clientFilesPath + "images/arrawBack.gif";
scrollL.Attributes.Add("onMouseOver", "this.className = 'editorArrowOver'; scrollR('" + this.ClientID + "_sl','" + this.ClientID + "_slh'," + scrollingLayerWidth + ");");
td.Controls.Add(scrollL);
tr.Cells.Add(td);
@@ -150,7 +172,7 @@ namespace umbraco.uicontrols {
menuLayer.Style.Add("left", "0px");
menuLayer.Attributes.Add("class", "sl");
menuLayer.Style.Add("height", "26px");
menuLayer.Style.Add("width", ScrollingLayerWidth + "px");
menuLayer.Style.Add("width", scrollingLayerWidth + "px");
HtmlGenericControl nobr = new HtmlGenericControl();
nobr.TagName = "nobr";
@@ -158,15 +180,15 @@ namespace umbraco.uicontrols {
menuLayer.Controls.Add(nobr);
// // add all icons to the menu layer
foreach (Control item in Icons) {
foreach (Control item in _icons) {
menuLayer.Controls.Add(item);
if (item.ID != "") {
iconIds = iconIds + item.ID + ",";
_iconIds = _iconIds + item.ID + ",";
}
}
outerLayer.Controls.Add(new LiteralControl("<script>RegisterScrollingMenuButtons('" + this.ClientID + "', '" + iconIds + "');</script>"));
outerLayer.Controls.Add(new LiteralControl("<script>RegisterScrollingMenuButtons('" + this.ClientID + "', '" + _iconIds + "');</script>"));
outerLayer.Controls.Add(menuLayer);
@@ -175,13 +197,13 @@ namespace umbraco.uicontrols {
// // scroll-right image
td = new TableCell();
td.ID = String.Format("{0}_tableContainerRight", this.ID);
System.Web.UI.WebControls.Image scrollR = scrollImage();
scrollR.ImageUrl = _ClientFilesPath + "images/arrowForward.gif";
scrollR.Attributes.Add("onMouseOver", "this.className = 'editorArrowOver'; scrollL('" + this.ClientID + "_sl','" + this.ClientID + "_slh'," + ScrollingLayerWidth + ");");
System.Web.UI.WebControls.Image scrollR = ScrollImage();
scrollR.ImageUrl = _clientFilesPath + "images/arrowForward.gif";
scrollR.Attributes.Add("onMouseOver", "this.className = 'editorArrowOver'; scrollL('" + this.ClientID + "_sl','" + this.ClientID + "_slh'," + scrollingLayerWidth + ");");
td.Controls.Add(scrollR);
tr.Cells.Add(td);
this.Controls.Add(Container);
this.Controls.Add(container);
}
}