xref: /haiku/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.cpp (revision 71452e98334eaac603bf542d159e24788a46bebb)
1 /*
2  * Copyright 2013, Axel Dörfler, axeld@pinc-software.de.
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.
6  */
7 
8 
9 #include <stdio.h>
10 
11 #include "InitializeParameterEditor.h"
12 
13 #include <Button.h>
14 #include <Catalog.h>
15 #include <ControlLook.h>
16 #include <GridLayoutBuilder.h>
17 #include <Partition.h>
18 #include <SpaceLayoutItem.h>
19 #include <TextControl.h>
20 #include <Variant.h>
21 #include <View.h>
22 #include <Window.h>
23 
24 
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "NTFS_Initialize_Parameter"
27 
28 
29 static uint32 MSG_NAME_CHANGED = 'nmch';
30 
31 
32 InitializeNTFSEditor::InitializeNTFSEditor()
33 	:
34 	BPartitionParameterEditor(),
35 	fView(NULL),
36 	fNameControl(NULL),
37 	fParameters(NULL)
38 {
39 	_CreateViewControls();
40 }
41 
42 
43 InitializeNTFSEditor::~InitializeNTFSEditor()
44 {
45 }
46 
47 
48 void
49 InitializeNTFSEditor::SetTo(BPartition* partition)
50 {
51 	BString name = partition->ContentName();
52 	if (!name.IsEmpty())
53 		fNameControl->SetText(name.String());
54 }
55 
56 
57 BView*
58 InitializeNTFSEditor::View()
59 {
60 	return fView;
61 }
62 
63 
64 bool
65 InitializeNTFSEditor::ValidateParameters() const
66 {
67 	// The name must be set
68 	return fNameControl->TextView()->TextLength() > 0;
69 }
70 
71 
72 status_t
73 InitializeNTFSEditor::ParameterChanged(const char* name,
74 	const BVariant& variant)
75 {
76 	if (!strcmp(name, "name"))
77 		fNameControl->SetText(variant.ToString());
78 	return B_OK;
79 }
80 
81 
82 status_t
83 InitializeNTFSEditor::GetParameters(BString& parameters)
84 {
85 	parameters = "name \"";
86 	parameters << fNameControl->Text() << "\";\n";
87 	return B_OK;
88 }
89 
90 
91 void
92 InitializeNTFSEditor::_CreateViewControls()
93 {
94 	fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New NTFS Volume",
95 		NULL);
96 	fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
97 	fNameControl->TextView()->SetMaxBytes(127);
98 
99 	float spacing = be_control_look->DefaultItemSpacing();
100 
101 	fView = BGridLayoutBuilder(spacing, spacing)
102 		.Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
103 		.Add(fNameControl->CreateTextViewLayoutItem(), 1, 0).View()
104 	;
105 }
106