public RepositoriesViewModel() { Repositories = new CollectionViewSource { Source = ApplicationSettings.Instance.Repositories }; Repositories.View.CurrentChanged += (s, e) => Mediator.NotifyColleaguesAsync <RepositorySelectedEvent>(Repositories.View.CurrentItem as Repository); if (ApplicationSettings.Instance.Repositories.Count > 0) { Repositories.View.MoveCurrentToFirst(); Mediator.NotifyColleaguesAsync <RepositorySelectedEvent>(Repositories.View.CurrentItem as Repository); } Mediator.Subscribe <DeleteRepositoryEvent>(r => { var repo = r as Repository; if (repo != null && ApplicationSettings.Instance.Repositories.Contains(repo)) { UiDispatcherService.InvokeAsync(() => { ApplicationSettings.Instance.Repositories.Remove(repo); ApplicationSettings.Save(); }); } }); }
protected void NotifyPropertyChanged(string propertyName) { if (UiDispatcherService != null && PropertyChanged != null) { UiDispatcherService.InvokeAsync(() => PropertyChanged(this, new PropertyChangedEventArgs(propertyName))); } }
public void RefreshCommitHistory() { if (BlockUpdates) { return; } Debug.WriteLine("Refreshing commit history for {0}", this.Name); var startRevision = this._items.OrderByDescending(item => item.Revision).Select(item => item.Revision).FirstOrDefault(); if (!_alreadyUpdating && _dataService != null) { lock (_locker) { _alreadyUpdating = true; Status = "Updating..."; } _dataService.GetLogAsync(this, items => { if (items != null) { UiDispatcherService.InvokeAsync(() => { var added = this._items.MergeAdd(items, (item, collection) => collection.FirstOrDefault(c => c.Revision == item.Revision), (itemOld, itemNew) => { itemOld.Revision = itemNew.Revision; itemOld.Author = itemNew.Author; itemOld.Date = itemNew.Date; itemOld.HasLocalEditsOnAnyFile = itemNew.HasLocalEditsOnAnyFile; itemOld.LogMessage = itemOld.LogMessage; itemOld.ItemChanges = itemNew.ItemChanges; }); var list = new List <ICommitItem>(); if (added != null) { list.AddRange(added); } Mediator.NotifyColleaguesAsync <CommitsPublishedEvent>(list); }); } lock (_locker) { _alreadyUpdating = false; Status = string.Format("Last Update: {0}", DateTime.Now.ToShortTimeString()); } }, startRevision: startRevision); } }
private void ReplaceChildren(ObservableCollection <AppViewModel> freshApps) { UiDispatcherService.RunOnUiThread(() => Children.Clear()); foreach (TreeViewItemViewModel avm in freshApps) { UiDispatcherService.RunOnUiThread(() => Children.Add(avm)); } if (Children.Count == 0) { UiDispatcherService.RunOnUiThread(() => Children.Add(EmptyPlaceholder)); } else if (Children.Count > 1 && HasEmptyPlaceholder) { UiDispatcherService.RunOnUiThread(() => Children.Remove(EmptyPlaceholder)); } }
public void Initialize() { BlockUpdates = false; if (CommitItems == null) { _items = new ObservableCollectionEx <ICommitItem>(); _locker = new object(); // Apparently, not only must CommitItems be set on the UI thread, but the ICollectionView object // must also be created on it! UiDispatcherService.Invoke(() => { CommitItems = CollectionViewSource.GetDefaultView(_items); var listCollectionView = CommitItems as ListCollectionView; if (listCollectionView != null) { listCollectionView.CustomSort = new CommitItemSorter() { Direction = ListSortDirection.Descending }; } }); } if (_historyChecker != null) { _historyChecker.Stop(); _historyChecker = null; } _dataService = (from d in DataServiceLocator.GetSharedServices() where this.Type == d.RepositoryType select d).FirstOrDefault(); this.RefreshCommitHistory(); _historyChecker = new DispatcherTimer() { IsEnabled = false, Interval = new TimeSpan(0, 0, UpdateInterval ?? 3, 0) }; _historyChecker.Tick += (s, e) => RefreshCommitHistory(); _historyChecker.IsEnabled = true; _historyChecker.Start(); }
/// <summary> /// add any ovms to cfivm.Children which are in currentOrgs but not in cfivm.Children. /// </summary> /// <param name="cfivm"></param> /// <param name="freshOrgs"></param> private void AddNewOrgs(ObservableCollection <OrgViewModel> freshOrgs) { foreach (OrgViewModel newOVM in freshOrgs) { if (newOVM != null) { bool orgInChildren = Children.Any(ovm => { var oldOVM = ovm as OrgViewModel; return(oldOVM != null && oldOVM.Org.OrgId == newOVM.Org.OrgId); }); if (!orgInChildren) { UiDispatcherService.RunOnUiThread(() => Children.Add(newOVM)); } } } }
/// <summary> /// Add any svms to Children which are in freshSpaces but not in Children. /// </summary> /// <param name="ovm"></param> /// <param name="freshSpaces"></param> private void AddNewSpaces(ObservableCollection <SpaceViewModel> freshSpaces) { foreach (SpaceViewModel newSVM in freshSpaces) { if (newSVM != null) { bool spaceInChildren = Children.Any(svm => { var oldSVM = svm as SpaceViewModel; return(oldSVM != null && oldSVM.Space.SpaceId == newSVM.Space.SpaceId); }); if (!spaceInChildren) { UiDispatcherService.RunOnUiThread(() => Children.Add(newSVM)); } } } }
/// <summary> /// remove all ovms from cfivm.Children which don't appear in currentOrgs. /// </summary> /// <param name="cfivm"></param> /// <param name="freshOrgs"></param> private void RemoveNonexistentOrgs(ObservableCollection <OrgViewModel> freshOrgs) { var orgsToRemove = new ObservableCollection <OrgViewModel>(); foreach (TreeViewItemViewModel priorChild in Children) { if (priorChild is OrgViewModel oldOVM) { bool orgStillExists = freshOrgs.Any(ovm => ovm != null && ovm.Org.OrgId == oldOVM.Org.OrgId); if (!orgStillExists) { orgsToRemove.Add(oldOVM); } } } foreach (OrgViewModel ovm in orgsToRemove) { UiDispatcherService.RunOnUiThread(() => Children.Remove(ovm)); } }
/// <summary> /// Remove all svms from Children which don't appear in freshSpaces. /// </summary> /// <param name="ovm"></param> /// <param name="freshSpaces"></param> private void RemoveNonexistentSpaces(ObservableCollection <SpaceViewModel> freshSpaces) { var spacesToRemove = new ObservableCollection <SpaceViewModel>(); foreach (TreeViewItemViewModel priorChild in Children) { if (priorChild is SpaceViewModel oldSVM) { bool spaceStillExists = freshSpaces.Any(svm => svm != null && svm.Space.SpaceId == oldSVM.Space.SpaceId); if (!spaceStillExists) { spacesToRemove.Add(oldSVM); } } } foreach (SpaceViewModel svm in spacesToRemove) { UiDispatcherService.RunOnUiThread(() => Children.Remove(svm)); } }
public override async Task RefreshChildren() { if (!IsRefreshing) { IsRefreshing = true; var freshOrgs = await FetchChildren(); RemoveNonexistentOrgs(freshOrgs); AddNewOrgs(freshOrgs); if (Children.Count == 0) { UiDispatcherService.RunOnUiThread(() => Children.Add(EmptyPlaceholder)); } else if (Children.Count > 1 && HasEmptyPlaceholder) { UiDispatcherService.RunOnUiThread(() => Children.Remove(EmptyPlaceholder)); } IsRefreshing = false; } }
public ShellViewModel() { if (!Directory.Exists(ApplicationSettings.Instance.DiffDirectory)) { Directory.CreateDirectory(ApplicationSettings.Instance.DiffDirectory); } var files = Directory.GetFiles(ApplicationSettings.Instance.DiffDirectory).ToList(); files.ForEach(File.Delete); MenuView = ViewLocator.GetSharedInstance <IMenuView>(); MainView = ViewLocator.GetSharedInstance <IRevisionHistoryView>(); RepositoriesView = ViewLocator.GetSharedInstance <IRepositoriesView>(); Container.RegisterInstance <ISourceControlController>(); ChildWindowState = WindowState.Closed; Mediator.Subscribe <BeginBusyEvent>(text => { IsBusy = true; IsBusyText = (text ?? "").ToString(); }); Mediator.Subscribe <EndBusyEvent>(text => IsBusy = false); var showChildWindow = new Action <object>(repo => { UiDispatcherService.InvokeAsync(() => { ChildWindowContent = ViewLocator.GetSharedInstance <IRepositoryEditorView>(); ChildWindowState = WindowState.Open; }); }); Mediator.Subscribe <EditRepositoryEvent>(showChildWindow); Mediator.Subscribe <AddRepositoryEvent>(showChildWindow); Mediator.Subscribe <HideChildWindowEvent>(ignore => ChildWindowState = WindowState.Closed); }