示例#1
0
        private IEnumerable <WoxResult> GetImportResults(WoxQuery query, int position)
        {
            var filename = query.GetAllSearchTermsStarting(position);

            if (!string.IsNullOrEmpty(filename))
            {
                if (WebAppService.FileExists(filename))
                {
                    yield return(GetActionResult
                                 (
                                     "import {0}".FormatWith(filename),
                                     "Import urls from [{0}]".FormatWith(filename),
                                     () => WebAppService.Import(filename)
                                 ));
                }
                else
                {
                    yield return(GetCompletionResultFinal
                                 (
                                     "import {0}".FormatWith(filename),
                                     "[{0}] does not exists".FormatWith(filename),
                                     () => "import {0}".FormatWith(filename)
                                 ));
                }
            }
            else
            {
                yield return(GetEmptyCommandResult("import", CommandInfos));
            }
        }
示例#2
0
        private IEnumerable <WoxResult> GetOpenResults(WoxQuery query, int position)
        {
            string profile = "default";
            bool   isValid = false;

            if (query.SearchTerms.Length == position + 1)
            {
                isValid = true;
            }
            if ((query.SearchTerms.Length == position + 2) && query.SearchTerms[position + 1].StartsWith("[") && query.SearchTerms[position + 1].EndsWith("]"))
            {
                isValid = true;
                profile = query.SearchTerms[position + 1].TrimStart('[').TrimEnd(']');
            }

            if (isValid)
            {
                var url = query.SearchTerms[position];
                yield return(GetActionResult
                             (
                                 "open {0}".FormatWith(url),
                                 "Open the web app page [{0}] with profile [{1}] without saving it".FormatWith(url, profile),
                                 () =>
                {
                    WebAppService.StartUrl(url, profile);
                }
                             ));
            }
            else
            {
                yield return(GetEmptyCommandResult("open", CommandInfos));
            }
        }
示例#3
0
        private IEnumerable <WoxResult> GetChangeDir(WoxQuery query, int position)
        {
            string name = query.GetTermOrEmpty(position);

            string value = query.GetAllSearchTermsStarting(position + 1);

            string actualPath = WorkspacerService.GetPathByName(name);

            if (value == null && actualPath == null)
            {
                bool foundRepo = false;
                var  repos     = WorkspacerService.GetRepos();
                foreach (var repo in repos)
                {
                    if (repo.Name.MatchPatternCaseInvariant(name))
                    {
                        foundRepo = true;
                        yield return(GetCompletionResult
                                     (
                                         "work cd {0} [PATTERN] [PATTERN]".FormatWith(repo.Name),
                                         "Search the {0} repo".FormatWith(repo.Name),
                                         () => "cd {0}".FormatWith(repo.Name)
                                     ));
                    }
                }
                if (!foundRepo)
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        yield return(GetEmptyCommandResult("cd", CommandInfos));
                    }
                }
            }
            else
            {
                if (actualPath != null)
                {
                    query.SearchTerms.Skip(2);
                    var workspaces = WorkspacerService.GetWorspaces(actualPath);
                    foreach (var workspace in workspaces)
                    {
                        if (query.SearchTerms.Skip(2).All(term => workspace.MatchPatternCaseInvariant(term)))
                        {
                            yield return(GetActionResult
                                         (
                                             "work cd {0} {1}".FormatWith(name, workspace),
                                             "Go to {1}".FormatWith(name, workspace),
                                             () => WorkspacerService.OpenDir(Path.Combine(actualPath, workspace))
                                         ));
                        }
                    }
                }
                else
                {
                    yield return(GetEmptyCommandResult("cd", CommandInfos));
                }
            }
        }
        public IEnumerable <WoxResult> ExportCommand(WoxQuery query, int position)
        {
            var filename = query.GetAllSearchTermsStarting(position);

            if (string.IsNullOrEmpty(filename))
            {
                yield return(GetEmptyCommandResult("export", CommandInfos));
            }
            else
            {
                yield return(GetActionResult("export {0}".FormatWith(filename), "Export unit and prefix definitions to filename [{0}]".FormatWith(filename), () => Export(filename)));
            }
        }
