DriveSetup: solved a few issues of CreateParametersPanel.

* I obviously wasn't really done last time: now the panel behaves as it should.
This commit is contained in:
Axel Dörfler
2013-02-12 22:24:16 +01:00
parent d2239cb8b9
commit 32da57f74b
4 changed files with 129 additions and 61 deletions
+73 -48
View File
@@ -136,54 +136,8 @@ AbstractParametersPanel::MessageReceived(BMessage* message)
status_t
AbstractParametersPanel::Go(BString& parameters)
{
// Without an editor, we cannot change anything, anyway
if (fEditor == NULL) {
parameters = "";
if (fReturnStatus == B_CANCELED)
fReturnStatus = B_OK;
if (!Lock())
return B_ERROR;
} else {
// run the window thread, to get an initial layout of the controls
Hide();
Show();
if (!Lock())
return B_CANCELED;
// center the panel above the parent window
CenterIn(fWindow->Frame());
Show();
Unlock();
// block this thread now, but keep the window repainting
while (true) {
status_t status = acquire_sem_etc(fExitSemaphore, 1,
B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000);
if (status != B_TIMED_OUT && status != B_INTERRUPTED)
break;
fWindow->UpdateIfNeeded();
}
if (!Lock())
return B_CANCELED;
if (fReturnStatus == B_OK) {
if (fEditor->ValidateParameters()) {
status_t err = fEditor->GetParameters(parameters);
if (err != B_OK)
fReturnStatus = err;
}
}
}
status_t status = fReturnStatus;
Quit();
// NOTE: this object is toast now!
return status;
BMessage storage;
return Go(parameters, storage);
}
@@ -240,6 +194,77 @@ AbstractParametersPanel::Init(B_PARAMETER_EDITOR_TYPE type,
}
status_t
AbstractParametersPanel::Go(BString& parameters, BMessage& storage)
{
// Without an editor, we cannot change anything, anyway
if (fEditor == NULL && NeedsEditor()) {
parameters = "";
if (fReturnStatus == B_CANCELED)
fReturnStatus = B_OK;
if (!Lock())
return B_ERROR;
} else {
// run the window thread, to get an initial layout of the controls
Hide();
Show();
if (!Lock())
return B_CANCELED;
// center the panel above the parent window
CenterIn(fWindow->Frame());
Show();
Unlock();
// block this thread now, but keep the window repainting
while (true) {
status_t status = acquire_sem_etc(fExitSemaphore, 1,
B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000);
if (status != B_TIMED_OUT && status != B_INTERRUPTED)
break;
fWindow->UpdateIfNeeded();
}
if (!Lock())
return B_CANCELED;
if (fReturnStatus == B_OK) {
if (fEditor != NULL && fEditor->ValidateParameters()) {
status_t status = fEditor->GetParameters(parameters);
if (status != B_OK)
fReturnStatus = status;
}
if (fReturnStatus == B_OK)
fReturnStatus = ParametersReceived(parameters, storage);
}
}
status_t status = fReturnStatus;
Quit();
// NOTE: this object is toast now!
return status;
}
bool
AbstractParametersPanel::NeedsEditor() const
{
return true;
}
status_t
AbstractParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
{
return B_OK;
}
void
AbstractParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView)
@@ -37,7 +37,11 @@ protected:
void Init(B_PARAMETER_EDITOR_TYPE type,
const BString& diskSystem,
BPartition* partition);
status_t Go(BString& parameters, BMessage& storage);
virtual bool NeedsEditor() const;
virtual status_t ParametersReceived(const BString& parameters,
BMessage& storage);
virtual void AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView);
+49 -13
View File
@@ -60,25 +60,25 @@ status_t
CreateParametersPanel::Go(off_t& offset, off_t& size, BString& name,
BString& type, BString& parameters)
{
// The object will be deleted in Go(), so we need to get the values before
// The object will be deleted in Go(), so we need to get the values via
// a BMessage
BMessage storage;
status_t status = AbstractParametersPanel::Go(parameters, storage);
if (status != B_OK)
return status;
// Return the value back as bytes.
size = fSizeSlider->Size();
offset = fSizeSlider->Offset();
size = storage.GetInt64("size", 0);
offset = storage.GetInt64("offset", 0);
// get name
name.SetTo(fNameTextControl->Text());
name.SetTo(storage.GetString("name", NULL));
// get type
if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
const char* _type;
BMessage* message = item->Message();
if (!message || message->FindString("type", &_type) < B_OK)
_type = kPartitionTypeBFS;
type << _type;
}
type.SetTo(storage.GetString("type", NULL));
return AbstractParametersPanel::Go(parameters);
return B_OK;
}
@@ -114,6 +114,41 @@ CreateParametersPanel::MessageReceived(BMessage* message)
}
bool
CreateParametersPanel::NeedsEditor() const
{
return false;
}
status_t
CreateParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
{
// Return the value back as bytes.
status_t status = storage.SetInt64("size", fSizeSlider->Size());
if (status == B_OK)
status = storage.SetInt64("offset", fSizeSlider->Offset());
// get name
if (status == B_OK)
status = storage.SetString("name", fNameTextControl->Text());
// get type
if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
const char* type;
BMessage* message = item->Message();
if (!message || message->FindString("type", &type) != B_OK)
type = kPartitionTypeBFS;
if (status == B_OK)
status = storage.SetString("type", type);
}
return status;
}
void
CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView)
@@ -136,7 +171,8 @@ CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
}
}
builder.Add(editorView);
if (editorView != NULL)
builder.Add(editorView);
}
@@ -33,6 +33,9 @@ public:
virtual void MessageReceived(BMessage* message);
protected:
virtual bool NeedsEditor() const;
virtual status_t ParametersReceived(const BString& parameters,
BMessage& storage);
virtual void AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView);