Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        private void MoveTargets()
        {
            Dictionary <string, ITabbedDocument> fileNameToOpenedDoc = new Dictionary <string, ITabbedDocument>();

            foreach (ITabbedDocument doc in PluginBase.MainForm.Documents)
            {
                fileNameToOpenedDoc.Add(doc.FileName, doc);
            }
            MessageBar.Locked = true;
            foreach (KeyValuePair <string, string> item in oldPathToNewPath)
            {
                string oldPath = item.Key;
                string newPath = item.Value;
                if (Path.HasExtension(oldPath))
                {
                    if (fileNameToOpenedDoc.ContainsKey(oldPath))
                    {
                        fileNameToOpenedDoc[oldPath].Save();
                        fileNameToOpenedDoc[oldPath].Close();
                    }
                    newPath = Path.Combine(item.Value, Path.GetFileName(oldPath));
                    // refactor failed or was refused
                    if (Path.GetFileName(oldPath).Equals(newPath, StringComparison.OrdinalIgnoreCase))
                    {
                        // name casing changed
                        string tmpPath = oldPath + "$renaming$";
                        File.Move(oldPath, tmpPath);
                        oldPath = tmpPath;
                    }
                    if (!Path.IsPathRooted(newPath))
                    {
                        newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath);
                    }
                    RefactoringHelper.Move(oldPath, newPath);
                }
                else
                {
                    foreach (string file in Directory.GetFiles(oldPath, "*.*", SearchOption.AllDirectories))
                    {
                        if (fileNameToOpenedDoc.ContainsKey(file))
                        {
                            fileNameToOpenedDoc[file].Save();
                            fileNameToOpenedDoc[file].Close();
                        }
                    }
                    RefactoringHelper.Move(oldPath, newPath, renaming);
                }
            }
            MessageBar.Locked = false;
        }
Exemple #2
0
        private void RenameFile(IDictionary <string, List <SearchMatch> > results)
        {
            // We close previous files to avoid unwanted "file modified" dialogs
            ITabbedDocument doc;
            bool            reopen = false;

            if (AssociatedDocumentHelper.InitiallyOpenedFiles.TryGetValue(oldFileName, out doc))
            {
                doc.Close();
                reopen = true;
            }
            if (AssociatedDocumentHelper.InitiallyOpenedFiles.TryGetValue(newFileName, out doc))
            {
                doc.Close();
                reopen = true;
            }

            // name casing changed
            if (oldFileName.Equals(newFileName, StringComparison.OrdinalIgnoreCase))
            {
                string tmpPath = oldFileName + "$renaming$";
                RefactoringHelper.Move(oldFileName, tmpPath);
                RefactoringHelper.Move(tmpPath, newFileName);
            }
            else
            {
                var project = (Project)PluginBase.CurrentProject;
                FileHelper.ForceMove(oldFileName, newFileName);
                DocumentManager.MoveDocuments(oldFileName, newFileName);
                if (project.IsDocumentClass(oldFileName))
                {
                    project.SetDocumentClass(newFileName, true);
                    project.Save();
                }
            }

            if (results.ContainsKey(oldFileName))
            {
                results[newFileName] = results[oldFileName];
                results.Remove(oldFileName);
            }
            if (reopen)
            {
                PluginBase.MainForm.OpenEditableDocument(newFileName);
            }
        }
Exemple #3
0
 private void MoveTargets()
 {
     MessageBar.Locked = true;
     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));
             // refactor failed or was refused
             if (Path.GetFileName(oldPath).Equals(newPath, StringComparison.OrdinalIgnoreCase))
             {
                 // name casing changed
                 string tmpPath = oldPath + "$renaming$";
                 RefactoringHelper.Move(oldPath, tmpPath);
                 oldPath = tmpPath;
             }
             if (!Path.IsPathRooted(newPath))
             {
                 newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath);
             }
             RefactoringHelper.Move(oldPath, newPath, true);
         }
         else if (Directory.Exists(oldPath))
         {
             if (Path.GetFileName(oldPath).Equals(newPath, StringComparison.OrdinalIgnoreCase))
             {
                 // name casing changed
                 string tmpPath = oldPath + "$renaming$";
                 RefactoringHelper.Move(oldPath, tmpPath);
                 oldPath = tmpPath;
             }
             RefactoringHelper.Move(oldPath, newPath, renaming);
         }
     }
     MessageBar.Locked = false;
 }
Exemple #4
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, true, target.OldFilePath);
                }
                else
                {
                    RefactoringHelper.RaiseMoveEvent(target.OldFilePath, 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
                    Project project          = (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);
                        DocumentManager.MoveDocuments(oldPath, tmpPath);
                        oldPath = tmpPath;
                    }

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

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

            MessageBar.Locked = false;
        }
Exemple #5
0
        private void RenameFile(IDictionary <string, List <SearchMatch> > results)
        {
            ASResult target        = findAllReferencesCommand.CurrentTarget;
            Boolean  isEnum        = target.Type.IsEnum();
            Boolean  isClass       = false;
            Boolean  isConstructor = false;

            if (!isEnum)
            {
                Boolean isVoid = target.Type.IsVoid();
                isClass       = !isVoid && target.IsStatic && target.Member == null;
                isConstructor = !isVoid && !isClass && RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.Constructor);
            }

            Boolean isGlobalFunction  = false;
            Boolean isGlobalNamespace = false;

            if (!isEnum && !isClass && !isConstructor && (target.InClass == null || target.InClass.IsVoid()))
            {
                isGlobalFunction  = RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.Function);
                isGlobalNamespace = RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.Namespace);
            }

            if (!isEnum && !isClass && !isConstructor && !isGlobalFunction && !isGlobalNamespace)
            {
                return;
            }

            FileModel inFile     = null;
            String    originName = null;

            if (isEnum || isClass)
            {
                inFile     = target.Type.InFile;
                originName = target.Type.Name;
            }
            else
            {
                inFile     = target.Member.InFile;
                originName = target.Member.Name;
            }

            if (inFile == null)
            {
                return;
            }

            String oldFileName = inFile.FileName;
            String oldName     = Path.GetFileNameWithoutExtension(oldFileName);

            if (!string.IsNullOrEmpty(oldName) && !oldName.Equals(originName))
            {
                return;
            }

            String fullPath = Path.GetFullPath(inFile.FileName);

            fullPath = Path.GetDirectoryName(fullPath);

            String newFileName = Path.Combine(fullPath, NewName + Path.GetExtension(oldFileName));

            if (string.IsNullOrEmpty(oldFileName) || oldFileName.Equals(newFileName))
            {
                return;
            }

            foreach (ITabbedDocument doc in PluginBase.MainForm.Documents)
            {
                if (doc.FileName.Equals(oldFileName))
                {
                    doc.Save();
                    doc.Close();
                    break;
                }
            }

            RefactoringHelper.Move(oldFileName, newFileName);
            AssociatedDocumentHelper.LoadDocument(newFileName);
            if (results.ContainsKey(oldFileName))
            {
                results[newFileName] = results[oldFileName];
                results.Remove(oldFileName);
            }
        }