Пример #1
0
        private async void RenameCollection(RecentCollectionViewModel recent_collection)
        {
            logger.Trace($"Renaming collection [{recent_collection.Name} - {recent_collection.Filename}]");

            if (recent_collection.Invalid)
            {
                logger.Trace("Collection is invalid, so cannot rename it");
                return;
            }

            var vm = new InputDialogViewModel
            {
                Title   = "Renaming Collection",
                Message = "Enter new name for collection",
                Hint    = recent_collection.Name
            };
            var result = (bool)await DialogManager.ShowInputDialogAsync(vm);

            if (result)
            {
                var collection = repository.LoadCollection(recent_collection.Filename);
                if (collection != null)
                {
                    recent_collection.Name = vm.Input;
                    collection.Name        = vm.Input;

                    repository.SaveCollection(collection);
                }
            }
        }
Пример #2
0
        public string ShowTextInputDialog(string title, string message, string defaultValue, IList<InputDialogOptionViewModel> options)
        {
            var viewModel = new InputDialogViewModel
            {
                Title = title,
                Message = message,
                DefaultValue = defaultValue,
                Options = options,
                Mode = options != null ? InputDialogMode.ComboBox : InputDialogMode.Text
            };
            var dialog = new InputDialog(viewModel);

            if (dialog.ShowDialog() == true)
            {
                switch (viewModel.Mode)
                {
                    case InputDialogMode.Text:
                        return dialog.TextBox.Text;
                    case InputDialogMode.ComboBox:
                        var selectedItem = dialog.ComboBox.SelectedItem;
                        if (selectedItem != null)
                        {
                            var selectedValue = ((InputDialogOptionViewModel)dialog.ComboBox.SelectedItem);
                            if (selectedValue.DisplayName == dialog.ComboBox.Text) return (string)selectedValue.Value;
                        }
                        return dialog.ComboBox.Text;
                    default:
                        throw new NotSupportedException("Invalid dialog mode: " + viewModel.Mode);
                }
            }
            return null;
        }
Пример #3
0
 public InputDialog(InputDialogViewModel viewModel)
 {
     Owner = Application.Current.MainWindow;
     InitializeComponent();
     DataContext = viewModel;
     Loaded     += OnLoaded;
 }
