コード例 #1
0
 public SearchSourceSettingWindow(IList <SearchSource> sources, PluginInitContext context, SearchSource old)
 {
     _oldSearchSource = old;
     _viewModel       = new SearchSourceViewModel {
         SearchSource = old.DeepCopy()
     };
     Initilize(sources, context, Action.Edit);
 }
コード例 #2
0
 private void Initilize(IList <SearchSource> sources, PluginInitContext context, Action action)
 {
     InitializeComponent();
     DataContext    = _viewModel;
     _searchSource  = _viewModel.SearchSource;
     _searchSources = sources;
     _action        = action;
     _context       = context;
     _api           = _context.API;
 }
コード例 #3
0
ファイル: SearchSource.cs プロジェクト: xianliy/Wox
        public SearchSource DeepCopy()
        {
            var webSearch = new SearchSource
            {
                Title         = string.Copy(Title),
                ActionKeyword = string.Copy(ActionKeyword),
                Url           = string.Copy(Url),
                Icon          = string.Copy(Icon),
                Enabled       = Enabled
            };

            return(webSearch);
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: zgca/CodeHub
        public List <Result> Query(Query query)
        {
            _updateSource?.Cancel();
            _updateSource = new CancellationTokenSource();
            _updateToken  = _updateSource.Token;

            SearchSource searchSource =
                _settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);

            if (searchSource != null)
            {
                string keyword  = query.Search;
                string title    = keyword;
                string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title;
                if (string.IsNullOrEmpty(keyword))
                {
                    var result = new Result
                    {
                        Title    = subtitle,
                        SubTitle = string.Empty,
                        IcoPath  = searchSource.IconPath
                    };
                    return(new List <Result> {
                        result
                    });
                }
                else
                {
                    var results = new List <Result>();
                    var result  = new Result
                    {
                        Title    = title,
                        SubTitle = subtitle,
                        Score    = 6,
                        IcoPath  = searchSource.IconPath,
                        Action   = c =>
                        {
                            Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
                            return(true);
                        }
                    };
                    results.Add(result);
                    UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
                    return(results);
                }
            }
            else
            {
                return(new List <Result>());
            }
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: xin497668869/Wox
        private void UpdateResultsFromSuggestion(List <Result> results, string keyword, string subtitle,
                                                 SearchSource searchSource, Query query)
        {
            if (_settings.EnableSuggestion)
            {
                const int waittime = 300;
                Task      task     = Task.Run(async() => {
                    IEnumerable <Result> suggestions = await Suggestions(keyword, subtitle, searchSource);
                    results.AddRange(suggestions);
                }, _updateToken);

                if (!task.Wait(waittime))
                {
                    task.ContinueWith(_ => ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs {
                        Results = results,
                        Query   = query
                    }), _updateToken);
                }
            }
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: cxfksword/Wox
        private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle,
            SearchSource searchSource, Query query)
        {
            if (_settings.EnableSuggestion)
            {
                const int waittime = 300;
                var task = Task.Run(async () =>
                {
                    var suggestions = await Suggestions(keyword, subtitle, searchSource);
                    results.AddRange(suggestions);
                }, _updateToken);

                if (!task.Wait(waittime))
                {
                    task.ContinueWith(_ => ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs
                    {
                        Results = results,
                        Query = query
                    }), _updateToken);
                }
            }
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: xin497668869/Wox
        Suggestions(string keyword, string subtitle, SearchSource searchSource)
        {
            SuggestionSource source = _settings.SelectedSuggestion;

            if (source != null)
            {
                List <string> suggestions = await source.Suggestions(keyword);

                IEnumerable <Result> resultsFromSuggestion = suggestions.Select(o => new Result {
                    Title    = o,
                    SubTitle = subtitle,
                    Score    = 5,
                    IcoPath  = searchSource.IconPath,
                    Action   = c => {
                        Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
                        return(true);
                    }
                });
                return(resultsFromSuggestion);
            }

            return(new List <Result>());
        }
コード例 #8
0
        private async Task <IEnumerable <Result> > Suggestions(string keyword, string subtitle, SearchSource searchSource)
        {
            var source = _settings.SelectedSuggestion;

            if (source != null)
            {
                var suggestions = await source.Suggestions(keyword);

                var resultsFromSuggestion = suggestions.Select(o => new Result
                {
                    Title    = o,
                    SubTitle = subtitle,
                    Score    = 5,
                    IcoPath  = searchSource.IconPath,
                    ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
                    Action = c =>
                    {
                        if (_settings.OpenInNewBrowser)
                        {
                            searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow(_settings.BrowserPath);
                        }
                        else
                        {
                            searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewTabInBrowser(_settings.BrowserPath);
                        }

                        return(true);
                    }
                });
                return(resultsFromSuggestion);
            }
            return(new List <Result>());
        }
コード例 #9
0
 private void Initilize(IList<SearchSource> sources, PluginInitContext context, Action action)
 {
     InitializeComponent();
     DataContext = _viewModel;
     _searchSource = _viewModel.SearchSource;
     _searchSources = sources;
     _action = action;
     _context = context;
     _api = _context.API;
 }
コード例 #10
0
 public SearchSourceSettingWindow(IList<SearchSource> sources, PluginInitContext context, SearchSource old)
 {
     _oldSearchSource = old;
     _viewModel = new SearchSourceViewModel {SearchSource = old.DeepCopy()};
     Initilize(sources, context, Action.Edit);
 }
コード例 #11
0
ファイル: Main.cs プロジェクト: cxfksword/Wox
 private async Task<IEnumerable<Result>> Suggestions(string keyword, string subtitle, SearchSource searchSource)
 {
     var source = _settings.SelectedSuggestion;
     if (source != null)
     {
         var suggestions = await source.Suggestions(keyword);
         var resultsFromSuggestion = suggestions.Select(o => new Result
         {
             Title = o,
             SubTitle = subtitle,
             Score = 5,
             IcoPath = searchSource.IconPath,
             Action = c =>
             {
                 Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
                 return true;
             }
         });
         return resultsFromSuggestion;
     }
     return new List<Result>();
 }
コード例 #12
0
ファイル: Main.cs プロジェクト: magicdmer/Wox
        private async Task <IEnumerable <Result> > Suggestions(string keyword, string subtitle, SearchSource searchSource)
        {
            var source = _settings.SelectedSuggestion;

            if (source != null)
            {
                var suggestions = await source.Suggestions(keyword);

                var resultsFromSuggestion = suggestions.Select(o => new Result
                {
                    Title    = o,
                    SubTitle = subtitle,
                    Score    = 5,
                    IcoPath  = searchSource.IconPath,
                    Action   = c =>
                    {
                        string browserPath = GetBrowserPath();
                        if (browserPath.Length == 0)
                        {
                            Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
                        }
                        else
                        {
                            Process.Start(browserPath, searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
                        }

                        return(true);
                    }
                });
                return(resultsFromSuggestion);
            }
            return(new List <Result>());
        }