示例#1
0
        private void ItemsCopyMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var menuItem  = (MenuItem)e.OriginalSource;
            var viewModel = GetSelectedTargets(menuItem).Cast <RssItemViewModel>().FirstOrDefault();

            if (viewModel is null)
            {
                return;
            }

            var kws = App.RSSViewerHost.ServiceProvider.GetRequiredService <KeywordsService>();
            var kw  = kws.GetKeywords(viewModel.RssItem);

            if (StringsPickerWindow.TryPickString(this, kw, out var text))
            {
                try
                {
                    Clipboard.SetText(text);
                }
                catch (Exception exc)
                {
                    MessageBox.Show($"Unable to copy: {exc}");
                }
            }
        }
示例#2
0
        private async void AddAutoRuleMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var menuItem  = (MenuItem)e.OriginalSource;
            var viewModel = GetSelectedTargets(menuItem).Cast <RssItemViewModel>().FirstOrDefault();

            if (viewModel is null)
            {
                return;
            }

            var sp  = App.RSSViewerHost.ServiceProvider;
            var kws = sp.GetRequiredService <KeywordsService>();
            var kw  = kws.GetKeywords(viewModel.RssItem);

            if (StringsPickerWindow.TryPickString(this, kw, out var text))
            {
                var rule = sp.GetRequiredService <ConfigService>()
                           .CreateMatchRule();

                var title = viewModel.RssItem.Title ?? string.Empty;
                if (title.StartsWith(text, StringComparison.OrdinalIgnoreCase))
                {
                    rule.Mode = MatchMode.StartsWith;
                }
                else
                {
                    rule.Mode = MatchMode.Contains;
                }
                rule.IgnoreCase = true;
                rule.Argument   = text;

                if (EditRuleWindow.Edit(this, rule))
                {
                    var cs = App.RSSViewerHost.ServiceProvider.GetRequiredService <ConfigService>();
                    await cs.AddMatchRuleAsync(rule);
                }
            }
        }