Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.DataPreprocessing.Views
-
branches/crossvalidation-2434/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs
r12676 r14029 31 31 namespace HeuristicLab.DataPreprocessing.Views { 32 32 [View("Data Grid Content View")] 33 [Content(typeof( IDataGridContent), true)]33 [Content(typeof(DataGridContent), true)] 34 34 public partial class DataGridContentView : StringConvertibleMatrixView { 35 35 … … 42 42 private Tuple<int, int> currentCell; 43 43 44 public new IDataGridContent Content {45 get { return ( IDataGridContent)base.Content; }44 public new DataGridContent Content { 45 get { return (DataGridContent)base.Content; } 46 46 set { base.Content = value; } 47 47 } … … 59 59 InitializeComponent(); 60 60 dataGridView.CellMouseClick += dataGridView_CellMouseClick; 61 dataGridView.RowHeaderMouseClick += dataGridView_RowHeaderMouseClick; 61 62 dataGridView.KeyDown += dataGridView_KeyDown; 62 63 dataGridView.MouseUp += dataGridView_MouseUp; … … 142 143 143 144 144 //protected override void PasteValuesToDataGridView() { 145 // base.PasteValuesToDataGridView(); 146 // dataGridView.Refresh(); 147 //} 145 protected override void PasteValuesToDataGridView() { 146 string[,] values = SplitClipboardString(Clipboard.GetText()); 147 if (values.Length == 0) return; 148 int rowIndex = 0; 149 int columnIndex = 0; 150 if (dataGridView.CurrentCell != null) { 151 rowIndex = dataGridView.CurrentCell.RowIndex; 152 columnIndex = dataGridView.CurrentCell.ColumnIndex; 153 } 154 155 bool containsHeader = false; 156 var firstRow = Enumerable.Range(0, values.GetLength(0)).Select(col => values[col, 0]).ToList(); 157 if ((Content.Selection.Values.Sum(s => s.Count) == Content.Rows * Content.Columns) 158 || (rowIndex == 0 && columnIndex == 0 && Content.Rows <= values.GetLength(1) && Content.Columns <= values.GetLength(0))) { 159 // All is selected -or- top left selected and everything will be replaced 160 double temp; 161 containsHeader = !firstRow.All(string.IsNullOrEmpty) && firstRow.Any(r => !double.TryParse(r, out temp)); 162 if (containsHeader) 163 rowIndex = columnIndex = 0; 164 } 165 166 int newRows = values.GetLength(1) + rowIndex - (containsHeader ? 1 : 0); 167 int newColumns = values.GetLength(0) + columnIndex; 168 if (Content.Rows < newRows) Content.Rows = newRows; 169 if (Content.Columns < newColumns) Content.Columns = newColumns; 170 171 ReplaceTransaction(() => { 172 Content.PreProcessingData.InTransaction(() => { 173 for (int row = containsHeader ? 1 : 0; row < values.GetLength(1); row++) { 174 for (int col = 0; col < values.GetLength(0); col++) { 175 Content.SetValue(values[col, row], row + rowIndex - (containsHeader ? 1 : 0), col + columnIndex); 176 } 177 } 178 if (containsHeader) { 179 for (int i = 0; i < firstRow.Count; i++) 180 if (string.IsNullOrWhiteSpace(firstRow[i])) 181 firstRow[i] = string.Format("<{0}>", i); 182 Content.PreProcessingData.RenameColumns(firstRow); 183 } 184 }); 185 }); 186 187 ClearSorting(); 188 } 148 189 149 190 protected override void SetEnabledStateOfControls() { … … 165 206 protected override void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { 166 207 if (Content != null) { 167 if (e.Button == System.Windows.Forms.MouseButtons.Left) {208 if (e.Button == MouseButtons.Left) { 168 209 dataGridView.Focus(); 169 210 dataGridView.ClearSelection(); … … 174 215 dataGridView[e.ColumnIndex, i].Selected = true; 175 216 } 176 } else if (Content.SortableView) { 217 } else if (e.Button == MouseButtons.Middle) { 218 int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0; 219 Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex); 220 } else if (e.Button == MouseButtons.Right && Content.SortableView) { 177 221 SortColumn(e.ColumnIndex); 178 222 } 179 223 } 180 224 searchIterator = null; 225 } 226 private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { 227 if (Content != null) { 228 if (e.Button == MouseButtons.Middle) { 229 int newIndex = e.RowIndex >= 0 ? e.RowIndex : 0; 230 Content.PreProcessingData.InsertRow(newIndex); 231 } 232 } 181 233 } 182 234 … … 450 502 private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { 451 503 if (Content == null) return; 452 if (e.Button == System.Windows.Forms.MouseButtons.Right && !(e.ColumnIndex != -1 && e.RowIndex == -1)) {504 if (e.Button == MouseButtons.Right && !(e.ColumnIndex != -1 && e.RowIndex == -1)) { 453 505 if (e.ColumnIndex == -1 || e.RowIndex == -1) { 454 506 replaceValueOverColumnToolStripMenuItem.Visible = false; … … 612 664 #endregion 613 665 666 private void addRowButton_Click(object sender, EventArgs e) { 667 Content.PreProcessingData.InsertRow(Content.Rows); 668 } 669 670 private void addColumnButton_Click(object sender, EventArgs e) { 671 Content.PreProcessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns); 672 } 673 674 private void renameColumnsButton_Click(object sender, EventArgs e) { 675 var renameDialog = new RenameColumnsDialog(Content.ColumnNames); 676 677 if (renameDialog.ShowDialog(this) == DialogResult.OK) { 678 Content.PreProcessingData.RenameColumns(renameDialog.ColumnNames); 679 } 680 } 614 681 } 615 682 }
Note: See TracChangeset
for help on using the changeset viewer.