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)); } } }
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)); } } }
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> 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)); } }
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) )); } } }
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> 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) ) )); } }