private void NewResourceDictionaryButton_Click(object sender, RoutedEventArgs e) { IProjectItem newResourceItem = (IProjectItem)null; EventHandler <ProjectItemEventArgs> eventHandler = (EventHandler <ProjectItemEventArgs>)((o, args) => newResourceItem = args.ProjectItem); IProject activeProject = this.designerContext.ActiveProject; if (activeProject != null) { AddNewItemCommand addNewItemCommand = new AddNewItemCommand(this.designerContext, 0 != 0, new string[1] { "ResourceDictionary.xaml" }); addNewItemCommand.SetProperty("TemporarilyStopProjectPaneActivation", (object)true); activeProject.ItemAdded += eventHandler; activeProject.ItemChanged += eventHandler; addNewItemCommand.ExecuteWithProject(activeProject); activeProject.ItemAdded -= eventHandler; activeProject.ItemChanged -= eventHandler; } if (newResourceItem == null || this.designerContext.ResourceManager.TopLevelResourceContainer == null) { return; } this.model.SelectedLocation = (object)this.model.OtherDocuments; this.otherDocumentRadioButton.IsChecked = new bool?(true); UIThreadDispatcher.Instance.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() => { this.model.UpdateResourceList(this.designerContext.ResourceManager); this.model.SelectedExternalResourceDictionaryFile = this.designerContext.ResourceManager.FindResourceContainer(newResourceItem.DocumentReference.Path); })); }
public UserMaintenanceViewModel(IUserManager userManager, IGroupManager groupManager, IEventAggregator eventAggregator) { if (userManager == null) { throw new ArgumentNullException("userManager"); } if (groupManager == null) { throw new ArgumentNullException("groupManager"); } if (eventAggregator == null) { throw new ArgumentNullException("eventAggregator"); } this.userManager = userManager; this.groupManager = groupManager; this.eventAggregator = eventAggregator; AddNewItemCommand = new AddNewItemCommand(this); ClearInputCommand = new ClearInputCommand(this); UpdateValidityCommand = new UpdateValidityCommand(this); InitializeCollections(); InitializeEventSubscriptions(); }
private bool CanAddNewItem(object parameter) { if (AddNewItemCommand != null) { return(AddNewItemCommand.CanExecute(parameter)); } return(IsCollection(ItemsSource)); }
public ClientMaintenanceViewModel() { AddNewItemCommand = new AddNewItemCommand(this); ClearInputCommand = new ClearInputCommand(this); UpdateValidityCommand = new UpdateValidityCommand(this); InitializeCollections(); InitializeEventSubscriptions(); }
public BankHolidayMaintenanceViewModel() { AddNewItemCommand = new AddNewItemCommand(this); ClearInputCommand = new ClearInputCommand(this); InitializeCollections(); eventAggregator.GetEvent <NewBankHolidayEvent>().Subscribe(HandleNewBankHolidayEvent, ThreadOption.UIThread, RequestForQuoteConstants.MAINTAIN_STRONG_REFERENCE); }
private void AddNewItem(object parameter) { if (AddNewItemCommand != null) { AddNewItemCommand.Execute(parameter); } else { var list = ItemsSource as IList; var newItem = Activator.CreateInstance(GetEnumerableGenericArgument(ItemsSource.GetType())); list.Add(newItem); } UpdateItemsCount(); GoToLastItem(null); }
/// <summary> /// Called when [new context report]. /// </summary> /// <param name="reportView">The report view.</param> private async void OnNewContextReport(Report reportView) { var errorOccurred = false; var progressService = new ProgressService(); progressService.SetProgress("Creating report", 0, false, true); //await Task.Delay(500); var report = new Report(reportView.SourceTemplate); report.Name = "New report based on " + report.Name; report.IsDefaultReport = false; var operationComplete = await progressService.Execute(() => { AddNewItemCommand.Execute(report); }, opResult => { progressService.SetProgress("Completed", 100, true, false); if (opResult.Status && opResult.Exception != null) { errorOccurred = true; LogEntityError(opResult.Exception.GetBaseException(), typeof(Report), Title); } else { errorOccurred = false; } }, new CancellationToken()); if (operationComplete && !errorOccurred) { OnLoad(); OnNavigateToDetails(report); } }
public ConnectionInfoManagementViewModel() { AddNewItemCommand = IsItemEditing.Inverse().ToReactiveCommand(); AddNewItemCommand.Subscribe(() => { SelectedItem.Value = null; EditingItem.Value = new T(); if (IsGroupSelected?.Value == true) { EditingItem.Value.GroupName = SelectedGroup.Value?.Name; } IsItemEditing.Value = true; }).AddTo(Disposable); ConnectCommand.Subscribe(async item => await ConfirmConnect(item)).AddTo(Disposable); IsItemSelected = SelectedItem.Select(x => x != null).ToReadOnlyReactiveProperty(); IsNotItemEditing = IsItemEditing.Inverse().ToReadOnlyReactiveProperty(); SelectedItem.Subscribe(x => { EditingItem.Value = SelectedItem.Value; IsItemEditing.Value = false; }).AddTo(Disposable); StartEditCommand = IsItemSelected .CombineLatest(IsItemEditing.Inverse(), (a, b) => a && b) .ToReactiveCommand(); StartEditCommand.Subscribe(() => { EditingItem.Value = SelectedItem.Value.CloneDeep(); IsItemEditing.Value = true; }).AddTo(Disposable); ReplicateCommand = IsItemSelected .CombineLatest(IsItemEditing.Inverse(), (a, b) => a && b) .ToReactiveCommand(); ReplicateCommand.Subscribe(() => { var replicated = SelectedItem.Value.CloneDeep(); replicated.Id = -1; SelectedItem.Value = null; EditingItem.Value = replicated; IsItemEditing.Value = true; }).AddTo(Disposable); RemoveCommand = IsItemSelected .CombineLatest(IsItemEditing.Inverse(), (a, b) => a && b) .ToAsyncReactiveCommand(); RemoveCommand.Subscribe(async() => { if (await Remove(SelectedItem.Value)) { Items.Remove(SelectedItem.Value); // Renew Windows JumpList JumpListHelper.RenewJumpList(await MainWindow.DbContext.EnumerateAllConnectionInfos()); } }).AddTo(Disposable); DiscardChangesCommand = IsItemEditing.ToReactiveCommand(); DiscardChangesCommand.Subscribe(() => { EditingItem.Value = SelectedItem.Value ?? new T(); IsItemEditing.Value = false; }).AddTo(Disposable); SaveChangesCommand = IsItemEditing.ToReactiveCommand(); SaveChangesCommand.Subscribe(async() => { var selectedItem = SelectedItem.Value; var item = EditingItem.Value; try { var(result, resultItem) = await Save(item); if (resultItem == null) { return; // FAILED } item = resultItem; // Replace with the saved item if (result) // ADDED { Items.Add(item); } else // UPDATED { var oldItem = Items.FirstOrDefault(x => x.Id == item.Id); if (oldItem != null) { var index = Items.IndexOf(oldItem); if (index >= 0) { Items.RemoveAt(index); Items.Insert(index, item); } } } // Renew Windows JumpList JumpListHelper.RenewJumpList(await MainWindow.DbContext.EnumerateAllConnectionInfos()); } catch (OperationCanceledException) // User manually canceled { return; } SelectedItem.Value = item; IsItemEditing.Value = false; }).AddTo(Disposable); // Connection info filterings FilterText .Throttle(TimeSpan.FromMilliseconds(500)) .ObserveOnDispatcher() .Subscribe(_ => RefreshCollectionView()) .AddTo(Disposable); SelectedGroup .ObserveOnDispatcher() .Subscribe(_ => RefreshCollectionView()) .AddTo(Disposable); // If any group is selected or not (except for "All") IsGroupSelected = SelectedGroup .Select(x => x?.Name != AllGroupName) .ToReadOnlyReactivePropertySlim() .AddTo(Disposable); // Group list extraction on connection info events Observable.CombineLatest( // When Add, Remove or Update Items.CollectionChangedAsObservable() .Select(_ => Unit.Default) .StartWith(Unit.Default), // When GroupName property in each element changed Items.ObserveElementPropertyChanged() .Where(x => x.EventArgs.PropertyName == nameof(ConnectionInfoBase.GroupName)) .Select(_ => Unit.Default) .StartWith(Unit.Default) ) .Throttle(TimeSpan.FromMilliseconds(500)) // Once 500 ms .ObserveOnDispatcher() .Subscribe(_ => { var selectedGroup = SelectedGroup.Value; // Reload group list Groups.Clear(); EnumerateGroups().ToList().ForEach(Groups.Add); // Reset selected group SelectedGroup.Value = (selectedGroup is null) ? Groups.FirstOrDefault() : selectedGroup; }) .AddTo(Disposable); }
/// <summary> /// Called when save is clicked to save the report changes. /// </summary> protected override async void OnSave() { base.OnSave(); if (HasErrors) { return; } if (!(Audiences[1].IsSelected || Audiences[2].IsSelected)) { MessageBox.Show( "Please enter a report type, report name, and recommended audience(s) to add a new report."); return; } try { var errorOccurred = false; var progressService = new ProgressService(); progressService.SetProgress("Creating report", 0, false, true); //await Task.Delay(500); var operationComplete = await progressService.Execute(() => { //Get all selected enum values but the default/non-selected value of zero "0" var selectedAudiences = Audiences.Where(a => a.IsSelected && a.Value != 0).Select(a => a.Enum).ToList(); //.Aggregate<AudienceModel, uint>(0, (current, a) => current + (uint)a.Value); var factory = new ReportManifestFactory(); var manifest = factory.InstalledManifests.FirstOrDefault(x => x.Name == ReportType); var report = new Report(manifest) { Name = Title }; //, Audiences = selectedAudiences.ToList() AddNewItemCommand.Execute(report); }, opResult => { progressService.SetProgress("Completed", 100, true, false); if (opResult.Status && opResult.Exception != null) { errorOccurred = true; LogEntityError(opResult.Exception.GetBaseException(), typeof(Report), Title); } else { errorOccurred = false; } }, new CancellationToken()); if (operationComplete && !errorOccurred) { OnLoad(); Notify(String.Format("New report {0} has been added", Title)); } } catch (Exception exc) { LogEntityError(exc, typeof(Report), Title); } finally { Reset(); } }