Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        /// <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)
                {
                }
            }
        }
        /// <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);
        }
Ejemplo n.º 6
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public override async Task <bool> SaveChangesAsync(ListedItem item)
        {
            while (true)
            {
                using DynamicDialog dialog = DynamicDialogFactory.GetFor_PropertySaveErrorDialog();
                try
                {
                    if (BaseProperties is FileProperties fileProps)
                    {
                        await fileProps.SyncPropertyChangesAsync();
                    }
                    return(true);
                }
                catch
                {
                    await dialog.TryShowAsync();

                    switch (dialog.DynamicResult)
                    {
                    case DynamicDialogResult.Primary:
                        break;

                    case DynamicDialogResult.Secondary:
                        return(true);

                    case DynamicDialogResult.Cancel:
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public static DynamicDialog GetFor_ConsentDialog()
        {
            DynamicDialog dialog = new DynamicDialog(new DynamicDialogViewModel()
            {
                TitleText           = "WelcomeDialog/Title".GetLocalized(),
                SubtitleText        = "WelcomeDialogTextBlock/Text".GetLocalized(), // We can use subtitle here as our content
                PrimaryButtonText   = "WelcomeDialog/PrimaryButtonText".GetLocalized(),
                PrimaryButtonAction = async(vm, e) => await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-broadfilesystemaccess")),
                DynamicButtons      = DynamicDialogButtons.Primary
            });

            return(dialog);
        }
Ejemplo n.º 10
0
        public static DynamicDialog GetFor_FileInUseDialog(List <Shared.Win32Process> lockingProcess = null)
        {
            DynamicDialog dialog = new DynamicDialog(new DynamicDialogViewModel()
            {
                TitleText    = "FileInUseDialog/Title".GetLocalized(),
                SubtitleText = lockingProcess.IsEmpty() ? "FileInUseDialog/Text".GetLocalized() :
                               string.Format("FileInUseByDialog/Text".GetLocalized(), string.Join(", ", lockingProcess.Select(x => $"{x.AppName ?? x.Name} (PID: {x.Pid})"))),
                PrimaryButtonText = "OK",
                DynamicButtons    = DynamicDialogButtons.Primary
            });

            return(dialog);
        }
Ejemplo n.º 11
0
        /// <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)
        {
            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
            });

            return(await ShowDialogAsync(dialog) == DynamicDialogResult.Primary);
        }
Ejemplo n.º 12
0
        public static DynamicDialog GetFor_PropertySaveErrorDialog()
        {
            DynamicDialog dialog = new DynamicDialog(new DynamicDialogViewModel()
            {
                TitleText           = "PropertySaveErrorDialog/Title".GetLocalized(),
                SubtitleText        = "PropertySaveErrorMessage/Text".GetLocalized(), // We can use subtitle here as our content
                PrimaryButtonText   = "PropertySaveErrorDialog/PrimaryButtonText".GetLocalized(),
                SecondaryButtonText = "PropertySaveErrorDialog/SecondaryButtonText".GetLocalized(),
                CloseButtonText     = "PropertySaveErrorDialog/CloseButtonText".GetLocalized(),
                DynamicButtons      = DynamicDialogButtons.Primary | DynamicDialogButtons.Secondary | DynamicDialogButtons.Cancel
            });

            return(dialog);
        }
Ejemplo n.º 13
0
        public void Test_valid_desserialization()
        {
            string        error         = string.Empty;
            DynamicDialog dynamicDialog = DynamicDialog.GetFromJson(null, out error);

            Assert.IsNull(dynamicDialog);
            Assert.IsNotNull(error);
            System.Diagnostics.Debug.WriteLine(error);

            // Sending correct json
            string json = GetCorrectJson();

            dynamicDialog = DynamicDialog.GetFromJson(json, out error);
            Assert.IsNotNull(dynamicDialog);
            Assert.IsTrue(string.IsNullOrEmpty(error));
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
 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());
     }
 }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            var    json  = GetCorrectJson();
            string error = "";
            var    df    = DynamicDialog.GetFromJson(json, out error);

            df.ShowDialog();

            Dictionary <string, string> dic = df.GetAllReturnValues();

            if (dic != null)
            {
                foreach (var key in dic.Keys)
                {
                    System.Console.WriteLine("Key [{0}], Value: {1}", key, dic[key]);
                }

                System.Console.Write("Pressione ENTER...");
                System.Console.ReadLine();
            }
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 18
0
        public static DynamicDialog GetFor_RenameDialog()
        {
            DynamicDialog dialog    = null;
            TextBox       inputText = new TextBox()
            {
                Height          = 35d,
                PlaceholderText = "RenameDialogInputText/PlaceholderText".GetLocalized()
            };

            TextBlock tipText = new TextBlock()
            {
                Text         = "RenameDialogSymbolsTip/Text".GetLocalized(),
                Margin       = new Windows.UI.Xaml.Thickness(0, 0, 4, 0),
                TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap,
                Opacity      = 0.0d
            };

            inputText.BeforeTextChanging += async(textBox, args) =>
            {
                if (FilesystemHelpers.ContainsRestrictedCharacters(args.NewText))
                {
                    args.Cancel = true;
                    await inputText.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        var oldSelection       = textBox.SelectionStart + textBox.SelectionLength;
                        var oldText            = textBox.Text;
                        textBox.Text           = FilesystemHelpers.FilterRestrictedCharacters(args.NewText);
                        textBox.SelectionStart = oldSelection + textBox.Text.Length - oldText.Length;
                        tipText.Opacity        = 1.0d;
                    });
                }
                else
                {
                    dialog.ViewModel.AdditionalData = args.NewText;

                    if (!string.IsNullOrWhiteSpace(args.NewText))
                    {
                        dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel;
                    }
                    else
                    {
                        dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
                    }

                    tipText.Opacity = 0.0d;
                }
            };

            inputText.Loaded += (s, e) =>
            {
                // dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
                _ = inputText.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                                  () => inputText.Focus(Windows.UI.Xaml.FocusState.Programmatic));
            };

            dialog = new DynamicDialog(new DynamicDialogViewModel()
            {
                TitleText      = "RenameDialog/Title".GetLocalized(),
                SubtitleText   = null,
                DisplayControl = new Grid()
                {
                    MinWidth = 300d,
                    Children =
                    {
                        new StackPanel()
                        {
                            Spacing  = 4d,
                            Children =
                            {
                                inputText,
                                tipText
                            }
                        }
                    }
                },
                PrimaryButtonAction = (vm, e) =>
                {
                    vm.HideDialog(); // Rename successful
                },
                PrimaryButtonText     = "RenameDialog/PrimaryButtonText".GetLocalized(),
                CloseButtonText       = "Cancel".GetLocalized(),
                DynamicButtonsEnabled = DynamicDialogButtons.Cancel,
                DynamicButtons        = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
            });

            return(dialog);
        }
