Exemplo n.º 1
0
        /// <inheritdoc />
        protected override bool CanPaste(bool asRoot)
        {
            var copyPasteService = ServiceProvider.TryGet <ICopyPasteService>();

            if (copyPasteService == null)
            {
                return(false);
            }

            if (asRoot)
            {
                return(PasteAsRootMonitor.Get(() =>
                                              copyPasteService.CanPaste(SafeClipboard.GetText(), Asset.AssetType, typeof(AssetCompositeHierarchyData <UIElementDesign, UIElement>), typeof(AssetCompositeHierarchyData <UIElementDesign, UIElement>))));
            }

            var canAddOrInsert = SelectedItems.All(element =>
            {
                var contentControl = element as ContentControlViewModel;
                if (contentControl != null)
                {
                    return(contentControl.AssetSideControl.Content == null);
                }
                return(element is PanelViewModel);
            });

            if (!canAddOrInsert)
            {
                return(false);
            }

            return(PasteMonitor.Get(() => copyPasteService.CanPaste(SafeClipboard.GetText(), Asset.AssetType, typeof(UIElement), typeof(AssetCompositeHierarchyData <UIElementDesign, UIElement>))));
        }
Exemplo n.º 2
0
        protected async void DoPaste(INodePresenter nodePresenter, bool replace)
        {
            var text = SafeClipboard.GetText();

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var assetNodePresenter = (IAssetNodePresenter)nodePresenter;
            var asset            = assetNodePresenter.Asset;
            var copyPasteService = asset.ServiceProvider.Get <ICopyPasteService>();
            var result           = copyPasteService.DeserializeCopiedData(text, asset.Asset, (nodePresenter as ItemNodePresenter)?.OwnerCollection.Type ?? nodePresenter.Type);

            if (result.Items.Count == 0)
            {
                return;
            }

            var nodeAccessor = nodePresenter.GetNodeAccessor();
            var targetNode   = nodeAccessor.Node;

            // If the node presenter is a virtual node without node, we cannot paste.
            if (targetNode == null)
            {
                return;
            }

            var actionService = asset.UndoRedoService;

            using (var transaction = actionService.CreateTransaction())
            {
                // FIXME: for now we only handle one result item
                var item = result.Items[0];
                if (item.Data is ICollection && !CollectionDescriptor.IsCollection(targetNode.Type))
                {
                    return; // cannot paste a collection to a non-collection content
                }
                var propertyContainer = new PropertyContainer {
                    { AssetPropertyPasteProcessor.IsReplaceKey, replace }
                };
                await(item.Processor?.Paste(item, asset.PropertyGraph, ref nodeAccessor, ref propertyContainer) ?? Task.CompletedTask);
                actionService.SetName(transaction, replace ? "Replace property": "Paste property");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// [UI Thread] : Ctrl+V による棋譜の貼り付け
        /// </summary>
        public void CopyFromClipboard()
        {
            if (gameScreenControl1.gameServer.GameMode == GameModeEnum.ConsiderationWithoutEngine)
            {
                if (gameScreenControl1.gameServer.KifuDirty)
                {
                    if (TheApp.app.MessageShow("未保存の棋譜が残っていますが、本当に棋譜を貼り付けますか?", MessageShowType.WarningOkCancel)
                        != DialogResult.OK)
                    {
                        return;
                    }
                }

                // クリップボードからテキスト取得

                // GetText()はUI Threadの制約があるので注意。
                var text = SafeClipboard.GetText();
                gameServer.KifuReadCommand(text);
                ViewModel.LastFileName = null;
            }
        }
Exemplo n.º 4
0
        protected virtual bool CanPaste([NotNull] IReadOnlyCollection <INodePresenter> nodePresenters)
        {
            if (nodePresenters == null)
            {
                throw new ArgumentNullException(nameof(nodePresenters));
            }
            foreach (var nodePresenter in nodePresenters)
            {
                var assetNodePresenter = nodePresenter as IAssetNodePresenter;
                var copyPasteService   = assetNodePresenter?.Asset?.ServiceProvider.TryGet <ICopyPasteService>();
                if (copyPasteService == null)
                {
                    return(false);
                }

                var asset = assetNodePresenter.Asset.Asset;

                if (!copyPasteService.CanPaste(SafeClipboard.GetText(), asset.GetType(), (nodePresenter as ItemNodePresenter)?.OwnerCollection.Type ?? nodePresenter.Type))
                {
                    return(false);
                }

                // Cannot paste into read-only collection
                if (IsInReadOnlyCollection(nodePresenter) || IsInReadOnlyCollection((nodePresenter as ItemNodePresenter)?.OwnerCollection))
                {
                    return(false);
                }

                // Cannot paste into read-only property (non-collection)
                if (!nodePresenter.IsEnumerable && nodePresenter.IsReadOnly)
                {
                    return(false);
                }
            }
            return(true);
        }