示例#5
0
        private IEnumerable <WoxResult> GetCreate(WoxQuery query, int position)
        {
            string name = query.GetTermOrEmpty(position);

            string value = query.GetAllSearchTermsStarting(position + 1);

            if (value == null)
            {
                bool foundRepo = false;
                var  repos     = WorkspacerService.GetRepos();
                foreach (var repo in repos)
                {
                    if (repo.Name.MatchPatternCaseInvariant(name))
                    {
                        foundRepo = true;
                        yield return(GetCompletionResult
                                     (
                                         "work cr {0}".FormatWith(repo.Name),
                                         "Create a new workspace in the {0} repo".FormatWith(repo.Name),
                                         () => "cr {0}".FormatWith(repo.Name)
                                     ));
                    }
                }
                if (!foundRepo)
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        yield return(GetEmptyCommandResult("cr", CommandInfos));
                    }
                }
            }
            else
            {
                string actualPath = WorkspacerService.GetPathByName(name);
                if (actualPath != null)
                {
                    yield return(GetActionResult
                                 (
                                     "work cr {0} {1}".FormatWith(name, value),
                                     "Create new workspace \"{1}\" in repo {0}".FormatWith(name, value),
                                     () => WorkspacerService.CreateDir(actualPath, value)
                                 ));
                }
                else
                {
                    yield return(GetEmptyCommandResult("cr", CommandInfos));
                }
            }
        }
        public IEnumerable <WoxResult> DefaultCommand(WoxQuery query, int position)
        {
            var search = query.GetAllSearchTermsStarting(position);

            if (search.Contains("="))
            {
                return(CreateNewUnit(search));
            }
            else if (search.Contains("~"))
            {
                return(CreateNewPrefix(search));
            }
            else
            {
                return(ConvertUnit(search));
            }
        }
示例#7
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));
            }
        }
示例#8
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);
            }
                       )
                   ));
        }
示例#9
0
        private IEnumerable <WoxResult> GetList(WoxQuery query, int position)
        {
            string name = query.GetTermOrEmpty(position);

            var repos = WorkspacerService.GetRepos();

            foreach (var repo in repos)
            {
                if (repo.Name.MatchPatternCaseInvariant(name))
                {
                    yield return(GetActionResult
                                 (
                                     "work list {0}".FormatWith(repo.Name),
                                     "Go to {0}".FormatWith(repo.Path),
                                     () => WorkspacerService.OpenDir(repo.Path)
                                 ));
                }
            }
        }
        private IEnumerable <WoxResult> SearchUnitCommand(WoxQuery query, int position)
        {
            var unitBaseNames = UnitConversionService.GetUnitBaseNames();
            var patterns      = query.SearchTerms.Skip(position);
            var patternFull   = query.GetAllSearchTermsStarting(position);
            var hasResult     = false;

            foreach (var unitBaseName in unitBaseNames)
            {
                var  searchField = "{0} {1} {2}".FormatWith(unitBaseName.Name, unitBaseName.Symbol, unitBaseName.Namespace);
                bool match       = true;
                foreach (var pattern in patterns)
                {
                    match = match && searchField.MatchPattern(pattern);
                }
                if (match && unitBaseName.Symbol.Length > 0)
                {
                    var convertSI = UnitConversionService.Convert(unitBaseName.Symbol);
                    var title     = "{0} ({1})".FormatWith(unitBaseName.Name, unitBaseName.Symbol);
                    var subtitle  = "{0} (namespace: {1})".FormatWith(convertSI.Item2, unitBaseName.Namespace);
                    if (patternFull == unitBaseName.Name)
                    {
                        subtitle  = subtitle + " - convert";
                        hasResult = true;
                        yield return(GetCompletionResultFinal(title, subtitle, () => "convert {0}".FormatWith(unitBaseName.Symbol)));
                    }
                    else
                    {
                        hasResult = true;
                        yield return(GetCompletionResultFinal(title, subtitle, () => "search unit {0}".FormatWith(unitBaseName.Name)));
                    }
                }
            }
            if (!hasResult)
            {
                yield return(GetEmptyCommandResult("unit", GetCommandInfos("search")));
            }
        }
        private IEnumerable <WoxResult> ImportCommand(WoxQuery query, int position)
        {
            var filename = query.GetAllSearchTermsStarting(position);

            if (string.IsNullOrEmpty(filename))
            {
                yield return(GetEmptyCommandResult("import", CommandInfos));
            }
            else
            {
                var fullFilename = GetImportExportFullFilename(filename);
                if (UnitConversionService.CanImportFrom(fullFilename))
                {
                    yield return(GetActionResult("import {0}".FormatWith(filename), "Import unit and prefix definitions from filename [{0}]".FormatWith(filename), () => Import(fullFilename)));
                }
                else
                {
                    yield return(new WoxResult {
                        Title = "import {0}".FormatWith(filename), SubTitle = "Import unit and prefix definitions from filename [{0}] (No file found!)".FormatWith(filename)
                    });
                }
            }
        }
