public SolveAddView() { InitializeComponent(); SolveTextBox = this.FindControl <TextBox>("SolveTextBox"); SolveTextBox.Text = "00:00:00.00"; SolveTextBox.CaretIndex = 6; SolveTextBox.CaretBrush = Avalonia.Media.Brushes.Yellow; SolveTextBox.AddHandler(TextInputEvent, PreviewTextInput, RoutingStrategies.Tunnel); SolveTextBox.AddHandler(KeyDownEvent, PreviewKeyDown, RoutingStrategies.Tunnel); CancelButton = this.Find <Button>("CancelButton"); #if DEBUG this.AttachDevTools(); #endif this.WhenActivated(disposableRegistration => { this.BindCommand( ViewModel, viewModel => viewModel.CancelCommand, view => view.CancelButton) .DisposeWith(disposableRegistration); ViewModel !.CancelCommand.Subscribe(_ => Close()) .DisposeWith(disposableRegistration); }); }
public MainWindowViewModel() { EdgeLocalStateFilePath.SetValidateNotifyError(IsExitisFile); EdgeCookiesFilePath.SetValidateNotifyError(IsExitisFile); ChromeLocalStateFilePath.SetValidateNotifyError(IsExitisFile); ChromeCookiesFilePath.SetValidateNotifyError(IsExitisFile); ObsCookiesFilePath.SetValidateNotifyError(IsExitisFile); EdgeCommand = new[] { EdgeLocalStateFilePath.ObserveHasErrors, EdgeCookiesFilePath.ObserveHasErrors, ObsCookiesFilePath.ObserveHasErrors }.CombineLatestValuesAreAllFalse().ToReactiveCommand <Models.CommandParameter>(); ChromeCommand = new[] { ChromeLocalStateFilePath.ObserveHasErrors, ChromeCookiesFilePath.ObserveHasErrors, ObsCookiesFilePath.ObserveHasErrors }.CombineLatestValuesAreAllFalse().ToReactiveCommand <Models.CommandParameter>(); LocalStateFilePath.SetValidateNotifyError(IsExitisFile); SrcCookieFilePath.SetValidateNotifyError(IsExitisFile); DestCookieFilePath.SetValidateNotifyError(IsExitisFile); HostKey.SetValidateNotifyError(host => { if (String.IsNullOrWhiteSpace(host)) { return("Empty"); } return(null); }); ParamCommand = new[] { LocalStateFilePath.ObserveHasErrors, SrcCookieFilePath.ObserveHasErrors, HostKey.ObserveHasErrors, DestCookieFilePath.ObserveHasErrors }.CombineLatestValuesAreAllFalse().ToReactiveCommand <Models.CommandParameter>(); EdgeCommand.Subscribe(ExecuteCommand.Execute); ChromeCommand.Subscribe(ExecuteCommand.Execute); ParamCommand.Subscribe(ExecuteCommand.Execute); OkCommand.Subscribe(async _ => { Executing.Value = true; try { await System.Threading.Tasks.Task.Run(() => { CookieManager.Converter.Convert(Environment.ExpandEnvironmentVariables(Param.LocalStateFilePath), Environment.ExpandEnvironmentVariables(Param.SrcCookieFilePath), Param.HostKey, Environment.ExpandEnvironmentVariables(Param.DestCookieFilePath)); }); } catch { IsErrorDialogOpen.Value = true; } Executing.Value = false; IsDialogOpen.Value = false; } ); ExecuteCommand.Subscribe(param => { IsDialogOpen.Value = true; Param = param; }); CancelCommand.Subscribe(_ => IsDialogOpen.Value = false); ErrorOkCommand.Subscribe(_ => IsErrorDialogOpen.Value = false); }
public ModalDialogViewModelBase(string title, bool okButton = true, bool cancelButton = true) { OKButtonVisible = okButton; CancelButtonVisible = cancelButton; isVisible = false; this.title = title; CancelCommand = ReactiveCommand.Create(); CancelCommand.Subscribe(_ => { Close(false); }); }
internal IoWindowViewModel(ProcessFilesApp context, Action <IApp> work, Action <IApp, Exception> onFailure) { this.context = context; var isInProgress = this.WhenAnyValue(me => me.TokenSource).Select(source => source != null).ObserveOn(Dispatcher.CurrentDispatcher); isInProgressHelper = this.WhenAnyValue(me => me.TokenSource).Select(source => source != null).ToProperty(this, me => me.IsInProgress, true); OpenFile = new InputFileBrowseViewModel(isInProgress.Select(f => !f)); SaveFile = new OutputFileBrowseViewModel(isInProgress.Select(f => !f), OpenFile); worker.DoWork += (o, e) => { work(this); e.Result = 0; }; worker.RunWorkerCompleted += (o, e) => { if (TokenSource.IsCancellationRequested) { Progress = 0; } else if (e.Error != null) { MessageBox.Show(Owner, e.Error.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); Progress = 0; } else { new ExportCompletedWindow(new ExportCompletedViewModel(Title, SaveFile.File)) { Owner = Owner, WindowStartupLocation = WindowStartupLocation.CenterOwner }.ShowDialog(); } TokenSource = null; if (e.Error != null) { onFailure?.Invoke(this, e.Error); } }; worker.ProgressChanged += (o, e) => Progress = e.ProgressPercentage; StartCommand = ReactiveCommand.Create(this.WhenAnyValue(me => me.OpenFile.File, me => me.SaveFile.File, me => me.TokenSource) .Select(CanStart).ObserveOn(Dispatcher.CurrentDispatcher)); CancelCommand = ReactiveCommand.Create(isInProgress); StartCommand.Subscribe(_ => { TokenSource = new CancellationTokenSource(); worker.RunWorkerAsync(); }); CancelCommand.Subscribe(_ => Cancel()); isInProgress.Where(f => f).Subscribe(source => CancellationToken = TokenSource.Token); this.WhenAnyValue(me => me.Title).Where(title => !string.IsNullOrEmpty(title)).Subscribe(title => Owner.Title = title); }
public ExportDialogViewModel() { OKCommand.Subscribe(async _ => { await RunExport(); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); }) .AddTo(_disposables); CancelCommand.Subscribe(_ => { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); }) .AddTo(_disposables); ReferenceCommand.Subscribe(_ => { ShowOpenFileDialog(); }) .AddTo(_disposables); TextVerifier.Value = new Func <string, bool?>((s) => Directory.Exists(s)); }
public MacroPanelViewModel(IMacroService macro, IMacroPool pool, ICanceler canceler, IWorkSituation work, ISwitchClock clock, ISerialPortService serialPort, ICancellationRequest cancelRequest, IGameCapture gameCapture) { m_macro = macro; m_macroCanceler = canceler; m_macroPool = pool; IsConnected = serialPort.ObserveProperty(p => p.IsOpen).ToReactiveProperty().AddTo(Disposables); IsBusy = work.ObserveProperty(w => w.IsBusy).ToReactiveProperty().AddTo(Disposables); Clock = clock.ToReactivePropertyAsSynchronized(m => m.DateTime).AddTo(Disposables); Clock.Value = DateTime.Now; DrawLotoIdCommand = CreateExecuteMacroCommand <DrawLotoIdMacro>(); GainWattsCommand = CreateExecuteMacroCommand <GainWattsMacro>(); BattleMaxRaidCommand = CreateExecuteMacroCommand <BattleMaxRaidMacro>(); //SeekPokemonCommand = CreateExecuteMacroCommand<SeekPokemonMacro>(); RapidTimeTravelCommand = CreateExecuteMacroCommand <RapidTimeTravelMacro>(); RapidTimeTravelDays = clock.ToReactivePropertyAsSynchronized(m => m.DaysCount).AddTo(Disposables); RapidTimeTravelDays.Value = 0; ThreeDaysTravelCommand = CreateExecuteMacroCommand <ThreeDaysTravelMacro>(); CanGoNextThreeDays = (m_macroPool.Get <ThreeDaysTravelMacro>() as ThreeDaysTravelMacro).ObserveProperty(m => m.CanGoNext).ToReactiveProperty().AddTo(Disposables); ThreeDaysTravelNextCommand = CanGoNextThreeDays.ToReactiveCommand().AddTo(Disposables); ThreeDaysTravelNextCommand.Subscribe(() => { using (var wait = new EventWaitHandle(false, EventResetMode.ManualReset, "WAIT_NEXT_3_DAYS")) { wait.Set(); } }); MashAButtonCommand = CreateExecuteMacroCommand <MashAButtonMacro>(); IsCanceling = cancelRequest.ObserveProperty(c => c.IsCancellationRequested).ToReactiveProperty().AddTo(Disposables); CancelCommand = new[] { IsBusy, IsCanceling }.CombineLatest(x => x[0] && !x[1]).ToReactiveCommand().AddTo(Disposables); CancelCommand.Subscribe(m_macroCanceler.Cancel); SaveImageCommand = new ReactiveCommand().AddTo(Disposables); SaveImageCommand.Subscribe(() => gameCapture.SaveFrame(null)); }
public RoomCreationView() { InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif CreateRoomButton = this.Find <Button>("CreateRoomButton"); JoinRoomButton = this.Find <Button>("JoinRoomButton"); CancelButton = this.Find <Button>("CancelButton"); EventsListBox = this.Find <ListBox>("EventsListBox"); AccessCodeTextBox = this.Find <TextBox>("AccessCodeTextBox"); ScramblesAmountTextBox = this.Find <TextBox>("ScramblesAmountTextBox"); SnackBarContentControl = this.Find <ContentControl>("SnackBarContentControl"); this.WhenActivated(disposableRegistration => { this.Bind( ViewModel, viewModel => viewModel.SelectedEvent, view => view.EventsListBox.SelectedItem) .DisposeWith(disposableRegistration); this.Bind( ViewModel, viewModel => viewModel.AccessCode, view => view.AccessCodeTextBox.Text) .DisposeWith(disposableRegistration); this.Bind( ViewModel, viewModel => viewModel.ScramblesAmount, view => view.ScramblesAmountTextBox.Text) .DisposeWith(disposableRegistration); this.Bind( ViewModel, viewModel => viewModel.SnackbarViewModel, view => view.SnackBarContentControl.Content) .DisposeWith(disposableRegistration); this.BindCommand( ViewModel, viewModel => viewModel.CreateRoomCommand, view => view.CreateRoomButton) .DisposeWith(disposableRegistration); this.BindCommand( ViewModel, viewModel => viewModel.JoinRoomCommand, view => view.JoinRoomButton) .DisposeWith(disposableRegistration); this.BindCommand( ViewModel, viewModel => viewModel.CancelCommand, view => view.CancelButton) .DisposeWith(disposableRegistration); ViewModel !.CreateRoomCommand.Subscribe(x => { if (x is null) { return; } Close(x); }) .DisposeWith(disposableRegistration); ViewModel !.JoinRoomCommand.Subscribe(x => { if (x is null) { return; } Close(x); }) .DisposeWith(disposableRegistration); ViewModel !.CancelCommand.Subscribe(_ => Close()) .DisposeWith(disposableRegistration); }); }
protected FlyoutBaseVm() { CancelCommand = ReactiveCommand.Create(Observable.Return(true)); CancelCommand.Subscribe(_ => IsOpen = false); }
private void HandleActivation(CompositeDisposable d) { // Create command. StartCommand = ReactiveCommand .CreateFromObservable(() => { Logs.Clear(); return(Locator.Current.GetService <OneOfRequirement>() .TimeConsumingTask(new OneOfRequest()) .TakeUntil(CancelCommand) .SubscribeOn(ThreadPoolScheduler.Instance)); }); // Create cancellation command. CancelCommand = ReactiveCommand .Create(() => { }, StartCommand.IsExecuting) .DisposeWith(d); // Register the process that when the command progress received. StartCommand .SubscribeProgress(progress => { ProgressPercentage = progress.Percentage; Logs.Add(new LogItem() { Time = DateTime.Now, Message = progress.Notification }); if (progress.IsCompleted) { Logs.Add(new LogItem() { Time = DateTime.Now, Message = "Task completed." }); } }); // Register the process that when the command error received. StartCommand .ThrownExceptions .Subscribe(error => { ProgressPercentage = 0; Logs.Add(new LogItem() { Time = DateTime.Now, Message = error.Message }); }); // Register the process that when the command was cancelled. CancelCommand .Subscribe(_ => { ProgressPercentage = 0; Logs.Add(new LogItem() { Time = DateTime.Now, Message = "Your pizza was cancelled." }); }) .DisposeWith(d); }
private void RegisterCommands() { OkCommand .Subscribe(dialog => { CheckUpdate(Config.WorkingDirectory, InitialConfig.WorkingDirectory); CheckUpdate(Config.ConnectionString, InitialConfig.ConnectionString); CheckUpdate(Config.LockFileInImporting, InitialConfig.LockFileInImporting); CheckUpdate(Config.BookListViewItemAuthorHeight, InitialConfig.BookListViewItemAuthorHeight); CheckUpdate(Config.BookListViewItemImageHeight, InitialConfig.BookListViewItemImageHeight); CheckUpdate(Config.BookListViewItemTitleHeight, InitialConfig.BookListViewItemTitleHeight); CheckUpdate(Config.BookListViewItemWidth, InitialConfig.BookListViewItemWidth); CheckUpdate(Config.BookListViewItemMarginLeft, InitialConfig.BookListViewItemMarginLeft); CheckUpdate(Config.BookListViewItemMarginTop, InitialConfig.BookListViewItemMarginTop); CheckUpdate(Config.BookListViewItemMarginRight, InitialConfig.BookListViewItemMarginRight); CheckUpdate(Config.BookListViewItemMarginBottom, InitialConfig.BookListViewItemMarginBottom); CheckUpdate(Config.ContentListViewItemImageHeight, InitialConfig.ContentListViewItemImageHeight); CheckUpdate(Config.ContentListViewItemTitleHeight, InitialConfig.ContentListViewItemTitleHeight); CheckUpdate(Config.ContentListViewItemWidth, InitialConfig.ContentListViewItemWidth); CheckUpdate(Config.ContentListViewItemMarginLeft, InitialConfig.ContentListViewItemMarginLeft); CheckUpdate(Config.ContentListViewItemMarginTop, InitialConfig.ContentListViewItemMarginTop); CheckUpdate(Config.ContentListViewItemMarginRight, InitialConfig.ContentListViewItemMarginRight); CheckUpdate(Config.ContentListViewItemMarginBottom, InitialConfig.ContentListViewItemMarginBottom); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); bool willRestart = false; if (RestartRequired) { willRestart = MessageBox.Show("変更を反映するには再起動が必要です.\n今すぐ再起動しますか?", Process.GetCurrentProcess().MainWindowTitle, MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK; } if (!RestartRequired || willRestart) { Configuration.ApplicationConfiguration = Config; Configuration.Save(Configuration.ApplicationConfiguration); } if (willRestart) { MainWindowViewModel.Close(); Process.Start(Process.GetCurrentProcess().MainModule.FileName); } }); CancelCommand .Subscribe(dialog => { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); }); PathReferenceCommand .Subscribe(textbox => { var dialog = new FolderSelectDialog(); dialog.InitialDirectory = textbox.Text; if (dialog.ShowDialog() == true) { textbox.Text = dialog.FileName; } }); }
private void RegisterCommands() { OkCommand .Subscribe(dialog => { UpdateBook(); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); }) .AddTo(disposables); CancelCommand .Subscribe(dialog => { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); }) .AddTo(disposables); SelectNextBookCommand .Subscribe(() => SelectNextBook()) .AddTo(disposables); SelectPreviousBookCommand .Subscribe(() => SelectPreviousBook()) .AddTo(disposables); OpenSaveDirCommand .Subscribe(() => OpenDir()) .AddTo(disposables); OpenAuthorManagementDialogCommand .Subscribe(() => { var dialog = new EntityManagementDialog <AuthorViewModel>(); var dialogViewModel = new EntityManagementDialogViewModel <AuthorViewModel>(dialog, LibraryManager, "Authorの管理", new Func <string, AuthorViewModel>((name) => { var author = new AuthorViewModel(); author.ID = Guid.NewGuid(); author.UnescapedName = name; AuthorFacade.Create(author); return(author); }), new Func <IEnumerable <AuthorViewModel> >(() => { return(AuthorFacade.OrderByNaturalString()); }), new Func <Guid, AuthorViewModel>((id) => { return(AuthorFacade.FindBy(id)); }), new Action <AuthorViewModel>((target) => { AuthorFacade.Update(target); var willUpdate = LibraryManager.BookSource.Where(b => b.AuthorID == target.ID); foreach (var x in willUpdate) { x.Author = target.Clone() as AuthorViewModel; } }), new Action <Guid>((id) => { AuthorFacade.Delete(id); var willUpdate = LibraryManager.BookSource.Where(b => b.AuthorID == id); foreach (var x in willUpdate) { x.Author = null; } }), new Action <AuthorViewModel, AuthorViewModel>((willDiscard, into) => { AuthorFacade.Delete(willDiscard.ID); var willUpdate = LibraryManager.BookSource.Where(b => b.AuthorID == willDiscard.ID); foreach (var x in willUpdate) { x.Author = into.Clone() as AuthorViewModel; BookFacade.Update(x); } })); dialog.EntityMngVM = dialogViewModel; dialogViewModel.Initialize(); dialog.Show(); }) .AddTo(disposables); TitleTextBoxKeyDownCommand = new ReactiveCommand <KeyEventArgs>(); TitleTextBoxKeyDownCommand.Subscribe(e => { switch (e.Key) { case Key.Enter: UpdateBook(); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); break; case Key.Escape: RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); break; default: break; } }) .AddTo(disposables); }