示例#1
0
        static void OnFileSaved(object sender, FileNameEventArgs e)
        {
            Solution solution = ProjectService.OpenSolution;

            if (solution == null)
            {
                return;
            }
            IProject project = solution.FindProjectContainingFile(e.FileName);

            if (project == null)
            {
                return;
            }
            FileProjectItem item = project.FindFile(e.FileName);

            if (item == null)
            {
                return;
            }
            if (!string.IsNullOrEmpty(item.CustomTool))
            {
                RunCustomTool(item, false);
            }
        }
示例#2
0
        /// <summary>
        /// Copies or moves a file to this directory.
        /// </summary>
        /// <param name="fileName">The name of the file to copy or move.</param>
        /// <param name="performMove">true to move the file, false to copy it.</param>
        /// <param name="keepDependency">true to copy the DependentUpon value of the file to the target if possible, false to discard the DependentUpon value.</param>
        public void CopyFileHere(string fileName, bool performMove, bool keepDependency)
        {
            string shortFileName  = Path.GetFileName(fileName);
            string copiedFileName = Path.Combine(Directory, shortFileName);

            if (FileUtility.IsEqualFileName(fileName, copiedFileName))
            {
                return;
            }
            bool wasFileReplacement = false;

            if (File.Exists(copiedFileName))
            {
                if (!FileService.FireFileReplacing(copiedFileName, false))
                {
                    return;
                }
                if (AddExistingItemsToProject.ShowReplaceExistingFileDialog(null, copiedFileName, false) == AddExistingItemsToProject.ReplaceExistingFile.Yes)
                {
                    wasFileReplacement = true;
                    IViewContent viewContent = FileService.GetOpenFile(copiedFileName);
                    if (viewContent != null)
                    {
                        viewContent.WorkbenchWindow.CloseWindow(true);
                    }
                }
                else
                {
                    // don't replace file
                    return;
                }
            }

            FileProjectItem newItem       = AddExistingItemsToProject.CopyFile(fileName, this, true);
            IProject        sourceProject = Solution.FindProjectContainingFile(fileName);

            if (sourceProject != null)
            {
                string sourceDirectory         = Path.GetDirectoryName(fileName);
                bool   dependendElementsCopied = false;
                foreach (ProjectItem item in sourceProject.Items)
                {
                    FileProjectItem fileItem = item as FileProjectItem;
                    if (fileItem == null)
                    {
                        continue;
                    }
                    if (newItem != null && FileUtility.IsEqualFileName(fileItem.FileName, fileName))
                    {
                        fileItem.CopyMetadataTo(newItem);
                        if (!keepDependency)
                        {
                            // Prevent the DependentUpon from being copied
                            // because the referenced file is now in a different directory.
                            newItem.DependentUpon = String.Empty;
                        }
                    }
                    if (!string.Equals(fileItem.DependentUpon, shortFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    string itemPath = Path.Combine(sourceProject.Directory, fileItem.VirtualName);
                    if (!FileUtility.IsEqualFileName(sourceDirectory, Path.GetDirectoryName(itemPath)))
                    {
                        continue;
                    }
                    // this file is dependend on the file being copied/moved: copy it, too
                    CopyFileHere(itemPath, performMove, true);
                    dependendElementsCopied = true;
                }
                if (dependendElementsCopied)
                {
                    RecreateSubNodes();
                }
            }
            if (performMove)
            {
                foreach (OpenedFile file in FileService.OpenedFiles)
                {
                    if (file.FileName != null &&
                        FileUtility.IsEqualFileName(file.FileName, fileName))
                    {
                        file.FileName = new FileName(copiedFileName);
                    }
                }
                FileService.RemoveFile(fileName, false);
            }
            if (wasFileReplacement)
            {
                FileService.FireFileReplaced(copiedFileName, false);
            }
        }
示例#3
0
        TreeNode FindDeepestOpenNodeForPath(string fileName)
        {
            //LoggingService.DebugFormatted("Finding Deepest for '{0}'", fileName);
            Solution solution = ProjectService.OpenSolution;

            if (solution == null)
            {
                return(null);
            }

            IProject project = solution.FindProjectContainingFile(fileName);

            if (project == null)
            {
                //LoggingService.Debug("no IProject found");
                return(null);
            }

            string relativePath = String.Empty;
            AbstractProjectBrowserTreeNode targetNode = FindProjectNode(project);

            if (targetNode == null)
            {
                // our project node is not yet created,
                // so start at the root and work down.

                if (treeView.Nodes == null || treeView.Nodes.Count < 1)
                {
                    // the treeView is not yet prepared to assist in this request.
                    return(null);
                }
                else
                {
                    targetNode = treeView.Nodes[0] as AbstractProjectBrowserTreeNode;
                    if (fileName.StartsWith(solution.Directory))
                    {
                        relativePath = fileName.Replace(solution.Directory, "");
                    }
                }
            }
            else
            {
                // start from the project node and work upwards
                // to the first visible node
                TreeNode t = targetNode;
                TreeNode p = targetNode.Parent;
                while (p != null)
                {
                    if (!p.IsExpanded)
                    {
                        t = p;
                    }
                    p = p.Parent;
                }

                if (t != targetNode)
                {
                    // project node is instantiated but not visible
                    // so select the most visible parent node.
                    return(t);
                }
                else
                {
                    // project node is instantiated and visible
                    // so we start here and work down
                    if (fileName.StartsWith((targetNode as ProjectNode).Directory))
                    {
                        relativePath = fileName.Replace((targetNode as ProjectNode).Directory, "");
                    }
                }
            }

            return(targetNode.GetNodeByRelativePath(relativePath));
        }
示例#4
0
        TreeNode FindDeepestOpenNodeForPath(string fileName)
        {
            //LoggingService.DebugFormatted("Finding Deepest for '{0}'", fileName);
            Solution solution = ProjectService.OpenSolution;

            if (solution == null)
            {
                return(null);
            }

            IProject project = solution.FindProjectContainingFile(fileName);

            if (project == null)
            {
                //LoggingService.Debug("no IProject found");
                return(null);
            }

            string   relativePath = String.Empty;
            TreeNode targetNode   = FindProjectNode(project);

            if (targetNode == null)
            {
                // our project node is not yet created,
                // so start at the root and work down.

                if (treeView.Nodes == null || treeView.Nodes.Count < 1)
                {
                    // the treeView is not yet prepared to assist in this request.
                    return(null);
                }
                else
                {
                    targetNode = treeView.Nodes[0];
                    if (fileName.StartsWith(solution.Directory))
                    {
                        relativePath = fileName.Replace(solution.Directory, "");
                    }
                }
            }
            else
            {
                // start from the project node and work upwards
                // to the first visible node
                TreeNode t = targetNode;
                TreeNode p = targetNode.Parent;
                while (p != null)
                {
                    if (!p.IsExpanded)
                    {
                        t = p;
                    }
                    p = p.Parent;
                }

                if (t != targetNode)
                {
                    // project node is instantiated but not visible
                    // so select the most visible parent node.
                    return(t);
                }
                else
                {
                    // project node is instantiated and visible
                    // so we start here and work down
                    if (fileName.StartsWith((targetNode as ProjectNode).Directory))
                    {
                        relativePath = fileName.Replace((targetNode as ProjectNode).Directory, "");
                    }
                }
            }

            if (!targetNode.IsExpanded)
            {
                // the targetNode is not expanded so it's as deep as we can go
                //LoggingService.DebugFormatted("target node '{0};{1}' is not expanded.", targetNode, targetNode.Text);
                return(targetNode);
            }

            //LoggingService.Debug("entering depth loop...");
            //LoggingService.DebugFormatted(@"\- looking for '{0}'", relativePath);
            //LoggingService.DebugFormatted(@"\- starting at '{0}'", targetNode != null ? targetNode.Text : "null");

            string[] targets  = relativePath.Trim('/', '\\').Split('/', '\\');
            TreeNode nextNode = null;

            foreach (string target in targets)
            {
                //LoggingService.Debug("-- looking for: "+target);
                nextNode = null;
                foreach (TreeNode node in targetNode.Nodes)
                {
                    if (node == null)
                    {
                        // can happen when the node is currently expanding
                        continue;
                    }
                    if (node.Text == target)
                    {
                        nextNode = node;
                        break;
                    }
                }
                if (nextNode == null)
                {
                    // targetNode is as deep as we can find
                    break;
                }
                else
                {
                    targetNode = nextNode;
                }
            }
            return(targetNode);
        }
示例#5
0
        public void CopyFileHere(string fileName, bool performMove)
        {
            string shortFileName  = Path.GetFileName(fileName);
            string copiedFileName = Path.Combine(Directory, shortFileName);

            if (FileUtility.IsEqualFileName(fileName, copiedFileName))
            {
                return;
            }
            bool wasFileReplacement = false;

            if (File.Exists(copiedFileName))
            {
                if (!FileService.FireFileReplacing(copiedFileName, false))
                {
                    return;
                }
                if (AddExistingItemsToProject.ShowReplaceExistingFileDialog(null, copiedFileName, false) == AddExistingItemsToProject.ReplaceExistingFile.Yes)
                {
                    wasFileReplacement = true;
                }
                else
                {
                    // don't replace file
                    return;
                }
            }

            FileProjectItem newItem       = AddExistingItemsToProject.CopyFile(fileName, this, true);
            IProject        sourceProject = Solution.FindProjectContainingFile(fileName);

            if (sourceProject != null)
            {
                string sourceDirectory         = Path.GetDirectoryName(fileName);
                bool   dependendElementsCopied = false;
                foreach (ProjectItem item in sourceProject.Items)
                {
                    FileProjectItem fileItem = item as FileProjectItem;
                    if (fileItem == null)
                    {
                        continue;
                    }
                    if (newItem != null && FileUtility.IsEqualFileName(fileItem.FileName, fileName))
                    {
                        fileItem.CopyMetadataTo(newItem);
                    }
                    if (!string.Equals(fileItem.DependentUpon, shortFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    string itemPath = Path.Combine(sourceProject.Directory, fileItem.VirtualName);
                    if (!FileUtility.IsEqualFileName(sourceDirectory, Path.GetDirectoryName(itemPath)))
                    {
                        continue;
                    }
                    // this file is dependend on the file being copied/moved: copy it, too
                    CopyFileHere(itemPath, performMove);
                    dependendElementsCopied = true;
                }
                if (dependendElementsCopied)
                {
                    RecreateSubNodes();
                }
            }
            if (performMove)
            {
                foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection)
                {
                    if (content.FileName != null &&
                        FileUtility.IsEqualFileName(content.FileName, fileName))
                    {
                        content.FileName  = copiedFileName;
                        content.TitleName = shortFileName;
                    }
                }
                FileService.RemoveFile(fileName, false);
            }
            if (wasFileReplacement)
            {
                FileService.FireFileReplaced(copiedFileName, false);
            }
        }