Пример #1
0
        protected virtual void Execute(bool openDirectoryOnly, IQuickWindow quickWindow)
        {
            string arg = quickWindow.GetArgument();

            if (arg == null)
            {
                return;
            }

            string[] splits = arg.Split(new char[] { ' ', '\t', '\r', '\n' }, 2);
            string   path   = splits[0];

            if (openDirectoryOnly)
            {
                string tmpPath = Path.GetDirectoryName(path);
                if (!Directory.Exists(tmpPath))
                {
                    tmpPath = MatchCommonShortcutPath(path);
                    if (tmpPath != null)
                    {
                        tmpPath = Path.GetDirectoryName(tmpPath);
                        if (!Directory.Exists(tmpPath))
                        {
                            return;
                        }
                        path = tmpPath;
                    }
                }
            }

            string shellarg = splits.Length > 1 ? splits[1] : null;

            Process.Start(path, shellarg ?? "");
        }
Пример #2
0
        public override bool GetIcon(IQuickWindow quickWindow, out System.Windows.Media.ImageSource icon)
        {
            try
            {
                if (Directory.Exists(m_fullpath))
                {
                    icon = GetRoot().DefaultFolderIcon;
                }
                else
                {
                    string dest = m_fullpath;
                    if (!Path.IsPathRooted(m_fullpath))
                    {
                        dest = MatchCommonShortcutPath(m_fullpath);
                    }

                    var tmp = Icon.ExtractAssociatedIcon(dest);     //获得主线程图标
                    icon = tmp.ToBitmapSource();
                }
                return(true);
            }
            catch { }
            icon = null;
            return(false);
        }
Пример #3
0
        public void KeyDown(IQuickWindow quickWindow, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Tab:
                TabKeyPressed = true;
                CompletePathInTextbox(quickWindow, e);
                return;

            case Key.LeftShift:
            case Key.RightShift:
            case Key.LeftCtrl:
            case Key.RightCtrl:
            case Key.LeftAlt:
            case Key.RightAlt:
                break;

            case Key.Enter:
                // Ctrl+Enter 打开文件夹
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    OpenDirectory(quickWindow);
                }
                break;
            }
        }
Пример #4
0
        public void TextChanged(IQuickWindow quickWindow, TextChangedEventArgs e)
        {
            var arg = quickWindow.GetArgument();

            if (arg == null)
            {
                GetCache().ClearCache();
                quickWindow.ResetMethods();
                return;
            }

            CalcResult(quickWindow);

            QuickCalcItemType[]  types = { QuickCalcItemType.ToDecimal,
                                           QuickCalcItemType.ToHex,
                                           QuickCalcItemType.ToBinary, };
            List <QuickCalcItem> calcItemList = new List <QuickCalcItem>();

            foreach (var type in types)
            {
                QuickCalcItem item = new QuickCalcItem(GetRoot(), type);
                calcItemList.Add(item);
            }
            if (calcItemList.Count > 0)
            {
                quickWindow.ReplaceMethods(calcItemList.ToArray());
            }
        }
Пример #5
0
        private bool Query(IQuickWindow quickWindow)
        {
            bool bInited = TestEverything(quickWindow);

            if (!bInited)
            {
                CurrentDescriptionType = DescriptionType.NotInited;
                quickWindow.Refresh(0);
                return(false);
            }

            QuickEverything.Everything_Reset();
            QuickEverything.Everything_SetMax(MAX_FILE_NUMBER_IN_ONE_QUERY);
            QuickEverything.Everything_SetOffset(GetPage() * MAX_FILE_NUMBER_IN_ONE_QUERY);

            string arg = quickWindow.GetArgument();

            if (arg == null)
            {
                return(false);
            }

            //改善易用性,将/视为\
            arg = arg.Replace('/', '\\');
            SearchOption option = SearchOption.File;
            string       a      = arg.Trim().ToLower();

            if (a.StartsWith("folder:"))
            {
                option = SearchOption.Folder;
            }
            else if (a.StartsWith("all:"))
            {
                option = SearchOption.All;
            }

            string realQueryText = arg;

            if (option == SearchOption.File)
            {
                realQueryText = "file:" + arg;
            }
            else if (option == SearchOption.Folder)
            {
                realQueryText = "folder:" + arg;
            }

            QuickEverything.Everything_SetSearchW(realQueryText);
            QuickEverything.Everything_QueryW(true);
            int count = QuickEverything.Everything_GetNumResults();
            EVERYTHING_RESULT result = (EVERYTHING_RESULT)QuickEverything.Everything_GetLastError();

            if (result == EVERYTHING_RESULT.EVERYTHING_OK && count > 0)
            {
                ReplaceMethods(quickWindow, count);
                return(true);
            }
            CurrentDescriptionType = DescriptionType.NoResult;
            return(false);
        }
