public override void RenameItem(string newName)
        {
            SystemFile file    = CurrentNode.DataItem as SystemFile;
            string     oldname = file.Path;

            string newname = Path.Combine(Path.GetDirectoryName(oldname), newName);

            if (newname != oldname)
            {
                try {
                    if (!FileService.IsValidPath(newname) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
                    {
                        MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                    }
                    else if (File.Exists(newname) || Directory.Exists(newname))
                    {
                        MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
                    }
                    else
                    {
                        FileService.RenameFile(oldname, newname);
                    }
                } catch (System.ArgumentException) {                 // new file name with wildcard (*, ?) characters in it
                    MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                } catch (System.IO.IOException ex) {
                    MessageService.ShowError(GettextCatalog.GetString("There was an error renaming the file."), ex);
                }
            }
        }
 public static bool RenameFileWithConflictCheck(FilePath oldPath, string newName, out string newPath)
 {
     newPath = oldPath.ParentDirectory.Combine(newName);
     if (oldPath == newPath)
     {
         return(false);
     }
     try {
         if (!FileService.IsValidPath(newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
         {
             MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
         }
         else if (File.Exists(newPath) || Directory.Exists(newPath))
         {
             MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
         }
         else
         {
             FileService.RenameFile(oldPath, newPath);
             return(true);
         }
     } catch (ArgumentException) {             // new file name with wildcard (*, ?) characters in it
         MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
     } catch (IOException ex) {
         MessageService.ShowError(GettextCatalog.GetString("There was an error renaming the file."), ex);
     }
     return(false);
 }
Example #3
0
        public async override void RenameItem(string newName)
        {
            ProjectFile newProjectFile = null;
            var         file           = (ProjectFile)CurrentNode.DataItem;

            string oldFileName = file.FilePath;
            string newFileName = Path.Combine(Path.GetDirectoryName(oldFileName), newName);

            if (oldFileName == newFileName)
            {
                return;
            }

            FilePath newPath, newLink = FilePath.Null;

            if (file.IsLink)
            {
                var oldLink = file.ProjectVirtualPath;
                newLink = oldLink.ParentDirectory.Combine(newName);
                newPath = file.Project.BaseDirectory.Combine(newLink);
            }
            else
            {
                newPath = file.FilePath.ParentDirectory.Combine(newName);
            }

            try {
                if (file.Project != null)
                {
                    newProjectFile = file.Project.Files.GetFileWithVirtualPath(newPath.ToRelative(file.Project.BaseDirectory));
                }

                if (!FileService.IsValidPath(newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
                {
                    MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                }
                else if ((newProjectFile != null && newProjectFile != file) || File.Exists(file.FilePath.ParentDirectory.Combine(newName)))
                {
                    // If there is already a file under the newPath which is *different*, then throw an exception
                    MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
                }
                else
                {
                    FileService.RenameFile(file.FilePath, newName);
                    if (file.Project != null)
                    {
                        await IdeApp.ProjectOperations.SaveAsync(file.Project);
                    }
                }
            } catch (ArgumentException) {             // new file name with wildcard (*, ?) characters in it
                MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
            } catch (IOException ex) {
                MessageService.ShowError(GettextCatalog.GetString("There was an error renaming the file."), ex);
            }
        }
Example #4
0
        static bool CanRenameFile(ProjectFile file, string newName)
        {
            ProjectFile newProjectFile = null;
            FilePath    newPath        = GetRenamedFilePath(file, newName);

            if (file.Project != null)
            {
                newProjectFile = file.Project.Files.GetFileWithVirtualPath(newPath.ToRelative(file.Project.BaseDirectory));
            }

            if (!FileService.IsValidPath(newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
            {
                MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                return(false);
            }
            else if ((newProjectFile != null && newProjectFile != file) || FileExistsCaseSensitive(file.FilePath.ParentDirectory, newName))
            {
                // If there is already a file under the newPath which is *different*, then throw an exception
                MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
                return(false);
            }

            return(true);
        }