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 QuickText(QuickText quick_text) { _name = quick_text.Name; _text = quick_text.Text; }
private void okButton_Click(object sender, EventArgs e) { if (nameTextBox.Text == string.Empty) { nameTextBox.Focus(); _tooltip.SetToolTip(nameTextBox, "Error"); _tooltip.Show("You must specify a name.", nameTextBox, 3000); return; } else if (!_edit_mode && _parent.QuickTextNames.Contains(nameTextBox.Text)) { nameTextBox.Focus(); _tooltip.SetToolTip(nameTextBox, "Error"); _tooltip.Show("A quick text with this name alreay exists. Please specify a different one.", nameTextBox, 3000); return; } else if (textBox.Text == string.Empty) { textBox.Focus(); _tooltip.SetToolTip(textBox, "Error"); _tooltip.Show("You must specify a path.", textBox, 3000); return; } _quick_text = new QuickText(nameTextBox.Text, textBox.Text); if (!_edit_mode) { _parent.QuickTextNames.Add(nameTextBox.Text); _parent.QuickTexts.Add(_quick_text); Command new_command = new Command("Insert " + nameTextBox.Text); new_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters) { return(true); })); new_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return("Insert " + _quick_text.Name); })); new_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return("Insert quick text in active window."); })); new_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters) { return("Insert " + _quick_text.Name); })); new_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters) { return(Properties.Resources.insert_small.ToBitmap()); })); new_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(new_command.Name, args, comp)); })); new_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers) { UserContext.Instance.InsertText(_quick_text.Text, true); })); _parent.Commands.Add(new_command); } DialogResult = DialogResult.OK; Close(); }