Ejemplo n.º 1
0
        internal void ReplaceFile(PackageFile oldFile, string newFilePath)
        {
            bool showingFile = PackageViewModel.IsShowingFileContent(oldFile);

            // temporarily remove the old file in order to add a new file
            Children.Remove(oldFile);

            PackageFile newFile = AddFile(newFilePath, isTempFile: false);

            if (newFile != null)
            {
                // new file added successfully, officially delete the old file by disposing it
                oldFile.Dispose();

                if (showingFile)
                {
                    PackageViewModel.ShowFileContent(newFile);
                }
            }
            else
            {
                // otherwise, if the adding failed, restore the old file
                Children.Add(oldFile);
            }
        }
Ejemplo n.º 2
0
        public PackageFile AddFile(string filePath, bool isTempFile)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException("File does not exist.", "filePath");
            }

            string newFileName = System.IO.Path.GetFileName(filePath);

            if (ContainsFolder(newFileName))
            {
                PackageViewModel.UIServices.Show(Resources.FileNameConflictWithExistingDirectory, MessageLevel.Error);
                return(null);
            }

            bool showingRemovedFile = false;

            if (ContainsFile(newFileName))
            {
                bool confirmed = PackageViewModel.UIServices.Confirm(
                    Resources.ConfirmToReplaceExsitingFile_Title,
                    String.Format(CultureInfo.CurrentCulture, Resources.ConfirmToReplaceExsitingFile, newFileName),
                    isWarning: true);

                if (confirmed)
                {
                    var part = this[newFileName] as PackageFile;
                    showingRemovedFile = PackageViewModel.IsShowingFileContent(part);

                    // remove the existing file before adding the new one
                    RemoveChildByName(newFileName);
                }
                else
                {
                    return(null);
                }
            }

            string newTargetPath = this.Path + "\\" + newFileName;
            var    physicalFile  = new PhysicalPackageFile
            {
                SourcePath = filePath,
                TargetPath = newTargetPath
            };
            var newFile = new PackageFile(physicalFile, newFileName, this);

            Children.Add(newFile);
            newFile.IsSelected = true;
            IsExpanded         = true;
            PackageViewModel.NotifyChanges();

            if (showingRemovedFile)
            {
                PackageViewModel.ShowFileContent(newFile);
            }

            return(newFile);
        }
        public bool Save(string editedFilePath)
        {
            if (!string.Equals(OriginalPath, editedFilePath, StringComparison.OrdinalIgnoreCase))
            {
                ReplaceWith(editedFilePath);
            }
            else if (PackageViewModel.IsShowingFileContent(this))
            {
                // force a refresh to show new content
                PackageViewModel.ShowFileContent(this);
            }

            return(true);
        }