public ListForm(CompareData parent) { InitializeComponent(); _parent = parent; _parent.ItemUpdated = OnItemUpdate; _settings = new AppSettings(); _diffItems = parent.Items.ToList(); // Set Caption string caption = parent.DescriptionA == null || parent.DescriptionB == null ? "Compare Items" : $"Compare {parent.DescriptionA} to {parent.DescriptionB}"; string plural = _diffItems.Count == 1 ? "" : "s"; Text = $"{caption} - {_diffItems.Count:#,0} item{plural}"; // Make sure the comparer exists _comparePath = ConfigurationManager.AppSettings[ComparePathKey]; if (string.IsNullOrWhiteSpace(_comparePath) || !File.Exists(_comparePath)) { throw new FileNotFoundException($@"Cannot file compare app at ""{_comparePath}"""); } // Set menu description if (parent.DescriptionA != null && parent.DescriptionB != null) { menuAOnly.Text = $"&A: {parent.DescriptionA}"; menuBOnly.Text = $"&B: {parent.DescriptionB}"; } }
/// <summary> /// Show Compare Dialog /// </summary> /// <param name="owner">Owner Window</param> /// <param name="items">Items to show in the dialog</param> /// <param name="descriptionA">Optional description of "A Only" items</param> /// <param name="descriptionB">Optional description of "B Only" items</param> /// <param name="nameLabels">Optional column-header names</param> /// <param name="customActionLabels">Optional Action labels</param> /// <param name="customAction">Optional custom action callback</param> /// <param name="checkEnabled">Optional callback to enable/disable custom action</param> public static void Compare(IWin32Window owner, IEnumerable <DiffItem> items, string descriptionA = null, string descriptionB = null, IEnumerable <string> nameLabels = null, IEnumerable <string> customActionLabels = null, Action <string, DiffItem> customAction = null, Func <string, DiffItem, bool> checkEnabled = null) { var cmp = new CompareData(items, descriptionA, descriptionB, nameLabels, customActionLabels, customAction, checkEnabled); using (var frm = new ListForm(cmp)) frm.ShowDialog(owner); }