public void Execute(InterpreterItem item, Keys modifiers) { string command = item.Desciption; bool test = true; try { test = _mutex.WaitOne(0, true); } catch { } if (test) { if ((modifiers & Keys.Shift) == Keys.Shift) { command = FileSearcher.GetItemFolder(command); } try { ProcessStartInfo info = new ProcessStartInfo(command); info.UseShellExecute = true; info.ErrorDialog = true; System.Diagnostics.Process.Start(info); info = null; } catch (Exception e) { MessageBox.Show(e.Message); } _mutex.ReleaseMutex(); } }
public SuperListBox(MainForm parent) { InitializeComponent(); _parent = parent; Owner = parent; listBox.DrawItem += new DrawItemEventHandler(listBox_DrawItem); listBox.MeasureItem += new MeasureItemEventHandler(listBox_MeasureItem); listBox.MouseMove += new MouseEventHandler(listBox_MouseMove); listBox.MouseEnter += new EventHandler(listBox_MouseEnter); listBox.MouseLeave += new EventHandler(listBox_MouseLeave); listBox.MouseDown += new MouseEventHandler(listBox_MouseDown); _lastItem = null; }
void listBox_MouseMove(object sender, MouseEventArgs e) { int index = listBox.IndexFromPoint(listBox.PointToClient(MousePosition)); if (index != ListBox.NoMatches) { InterpreterItem item = _items[index]; if (item != _lastItem) { _lastItem = item; _tooltip.SetToolTip(listBox, item.Desciption); } } }
public void Execute(string cmd, InterpreterItem item, Keys modifiers) { StoreKeywords(cmd, item); item.Text = ReplaceSpecialKeywords(item.Text, item.CommandTokens); switch (item.Type) { case InterpreterItem.OwnerType.Indexer: _fileIndexer.Execute(item, modifiers); _parent.HideAutomator(); break; case InterpreterItem.OwnerType.FileSystem: _systemBrowser.Execute(item, modifiers); _parent.HideAutomator(); break; case InterpreterItem.OwnerType.Menu: if (_menuEngine.Execute(item, modifiers)) { _parent.HideAutomator(); } break; case InterpreterItem.OwnerType.Plugin: StoreKeywords(cmd, item); foreach (InterpreterPlugin plugin in _plugins) { if (plugin.Name == item.PluginId) { if (plugin.Execute(item, modifiers)) { _parent.HideAutomator(); } break; } } break; default: break; } }
public void Execute(InterpreterItem item, Keys modifiers) { try { string command = item.AutoComplete; if ((modifiers & Keys.Shift) == Keys.Shift) { command = FileSearcher.GetItemFolder(command); } ProcessStartInfo info = new ProcessStartInfo(command); info.UseShellExecute = true; info.ErrorDialog = true; System.Diagnostics.Process.Start(info); info = null; } catch (Exception e) { MessageBox.Show(e.Message); } }
private void StoreKeywords(string cmd, InterpreterItem item) { string str = cmd.ToLower(); //if (str != item.AutoComplete.ToLower()) //{ if (item.Type == InterpreterItem.OwnerType.Indexer) { //if (str != item.Desciption.ToLower()) SettingsManager.Instance.AddLearned(str, item.Type, item.Desciption, item.CommandTokens); } else if (item.Type == InterpreterItem.OwnerType.Menu) { //SettingsManager.Instance.AddLearned(str, ProtectCommand(item.Name)); //SettingsManager.Instance.AddLearned(item.Text, Command.ProtectCommand(item.CommandName)); // StringUtility.ArrayToStr(item.CommandTokens), item.CommandName SettingsManager.Instance.AddLearned(StringUtility.ArrayToStr(item.CommandTokens, false), item.Type, item.Name, item.CommandTokens); } else if (item.Type == InterpreterItem.OwnerType.Plugin) { //InterpreterPlugin p = _plugins.Find(delegate(InterpreterPlugin plugin) { return plugin.Name == item.OwnerId; }); //Command command = p.GetCommand(item); //if (command == null) // SettingsManager.Instance.AddLearned(str, str); //else if (command.FitsPriority(Command.PriorityType.Medium)) // SettingsManager.Instance.AddLearned(item.Text, command.ProtectedName);//SettingsManager.Instance.AddLearned(StringUtility.ArrayToStr(item.CommandTokens), command.ProtectedName); //else if (command.FitsPriority(Command.PriorityType.Low)) // SettingsManager.Instance.AddLearned(item.Text, command.ProtectedName); //else if (command.FitsPriority(Command.PriorityType.Medium)) // SettingsManager.Instance.AddLearned(BuildCommandParameters(item.Text, item.CommandTokens), command.ProtectedName); SettingsManager.Instance.AddLearned(StringUtility.ArrayToStr(item.CommandTokens, false), item.Type, item.Name, item.CommandTokens); } //else //{ // //if (str != item.AutoComplete.ToLower()) // SettingsManager.Instance.AddLearned(str, item.AutoComplete); //} //} }
void listBox_MouseLeave(object sender, EventArgs e) { _tooltip.Active = false; _lastItem = null; }
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); }