Ejemplo n.º 1
0
        private static async Task <string[]> ShowAsync(this FileDialog me, Window parent, bool fallBack)
        {
            if (fallBack)
            {
                try
                {
                    return(await ShowOpenSaveFileDialogAsync(me, parent));
                }
                catch (Exception ex)
                {
                    WalletWasabi.Logging.Logger.LogWarning(ex, me.GetType().Name);

                    string title = !string.IsNullOrWhiteSpace(me.Title)
                                                ? me.Title
                                                : me is OpenFileDialog
                                                        ? "Open File"
                                                        : me is SaveFileDialog
                                                                ? "Save File"
                                                                : throw new NotImplementedException();

                    string instructions = me is OpenFileDialog
                                                ? $"Failed to use your operating system's {nameof(OpenFileDialog)}. Please provide the path of the file you want to open manually:"
                                                : me is SaveFileDialog
                                                        ? $"Failed to use your operating system's {nameof(SaveFileDialog)}. Please provide the path where you want your file to be saved to:"
                                                        : throw new NotImplementedException();

                    string exampleFilePath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                                                ? @"C:\path\to\the\file.ext"
                                                : @"/path/to/the/file";

                    string defaultTextInput = me is OpenFileDialog
                                                ? Path.Combine(me.InitialDirectory ?? "", me.InitialFileName ?? "")
                                                : me is SaveFileDialog sfd
                                                        ? Path.ChangeExtension(
                        Path.Combine(
                            string.IsNullOrEmpty(me.InitialDirectory) ? Path.GetDirectoryName(exampleFilePath) : me.InitialDirectory,
                            string.IsNullOrEmpty(me.InitialFileName) ? Path.GetFileName(exampleFilePath) : me.InitialFileName),
                        string.IsNullOrEmpty(sfd.DefaultExtension)? "ext" : sfd.DefaultExtension)
                                                        : throw new NotImplementedException();

                    var dialog  = new TextInputDialogViewModel(title, instructions, exampleFilePath, defaultTextInput);
                    var success = await MainWindowViewModel.Instance.ShowDialogAsync(dialog);

                    if (success)
                    {
                        var path = dialog.TextInput.Trim();
                        return(new string[] { path });
                    }
                    else
                    {
                        return(new string[0]);
                    }
                }
            }
            else
            {
                return(await ShowOpenSaveFileDialogAsync(me, parent));
            }
        }
Ejemplo n.º 2
0
        public void NotifyPropertyChangedIsImplementedCorrectly()
        {
            // Arrange
            var vm     = new TextInputDialogViewModel();
            var tester = new PropertyChangedTester(vm);

            // Act
            tester.Test();

            // Assert
            tester.Verify();
        }
Ejemplo n.º 3
0
        private async void GroupCButtonClick(object sender, RoutedEventArgs e)
        {
            var viewModel = new TextInputDialogViewModel
            {
                AffirmativeButtonText = "TRY NOW",
                NegativeButtonText    = "NEVERMIND",
                Message = "Type 'cool' into the box"
            };

            var dialog = new TextInputDialog(viewModel);
            await MaterialDesignThemes.Wpf.DialogHost.Show(dialog, "MainDialogHost", DialogClosing);

            Snackbar.MessageQueue.Enqueue($"We did it!");
        }
Ejemplo n.º 4
0
        private async void GroupBButtonClick(object sender, RoutedEventArgs e)
        {
            var viewModel = new TextInputDialogViewModel
            {
                Message = "Enter some text"
            };

            var dialog = new TextInputDialog(viewModel);
            var result = (bool)await MaterialDesignThemes.Wpf.DialogHost.Show(dialog, "MainDialogHost");

            if (result)
            {
                Snackbar.MessageQueue.Enqueue($"Received text: {viewModel.Text}");
            }
        }
Ejemplo n.º 5
0
        protected virtual void OnAddAttribute(object parameter)
        {
            var textInputData = new TextInputDialogViewModel
            {
                Title = "Property Name"
            };
            bool?success = dialogService.ShowCustomDialog <TextInputDialog>(ownerViewModel, textInputData);

            if (success == true)
            {
                Properties.Add(new TreeViewNodeProperty(this.node, textInputData.Text, string.Empty));
                // #todo: why do we need this??
                //mediator.NotifyAttributeAdded(this);
            }
        }
Ejemplo n.º 6
0
        public void InputMustNotBeEmpty()
        {
            // Arrange
            var vm = new TextInputDialogViewModel
            {
                Input = "test"
            };

            vm.Input = null;

            // Act
            bool nul = vm.OkCommand.CanExecute(null);

            vm.Input = string.Empty;
            bool empty = vm.OkCommand.CanExecute(null);

            vm.Input = "test";
            bool text = vm.OkCommand.CanExecute(null);

            // Assert
            Assert.IsFalse(nul);
            Assert.IsFalse(empty);
            Assert.IsTrue(text);
        }
Ejemplo n.º 7
0
 public TextInputDialog(TextInputDialogViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
 }