Пример #4
0
        private async Task <T> Show <T>(string message, string watermark, T defaultValue, bool acceptsTab, bool acceptsReturn)
        {
            var vm = new InputDialogViewModel <T>
            {
                Message       = message,
                Watermark     = watermark,
                Text          = defaultValue?.ToString(),
                AcceptsTab    = acceptsTab,
                AcceptsReturn = acceptsReturn
            };

            if (vm.Text == null && typeof(T) == typeof(string))
            {
                // this is to distinguish between clicking 'cancel' and clicking 'ok' with an empty input
                vm.Text = "";
            }
            ViewModel = vm;

            bool wasCancelled = await WaitDialog();

            Close();

            if (wasCancelled)
            {
                return(default);
Пример #5
0
        public void OpenInputDialog(string Title, string Message, Window Owner, Action <string> CallBack)
        {
            InputDialogViewModel vm = new InputDialogViewModel(Title, Message);
            var ret = ShowDialog(vm, Owner);

            if (ret.HasValue && ret == true)
            {
                CallBack(vm.InputText);
            }
        }
Пример #6
0
        public LulDialogResult Show(string title, string message, DialogButtons dialogButtons)
        {
            DataContext = new InputDialogViewModel(title, message, dialogButtons);

            ShowDialog();

            return(new InputDialogResult
            {
                DialogResult = DialogResult,
                Input = (DialogResult == DialogResults.Ok) ? ((InputDialogViewModel)DataContext).Input : null
            });
        }
Пример #7
0
        public InputDialog(string question, string mode)
        {
            InitializeComponent();

            if (idvm == null)
            {
                idvm = new InputDialogViewModel(mode)
                {
                    Answer = txtAnswer.Text, IsValid = false
                };
            }

            DataContext = idvm;

            Question.Content = question;
        }
Пример #8
0
        private async void RenameShelf(ShelfViewModel vm)
        {
            logger.Trace($"Renaming shelf [{vm.Name}]");

            var dialog = new InputDialogViewModel
            {
                Title   = "Renaming Shelf",
                Message = "Enter new name for shelf",
                Hint    = vm.Name
            };
            var result = (bool)await DialogManager.ShowInputDialogAsync(dialog);

            if (true)
            {
                vm.Obj.Name = dialog.Input;
            }
        }
Пример #9
0
        private async void AddShelf()
        {
            var dialog = new InputDialogViewModel
            {
                Title   = "Adding Shelf",
                Message = "Enter name",
                Hint    = "Shelf Name"
            };
            var result = (bool)await DialogManager.ShowInputDialogAsync(dialog);

            if (result)
            {
                var shelf = state_manager.CurrentCollection.AddShelf(dialog.Input);
                var vm    = new ShelfViewModel(shelf);
                Shelves.Add(vm);
            }
        }
Пример #10
0
        private void GameExit(object sender, EventArgs e)
        {
            this._currentGame.GameExit -= GameExit;

            InputDialog          dia   = new InputDialog();
            InputDialogViewModel diavm = new InputDialogViewModel(dia);

            dia.DataContext    = diavm;
            diavm.CloseDialog += CloseDialog;

            dia.ShowDialog();

            if (diavm.result == true)
            {
                String name = dia.Input.Text;
                if ((int)this._currentGame.P1.Score > (int)this._currentGame.P2.Score)
                {
                    LeaderboardEntry board = new LeaderboardEntry();
                    board.UserName      = name;
                    board.GameType      = GameTypes.TicTacToe;
                    board.Date          = DateTime.Now;
                    board.GameSessionId = "session1";
                    board.Score         = (int)this._currentGame.P1.Score;

                    _store.AddLeaderboardEntryAsync(board);
                }
                else
                {
                    LeaderboardEntry board = new LeaderboardEntry();
                    board.UserName      = name;
                    board.GameType      = GameTypes.TicTacToe;
                    board.Date          = DateTime.Now;
                    board.GameSessionId = "session1";
                    board.Score         = (int)this._currentGame.P2.Score;

                    _store.AddLeaderboardEntryAsync(board);
                }
            }

            this._currentGame.CloseWindow();

            this._currentGame = null;

            _window.Show();
        }
Пример #11
0
        public object ShowListInputDialog(string title, string message, object defaultValue, IList<InputDialogOptionViewModel> options)
        {
            if (options == null) throw new ArgumentException();

            var viewModel = new InputDialogViewModel
            {
                Title = title,
                Message = message,
                DefaultValue = defaultValue,
                Options = options,
                Mode = InputDialogMode.RadioGroup
            };

            var dialog = new InputDialog(viewModel);

            dialog.ShowDialog();
            return options.First(o => o.IsSelected).Value;
        }
Пример #12
0
        private async void AddNote()
        {
            var dialog = new InputDialogViewModel
            {
                Title   = "Adding Note",
                Message = "Enter name",
                Hint    = "Note Name"
            };
            var result = (bool)await DialogManager.ShowInputDialogAsync(dialog);

            if (result)
            {
                var note = state_manager.CurrentCollection.AddNote(dialog.Input);
                var vm   = new NoteViewModel(note);
                Notes.Add(vm);
                SelectedNote = vm;
            }
        }
Пример #13
0
        public async Task <string> GetValue(string text, WindowType hostIdentifier = WindowType.Root,
                                            string value = null)
        {
            var viewModel = new InputDialogViewModel(text);

            if (value != null)
            {
                viewModel.Value = value;
            }

            var view = new InputDialog {
                ViewModel = viewModel
            };

            object ret = null;
            await DialogHost.Show(view, Common.GetEnumDescription(hostIdentifier), (o, args) =>
            {
                ret = args.Parameter;
            });

            return(ret == null ? null : viewModel.Value);
        }
 private static InputDialogViewModel <InputDialogDisplayViewModel> InputGetsNotAccepted(InputDialogViewModel <InputDialogDisplayViewModel> dialog)
 {
     ((DialogCancelButtonViewModel)dialog.ButtonViewModel).CancelCommand.Execute(null);
     return(dialog);
 }
 private static InputDialogViewModel <InputDialogDisplayViewModel> InputGetsAccepted(InputDialogViewModel <InputDialogDisplayViewModel> dialog)
 {
     dialog.ButtonViewModel.OkCommand.Execute(null);
     return(dialog);
 }
 private void Initialize()
 {
     if (this.ViewModel == null)
     {
         // this would normally happen in xaml by setting DataContext
         this.ViewModel = ServiceLocator.Current.GetInstance<InputDialogViewModel>();
         this.NavigationService = ServiceLocator.Current.GetInstance<INavigationService>();
     }
 }