예제 #1
0
        public static void DoPaste(ISolutionFolderNode folderNode)
        {
            if (!DoEnablePaste(folderNode))
            {
                LoggingService.Warn("SolutionFolderNode.DoPaste: Pasting was not enabled.");
                return;
            }

            ExtTreeNode folderTreeNode = (ExtTreeNode)folderNode;
            IDataObject dataObject     = ClipboardWrapper.GetDataObject();

            if (dataObject.GetDataPresent(typeof(ISolutionFolder).ToString()))
            {
                string          guid           = dataObject.GetData(typeof(ISolutionFolder).ToString()).ToString();
                ISolutionFolder solutionFolder = folderNode.Solution.GetSolutionFolder(guid);
                if (solutionFolder != null)
                {
                    folderNode.Container.AddFolder(solutionFolder);
                    ExtTreeView treeView = (ExtTreeView)folderTreeNode.TreeView;
                    foreach (ExtTreeNode node in treeView.CutNodes)
                    {
                        ExtTreeNode oldParent = node.Parent as ExtTreeNode;
                        node.Remove();

                        node.AddTo(folderTreeNode);
                        if (oldParent != null)
                        {
                            oldParent.Refresh();
                        }
                    }
                    ProjectService.SaveSolution();
                }
            }
            folderTreeNode.Expand();
        }
예제 #2
0
        public static void RenameProject(IProject project, string newName)
        {
            if (project.Name == newName)
            {
                return;
            }
            if (!FileService.CheckFileName(newName))
            {
                return;
            }
            // multiple projects with the same name shouldn't be a problem
//			foreach (IProject p in ProjectService.OpenSolution.Projects) {
//				if (string.Equals(p.Name, newName, StringComparison.OrdinalIgnoreCase)) {
//					MessageService.ShowMessage("There is already a project with this name.");
//					return;
//				}
//			}
            string newFileName = Path.Combine(project.Directory, newName + Path.GetExtension(project.FileName));

            // see issue #2 on http://community.sharpdevelop.net/forums/t/15800.aspx:
            // The name of the project and the file name might differ. So if the FileName is
            // already the same as the new project file name, just update the name in the solution.
            if (FileUtility.IsEqualFileName(newFileName, project.FileName))
            {
                project.Name = newName;
                ProjectService.SaveSolution();
                return;
            }

            if (!FileService.RenameFile(project.FileName, newFileName, false))
            {
                return;
            }
            if (project.AssemblyName == project.Name)
            {
                project.AssemblyName = newName;
            }
            if (File.Exists(project.FileName + ".user"))
            {
                FileService.RenameFile(project.FileName + ".user", newFileName + ".user", false);
            }
            foreach (IProject p in ProjectService.OpenSolution.Projects)
            {
                foreach (ProjectItem item in p.Items)
                {
                    if (item.ItemType == ItemType.ProjectReference)
                    {
                        ProjectReferenceProjectItem refItem = (ProjectReferenceProjectItem)item;
                        if (refItem.ReferencedProject == project)
                        {
                            refItem.ProjectName = newName;
                            refItem.Include     = FileUtility.GetRelativePath(p.Directory, newFileName);
                        }
                    }
                }
            }
            project.FileName = newFileName;
            project.Name     = newName;
            ProjectService.SaveSolution();
        }
        public static void DoPaste(ISolutionFolderNode folderNode)
        {
            System.Windows.IDataObject dataObject = SD.Clipboard.GetDataObject();
            if (!DoEnablePaste(folderNode.Folder, dataObject))
            {
                LoggingService.Warn("SolutionFolderNode.DoPaste: Pasting was not enabled.");
                return;
            }

            ExtTreeNode folderTreeNode = (ExtTreeNode)folderNode;

            if (dataObject.GetDataPresent(typeof(ISolutionItem).ToString()))
            {
                Guid          guid         = Guid.Parse(dataObject.GetData(typeof(ISolutionItem).ToString()).ToString());
                ISolutionItem solutionItem = folderNode.Solution.GetItemByGuid(guid);
                if (solutionItem != null)
                {
                    MoveItem(solutionItem, folderNode.Folder);
                    ExtTreeView treeView = (ExtTreeView)folderTreeNode.TreeView;
                    foreach (ExtTreeNode node in treeView.CutNodes)
                    {
                        ExtTreeNode oldParent = node.Parent as ExtTreeNode;
                        node.Remove();

                        node.InsertSorted(folderTreeNode);
                        if (oldParent != null)
                        {
                            oldParent.Refresh();
                        }
                    }
                    ProjectService.SaveSolution();
                }
            }
            folderTreeNode.Expand();
        }