Пример #6
0
        private void QueryOnTick(object sender, EventArgs e)
        {
            DispatcherTimer timer       = (DispatcherTimer)sender;
            IQuickWindow    quickWindow = (IQuickWindow)timer.Tag;

            AsyncQuery(quickWindow);
            timer.Stop();
        }
Пример #7
0
 public virtual string GetDescription(IQuickWindow quickWindow)
 {
     if (!GetCache().HasCache())
     {
         return("输入算式进行计算,回车粘贴到剪贴板");
     }
     return(GetCache().GetValue().ToString());
 }
Пример #8
0
 public virtual void KeyDown(IQuickWindow quickWindow, System.Windows.Input.KeyEventArgs e)
 {
     if (quickWindow != null && m_everythingExePath == null)
     {
         m_everythingExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                            quickWindow.GetPluginsPath(),
                                            "3rdparty/everything/everything.exe");
     }
 }
Пример #9
0
 public override void Invoke(object sender, IQuickWindow quickWindow)
 {
     if (m_directoryOpenedToogle)
     {
         m_directoryOpenedToogle = false;
         return;
     }
     Execute(false);
 }
Пример #10
0
 private void AsyncQuery(IQuickWindow quickWindow)
 {
     quickWindow.AsyncInvoke(
         () =>
     {
         Query(quickWindow);
         quickWindow.Refresh(0);
     }
         );
 }
Пример #11
0
 public static IHostBuilder UseWindow <T>(this IHostBuilder builder) where T : IQuickWindow
 {
     builder.ConfigureService(services =>
     {
         IServiceCollection pool = services.GetService(typeof(IServiceCollection)) as IServiceCollection;
         IQuickWindow window     = services.CreateInstance <T>();
         pool.Add(ServiceDescriptor.Singleton <IQuickWindow>(window));
     });
     return(builder);
 }
Пример #12
0
 public virtual DispatcherTimer GetTimer(IQuickWindow quickWindow)
 {
     if (m_timer == null)
     {
         m_timer          = new DispatcherTimer(DispatcherPriority.Normal);
         m_timer.Interval = TimeSpan.FromMilliseconds(COUNT_DOWN_TIMEOUT);
         m_timer.Tick    += QueryOnTick;
         m_timer.Tag      = quickWindow;
     }
     return(m_timer);
 }
Пример #13
0
 public void PageDown(IQuickWindow quickWindow)
 {
     try
     {
         m_method.PageDown(quickWindow);
     }
     catch (Exception ex)
     {
         QuickVitality.UpdateVitality("error in plugin method", m_method.GetName(), "invoking: PageDown() and caused " + ex.Message + Environment.NewLine + ex.StackTrace);
     }
 }
Пример #14
0
 public Host(IServiceProvider services, IServiceCollection pool, IAppBuilder appBuilder, ITerminationNotifier terminationNotifier, ITray tray, IHotKey hotkey, IQuickWindow window)
 {
     this.services            = services;
     this.pool                = pool;
     this.appBuilder          = appBuilder;
     this.terminationNotifier = terminationNotifier;
     this.tray                = tray;
     this.hotkey              = hotkey;
     this.window              = window;
     actions = new ObservableCollection <ActionBase>();
 }
Пример #15
0
 public void TextChanged(IQuickWindow quickWindow, System.Windows.Controls.TextChangedEventArgs e)
 {
     try
     {
         m_method.TextChanged(quickWindow, e);
     }
     catch (Exception ex)
     {
         QuickVitality.UpdateVitality("error in plugin method", m_method.GetName(), "invoking: TextChanged() and caused " + ex.Message + Environment.NewLine + ex.StackTrace);
     }
 }
Пример #16
0
 public void KeyDown(IQuickWindow quickWindow, System.Windows.Input.KeyEventArgs e)
 {
     try
     {
         m_method.KeyDown(quickWindow, e);
     }
     catch (Exception ex)
     {
         QuickVitality.UpdateVitality("error in plugin method", m_method.GetName(), "invoking: KeyDown() and caused " + ex.Message + Environment.NewLine + ex.StackTrace);
     }
 }
