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 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 ?? ""; } }