private Insertion BuildInsertion(string parameters) { List <string> text = new List <string>(parameters.Split(new string[] { "\"" }, StringSplitOptions.RemoveEmptyEntries)); text.RemoveAll(delegate(string s) { if (s.Trim() == string.Empty) { return(true); } else { return(false); } }); Insertion insertion; if (text.Count >= 2) { insertion = new Insertion(text[0], text[1]); } else if (text.Count == 1) { insertion = new Insertion(text[0]); } else { insertion = new Insertion(); } return(insertion); }
protected override void SetupCommands() { LoadSettings(); // Build the Add command _add_command = new Command("Add New Quick Text", "Add a new quick text."); _add_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(false); })); _add_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_add_command.Name); })); _add_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_add_command.Description); })); _add_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_add_command.Name); })); _add_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(_add_icon.ToBitmap()); })); _add_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters) { List <string> args = new List <string>(); Dictionary <string, bool> comp = new Dictionary <string, bool>(); return(new CommandUsage(_add_command.Name, args, comp)); })); _add_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { QuickTextPicker ep = new QuickTextPicker(this); if (ep.ShowDialog() == DialogResult.OK) { SaveSettings(); } ep.Dispose(); })); Commands.Add(_add_command); // Build the to lower command _to_lower_command = new Command("To Lower", "Convert selected text to lower case."); _to_lower_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(false); })); _to_lower_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_to_lower_command.Name); })); _to_lower_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_to_lower_command.Description); })); _to_lower_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_to_lower_command.Name); })); _to_lower_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(_insert_icon.ToBitmap()); })); _to_lower_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters) { List <string> args = new List <string>(); Dictionary <string, bool> comp = new Dictionary <string, bool>(); return(new CommandUsage(_to_lower_command.Name, args, comp)); })); _to_lower_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { UserContext.Instance.SelectedTextToLower(true); })); Commands.Add(_to_lower_command); // Build the to upper command _to_upper_command = new Command("To Upper", "Convert selected text to upper case."); _to_upper_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(false); })); _to_upper_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_to_upper_command.Name); })); _to_upper_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_to_upper_command.Description); })); _to_upper_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_to_upper_command.Name); })); _to_upper_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(_insert_icon.ToBitmap()); })); _to_upper_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters) { List <string> args = new List <string>(); Dictionary <string, bool> comp = new Dictionary <string, bool>(); return(new CommandUsage(_to_upper_command.Name, args, comp)); })); _to_upper_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { UserContext.Instance.SelectedTextToUpper(true); })); Commands.Add(_to_upper_command); // Build the sort command _sort_command = new Command("Sort Text", "Sort selected text."); _sort_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(false); })); _sort_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_sort_command.Name); })); _sort_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_sort_command.Description); })); _sort_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return(_sort_command.Name); })); _sort_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(_insert_icon.ToBitmap()); })); _sort_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters) { List <string> args = new List <string>(); Dictionary <string, bool> comp = new Dictionary <string, bool>(); return(new CommandUsage(_sort_command.Name, args, comp)); })); _sort_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { UserContext.Instance.SelectedTextSortLines(true); })); Commands.Add(_sort_command); // Build the insert command _insert_command = new Command("Insert"); _insert_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(false); })); _insert_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { Insertion insertion = BuildInsertion(parameters); if (insertion.Text == string.Empty) { return("Insert clipboard..."); } else { return("Insert " + insertion.Text); } })); _insert_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { Insertion insertion = BuildInsertion(parameters); if (insertion.Target == string.Empty) { return("... into top window."); } else { return("... into " + insertion.Target); } })); _insert_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { string auto = _insert_command.Name; Insertion insertion = BuildInsertion(parameters); if (insertion.Text != string.Empty) { auto += " " + insertion.Text; } if (insertion.Target != string.Empty) { auto += " " + insertion.Target; } return(auto); })); _insert_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(_insert_icon.ToBitmap()); })); _insert_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters) { List <string> args = new List <string>(new string[] { "\"text\"", "\"file\"" }); Dictionary <string, bool> comp = new Dictionary <string, bool>(); foreach (string arg in args) { comp.Add(arg, false); } Insertion insertion = BuildInsertion(parameters); if (insertion.Text != string.Empty) { comp["\"text\""] = true; } if (insertion.Target != string.Empty) { comp["\"file\""] = true; } return(new CommandUsage(_insert_command.Name, args, comp)); })); _insert_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { Insertion insertion = BuildInsertion(parameters); string text = insertion.Text; if (text == string.Empty) { ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetClipboardContent(); if (data.Text != null) { text = data.Text; } data.Dispose(); } if (insertion.Target == string.Empty) { UserContext.Instance.InsertText(text, true); } else { StreamWriter writer = new StreamWriter(insertion.Target, true); writer.WriteLine(text); writer.Close(); } })); Commands.Add(_insert_command); // Build user quick text commands foreach (QuickText quick_text in _quick_texts) { QuickText qtext = new QuickText(quick_text); Command cmd = new Command("Insert " + qtext.Name); cmd.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(true); })); cmd.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return("Insert " + qtext.Name); })); cmd.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return("Insert quick text in active window."); })); cmd.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return("Insert " + qtext.Name); })); cmd.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(_insert_icon.ToBitmap()); })); cmd.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters) { List <string> args = new List <string>(); Dictionary <string, bool> comp = new Dictionary <string, bool>(); return(new CommandUsage(cmd.Name, args, comp)); })); cmd.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { UserContext.Instance.InsertText(qtext.Text, true); })); _commands.Add(cmd); } }
public Insertion(Insertion insertion) { _text = insertion.Text; _target = insertion.Target; }