void Edit(TabViewModel toEdit) { if (toEdit == null) { throw new ArgumentNullException("toEdit"); } TabViewModel editTab = new TabViewModel(); editTab.UpdateWith(toEdit); ServiceManager.GetService <IViewService>().OpenDialog(editTab); if (editTab.Result != MessageResult.Okay) { return; // Cancelled edit } if (!editTab.Title.Equals(toEdit.Title, StringComparison.InvariantCultureIgnoreCase)) { // Tab title changed, check if any other tabs have this title. if (Tabs.Any(t => t.Title == editTab.Title)) { ServiceManager.GetService <IMessageBoxService>().Show( "Tab wit that title already exists", "Astounding Dock", MessageIcon.Error); // Re-open dialog. Edit(toEdit); return; } } toEdit.UpdateWith(editTab); Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Update(toEdit.Model)); }
void ReorderTabs(TabViewModel tab, bool moveUp) { if (moveUp && tab.TabOrder == 1) { return; } if (!moveUp && tab.TabOrder == Tabs.Max(x => x.TabOrder)) { return; } int currentPosition = Tabs.IndexOf(tab); int newPosition = moveUp ? currentPosition - 1 : currentPosition + 1; Tabs.Move(currentPosition, newPosition); int tabOrder = 1; foreach (var item in Tabs) { item.TabOrder = tabOrder; tabOrder++; Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Update(item.Model)); } // Refresh the view to reapply the sort TabsView.Refresh(); }
void Add(TabViewModel addThis) { if (addThis == null) { throw new ArgumentNullException("addThis"); } ServiceManager.GetService <IViewService>().OpenDialog(addThis); if (addThis.Result != MessageResult.Okay) { return; // Cancelled add } // Check if any other tabs have this title. if (Tabs.Any(sectionElem => sectionElem.Title == addThis.Title)) { ServiceManager.GetService <IMessageBoxService>().Show( "Tab with that title already exists", "Astounding Dock", MessageIcon.Error); // Re-open dialog. Add(addThis); return; } addThis.TabOrder = Tabs.Max(x => x.TabOrder) + 1; Tabs.Add(addThis); }
void Add(ApplicationViewModel addThis, TabViewModel addToThis, bool suppressDialog) { if (addThis == null) { throw new ArgumentNullException("addThis"); } if (addToThis == null) { throw new ArgumentNullException("addToThis"); } var tab = Tabs.SingleOrDefault(tabElem => tabElem.Applications.Contains(addThis)); if (tab != null) { ServiceManager.GetService <IMessageBoxService>().Show(String.Format( "{0} already added to tab {1}", addThis.Title, tab.Title), "Astounding Dock", MessageIcon.Error); return; } addToThis.Applications.Add(addThis); if (!suppressDialog) { ServiceManager.GetService <IMessageBoxService>().Show(String.Format( "Added application {0} to {1}", addThis.Title, addToThis.Title), "Astounding Dock"); } }
void Move(TabViewModel moveThis, TabViewModel moveToThis) { if (moveThis == null) { throw new ArgumentNullException("moveThis"); } if (moveToThis == null) { throw new ArgumentNullException("moveToThis"); } Tabs.Move(Tabs.IndexOf(moveThis), Tabs.IndexOf(moveToThis)); }
void Move(ApplicationViewModel toMove, TabViewModel movingTo) { if (toMove == null) { throw new ArgumentNullException("toMove"); } if (movingTo == null) { throw new ArgumentNullException("movingTo"); } if (!movingTo.Applications.Contains(toMove)) { var movingFrom = Tabs.Single(sectionElem => sectionElem.Applications.Contains(toMove)); movingFrom.Applications.Remove(toMove); movingTo.Applications.Add(toMove); } }
void Remove(TabViewModel removeThis) { if (removeThis == null) { throw new ArgumentNullException("removeThis"); } var result = ServiceManager.GetService <IMessageBoxService>().Show(String.Format( "Are you sure you wish to remove {0}?", removeThis.Title), "Astounding Dock", MessageIcon.Question, MessageOptions.YesNo); if (result != MessageResult.Yes) { return; } if (removeThis.Title == Configuration.DefaultTab) { ServiceManager.GetService <IMessageBoxService>().Show( "Cannot remove the default section", "Astounding Dock", MessageIcon.Error); return; } if (removeThis.Applications.Count > 0) { var result2 = ServiceManager.GetService <IMessageBoxService>().Show(String.Format( "This tab has {0} applications, remove anyway?", removeThis.Applications.Count), "Astounding Dock", MessageIcon.Question, MessageOptions.YesNo); if (result2 != MessageResult.Yes) { return; } } Tabs.Remove(removeThis); }
public MainViewModel(XmlDatabase database) { if (database == null) { throw new ArgumentNullException("database"); } _database = database; Tabs = new ObservableCollection <TabViewModel>(); TabsView = (ListCollectionView)CollectionViewSource.GetDefaultView(Tabs); TabsView.SortDescriptions.Add(new SortDescription("TabOrder", ListSortDirection.Ascending)); // Loading applications asynchronously using reactive extensions to reduce initial startup time. // TODO: Does this actually speed things up or is it loading all the sections before add doing // the subscribe?? _database.LoadTabs().OrderBy(x => x.TabOrder).ToObservable().Subscribe(tabModel => { TabViewModel tabViewModel = new TabViewModel(tabModel); Tabs.Add(tabViewModel); Configuration.AvailableTabs.Add(tabViewModel.Title); }, () => // OnComplete { FixTabOrdering(); Tabs.CollectionChanged += OnTabsChanged; // Expand the default tab when the application starts up. ExpandedTab = Tabs.SingleOrDefault(obj => obj.Title == Configuration.DefaultTab) ?? Tabs.FirstOrDefault(); }); Messenger.Default.Register <ApplicationMessage>(this, OnApplicationMessage); Messenger.Default.Register <TabMessage>(this, OnTabMessage); Messenger.Default.Register <TabToMainMessage>(this, OnTabToMainMessage); }
void Add(ApplicationViewModel addThis, TabViewModel addToThis) { Add(addThis, addToThis, false); }