Пример #1
0
        public PatcherVm(
            ILifetimeScope scope,
            IPatcherNameVm nameVm,
            IProfileDisplayControllerVm selPatcher,
            IConfirmationPanelControllerVm confirmation,
            IPatcherIdProvider idProvider,
            PatcherRenameActionVm.Factory renameFactory,
            PatcherSettings?settings)
        {
            Scope = scope;
            Scope.DisposeWith(this);
            NameVm     = nameVm;
            InternalID = idProvider.InternalId;

            _isSelected = selPatcher.WhenAnyValue(x => x.SelectedObject)
                          .Select(x => x == this)
                          // Not GuiProperty, as it interacts with drag/drop oddly
                          .ToProperty(this, nameof(IsSelected));

            if (settings != null)
            {
                CopyInSettings(settings);
            }

            DeleteCommand = ReactiveCommand.Create(() =>
            {
                confirmation.TargetConfirmation = new ConfirmationActionVm(
                    "Confirm",
                    $"Are you sure you want to delete {NameVm.Name}?",
                    Delete);
            });

            RenameCommand = ReactiveCommand.Create(() =>
            {
                confirmation.TargetConfirmation = renameFactory();
            });

            ErrorDisplayVm = new ErrorDisplayVm(this, this.WhenAnyValue(x => x.State));
        }
Пример #2
0
 public SelectedGroupControllerVm(
     IProfileGroupsList groupsList,
     IProfileDisplayControllerVm selected)
 {
     _selectedGroup = Observable.CombineLatest(
         selected.WhenAnyValue(x => x.SelectedObject),
         groupsList.Groups.Connect()
         .ObserveOnGui()
         .QueryWhenChanged(q => q),
         (selected, groups) => selected ?? groups.FirstOrDefault())
                      .Select(x =>
     {
         if (x is GroupVm group)
         {
             return(group);
         }
         if (x is PatcherVm patcher)
         {
             return(patcher.Group);
         }
         return(default(GroupVm?));
     })
                      .ToGuiProperty(this, nameof(SelectedGroup), default(GroupVm?), deferSubscription: true);
 }