From 026596dd1de1cf86deaea712130cfb6a4901b6fd Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 6 Jun 2015 23:25:30 -0400 Subject: [PATCH] Debugger: Add table cell editors for various value types. TableCell{Bool,Enumeration}Editor: - OptionPopUp-derived editors for their respective value types. TableCellIntegerEditor: - TextControl-derived editor for integer values that validates inputs based on the target integer size and type. Not actually used yet, but together with the previous changes, these lay the groundwork for the remaining part of #9708. --- src/apps/debugger/Jamfile | 3 ++ .../gui/value/TableCellBoolEditor.cpp | 40 ++++++++++++++ .../gui/value/TableCellBoolEditor.h | 23 ++++++++ .../gui/value/TableCellEnumerationEditor.cpp | 48 +++++++++++++++++ .../gui/value/TableCellEnumerationEditor.h | 24 +++++++++ .../gui/value/TableCellIntegerEditor.cpp | 52 +++++++++++++++++++ .../gui/value/TableCellIntegerEditor.h | 26 ++++++++++ 7 files changed, 216 insertions(+) create mode 100644 src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.cpp create mode 100644 src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.h create mode 100644 src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.cpp create mode 100644 src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.h create mode 100644 src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.cpp create mode 100644 src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 3f1e595af3..442115964a 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -300,8 +300,11 @@ Application Debugger : WatchPromptWindow.cpp # user_interface/gui/value + TableCellBoolEditor.cpp + TableCellEnumerationEditor.cpp TableCellFormattedValueEditor.cpp TableCellFormattedValueRenderer.cpp + TableCellIntegerEditor.cpp TableCellOptionPopUpEditor.cpp TableCellTextControlEditor.cpp TableCellValueEditor.cpp diff --git a/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.cpp b/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.cpp new file mode 100644 index 0000000000..5a5b7afa33 --- /dev/null +++ b/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2015, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ + +#include "TableCellBoolEditor.h" + +#include "BoolValue.h" + + +TableCellBoolEditor::TableCellBoolEditor(::Value* initialValue, + ValueFormatter* formatter) + : + TableCellOptionPopUpEditor(initialValue, formatter) +{ +} + + +TableCellBoolEditor::~TableCellBoolEditor() +{ +} + + +status_t +TableCellBoolEditor::ConfigureOptions() +{ + BoolValue* initialValue = dynamic_cast(InitialValue()); + if (initialValue == NULL) + return B_BAD_VALUE; + + status_t error = AddOption("true", true); + if (error != B_OK) + return error; + + error = AddOption("false", false); + if (error != B_OK) + return error; + + return SelectOptionFor(initialValue->GetValue()); +} diff --git a/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.h b/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.h new file mode 100644 index 0000000000..b8fd82811a --- /dev/null +++ b/src/apps/debugger/user_interface/gui/value/TableCellBoolEditor.h @@ -0,0 +1,23 @@ +/* + * Copyright 2015, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#ifndef TABLE_CELL_BOOL_EDITOR_H +#define TABLE_CELL_BOOL_EDITOR_H + +#include + +#include "TableCellOptionPopUpEditor.h" + + +class TableCellBoolEditor : public TableCellOptionPopUpEditor { +public: + TableCellBoolEditor(::Value* initialValue, + ValueFormatter* formatter); + virtual ~TableCellBoolEditor(); + + virtual status_t ConfigureOptions(); + +}; + +#endif // TABLE_CELL_BOOL_EDITOR_H diff --git a/src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.cpp b/src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.cpp new file mode 100644 index 0000000000..fdae22afe3 --- /dev/null +++ b/src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2015, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ + +#include "TableCellEnumerationEditor.h" + +#include "EnumerationValue.h" +#include "Type.h" + + +TableCellEnumerationEditor::TableCellEnumerationEditor(::Value* initialValue, + ValueFormatter* formatter) + : + TableCellOptionPopUpEditor(initialValue, formatter) +{ +} + + +TableCellEnumerationEditor::~TableCellEnumerationEditor() +{ +} + + +status_t +TableCellEnumerationEditor::ConfigureOptions() +{ + EnumerationValue* initialValue = dynamic_cast( + InitialValue()); + if (initialValue == NULL) + return B_BAD_VALUE; + + EnumerationType* type = initialValue->GetType(); + for (int32 i = 0; i < type->CountValues(); i++) { + EnumeratorValue* value = type->ValueAt(i); + BString output; + + status_t error = AddOption(value->Name(), value->Value().ToInt32()); + if (error != B_OK) + return error; + } + + BVariant integerValue; + if (!initialValue->ToVariant(integerValue)) + return B_NO_MEMORY; + + return SelectOptionFor(integerValue.ToInt32()); +} diff --git a/src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.h b/src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.h new file mode 100644 index 0000000000..4a26e34de4 --- /dev/null +++ b/src/apps/debugger/user_interface/gui/value/TableCellEnumerationEditor.h @@ -0,0 +1,24 @@ +/* + * Copyright 2015, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#ifndef TABLE_CELL_ENUMERATION_EDITOR_H +#define TABLE_CELL_ENUMERATION_EDITOR_H + +#include + +#include "TableCellOptionPopUpEditor.h" + + +class TableCellEnumerationEditor : public TableCellOptionPopUpEditor { +public: + TableCellEnumerationEditor( + ::Value* initialValue, + ValueFormatter* formatter); + virtual ~TableCellEnumerationEditor(); + + virtual status_t ConfigureOptions(); + +}; + +#endif // TABLE_CELL_ENUMERATION_EDITOR_H diff --git a/src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.cpp b/src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.cpp new file mode 100644 index 0000000000..cc33e6ba6e --- /dev/null +++ b/src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2015, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ + +#include "TableCellIntegerEditor.h" + +#include + +#include + +#include "IntegerValue.h" +#include "IntegerValueFormatter.h" + + +TableCellIntegerEditor::TableCellIntegerEditor(::Value* initialValue, + ValueFormatter* formatter) + : + TableCellTextControlEditor(initialValue, formatter) +{ +} + + +TableCellIntegerEditor::~TableCellIntegerEditor() +{ +} + + +bool +TableCellIntegerEditor::ValidateInput() const +{ + BVariant variantValue; + if (!InitialValue()->ToVariant(variantValue)) + return false; + + return GetValueFormatter()->ValidateFormattedValue(Text(), + variantValue.Type()); +} + + +status_t +TableCellIntegerEditor::GetValueForInput(::Value*& _output) const +{ + BVariant variantValue; + if (!InitialValue()->ToVariant(variantValue)) + return B_NO_MEMORY; + + return GetValueFormatter()->GetValueFromFormattedInput(Text(), + variantValue.Type(), _output); +} + + diff --git a/src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.h b/src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.h new file mode 100644 index 0000000000..c2d688a113 --- /dev/null +++ b/src/apps/debugger/user_interface/gui/value/TableCellIntegerEditor.h @@ -0,0 +1,26 @@ +/* + * Copyright 2015, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#ifndef TABLE_CELL_INTEGER_EDITOR_H +#define TABLE_CELL_INTEGER_EDITOR_H + +#include + +#include "IntegerFormatter.h" +#include "TableCellTextControlEditor.h" + + +class TableCellIntegerEditor : public TableCellTextControlEditor { +public: + TableCellIntegerEditor(::Value* initialValue, + ValueFormatter* formatter); + virtual ~TableCellIntegerEditor(); + + virtual bool ValidateInput() const; + + virtual status_t GetValueForInput(::Value*& _output) const; + // returns reference +}; + +#endif // TABLE_CELL_INTEGER_EDITOR_H