コード例 #1
0
ファイル: AddItemDialog.xaml.cs プロジェクト: robhein/Files
        public static async void CreateFile(AddItemType itemType)
        {
            string currentPath = null;

            if (App.CurrentInstance.ContentPage != null)
            {
                currentPath = App.CurrentInstance.FilesystemViewModel.WorkingDirectory;
            }

            StorageFolderWithPath folderWithPath = await ItemViewModel.GetFolderWithPathFromPathAsync(currentPath);

            StorageFolder folderToCreateItem = folderWithPath.Folder;

            // Show rename dialog
            RenameDialog renameDialog = new RenameDialog();
            var          renameResult = await renameDialog.ShowAsync();

            if (renameResult != ContentDialogResult.Primary)
            {
                return;
            }

            // Create file based on dialog result
            string userInput = renameDialog.storedRenameInput;

            try
            {
                switch (itemType)
                {
                case AddItemType.Folder:
                    userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
                    await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.GenerateUniqueName);

                    break;

                case AddItemType.TextDocument:
                    userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewTextDocument".GetLocalized();
                    await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.GenerateUniqueName);

                    break;

                case AddItemType.BitmapImage:
                    userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewBitmapImage".GetLocalized();
                    await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.GenerateUniqueName);

                    break;
                }
            }
            catch (UnauthorizedAccessException)
            {
                await DialogDisplayHelper.ShowDialog("AccessDeniedCreateDialog/Title".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
            }
        }
コード例 #2
0
ファイル: AddItemDialog.xaml.cs プロジェクト: teemobean/Files
        public static async void CreateFile(AddItemType itemType)
        {
            string currentPath = null;

            if (App.CurrentInstance.ContentPage != null)
            {
                currentPath = App.CurrentInstance.FilesystemViewModel.WorkingDirectory;
            }

            StorageFolderWithPath folderWithPath = await ItemViewModel.GetFolderWithPathFromPathAsync(currentPath);

            StorageFolder folderToCreateItem = folderWithPath.Folder;

            // Show rename dialog
            RenameDialog renameDialog = new RenameDialog();
            var          renameResult = await renameDialog.ShowAsync();

            if (renameResult != ContentDialogResult.Primary)
            {
                return;
            }

            // Create file based on dialog result
            string userInput = renameDialog.storedRenameInput;

            switch (itemType)
            {
            case AddItemType.Folder:
                userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewFolder");
                await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.GenerateUniqueName);

                break;

            case AddItemType.TextDocument:
                userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewTextDocument");
                await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.GenerateUniqueName);

                break;

            case AddItemType.BitmapImage:
                userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewBitmapImage");
                await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.GenerateUniqueName);

                break;
            }
        }
コード例 #3
0
        public static async void CreateFile(AddItemType fileType)
        {
            var    TabInstance = App.CurrentInstance;
            string currentPath = null;

            if (TabInstance.ContentPage != null)
            {
                currentPath = TabInstance.FilesystemViewModel.WorkingDirectory;
            }
            var folderWithPath = await Filesystem.ItemViewModel.GetFolderWithPathFromPathAsync(currentPath);

            StorageFolder folderToCreateItem = folderWithPath.Folder;
            RenameDialog  renameDialog       = new RenameDialog();

            var renameResult = await renameDialog.ShowAsync();

            if (renameResult != ContentDialogResult.Primary)
            {
                return;
            }

            var userInput = renameDialog.storedRenameInput;

            if (fileType == AddItemType.Folder)
            {
                userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewFolder");

                await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.GenerateUniqueName);
            }
            else if (fileType == AddItemType.TextDocument)
            {
                userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewTextDocument");

                await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.GenerateUniqueName);
            }
            else if (fileType == AddItemType.BitmapImage)
            {
                userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewBitmapImage");

                await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.GenerateUniqueName);
            }
        }