Ejemplo n.º 19
0
	string[] BranchDialog(DynamicDialog[] messages){
		int length = 0;
		for (int i = 0; i < messages.Length; i++){
			if (dynamicText){
				length++;
				}
			else if (!messages[i].isDynamic){
				length++;
			}
		}

		string[] returnArray = new string[length];

		for (int i = 0; i < messages.Length; i++){
			if (dynamicText){
				returnArray[i] = messages[i].message;
			}
			else if (!messages[i].isDynamic){
				returnArray[i] = messages[i].message;
			}
		}
		dynamicText = false;
		return returnArray;
	}
Ejemplo n.º 20
0
        public static DynamicDialog GetFor_RenameDialog()
        {
            DynamicDialog dialog    = null;
            TextBox       inputText = new TextBox()
            {
                Height          = 35d,
                PlaceholderText = "RenameDialogInputText/PlaceholderText".GetLocalized()
            };

            TextBlock tipText = new TextBlock()
            {
                Text         = "RenameDialogSymbolsTip/Text".GetLocalized(),
                Margin       = new Windows.UI.Xaml.Thickness(0, 0, 4, 0),
                TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap,
                Opacity      = 0.0d
            };

            inputText.TextChanged += (s, e) =>
            {
                var textBox = s as TextBox;
                dialog.ViewModel.AdditionalData = textBox.Text;

                if (FilesystemHelpers.ContainsRestrictedCharacters(textBox.Text))
                {
                    dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
                    tipText.Opacity = 1.0d;
                    return;
                }
                else if (!string.IsNullOrWhiteSpace(textBox.Text))
                {
                    dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel;
                }
                else
                {
                    dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
                }

                tipText.Opacity = 0.0d;
            };

            inputText.Loaded += (s, e) =>
            {
                // dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
                _ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => inputText.Focus(Windows.UI.Xaml.FocusState.Programmatic));
            };

            dialog = new DynamicDialog(new DynamicDialogViewModel()
            {
                TitleText      = "RenameDialog/Title".GetLocalized(),
                SubtitleText   = null,
                DisplayControl = new Grid()
                {
                    MinWidth = 300d,
                    Children =
                    {
                        new StackPanel()
                        {
                            Spacing  = 4d,
                            Children =
                            {
                                inputText,
                                tipText
                            }
                        }
                    }
                },
                PrimaryButtonAction = (vm, e) =>
                {
                    vm.HideDialog(); // Rename successful
                },
                PrimaryButtonText     = "RenameDialog/PrimaryButtonText".GetLocalized(),
                CloseButtonText       = "Cancel".GetLocalized(),
                DynamicButtonsEnabled = DynamicDialogButtons.Cancel,
                DynamicButtons        = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
            });

            return(dialog);
        }
