protected void AddItem(ClientPipelineArgs args) { if (args.IsPostBack) { if (args.HasResult) { SetModified(); LastSelectedItemID = args.Result; SheerResponse.Eval("window.frames['{0}_frame'].window.scVisualList.addItem('{1}');".FormatWith(ID, args.Result)); } } else { var source = new UrlString(StringUtil.GetString(Source, "/sitecore/media library")).Path; Item lastSelectedItem = null; if (!string.IsNullOrEmpty(LastSelectedItemID)) { lastSelectedItem = Client.ContentDatabase.GetItem(LastSelectedItemID); } if (source.Contains("/sitecore/media library")) { var options = new MediaBrowserOptions(); if (source.StartsWith("~")) { options.Root = Client.GetItemNotNull(ItemIDs.MediaLibraryRoot); options.SelectedItem = Client.GetItemNotNull(source.Substring(1)); } else { options.Root = Client.GetItemNotNull(source); } if (lastSelectedItem != null && lastSelectedItem.Parent.Paths.IsDescendantOf(options.Root)) { options.SelectedItem = lastSelectedItem.Parent; } SheerResponse.ShowModalDialog(options.ToUrlString().ToString(), true); } else { var options = new SelectItemOptions { Title = "Please Select an Item", Text = "Select an item to add", Icon = "Applications/32x32/star_green.png" }; if (source.StartsWith("~")) { options.Root = Client.GetItemNotNull(ItemIDs.ContentRoot); options.SelectedItem = Client.GetItemNotNull(source.Substring(1)); } else { options.Root = Client.GetItemNotNull(source); } if (lastSelectedItem != null && lastSelectedItem.Paths.IsDescendantOf(options.Root)) { options.SelectedItem = lastSelectedItem; } SheerResponse.ShowModalDialog(options.ToUrlString().ToString(), true); } args.WaitForPostBack(); } }