Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Starter/AboutDialog.cs @ 3736

Last change on this file since 3736 was 3736, checked in by gkronber, 14 years ago

Added about dialog. #893

File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using System.Reflection;
10using System.Diagnostics;
11using HeuristicLab.PluginInfrastructure.Advanced;
12
13namespace HeuristicLab.PluginInfrastructure.Starter {
14  /// <summary>
15  /// Shows product, version and copyright information for HeuristicLab and all plugins.
16  /// </summary>
17  public partial class AboutDialog : Form {
18    /// <summary>
19    /// Creates a new about dialog with all plugins loaded in the current application.
20    /// </summary>
21    public AboutDialog() {
22      InitializeComponent();
23      var curAssembly = this.GetType().Assembly;
24      productTextBox.Text = GetProduct(curAssembly);
25      versionTextBox.Text = GetVersion(curAssembly);
26      copyrightTextBox.Text = GetCopyright(curAssembly);
27      imageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Plugin);
28      pictureBox.Image = HeuristicLab.PluginInfrastructure.Resources.Logo_white;
29      UpdatePluginList(ApplicationManager.Manager.Plugins);
30      ActiveControl = okButton;
31    }
32
33    /// <summary>
34    /// Creates a new about dialog listing all plugins in the <paramref name="plugins"/> enumerable.
35    /// </summary>
36    /// <param name="plugins">Enumerable of plugins that should be listed.</param>
37    public AboutDialog(IEnumerable<IPluginDescription> plugins) : this() {
38      UpdatePluginList(plugins);
39    }
40
41    private void UpdatePluginList(IEnumerable<IPluginDescription> plugins) {
42      pluginListView.Items.Clear();
43      foreach (var plugin in plugins) {
44        ListViewItem pluginItem = CreateListViewItem(plugin);
45        pluginListView.Items.Add(pluginItem);
46      }
47      Util.ResizeColumns(pluginListView.Columns.OfType<ColumnHeader>());
48    }
49
50    private ListViewItem CreateListViewItem(IPluginDescription plugin) {
51      ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
52      item.ImageIndex = 0;
53      return item;
54    }
55
56    private string GetCopyright(Assembly asm) {
57      AssemblyCopyrightAttribute attribute = GetAttribute<AssemblyCopyrightAttribute>(asm);
58      return attribute.Copyright;
59    }
60
61    private string GetVersion(Assembly asm) {
62      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
63      return pluginInfrastructureVersion.FileVersion;
64    }
65
66    private string GetProduct(Assembly asm) {
67      AssemblyProductAttribute attribute = GetAttribute<AssemblyProductAttribute>(asm);
68      return attribute.Product;
69    }
70
71    private T GetAttribute<T>(Assembly asm) {
72      return (T)asm.GetCustomAttributes(typeof(T), false).Single();
73    }
74
75    private void okButton_Click(object sender, EventArgs e) {
76      Close();
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.