NotifyChanges() private method

private NotifyChanges ( ) : void
return void
Exemplo n.º 1
0
 private void AddFolderCore(PackageFolder childFolder)
 {
     Attach(childFolder);
     childFolder.IsSelected = true;
     IsExpanded             = true;
     PackageViewModel.NotifyChanges();
 }
Exemplo n.º 2
0
        public PackageFile AddFile(string filePath)
        {
            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, Types.MessageLevel.Error);
                return(null);
            }

            bool showingRemovedFile = false;

            if (ContainsFile(newFileName))
            {
                bool confirmed = PackageViewModel.UIServices.Confirm(Resources.ConfirmToReplaceExsitingFile, true);
                if (confirmed)
                {
                    // check if we are currently showing the content of the file to be removed.
                    // if we are, we'll need to show the new content after replacing the file.
                    if (PackageViewModel.ShowContentViewer)
                    {
                        PackagePart part = this[newFileName];
                        if (PackageViewModel.CurrentFileInfo.File == part)
                        {
                            showingRemovedFile = true;
                        }
                    }

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

            var physicalFile = new PhysicalFile(filePath);
            var newFile      = new PackageFile(physicalFile, newFileName, this);

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

            if (showingRemovedFile)
            {
                ICommand command = PackageViewModel.ViewContentCommand;
                command.Execute(newFile);
            }

            return(newFile);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 private void RemoveChildByName(string name)
 {
     var count = Children.RemoveAll(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
     Debug.Assert(count <= 1);
     if (count == 1)
     {
         PackageViewModel.NotifyChanges();
     }
 }
Exemplo n.º 5
0
        public void RemoveChild(PackagePart child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            bool removed = Children.Remove(child);

            if (removed)
            {
                PackageViewModel.NotifyChanges();
            }
        }
        public void RemoveChild(PackagePart child)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var removed = Children.Remove(child);

            if (removed)
            {
                child.Dispose();
                PackageViewModel.NotifyChanges();
            }
        }
Exemplo n.º 7
0
        public PackageFolder AddFolder(string folderName)
        {
            if (ContainsFolder(folderName) || ContainsFile(folderName))
            {
                PackageViewModel.UIServices.Show(Resources.RenameCausesNameCollison, Types.MessageLevel.Error);
                return(null);
            }
            var newFolder = new PackageFolder(folderName, this);

            Children.Add(newFolder);
            newFolder.IsSelected = true;
            this.IsExpanded      = true;
            PackageViewModel.NotifyChanges();
            return(newFolder);
        }
Exemplo n.º 8
0
        public void AddFile(PackageFile file, bool makeCopy = false)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (Contains(file))
            {
                return;
            }

            PackagePart newFile;

            if (makeCopy)
            {
                string fileCopyPath;
                using (Stream originalFileStream = file.GetStream())
                {
                    fileCopyPath = FileHelper.CreateTempFile(file.Name, originalFileStream);
                }

                string newTargetPath = this.Path + "\\" + file.Name;
                var    physicalFile  = new PhysicalPackageFile
                {
                    SourcePath = fileCopyPath,
                    TargetPath = newTargetPath
                };

                newFile = new PackageFile(physicalFile, file.Name, this);
            }
            else
            {
                // detach from current parent
                if (file.Parent != null)
                {
                    file.Parent.Detach(file);
                }

                newFile = file;
            }

            Attach(newFile);
            newFile.IsSelected = true;
            IsExpanded         = true;
            PackageViewModel.NotifyChanges();
        }
Exemplo n.º 9
0
        public void Rename(string newName)
        {
            if (Name != newName)
            {
                if (Parent != null)
                {
                    if (Parent.ContainsFile(newName) || Parent.ContainsFolder(newName))
                    {
                        PackageViewModel.UIServices.Show(Resources.RenameCausesNameCollison, Types.MessageLevel.Error);
                        return;
                    }
                }

                Name = newName;
                PackageViewModel.NotifyChanges();
            }
        }
Exemplo n.º 10
0
        public void AddFile(PackageFile file, bool makeCopy = false)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (Contains(file))
            {
                return;
            }

            PackagePart newFile;

            if (makeCopy)
            {
                string fileCopyPath;
                using (var originalFileStream = file.GetStream())
                {
                    fileCopyPath = FileHelper.CreateTempFile(file.Name, originalFileStream);
                }

                var newTargetPath = Path + "\\" + file.Name;
                var physicalFile  = new DiskPackageFile(newTargetPath, fileCopyPath);

                newFile = new PackageFile(physicalFile, file.Name, this);
            }
            else
            {
                ((PackageFolder?)file.Parent)?.Detach(file);

                newFile = file;
            }

            Attach(newFile);
            newFile.IsSelected = true;
            IsExpanded         = true;
            PackageViewModel?.NotifyChanges();
        }
 private void SaveFile(IFileEditorService editorService)
 {
     editorService.Save(_filePath);
     _packageViewModel.NotifyChanges();
     _hasSaved = true;
 }