示例#1
0
        void AssertMatch(IContext context, IActionSource3 c, string input, string expectedActionText)
        {
            var q       = Query.Parse(context, input);
            var results = c.GetActions(q).ToEnumerable().OrderByDescending(_ => _.Priority).ToList();

            Assert.IsTrue(results.First().Action.Name.Contains(expectedActionText));
        }
示例#2
0
        public void Add(IActionSource3 source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            Sources = Sources.Concat(source).ToList();
        }
示例#3
0
 public static IActionSource3 CreateFilter(this IActionSource3 source, Func <IAction, IEnumerable <IAction> > filterFunction)
 {
     return(new Filter(source, results =>
     {
         return results.SelectMany(result =>
         {
             var action = result.Action;
             return filterFunction(action).Select(_ => { var r = _.ToResult(); r.Priority = result.Priority; return r; });
         });
     }));
 }
示例#4
0
 public static IActionSource3 NoFileAssociation(IActionSource3 source)
 {
     return(source.CreateFilter(action =>
     {
         var p = GetPath(action);
         if (p != null && p.IsFile && !blacklist.Contains(p.Extension.ToLower()))
         {
             var openInVlc = new Action()
             {
                 Name = String.Format("Notepad: {0}", p),
                 CommandObject = new StartProcess()
                 {
                     Arguments = p.Quote(),
                     FileName = notepadPlusPlusExe,
                 }
             };
             return new IAction[] { action, openInVlc };
         }
         return new[] { action };
     }));
 }
示例#5
0
        public static IActionSource3 OpenInVlc(IActionSource3 source)
        {
            return(source.CreateFilter(action =>
            {
                var dir = GetPath(action);
                if (dir != null && dir.IsDirectory)
                {
                    var openInVlc = new Action()
                    {
                        Name = String.Format("Open in VLC: {0}", dir.Quote()),
                        CommandObject = new StartProcess()
                        {
                            Arguments = dir.Quote(),
                            FileName = vlcExe
                        }
                    };
                    return new[] { action, openInVlc };
                }

                return new[] { action };
            }));
        }
示例#6
0
 public Filter(IActionSource3 source, Func <IObservable <IResult>, IObservable <IResult> > filter)
 {
     this.source = source;
     this.filter = filter;
 }
示例#7
0
        public SearchBox(IContext context, IActionSource3 actionSource)
        {
            int size = 40;

            Context = context;

            System.Threading.Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var font  = this.Font;
            var brush = new SolidBrush(Color.Black);

            itemView = new ObjectListView()
            {
                HeaderStyle                       = ColumnHeaderStyle.None,
                Dock                              = DockStyle.Fill,
                TabStop                           = false,
                RowHeight                         = size,
                GridLines                         = false,
                HideSelection                     = false,
                UseCustomSelectionColors          = true,
                HighlightBackgroundColor          = SystemColors.Highlight,
                UnfocusedHighlightBackgroundColor = SystemColors.Highlight,
                HighlightForegroundColor          = SystemColors.HighlightText,
                UnfocusedHighlightForegroundColor = SystemColors.HighlightText,
                OwnerDraw                         = true,
                ShowGroups                        = false,
                ShowItemToolTips                  = true,
                Sorting                           = SortOrder.None,
                UseAlternatingBackColors          = true,
                AlternateRowBackColor             = Color.FromArgb(0xff, 0xf0, 0xf0, 0xf0),
                UseHotItem                        = true,
                FullRowSelect                     = true,
            };

            itemView.Columns.Add(new OLVColumn()
            {
                Name                    = "Icon",
                AspectGetter            = x => ((IResult)x).Action.Name,
                AspectToStringConverter = x => String.Empty,
                ImageGetter             = x =>
                {
                    try
                    {
                        var icon = ((IResult)x).Action.Icon;
                        return(icon != null ? icon.ToBitmap() : null);
                    }
                    catch
                    {
                        return(null);
                    }
                },
                Width = size,
            });

            var markdownTextRenderer = new MarkdownTextRenderer(new Font(FontFamily.GenericSansSerif, 11.0f));

            itemView.Columns.Add(new OLVColumn()
            {
                Name         = "Name",
                AspectGetter = data =>
                {
                    var result = (IResult)data;
                    var action = result.Action;
                    return(String.Format("{0}", action.Name));
                },
                WordWrap       = true,
                FillsFreeSpace = true,

                /*
                 * RendererDelegate = delegate(EventArgs e, Graphics g, Rectangle r, Object rowObject)
                 * {
                 *  var a = ((IResult)rowObject).Action;
                 *  var text = Highlight(a.Name, this.Query);
                 *  g.FillRectangle(Brushes.White, r);
                 *  markdownTextRenderer.DrawText(g, text, r);
                 *  return true;
                 * }
                 */
            });

            // todo: react on updated icons
            // Action.IconCache.EntryUpdated +=new EventHandler<LruCacheBackground<Action,Icon>.EntryUpdatedEventArgs>(IconCache_EntryUpdated);

            this.Controls.Add(itemView);

            InitializeComponent();

            itemView.ItemActivate += new EventHandler(itemView_ItemsActivated);
            itemView.GotFocus     += new EventHandler(itemView_GotFocus);

            itemView.ContextMenu = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Activate", (s, e) =>
                {
                    OnItemsActivated();
                }),
                new MenuItem("Remove", (s, e) =>
                {
                    Remove();
                }),
                new MenuItem("Properties", (s, e) =>
                {
                    Properties();
                }),
            });

            textBoxQuery.KeyDown += new KeyEventHandler(textBoxQuery_KeyDown);

            ActionSource = actionSource;

            textBoxQuery.HandleCreated += (s, e) =>
            {
                var resultStream = textBoxQuery.GetTextChangedObservable()
                                   .Throttle(TimeSpan.FromMilliseconds(200))
                                   .Select(text => { var c = Context; return(c == null ? null : Query.Parse(c, text)); })
                                   .Where(_ => _ != null)
                                   .Merge(ManualUpdate)
                                   .Select(query =>
                {
                    log.Info("Query: " + query.Text);
                    return(ActionSource.GetActions(query));
                });

                resultStream.Subscribe(result =>
                {
                    results = new List <IResult>();

                    if (currentItemsReceiver != null)
                    {
                        currentItemsReceiver.Dispose();
                    }

                    currentItemsReceiver = result
                                           .Buffer(TimeSpan.FromMilliseconds(200), 50)
                                           .Select(_ =>
                    {
                        results = results.Concat(_)
                                  .OrderByDescending(x => x.Priority)
                                  .ThenByDescending(x => x.Action.LastExecuted)
                                  .ToList();
                        return(results);
                    })
                                           .ObserveOn(this)
                                           .Subscribe(results =>
                    {
                        itemView.SetObjects(results.Take(100).ToList());
                        itemView.SelectedIndex = 0;
                    });
                });
            };
        }