protected override bool OnConfirmed(UIResultItem result) { string path = result.ResultDesc; if (!string.IsNullOrWhiteSpace(path)) { if (Directory.Exists(path) || File.Exists(path)) { if (path.Contains("steamapps\\common") && Path.GetExtension(path) == ".exe") { Log.Warning("Steam game detected, might not launch properly if exe is run directly."); } string file = Path.GetFileName(path); Log.Message(string.Format("Starting process for: '{0}'...", file)); try { Process.Start(path); Log.Success(string.Format("Process for: '{0}' started succesfully", file)); } catch (Exception e) { Log.Error(string.Format("Failed to start process for '{0}'", result.ResultName)); Log.Exception(e); } } else { Log.Error(string.Format("Failed to open file or directory: file or directory '{0}' does not exist", path)); return(false); } } return(true); }
private void AddIconToResult(UIResultItem result) { if (result.iconFromFile) { IntPtr iIcon = Win32.GetIconIndex(result.ResultDesc); IntPtr hIcon = Win32.GetExtraLargeIcon(iIcon); if (!IconCache.ContainsKey(iIcon)) { if (hIcon != IntPtr.Zero) { Icon icon = Icon.FromHandle(hIcon); if (icon != null) { ImageSource imgSource = icon.ToImageSource(); IconCache.Add(iIcon, imgSource); result.ResultIconBitmap = imgSource; } } } else { result.ResultIconBitmap = IconCache[iIcon]; } } }
public bool Confirm() { if (MainWindow.ListBoxResults.SelectedItem != null) { UIResultItem item = (UIResultItem)MainWindow.ListBoxResults.SelectedItem; Log.Message(string.Format("Confirmed item: {0}", item.ResultName)); return(OnConfirmed(item)); } return(false); }
private void PreviewPicture(UIResultItem item, string extension) { Uri uri = new Uri(item.ResultDesc, UriKind.Absolute); BitmapImage img = new BitmapImage(uri); PreviewImage.Width = img.Height; PreviewImage.Height = img.Height; PreviewImage.UpdateLayout(); PreviewImage.Source = img; }
protected override void OnQuery(string query) { if (IsScanning) { return; } string lowerCaseQuery = query.ToLower(); int closestIndex = -1; if (_queryWorker.IsBusy) { _queryWorker.CancelAsync(); _queryWorker.Dispose(); _queryWorker = new BackgroundWorker(); _queryWorker.WorkerSupportsCancellation = true; } _queryWorker.DoWork += (sender, args) => { closestIndex = FindClosestResultIndex(lowerCaseQuery); // heavy CPU }; _queryWorker.RunWorkerCompleted += (sender, args) => { if (closestIndex != -1) { UIResults results = new UIResults(); Log.Message(string.Format("Last query result: {0}", Path.GetFileName(BigResultList[closestIndex].GetPathString()))); for (int i = 0; i < MaxResultsShown; i++) { int index = (closestIndex + i); if (index < BigResultList.Count && index > 0) { string path = BigResultList[index].GetPathString(); string file = Path.GetFileName(path); UIResultItem uiItem = new UIResultItem(true, file, path); results.Add(uiItem); } } ShowResults(results, lowerCaseQuery); QueryEnd(results, query); } else { QueryEnd(null, query); } }; _queryWorker.RunWorkerAsync(); }
protected override bool OnConfirmed(UIResultItem result) { string text = result.ResultName.ToLower(); if (_commands.ContainsKey(text)) { _commands[text].Execute(); return(true); } else { Log.Warning(string.Format("Command {0} not found, no such command exists", text)); return(false); } }
public virtual void PreviewFromQueryResultItem(UIResultItem item) { string extension = Path.GetExtension(item.ResultDesc); PreviewName.Text = item.ResultName; PreviewDesc.Text = item.ResultDesc; if (BitmapHelper.IsSupportedFormat(extension)) { PreviewPicture(item, extension); } else { PreviewDefault(item); } }
private void PreviewDefault(UIResultItem item) { if (item.ResultIconBitmap != null) { IntPtr iIcon = Win32.GetIconIndex(item.ResultDesc); IntPtr hIcon = Win32.GetJumboIcon(iIcon); if (hIcon != IntPtr.Zero) { Icon icon = Icon.FromHandle(hIcon); if (icon != null) { ImageSource imgSource = icon.ToImageSource(); PreviewImage.Width = imgSource.Width; PreviewImage.Height = imgSource.Height; PreviewImage.Source = imgSource; } } } else { if (!string.IsNullOrWhiteSpace(item.ResultIcon)) { if (!_resourceIconCache.ContainsKey(item.ResultIcon)) { BitmapImage img = new BitmapImage(new Uri(item.ResultIcon, UriKind.Absolute)); _resourceIconCache.Add(item.ResultIcon, img); } BitmapImage imgSource = _resourceIconCache[item.ResultIcon]; PreviewImage.Width = imgSource.Width; PreviewImage.Height = imgSource.Height; PreviewImage.Source = imgSource; } } }
protected abstract bool OnConfirmed(UIResultItem result);
public MainWindow() { InitializeComponent(); QueryHandlers = new Dictionary <Type, QueryHandler>(); ListBoxResults.SelectionMode = SelectionMode.Single; _hooks = new KeyboardHooks(); _hooks.OnKeyPressed += OnHookedKeyPressed; _hooks.OnKeyReleased += OnHookedKeyReleased; _hooks.HookKeyboard(); HeightBarOnly = 87; HeightTotal = Height; HideResultsPane(); ResetLocation(); QueryHandlers.Add(typeof(CommandQueryHandler), new CommandQueryHandler(this)); QueryHandlers.Add(typeof(SystemQueryHandler), new SystemQueryHandler(this)); QueryHandlers.Add(typeof(WebQueryHandler), new WebQueryHandler(this)); Log.ReportMemoryUsage(); foreach (KeyValuePair <Type, QueryHandler> qHandlers in QueryHandlers) { qHandlers.Value.OnQueryEnd += (results, query) => { _lastQuery = query; }; qHandlers.Value.OnScanComplete += () => { FrameLoadResults.Visibility = Visibility.Hidden; Query(TextBoxSearchBar.Text.ToLower()); }; qHandlers.Value.Scan(); } _queryTimer = new DispatcherTimer(); _queryTimer.Interval = new TimeSpan(0, 0, 0, 0, MIN_TIME_BETWEEN_QUERIES_MS); _queryTimer.Tick += (sender, args) => { if (_textChangedRecently) { _textChangedRecently = false; if (_lastQuery != TextBoxSearchBar.Text) { Query(TextBoxSearchBar.Text.ToLower()); } } }; _queryTimer.Start(); _previewer = new Previewer(PreviewGrid, PreviewImage, PreviewName, PreviewDesc); ListBoxResults.SelectionChanged += (sender, args) => { if (ListBoxResults.SelectedIndex >= 0) { UIResultItem item = (UIResultItem)ListBoxResults.SelectedItem; if (item != null) { _previewer.PreviewFromQueryResultItem(item); } else { Log.Error("Selected item is null"); } } }; }
protected override bool OnConfirmed(UIResultItem result) { return(true); }