public override bool GetChildren(GetChildrenDelegate callback, bool async)
        {
            Assert.ArgumentNotNull(callback, nameof(callback));

            var result = new List <BaseSiteTreeViewItem>();

            var children = Site.DataService.GetRootItems(DatabaseUri).ToList();

            if (!children.Any())
            {
                return(false);
            }

            foreach (var child in children)
            {
                var item = new ItemTreeViewItem(child);

                if (child.HasChildren)
                {
                    item.MakeExpandable();
                }

                result.Add(item);
            }

            callback(result);

            return(true);
        }
Пример #2
0
        private void HandleSolutionExplorerDrop([NotNull] ItemTreeViewItem target, [NotNull] DragEventArgs e)
        {
            Diagnostics.Debug.ArgumentNotNull(target, nameof(target));
            Diagnostics.Debug.ArgumentNotNull(e, nameof(e));

            var droppedFileName = e.Data.GetData(DataFormats.Text, true) as string;

            if (droppedFileName == null)
            {
                return;
            }

            var project = AppHost.Projects.FirstOrDefault(p => droppedFileName.StartsWith(p.FolderName, StringComparison.InvariantCultureIgnoreCase));

            if (project == null)
            {
                return;
            }

            var relativeFileName = project.GetRelativeFileName(droppedFileName);

            if (AppHost.MessageBox(string.Format("Are you sure you want to bind:\n\n\\{0}\n\nto:\n\n{1}", relativeFileName, target.Item.Path), "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
            {
                return;
            }

            project.LinkItemAndFile(target.ItemUri, relativeFileName);
        }
Пример #3
0
        private void TransferItems([NotNull] ItemTreeViewItem target, [NotNull] IEnumerable <IItem> items)
        {
            Diagnostics.Debug.ArgumentNotNull(target, nameof(target));
            Diagnostics.Debug.ArgumentNotNull(items, nameof(items));

            var options = new TaskDialogOptions
            {
                Owner           = this.GetAncestorOrSelf <Window>(),
                Title           = "Transfer Items",
                CommonButtons   = TaskDialogCommonButtons.None,
                MainInstruction = "Are you sure you want to transfer these items to another database?",
                Content         = "Any item dependencies will not be copied.",
                MainIcon        = VistaTaskDialogIcon.Information,
                CommandButtons  = new[]
                {
                    "Copy Items",
                    "Copy Items and SubItems",
                    "Copy Items - Change Item IDs",
                    "Copy Items and SubItems - Change Item IDs"
                },
                AllowDialogCancellation = true
            };

            var r = TaskDialog.Show(options).CommandButtonResult;

            if (r == null)
            {
                return;
            }

            var transfer = new TransferDialog(target, items, r == 1 || r == 3, r == 2 || r == 3);

            AppHost.Shell.ShowDialog(transfer);
        }
Пример #4
0
        private void HandleItemDrop([NotNull] ItemTreeViewItem target, [NotNull] DragEventArgs e)
        {
            Diagnostics.Debug.ArgumentNotNull(target, nameof(target));
            Diagnostics.Debug.ArgumentNotNull(e, nameof(e));

            var items = e.Data.GetData(DragManager.DragIdentifier) as IEnumerable <IItem>;

            if (items == null)
            {
                Diagnostics.Trace.Expected(typeof(IEnumerable <IItem>));
                return;
            }

            var isSameDatabase = items.All(i => i.ItemUri.DatabaseUri == target.ItemUri.DatabaseUri);

            if (!isSameDatabase)
            {
                TransferItems(target, items);
                return;
            }

            switch (GetDragOperation(e, target, items, true))
            {
            case DragOperation.Copy:
                DragCopyPipeline.Run().WithParameters(target, items, adorner.LastPosition, e.KeyStates);
                break;

            case DragOperation.Move:
                DragMovePipeline.Run().WithParameters(target, items, adorner.LastPosition, e.KeyStates);
                break;
            }
        }
Пример #5
0
        private void HandleDropFiles([NotNull] string[] droppedFilePaths)
        {
            Diagnostics.Debug.ArgumentNotNull(droppedFilePaths, nameof(droppedFilePaths));

            var site = Item.ItemUri.Site;

            if (!site.DataService.CanExecuteAsync("Media.Upload"))
            {
                AppHost.MessageBox(string.Format(Rocks.Resources.MediaSkinListBox_HandleDropFiles_, site.DataServiceName), Rocks.Resources.Information, MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            GetValueCompleted <ItemHeader> uploadCompleted = delegate(ItemHeader value)
            {
                if (droppedFilePaths.Length != 1)
                {
                    return;
                }

                var item = new ItemTreeViewItem(value);
                Items.Add(item);

                var itemVersionUri = new ItemVersionUri(value.ItemUri, LanguageManager.CurrentLanguage, Data.Version.Latest);

                AppHost.OpenContentEditor(itemVersionUri);
            };

            MediaManager.Upload(Item.ItemUri.DatabaseUri, Item.Path, droppedFilePaths, uploadCompleted);
        }
Пример #6
0
        private DragOperation GetDragOperation([NotNull] DragEventArgs e, [NotNull] ItemTreeViewItem target, [NotNull] IEnumerable <IItem> items, bool isSameDatabase)
        {
            Diagnostics.Debug.ArgumentNotNull(e, nameof(e));
            Diagnostics.Debug.ArgumentNotNull(target, nameof(target));
            Diagnostics.Debug.ArgumentNotNull(items, nameof(items));

            if (!isSameDatabase)
            {
                return(DragOperation.Copy);
            }

            if (items.Count() == 1 && (e.KeyStates & DragDropKeyStates.AltKey) == DragDropKeyStates.AltKey)
            {
                var item = items.First() as ItemTreeViewItem;

                if (item != null && item.IsTemplate)
                {
                    var path = target.GetPath();
                    if (!path.StartsWith(@"/sitecore/templates", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(DragOperation.CreateItem);
                    }
                }
            }

            if ((e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey)
            {
                return(DragOperation.Copy);
            }

            return(DragOperation.Move);
        }
Пример #7
0
        BaseTreeViewItem IScopeable.GetScopedTreeViewItem()
        {
            var result = new ItemTreeViewItem(Item);

            if (Item.HasChildren)
            {
                result.MakeExpandable();
            }

            return(result);
        }
Пример #8
0
        private void HandleItemDragOver([NotNull] ItemTreeViewItem target, [NotNull] DragEventArgs e)
        {
            Diagnostics.Debug.ArgumentNotNull(target, nameof(target));
            Diagnostics.Debug.ArgumentNotNull(e, nameof(e));

            var items = e.Data.GetData(DragManager.DragIdentifier) as IEnumerable <IItem>;

            if (items == null)
            {
                Diagnostics.Trace.Expected(typeof(IEnumerable <IItem>));
                return;
            }

            var isSameDatabase = true;

            foreach (var s in items)
            {
                if (s == null)
                {
                    Diagnostics.Trace.EnumerableContainsNull();
                    return;
                }

                if (s.ItemUri.DatabaseUri != target.ItemUri.DatabaseUri)
                {
                    isSameDatabase = false;
                }

                if (s.ItemUri == target.ItemUri)
                {
                    return;
                }
            }

            switch (GetDragOperation(e, target, items, isSameDatabase))
            {
            case DragOperation.Copy:
                adorner.AllowedPositions = ControlDragAdornerPosition.All;
                e.Effects = DragDropEffects.Copy;
                break;

            case DragOperation.Move:
                adorner.AllowedPositions = ControlDragAdornerPosition.All;
                e.Effects = DragDropEffects.Move;
                break;

            case DragOperation.CreateItem:
                adorner.AllowedPositions = ControlDragAdornerPosition.Over;
                e.Effects = DragDropEffects.Link;
                break;
            }
        }