public void DeleteSelection() { if (!HasSelectedRows) { return; // Nothing to delete } // We want the keep the focus at the same row index after the row has been deleted. // Store the index of the row that has the focus for restoring it at the end of this method. int focusedRowIndex = SelectedRows[0].RowIndex; Row[] rows = SelectedRows.GetUniqueRowsInGuiOrder(); // Clear the selection to avoid intermediate updates SelectedRows.Clear(); var project = DataSource as IProject; foreach (Row row in rows) { if (row.Item is IInputFile) { DeleteInputFile(project, row.Item as IInputFile); } else if (row.Item is IDataBlock) { DeleteDataBlock(project, row.Item as IDataBlock); } } // Put the focus back at the same row index, // or at the row index above if the last row was removed FocusRow = GetRow(focusedRowIndex) ?? RootRow.ChildRowByIndex(RootRow.NumChildren - 1); }
/// <summary> /// Removes all rows from the tree. /// </summary> public void Clear() { if (IsWorkpad && RootRow != null) { IResultNode root = RootItem as IResultNode; if (root != null) { root.Children.Clear(); SelectedRows.SuspendChangeNotification(); RootRow.UpdateChildren(false, true); SelectedRows.ResumeChangeNotification(); } } }
/// <summary> /// Deletes all headers of the selected types. /// </summary> public void DeleteSelectedHeaderTypes() { if (IsWorkpad && HasSelectedRows) { foreach (IResultNode resultNode in Selections[HeaderSelectionType.AllHeadersOfSelectedTypeIncludingChildren].Results) { if (resultNode.Parent != null) { resultNode.Parent.RemoveChild(resultNode); } } SelectedRows.SuspendChangeNotification(); RootRow.UpdateChildren(false, true); SelectedRows.ResumeChangeNotification(); } }
/// <summary> /// Deletes the current selection. /// </summary> public void DeleteSelection() { if (IsWorkpad && RootRow != null) { foreach (IResultNode resultNode in SelectedItems) { if (resultNode.Parent != null) { resultNode.Parent.RemoveChild(resultNode); } } SelectedRows.SuspendChangeNotification(); RootRow.UpdateChildren(false, true); SelectedRows.ResumeChangeNotification(); } }
/// <summary> /// Moves the <paramref name="rows"/> to the top of the tree. /// </summary> /// <param name="rows">the rows to be moved</param> public void MoveToTop(Row[] rows) { if (rows == null) { throw new ArgumentNullException("rows"); } if (IsWorkpad && RootRow != null && RootRow.NumChildren > 0) { IResultNode root = RootItem as IResultNode; int index = 0; foreach (Row row in UniqueSelectedRowsInGuiOrder) { IResultNode resultNode = (IResultNode)row.Item; resultNode.Parent.RemoveChild(resultNode); root.InsertChild(index++, resultNode); } SelectedRows.SuspendChangeNotification(); RootRow.UpdateChildren(false, true); SelectedRows.ResumeChangeNotification(); } }
private void Project_ProjectChanged(object sender, ProjectChangedEventArgs e) { switch (e.Type) { case ProjectChangedType.FileDeleted: case ProjectChangedType.DataBlockDeleted: { Row row = FindRow(e.Item); if (row.HasFocus) { SetFocusRow(row.ParentRow, false); } row.ParentRow.UpdateChildren(true, false); } break; case ProjectChangedType.FileAdded: { RootRow.UpdateChildren(true, false); } break; case ProjectChangedType.DataBlockAdded: { Row row = FindRow(((IDataBlock)e.Item).InputFile); if (row != null) { row.UpdateChildren(true, false); } else { RootRow.UpdateChildren(true, false); } } break; } }