/// <summary> /// Add the selected plug-in to the project with a default /// configuration. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnAddPlugIn_Click(object sender, EventArgs e) { string key = (string)lbAvailablePlugIns.SelectedItem; int idx = lbProjectPlugIns.FindStringExact(key); // Currently, no duplicates are allowed if (idx != -1) { lbProjectPlugIns.SelectedIndex = idx; return; } if (PlugInManager.IsSupported(key)) { idx = lbProjectPlugIns.Items.Add(key); if (idx != -1) { currentConfigs.Add(key, true, null); lbProjectPlugIns.SelectedIndex = idx; lbProjectPlugIns.SetItemChecked(idx, true); btnConfigure.Enabled = btnDelete.Enabled = true; currentConfigs.OnDictionaryChanged(new ListChangedEventArgs( ListChangedType.ItemAdded, -1)); } } else { MessageBox.Show("The selected plug-in's version is not " + "compatible with this version of the help file builder " + "and cannot be used.", Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add the selected plug-in to the project with a default configuration /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnAddPlugIn_Click(object sender, RoutedEventArgs e) { string key = (string)lbAvailablePlugIns.SelectedItem; var match = lbProjectPlugIns.Items.Cast <PlugInConfig>().FirstOrDefault(c => c.Name == key); if (availablePlugIns != null) { // No duplicates are allowed if (match != null) { lbProjectPlugIns.SelectedIndex = lbProjectPlugIns.Items.IndexOf(match); } else { var plugIn = availablePlugIns.FirstOrDefault(p => p.Metadata.Id == key); if (plugIn != null) { try { var c = currentConfigs.Add(key, true, null); match = new PlugInConfig { Name = key, Configuration = c }; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); MessageBox.Show("Unexpected error attempting to add plug-in: " + ex.Message, Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Error); return; } lbProjectPlugIns.SelectedIndex = lbProjectPlugIns.Items.Add(match); lbProjectPlugIns.Items.Refresh(); btnConfigure.IsEnabled = btnDelete.IsEnabled = true; this.PlugInsModified?.Invoke(this, EventArgs.Empty); // Open the configuration dialog to configure it when first added if needed btnConfigure_Click(sender, e); } } } }
/// <summary> /// Add the selected plug-in to the project with a default configuration /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnAddPlugIn_Click(object sender, EventArgs e) { string key = (string)lbAvailablePlugIns.SelectedItem; int idx = lbProjectPlugIns.FindStringExact(key); if (availablePlugIns != null) { // Currently, no duplicates are allowed if (idx != -1) { lbProjectPlugIns.SelectedIndex = idx; } else { var plugIn = availablePlugIns.FirstOrDefault(p => p.Metadata.Id == key); if (plugIn != null) { idx = lbProjectPlugIns.Items.Add(key); if (idx != -1) { currentConfigs.Add(key, true, null); lbProjectPlugIns.SelectedIndex = idx; lbProjectPlugIns.SetItemChecked(idx, true); btnConfigure.Enabled = btnDelete.Enabled = true; this.IsDirty = true; // Open the configuration dialog to configure it when first added if needed btnConfigure_Click(sender, e); } } } } }