Ignore:
Timestamp:
03/23/10 06:59:41 (12 years ago)
Author:
swagner
Message:

Added content of start page (#936).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs

    r3163 r3202  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.IO;
     25using System.Linq;
     26using System.Reflection;
     27using System.Windows.Forms;
     28using HeuristicLab.Core;
    2329using HeuristicLab.MainForm;
    24 using HeuristicLab.MainForm.WindowsForms;
     30using HeuristicLab.Persistence.Default.Xml;
    2531
    2632namespace HeuristicLab.Optimizer {
    2733  [View("Start Page")]
    28   public partial class StartPage : View {
     34  public partial class StartPage : HeuristicLab.MainForm.WindowsForms.View {
     35    private List<INamedItem> samples;
     36
    2937    public StartPage() {
    3038      InitializeComponent();
     
    3442    protected override void OnInitialized(EventArgs e) {
    3543      base.OnInitialized(e);
     44      Assembly assembly = Assembly.GetExecutingAssembly();
     45      AssemblyFileVersionAttribute version = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
     46                                             Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
     47      titleLabel.Text = "HeuristicLab Optimizer";
     48      if (version != null) titleLabel.Text += " " + version.Version;
     49
     50      try {
     51        using (Stream stream = assembly.GetManifestResourceStream(typeof(StartPage), "Documents.FirstSteps.rtf"))
     52          firstStepsRichTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
     53      }
     54      catch (Exception) { }
     55
     56      samples = new List<INamedItem>();
     57      string path = Path.GetTempFileName();
     58      foreach (string name in assembly.GetManifestResourceNames()) {
     59        if (name.EndsWith(".hl")) {
     60          try {
     61            using (Stream stream = assembly.GetManifestResourceStream(name)) {
     62              WriteStreamToTempFile(stream, path);
     63              IItem item = XmlParser.Deserialize<IItem>(path);
     64              if (item is INamedItem) samples.Add((INamedItem)item);
     65            }
     66          }
     67          catch (Exception) { }
     68        }
     69      }
     70      foreach (INamedItem sample in samples) {
     71        ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description });
     72        item.ToolTipText = sample.ItemName + " (" + sample.ItemDescription + ")";
     73        samplesListView.SmallImageList.Images.Add(sample.ItemImage);
     74        item.ImageIndex = samplesListView.SmallImageList.Images.Count - 1;
     75        item.Tag = sample;
     76        samplesListView.Items.Add(item);
     77      }
     78      samplesListView.Enabled = samplesListView.Items.Count > 0;
     79      if (samplesListView.Items.Count > 0) {
     80        for (int i = 0; i < samplesListView.Columns.Count; i++)
     81          samplesListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     82      }
     83
    3684      showStartPageCheckBox.Checked = Properties.Settings.Default.ShowStartPage;
     85    }
     86
     87    private void firstStepsRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e) {
     88      System.Diagnostics.Process.Start(e.LinkText);
     89    }
     90
     91    private void samplesListView_DoubleClick(object sender, EventArgs e) {
     92      if (samplesListView.SelectedItems.Count == 1)
     93        MainFormManager.CreateDefaultView(((IItem)samplesListView.SelectedItems[0].Tag).Clone()).Show();
    3794    }
    3895
     
    4198      Properties.Settings.Default.Save();
    4299    }
     100
     101    #region Helpers
     102    private void WriteStreamToTempFile(Stream stream, string path) {
     103      using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {
     104        int cnt = 0;
     105        byte[] buffer = new byte[32 * 1024];
     106        while ((cnt = stream.Read(buffer, 0, buffer.Length)) != 0)
     107          output.Write(buffer, 0, cnt);
     108      }
     109    }
     110    #endregion
    43111  }
    44112}
Note: See TracChangeset for help on using the changeset viewer.