예제 #1
0
        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));
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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");
            }
        }
예제 #5
0
        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));
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
 void Add(ApplicationViewModel addThis, TabViewModel addToThis)
 {
     Add(addThis, addToThis, false);
 }