Пример #17
0
 public void Invoke(object sender, IQuickWindow quickWindow)
 {
     try
     {
         m_method.Invoke(sender, quickWindow);
     }
     catch (Exception ex)
     {
         QuickVitality.UpdateVitality("error in plugin method", m_method.GetName(), "invoking: Invoke() and caused " + ex.Message + Environment.NewLine + ex.StackTrace);
     }
 }
Пример #18
0
 public string GetDescription(IQuickWindow quickWindow)
 {
     try
     {
         return(m_method.GetDescription(quickWindow));
     }
     catch (Exception ex)
     {
         QuickVitality.UpdateVitality("error in plugin method", m_method.GetName(), "invoking: GetName() and caused " + ex.Message + Environment.NewLine + ex.StackTrace);
         return(null);
     }
 }
Пример #19
0
 public override bool GetIcon(IQuickWindow quickWindow, out System.Windows.Media.ImageSource icon)
 {
     try
     {
         var tmp = Icon.ExtractAssociatedIcon(m_fullpath);     //获得主线程图标
         icon = tmp.ToBitmapSource();
         return(true);
     }
     catch { }
     icon = null;
     return(false);
 }
Пример #20
0
 public bool GetIcon(IQuickWindow quickWindow, out System.Windows.Media.ImageSource icon)
 {
     try
     {
         return(m_method.GetIcon(quickWindow, out icon));
     }
     catch (Exception ex)
     {
         QuickVitality.UpdateVitality("error in plugin method", m_method.GetName(), "invoking: GetIcon() and caused " + ex.Message + Environment.NewLine + ex.StackTrace);
         icon = null;
         return(false);
     }
 }
Пример #21
0
 public override void KeyDown(IQuickWindow quickWindow, System.Windows.Input.KeyEventArgs e)
 {
     switch (e.Key)
     {
     case Key.Enter:
         // Ctrl+Enter 打开文件夹
         if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
         {
             OpenDirectory();
         }
         break;
     }
 }
Пример #22
0
        public virtual string GetDescription(IQuickWindow quickWindow)
        {
            switch (CurrentDescriptionType)
            {
            case DescriptionType.NoResult:
                return(NO_RESULT_DESCRIPTION);

            case DescriptionType.NotInited:
                return(NOT_INITED_YET);

            default:
                return(DEFAULT_DESCRIPTION);
            }
        }
Пример #23
0
        public void TextChanged(IQuickWindow quickWindow, System.Windows.Controls.TextChangedEventArgs e)
        {
            ResetPage();

            var timer = GetTimer(quickWindow);

            timer.Stop();

            var arg = quickWindow.GetArgument();

            if (arg == null)
            {
                quickWindow.ResetMethods();
                CurrentDescriptionType = DescriptionType.Default;
                return;
            }

            timer.Start();
        }
Пример #24
0
        public void TextChanged(IQuickWindow quickWindow, TextChangedEventArgs e)
        {
            if (TabKeyPressed)
            {
                TabKeyPressed = false;
                TextDirty     = false;
            }
            else
            {
                TextDirty = true;
            }

            // 在没有参数传进来的时候,因为已经退出了SubModel
            var arg = quickWindow.GetArgument();

            if (arg == null)
            {
                quickWindow.ResetMethods();
                return;
            }

            List <string> matchedFiles = new List <string>();

            matchedFiles = GetCurrentPathFileNames(arg);

            List <QuickRunItem> runItemList = new List <QuickRunItem>();

            foreach (var r in matchedFiles)
            {
                QuickRunItem item = new QuickRunItem(GetRoot(), Path.GetFileNameWithoutExtension(r), MatchCommonShortcutPath(r) ?? r);
                runItemList.Add(item);
            }

            if (runItemList.Count > 0)
            {
                quickWindow.ReplaceMethods(runItemList.ToArray());
            }
            else
            {
                quickWindow.ResetMethods();
            }
        }
Пример #25
0
        private void CalcResult(IQuickWindow quickWindow)
        {
            QuickCalcScanner calc = new QuickCalcScanner();

            if (quickWindow != null)
            {
                var arg = quickWindow.GetArgument();
                if (arg != null)
                {
                    try
                    {
                        var result = calc.Eval(arg);
                        GetCache().SetValue(result);
                    }
                    catch { }
                    return;
                }
            }
            GetCache().ClearCache();
        }
