2 * Copyright 2015, François Revol <revol@free.fr>
3 * Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
4 * Copyright 2009, Bryce Groff, brycegroff@gmail.com.
5 * Distributed under the terms of the MIT License.
11 #include "InitializeParameterEditor.h"
16 #include <ControlLook.h>
17 #include <GridLayoutBuilder.h>
18 #include <MenuField.h>
20 #include <Partition.h>
21 #include <PopUpMenu.h>
22 #include <SpaceLayoutItem.h>
23 #include <TextControl.h>
29 #undef B_TRANSLATION_CONTEXT
30 #define B_TRANSLATION_CONTEXT "FAT_Initialize_Parameter"
33 static uint32 MSG_NAME_CHANGED
= 'nmch';
34 static uint32 MSG_FAT_BITS
= 'fatb';
36 InitializeFATEditor::InitializeFATEditor()
38 BPartitionParameterEditor(),
41 fFatBitsMenuField(NULL
),
44 _CreateViewControls();
48 InitializeFATEditor::~InitializeFATEditor()
54 InitializeFATEditor::SetTo(BPartition
* partition
)
56 BString name
= partition
->Name();
58 name
= partition
->ContentName();
60 fNameControl
->SetText(name
.String());
65 InitializeFATEditor::View()
72 InitializeFATEditor::ValidateParameters() const
74 // The name must be set
75 return fNameControl
->TextView()->TextLength() > 0;
80 InitializeFATEditor::ParameterChanged(const char* name
,
81 const BVariant
& variant
)
83 if (!strcmp(name
, "name"))
84 fNameControl
->SetText(variant
.ToString());
90 InitializeFATEditor::GetParameters(BString
& parameters
)
94 if (BMenuItem
* item
= fFatBitsMenuField
->Menu()->FindMarked()) {
96 BMessage
* message
= item
->Message();
97 if (!message
|| message
->FindString("fat", &size
) < B_OK
)
98 size
= "0"; // autodetect
99 // TODO: use libroot driver settings API
100 parameters
<< "fat " << size
<< ";\n";
103 parameters
<< "name \"";
104 parameters
<< fNameControl
->Text() << "\";\n";
105 printf("p:%s", parameters
.String());
111 InitializeFATEditor::_CreateViewControls()
113 fNameControl
= new BTextControl(B_TRANSLATE("Name:"), "New FAT Vol",
115 fNameControl
->SetModificationMessage(new BMessage(MSG_NAME_CHANGED
));
116 // TODO find out what is the max length for this specific FS partition name
117 fNameControl
->TextView()->SetMaxBytes(11);
119 BPopUpMenu
* fatBitsMenu
= new BPopUpMenu("fat size");
120 BMessage
* message
= new BMessage(MSG_FAT_BITS
);
121 message
->AddString("fat", "0");
122 BMenuItem
* defaultItem
= new BMenuItem(
123 B_TRANSLATE("Auto (default)"), message
);
124 fatBitsMenu
->AddItem(defaultItem
);
125 message
= new BMessage(MSG_FAT_BITS
);
126 message
->AddString("fat", "12");
127 fatBitsMenu
->AddItem(new BMenuItem("12", message
));
128 message
= new BMessage(MSG_FAT_BITS
);
129 message
->AddString("fat", "16");
130 fatBitsMenu
->AddItem(new BMenuItem("16", message
));
131 message
= new BMessage(MSG_FAT_BITS
);
132 message
->AddString("fat", "32");
133 fatBitsMenu
->AddItem(new BMenuItem("32", message
));
135 fFatBitsMenuField
= new BMenuField(B_TRANSLATE("FAT bits:"),
137 defaultItem
->SetMarked(true);
139 float spacing
= be_control_look
->DefaultItemSpacing();
141 fView
= BGridLayoutBuilder(spacing
, spacing
)
143 .Add(fNameControl
->CreateLabelLayoutItem(), 0, 0)
144 .Add(fNameControl
->CreateTextViewLayoutItem(), 1, 0)
147 .Add(fFatBitsMenuField
->CreateLabelLayoutItem(), 0, 1)
148 .Add(fFatBitsMenuField
->CreateMenuBarLayoutItem(), 1, 1).View()