void Context_DragDrop(object sender, DragEventArgs e) { if (!AcceptDrop) { return; } var tagsPrefix = GetTagsPrefix(); ClipboardUrl cbUrl; if (ClipboardUrl.TryParse(e.Data, out cbUrl)) { FileActionFactory f = new FileActionFactory(); var action = f.FromUrl(cbUrl.Url, cbUrl.Title); action.Name = tagsPrefix + action.Name; actions.AddOrUpdate(action); return; } // right-mouse drag - add recursive bool recursive = (e.Effect == DragDropEffects.Link); var pathList = Sidi.IO.PathList.Get(e.Data); if (pathList != null) { context.AddJob(new Job(pathList.ToString(), () => { Add(pathList, tagsPrefix); })); return; } log.WarnFormat("Dropped data could not be added. Available formats:\r\n{0}", e.Data.GetFormats().ListFormat()); }
public static IEnumerable <Action> GetSpecialFolderActions() { FileActionFactory f = new FileActionFactory(); return(Enum.GetValues(typeof(Environment.SpecialFolder)).Cast <Environment.SpecialFolder>() .SafeSelect(i => { var a = f.FromFile(Environment.GetFolderPath((Environment.SpecialFolder)i)); a.Name = i.ToString(); return a; })); }
public static IEnumerable <Action> GetPathExecutables() { FileActionFactory f = new FileActionFactory(); var exeExtensions = new FileType("exe", "bat", "cmd", "msc", "cpl"); var path = Regex.Split(System.Environment.GetEnvironmentVariable("PATH"), @"\;") .SafeSelect(x => LPath.Parse(x)).ToList(); log.InfoFormat("Searching {0}", path); return(path.SelectMany(p => { return p.GetFiles().Where(x => exeExtensions.Is(x)) .SafeSelect(x => f.FromFile(x)); })); }
public static IEnumerable <Action> GetStartMenuActions() { var factory = new FileActionFactory(); return (new[] { Find.AllFiles(new LPath(AllUsersStartMenu)), Find.AllFiles(Sidi.IO.Paths.GetFolderPath(Environment.SpecialFolder.StartMenu)), Find.AllFiles(Sidi.IO.Paths.GetFolderPath(Environment.SpecialFolder.MyDocuments).CatDir("My RoboForm Data")) .Where(_ => !_.FullName.Parts.Contains("obsolete")) } .SelectMany(_ => _) .Where(x => x.Exists) .Select(_ => factory.FromFile(_))); }
public void Add(PathList paths, string tagsPrefix) { using (var actions = OpenActions()) { FileActionFactory f = new FileActionFactory(); foreach (var i in paths .Where(p => p.Exists && !p.Info.IsHidden)) { try { log.Info(i); var action = f.FromFile(i); action.Name = tagsPrefix + action.Name; actions.AddOrUpdate(action); } catch (Exception ex) { log.Warn(ex); } } } }
protected override IEnumerable <IResult> GetResults(IQuery query) { var terms = query.GetTerms(); var tags = query.Tags; if (!tags.Any() && !terms.Any(_ => _.Length >= 1)) { return(Enumerable.Empty <IResult>()); } var cmd = actions.Connection.CreateCommand(); var termsQuery = And(terms.Select((t, i) => { var paramName = String.Format("@term{0}", i); var parameter = cmd.Parameters.Add(paramName, System.Data.DbType.String); parameter.Value = String.Format("%{0}%", t); return(String.Format("Name like {0}", paramName)); })); var tagsQuery = And(tags.Select((t, i) => { var paramName = String.Format("@tag{0}", i); var parameter = cmd.Parameters.Add(paramName, System.Data.DbType.String); parameter.Value = String.Format("%{0}%", t); return(String.Format("Name like {0}", paramName)); })); cmd.CommandText = String.Format($"select oid from {actions.Table} where {And(tagsQuery, termsQuery)} order by LastUseTime desc limit 50"); log.Info(cmd.CommandText); IList <Action> r; try { r = actions.Query(cmd); } catch (System.Data.SQLite.SQLiteException e) { log.Info(e); return(Enumerable.Empty <IResult>()); } var results = r.SelectMany(action => ToIActions(action)) .Select(a => a.ToResult(query)) .ToList(); if (results.Count == 0) { var markdownLink = MarkdownLink.Parse(query.RawText); if (markdownLink != null) { results.Add(new SimpleAction("add", $"Add {markdownLink.Title}", () => { var factory = new FileActionFactory(); var title = Prompt.GetText("Title"); var action = factory.FromUrl(markdownLink.Href, markdownLink.Title); actions.Add(action); }).ToResult()); } var namedUrl = NamedUrl.Parse(query.RawText); if (namedUrl != null) { results.Add(new SimpleAction("add", $"Add {namedUrl.Title}", () => { var factory = new FileActionFactory(); var title = Prompt.GetText("Title"); var action = factory.FromUrl(namedUrl.Url, namedUrl.Title); actions.Add(action); }).ToResult()); } } return(results); }