示例#12
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));
            }
        }
示例#13
0
        private IEnumerable <WoxResult> GetName(WoxQuery query, int position)
        {
            string name = query.GetTermOrEmpty(position);

            string value = query.GetAllSearchTermsStarting(position + 1);

            if (value == null)
            {
                bool foundRepo = false;
                var  repos     = WorkspacerService.GetRepos();
                foreach (var repo in repos)
                {
                    if (repo.Name.MatchPatternCaseInvariant(name))
                    {
                        foundRepo = true;
                        yield return(GetCompletionResult
                                     (
                                         "work name {0} {1}".FormatWith(repo.Name, repo.Path),
                                         "The current Path for name {0} is {1}".FormatWith(repo.Name, repo.Path),
                                         () => "name {0} {1}".FormatWith(repo.Name, repo.Path)
                                     ));
                    }
                }
                if (!foundRepo)
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        yield return(GetCompletionResult
                                     (
                                         "work name {0}".FormatWith(name),
                                         "There is no repo named {0} yet".FormatWith(name),
                                         () => "name {0}".FormatWith(name)
                                     ));
                    }
                }
            }
            else
            {
                string actualPath = WorkspacerService.GetPathByName(name);
                if (actualPath != value)
                {
                    if (actualPath == null)
                    {
                        yield return(GetActionResult
                                     (
                                         "work name {0} {1}".FormatWith(name, value),
                                         "Set repo name {0} to path {1}".FormatWith(name, value),
                                         () =>
                        {
                            WorkspacerService.SetPathByName(name, value);
                        }
                                     ));
                    }
                    else
                    {
                        yield return(GetActionResult
                                     (
                                         "work name {0} {1}".FormatWith(name, value),
                                         "Replace repo name {0} to path {1} (actual value is {2})".FormatWith(name, value, actualPath),
                                         () =>
                        {
                            WorkspacerService.SetPathByName(name, value);
                        }
                                     ));
                    }
                }
                else
                {
                    yield return(GetCompletionResultFinal
                                 (
                                     "work name {0} {1}".FormatWith(name, value),
                                     "The current name {0} points to path {1}".FormatWith(name, value),
                                     () => "name {0} {1}".FormatWith(name, value)
                                 ));
                }
            }
        }
 private IEnumerable <WoxResult> ConvertCommand(WoxQuery query, int position) => ConvertUnit(query.GetAllSearchTermsStarting(position));
示例#15
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)
                           )
                       ));
            }
        }
