示例#1
0
        private IEnumerable <WoxResult> GetRemoveResults(WoxQuery query, int position)
        {
            var webAppItems = WebAppService
                              .Search(query.GetSearchTermsStarting(position));
            string urlTyped = null;

            if (query.SearchTerms.Length == position + 1)
            {
                urlTyped = query.SearchTerms[position];
            }
            var results = webAppItems
                          .Select
                          (
                item =>
                (urlTyped != null && item.Url == urlTyped)
                        ?
                GetActionResult
                (
                    string.Format("remove {0}", urlTyped),
                    string.Format("Remove the url {0}", urlTyped),
                    () => WebAppService.RemoveUrl(urlTyped)
                )
                        :
                GetCompletionResultFinal
                (
                    string.Format("remove {0}", item.Url),
                    string.Format("Prepare to remove {0}", item.Url),
                    () => string.Format("remove {0}", item.Url)
                )
                          );

            if (results.Count() > 0)
            {
                foreach (var result in results)
                {
                    yield return(result);
                }
            }
            else
            {
                yield return(GetEmptyCommandResult("remove", CommandInfos));
            }
        }
示例#2
0
        private IEnumerable <WoxResult> GetListResults(WoxQuery query, int position)
        {
            var terms = query.GetSearchTermsStarting(position);

            return(WebAppService
                   .Search(terms)
                   .Select
                   (
                       item => GetActionResult
                       (
                           string.Format("Start {0}", item.Url),
                           string.Format("Start the url {0} ({1}) [{2}]", item.Url, item.Keywords, item.Profile),
                           () =>
            {
                WebAppService.StartUrl(item.Url, item.Profile);
            }
                       )
                   ));
        }
示例#3
0
        private IEnumerable <WoxResult> GetEditResults(WoxQuery query, int position)
        {
            if (query.SearchTerms.Contains("->"))
            {
                var url  = query.GetTermOrEmpty(1);
                var oper = query.GetTermOrEmpty(2);
                if (oper == "->")
                {
                    var    newUrl      = query.GetTermOrEmpty(3);
                    var    newKeywords = query.GetAllSearchTermsStarting(4);
                    string newProfile  = null;
                    if (!HelperService.ExtractProfile(newKeywords, ref newKeywords, ref newProfile))
                    {
                        newProfile = "default";
                    }
                    var webAppItem = WebAppService.GetUrlInfo(url);
                    var keywords   = webAppItem.Keywords;
                    var profile    = webAppItem.Profile;

                    if ((keywords == newKeywords) && (url == newUrl) && (profile == newProfile))
                    {
                        return(new List <WoxResult> {
                            GetCompletionResultFinal(
                                string.Format("Edit {0}", url),
                                string.Format("Edit the url {0} ({1}) [{2}]", url, keywords, profile),
                                () => string.Format("edit {0} -> {0} {1} [{2}]", url, keywords, profile)
                                )
                        });
                    }
                    else
                    {
                        return(new List <WoxResult> {
                            GetActionResult(
                                string.Format("Edit {0}", url),
                                string.Format("Edit the url {0} ({1}) [{2}] -> {3} ({4}) [{5}]", url, keywords, profile, newUrl, newKeywords, newProfile),
                                () =>
                            {
                                WebAppService.EditWebAppItem(url, newUrl, newKeywords, newProfile);
                            }
                                )
                        });
                    }
                }
                else
                {
                    return(new List <WoxResult> {
                        GetCompletionResult(
                            "edit [URL|PATTERN] [ -> URL [KEYWORD] [KEYWORD] [...]]",
                            "Edit an existing url",
                            () => "edit "
                            )
                    });
                }

                throw new System.NotImplementedException();
            }
            else
            {
                var terms = query.GetSearchTermsStarting(position);
                return(WebAppService
                       .Search(terms)
                       .Select
                       (
                           item => GetCompletionResultFinal
                           (
                               string.Format("Edit {0}", item.Url),
                               string.Format("Edit the url {0} ({1}) [{2}]", item.Url, item.Keywords, item.Profile),
                               () => string.Format("edit {0} -> {0} {1} [{2}]", item.Url, item.Keywords, item.Profile)
                           )
                       ));
            }
        }