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 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 Edit(ApplicationViewModel toEdit) { if (toEdit == null) { throw new ArgumentNullException("toEdit"); } ApplicationViewModel editApplication = new ApplicationViewModel(); editApplication.UpdateWith(toEdit); ServiceManager.GetService <IViewService>().OpenDialog(editApplication); if (editApplication.Result != MessageResult.Okay) { return; // Cancelled edit. } if (!editApplication.Title.Equals(toEdit.Title, StringComparison.InvariantCultureIgnoreCase)) { // Application title has changed, check if any other applications have the new title if (Tabs.Any(t => t.Applications.Any(a => a.Title == editApplication.Title))) { ServiceManager.GetService <IMessageBoxService>().Show( "Already exists with the title " + editApplication.Title, "Astounding Dock", MessageIcon.Error); // Re-open dialog. Edit(toEdit); return; } } toEdit.UpdateWith(editApplication); if (toEdit.Tab != toEdit.OldTab) { // Moving to a new tab. var newTab = Tabs.Single(t => t.Title == toEdit.Tab); Move(toEdit, newTab); } else { Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Update(toEdit.Model)); } // Refresh the view to reapply the sort in case the application was renamed. // Needs to be done after 'UpdateWith' is called. Tabs.Single(t => t.Title == editApplication.Tab).ApplicationsView.Refresh(); }
/// <summary> /// If we mess up the tab ordering just reset the order /// </summary> void FixTabOrdering() { int tabsWithDefaultOrder = Tabs.Count(x => x.TabOrder == 1); int tabsWithMaxOrder = Tabs.Count(x => x.TabOrder == Tabs.Max(m => m.TabOrder)); if (tabsWithDefaultOrder > 1 || tabsWithMaxOrder > 1) { int order = 1; foreach (var tab in Tabs.OrderBy(x => x.Title)) { tab.TabOrder = order; order++; Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Update(tab.Model)); } // Refresh the view to reapply the sort TabsView.Refresh(); } }