Exemplo n.º 1
0
        private IEnumerable <WoxResult> GetAddResults(WoxQuery query, int position)
        {
            var url = query.GetTermOrEmpty(position);

            if (!string.IsNullOrEmpty(url))
            {
                var    keywords = query.GetAllSearchTermsStarting(position + 1);
                string profile  = "default";
                HelperService.ExtractProfile(keywords, ref keywords, ref profile);
                yield return(GetActionResult
                             (
                                 string.Format("add {0} {1} [{2}]", url, keywords, profile),
                                 string.Format("Add the url {0} with keywords ({1}) and using profile [{2}]", url, keywords, profile),
                                 () =>
                {
                    WebAppService.AddWebAppItem(url, keywords, profile);
                }
                             ));
            }
            else
            {
                yield return(GetEmptyCommandResult("add", CommandInfos));
            }
        }
Exemplo n.º 2
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)
                           )
                       ));
            }
        }