xref: /haiku/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.cpp (revision b247f935d133a42c427cad8a759a1bf2f65bc290)
1 /*
2  * Copyright 2015, Rene Gollent, rene@gollent.com.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "TableCellBoolEditor.h"
7 
8 #include "BoolValue.h"
9 
10 
11 TableCellBoolEditor::TableCellBoolEditor(::Value* initialValue,
12 	ValueFormatter* formatter)
13 	:
14 	TableCellOptionPopUpEditor(initialValue, formatter)
15 {
16 }
17 
18 
19 TableCellBoolEditor::~TableCellBoolEditor()
20 {
21 }
22 
23 
24 status_t
25 TableCellBoolEditor::ConfigureOptions()
26 {
27 	BoolValue* initialValue = dynamic_cast<BoolValue*>(InitialValue());
28 	if (initialValue == NULL)
29 		return B_BAD_VALUE;
30 
31 	status_t error = AddOption("true", true);
32 	if (error != B_OK)
33 		return error;
34 
35 	error = AddOption("false", false);
36 	if (error != B_OK)
37 		return error;
38 
39 	return SelectOptionFor(initialValue->GetValue());
40 }
41 
42 
43 status_t
44 TableCellBoolEditor::GetSelectedValue(::Value*& _value) const
45 {
46 	const char* name = NULL;
47 	int32 selectedValue = 0;
48 	SelectedOption(&name, &selectedValue);
49 	BoolValue* value = new(std::nothrow) BoolValue((bool)selectedValue);
50 	if (value == NULL)
51 		return B_NO_MEMORY;
52 
53 	_value = value;
54 	return B_OK;
55 }
56