示例#1
0
        private static void AddToCutList(IProjectItem item, List <CutBuffer.ItemCopyInformation> cutList, bool isCut)
        {
            bool flag  = false;
            int  count = cutList.Count - 1;

            while (count >= 0)
            {
                string itemUrl = cutList[count].ItemUrl;
                if (itemUrl == item.DocumentReference.Path)
                {
                    flag = true;
                    break;
                }
                else if (!itemUrl.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase) || !item.DocumentReference.Path.StartsWith(itemUrl, StringComparison.OrdinalIgnoreCase))
                {
                    if (item.DocumentReference.Path.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase) && itemUrl.StartsWith(item.DocumentReference.Path, StringComparison.OrdinalIgnoreCase))
                    {
                        cutList.RemoveAt(count);
                    }
                    count--;
                }
                else
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                if (!item.DocumentReference.Path.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase))
                {
                    foreach (IProjectItem child in item.Children)
                    {
                        CutBuffer.AddToCutList(child, cutList, isCut);
                    }
                }
                string       path           = null;
                IProjectItem codeBehindItem = item.CodeBehindItem;
                if (codeBehindItem != null)
                {
                    path = codeBehindItem.DocumentReference.Path;
                }
                cutList.Add(new CutBuffer.ItemCopyInformation(item.DocumentReference.Path, path));
                item.IsCut = isCut;
            }
        }
示例#2
0
        private void CutCopy(bool isCut)
        {
            if (this.Services.ProjectManager().ItemSelectionSet.IsEmpty)
            {
                return;
            }
            IProject project = this.Services.ProjectManager().ItemSelectionSet.SelectedProjects.SingleOrNull <IProject>();

            if (project == null)
            {
                return;
            }
            this.UpdateLastCut(null);
            List <CutBuffer.ItemCopyInformation> itemCopyInformations = new List <CutBuffer.ItemCopyInformation>();

            foreach (IProjectItem projectItem in this.Services.ProjectManager().ItemSelectionSet.Selection.OfType <IProjectItem>())
            {
                if (isCut && projectItem.IsLinkedFile || !projectItem.FileExists || projectItem.IsVirtual || projectItem is AssemblyReferenceProjectItem)
                {
                    continue;
                }
                CutBuffer.AddToCutList(projectItem, itemCopyInformations, isCut);
            }
            string[] itemUrl = new string[itemCopyInformations.Count];
            for (int i = 0; i < itemCopyInformations.Count; i++)
            {
                itemUrl[i] = itemCopyInformations[i].ItemUrl;
            }
            DataObject dataObject = new DataObject();

            dataObject.SetData(typeof(string[]), itemUrl);
            dataObject.SetData(DataFormats.FileDrop, itemUrl);
            dataObject.SetData(new CutBuffer.ProjectCopyInformation(isCut, project.DocumentReference.Path, itemCopyInformations));
            ClipboardService.SetDataObject(dataObject);
            this.LastCut = dataObject;
        }
示例#3
0
        public void Paste()
        {
            IProject project = this.Services.ProjectManager().ItemSelectionSet.SelectedProjects.SingleOrNull <IProject>();

            if (project == null)
            {
                return;
            }
            CutBuffer.ProjectCopyInformation copyInformation = this.GetCopyInformation();
            if (copyInformation == null)
            {
                CutBuffer.AddImageDataFromClipboard(this.Services.ProjectManager(), project);
            }
            else
            {
                IProject project1 = null;
                if (copyInformation.IsCut)
                {
                    project1 = this.Services.ProjectManager().CurrentSolution.Projects.FindMatchByUrl <IProject>(copyInformation.ProjectUrl);
                }
                if (copyInformation.Items != null && copyInformation.Items.Count > 0)
                {
                    string str = this.Services.ProjectManager().TargetFolderForProject(project);
                    if (str != null)
                    {
                        IEnumerable <CutBuffer.CopyInformation> copyInformations = copyInformation.Items.Where <CutBuffer.ItemCopyInformation>((CutBuffer.ItemCopyInformation itemToCopy) => {
                            if (project1 == null)
                            {
                                return(true);
                            }
                            return(!Microsoft.Expression.Framework.Documents.PathHelper.ArePathsEquivalent(Microsoft.Expression.Framework.Documents.PathHelper.GetParentDirectory(itemToCopy.ItemUrl), str));
                        }).Select <CutBuffer.ItemCopyInformation, CutBuffer.CopyInformation>((CutBuffer.ItemCopyInformation itemToCopy) => new CutBuffer.CopyInformation(itemToCopy.ItemUrl, this.DetermineFileUrlForCopy(itemToCopy.ItemUrl, str)));
                        if (!this.CopyItems(project, copyInformations))
                        {
                            return;
                        }
                    }
                    if (project1 != null)
                    {
                        foreach (CutBuffer.ItemCopyInformation item in copyInformation.Items)
                        {
                            IProjectItem projectItem = project1.FindItem(DocumentReference.Create(item.ItemUrl));
                            if (projectItem == null)
                            {
                                continue;
                            }
                            if (Microsoft.Expression.Framework.Documents.PathHelper.ArePathsEquivalent(Microsoft.Expression.Framework.Documents.PathHelper.GetParentDirectory(item.ItemUrl), str))
                            {
                                projectItem.IsCut = false;
                            }
                            else
                            {
                                IProjectItem codeBehindItem = projectItem.CodeBehindItem;
                                if (codeBehindItem != null)
                                {
                                    IProject       project2         = project1;
                                    IProjectItem[] projectItemArray = new IProjectItem[] { codeBehindItem };
                                    project2.RemoveItems(true, projectItemArray);
                                }
                                IProject       project3          = project1;
                                IProjectItem[] projectItemArray1 = new IProjectItem[] { projectItem };
                                project3.RemoveItems(true, projectItemArray1);
                            }
                        }
                        ClipboardService.SetDataObject(new DataObject());
                        this.LastCut = null;
                        return;
                    }
                }
            }
        }