Ejemplo n.º 1
0
        private void AddFileToFolder(PackageFolder folder, string file)
        {
            if (folder == null)
            {
                string guessFolderName = FileHelper.GuessFolderNameFromFile(file);
                bool   confirmed       = UIServices.Confirm(
                    String.Format(CultureInfo.CurrentCulture, Resources.ConfirmToMoveFileIntoFolder, file, guessFolderName));

                if (confirmed)
                {
                    if (RootFolder.ContainsFolder(guessFolderName))
                    {
                        folder = (PackageFolder)RootFolder[guessFolderName];
                    }
                    else
                    {
                        folder = RootFolder.AddFolder(guessFolderName);
                    }
                }
                else
                {
                    folder = RootFolder;
                }
            }

            folder.AddFile(file);
        }
Ejemplo n.º 2
0
        private void AddPhysicalFolderCore(DirectoryInfo dirInfo)
        {
            PackageFolder childPackgeFolder = AddFolder(dirInfo.Name);

            foreach (FileInfo file in dirInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly))
            {
                childPackgeFolder.AddFile(file.FullName, isTempFile: false);
            }
            foreach (DirectoryInfo subFolder in dirInfo.GetDirectories("*.*", SearchOption.TopDirectoryOnly))
            {
                childPackgeFolder.AddPhysicalFolderCore(subFolder);
            }
        }
        public void AddFolder(PackageFolder childFolder, bool makeCopy = false)
        {
            if (childFolder is null)
            {
                throw new ArgumentNullException(nameof(childFolder));
            }
            if (!AddContentFolderCanExecute(childFolder.Name))
            {
                PackageViewModel.UIServices.Show(
                    string.Format(CultureInfo.CurrentCulture, Resources.RenameCausesNameCollison, childFolder.Name),
                    MessageLevel.Error);
                return;
            }

            if (IsDescendantOf(childFolder))
            {
                return;
            }

            PackageFolder newFolder;

            if (makeCopy)
            {
                newFolder = new PackageFolder(childFolder.Name, this);

                foreach (var child in childFolder.Children)
                {
                    if (child is PackageFile packageFile)
                    {
                        newFolder.AddFile(packageFile, true);
                    }
                    else if (child is PackageFolder packageFolder)
                    {
                        newFolder.AddFolder(packageFolder, true);
                    }
                }
            }
            else
            {
                if (childFolder.Parent != null)
                {
                    childFolder.Parent.Detach(childFolder);
                }

                newFolder = childFolder;
            }

            AddFolderCore(newFolder);
        }
Ejemplo n.º 4
0
        private void AddExistingFileToFolder(PackageFolder folder)
        {
            var result = UIServices.OpenMultipleFilesDialog(
                "Select Files",
                "All files (*.*)|*.*",
                out var selectedFiles);

            if (result)
            {
                foreach (var file in selectedFiles)
                {
                    folder.AddFile(file);
                }
            }
        }
        private void AddExistingFileToFolder(PackageFolder folder)
        {
            string[] selectedFiles;
            bool     result = UIServices.OpenMultipleFilesDialog(
                "Select Files",
                "All files (*.*)|*.*",
                out selectedFiles);

            if (result)
            {
                foreach (string file in selectedFiles)
                {
                    folder.AddFile(file, isTempFile: false);
                }
            }
        }
Ejemplo n.º 6
0
        private void AddNewFileToFolder(PackageFolder folder)
        {
            var result = UIServices.OpenRenameDialog(
                "NewFile.txt",
                "Provide name for the new file.",
                out var newName);

            if (result)
            {
                var sourcePath = FileHelper.CreateTempFile(newName);
                var file       = folder.AddFile(sourcePath);
                // file can be null if it collides with other files in the same directory
                if (file != null)
                {
                    EditFileCommandExecute(file);
                }
            }
        }
