/// <summary> /// Tries to save changed properties to file. /// </summary> /// <returns>Returns true if properties have been saved successfully.</returns> public async Task <bool> SaveChangesAsync() { while (true) { using DynamicDialog dialog = DynamicDialogFactory.GetFor_PropertySaveErrorDialog(); try { await(BaseProperties as FileProperties).SyncPropertyChangesAsync(); return(true); } catch { // Attempting to open more than one ContentDialog // at a time will throw an error) if (UIHelpers.IsAnyContentDialogOpen()) { return(false); } await dialog.ShowAsync(); switch (dialog.DynamicResult) { case DynamicDialogResult.Primary: break; case DynamicDialogResult.Secondary: return(true); case DynamicDialogResult.Cancel: return(false); } } } }
public static async void ShowRestoreDefaultLibrariesDialog() { var dialog = new DynamicDialog(new DynamicDialogViewModel { TitleText = "DialogRestoreLibrariesTitleText".GetLocalized(), SubtitleText = "DialogRestoreLibrariesSubtitleText".GetLocalized(), PrimaryButtonText = "DialogRestoreLibrariesButtonText".GetLocalized(), CloseButtonText = "Cancel".GetLocalized(), PrimaryButtonAction = async(vm, e) => { var connection = await AppServiceConnectionHelper.Instance; if (connection != null) { await connection.SendMessageAsync(new ValueSet() { { "Arguments", "InvokeVerb" }, { "FilePath", ShellLibraryItem.LibrariesPath }, { "Verb", "restorelibraries" } }); } await App.LibraryManager.EnumerateLibrariesAsync(); }, CloseButtonAction = (vm, e) => vm.HideDialog(), KeyDownAction = (vm, e) => { if (e.Key == VirtualKey.Escape) { vm.HideDialog(); } }, DynamicButtons = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel }); await dialog.ShowAsync(); }
/// <summary> /// Standard dialog, to ensure consistency. /// The secondaryText can be un-assigned to hide its respective button. /// Result is true if the user presses primary text button /// </summary> /// <param name="title"> /// The title of this dialog /// </param> /// <param name="message"> /// THe main body message displayed within the dialog /// </param> /// <param name="primaryText"> /// Text to be displayed on the primary button (which returns true when pressed). /// If not set, defaults to 'OK' /// </param> /// <param name="secondaryText"> /// The (optional) secondary button text. /// If not set, it won't be presented to the user at all. /// </param> public static async Task <bool> ShowDialogAsync(string title, string message, string primaryText = "OK", string secondaryText = null) { bool result = false; try { if (Window.Current.Content is Frame rootFrame) { DynamicDialog dialog = new DynamicDialog(new DynamicDialogViewModel() { TitleText = title, SubtitleText = message, // We can use subtitle here as our actual message and skip DisplayControl PrimaryButtonText = primaryText, SecondaryButtonText = secondaryText, DynamicButtons = DynamicDialogButtons.Primary | DynamicDialogButtons.Secondary }); await dialog.ShowAsync(); result = dialog.DynamicResult == DynamicDialogResult.Primary; } } catch (Exception) { } return(result); }
private async void DeleteLibrary_Click(object sender, RoutedEventArgs e) { var item = (sender as MenuFlyoutItem).DataContext as LibraryCardItem; if (item.IsUserCreatedLibrary) { var dialog = new DynamicDialog(new DynamicDialogViewModel { TitleText = "LibraryCardsDeleteLibraryDialogTitleText".GetLocalized(), SubtitleText = "LibraryCardsDeleteLibraryDialogSubtitleText".GetLocalized(), PrimaryButtonText = "DialogDeleteLibraryButtonText".GetLocalized(), CloseButtonText = "DialogCancelButtonText".GetLocalized(), PrimaryButtonAction = (vm, e) => LibraryCardDeleteInvoked?.Invoke(this, new LibraryCardEventArgs { Library = item.Library }), CloseButtonAction = (vm, e) => vm.HideDialog(), KeyDownAction = (vm, e) => { if (e.Key == VirtualKey.Enter) { vm.PrimaryButtonAction(vm, null); } else if (e.Key == VirtualKey.Escape) { vm.HideDialog(); } }, DynamicButtons = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel }); await dialog.ShowAsync(); } }
public static async Task <IStorageItem> CreateFileFromDialogResultTypeForResult(AddItemDialogItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance) { string currentPath = null; if (associatedInstance.SlimContentPage != null) { currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory; if (App.LibraryManager.TryGetLibrary(currentPath, out var library)) { if (!library.IsEmpty && library.Folders.Count == 1) // TODO: handle libraries with multiple folders { currentPath = library.Folders.First(); } } } // Skip rename dialog when ShellNewEntry has a Command (e.g. ".accdb", ".gdoc") string userInput = null; if (itemType != AddItemDialogItemType.File || itemInfo?.Command == null) { DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog(); await dialog.ShowAsync(); // Show rename dialog if (dialog.DynamicResult != DynamicDialogResult.Primary) { return(null); } userInput = dialog.ViewModel.AdditionalData as string; } // Create file based on dialog result (ReturnResult Status, IStorageItem Item)created = (ReturnResult.Failed, null); switch (itemType) { case AddItemDialogItemType.Folder: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized(); created = await associatedInstance.FilesystemHelpers.CreateAsync( StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput), FilesystemItemType.Directory), true); break; case AddItemDialogItemType.File: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized(); created = await associatedInstance.FilesystemHelpers.CreateAsync( StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput + itemInfo?.Extension), FilesystemItemType.File), true); break; } if (created.Status == ReturnResult.AccessUnauthorized) { await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized()); } return(created.Item); }
/// <summary> /// Tries to save changed properties to file. /// </summary> /// <returns>Returns true if properties have been saved successfully.</returns> public async Task <bool> SaveChangesAsync() { while (true) { using DynamicDialog dialog = DynamicDialogFactory.GetFor_PropertySaveErrorDialog(); try { await(BaseProperties as FileProperties).SyncPropertyChangesAsync(); return(true); } catch { await dialog.ShowAsync(); switch (dialog.DynamicResult) { case DynamicDialogResult.Primary: break; case DynamicDialogResult.Secondary: return(true); case DynamicDialogResult.Cancel: return(false); } } // Wait for the current dialog to be closed before continuing the loop // and opening another dialog (attempting to open more than one ContentDialog // at a time will throw an error) while (dialog.IsLoaded) { } } }
public static async Task <IStorageItem> CreateFileFromDialogResultTypeForResult(AddItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance) { string currentPath = null; if (associatedInstance.SlimContentPage != null) { currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory; } // Show rename dialog DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog(); await dialog.ShowAsync(); if (dialog.DynamicResult != DynamicDialogResult.Primary) { return(null); } // Create file based on dialog result string userInput = dialog.ViewModel.AdditionalData as string; var folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath); FilesystemResult <(ReturnResult, IStorageItem)> created = null; if (folderRes) { switch (itemType) { case AddItemType.Folder: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized(); created = await FilesystemTasks.Wrap(async() => { return(await associatedInstance.FilesystemHelpers.CreateAsync( StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory), true)); }); break; case AddItemType.File: userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized(); created = await FilesystemTasks.Wrap(async() => { return(await associatedInstance.FilesystemHelpers.CreateAsync( StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File), true)); }); break; } } if (created == FileSystemStatusCode.Unauthorized) { await DialogDisplayHelper.ShowDialogAsync("AccessDeniedCreateDialog/Title".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized()); } return(created.Result.Item2); }
public static async Task <DynamicDialogResult> ShowDialogAsync(DynamicDialog dialog) { try { if (Window.Current.Content is Frame rootFrame) { await dialog.ShowAsync(); return(dialog.DynamicResult); } } catch (Exception) { } return(DynamicDialogResult.Cancel); }
private async void RecentFilesWidget_RecentFileInvoked(object sender, UserControls.PathNavigationEventArgs e) { try { var directoryName = Path.GetDirectoryName(e.ItemPath); await AppInstance.InteractionOperations.InvokeWin32ComponentAsync(e.ItemPath, workingDir : directoryName); } catch (UnauthorizedAccessException) { DynamicDialog dialog = DynamicDialogFactory.GetFor_ConsentDialog(); await dialog.ShowAsync(); } catch (ArgumentException) { if (new DirectoryInfo(e.ItemPath).Root.ToString().Contains(@"C:\")) { AppInstance.ContentFrame.Navigate(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments() { AssociatedTabInstance = AppInstance, NavPathParam = e.ItemPath }); } else { foreach (DriveItem drive in Enumerable.Concat(App.DrivesManager.Drives, AppSettings.CloudDrivesManager.Drives)) { if (drive.Path.ToString() == new DirectoryInfo(e.ItemPath).Root.ToString()) { AppInstance.ContentFrame.Navigate(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments() { AssociatedTabInstance = AppInstance, NavPathParam = e.ItemPath }); return; } } } } catch (COMException) { await DialogDisplayHelper.ShowDialogAsync( "DriveUnpluggedDialog/Title".GetLocalized(), "DriveUnpluggedDialog/Text".GetLocalized()); } }
public static async void ShowCreateNewLibraryDialog() { var inputText = new TextBox { PlaceholderText = "FolderWidgetCreateNewLibraryInputPlaceholderText".GetLocalized() }; var tipText = new TextBlock { Text = string.Empty, Visibility = Visibility.Collapsed }; var dialog = new DynamicDialog(new DynamicDialogViewModel { DisplayControl = new Grid { Children = { new StackPanel { Spacing = 4d, Children = { inputText, tipText } } } }, TitleText = "FolderWidgetCreateNewLibraryDialogTitleText".GetLocalized(), SubtitleText = "SideBarCreateNewLibrary/Text".GetLocalized(), PrimaryButtonText = "DialogCreateLibraryButtonText".GetLocalized(), CloseButtonText = "Cancel".GetLocalized(), PrimaryButtonAction = async(vm, e) => { var(result, reason) = App.LibraryManager.CanCreateLibrary(inputText.Text); tipText.Text = reason; tipText.Visibility = result ? Visibility.Collapsed : Visibility.Visible; if (!result) { e.Cancel = true; return; } await App.LibraryManager.CreateNewLibrary(inputText.Text); }, CloseButtonAction = (vm, e) => { vm.HideDialog(); }, KeyDownAction = async(vm, e) => { if (e.Key == VirtualKey.Enter) { await App.LibraryManager.CreateNewLibrary(inputText.Text); } else if (e.Key == VirtualKey.Escape) { vm.HideDialog(); } }, DynamicButtons = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel }); await dialog.ShowAsync(); }