private void tool_selectionCommitted(object sender, EventArgs e) { ComboBox box = (ComboBox)sender; AnkhDiffTool tool = box.SelectedItem as AnkhDiffTool; if (tool != null) { box.DropDownStyle = ComboBoxStyle.DropDownList; box.Tag = tool.ToolTemplate; } else { box.DropDownStyle = ComboBoxStyle.DropDown; if (box.SelectedItem != null) { box.SelectedItem = null; } if (box.Tag is string) { box.Text = (string)box.Tag; } else if (box.Tag is AnkhDiffTool) { box.Text = ((AnkhDiffTool)box.Tag).ToolTemplate; } if (!string.IsNullOrEmpty(box.Text)) { box.SelectionStart = 0; box.SelectionLength = box.Text.Length; } } }
void BrowseCombo(ComboBox box) { AnkhDiffTool tool = box.SelectedItem as AnkhDiffTool; string line; if (tool != null) { line = string.Format("\"{0}\" {1}", tool.Program, tool.Arguments); } else { line = box.Text; } using (ToolArgumentDialog dlg = new ToolArgumentDialog()) { dlg.Value = line; dlg.SetTemplates(Context.GetService <IAnkhDiffHandler>().ArgumentDefinitions); if (DialogResult.OK == dlg.ShowDialog(Context)) { string newValue = dlg.Value; if (!string.IsNullOrEmpty(newValue) && newValue != line) { box.DropDownStyle = ComboBoxStyle.DropDown; box.SelectedItem = null; box.Text = newValue; } } } }
string GetAppTemplate(string appName, DiffToolMode toolMode) { AnkhDiffTool tool = GetAppItem(appName, toolMode); if (tool != null) { return(string.Format("\"{0}\" {1}", tool.Program, tool.Arguments)); } return(null); }
string GetAppPath(string appName, DiffToolMode toolMode) { AnkhDiffTool tool = GetAppItem(appName, toolMode); if (tool != null) { return(tool.Program); } return(null); }
private bool Substitute(string reference, AnkhDiffToolArgs args, DiffToolMode toolMode, out string program, out string arguments) { if (string.IsNullOrEmpty(reference)) { throw new ArgumentNullException("reference"); } else if (args == null) { throw new ArgumentNullException("args"); } // Ok: We received a string with a program and arguments and windows // wants a program and arguments separated. Let's find the program before substituting reference = reference.TrimStart(); program = null; arguments = null; string app; if (!string.IsNullOrEmpty(app = AnkhDiffTool.GetToolNameFromTemplate(reference))) { // We have a predefined template. Just use it AnkhDiffTool tool = GetAppItem(app, toolMode); if (tool == null) { return(false); } else if (!tool.IsAvailable) { return(false); } program = SubstituteArguments(tool.Program, args, toolMode); arguments = SubstituteArguments(tool.Arguments, args, toolMode); return(!String.IsNullOrEmpty(program) && File.Exists(program)); } else if (!SvnTools.TrySplitCommandLine(reference, SubstituteEmpty, out program, out arguments)) { return(false); } program = SubstituteArguments(program, args, toolMode); arguments = SubstituteArguments(arguments, args, toolMode); return(true); }
static string SaveBox(ComboBox box) { if (box == null) { throw new ArgumentNullException("box"); } AnkhDiffTool tool = box.SelectedItem as AnkhDiffTool; if (tool != null) { return(tool.ToolTemplate); } return(box.Text); }
static void LoadBox(ComboBox combo, string value, IEnumerable <AnkhDiffTool> tools) { if (combo == null) { throw new ArgumentNullException("combo"); } combo.DropDownStyle = ComboBoxStyle.DropDown; combo.Items.Clear(); string selectedName = string.IsNullOrEmpty(value) ? null : AnkhDiffTool.GetToolNameFromTemplate(value); bool search = !string.IsNullOrEmpty(selectedName); bool found = false; foreach (AnkhDiffTool tool in tools) { // Items are presorted combo.Items.Add(tool); if (search && string.Equals(tool.Name, selectedName, StringComparison.OrdinalIgnoreCase)) { search = false; found = true; combo.DropDownStyle = ComboBoxStyle.DropDownList; combo.SelectedItem = tool; } } combo.Items.Add(new OtherTool(null)); if (!found) { combo.SelectedItem = null; combo.Text = value ?? ""; } }