示例#1
0
        private async Task RenameFiles(IList <IArchiveFileInfo> files)
        {
            if (files.Count <= 0)
            {
                _communicator.ReportStatus(true, "No files to rename.");
                return;
            }

            // Rename elements
            _communicator.ReportStatus(true, string.Empty);

            _progress.StartProgress();
            await _asyncOperation.StartAsync(cts =>
            {
                var count = 0;
                foreach (var file in files)
                {
                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }

                    _progress.ReportProgress("Rename files", count++, files.Count);

                    // Select new name
                    var newName = Application.Instance.Invoke(() =>
                    {
                        var inputBox = new InputBoxDialog($"Select a new name for '{file.FilePath.GetName()}'",
                                                          "Rename file", file.FilePath.GetName());
                        return(inputBox.ShowModal(this));
                    });

                    if (string.IsNullOrEmpty(newName))
                    {
                        continue;
                    }

                    // Rename possibly open file in main form
                    _communicator.Rename(file, file.FilePath.GetDirectory() / newName);

                    // Rename file in archive
                    _archiveFileSystem.MoveFile(file.FilePath, file.FilePath.GetDirectory() / newName);

                    AddChangedDirectory(file.FilePath.GetDirectory());
                }
            });

            _progress.ReportProgress("Rename files", 1, 1);
            _progress.FinishProgress();

            if (_asyncOperation.WasCancelled)
            {
                _communicator.ReportStatus(false, "File renaming cancelled.");
            }
            else
            {
                _communicator.ReportStatus(true, "File(s) renamed successfully.");
            }

            UpdateFiles(GetAbsolutePath((TreeGridItem)folderView.SelectedItem));
            UpdateDirectories();
        }
示例#2
0
        private async Task RenameDirectory(TreeGridItem item)
        {
            var itemPath  = GetAbsolutePath(item);
            var filePaths = _archiveFileSystem.EnumerateAllFiles(itemPath).Select(x => x.GetSubDirectory(itemPath).ToRelative()).ToArray();

            if (filePaths.Length <= 0)
            {
                _communicator.ReportStatus(true, "No files to rename.");
                return;
            }

            // Select new directory name
            var inputBox = new InputBoxDialog($"Select a new name for '{GetItemName(item)}'",
                                              "Rename directory", GetItemName(item));
            var newName = inputBox.ShowModal(this);

            if (string.IsNullOrEmpty(newName))
            {
                _communicator.ReportStatus(false, "No new name given.");
                return;
            }

            // Rename elements
            _communicator.ReportStatus(true, string.Empty);

            var newDirectoryPath = GetAbsolutePath(item).GetDirectory() / newName;

            _progress.StartProgress();
            await _asyncOperation.StartAsync(cts =>
            {
                var count = 0;
                foreach (var filePath in filePaths)
                {
                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }

                    _progress.ReportProgress("Rename files", count++, filePaths.Length);

                    // Rename possibly open file in main form
                    var afi = ((AfiFileEntry)_archiveFileSystem.GetFileEntry(itemPath / filePath)).ArchiveFileInfo;
                    _communicator.Rename(afi, newDirectoryPath / filePath.ToRelative());

                    // Rename file in archive
                    _archiveFileSystem.MoveFile(afi.FilePath, newDirectoryPath / filePath.ToRelative());

                    AddChangedDirectory(afi.FilePath.GetDirectory());
                }
            });

            _progress.ReportProgress("Rename files", 1, 1);
            _progress.FinishProgress();

            if (_asyncOperation.WasCancelled)
            {
                _communicator.ReportStatus(false, "File renaming cancelled.");
            }
            else
            {
                _communicator.ReportStatus(true, "File(s) renamed successfully.");
            }

            SetItemName(item, newName);

            UpdateFiles(GetAbsolutePath((TreeGridItem)folderView.SelectedItem));
            UpdateDirectories();
        }