private void SetSubitemsSorting([NotNull] object sender, [NotNull] RoutedEventArgs e) { Debug.ArgumentNotNull(sender, nameof(sender)); Debug.ArgumentNotNull(e, nameof(e)); var context = Context; if (context == null) { return; } var item = context.SelectedItems.FirstOrDefault() as ItemTreeViewItem; if (item == null) { return; } var menuItem = e.Source as MenuItem; if (menuItem == null) { return; } var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Subitems Sorting"); var sortOrder = menuItem.Tag as string ?? string.Empty; ItemModifier.Edit(item.ItemUri, fieldId, sortOrder); item.Refresh(); }
private void CreateStandardValues(ItemUri templateUri) { var standardValuesItemUri = templateUri.Site.DataService.AddFromTemplate(templateUri, templateUri, @"__Standard Values"); if (standardValuesItemUri == ItemUri.Empty) { return; } var standardValuesFieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Advanced/Advanced/__Standard values"); var standardValuesField = new Field { Value = standardValuesItemUri.ItemId.ToString(), HasValue = true }; standardValuesField.FieldUris.Add(new FieldUri(new ItemVersionUri(templateUri, LanguageManager.CurrentLanguage, Data.Version.Latest), standardValuesFieldId)); var fields = new List <Field> { standardValuesField }; ItemModifier.Edit(standardValuesItemUri.DatabaseUri, fields, true); }
public void UpdateItem([NotNull] ItemUri itemUri, [NotNull] List <Tuple <FieldId, string> > fieldValues) { Assert.ArgumentNotNull(itemUri, nameof(itemUri)); Assert.ArgumentNotNull(fieldValues, nameof(fieldValues)); ItemModifier.Edit(itemUri, fieldValues); }
public void UpdateItem([NotNull] ItemUri itemUri, [NotNull] string fieldName, [NotNull] string value) { Assert.ArgumentNotNull(itemUri, nameof(itemUri)); Assert.ArgumentNotNull(fieldName, nameof(fieldName)); Assert.ArgumentNotNull(value, nameof(value)); ItemModifier.Edit(new ItemVersionUri(itemUri, Language.Current, Data.Version.Latest), fieldName, value); }
public void UpdateItem([NotNull] ItemVersionUri itemVersionUri, [NotNull] string fieldName, [NotNull] string value) { Assert.ArgumentNotNull(itemVersionUri, nameof(itemVersionUri)); Assert.ArgumentNotNull(fieldName, nameof(fieldName)); Assert.ArgumentNotNull(value, nameof(value)); ItemModifier.Edit(itemVersionUri, fieldName, value); }
public void UpdateItem([NotNull] ItemUri itemUri, [NotNull] FieldId fieldId, [NotNull] string value) { Assert.ArgumentNotNull(itemUri, nameof(itemUri)); Assert.ArgumentNotNull(fieldId, nameof(fieldId)); Assert.ArgumentNotNull(value, nameof(value)); ItemModifier.Edit(itemUri, fieldId, value); }
public override void Execute(object parameter) { var context = parameter as ContentTreeContext; if (context == null) { return; } var item = context.SelectedItems.FirstOrDefault() as ItemTreeViewItem; if (item == null) { return; } var parentUri = item.ItemUri; // create __Standard Values item var templateUri = item.ItemUri; var standardValuesItemUri = parentUri.Site.DataService.AddFromTemplate(parentUri, templateUri, @"__Standard Values"); if (standardValuesItemUri == ItemUri.Empty) { return; } // set "Standard Values" field var standardValuesFieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Advanced/Advanced/__Standard values"); var standardValuesField = new Field { Value = standardValuesItemUri.ItemId.ToString(), HasValue = true }; standardValuesField.FieldUris.Add(new FieldUri(new ItemVersionUri(item.ItemUri, LanguageManager.CurrentLanguage, Version.Latest), standardValuesFieldId)); var fields = new List <Field> { standardValuesField }; ItemModifier.Edit(standardValuesItemUri.DatabaseUri, fields, true); // expand tree context.ContentTree.ExpandTo(standardValuesItemUri); var itemVersionUri = new ItemVersionUri(standardValuesItemUri, LanguageManager.CurrentLanguage, Version.Latest); item.Item.StandardValuesId = standardValuesItemUri.ItemId; item.Item.StandardValuesField = standardValuesItemUri.ItemId; AppHost.OpenContentEditor(itemVersionUri); Notifications.RaiseItemAdded(this, itemVersionUri, parentUri); }
private void Save() { var publishFrom = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Publishing/Publishing/__Publish"); var publishTo = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Publishing/Publishing/__Unpublish"); var neverPublish = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Publishing/Publishing/__Never publish"); var validTo = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Lifetime/Lifetime/__Valid to"); var validFrom = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Lifetime/Lifetime/__Valid from"); var hideVersion = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Lifetime/Lifetime/__Hide version"); var publishingGroups = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Publishing/Publishing/__Publishing groups"); var fields = new List <Tuple <FieldUri, string> >(); fields.Add(new Tuple <FieldUri, string>(new FieldUri(ItemUri, publishFrom), ToIsoDateTime(ItemPublishFrom.Value))); fields.Add(new Tuple <FieldUri, string>(new FieldUri(ItemUri, publishTo), ToIsoDateTime(ItemPublishTo.Value))); fields.Add(new Tuple <FieldUri, string>(new FieldUri(ItemUri, neverPublish), ItemPublishable.IsChecked == true ? string.Empty : @"1")); foreach (var restriction in restrictions) { var itemVersionUri = new ItemVersionUri(ItemUri.ItemUri, ItemUri.Language, new Data.Version(restriction.Version)); fields.Add(new Tuple <FieldUri, string>(new FieldUri(itemVersionUri, validFrom), ToIsoDateTime(restriction.PublishFrom))); fields.Add(new Tuple <FieldUri, string>(new FieldUri(itemVersionUri, validTo), ToIsoDateTime(restriction.PublishTo))); fields.Add(new Tuple <FieldUri, string>(new FieldUri(itemVersionUri, hideVersion), restriction.Publishable ? string.Empty : @"1")); } var targets = string.Empty; foreach (var item in PublishingTargets.Items) { var listBoxItem = item as ListBoxItem; if (listBoxItem == null) { continue; } if (!listBoxItem.IsSelected) { continue; } var publishingTarget = listBoxItem.Tag as PublishingTarget; if (publishingTarget == null) { continue; } if (!string.IsNullOrEmpty(targets)) { targets += @"|"; } targets += publishingTarget.Id; } fields.Add(new Tuple <FieldUri, string>(new FieldUri(ItemUri, publishingGroups), targets)); ItemModifier.Edit(ItemUri.DatabaseUri, fields); }
protected override void UpdateFields(NewItemWizardPipeline pipeline, ProjectItem projectItem, ItemUri itemUri) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); Debug.ArgumentNotNull(projectItem, nameof(projectItem)); Debug.ArgumentNotNull(itemUri, nameof(itemUri)); var modelName = GetTypeName(pipeline, projectItem); ItemModifier.Edit(itemUri, new FieldId(new Guid("{EE9E23D2-181D-4172-A929-0E0B8D10313C}")), modelName); }
protected virtual void UpdateFields([NotNull] EnvDTE.ProjectItem projectItem, [NotNull] ItemUri itemUri, [NotNull] string fileName) { Debug.ArgumentNotNull(projectItem, nameof(projectItem)); Debug.ArgumentNotNull(itemUri, nameof(itemUri)); Debug.ArgumentNotNull(fileName, nameof(fileName)); if (!string.IsNullOrEmpty(PathFieldName)) { ItemModifier.Edit(itemUri, PathFieldName, "/" + fileName.Replace('\\', '/')); } }
public override void Execute(object parameter) { var context = parameter as IItemSelectionContext; if (context == null) { return; } var firstItem = context.Items.FirstOrDefault(); if (firstItem == null) { return; } var iconPath = firstItem.Icon.IconPath; foreach (var item in context.Items) { if (item.Icon.IconPath != iconPath) { iconPath = string.Empty; } } var n = iconPath.IndexOf("~/icon/", StringComparison.InvariantCultureIgnoreCase); if (n >= 0) { iconPath = iconPath.Mid(n + 7); } n = iconPath.IndexOf("/IconCache/", StringComparison.InvariantCultureIgnoreCase); if (n >= 0) { iconPath = iconPath.Mid(n + 11); } var d = new SetIconDialog(); d.Initialize(firstItem.ItemUri.Site, iconPath); if (AppHost.Shell.ShowDialog(d) != true) { return; } var value = d.FileName.Replace("32x32", "16x16"); foreach (var item in context.Items) { ItemModifier.Edit(item.ItemUri, FieldIds.Icon, value); } }
public void Fix(ValidationDescriptor validationDescriptor) { Assert.ArgumentNotNull(validationDescriptor, nameof(validationDescriptor)); var oldFieldType = Parse(validationDescriptor.Problem); var newFieldType = Parse(validationDescriptor.Solution); if (AppHost.MessageBox(string.Format("Are you sure you want to change the field type from \"{0}\" to \"{1}\"?", oldFieldType, newFieldType), "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK) { return; } ItemModifier.Edit(validationDescriptor.ItemUri, "Type", newFieldType); }
public override void Execute(object parameter) { var context = parameter as IItemSelectionContext; if (context == null) { return; } foreach (var item in context.Items) { ItemModifier.Edit(new ItemVersionUri(item.ItemUri, LanguageManager.CurrentLanguage, Version.Latest), FieldName, Value); } }
private void CopyNextTo([NotNull] DragCopyPipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); int sortOrder; int sortOrderDelta; ItemTreeViewItem parent; ItemTreeViewItem anchor; SortOrderHelper.GetSortOrder(pipeline.Target, pipeline.Position, pipeline.Items.Count(), out sortOrder, out sortOrderDelta, out parent, out anchor); if (parent == null) { AppHost.MessageBox(Resources.CopyItems_CopyNextTo_Parent_is_not_an_item, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); pipeline.Abort(); return; } pipeline.Owner = parent; pipeline.Anchor = anchor; var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Sortorder"); foreach (var item in pipeline.Items) { var newName = string.Format(Resources.CopyItems_CopyNextTo_Copy_of__0_, item.Name); var newItemUri = item.ItemUri.Site.DataService.Copy(item.ItemUri, parent.ItemUri.ItemId, newName); if (newItemUri == ItemUri.Empty) { AppHost.MessageBox(string.Format(Resources.CopyItems_CopyNextTo_Failed_to_copy___0_, item.Name), Resources.Error, MessageBoxButton.OK, MessageBoxImage.Information); pipeline.Abort(); return; } var newItem = new DragCopyPipeline.NewItem { Item = item, NewName = newName, NewItemUri = newItemUri, SortOrder = sortOrder }; ItemModifier.Edit(newItemUri, fieldId, sortOrder.ToString(CultureInfo.InvariantCulture)); sortOrder += sortOrderDelta; pipeline.NewItems.Add(newItem); } }
private void SetAllowed([NotNull] PlaceholderItem item, IEnumerable <ItemId> selectedItems) { var dialog = new SelectRenderingsDialog(); dialog.Initialize("Set Allowed Placeholders", item.DatabaseUri, selectedItems); if (AppHost.Shell.ShowDialog(dialog) != true) { return; } var itemUri = new ItemUri(item.DatabaseUri, new ItemId(new Guid(item.MetaDataItemId))); ItemModifier.Edit(itemUri, "{E391B526-D0C5-439D-803E-17512EAE6222}", string.Join("|", dialog.SelectedRenderings)); }
protected override void UpdateFields(EnvDTE.ProjectItem projectItem, ItemUri itemUri, string fileName) { Debug.ArgumentNotNull(projectItem, nameof(projectItem)); Debug.ArgumentNotNull(itemUri, nameof(itemUri)); Debug.ArgumentNotNull(fileName, nameof(fileName)); var className = GetFirstClass(projectItem); if (string.IsNullOrEmpty(className)) { return; } ItemModifier.Edit(itemUri, "Controller Name", className); }
protected override void UpdateFields(NewItemWizardPipeline pipeline, ProjectItem projectItem, ItemUri itemUri) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); Debug.ArgumentNotNull(projectItem, nameof(projectItem)); Debug.ArgumentNotNull(itemUri, nameof(itemUri)); var modelName = GetTypeName(pipeline, projectItem); var fieldValues = new List <Tuple <FieldId, string> >(); fieldValues.Add(new Tuple <FieldId, string>(new FieldId(new Guid("{1A0AE537-291C-4CC8-B53F-7CA307A0FEF5}")), modelName)); fieldValues.Add(new Tuple <FieldId, string>(new FieldId(new Guid("{298F7E71-8AEB-488B-BC93-CE6F2B09E130}")), "Index")); ItemModifier.Edit(itemUri, fieldValues); }
public override void Execute(object parameter) { var context = parameter as IItemSelectionContext; if (context == null) { return; } var templateId = TemplateHeader.TemplateUri.ItemId.ToString(); var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Template/Data/__Base template"); foreach (var item in context.Items) { ItemModifier.Edit(item.ItemUri, fieldId, templateId); } }
public override void Execute(object parameter) { var context = parameter as TemplateDesignerContext; if (context == null) { return; } var parentUri = context.TemplateDesigner.TemplateUri; // create __Standard Values item var templateUri = context.TemplateDesigner.TemplateUri; var standardValuesItemUri = parentUri.Site.DataService.AddFromTemplate(parentUri, templateUri, @"__Standard Values"); if (standardValuesItemUri == ItemUri.Empty) { return; } context.TemplateDesigner.StandardValueItemId = standardValuesItemUri.ItemId; // set "Standard Values" field var standardValuesField = new Field { Value = standardValuesItemUri.ItemId.ToString(), HasValue = true }; standardValuesField.FieldUris.Add(new FieldUri(new ItemVersionUri(templateUri, LanguageManager.CurrentLanguage, Version.Latest), FieldIds.StandardValues)); var fields = new List <Field> { standardValuesField }; ItemModifier.Edit(standardValuesItemUri.DatabaseUri, fields, true); // expand tree var itemVersionUri = new ItemVersionUri(standardValuesItemUri, LanguageManager.CurrentLanguage, Version.Latest); AppHost.OpenContentEditor(itemVersionUri); Notifications.RaiseItemAdded(this, itemVersionUri, parentUri); }
private void MoveNextTo([NotNull] DragMovePipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); int sortOrder; int sortOrderDelta; ItemTreeViewItem parent; ItemTreeViewItem anchor; SortOrderHelper.GetSortOrder(pipeline.Target, pipeline.Position, pipeline.Items.Count(), out sortOrder, out sortOrderDelta, out parent, out anchor); if (parent == null) { AppHost.MessageBox(Resources.MoveItems_MoveNextTo_Parent_is_not_an_item, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); pipeline.Abort(); return; } pipeline.Owner = parent; pipeline.Anchor = anchor; var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Sortorder"); foreach (var item in pipeline.Items) { if (!Move(item.ItemUri, parent.ItemUri)) { AppHost.MessageBox(string.Format(Resources.MoveItems_MoveNextTo_Failed_to_move___0_, item.Name), Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); break; } ItemModifier.Edit(item.ItemUri, fieldId, sortOrder.ToString()); var itemTreeViewItem = item as ItemTreeViewItem; if (itemTreeViewItem != null) { itemTreeViewItem.Item.SortOrder = sortOrder; } sortOrder += sortOrderDelta; pipeline.MovedItems.Add(item); } }
public void Save() { var databaseUri = DatabaseUri; var fields = new List <Tuple <FieldUri, string> >(); foreach (var dataTable in DataTables) { foreach (ResultDataRow dataRow in dataTable.Rows) { if (dataRow.RowState == DataRowState.Unchanged) { continue; } for (var index = 0; index < dataRow.ItemArray.Length; index++) { var fieldUri = dataRow.FieldArray[index]; if (fieldUri == null) { continue; } var value = dataRow.ItemArray[index]; if (value == null) { continue; } var v = value.ToString(); if (v == "\b") { v = string.Empty; } var field = new Tuple <FieldUri, string>(fieldUri, v); fields.Add(field); } } } ItemModifier.Edit(databaseUri, fields); }
protected override void UpdateFields(NewItemWizardPipeline pipeline, ProjectItem projectItem, ItemUri itemUri) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); Debug.ArgumentNotNull(projectItem, nameof(projectItem)); Debug.ArgumentNotNull(itemUri, nameof(itemUri)); var fileName = GetFileName(pipeline, projectItem); var pathFieldId = IdManager.GetFieldId("/sitecore/templates/System/Layout/Layout/Data/Path"); var fieldValues = new List <Tuple <FieldId, string> > { new Tuple <FieldId, string>(pathFieldId, fileName), }; ItemModifier.Edit(itemUri, fieldValues); projectItem.Project.LinkItemAndFile(itemUri, fileName); }
public override void Execute(object parameter) { var context = parameter as ContentTreeContext; if (context == null) { return; } var itemTreeViewItem = context.SelectedItems.FirstOrDefault() as ItemTreeViewItem; if (itemTreeViewItem == null) { return; } var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Template/Data/__Base template"); GetValueCompleted <Item> completed = delegate(Item item) { var field = item.Fields.FirstOrDefault(f => f.Name == "__Base template"); var selectedItems = field != null?field.Value.Split('|').Where(v => !string.IsNullOrWhiteSpace(v)).Select(id => new ItemId(new Guid(id))) : Enumerable.Empty <ItemId>(); var d = new SelectTemplatesDialog { HelpText = "Each data template inherits from zero or more base data templates, which in turn specify base templates.", Label = "Select the Base Templates:" }; d.Initialize(Resources.SetBaseTemplates_Execute_Base_Templates, item.ItemUri.DatabaseUri, selectedItems); if (AppHost.Shell.ShowDialog(d) != true) { return; } var baseTemplates = string.Join("|", d.SelectedTemplates.Select(i => i.ToString())); ItemModifier.Edit(item.ItemUri, fieldId, baseTemplates); }; itemTreeViewItem.ItemUri.Site.DataService.GetItemFieldsAsync(new ItemVersionUri(itemTreeViewItem.ItemUri, Language.Current, Data.Version.Latest), completed); }
public override void Execute(object parameter) { var context = parameter as IItemSelectionContext; if (context == null) { return; } foreach (var field in Fields) { foreach (var item in context.Items) { var itemVersionUri = new ItemVersionUri(item.ItemUri, Language.Current, Data.Version.Latest); ItemModifier.Edit(itemVersionUri, field.Item1.Name, field.Item2); } } }
public void UpdateItems([NotNull] List <Tuple <FieldUri, string> > fieldValues) { Assert.ArgumentNotNull(fieldValues, nameof(fieldValues)); var fieldValue = fieldValues.FirstOrDefault(); if (fieldValue == null) { return; } if (!fieldValues.AllHasValue(f => f.Item1.DatabaseUri)) { throw new InvalidOperationException("All items must have the same site and database."); } var databaseUri = fieldValue.Item1.ItemVersionUri.DatabaseUri; ItemModifier.Edit(databaseUri, fieldValues); }
protected override void Process(SaveItemPipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); var itemUri = pipeline.ContentModel.FirstItem.Uri.ItemUri; ExecuteCompleted callback = delegate(string response, ExecuteResult executeResult) { if (!DataService.HandleExecute(response, executeResult)) { return; } pipeline.Resume(); }; pipeline.Suspend(); ItemModifier.Edit(itemUri.DatabaseUri, pipeline.ContentModel.Fields, true, callback); }
public override void Execute(object parameter) { var context = parameter as IItemSelectionContext; if (context == null) { return; } if (AppHost.MessageBox("Are you sure you want to reset the layout to the standard value?", "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK) { return; } var databaseUri = DatabaseUri.Empty; var fields = new List <Field>(); var layoutFieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Layout/Layout/__Renderings"); foreach (var item in context.Items) { var field = new Field { ResetOnSave = true, HasValue = true, Value = string.Empty }; field.FieldUris.Add(new FieldUri(new ItemVersionUri(item.ItemUri, Language.Current, Version.Latest), layoutFieldId)); fields.Add(field); if (databaseUri == DatabaseUri.Empty) { databaseUri = item.ItemUri.DatabaseUri; } } ItemModifier.Edit(databaseUri, fields, false); }
protected void SetHelp(ItemVersionUri itemUri) { var item = itemUri.Site.DataService.GetItemFields(itemUri); var shortHelpField = item.Fields.FirstOrDefault(f => f != null && f.Name == "__Short description"); var longHelpField = item.Fields.FirstOrDefault(f => f != null && f.Name == "__Long description"); var shortHelp = shortHelpField != null ? shortHelpField.Value : string.Empty; var longHelp = longHelpField != null ? longHelpField.Value : string.Empty; var d = new SetHelpDialog(); d.Initialize(shortHelp, longHelp); if (AppHost.Shell.ShowDialog(d) != true) { return; } var shortProperty = d.GetType().GetField("ShortHelp", BindingFlags.NonPublic | BindingFlags.Instance); var shortHelpTextBox = shortProperty.GetValue(d) as TextBox; if (shortHelpTextBox != null) { shortHelp = shortHelpTextBox.Text ?? string.Empty; } var longProperty = d.GetType().GetField("LongHelp", BindingFlags.NonPublic | BindingFlags.Instance); var longHelpTextBox = longProperty.GetValue(d) as TextBox; if (longHelpTextBox != null) { longHelp = longHelpTextBox.Text ?? string.Empty; } ItemModifier.Edit(itemUri, "__Short description", shortHelp); ItemModifier.Edit(itemUri, "__Long description", longHelp); }
public override void Execute(object parameter) { var context = parameter as ContentTreeContext; if (context == null) { return; } var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Sortorder"); foreach (var i in context.SelectedItems) { var item = i as ItemTreeViewItem; if (item == null) { continue; } var sortOrder = 0; foreach (var obj in item.Items) { var child = obj as ItemTreeViewItem; if (child == null) { continue; } ItemModifier.Edit(child.Item.ItemUri, fieldId, sortOrder.ToString()); child.Item.SortOrder = sortOrder; sortOrder += 100; } } }
private static void GetAfterSortOrder([NotNull] ItemTreeViewItem target, int itemCount, out int sortOrder, out int sortOrderDelta, [CanBeNull] out ItemTreeViewItem parent, [CanBeNull] out ItemTreeViewItem anchor) { Debug.ArgumentNotNull(target, nameof(target)); sortOrder = target.Item.SortOrder; parent = null; anchor = null; var itemsControl = target.GetParentTreeViewItem(); if (itemsControl == null) { sortOrder += 100; sortOrderDelta = 100; return; } parent = itemsControl as ItemTreeViewItem; if (parent == null) { sortOrder -= itemCount * 100; sortOrderDelta = 100; return; } var index = itemsControl.Items.IndexOf(target); if (index < 0 || index == itemsControl.Items.Count - 1) { sortOrder += 100; sortOrderDelta = 100; return; } var nextItem = itemsControl.Items[index + 1] as ItemTreeViewItem; if (nextItem == null) { sortOrder += 100; sortOrderDelta = 100; return; } anchor = nextItem; var nextSortOrder = nextItem.Item.SortOrder; if (nextSortOrder == sortOrder) { var sort = 0; var fieldId = IdManager.GetFieldId("/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Sortorder"); for (var i = 0; i < parent.Items.Count; i++) { var item = parent.Items[i] as ItemTreeViewItem; if (item != null) { ItemModifier.Edit(item.Item.ItemUri, fieldId, sort.ToString()); item.Item.SortOrder = sort; } sort += i == index ? (itemCount + 1) * 100 : 100; } sortOrder = index * 100; nextSortOrder = sortOrder + (itemCount + 1) * 100; } var gap = nextSortOrder - sortOrder; sortOrderDelta = gap / (itemCount + 1); if (sortOrderDelta == 0) { sortOrder = sortOrder + (int)Math.Floor((double)gap / 2); return; } sortOrder += sortOrderDelta; }