Inheritance: TreeNodeViewModel
コード例 #1
0
        private void MarkFeedRead(RoutedEventArgs e)
        {
            if (_selectedNode == null)
            {
                return;
            }
            SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode;

            if (tvm.Node is Model.Feed)
            {
                Model.Feed selectedFeed = (Model.Feed)tvm.Node;
                Data.Feed  df           = new Data.Feed(selectedFeed);
                df.MarkAllRead();
            }
            else if (tvm.Node is Model.Host)
            {
                Model.Host selectedHost = (Model.Host)tvm.Node;
                Data.Host  dh           = new Data.Host(selectedHost);
                dh.MarkAllRead();
            }
            else
            {
                return;
            }

            foreach (Article a in Articles)
            {
                a.Unread = false;
            }
        }
コード例 #2
0
        private void SelectedItemChanged(RoutedPropertyChangedEventArgs <object> obj)
        {
            object selected = obj.NewValue;

            if (selected == null)
            {
                return;
            }

            if (selected is SimpleTreeNodeViewModel)
            {
                SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)selected;
                _selectedNode = tvm;
                if (tvm.Node is Model.Feed)
                {
                    Articles = new SortableObservableCollection <Model.Article>(((Model.Feed)tvm.Node).Articles);
                }
                else if (tvm.Node is Model.Host)
                {
                    List <Model.Article> intermediate = new List <Model.Article>();
                    foreach (Model.Feed feed in ((Model.Host)tvm.Node).Feeds)
                    {
                        foreach (Model.Article a in feed.Articles)
                        {
                            intermediate.Add(a);
                        }
                    }
                    Articles = new SortableObservableCollection <Model.Article>(intermediate);
                }
                else
                {
                    if (_articles == null)
                    {
                        _articles = new SortableObservableCollection <Article>();
                    }
                    _articles.Clear();
                    foreach (Model.Host h in _allData)
                    {
                        foreach (Model.Feed feed in h.Feeds)
                        {
                            foreach (Model.Article a in feed.Articles)
                            {
                                _articles.Add(a);
                            }
                        }
                    }
                }
                SortedArticles.SortDescriptions.Clear();                                                           // Clear all
                SortedArticles.SortDescriptions.Add(new SortDescription("SortKey", ListSortDirection.Descending)); // Sort descending by "PropertyName"
                //Articles.OrderByDescending(el => el.SortKey);
            }
            RaisePropertyChanged("SortedArticles");
        }