예제 #4
0
        public override void Paste()
        {
            IDataObject dataObject = ClipboardWrapper.GetDataObject();

            if (dataObject == null)
            {
                return;
            }

            if (dataObject.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
                foreach (string fileName in files)
                {
                    if (System.IO.Directory.Exists(fileName))
                    {
                        if (!FileUtility.IsBaseDirectory(fileName, Directory))
                        {
                            CopyDirectoryHere(fileName, false);
                        }
                    }
                    else
                    {
                        CopyFileHere(fileName, false);
                    }
                }
            }
            else if (dataObject.GetDataPresent(typeof(FileNode)))
            {
                FileOperationClipboardObject clipboardObject = (FileOperationClipboardObject)dataObject.GetData(typeof(FileNode).ToString());

                if (File.Exists(clipboardObject.FileName))
                {
                    CopyFileHere(clipboardObject.FileName, clipboardObject.PerformMove);
                    if (clipboardObject.PerformMove)
                    {
                        Clipboard.Clear();
                    }
                }
            }
            else if (dataObject.GetDataPresent(typeof(DirectoryNode)))
            {
                FileOperationClipboardObject clipboardObject = (FileOperationClipboardObject)dataObject.GetData(typeof(DirectoryNode).ToString());

                if (System.IO.Directory.Exists(clipboardObject.FileName))
                {
                    CopyDirectoryHere(clipboardObject.FileName, clipboardObject.PerformMove);
                    if (clipboardObject.PerformMove)
                    {
                        Clipboard.Clear();
                    }
                }
            }
            ProjectService.SaveSolution();
        }
예제 #5
0
        //public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect)
        public virtual void DoDragDrop(IDataObject dataObject, DragDropEffects effect)
        {
            if (dataObject.GetDataPresent(typeof(FileNode)))
            {
                // Dragging a file onto another creates a dependency.

                FileNode other = (FileNode)dataObject.GetData(typeof(FileNode));
                LoggingService.Debug("ProjectBrowser: Dragging file '" + other.FileName + "' onto file '" + this.FileName + "'");

                // Copy/move the file to the correct directory
                // if the target is in a different directory than the source.
                if (!FileUtility.IsEqualFileName(Path.GetDirectoryName(this.FileName), Path.GetDirectoryName(other.FileName)))
                {
                    LoggingService.Debug("-> Source file is in different directory, performing " + effect.ToString());
                    ExtTreeNode   p = this;
                    DirectoryNode parentDirectory;
                    do
                    {
                        p = (ExtTreeNode)p.Parent;
                        parentDirectory = p as DirectoryNode;
                    } while (parentDirectory == null && p != null);
                    if (parentDirectory == null)
                    {
                        throw new InvalidOperationException("File '" + this.FileName + "' does not have a parent directory.");
                    }
                    LoggingService.Debug("-> Copying/Moving source file to parent directory of target: " + parentDirectory.Directory);
                    string otherFileName = Path.GetFileName(other.FileName);
                    parentDirectory.CopyFileHere(other, effect == DragDropEffects.Move);
                    // Find the copied or moved file node again
                    other = parentDirectory.AllNodes.OfType <FileNode>().SingleOrDefault(n => FileUtility.IsEqualFileName(Path.GetFileName(n.FileName), otherFileName));
                }

                if (other != null)
                {
                    other.Remove();
                    ((FileProjectItem)other.ProjectItem).DependentUpon = Path.GetFileName(this.FileName);
                    other.FileNodeStatus = FileNodeStatus.BehindFile;
                    other.InsertSorted(this);
                    LoggingService.Debug("-> Created new dependency, saving solution");
                    ProjectService.SaveSolution();
                }
                else
                {
                    LoggingService.Debug("-> Could not find the copied or moved file node in the new parent directory.");
                }

                return;
            }

            //((ExtTreeNode)Parent).DoDragDrop(dataObject, effect);
            DragDrop.DoDragDrop(this, dataObject, effect);
        }
