Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3298


Ignore:
Timestamp:
04/11/10 03:16:07 (15 years ago)
Author:
swagner
Message:

Implemented clipboard control (#965).

Location:
trunk/sources
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.Designer.cs

    r3292 r3298  
    2121
    2222namespace HeuristicLab.Core.Views {
    23   partial class Clipboard {
     23  partial class Clipboard<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    3333    protected override void Dispose(bool disposing) {
    3434      if (disposing) {
     35        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    3536        if (components != null) components.Dispose();
    3637      }
     
    4546    /// </summary>
    4647    private void InitializeComponent() {
     48      this.components = new System.ComponentModel.Container();
     49      this.listView = new System.Windows.Forms.ListView();
     50      this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
     51      this.imageList = new System.Windows.Forms.ImageList(this.components);
     52      this.infoPanel = new System.Windows.Forms.Panel();
     53      this.progressBar = new System.Windows.Forms.ProgressBar();
     54      this.infoLabel = new System.Windows.Forms.Label();
     55      this.sortDescendingButton = new System.Windows.Forms.Button();
     56      this.sortAscendingButton = new System.Windows.Forms.Button();
     57      this.removeButton = new System.Windows.Forms.Button();
     58      this.addButton = new System.Windows.Forms.Button();
     59      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     60      this.saveButton = new System.Windows.Forms.Button();
     61      this.infoPanel.SuspendLayout();
    4762      this.SuspendLayout();
     63      //
     64      // listView
     65      //
     66      this.listView.AllowDrop = true;
     67      this.listView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     68                  | System.Windows.Forms.AnchorStyles.Left)
     69                  | System.Windows.Forms.AnchorStyles.Right)));
     70      this.listView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
     71            this.columnHeader1});
     72      this.listView.FullRowSelect = true;
     73      this.listView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
     74      this.listView.HideSelection = false;
     75      this.listView.Location = new System.Drawing.Point(0, 30);
     76      this.listView.Name = "listView";
     77      this.listView.ShowItemToolTips = true;
     78      this.listView.Size = new System.Drawing.Size(179, 432);
     79      this.listView.SmallImageList = this.imageList;
     80      this.listView.Sorting = System.Windows.Forms.SortOrder.Ascending;
     81      this.listView.TabIndex = 0;
     82      this.listView.UseCompatibleStateImageBehavior = false;
     83      this.listView.View = System.Windows.Forms.View.Details;
     84      this.listView.SelectedIndexChanged += new System.EventHandler(this.listView_SelectedIndexChanged);
     85      this.listView.SizeChanged += new System.EventHandler(this.listView_SizeChanged);
     86      this.listView.DoubleClick += new System.EventHandler(this.listView_DoubleClick);
     87      this.listView.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView_DragDrop);
     88      this.listView.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView_DragEnterOver);
     89      this.listView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listView_KeyDown);
     90      this.listView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.listView_ItemDrag);
     91      this.listView.DragOver += new System.Windows.Forms.DragEventHandler(this.listView_DragEnterOver);
     92      //
     93      // imageList
     94      //
     95      this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
     96      this.imageList.ImageSize = new System.Drawing.Size(16, 16);
     97      this.imageList.TransparentColor = System.Drawing.Color.Transparent;
     98      //
     99      // infoPanel
     100      //
     101      this.infoPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
     102      this.infoPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     103      this.infoPanel.Controls.Add(this.progressBar);
     104      this.infoPanel.Controls.Add(this.infoLabel);
     105      this.infoPanel.Enabled = false;
     106      this.infoPanel.Location = new System.Drawing.Point(13, 202);
     107      this.infoPanel.Name = "infoPanel";
     108      this.infoPanel.Size = new System.Drawing.Size(154, 59);
     109      this.infoPanel.TabIndex = 6;
     110      //
     111      // progressBar
     112      //
     113      this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
     114      this.progressBar.Location = new System.Drawing.Point(3, 30);
     115      this.progressBar.Name = "progressBar";
     116      this.progressBar.Size = new System.Drawing.Size(146, 23);
     117      this.progressBar.Step = 1;
     118      this.progressBar.TabIndex = 1;
     119      //
     120      // infoLabel
     121      //
     122      this.infoLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
     123      this.infoLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     124      this.infoLabel.Location = new System.Drawing.Point(3, 4);
     125      this.infoLabel.Name = "infoLabel";
     126      this.infoLabel.Size = new System.Drawing.Size(146, 23);
     127      this.infoLabel.TabIndex = 0;
     128      this.infoLabel.Text = "Loading ...";
     129      this.infoLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
     130      //
     131      // sortDescendingButton
     132      //
     133      this.sortDescendingButton.Enabled = false;
     134      this.sortDescendingButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.SortUp;
     135      this.sortDescendingButton.Location = new System.Drawing.Point(30, 0);
     136      this.sortDescendingButton.Name = "sortDescendingButton";
     137      this.sortDescendingButton.Size = new System.Drawing.Size(24, 24);
     138      this.sortDescendingButton.TabIndex = 2;
     139      this.toolTip.SetToolTip(this.sortDescendingButton, "Sort Descending");
     140      this.sortDescendingButton.UseVisualStyleBackColor = true;
     141      this.sortDescendingButton.Click += new System.EventHandler(this.sortDescendingButton_Click);
     142      //
     143      // sortAscendingButton
     144      //
     145      this.sortAscendingButton.Enabled = false;
     146      this.sortAscendingButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Sort;
     147      this.sortAscendingButton.Location = new System.Drawing.Point(60, 0);
     148      this.sortAscendingButton.Name = "sortAscendingButton";
     149      this.sortAscendingButton.Size = new System.Drawing.Size(24, 24);
     150      this.sortAscendingButton.TabIndex = 3;
     151      this.toolTip.SetToolTip(this.sortAscendingButton, "Sort Ascending");
     152      this.sortAscendingButton.UseVisualStyleBackColor = true;
     153      this.sortAscendingButton.Click += new System.EventHandler(this.sortAscendingButton_Click);
     154      //
     155      // removeButton
     156      //
     157      this.removeButton.Enabled = false;
     158      this.removeButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;
     159      this.removeButton.Location = new System.Drawing.Point(90, 0);
     160      this.removeButton.Name = "removeButton";
     161      this.removeButton.Size = new System.Drawing.Size(24, 24);
     162      this.removeButton.TabIndex = 4;
     163      this.toolTip.SetToolTip(this.removeButton, "Remove Item");
     164      this.removeButton.UseVisualStyleBackColor = true;
     165      this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
     166      //
     167      // addButton
     168      //
     169      this.addButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;
     170      this.addButton.Location = new System.Drawing.Point(0, 0);
     171      this.addButton.Name = "addButton";
     172      this.addButton.Size = new System.Drawing.Size(24, 24);
     173      this.addButton.TabIndex = 1;
     174      this.toolTip.SetToolTip(this.addButton, "Add Item");
     175      this.addButton.UseVisualStyleBackColor = true;
     176      this.addButton.Click += new System.EventHandler(this.addButton_Click);
     177      //
     178      // saveButton
     179      //
     180      this.saveButton.Enabled = false;
     181      this.saveButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Save;
     182      this.saveButton.Location = new System.Drawing.Point(120, 0);
     183      this.saveButton.Name = "saveButton";
     184      this.saveButton.Size = new System.Drawing.Size(24, 24);
     185      this.saveButton.TabIndex = 5;
     186      this.toolTip.SetToolTip(this.saveButton, "Save All Items");
     187      this.saveButton.UseVisualStyleBackColor = true;
     188      this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
    48189      //
    49190      // Clipboard
     
    52193      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    53194      this.Caption = "Clipboard";
     195      this.Controls.Add(this.sortDescendingButton);
     196      this.Controls.Add(this.sortAscendingButton);
     197      this.Controls.Add(this.saveButton);
     198      this.Controls.Add(this.removeButton);
     199      this.Controls.Add(this.addButton);
     200      this.Controls.Add(this.infoPanel);
     201      this.Controls.Add(this.listView);
    54202      this.Name = "Clipboard";
    55       this.Size = new System.Drawing.Size(316, 296);
     203      this.Size = new System.Drawing.Size(179, 462);
     204      this.infoPanel.ResumeLayout(false);
    56205      this.ResumeLayout(false);
    57206
     
    59208
    60209    #endregion
     210
     211    private System.Windows.Forms.ListView listView;
     212    private System.Windows.Forms.Panel infoPanel;
     213    private System.Windows.Forms.ProgressBar progressBar;
     214    private System.Windows.Forms.Label infoLabel;
     215    private System.Windows.Forms.ImageList imageList;
     216    private System.Windows.Forms.Button sortDescendingButton;
     217    private System.Windows.Forms.Button sortAscendingButton;
     218    private System.Windows.Forms.Button removeButton;
     219    private System.Windows.Forms.Button addButton;
     220    private System.Windows.Forms.ColumnHeader columnHeader1;
     221    private System.Windows.Forms.ToolTip toolTip;
     222    private System.Windows.Forms.Button saveButton;
    61223
    62224  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.cs

    r3292 r3298  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.IO;
     25using System.Linq;
     26using System.Threading;
    2327using System.Windows.Forms;
    2428using HeuristicLab.MainForm;
     29using HeuristicLab.Persistence.Default.Xml;
    2530
    2631namespace HeuristicLab.Core.Views {
    2732  [View("Clipboard")]
    28   public partial class Clipboard : HeuristicLab.MainForm.WindowsForms.View {
     33  public sealed partial class Clipboard<T> : HeuristicLab.MainForm.WindowsForms.View where T : class, IItem {
     34    private TypeSelectorDialog typeSelectorDialog;
     35    private Dictionary<T, ListViewItem> itemListViewItemTable;
     36
     37    private string itemsPath;
     38    public string ItemsPath {
     39      get { return itemsPath; }
     40      private set {
     41        if (string.IsNullOrEmpty(value)) throw new ArgumentException(string.Format("Invalid items path \"{0}\".", value));
     42        itemsPath = value;
     43        try {
     44          if (!Directory.Exists(itemsPath)) {
     45            Directory.CreateDirectory(itemsPath);
     46            // directory creation might take some time -> wait until it is definitively created
     47            while (!Directory.Exists(itemsPath)) {
     48              Thread.Sleep(100);
     49              Directory.CreateDirectory(itemsPath);
     50            }
     51          }
     52        }
     53        catch (Exception ex) {
     54          throw new ArgumentException(string.Format("Invalid items path \"{0}\".", itemsPath), ex);
     55        }
     56      }
     57    }
     58
    2959    public Clipboard() {
    3060      InitializeComponent();
     61      ItemsPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
     62                  Path.DirectorySeparatorChar + "HeuristicLab" + Path.DirectorySeparatorChar + "Clipboard";
     63      itemListViewItemTable = new Dictionary<T, ListViewItem>();
     64    }
     65    public Clipboard(string itemsPath) {
     66      InitializeComponent();
     67      ItemsPath = itemsPath;
     68      itemListViewItemTable = new Dictionary<T, ListViewItem>();
    3169    }
    3270
    3371    protected override void OnInitialized(EventArgs e) {
    3472      base.OnInitialized(e);
     73      Enabled = false;
     74      infoLabel.Text = "Loading ...";
     75      progressBar.Value = 0;
     76      infoPanel.Visible = true;
     77      ThreadPool.QueueUserWorkItem(new WaitCallback(LoadItems));
    3578    }
    3679    protected override void OnClosing(FormClosingEventArgs e) {
     
    4184      }
    4285    }
     86
     87    public void AddItem(T item) {
     88      if (InvokeRequired)
     89        Invoke(new Action<T>(AddItem), item);
     90      else {
     91        if (!itemListViewItemTable.ContainsKey(item)) {
     92          if (!listView.SmallImageList.Images.ContainsKey(item.GetType().FullName))
     93            listView.SmallImageList.Images.Add(item.GetType().FullName, item.ItemImage);
     94
     95          ListViewItem listViewItem = new ListViewItem(item.ToString());
     96          listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
     97          listViewItem.ImageIndex = listView.SmallImageList.Images.IndexOfKey(item.GetType().FullName);
     98          listViewItem.Tag = item;
     99          listView.Items.Add(listViewItem);
     100          itemListViewItemTable.Add(item, listViewItem);
     101          item.ToStringChanged += new EventHandler(Item_ToStringChanged);
     102          sortAscendingButton.Enabled = sortDescendingButton.Enabled = listView.Items.Count > 1;
     103          saveButton.Enabled = listView.Items.Count > 0;
     104        }
     105      }
     106    }
     107    private void RemoveItem(T item) {
     108      if (InvokeRequired)
     109        Invoke(new Action<T>(RemoveItem), item);
     110      else {
     111        if (itemListViewItemTable.ContainsKey(item)) {
     112          item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     113          itemListViewItemTable[item].Remove();
     114          itemListViewItemTable.Remove(item);
     115          sortAscendingButton.Enabled = sortDescendingButton.Enabled = listView.Items.Count > 1;
     116          saveButton.Enabled = listView.Items.Count > 0;
     117        }
     118      }
     119    }
     120    private void Save() {
     121      if (InvokeRequired)
     122        Invoke(new Action(Save));
     123      else {
     124        Enabled = false;
     125        infoLabel.Text = "Saving ...";
     126        progressBar.Value = 0;
     127        infoPanel.Visible = true;
     128        ThreadPool.QueueUserWorkItem(new WaitCallback(SaveItems));
     129      }
     130    }
     131
     132    #region Loading/Saving Items
     133    private void LoadItems(object state) {
     134      string[] items = Directory.GetFiles(ItemsPath);
     135      foreach (string filename in items) {
     136        try {
     137          T item = XmlParser.Deserialize<T>(filename);
     138          OnItemLoaded(item, progressBar.Maximum / items.Length);
     139        }
     140        catch (Exception) { }
     141      }
     142      OnAllItemsLoaded();
     143    }
     144    private void OnItemLoaded(T item, int progress) {
     145      if (InvokeRequired)
     146        Invoke(new Action<T, int>(OnItemLoaded), item, progress);
     147      else {
     148        AddItem(item);
     149        progressBar.Value += progress;
     150      }
     151    }
     152    private void OnAllItemsLoaded() {
     153      if (InvokeRequired)
     154        Invoke(new Action(OnAllItemsLoaded));
     155      else {
     156        Enabled = true;
     157        if (listView.Items.Count > 0) {
     158          for (int i = 0; i < listView.Columns.Count; i++)
     159            listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     160        }
     161        infoPanel.Visible = false;
     162      }
     163    }
     164    private void SaveItems(object param) {
     165      Directory.Delete(ItemsPath, true);
     166      Directory.CreateDirectory(ItemsPath);
     167      // directory creation might take some time -> wait until it is definitively created
     168      while (!Directory.Exists(ItemsPath)) {
     169        Thread.Sleep(100);
     170        Directory.CreateDirectory(ItemsPath);
     171      }
     172
     173      int i = 0;
     174      T[] items = itemListViewItemTable.Keys.ToArray();
     175      foreach (T item in items) {
     176        try {
     177          i++;
     178          XmlGenerator.Serialize(item, ItemsPath + Path.DirectorySeparatorChar + i.ToString("00000000") + ".hl", 9);
     179          OnItemSaved(item, progressBar.Maximum / listView.Items.Count);
     180        }
     181        catch (Exception) { }
     182      }
     183      OnAllItemsSaved();
     184    }
     185    private void OnItemSaved(T item, int progress) {
     186      if (item != null) {
     187        if (InvokeRequired)
     188          Invoke(new Action<T, int>(OnItemLoaded), item, progress);
     189        else
     190          progressBar.Value += progress;
     191      }
     192    }
     193    private void OnAllItemsSaved() {
     194      if (InvokeRequired)
     195        Invoke(new Action(OnAllItemsLoaded));
     196      else {
     197        Enabled = true;
     198        infoPanel.Visible = false;
     199      }
     200    }
     201    #endregion
     202
     203    #region ListView Events
     204    private void listView_SelectedIndexChanged(object sender, EventArgs e) {
     205      removeButton.Enabled = listView.SelectedItems.Count > 0;
     206    }
     207    private void listView_SizeChanged(object sender, EventArgs e) {
     208      if (listView.Columns.Count > 0)
     209        listView.Columns[0].Width = Math.Max(0, listView.Width - 25);
     210    }
     211    private void listView_KeyDown(object sender, KeyEventArgs e) {
     212      if (e.KeyCode == Keys.Delete) {
     213        if (listView.SelectedItems.Count > 0) {
     214          foreach (ListViewItem item in listView.SelectedItems)
     215            RemoveItem((T)item.Tag);
     216        }
     217      }
     218    }
     219    private void listView_DoubleClick(object sender, EventArgs e) {
     220      if (listView.SelectedItems.Count == 1) {
     221        T item = (T)listView.SelectedItems[0].Tag;
     222        IView view = MainFormManager.CreateDefaultView(item);
     223        if (view != null) view.Show();
     224      }
     225    }
     226    private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
     227      ListViewItem listViewItem = (ListViewItem)e.Item;
     228      T item = (T)listViewItem.Tag;
     229      DataObject data = new DataObject();
     230      data.SetData("Type", item.GetType());
     231      data.SetData("Value", item);
     232      DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     233      if ((result & DragDropEffects.Move) == DragDropEffects.Move)
     234        RemoveItem(item);
     235    }
     236    private void listView_DragEnterOver(object sender, DragEventArgs e) {
     237      e.Effect = DragDropEffects.None;
     238      Type type = e.Data.GetData("Type") as Type;
     239      T item = e.Data.GetData("Value") as T;
     240      if ((type != null) && (item != null)) {
     241        if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy;  // CTRL key
     242        else if (((e.KeyState & 4) == 4) && !itemListViewItemTable.ContainsKey(item)) e.Effect = DragDropEffects.Move;  // SHIFT key
     243        else if (((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) && !itemListViewItemTable.ContainsKey(item)) e.Effect = DragDropEffects.Link;
     244        else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
     245        else if (((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) && !itemListViewItemTable.ContainsKey(item)) e.Effect = DragDropEffects.Move;
     246      }
     247    }
     248    private void listView_DragDrop(object sender, DragEventArgs e) {
     249      if (e.Effect != DragDropEffects.None) {
     250        T item = e.Data.GetData("Value") as T;
     251        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
     252        AddItem(item);
     253      }
     254    }
     255    #endregion
     256
     257    #region Button Events
     258    private void addButton_Click(object sender, EventArgs e) {
     259      if (typeSelectorDialog == null) {
     260        typeSelectorDialog = new TypeSelectorDialog();
     261        typeSelectorDialog.Caption = "Select Item";
     262        typeSelectorDialog.TypeSelector.Caption = "Available Items";
     263        typeSelectorDialog.TypeSelector.Configure(typeof(T), false, false);
     264      }
     265
     266      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
     267        AddItem((T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType());
     268    }
     269    private void sortAscendingButton_Click(object sender, EventArgs e) {
     270      listView.Sorting = SortOrder.None;
     271      listView.Sorting = SortOrder.Ascending;
     272    }
     273    private void sortDescendingButton_Click(object sender, EventArgs e) {
     274      listView.Sorting = SortOrder.None;
     275      listView.Sorting = SortOrder.Descending;
     276    }
     277    private void removeButton_Click(object sender, EventArgs e) {
     278      if (listView.SelectedItems.Count > 0) {
     279        foreach (ListViewItem item in listView.SelectedItems)
     280          RemoveItem((T)item.Tag);
     281      }
     282    }
     283    private void saveButton_Click(object sender, EventArgs e) {
     284      Save();
     285    }
     286    #endregion
     287
     288    #region Item Events
     289    private void Item_ToStringChanged(object sender, EventArgs e) {
     290      if (InvokeRequired)
     291        Invoke(new EventHandler(Item_ToStringChanged), sender, e);
     292      else {
     293        T item = (T)sender;
     294        itemListViewItemTable[item].Text = item.ToString();
     295        listView.Sort();
     296      }
     297    }
     298    #endregion
    43299  }
    44300}
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r3228 r3298  
    268268    #region Helpers
    269269    protected virtual void SortItemsListView(SortOrder sortOrder) {
     270      itemsListView.Sorting = SortOrder.None;
    270271      itemsListView.Sorting = sortOrder;
    271       itemsListView.Sort();
    272272      itemsListView.Sorting = SortOrder.None;
    273273    }
  • trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj

    r3292 r3298  
    8888    <Compile Include="FileManager.cs" />
    8989    <Compile Include="MenuItems\ClipboardMenuItem.cs" />
     90    <Compile Include="MenuItems\CopyToClipboardMenuItem.cs" />
    9091    <Compile Include="MenuItems\StartPageMenuItem.cs" />
    9192    <Compile Include="Properties\Settings.Designer.cs">
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/ClipboardMenuItem.cs

    r3292 r3298  
    2424using System.Linq;
    2525using System.Windows.Forms;
     26using HeuristicLab.Core;
    2627using HeuristicLab.Core.Views;
    2728using HeuristicLab.MainForm;
     
    3839    }
    3940    public override int Position {
    40       get { return 2200; }
     41      get { return 3200; }
    4142    }
    4243
     
    5354
    5455    private void MainForm_ViewShown(object sender, ViewShownEventArgs e) {
    55       if ((e.View is HeuristicLab.Core.Views.Clipboard) && (menuItem != null)) {
     56      if ((e.View is Clipboard<IItem>) && (menuItem != null)) {
    5657        menuItem.Checked = true;
    5758        Properties.Settings.Default.ShowClipboard = true;
     
    6061    }
    6162    private void MainForm_ViewHidden(object sender, ViewEventArgs e) {
    62       if ((e.View is HeuristicLab.Core.Views.Clipboard) && (menuItem != null)) {
     63      if ((e.View is Clipboard<IItem>) && (menuItem != null)) {
    6364        menuItem.Checked = false;
    6465        Properties.Settings.Default.ShowClipboard = false;
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/OperatorsMenuItem.cs

    r3292 r3298  
    3838    }
    3939    public override int Position {
    40       get { return 2300; }
     40      get { return 3300; }
    4141    }
    4242
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/StartPageMenuItem.cs

    r3291 r3298  
    3838    }
    3939    public override int Position {
    40       get { return 2100; }
     40      get { return 3100; }
    4141    }
    4242
  • trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerMainForm.cs

    r3292 r3298  
    2424using System.Reflection;
    2525using System.Windows.Forms;
     26using HeuristicLab.Core;
    2627using HeuristicLab.Core.Views;
    2728using HeuristicLab.MainForm;
     
    3031namespace HeuristicLab.Optimizer {
    3132  internal partial class OptimizerMainForm : DockingMainForm {
    32     private HeuristicLab.Core.Views.Clipboard clipboard;
    33     public HeuristicLab.Core.Views.Clipboard Clipboard {
     33    private Clipboard<IItem> clipboard;
     34    public Clipboard<IItem> Clipboard {
    3435      get { return clipboard; }
    3536    }
     
    5354      ViewClosed += new EventHandler<ViewEventArgs>(FileManager.ViewClosed);
    5455
    55       clipboard = new HeuristicLab.Core.Views.Clipboard();
     56      clipboard = new Clipboard<IItem>();
    5657      clipboard.Dock = DockStyle.Left;
    5758      if (Properties.Settings.Default.ShowClipboard) {
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.Designer.cs

    r3291 r3298  
    164164      this.samplesListView.View = System.Windows.Forms.View.Details;
    165165      this.samplesListView.DoubleClick += new System.EventHandler(this.samplesListView_DoubleClick);
     166      this.samplesListView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.samplesListView_ItemDrag);
    166167      //
    167168      // nameColumnHeader
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs

    r3296 r3298  
    7070      Assembly assembly = Assembly.GetExecutingAssembly();
    7171      var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(".hl"));
     72      int count = samples.Count();
    7273      string path = Path.GetTempFileName();
    73       int progress = loadingProgressBar.Maximum / samples.Count();
    7474
    7575      foreach (string name in samples) {
     
    7777          using (Stream stream = assembly.GetManifestResourceStream(name)) {
    7878            WriteStreamToTempFile(stream, path);
    79             IItem item = XmlParser.Deserialize<IItem>(path);
    80             OnSampleLoaded(item as INamedItem, progress);
     79            INamedItem item = XmlParser.Deserialize<INamedItem>(path);
     80            OnSampleLoaded(item, loadingProgressBar.Maximum / count);
    8181          }
    8282        }
     
    8686    }
    8787    private void OnSampleLoaded(INamedItem sample, int progress) {
    88       if (sample != null) {
    89         if (InvokeRequired)
    90           Invoke(new Action<INamedItem, int>(OnSampleLoaded), sample, progress);
    91         else {
    92           ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description });
    93           item.ToolTipText = sample.ItemName + " (" + sample.ItemDescription + ")";
    94           samplesListView.SmallImageList.Images.Add(sample.ItemImage);
    95           item.ImageIndex = samplesListView.SmallImageList.Images.Count - 1;
    96           item.Tag = sample;
    97           samplesListView.Items.Add(item);
    98           loadingProgressBar.Value += progress;
    99         }
     88      if (InvokeRequired)
     89        Invoke(new Action<INamedItem, int>(OnSampleLoaded), sample, progress);
     90      else {
     91        ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description });
     92        item.ToolTipText = sample.ItemName + ": " + sample.ItemDescription;
     93        samplesListView.SmallImageList.Images.Add(sample.ItemImage);
     94        item.ImageIndex = samplesListView.SmallImageList.Images.Count - 1;
     95        item.Tag = sample;
     96        samplesListView.Items.Add(item);
     97        loadingProgressBar.Value += progress;
    10098      }
    10199    }
     
    121119        MainFormManager.CreateDefaultView(((IItem)samplesListView.SelectedItems[0].Tag).Clone()).Show();
    122120    }
     121    private void samplesListView_ItemDrag(object sender, ItemDragEventArgs e) {
     122      ListViewItem listViewItem = (ListViewItem)e.Item;
     123      IItem item = (IItem)listViewItem.Tag;
     124      DataObject data = new DataObject();
     125      data.SetData("Type", item.GetType());
     126      data.SetData("Value", item);
     127      DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
     128    }
    123129
    124130    private void showStartPageCheckBox_CheckedChanged(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.