Changeset 14968
- Timestamp:
- 05/11/17 14:03:44 (8 years ago)
- Location:
- stable
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
stable ¶
- Property svn:mergeinfo changed
/trunk/sources merged: 14299,14561
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data.Views ¶
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Data.Views merged: 14299,14561
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data.Views/3.3 ¶
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Data.Views/3.3 merged: 14299,14561
- Property svn:mergeinfo changed
-
TabularUnified stable/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.Designer.cs ¶
r14186 r14968 65 65 // lengthTextBox 66 66 // 67 this.lengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 68 67 this.lengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 68 | System.Windows.Forms.AnchorStyles.Right))); 69 69 this.lengthTextBox.Location = new System.Drawing.Point(52, 0); 70 70 this.lengthTextBox.Name = "lengthTextBox"; … … 79 79 this.dataGridView.AllowUserToAddRows = false; 80 80 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 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; 85 85 this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 86 86 this.dataGridView.ColumnHeadersVisible = false; … … 101 101 // StringConvertibleArrayView 102 102 // 103 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);104 103 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 105 104 this.Controls.Add(this.dataGridView); -
TabularUnified stable/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs ¶
r14186 r14968 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.ComponentModel; 24 25 using System.Drawing; 26 using System.Linq; 25 27 using System.Text; 26 28 using System.Windows.Forms; … … 199 201 } 200 202 203 var elementNames = Content.ElementNames.ToList(); 201 204 for (int i = minRowIndex; i <= maxRowIndex; i++) { 202 205 DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible); 203 206 DataGridViewCell cell = dataGridView[column.Index, i]; 204 207 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 } 205 215 s.Append(Content.GetValue(i)); 206 216 s.Append(Environment.NewLine); … … 210 220 } 211 221 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 } 213 229 int rowIndex = 0; 214 230 if (dataGridView.CurrentCell != null) … … 216 232 217 233 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) { 222 248 if (clipboardText.EndsWith(Environment.NewLine)) 223 249 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 } 225 285 } 226 286 #endregion
Note: See TracChangeset
for help on using the changeset viewer.