예제 #1
0
파일: Plugin.cs 프로젝트: sidiandi/hagen
        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());
        }
예제 #2
0
        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);
        }