Пример #1
0
        public static void Copy(string oldPath, string newPath, bool renaming, bool simulateMove)
        {
            if (string.IsNullOrEmpty(oldPath) || string.IsNullOrEmpty(newPath))
            {
                return;
            }
            ProjectManager.Projects.Project project = (ProjectManager.Projects.Project)PluginBase.CurrentProject;
            string newDocumentClass = null;

            if (File.Exists(oldPath) && FileHelper.ConfirmOverwrite(newPath))
            {
                File.Copy(oldPath, newPath, true);
                if (simulateMove)
                {
                    PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath);
                    if (project.IsDocumentClass(oldPath))
                    {
                        newDocumentClass = newPath;
                    }
                }
            }
            else if (Directory.Exists(oldPath))
            {
                newPath = renaming ? Path.Combine(Path.GetDirectoryName(oldPath), newPath) : Path.Combine(newPath, Path.GetFileName(oldPath));
                if (!FileHelper.ConfirmOverwrite(newPath))
                {
                    return;
                }
                string searchPattern = project.DefaultSearchFilter;
                if (simulateMove)
                {
                    // We need to use our own method for moving directories if folders in the new path already exist
                    FileHelper.CopyDirectory(oldPath, newPath, true);
                    foreach (string pattern in searchPattern.Split(';'))
                    {
                        foreach (string file in Directory.GetFiles(oldPath, pattern, SearchOption.AllDirectories))
                        {
                            if (project.IsDocumentClass(file))
                            {
                                newDocumentClass = file.Replace(oldPath, newPath);
                                break;
                            }
                            PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath);
                        }
                        if (newDocumentClass != null)
                        {
                            break;
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(newDocumentClass))
            {
                project.SetDocumentClass(newDocumentClass, true);
                project.Save();
            }
        }
Пример #2
0
        public static void Move(string oldPath, string newPath, bool renaming)
        {
            if (string.IsNullOrEmpty(oldPath) || string.IsNullOrEmpty(newPath))
            {
                return;
            }
            ProjectManager.Projects.Project project = (ProjectManager.Projects.Project)PluginBase.CurrentProject;
            string newDocumentClass = null;

            if (File.Exists(oldPath))
            {
                File.Move(oldPath, newPath);
                PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath);
                if (project.IsDocumentClass(oldPath))
                {
                    newDocumentClass = newPath;
                }
            }
            else if (Directory.Exists(oldPath))
            {
                newPath = renaming ? Path.Combine(Path.GetDirectoryName(oldPath), newPath) : Path.Combine(newPath, Path.GetFileName(oldPath));
                string searchPattern = GetSearchPatternFromLang(project.Language.ToLower());
                foreach (string file in Directory.GetFiles(oldPath, searchPattern, SearchOption.AllDirectories))
                {
                    if (project.IsDocumentClass(file))
                    {
                        newDocumentClass = file.Replace(oldPath, newPath);
                        break;
                    }
                }
                Directory.Move(oldPath, newPath);
                PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath);
            }
            if (!string.IsNullOrEmpty(newDocumentClass))
            {
                project.SetDocumentClass(newDocumentClass, true);
                project.Save();
            }
        }
Пример #3
0
        private void MoveRefactoredFiles()
        {
            MessageBar.Locked = true;
            AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments();
            foreach (var target in targets)
            {
                File.Delete(target.OldFilePath);

                if (target.OwnerPath == null)
                {
                    OldPathToNewPath.Remove(target.OldFilePath);
                }

                // Casing changes, we cannot move directly here, there may be conflicts, better leave it to the next step
                if (target.TmpFilePath != null)
                {
                    RefactoringHelper.Move(target.TmpFilePath, target.NewFilePath);
                }
            }
            // Move non-source files and whole folders
            foreach (KeyValuePair <string, string> item in OldPathToNewPath)
            {
                string oldPath = item.Key;
                string newPath = item.Value;
                if (File.Exists(oldPath))
                {
                    newPath = Path.Combine(newPath, Path.GetFileName(oldPath));
                    if (!Path.IsPathRooted(newPath))
                    {
                        newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath);
                    }
                    RefactoringHelper.Move(oldPath, newPath, true);
                }
                else if (Directory.Exists(oldPath))
                {
                    newPath = renaming ? Path.Combine(Path.GetDirectoryName(oldPath), newPath) : Path.Combine(newPath, Path.GetFileName(oldPath));

                    // Look for document class changes
                    // Do not use RefactoringHelper to avoid possible dialogs that we don't want
                    ProjectManager.Projects.Project project = (ProjectManager.Projects.Project)PluginBase.CurrentProject;
                    string newDocumentClass = null;
                    string searchPattern    = project.DefaultSearchFilter;
                    foreach (string pattern in searchPattern.Split(';'))
                    {
                        foreach (string file in Directory.GetFiles(oldPath, pattern, SearchOption.AllDirectories))
                        {
                            if (project.IsDocumentClass(file))
                            {
                                newDocumentClass = file.Replace(oldPath, newPath);
                                break;
                            }
                        }
                        if (newDocumentClass != null)
                        {
                            break;
                        }
                    }

                    // Check if this is a name casing change
                    if (oldPath.Equals(newPath, StringComparison.OrdinalIgnoreCase))
                    {
                        string tmpPath = oldPath + "$renaming$";
                        FileHelper.ForceMoveDirectory(oldPath, tmpPath);
                        PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, tmpPath);
                        oldPath = tmpPath;
                    }

                    // Move directory contents to final location
                    FileHelper.ForceMoveDirectory(oldPath, newPath);
                    PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath);

                    if (!string.IsNullOrEmpty(newDocumentClass))
                    {
                        project.SetDocumentClass(newDocumentClass, true);
                        project.Save();
                    }
                }
            }

            MessageBar.Locked = false;
        }