Ejemplo n.º 7
0
        public void AddDraggedAndDroppedFiles(PackageFolder folder, string[] fileNames)
        {
            if (folder == null)
            {
                bool?rememberedAnswer = null;

                for (var i = 0; i < fileNames.Length; i++)
                {
                    var file = fileNames[i];
                    if (File.Exists(file))
                    {
                        bool movingFile;

                        PackageFolder targetFolder;
                        var           guessFolderName = FileHelper.GuessFolderNameFromFile(file);

                        if (rememberedAnswer == null)
                        {
                            // ask user if he wants to move file
                            var answer = UIServices.ConfirmMoveFile(
                                Path.GetFileName(file),
                                guessFolderName, fileNames.Length - i - 1);

                            if (answer.Item1 == null)
                            {
                                // user presses Cancel
                                break;
                            }

                            movingFile = (bool)answer.Item1;
                            if (answer.Item2)
                            {
                                rememberedAnswer = answer.Item1;
                            }
                        }
                        else
                        {
                            movingFile = (bool)rememberedAnswer;
                        }

                        if (movingFile)
                        {
                            if (RootFolder.ContainsFolder(guessFolderName))
                            {
                                targetFolder = (PackageFolder)RootFolder[guessFolderName];
                            }
                            else
                            {
                                targetFolder = RootFolder.AddFolder(guessFolderName);
                            }
                        }
                        else
                        {
                            targetFolder = RootFolder;
                        }

                        targetFolder.AddFile(file);
                    }
                    else if (Directory.Exists(file))
                    {
                        RootFolder.AddPhysicalFolder(file);
                    }
                }
            }
            else
            {
                foreach (var file in fileNames)
                {
                    if (File.Exists(file))
                    {
                        folder.AddFile(file);
                    }
                    else if (Directory.Exists(file))
                    {
                        folder.AddPhysicalFolder(file);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void AddFileToFolder(PackageFolder folder, string file)
        {
            if (folder == null) {
                string guessFolderName = FileHelper.GuessFolderNameFromFile(file);
                bool confirmed = UIServices.Confirm(
                    String.Format(CultureInfo.CurrentCulture, Resources.ConfirmToMoveFileIntoFolder, file, guessFolderName));

                if (confirmed) {
                    if (RootFolder.ContainsFolder(guessFolderName)) {
                        folder = (PackageFolder)RootFolder[guessFolderName];
                    }
                    else {
                        folder = RootFolder.AddFolder(guessFolderName);
                    }
                }
                else {
                    folder = RootFolder;
                }
            }

            folder.AddFile(file);
        }
Ejemplo n.º 9
0
        private void AddExistingFileToFolder(PackageFolder folder)
        {
            string[] selectedFiles;
            bool result = UIServices.OpenMultipleFilesDialog(
                "Select Files",
                "All files (*.*)|*.*",
                out selectedFiles);

            if (result) {
                foreach (string file in selectedFiles) {
                    folder.AddFile(file);
                }
            }
        }
 private void AddNewFileToFolder(PackageFolder folder)
 {
     string newName;
     bool result = UIServices.OpenRenameDialog(
         "NewFile.txt",
         "Provide name for the new file.",
         out newName);
     if (result)
     {
         string sourcePath = FileHelper.CreateTempFile(newName);
         PackageFile file = folder.AddFile(sourcePath, isTempFile: true);
         // file can be null if it collides with other files in the same directory
         if (file != null)
         {
             EditFileCommandExecute(file);
         }
     }
 }
        public void AddDraggedAndDroppedFiles(PackageFolder folder, string[] fileNames)
        {
            if (folder == null)
            {
                bool? rememberedAnswer = null;

                for (int i = 0; i < fileNames.Length; i++)
                {
                    string file = fileNames[i];
                    if (File.Exists(file))
                    {
                        bool movingFile;

                        PackageFolder targetFolder;
                        string guessFolderName = FileHelper.GuessFolderNameFromFile(file);

                        if (rememberedAnswer == null)
                        {
                            // ask user if he wants to move file
                            Tuple<bool?, bool> answer = UIServices.ConfirmMoveFile(
                                Path.GetFileName(file),
                                guessFolderName, fileNames.Length - i - 1);

                            if (answer.Item1 == null)
                            {
                                // user presses Cancel
                                break;
                            }

                            movingFile = (bool) answer.Item1;
                            if (answer.Item2)
                            {
                                rememberedAnswer = answer.Item1;
                            }
                        }
                        else
                        {
                            movingFile = (bool) rememberedAnswer;
                        }

                        if (movingFile)
                        {
                            if (RootFolder.ContainsFolder(guessFolderName))
                            {
                                targetFolder = (PackageFolder) RootFolder[guessFolderName];
                            }
                            else
                            {
                                targetFolder = RootFolder.AddFolder(guessFolderName);
                            }
                        }
                        else
                        {
                            targetFolder = RootFolder;
                        }

                        targetFolder.AddFile(file, isTempFile: false);
                    }
                    else if (Directory.Exists(file))
                    {
                        RootFolder.AddPhysicalFolder(file);
                    }
                }
            }
            else
            {
                foreach (string file in fileNames)
                {
                    if (File.Exists(file))
                    {
                        folder.AddFile(file, isTempFile: false);
                    }
                    else if (Directory.Exists(file))
                    {
                        folder.AddPhysicalFolder(file);
                    }
                }
            }
        }