2 * Copyright 2008-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
6 * Stephan Aßmus <superstippi@gmx.de>
7 * Axel Dörfler, axeld@pinc-software.de.
8 * Bryce Groff <bgroff@hawaii.edu>
9 * Karsten Heimrich <host.haiku@gmx.de>
13 #include "ChangeParametersPanel.h"
17 #include <ControlLook.h>
18 #include <DiskDeviceTypes.h>
19 #include <MenuField.h>
21 #include <MessageFilter.h>
22 #include <PopUpMenu.h>
24 #include <TextControl.h>
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "ChangeParametersPanel"
35 MSG_PARTITION_TYPE
= 'type',
39 ChangeParametersPanel::ChangeParametersPanel(BWindow
* window
,
40 BPartition
* partition
)
42 AbstractParametersPanel(window
)
44 CreateChangeControls(partition
);
46 Init(B_PROPERTIES_PARAMETER_EDITOR
, "", partition
);
50 ChangeParametersPanel::~ChangeParametersPanel()
56 ChangeParametersPanel::Go(BString
& name
, BString
& type
, BString
& parameters
)
59 return Go(name
, type
, parameters
, storage
);
64 ChangeParametersPanel::MessageReceived(BMessage
* message
)
66 switch (message
->what
) {
67 case MSG_PARTITION_TYPE
:
68 if (fEditor
!= NULL
) {
70 if (message
->FindString("type", &type
) == B_OK
)
71 fEditor
->ParameterChanged("type", BVariant(type
));
76 AbstractParametersPanel::MessageReceived(message
);
81 // #pragma mark - protected
84 ChangeParametersPanel::ChangeParametersPanel(BWindow
* window
)
86 AbstractParametersPanel(window
)
92 ChangeParametersPanel::Go(BString
& name
, BString
& type
, BString
& parameters
,
95 // The object will be deleted in Go(), so we need to get the values via
97 status_t status
= AbstractParametersPanel::Go(parameters
, storage
);
102 name
.SetTo(storage
.GetString("name", NULL
));
105 type
.SetTo(storage
.GetString("type", NULL
));
112 ChangeParametersPanel::CreateChangeControls(BPartition
* parent
)
114 fNameTextControl
= new BTextControl("Name Control",
115 B_TRANSLATE("Partition name:"), "", NULL
);
116 fSupportsName
= parent
->SupportsChildName();
118 fTypePopUpMenu
= new BPopUpMenu("Partition Type");
121 BString supportedType
;
122 while (parent
->GetNextSupportedChildType(&cookie
, &supportedType
) == B_OK
) {
123 BMessage
* message
= new BMessage(MSG_PARTITION_TYPE
);
124 message
->AddString("type", supportedType
);
125 BMenuItem
* item
= new BMenuItem(supportedType
, message
);
126 fTypePopUpMenu
->AddItem(item
);
128 if (strcmp(supportedType
, kPartitionTypeBFS
) == 0)
129 item
->SetMarked(true);
132 fTypeMenuField
= new BMenuField(B_TRANSLATE("Partition type:"),
134 fSupportsType
= fTypePopUpMenu
->CountItems() != 0;
136 fOkButton
->SetLabel(B_TRANSLATE("Change"));
141 ChangeParametersPanel::NeedsEditor() const
143 return !fSupportsName
&& !fSupportsType
;
148 ChangeParametersPanel::ValidWithoutEditor() const
150 return !NeedsEditor();
155 ChangeParametersPanel::ParametersReceived(const BString
& parameters
,
159 status_t status
= storage
.SetString("name", fNameTextControl
->Text());
162 if (BMenuItem
* item
= fTypeMenuField
->Menu()->FindMarked()) {
164 BMessage
* message
= item
->Message();
165 if (!message
|| message
->FindString("type", &type
) != B_OK
)
166 type
= kPartitionTypeBFS
;
169 status
= storage
.SetString("type", type
);
177 ChangeParametersPanel::AddControls(BLayoutBuilder::Group
<>& builder
,
180 if (fSupportsName
|| fSupportsType
) {
181 BLayoutBuilder::Group
<>::GridBuilder gridBuilder
182 = builder
.AddGrid(0.0, B_USE_DEFAULT_SPACING
);
185 gridBuilder
.Add(fNameTextControl
->CreateLabelLayoutItem(), 0, 0)
186 .Add(fNameTextControl
->CreateTextViewLayoutItem(), 1, 0);
189 gridBuilder
.Add(fTypeMenuField
->CreateLabelLayoutItem(), 0, 1)
190 .Add(fTypeMenuField
->CreateMenuBarLayoutItem(), 1, 1);
194 if (editorView
!= NULL
)
195 builder
.Add(editorView
);