void MainWindow::_AdaptToSelectedPartition() { partition_id diskID = -1; partition_id partitionID = -1; partition_id parentID = -1; BRow* _selectedRow = fListView->CurrentSelection(); if (_selectedRow) { // go up to top level row BRow* _topLevelRow = _selectedRow; BRow* parent = NULL; while (fListView->FindParent(_topLevelRow, &parent, NULL)) _topLevelRow = parent; PartitionListRow* topLevelRow = dynamic_cast<PartitionListRow*>(_topLevelRow); PartitionListRow* selectedRow = dynamic_cast<PartitionListRow*>(_selectedRow); if (topLevelRow) diskID = topLevelRow->ID(); if (selectedRow) { partitionID = selectedRow->ID(); parentID = selectedRow->ParentID(); } } _SetToDiskAndPartition(diskID, partitionID, parentID); }
PartitionListRow* PartitionListView::FindRow(partition_id id, PartitionListRow* parent) { for (int32 i = 0; i < CountRows(parent); i++) { PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(i, parent)); if (item != NULL && item->ID() == id) return item; if (CountRows(item) > 0) { // recurse into child rows item = FindRow(id, item); if (item) return item; } } return NULL; }
void MainWindow::_ScanDrives() { fSpaceIDMap.Clear(); int32 diskCount = 0; ListPopulatorVisitor driveVisitor(fListView, diskCount, fSpaceIDMap); fDDRoster.VisitEachPartition(&driveVisitor); fDiskView->SetDiskCount(diskCount); // restore selection PartitionListRow* previousSelection = fListView->FindRow(fCurrentPartitionID); if (previousSelection) { fListView->AddToSelection(previousSelection); _UpdateMenus(fCurrentDisk, fCurrentPartitionID, previousSelection->ParentID()); fDiskView->ForceUpdate(); } else { _UpdateMenus(NULL, -1, -1); } }
bool PartitionListView::InitiateDrag(BPoint rowPoint, bool wasSelected) { PartitionListRow* draggedRow = dynamic_cast<PartitionListRow*>(RowAt(rowPoint)); if (draggedRow == NULL) return false; const char* draggedPath = draggedRow->DevicePath(); if (draggedPath == NULL) return false; BRect draggedRowRect; GetRowRect(draggedRow, &draggedRowRect); BMessage dragMessage(B_MIME_DATA); dragMessage.AddData("text/plain", B_MIME_TYPE, draggedPath, strlen(draggedPath)); DragMessage(&dragMessage, draggedRowRect, NULL); return true; }
void MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition) { if (!disk || selectedPartition > -2) { _DisplayPartitionError(B_TRANSLATE("The currently selected partition " "is not empty.")); return; } if (disk->IsReadOnly()) { _DisplayPartitionError(B_TRANSLATE("The selected disk is read-only.")); return; } PartitionListRow* currentSelection = dynamic_cast<PartitionListRow*>( fListView->CurrentSelection()); if (!currentSelection) { _DisplayPartitionError(B_TRANSLATE("There was an error acquiring the " "partition row.")); return; } BPartition* parent = disk->FindDescendant(currentSelection->ParentID()); if (!parent) { _DisplayPartitionError(B_TRANSLATE("The currently selected partition " "does not have a parent partition.")); return; } if (!parent->ContainsPartitioningSystem()) { _DisplayPartitionError(B_TRANSLATE("The selected partition does not " "contain a partitioning system.")); return; } ModificationPreparer modificationPreparer(disk); status_t ret = modificationPreparer.ModificationStatus(); if (ret != B_OK) { _DisplayPartitionError(B_TRANSLATE("There was an error preparing the " "disk for modifications."), NULL, ret); return; } // get partitioning info BPartitioningInfo partitioningInfo; status_t error = parent->GetPartitioningInfo(&partitioningInfo); if (error != B_OK) { _DisplayPartitionError(B_TRANSLATE("Could not aquire partitioning " "information.")); return; } int32 spacesCount = partitioningInfo.CountPartitionableSpaces(); if (spacesCount == 0) { _DisplayPartitionError(B_TRANSLATE("There's no space on the partition " "where a child partition could be created.")); return; } BString name, type, parameters; off_t offset = currentSelection->Offset(); off_t size = currentSelection->Size(); CreateParamsPanel* panel = new CreateParamsPanel(this, parent, offset, size); if (panel->Go(offset, size, name, type, parameters) == GO_CANCELED) return; ret = parent->ValidateCreateChild(&offset, &size, type.String(), &name, parameters.String()); if (ret != B_OK) { _DisplayPartitionError(B_TRANSLATE("Validation of the given creation " "parameters failed.")); return; } // Warn the user one more time... BAlert* alert = new BAlert("final notice", B_TRANSLATE("Are you sure you " "want to write the changes back to disk now?\n\n" "All data on the partition will be irretrievably lost if you do " "so!"), B_TRANSLATE("Write changes"), B_TRANSLATE("Cancel"), NULL, B_WIDTH_FROM_WIDEST, B_WARNING_ALERT); int32 choice = alert->Go(); if (choice == 1) return; ret = parent->CreateChild(offset, size, type.String(), name.String(), parameters.String()); if (ret != B_OK) { _DisplayPartitionError(B_TRANSLATE("Creation of the partition has " "failed.")); return; } // commit ret = modificationPreparer.CommitModifications(); if (ret != B_OK) { _DisplayPartitionError(B_TRANSLATE("Failed to format the " "partition. No changes have been written to disk.")); return; } // The disk layout has changed, update disk information bool updated; ret = disk->Update(&updated); _ScanDrives(); fDiskView->ForceUpdate(); }