Ignore:
Timestamp:
05/11/17 14:03:44 (4 years ago)
Author:
abeham
Message:

#2674: merged 14299,14561 to stable

Location:
stable
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Data.Views

  • stable/HeuristicLab.Data.Views/3.3

  • stable/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.Designer.cs

    r14186 r14968  
    6565      // lengthTextBox
    6666      //
    67       this.lengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    68                   | System.Windows.Forms.AnchorStyles.Right)));
     67      this.lengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     68            | System.Windows.Forms.AnchorStyles.Right)));
    6969      this.lengthTextBox.Location = new System.Drawing.Point(52, 0);
    7070      this.lengthTextBox.Name = "lengthTextBox";
     
    7979      this.dataGridView.AllowUserToAddRows = false;
    8080      this.dataGridView.AllowUserToDeleteRows = false;
    81       this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    82                   | System.Windows.Forms.AnchorStyles.Left)
    83                   | System.Windows.Forms.AnchorStyles.Right)));
    84       this.dataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
     81      this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     82            | System.Windows.Forms.AnchorStyles.Left)
     83            | System.Windows.Forms.AnchorStyles.Right)));
     84      this.dataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.Disable;
    8585      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    8686      this.dataGridView.ColumnHeadersVisible = false;
     
    101101      // StringConvertibleArrayView
    102102      //
    103       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    104103      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    105104      this.Controls.Add(this.dataGridView);
  • stable/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r14186 r14968  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.ComponentModel;
    2425using System.Drawing;
     26using System.Linq;
    2527using System.Text;
    2628using System.Windows.Forms;
     
    199201      }
    200202
     203      var elementNames = Content.ElementNames.ToList();
    201204      for (int i = minRowIndex; i <= maxRowIndex; i++) {
    202205        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    203206        DataGridViewCell cell = dataGridView[column.Index, i];
    204207        if (cell.Selected) {
     208          if (i < elementNames.Count) {
     209            s.Append(elementNames[i]);
     210            s.Append("\t");
     211          } else if (elementNames.Count > 0) {
     212            s.Append("Index " + i);
     213            s.Append("\t");
     214          }
    205215          s.Append(Content.GetValue(i));
    206216          s.Append(Environment.NewLine);
     
    210220    }
    211221    private void PasteValuesToDataGridView() {
    212       string[] values = SplitClipboardString(Clipboard.GetText());
     222      Tuple<string, string>[] values = null;
     223      try {
     224        values = SplitClipboardString(Clipboard.GetText()).ToArray();
     225      } catch (ArgumentException ex) {
     226        MessageBox.Show(this, ex.Message, "Error while parsing clipboard text.", MessageBoxButtons.OK, MessageBoxIcon.Error);
     227        return;
     228      }
    213229      int rowIndex = 0;
    214230      if (dataGridView.CurrentCell != null)
     
    216232
    217233      if (Content.Length < rowIndex + values.Length) Content.Length = rowIndex + values.Length;
    218       for (int row = 0; row < values.Length; row++)
    219         Content.SetValue(values[row], row + rowIndex);
    220     }
    221     private string[] SplitClipboardString(string clipboardText) {
     234      for (int row = 0; row < values.Length; row++) {
     235        Content.SetValue(values[row].Item2, row + rowIndex);
     236      }
     237      if (values.Any(x => !string.IsNullOrEmpty(x.Item1))) {
     238        var elementNames = Content.ElementNames.ToList();
     239        for (int row = 0; row < values.Length; row++) {
     240          if (row + rowIndex < elementNames.Count)
     241            elementNames[row + rowIndex] = values[row].Item1;
     242          else elementNames.Add(values[row].Item1);
     243        }
     244        Content.ElementNames = elementNames;
     245      }
     246    }
     247    private IEnumerable<Tuple<string, string>> SplitClipboardString(string clipboardText) {
    222248      if (clipboardText.EndsWith(Environment.NewLine))
    223249        clipboardText = clipboardText.Remove(clipboardText.Length - Environment.NewLine.Length);  //remove last newline constant
    224       return clipboardText.Split(new string[] { Environment.NewLine, "\t" }, StringSplitOptions.None);
     250
     251      var lines = clipboardText.Split(new [] { Environment.NewLine }, StringSplitOptions.None);
     252      var tabSep = new[] { '\t' };
     253      if (lines.Length > 2) {
     254        // Case 1: Each line contains either "elementName \t value" or just "value" (one or two vertical vectors)
     255        foreach (var l in lines) {
     256          var row = l.Split(tabSep, StringSplitOptions.RemoveEmptyEntries);
     257          if (row.Length > 2) throw new ArgumentException("Clipboard may have either at most two rows or at most two columns.");
     258          if (row.Length == 2) yield return Tuple.Create(row[0], row[1]);
     259          else if (row.Length == 1) yield return Tuple.Create(string.Empty, row[0]);
     260          else yield return Tuple.Create(string.Empty, string.Empty);
     261        }
     262      } else if (lines.Length == 2) {
     263        var firstLine = lines[0].Split(tabSep, StringSplitOptions.None);
     264        var secondLine = lines[1].Split(tabSep, StringSplitOptions.None);
     265        if (firstLine.Length <= 2 && secondLine.Length <= 2) {
     266          // Case 2a: The two lines contain either "elementName \t value" or just "value" (one or two vertical vectors)
     267          yield return firstLine.Length >= 2 ? Tuple.Create(firstLine[0], firstLine[1]) : Tuple.Create(string.Empty, firstLine[0]);
     268          yield return secondLine.Length >= 2 ? Tuple.Create(secondLine[0], secondLine[1]) : Tuple.Create(string.Empty, secondLine[0]);
     269        } else {
     270          // Case 2b: The first line contains the elementNames, the second line contains the values (two horizontal vectors)
     271          var max = Math.Max(firstLine.Length, secondLine.Length);
     272          for (var i = 0; i < max; i++) {
     273            var elemName = i < firstLine.Length ? firstLine[i] : string.Empty;
     274            var value = i < secondLine.Length ? secondLine[i] : string.Empty;
     275            yield return Tuple.Create(elemName, value);
     276          }
     277        }
     278      } else if (lines.Length == 1) {
     279        // Case 3: The line contains the values (one horizontal vector)
     280        var entries = lines[0].Split(tabSep, StringSplitOptions.None);
     281        foreach (var e in entries) {
     282          yield return Tuple.Create(string.Empty, e);
     283        }
     284      }
    225285    }
    226286    #endregion
Note: See TracChangeset for help on using the changeset viewer.