From f4abe40626d9a1192f2c1519f08dbfb94229e0e5 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 23 Mar 2021 22:47:59 +0100 Subject: [PATCH] DriveSetup: fix creating partitions The code paths for creating a new partition and editing an existing one are more mixed together than I thought: - CreateParametersPanel reuses a method from ChangeParametersPanel which I had modified. - In the storage kit, the code to create the parameter editor is also shared between the two. The problem is that when creating a partition, we have only the parent BPartition. When modifying parameters, we have the child, and we need to get some things from the child (the current parameters), and some from the parent (the parameter editor). Fixes #16859. Change-Id: I5978386978c79a351e94c098c065fd43c422eb51 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3822 Reviewed-by: Adrien Destugues --- src/apps/drivesetup/ChangeParametersPanel.cpp | 17 ++++++++++++----- src/apps/drivesetup/ChangeParametersPanel.h | 3 ++- src/apps/drivesetup/CreateParametersPanel.cpp | 2 +- src/apps/drivesetup/MainWindow.cpp | 2 +- src/kits/storage/disk_device/Partition.cpp | 19 +++++++++++++++---- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/apps/drivesetup/ChangeParametersPanel.cpp b/src/apps/drivesetup/ChangeParametersPanel.cpp index 58cd2790e6..4b0ab15ab4 100644 --- a/src/apps/drivesetup/ChangeParametersPanel.cpp +++ b/src/apps/drivesetup/ChangeParametersPanel.cpp @@ -41,7 +41,7 @@ ChangeParametersPanel::ChangeParametersPanel(BWindow* window, : AbstractParametersPanel(window) { - CreateChangeControls(partition); + CreateChangeControls(partition, partition->Parent()); Init(B_PROPERTIES_PARAMETER_EDITOR, "", partition); } @@ -109,17 +109,24 @@ ChangeParametersPanel::Go(BString& name, BString& type, BString& parameters, void -ChangeParametersPanel::CreateChangeControls(BPartition* partition) +ChangeParametersPanel::CreateChangeControls(BPartition* partition, + BPartition* parent) { + const char* name = ""; + if (partition != NULL) + name = partition->Name(); + fNameTextControl = new BTextControl("Name Control", - B_TRANSLATE("Partition name:"), partition->Name(), NULL); - fSupportsName = partition->CanSetName(); + B_TRANSLATE("Partition name:"), name, NULL); + if (partition != NULL) + fSupportsName = partition->CanSetName(); + else if (parent != NULL) + fSupportsName = parent->SupportsChildName(); fTypePopUpMenu = new BPopUpMenu("Partition Type"); int32 cookie = 0; BString supportedType; - BPartition* parent = partition->Parent(); if (parent != NULL) { while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) { diff --git a/src/apps/drivesetup/ChangeParametersPanel.h b/src/apps/drivesetup/ChangeParametersPanel.h index 54e96c52ce..dd2458c1d4 100644 --- a/src/apps/drivesetup/ChangeParametersPanel.h +++ b/src/apps/drivesetup/ChangeParametersPanel.h @@ -35,7 +35,8 @@ protected: status_t Go(BString& name, BString& type, BString& parameters, BMessage& storage); - void CreateChangeControls(BPartition* parent); + void CreateChangeControls(BPartition* partition, + BPartition* parent); virtual bool NeedsEditor() const; virtual bool ValidWithoutEditor() const; diff --git a/src/apps/drivesetup/CreateParametersPanel.cpp b/src/apps/drivesetup/CreateParametersPanel.cpp index e08d5ca7fb..b1d1c1ae91 100644 --- a/src/apps/drivesetup/CreateParametersPanel.cpp +++ b/src/apps/drivesetup/CreateParametersPanel.cpp @@ -157,7 +157,7 @@ CreateParametersPanel::_CreateCreateControls(BPartition* parent, off_t offset, fSizeTextControl->SetModificationMessage( new BMessage(MSG_SIZE_TEXTCONTROL)); - CreateChangeControls(parent); + CreateChangeControls(NULL, parent); fOkButton->SetLabel(B_TRANSLATE("Create")); } diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index 6742431086..272189fd62 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -1254,7 +1254,7 @@ MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition) status = modificationPreparer.CommitModifications(); if (status != B_OK) { - _DisplayPartitionError(B_TRANSLATE("Failed to format the " + _DisplayPartitionError(B_TRANSLATE("Failed to create the " "partition. No changes have been written to disk."), NULL, status); return; } diff --git a/src/kits/storage/disk_device/Partition.cpp b/src/kits/storage/disk_device/Partition.cpp index 5c5ff53477..935c2fd8da 100644 --- a/src/kits/storage/disk_device/Partition.cpp +++ b/src/kits/storage/disk_device/Partition.cpp @@ -1035,11 +1035,22 @@ status_t BPartition::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type, BPartitionParameterEditor** editor) { - BPartition* parent = Parent(); - if (parent == NULL || parent->fDelegate == NULL) - return B_NO_INIT; + // When creating a new partition, this will be called for parent inside + // which we are creating a partition. + // When modifying an existing partition, this will be called for the + // partition itself, but the parameters are in fact managed by the parent + // (see SetParameters) + if (type == B_CREATE_PARAMETER_EDITOR) { + if (fDelegate == NULL) + return B_NO_INIT; + return fDelegate->GetParameterEditor(type, editor); + } else { + BPartition* parent = Parent(); + if (parent == NULL || parent->fDelegate == NULL) + return B_NO_INIT; - return parent->fDelegate->GetParameterEditor(type, editor); + return parent->fDelegate->GetParameterEditor(type, editor); + } }