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 <pulkomandy@gmail.com>
This commit is contained in:
Adrien Destugues 2021-03-23 22:47:59 +01:00 committed by Adrien Destugues
parent 7534e5870d
commit f4abe40626
5 changed files with 31 additions and 12 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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"));
}

View File

@ -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;
}

View File

@ -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);
}
}