예제 #6
0
        public static void RenameProject(IProject project, string newName)
        {
            if (project.Name == newName)
            {
                return;
            }
            if (!FileService.CheckFileName(newName))
            {
                return;
            }
            // multiple projects with the same name shouldn't be a problem
//			foreach (IProject p in ProjectService.OpenSolution.Projects) {
//				if (string.Equals(p.Name, newName, StringComparison.OrdinalIgnoreCase)) {
//					MessageService.ShowMessage("There is already a project with this name.");
//					return;
//				}
//			}
            string newFileName = Path.Combine(project.Directory, newName + Path.GetExtension(project.FileName));

            if (!FileService.RenameFile(project.FileName, newFileName, false))
            {
                return;
            }
            if (project.AssemblyName == project.Name)
            {
                project.AssemblyName = newName;
            }
            if (File.Exists(project.FileName + ".user"))
            {
                FileService.RenameFile(project.FileName + ".user", newFileName + ".user", false);
            }
            foreach (IProject p in ProjectService.OpenSolution.Projects)
            {
                foreach (ProjectItem item in p.Items)
                {
                    if (item.ItemType == ItemType.ProjectReference)
                    {
                        ProjectReferenceProjectItem refItem = (ProjectReferenceProjectItem)item;
                        if (refItem.ReferencedProject == project)
                        {
                            refItem.ProjectName = newName;
                            refItem.Include     = FileUtility.GetRelativePath(p.Directory, newFileName);
                        }
                    }
                }
            }
            project.FileName = newFileName;
            project.Name     = newName;
            ProjectService.SaveSolution();
        }
예제 #7
0
        public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect)
        {
            PerformInitialization();
            Expand();
            try {
                if (dataObject.GetDataPresent(typeof(FileNode)))
                {
                    FileNode fileNode = (FileNode)dataObject.GetData(typeof(FileNode));
                    CopyFileHere(fileNode, effect == DragDropEffects.Move);
                }
                else if (dataObject.GetDataPresent(typeof(DirectoryNode)))
                {
                    DirectoryNode directoryNode = (DirectoryNode)dataObject.GetData(typeof(DirectoryNode));
                    CopyDirectoryHere(directoryNode, effect == DragDropEffects.Move);
                }
                else if (dataObject.GetDataPresent(DataFormats.FileDrop))
                {
                    string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
                    foreach (string fileName in files)
                    {
                        if (System.IO.Directory.Exists(fileName))
                        {
                            if (!FileUtility.IsBaseDirectory(fileName, Directory))
                            {
                                CopyDirectoryHere(fileName, false);
                            }
                        }
                        else
                        {
                            CopyFileHere(fileName, false);
                        }
                    }
                }

                ProjectService.SaveSolution();
            } catch (Exception e) {
                MessageService.ShowError(e);
            }
        }
예제 #8
0
        public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect)
        {
            PerformInitialization();
            Expand();
            try {
                if (dataObject.GetDataPresent(typeof(FileNode)))
                {
                    FileNode fileNode = (FileNode)dataObject.GetData(typeof(FileNode));
                    LoggingService.Debug("ProjectBrowser: Dragging file '" + fileNode.FileName + "' onto directory '" + this.Directory + "'");
                    if (!FileUtility.IsEqualFileName(Directory, fileNode.FileName) && !FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(fileNode.FileName)) &&
                        !(fileNode.ProjectItem is FileProjectItem && FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(GetFullVirtualName((FileProjectItem)fileNode.ProjectItem)))))
                    {
                        LoggingService.Debug("-> Not in same directory, performing " + effect.ToString());
                        CopyFileHere(fileNode, effect == DragDropEffects.Move);
                    }
                    else
                    {
                        // Dragging a dependent file onto its parent directory
                        // removes the dependency.
                        LoggingService.Debug("-> In same directory, removing dependency");
                        ((FileProjectItem)fileNode.ProjectItem).DependentUpon = String.Empty;
                        fileNode.Remove();
                        if (!File.Exists(fileNode.FileName))
                        {
                            fileNode.FileNodeStatus = FileNodeStatus.Missing;
                        }
                        else
                        {
                            fileNode.FileNodeStatus = FileNodeStatus.InProject;
                        }
                        fileNode.InsertSorted(this);
                    }
                }
                else if (dataObject.GetDataPresent(typeof(DirectoryNode)))
                {
                    DirectoryNode directoryNode = (DirectoryNode)dataObject.GetData(typeof(DirectoryNode));
                    CopyDirectoryHere(directoryNode, effect == DragDropEffects.Move);
                }
                else if (dataObject.GetDataPresent(DataFormats.FileDrop))
                {
                    string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
                    if (files != null)
                    {
                        foreach (string fileName in files)
                        {
                            if (System.IO.Directory.Exists(fileName))
                            {
                                if (!FileUtility.IsBaseDirectory(fileName, Directory))
                                {
                                    CopyDirectoryHere(fileName, false);
                                }
                            }
                            else
                            {
                                CopyFileHere(fileName, false);
                            }
                        }
                    }
                }

                ProjectService.SaveSolution();
            } catch (Exception e) {
                MessageService.ShowException(e);
            }
        }
예제 #9
0
 public override void Delete()
 {
     ProjectService.RemoveSolutionFolder(Project.IdGuid);
     ProjectService.SaveSolution();
 }