Ejemplo n.º 21
0
        public static DynamicDialog GetFor_RenameDialog()
        {
            DynamicDialog dialog    = null;
            TextBox       inputText = new TextBox()
            {
                Height          = 35d,
                PlaceholderText = "RenameDialogInputText/PlaceholderText".GetLocalized()
            };

            TextBlock tipText = new TextBlock()
            {
                Text         = "RenameDialogSymbolsTip/Text".GetLocalized(),
                Margin       = new Windows.UI.Xaml.Thickness(0, 0, 4, 0),
                TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap,
                Opacity      = 0.0d
            };

            inputText.TextChanged += (s, e) =>
            {
                var textBox = s as TextBox;
                dialog.ViewModel.AdditionalData = textBox.Text;

                if (FilesystemHelpers.ContainsRestrictedCharacters(textBox.Text))
                {
                    dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
                    tipText.Opacity = 1.0d;
                    return;
                }
                else if (!string.IsNullOrWhiteSpace(textBox.Text))
                {
                    dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel;
                }
                else
                {
                    dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
                }

                tipText.Opacity = 0.0d;
            };

            dialog = new DynamicDialog(new DynamicDialogViewModel()
            {
                TitleText      = "RenameDialog/Title".GetLocalized(),
                SubtitleText   = null,
                DisplayControl = new Grid()
                {
                    MinWidth = 300d,
                    Children =
                    {
                        new StackPanel()
                        {
                            Orientation = Orientation.Vertical,
                            Spacing     = 4d,
                            Children    =
                            {
                                inputText,
                                tipText
                            }
                        }
                    }
                },
                PrimaryButtonAction = (vm, e) =>
                {
                    vm.HideDialog(); // Rename successful
                },
                PrimaryButtonText     = "RenameDialog/PrimaryButtonText".GetLocalized(),
                CloseButtonText       = "RenameDialog/SecondaryButtonText".GetLocalized(),
                DynamicButtonsEnabled = DynamicDialogButtons.Cancel,
                DynamicButtons        = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
            });

            return(dialog);
        }
Ejemplo n.º 22
0
	public void DynamicMessage (DynamicDialog[] messages)
	{
		string [] updatedMessages = BranchDialog(messages);
		if (donePrinting && currentText == "")
		{
			SetMessages(updatedMessages);
		}
		else if (donePrinting)
		{
			currentText = "";
			SetMessages(updatedMessages);
		}
		else return;
	}