Пример #26
0
        protected override void Execute(bool openDirectoryOnly, IQuickWindow quickWindow)
        {
            string arg = quickWindow.GetArgument();

            if (arg == null)
            {
                return;
            }

            string[] splits = arg.Split(new char[] { ' ', '\t', '\r', '\n' }, 2);
            string   path   = m_fullpath;

            if (openDirectoryOnly)
            {
                path = Path.GetDirectoryName(m_fullpath);
            }

            string shellarg = splits.Length > 1 ? splits[1] : null;

            Process.Start(path, shellarg ?? "");
        }
Пример #27
0
        private void ReplaceMethods(IQuickWindow quickWindow, int count)
        {
            const int            bufsize      = 260;
            StringBuilder        buf          = new StringBuilder(bufsize);
            List <QuickFindItem> findItemList = new List <QuickFindItem>();

            for (int i = 0; i < count; i++)
            {
                QuickEverything.Everything_GetResultFullPathNameW(i, buf, bufsize);
                EVERYTHING_RESULT result = (EVERYTHING_RESULT)QuickEverything.Everything_GetLastError();
                if (result != EVERYTHING_RESULT.EVERYTHING_OK)
                {
                    continue;
                }

                QuickFindItem item = new QuickFindItem(GetRoot(), buf.ToString());
                findItemList.Add(item);
            }

            quickWindow.ReplaceMethods(findItemList.ToArray());
        }
Пример #28
0
        private bool TestEverything(IQuickWindow quickWindow)
        {
            // 返回引擎是否已经初始化
            QuickEverything.Everything_Reset();
            QuickEverything.Everything_SetMax(1);
            QuickEverything.Everything_SetOffset(0);
            QuickEverything.Everything_SetSearchW("*");
            bool success     = false;
            bool startServer = false;
            int  times       = 0;

            do
            {
                success = QuickEverything.Everything_QueryW(true);
                if (success)
                {
                    quickWindow.UnlockWindow();
                    int count = QuickEverything.Everything_GetNumResults();
                    return(count > 0 ? true : false);
                }
                else
                {
                    quickWindow.LockWindow();
                    if (!startServer)
                    {
                        StartService();
                        startServer = true;
                    }
                    Thread.Sleep(COUNT_DOWN_TIMEOUT);
                    times++;
                    if (times > MAX_TRYING_TIMES)
                    {
                        return(false);
                    }
                }
            } while (!success);
            Debug.Assert(false, "应该在success的时候就返回了");
            return(false);
        }
Пример #29
0
        private void CompletePathInTextbox(IQuickWindow quickWindow, KeyEventArgs e)
        {
            var    modifiers = e.KeyboardDevice.Modifiers;
            string queryPath = quickWindow.GetArgument();

            if (queryPath.Length == 0)
            {
                return;
            }

            if (TextDirty)
            {
                ResultList = GetCurrentPathFileNames(queryPath);
            }

            if (ResultList.Count == 0)
            {
                return;
            }

            if (modifiers != ModifierKeys.Shift)
            {
                AutoSearchIndex = ++AutoSearchIndex % ResultList.Count;
            }
            else if (modifiers == ModifierKeys.Shift)
            {
                AutoSearchIndex = --AutoSearchIndex < 0 ? ResultList.Count - 1 : AutoSearchIndex;
            }

            string content  = quickWindow.GetQueryText();
            string replaced = content.Replace(queryPath, ResultList[AutoSearchIndex]);

            quickWindow.SetQueryText(replaced);
            var textbox = quickWindow.GetQueryTextBox();

            textbox.CaretPosition = textbox.Document.ContentEnd;
        }
Пример #30
0
        private void UpdatePage(IQuickWindow quickWindow, bool isPageDown)
        {
            int backupPage = GetPage();

            if (isPageDown)
            {
                SetPage(GetPage() + 1);
            }
            else
            {
                if (GetPage() > 0)
                {
                    SetPage(GetPage() - 1);
                }
                else
                {
                    return;
                }
            }

            bool success = Query(quickWindow);

            if (!success)
            {
                SetPage(backupPage);
                return;
            }

            if (isPageDown)
            {
                quickWindow.Refresh(0);
            }
            else
            {
                quickWindow.Refresh(MAX_FILE_NUMBER_IN_ONE_QUERY);
            }
        }