コード例 #3
0
        private async void DeleteFeed(RoutedEventArgs e)
        {
            if (_selectedNode == null)
            {
                return;
            }
            SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode;

            Model.Feed selectedFeed = null;
            if (tvm.Node is Model.Feed)
            {
                selectedFeed = (Model.Feed)tvm.Node;
            }
            else
            {
                return;
            }


            // Hides browser otherwise dialog gets behind it
            IsBrowserVisible = false;
            RaisePropertyChanged("IsBrowserVisible");

            MessageDialogResult result = await _dialogCoordinator.ShowMessageAsync(this, "Delete Feed", "This action also deletes all downloaded articles and cannot be undone. Are you sure?", MessageDialogStyle.AffirmativeAndNegative);

            if (result == MessageDialogResult.Affirmative)
            {
                string errMsg = null;
                try
                {
                    Data.Feed feed = new Data.Feed(selectedFeed);
                    feed.Delete();
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                if (errMsg != null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Edit Feed", "Unable to edit feed with the supplied URL: " + errMsg);
                }
            }
            IsBrowserVisible = true;
            RaisePropertyChanged("IsBrowserVisible");
            InitializeData(true);
        }
コード例 #4
0
        private void InitializeData(Boolean refreshTreeView)
        {
            SetStatusMessage("Loading");
            //
            // Read from Database
            //
            _allData = Data.Host.LoadAll();

            SetStatusMessage("Loaded");

            //
            // Update the treeview
            //

            if (refreshTreeView)
            {
                //Set selected item
                TreeModel.Items[0].IsSelected = true;
                RaisePropertyChanged("TreeModel");
                SelectedItemChanged(new RoutedPropertyChangedEventArgs <object>(null, TreeModel.Items[0]));
            }

            //
            // Update articles
            //
            if (_selectedNode != null)
            {
                SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode;
                if (tvm.Node is Model.Feed)
                {
                    SetStatusMessage("Updating Articles (feed)... ");
                    Model.Feed selectedFeed = (Model.Feed)tvm.Node;
                    // Find the feed and add the Articles
                    foreach (Host h in _allData)
                    {
                        Feed f = h.Feeds.FirstOrDefault(el => el.Location.Equals(selectedFeed.Location));
                        if (f != null)
                        {
                            Articles.AddMissing(f.Articles, new ArticleEqualityComparer(), _uiContext);
                        }
                    }
                }
                else if (tvm.Node is Model.Host)
                {
                    SetStatusMessage("Updating Articles (host)... ");
                    Model.Host selectedHost = (Model.Host)tvm.Node;
                    // Find the host and add the Articels
                    Model.Host h = _allData.FirstOrDefault(el => el.Location.Equals(selectedHost.Location));
                    foreach (Model.Feed feed in h.Feeds)
                    {
                        Articles.AddMissing(feed.Articles, new ArticleEqualityComparer(), _uiContext);
                    }
                }
                else
                {
                    SetStatusMessage("Updating Articles (article)... ");
                    foreach (Model.Host h in _allData)
                    {
                        foreach (Model.Feed feed in h.Feeds)
                        {
                            Articles.AddMissing(feed.Articles, new ArticleEqualityComparer(), _uiContext);
                        }
                    }
                }
            }
            if (refreshTreeView)
            {
                SetStatusMessage("Refreshing Article list");
                SetSortOrder();
            }
            SetStatusMessage("Ready");
        }
コード例 #5
0
        private async void EditFeed(RoutedEventArgs e)
        {
            if (_selectedNode == null)
            {
                return;
            }
            SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode;

            Model.Feed selectedFeed = null;
            if (tvm.Node is Model.Feed)
            {
                selectedFeed = (Model.Feed)tvm.Node;
            }
            else
            {
                if (tvm.Node is Model.Host)
                {
                    try
                    {
                        Model.Host selectedHost = (Model.Host)tvm.Node;
                        IsBrowserVisible = false;
                        RaisePropertyChanged("IsBrowserVisible");
                        MetroDialogSettings diagSettings = new MetroDialogSettings();
                        diagSettings.DefaultText = selectedHost.Zoom.ToString();
                        var ZoomLevel = await _dialogCoordinator.ShowInputAsync(this, "Set Zoom Level", "Enter the desired zoom level for this host: ", diagSettings);

                        int prevZoom = selectedHost.Zoom;
                        selectedHost.Zoom = Int32.Parse(ZoomLevel.ToString());
                        Data.Host dh = new Data.Host(selectedHost);
                        dh.Save();

                        if (prevZoom != selectedHost.Zoom)
                        {
                            var msg = new SendSetZoomMessage(selectedHost.Zoom);
                            msg.SetImmediately = true;
                            Messenger.Default.Send <SendSetZoomMessage>(msg);
                        }
                    }
                    catch (Exception ex)
                    {
                        await _dialogCoordinator.ShowMessageAsync(this, "Set Zoom Level", "Unable to set zoom: " + ex.Message);
                    }
                    finally
                    {
                        IsBrowserVisible = true;
                        RaisePropertyChanged("IsBrowserVisible");
                    }
                }
                return;
            }


            // Hides browser otherwise dialog gets behind it
            IsBrowserVisible = false;
            RaisePropertyChanged("IsBrowserVisible");
            MetroDialogSettings dialogSettings = new MetroDialogSettings();

            dialogSettings.DefaultText = selectedFeed.Location.ToString();
            var FeedText = await _dialogCoordinator.ShowInputAsync(this, "Edit feed", "Enter the URL of the feed:", dialogSettings);

            if (FeedText != null)
            {
                string errMsg = null;
                try
                {
                    Uri       feedUri = new Uri(FeedText);
                    Data.Feed f       = new Data.Feed(selectedFeed);
                    f.Location = feedUri;
                    f.UpdateFromUri(true, RetentionDays);
                    f.Save(true);
                    InitializeData(true);
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                if (errMsg != null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Edit Feed", "Unable to edit feed with the supplied URL: " + errMsg);
                }
            }
            IsBrowserVisible = true;
            RaisePropertyChanged("IsBrowserVisible");
        }