Patch by "jwlh172": Added a text control to the partition

creation panel of DriveSetup, to enter the partition size
manually. Closes ticket #7991. Changes by myself: I've
refactored updating the text control from the size slider
and used that method also when the user somehow entered
invalid input into the text control (untested).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42759 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2011-09-19 20:01:38 +00:00
parent 1724ebde55
commit 42ea87d59b
4 changed files with 52 additions and 2 deletions
+39 -1
View File
@@ -77,7 +77,9 @@ private:
enum {
MSG_OK = 'okok',
MSG_CANCEL = 'cncl',
MSG_PARTITION_TYPE = 'type'
MSG_PARTITION_TYPE = 'type',
MSG_SIZE_SLIDER = 'ssld',
MSG_SIZE_TEXTCONTROL = 'stct'
};
@@ -138,6 +140,22 @@ CreateParamsPanel::MessageReceived(BMessage* message)
fEditor->PartitionTypeChanged(type);
}
break;
case MSG_SIZE_SLIDER:
_UpdateTextControl();
break;
case MSG_SIZE_TEXTCONTROL:
{
BString sizeString;
sizeString = fSizeTextControl->Text();
int32 sizeInt = atoi(sizeString.String());
if (sizeInt >= 0 && sizeInt <= fSizeSlider->MaxPartitionSize())
fSizeSlider->SetValue(sizeInt);
else
_UpdateTextControl();
break;
}
default:
BWindow::MessageReceived(message);
@@ -225,6 +243,17 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset,
fSizeSlider = new SizeSlider("Slider", B_TRANSLATE("Partition size"), NULL,
offset, offset + size);
fSizeSlider->SetPosition(1.0);
fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER));
BString sizeText;
sizeText << fSizeSlider->Value();
fSizeTextControl = new BTextControl("Size Control",
"", sizeText.String(), NULL);
for(int32 i = 0; i < 256; i++)
fSizeTextControl->TextView()->DisallowChar(i);
for(int32 i = '0'; i <= '9'; i++)
fSizeTextControl->TextView()->AllowChar(i);
fSizeTextControl->SetModificationMessage(new BMessage(MSG_SIZE_TEXTCONTROL));
fNameTextControl = new BTextControl("Name Control",
B_TRANSLATE("Partition name:"), "", NULL);
@@ -257,6 +286,7 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset,
AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing)
.Add(fSizeSlider)
.Add(fSizeTextControl)
.Add(BGridLayoutBuilder(0.0, 5.0)
.Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0)
.Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0)
@@ -284,3 +314,11 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset,
layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
void
CreateParamsPanel::_UpdateTextControl()
{
BString sizeString;
sizeString << fSizeSlider->Value();
fSizeTextControl->SetText(sizeString.String());
}
+3
View File
@@ -38,6 +38,8 @@ private:
void _CreateViewControls(BPartition* parent,
off_t offset, off_t size);
void _UpdateTextControl();
class EscapeFilter;
EscapeFilter* fEscapeFilter;
sem_id fExitSemaphore;
@@ -50,6 +52,7 @@ private:
BMenuField* fTypeMenuField;
BTextControl* fNameTextControl;
SizeSlider* fSizeSlider;
BTextControl* fSizeTextControl;
};
#endif // CREATE_PARAMS_PANEL_H
+8 -1
View File
@@ -99,7 +99,8 @@ SizeSlider::SizeSlider(const char* name, const char* label,
BSlider(name, label, message, minValue, maxValue,
B_HORIZONTAL, B_TRIANGLE_THUMB),
fStartOffset(minValue),
fEndOffset(maxValue)
fEndOffset(maxValue),
fMaxPartitionSize(maxValue)
{
SetBarColor((rgb_color){ 0, 80, 255, 255 });
char minString[64];
@@ -143,3 +144,9 @@ SizeSlider::Offset()
// headed slider is implemented.
return fStartOffset;
}
int32
SizeSlider::MaxPartitionSize()
{
return fMaxPartitionSize;
}
+2
View File
@@ -51,10 +51,12 @@ public:
virtual const char* UpdateText() const;
int32 Size();
int32 Offset();
int32 MaxPartitionSize();
private:
off_t fStartOffset;
off_t fEndOffset;
off_t fMaxPartitionSize;
mutable char fStatusLabel[64];
};