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:
parent
7534e5870d
commit
f4abe40626
@ -41,7 +41,7 @@ ChangeParametersPanel::ChangeParametersPanel(BWindow* window,
|
|||||||
:
|
:
|
||||||
AbstractParametersPanel(window)
|
AbstractParametersPanel(window)
|
||||||
{
|
{
|
||||||
CreateChangeControls(partition);
|
CreateChangeControls(partition, partition->Parent());
|
||||||
|
|
||||||
Init(B_PROPERTIES_PARAMETER_EDITOR, "", partition);
|
Init(B_PROPERTIES_PARAMETER_EDITOR, "", partition);
|
||||||
}
|
}
|
||||||
@ -109,17 +109,24 @@ ChangeParametersPanel::Go(BString& name, BString& type, BString& parameters,
|
|||||||
|
|
||||||
|
|
||||||
void
|
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",
|
fNameTextControl = new BTextControl("Name Control",
|
||||||
B_TRANSLATE("Partition name:"), partition->Name(), NULL);
|
B_TRANSLATE("Partition name:"), name, NULL);
|
||||||
fSupportsName = partition->CanSetName();
|
if (partition != NULL)
|
||||||
|
fSupportsName = partition->CanSetName();
|
||||||
|
else if (parent != NULL)
|
||||||
|
fSupportsName = parent->SupportsChildName();
|
||||||
|
|
||||||
fTypePopUpMenu = new BPopUpMenu("Partition Type");
|
fTypePopUpMenu = new BPopUpMenu("Partition Type");
|
||||||
|
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
BString supportedType;
|
BString supportedType;
|
||||||
BPartition* parent = partition->Parent();
|
|
||||||
if (parent != NULL) {
|
if (parent != NULL) {
|
||||||
while (parent->GetNextSupportedChildType(&cookie, &supportedType)
|
while (parent->GetNextSupportedChildType(&cookie, &supportedType)
|
||||||
== B_OK) {
|
== B_OK) {
|
||||||
|
@ -35,7 +35,8 @@ protected:
|
|||||||
|
|
||||||
status_t Go(BString& name, BString& type,
|
status_t Go(BString& name, BString& type,
|
||||||
BString& parameters, BMessage& storage);
|
BString& parameters, BMessage& storage);
|
||||||
void CreateChangeControls(BPartition* parent);
|
void CreateChangeControls(BPartition* partition,
|
||||||
|
BPartition* parent);
|
||||||
|
|
||||||
virtual bool NeedsEditor() const;
|
virtual bool NeedsEditor() const;
|
||||||
virtual bool ValidWithoutEditor() const;
|
virtual bool ValidWithoutEditor() const;
|
||||||
|
@ -157,7 +157,7 @@ CreateParametersPanel::_CreateCreateControls(BPartition* parent, off_t offset,
|
|||||||
fSizeTextControl->SetModificationMessage(
|
fSizeTextControl->SetModificationMessage(
|
||||||
new BMessage(MSG_SIZE_TEXTCONTROL));
|
new BMessage(MSG_SIZE_TEXTCONTROL));
|
||||||
|
|
||||||
CreateChangeControls(parent);
|
CreateChangeControls(NULL, parent);
|
||||||
|
|
||||||
fOkButton->SetLabel(B_TRANSLATE("Create"));
|
fOkButton->SetLabel(B_TRANSLATE("Create"));
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1254,7 @@ MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition)
|
|||||||
status = modificationPreparer.CommitModifications();
|
status = modificationPreparer.CommitModifications();
|
||||||
|
|
||||||
if (status != B_OK) {
|
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);
|
"partition. No changes have been written to disk."), NULL, status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1035,11 +1035,22 @@ status_t
|
|||||||
BPartition::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
|
BPartition::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
|
||||||
BPartitionParameterEditor** editor)
|
BPartitionParameterEditor** editor)
|
||||||
{
|
{
|
||||||
BPartition* parent = Parent();
|
// When creating a new partition, this will be called for parent inside
|
||||||
if (parent == NULL || parent->fDelegate == NULL)
|
// which we are creating a partition.
|
||||||
return B_NO_INIT;
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user