xref: /haiku/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.cpp (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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->Name();
52 	if (name.IsEmpty())
53 		name = partition->RawContentName();
54 	if (!name.IsEmpty())
55 		fNameControl->SetText(name.String());
56 }
57 
58 
59 BView*
60 InitializeNTFSEditor::View()
61 {
62 	return fView;
63 }
64 
65 
66 bool
67 InitializeNTFSEditor::ValidateParameters() const
68 {
69 	// The name must be set
70 	return fNameControl->TextView()->TextLength() > 0;
71 }
72 
73 
74 status_t
75 InitializeNTFSEditor::ParameterChanged(const char* name,
76 	const BVariant& variant)
77 {
78 	if (!strcmp(name, "name"))
79 		fNameControl->SetText(variant.ToString());
80 	return B_OK;
81 }
82 
83 
84 status_t
85 InitializeNTFSEditor::GetParameters(BString& parameters)
86 {
87 	parameters = "name \"";
88 	parameters << fNameControl->Text() << "\";\n";
89 	return B_OK;
90 }
91 
92 
93 void
94 InitializeNTFSEditor::_CreateViewControls()
95 {
96 	fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New NTFS Volume",
97 		NULL);
98 	fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
99 	fNameControl->TextView()->SetMaxBytes(127);
100 
101 	float spacing = be_control_look->DefaultItemSpacing();
102 
103 	fView = BGridLayoutBuilder(spacing, spacing)
104 		.Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
105 		.Add(fNameControl->CreateTextViewLayoutItem(), 1, 0).View()
106 	;
107 }
108