コード例 #1
0
ファイル: CommandPicker.cs プロジェクト: erisonliang/Blaze
 private void EnginePicker_Load(object sender, EventArgs e)
 {
     _tooltip           = new ToolTip();
     _tooltip.IsBalloon = true;
     //_tooltip.ShowAlways = true;
     _tooltip.Active       = true;
     _tooltip.ToolTipIcon  = ToolTipIcon.Error;
     _tooltip.ToolTipTitle = "Error";
     //_tooltip.AutoPopDelay = 3000;
     _tooltip.InitialDelay = 0;
     //_tooltip.ReshowDelay = 500;
     ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
     if (data.FileList != null && data.FileList.Length > 0)
     {
         string path = data.FileList[data.FileList.Length - 1];
         if (File.Exists(path))
         {
             FileInfo info = new FileInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFileName(info.Name);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
         else if (Directory.Exists(path))
         {
             DirectoryInfo info = new DirectoryInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFolderName(path);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
     }
     if (data.Text != null && data.Text.Trim() != string.Empty)
     {
         string path = data.Text.Trim();
         if (File.Exists(path))
         {
             FileInfo info = new FileInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFileName(info.Name);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
         else if (Directory.Exists(path))
         {
             DirectoryInfo info = new DirectoryInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFolderName(path);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
     }
     data.Dispose();
 }
コード例 #2
0
        public List <InterpreterItem> RetrieveTopItems(string text)
        {
            List <InterpreterItem> ret                  = new List <InterpreterItem>();
            string                   user_text          = text.Trim().ToLower();
            List <string>            assisting_commands = new List <string>();
            List <string>            assisting_plugins  = new List <string>();
            List <InterpreterPlugin> plugins            = new List <InterpreterPlugin>(_plugins);

            plugins.Add(_menuEngine);
            bool filesystem_assisted = false;

            // take care of high priority commands
            foreach (InterpreterPlugin plugin in plugins)
            {
                Command command = plugin.GetAssistingCommand(Command.PriorityType.High, text);
                if (command != null)
                {
                    InterpreterItem item = new InterpreterItem(plugin.GetItemName(command.Name, text, null),
                                                               plugin.GetItemDescription(command.Name, text, null),
                                                               plugin.GetItemAutoComplete(command.Name, text, null),
                                                               plugin.GetItemIcon(command.Name, text, null),
                                                               InterpreterItem.OwnerType.Plugin,
                                                               user_text);
                    item.CommandName   = command.Name;
                    item.CommandTokens = null;
                    item.CommandUsage  = plugin.GetUsage(command.Name, text, null);
                    item.PluginId      = plugin.Name;
                    assisting_commands.Add(plugin.Name);
                    ret.Add(item);
                }
            }

            if (_systemBrowser.IsOwner(user_text))
            {
                //List<string> user_tokens = new List<string>();
                //user_tokens.Add(user_text.ToLower());

                //Dictionary<string, double> distances = new Dictionary<string, double>();
                //Dictionary<string, string[]> displacements = new Dictionary<string, string[]>();
                //List<string> suited_names = new List<string>();
                //List<string> min_names = new List<string>();

                List <string> paths = _systemBrowser.RetrieveItems(user_text);
                //paths.Sort();

                //Dictionary<string, List<string>> keywords = new Dictionary<string, List<string>>();
                //foreach (string s in paths)
                //    keywords.Add(s, new List<string>(new string[] { s.ToLower() }));

                //TextPredictor.Instance.PredictNamesAndDistance(user_text, user_tokens, paths, keywords, ref suited_names, ref distances, ref displacements, false);

                //while (suited_names.Count > 0)
                //{
                //    string min_name = string.Empty;
                //    for (int i = 0; i < suited_names.Count; i++)
                //    {
                //        if (min_name == string.Empty)
                //        {
                //            min_name = suited_names[i];
                //        }
                //        else if (distances[min_name] > distances[suited_names[i]])
                //        {
                //            min_name = suited_names[i];
                //        }
                //    }
                //    if (min_name != string.Empty)
                //    {
                //        min_names.Add(min_name);
                //        suited_names.Remove(min_name);
                //    }
                //}

                foreach (string s in paths)
                {
                    ret.Add(new InterpreterItem(FileNameManipulator.GetFolderName(s),
                                                s,
                                                s,
                                                _systemBrowser.GetItemIcon(s),
                                                InterpreterItem.OwnerType.FileSystem,
                                                user_text));
                }

                // clean up
                //user_tokens = null;
                //distances = null;
                //suited_names = null;
                //min_names = null;
                paths = null;
                //keywords = null;

                filesystem_assisted = true;
            }
            if (!filesystem_assisted)
            {
                List <string> user_tokens      = new List <string>(StringUtility.GenerateKeywords(user_text, true, true));
                int           user_tokens_size = user_tokens.Count;

                Index index = _fileIndexer.RetrieveItems();
                //_commandCache.Update(plugins);
                //index.Merge(_commandCache.Index);
                if (!_fileIndexer.IsCacheMerged)
                {
                    Predictor.Instance.InvalidateCache();
                }
                if (_commandCache.NeedsUpdate() || !_fileIndexer.IsCacheMerged)
                {
                    _commandCache.Update(plugins);
                    index.Merge(_commandCache.Index);
                    _fileIndexer.IsCacheMerged = true;
                }

                Dictionary <IndexItem, List <string> > tokens = null;
                LearnedContent learned_commands = SettingsManager.Instance.GetLearnedContents();
                IndexItem[]    items            = Predictor.Instance.GetBestItems(index, user_text, user_tokens, ref tokens, learned_commands);
                // TODO
                foreach (IndexItem i in items)
                {
                    // take care of medium priority commands
                    string   command_name       = i.Name;
                    string[] item_tokens        = tokens[i].ToArray();
                    bool     assisted_by_plugin = false;
                    foreach (InterpreterPlugin plugin in _plugins)
                    {
                        if (command_name == string.Empty)
                        {
                            continue;
                        }
                        Command command = plugin.GetCommandByName(command_name);
                        if (command != null && command.FitsPriority(Command.PriorityType.Medium) /*&& !assisting_plugins.Contains(plugin.Name)*/ && !assisting_commands.Contains(command_name))
                        {
                            InterpreterItem item = new InterpreterItem(plugin.GetItemName(command_name, text, item_tokens),
                                                                       plugin.GetItemDescription(command_name, text, item_tokens),
                                                                       plugin.GetItemAutoComplete(command_name, text, item_tokens),
                                                                       plugin.GetItemIcon(command_name, text, item_tokens),
                                                                       InterpreterItem.OwnerType.Plugin,
                                                                       user_text);
                            item.CommandName   = command_name;
                            item.CommandTokens = item_tokens;
                            item.CommandUsage  = plugin.GetUsage(command.Name, text, item_tokens);
                            item.PluginId      = plugin.Name;
                            assisting_commands.Add(command_name);
                            ret.Add(item);
                            assisted_by_plugin = true;
                        }
                    }
                    if (!assisted_by_plugin)
                    {
                        if (_menuEngine.IsOwner(i.Name))
                        {
                            InterpreterItem item = new InterpreterItem(command_name,
                                                                       _menuEngine.GetItemDescription(command_name, user_text, item_tokens),
                                                                       command_name,
                                                                       _menuEngine.GetItemIcon(command_name, text, item_tokens),
                                                                       InterpreterItem.OwnerType.Menu,
                                                                       user_text);
                            item.CommandName   = command_name;
                            item.CommandTokens = item_tokens;
                            item.CommandUsage  = _menuEngine.GetUsage(command_name, text, item_tokens);
                            ret.Add(item);
                            item = null;
                        }
                        else
                        {
                            ret.Add(new InterpreterItem(i.Name, i.Path, i.Name, i.GetIcon(), InterpreterItem.OwnerType.Indexer, user_text));
                        }
                    }
                }
            }

            // take care of low priority commands
            foreach (InterpreterPlugin plugin in _plugins)
            {
                Command command = plugin.GetAssistingCommand(Command.PriorityType.Low, text);
                if (command != null /*&& !assisting_plugins.Contains(plugin.Name)*/ && !assisting_commands.Contains(command.Name))
                {
                    InterpreterItem item = new InterpreterItem(plugin.GetItemName(command.Name, text, null),
                                                               plugin.GetItemDescription(command.Name, text, null),
                                                               plugin.GetItemAutoComplete(command.Name, text, null),
                                                               plugin.GetItemIcon(command.Name, text, null),
                                                               InterpreterItem.OwnerType.Plugin,
                                                               user_text);
                    item.CommandName   = command.Name;
                    item.CommandTokens = null;
                    item.CommandUsage  = plugin.GetUsage(command.Name, text, null);
                    item.PluginId      = plugin.Name;
                    assisting_commands.Add(command.Name);
                    ret.Add(item);
                    item = null;
                }
            }

            //LearnedContent lc = SettingsManager.Instance.GetLearnedContents();
            //int pos = 0;
            //foreach (string token in lc.GetSortedKeywords(user_text))
            //{
            //    int curr_pos = -1;
            //    string distinguisher = lc.Distinguishers[token];
            //    switch (lc.Types[token])
            //    {
            //        case InterpreterItem.OwnerType.Indexer:
            //            curr_pos = ret.FindIndex(delegate(InterpreterItem a)
            //            {
            //                return a.Desciption == distinguisher;
            //            });
            //            break;
            //        default:
            //            curr_pos = ret.FindIndex(delegate(InterpreterItem a)
            //            {
            //                return a.Name == distinguisher;
            //            });
            //            break;
            //    }
            //    if (curr_pos != -1)
            //    {
            //        InterpreterItem to_insert = ret[curr_pos];
            //        ret.RemoveAt(curr_pos);
            //        ret.Insert(0, to_insert);
            //        pos++;
            //    }
            //}

            user_text          = null;
            assisting_commands = null;
            return(ret);
        }