Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.PluginInfrastructure/3.3/Starter/AboutDialog.cs @ 13091

Last change on this file since 13091 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Reflection;
26using System.Windows.Forms;
27using HeuristicLab.PluginInfrastructure.Advanced;
28
29namespace HeuristicLab.PluginInfrastructure.Starter {
30  /// <summary>
31  /// Shows product, version and copyright information for HeuristicLab and all plugins.
32  /// </summary>
33  public partial class AboutDialog : Form {
34    /// <summary>
35    /// Creates a new about dialog with all plugins loaded in the current application.
36    /// </summary>
37    public AboutDialog() {
38      InitializeComponent();
39      var curAssembly = this.GetType().Assembly;
40      productTextBox.Text = GetProduct(curAssembly);
41      versionTextBox.Text = GetVersion();
42      copyrightTextBox.Text = GetCopyright(curAssembly);
43      imageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Plugin);
44      pictureBox.Image = HeuristicLab.PluginInfrastructure.Resources.HeuristicLabLogo;
45      licenseTextBox.Text = HeuristicLab.PluginInfrastructure.Resources.LicenseText;
46      UpdatePluginList(ApplicationManager.Manager.Plugins);
47      ActiveControl = okButton;
48    }
49
50    /// <summary>
51    /// Creates a new about dialog listing all plugins in the <paramref name="plugins"/> enumerable.
52    /// </summary>
53    /// <param name="plugins">Enumerable of plugins that should be listed.</param>
54    public AboutDialog(IEnumerable<IPluginDescription> plugins)
55      : this() {
56      UpdatePluginList(plugins);
57    }
58
59    private void UpdatePluginList(IEnumerable<IPluginDescription> plugins) {
60      pluginListView.Items.Clear();
61      foreach (var plugin in plugins) {
62        ListViewItem pluginItem = CreateListViewItem(plugin);
63        pluginListView.Items.Add(pluginItem);
64      }
65      Util.ResizeColumns(pluginListView.Columns.OfType<ColumnHeader>());
66    }
67
68    private ListViewItem CreateListViewItem(IPluginDescription plugin) {
69      ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
70      item.Tag = plugin;
71      item.ImageIndex = 0;
72      return item;
73    }
74
75    private string GetCopyright(Assembly asm) {
76      AssemblyCopyrightAttribute attribute = GetAttribute<AssemblyCopyrightAttribute>(asm);
77      return attribute.Copyright;
78    }
79
80    private string GetVersion() {
81      return AssemblyHelpers.GetFileVersion(GetType().Assembly);
82    }
83
84    private string GetProduct(Assembly asm) {
85      AssemblyProductAttribute attribute = GetAttribute<AssemblyProductAttribute>(asm);
86      return attribute.Product;
87    }
88
89    private T GetAttribute<T>(Assembly asm) {
90      return (T)asm.GetCustomAttributes(typeof(T), false).Single();
91    }
92
93    private void okButton_Click(object sender, EventArgs e) {
94      Close();
95    }
96
97    private void pluginListView_ItemActivate(object sender, EventArgs e) {
98      if (pluginListView.SelectedItems.Count > 0) {
99        PluginView view = new PluginView((IPluginDescription)pluginListView.SelectedItems[0].Tag);
100        view.Show(this);
101      }
102    }
103
104    private void licenseTextBox_LinkClicked(object sender, LinkClickedEventArgs e) {
105      System.Diagnostics.Process.Start(e.LinkText);
106    }
107
108    private void webLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
109      System.Diagnostics.Process.Start(webLinkLabel.Text);
110    }
111
112    private void mailLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
113      System.Diagnostics.Process.Start("mailto:" + mailLinkLabel.Text);
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.