示例#16
0
        private IEnumerable <WoxResult> GetConfig(WoxQuery query, int position)
        {
            var configuration = WorkspacerService.GetConfiguration();
            var configName    = query.GetTermOrEmpty(position);

            string configValue = null;

            if (configName.Contains("="))
            {
                configName = query.GetAllSearchTermsStarting(position);
                var equalPosition = configName.IndexOf("=");
                configValue = configName.Substring(equalPosition + 1, configName.Length - equalPosition - 1);
                configName  = configName.Substring(0, equalPosition);
            }

            if (ConfigNames.ContainsKey(configName))
            {
                var reader = ConfigNames[configName].Key;
                var writer = ConfigNames[configName].Value;

                if (configValue == null)
                {
                    yield return(GetCompletionResultFinal
                                 (
                                     "work config {0}".FormatWith(configName),
                                     "Select {0}={1}".FormatWith(configName, reader(configuration)),
                                     () => "config {0}={1}".FormatWith(configName, reader(configuration))
                                 ));
                }
                else
                {
                    if (reader(configuration) == configValue)
                    {
                        yield return(GetCompletionResultFinal
                                     (
                                         "work config {0}".FormatWith(configName),
                                         "The current value for {0} is {1}".FormatWith(configName, reader(configuration)),
                                         () => "config {0}={1}".FormatWith(configName, reader(configuration))
                                     ));
                    }
                    else
                    {
                        yield return(GetActionResult
                                     (
                                         "work config {0}".FormatWith(configName),
                                         "Set the value for {0} to {1}".FormatWith(configName, configValue),
                                         () =>
                        {
                            writer(configuration, configValue);
                            WorkspacerService.SaveConfiguration(configuration);
                        }
                                     ));
                    }
                }
            }
            else
            {
                if (configValue == null)
                {
                    foreach (var configNameReference in ConfigNames.Keys.OrderBy(k => k))
                    {
                        if (configNameReference.ToLowerInvariant().MatchPatternCaseInvariant(configName.ToLowerInvariant()))
                        {
                            yield return(GetCompletionResult
                                         (
                                             "work config {0}".FormatWith(configNameReference),
                                             "{0}={1}".FormatWith(configNameReference, ConfigNames[configNameReference].Key(configuration)),
                                             () => "config {0}".FormatWith(configNameReference)
                                         ));
                        }
                    }
                }
                else
                {
                    yield return(GetCompletionResultFinal
                                 (
                                     "Configuration error",
                                     "There is no configuration item named {0}".FormatWith(configName),
                                     () => "config {0}".FormatWith(configName)
                                 ));
                }
            }
        }
示例#17
0
        private IEnumerable <WoxResult> GetConfigResults(WoxQuery query, int position)
        {
            if (query.SearchTerms.Length > position)
            {
                var profile       = query.SearchTerms[position];
                var configuration = WebAppService.GetConfiguration(profile);

                if (query.SearchTerms.Length > position + 1)
                {
                    var    launcher             = query.SearchTerms[position + 1];
                    string arguments            = query.GetAllSearchTermsStarting(position + 2);
                    string argumentsCommandLine = arguments ?? "[APP_ARGUMENT_PATTERN]";
                    string argumentsReal        = arguments ?? configuration.WebAppArgumentPattern;

                    string title    = string.Format("config {0} {1} {2}", profile, launcher, argumentsCommandLine);
                    string subTitle = string.Format("Change {0} webapp launcher to [{1}] and argument to [{2}]", profile, launcher, argumentsReal);
                    if (!argumentsReal.Contains("{0}"))
                    {
                        subTitle = string.Format("You should consider having [{0}] inside arguments. Now it contains only [{1}]", "{0}", argumentsReal);
                    }
                    yield return(GetActionResult
                                 (
                                     title,
                                     subTitle,
                                     () =>
                    {
                        WebAppService.UpdateLauncher(launcher, argumentsReal, profile);
                    }
                                 ));
                }
                else
                {
                    if (configuration == null)
                    {
                        yield return(GetCompletionResultFinal
                                     (
                                         string.Format("config {0} [APP_PATH] [APP_ARGUMENT_PATTERN]", profile),
                                         "Create a {0} webapp launcher".FormatWith(profile),
                                         () => {
                            configuration = WebAppService.GetOrCreateConfiguration(profile);
                            return string.Format("config {0} {1} {2}", profile, configuration.WebAppLauncher, configuration.WebAppArgumentPattern);
                        }
                                     ));
                    }
                    else
                    {
                        yield return(GetCompletionResultFinal
                                     (
                                         string.Format("config {0} {1} {2}", profile, configuration.WebAppLauncher, configuration.WebAppArgumentPattern),
                                         "Change {0} webapp launcher to [{1}] and argument to [{2}]".FormatWith(profile, configuration.WebAppLauncher, configuration.WebAppArgumentPattern),
                                         () => string.Format("config {0} {1} {2}", profile, configuration.WebAppLauncher, configuration.WebAppArgumentPattern)
                                     ));
                    }
                }
            }
            else
            {
                var emptyResult = GetEmptyCommandResult("config", CommandInfos);
                foreach (var profile in WebAppService.GetProfiles())
                {
                    var configuration = WebAppService.GetConfiguration(profile);
                    yield return(GetCompletionResult
                                 (
                                     string.Format("config {0} [APP_PATH] [APP_ARGUMENT_PATTERN]", profile),
                                     "Configure the {0} launcher - Select this item to complete the current config".FormatWith(profile),
                                     () => string.Format("config {0}", profile)
                                 ));
                }
            }
        }