コード例 #4
0
        public static async void CreateFile(AddItemType fileType)
        {
            var    TabInstance = App.OccupiedInstance;
            string currentPath = null;

            if (TabInstance.ItemDisplayFrame.SourcePageType == typeof(GenericFileBrowser))
            {
                currentPath = TabInstance.instanceViewModel.Universal.path;
            }
            else if (TabInstance.ItemDisplayFrame.SourcePageType == typeof(PhotoAlbum))
            {
                currentPath = TabInstance.instanceViewModel.Universal.path;
            }
            StorageFolder folderToCreateItem = await StorageFolder.GetFolderFromPathAsync(currentPath);

            RenameDialog renameDialog = new RenameDialog();

            await renameDialog.ShowAsync();

            var userInput = renameDialog.storedRenameInput;

            if (fileType == AddItemType.Folder)
            {
                StorageFolder folder;
                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    folder = await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.FailIfExists);
                }
                else
                {
                    folder = await folderToCreateItem.CreateFolderAsync("New Folder", CreationCollisionOption.GenerateUniqueName);
                }
                TabInstance.instanceViewModel.AddFileOrFolder(new ListedItem(folder.FolderRelativeId)
                {
                    FileName = folder.DisplayName, FileDateReal = DateTimeOffset.Now, EmptyImgVis = Visibility.Collapsed, FolderImg = Visibility.Visible, FileIconVis = Visibility.Collapsed, FileType = "Folder", FileImg = null, FilePath = folder.Path
                });
            }
            else if (fileType == AddItemType.TextDocument)
            {
                StorageFile item;
                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    item = await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.FailIfExists);
                }
                else
                {
                    item = await folderToCreateItem.CreateFileAsync("New Text Document" + ".txt", CreationCollisionOption.GenerateUniqueName);
                }
                TabInstance.instanceViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId)
                {
                    FileName = item.DisplayName, FileDateReal = DateTimeOffset.Now, EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileType = item.DisplayType, FileImg = null, FilePath = item.Path, DotFileExtension = item.FileType
                });
            }
            else if (fileType == AddItemType.BitmapImage)
            {
                StorageFile item;
                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    item = await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.FailIfExists);
                }
                else
                {
                    item = await folderToCreateItem.CreateFileAsync("New Bitmap Image" + ".bmp", CreationCollisionOption.GenerateUniqueName);
                }
                TabInstance.instanceViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId)
                {
                    FileName = item.DisplayName, FileDateReal = DateTimeOffset.Now, EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileType = item.DisplayType, FileImg = null, FilePath = item.Path, DotFileExtension = item.FileType
                });
            }
        }
コード例 #5
0
        public static async void CreateFile(AddItemType fileType)
        {
            var    TabInstance = App.CurrentInstance;
            string currentPath = null;

            if (TabInstance.ContentPage != null)
            {
                currentPath = TabInstance.ViewModel.WorkingDirectory;
            }
            StorageFolder folderToCreateItem = await StorageFolder.GetFolderFromPathAsync(currentPath);

            RenameDialog renameDialog = new RenameDialog();

            var renameResult = await renameDialog.ShowAsync();

            if (renameResult == ContentDialogResult.Secondary)
            {
                return;
            }

            var userInput = renameDialog.storedRenameInput;

            if (fileType == AddItemType.Folder)
            {
                StorageFolder folder;
                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    folder = await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.GenerateUniqueName);
                }
                else
                {
                    folder = await folderToCreateItem.CreateFolderAsync(ResourceController.GetTranslation("NewFolder"), CreationCollisionOption.GenerateUniqueName);
                }
                TabInstance.ViewModel.AddFileOrFolder(new ListedItem(folder.FolderRelativeId)
                {
                    PrimaryItemAttribute = StorageItemTypes.Folder, ItemName = folder.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = false, LoadFolderGlyph = true, LoadFileIcon = false, ItemType = "Folder", FileImage = null, ItemPath = folder.Path
                });
            }
            else if (fileType == AddItemType.TextDocument)
            {
                StorageFile item;
                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    item = await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.GenerateUniqueName);
                }
                else
                {
                    item = await folderToCreateItem.CreateFileAsync(ResourceController.GetTranslation("NewTextDocument") + ".txt", CreationCollisionOption.GenerateUniqueName);
                }
                TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId)
                {
                    PrimaryItemAttribute = StorageItemTypes.File, ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType
                });
            }
            else if (fileType == AddItemType.BitmapImage)
            {
                StorageFile item;
                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    item = await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.GenerateUniqueName);
                }
                else
                {
                    item = await folderToCreateItem.CreateFileAsync(ResourceController.GetTranslation("NewBitmapImage") + ".bmp", CreationCollisionOption.GenerateUniqueName);
                }
                TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId)
                {
                    PrimaryItemAttribute = StorageItemTypes.File, ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType
                });
            }
        }