Debugger: Add simple prompt window for adding expressions.

- Requests an expression + type from the user for use elsewhere.
  Intended to be used by VariablesView and possibly others.
This commit is contained in:
Rene Gollent
2014-11-08 10:48:59 -05:00
parent 6a7eaa2a75
commit 0b21bf1038
4 changed files with 237 additions and 0 deletions
+1
View File
@@ -270,6 +270,7 @@ Application Debugger :
BreakpointsView.cpp
ConsoleOutputView.cpp
ExpressionEvaluationWindow.cpp
ExpressionPromptWindow.cpp
ImageFunctionsView.cpp
ImageListView.cpp
RegistersView.cpp
+3
View File
@@ -71,6 +71,9 @@ enum {
MSG_INSPECTOR_WINDOW_CLOSED = 'irwc',
MSG_SHOW_EXPRESSION_WINDOW = 'seww',
MSG_EXPRESSION_WINDOW_CLOSED = 'ewwc',
MSG_SHOW_EXPRESSION_PROMPT_WINDOW = 'sepw',
MSG_ADD_NEW_EXPRESSION = 'anex',
MSG_EXPRESSION_PROMPT_WINDOW_CLOSED = 'epwc',
MSG_INSPECT_ADDRESS = 'isad',
MSG_EVALUATE_EXPRESSION = 'evex',
MSG_EXPRESSION_EVALUATED = 'exev',
@@ -0,0 +1,185 @@
/*
* Copyright 2014, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "ExpressionPromptWindow.h"
#include <Button.h>
#include <LayoutBuilder.h>
#include <MenuField.h>
#include <String.h>
#include <TextControl.h>
#include "MessageCodes.h"
enum {
MSG_CHANGE_EVALUATION_TYPE = 'chet',
};
ExpressionPromptWindow::ExpressionPromptWindow(BHandler* addTarget,
BHandler* closeTarget)
:
BWindow(BRect(), "Add Expression", B_FLOATING_WINDOW,
B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fExpressionInput(NULL),
fCancelButton(NULL),
fAddButton(NULL),
fAddTarget(addTarget),
fCloseTarget(closeTarget),
fCurrentType(B_INT64_TYPE)
{
}
ExpressionPromptWindow::~ExpressionPromptWindow()
{
}
ExpressionPromptWindow*
ExpressionPromptWindow::Create(BHandler* addTarget, BHandler* closeTarget)
{
ExpressionPromptWindow* self = new ExpressionPromptWindow(addTarget,
closeTarget);
try {
self->_Init();
} catch (...) {
delete self;
throw;
}
return self;
}
void
ExpressionPromptWindow::_Init()
{
fExpressionInput = new BTextControl("Expression:", NULL,
new BMessage(MSG_EVALUATE_EXPRESSION));
BLayoutItem* labelItem = fExpressionInput->CreateLabelLayoutItem();
BLayoutItem* inputItem = fExpressionInput->CreateTextViewLayoutItem();
inputItem->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET));
inputItem->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
labelItem->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BMenuField* typeField = new BMenuField("Type:", _BuildTypesMenu());
typeField->Menu()->SetTargetForItems(this);
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(labelItem)
.Add(inputItem)
.Add(typeField->CreateLabelLayoutItem())
.Add(typeField->CreateMenuBarLayoutItem())
.End()
.AddGroup(B_HORIZONTAL, 4.0f)
.AddGlue()
.Add((fCancelButton = new BButton("Cancel",
new BMessage(B_QUIT_REQUESTED))))
.Add((fAddButton = new BButton("Add",
new BMessage(MSG_ADD_NEW_EXPRESSION))))
.End();
fExpressionInput->SetTarget(this);
fCancelButton->SetTarget(this);
fAddButton->SetTarget(this);
fAddButton->MakeDefault(true);
fExpressionInput->TextView()->MakeFocus(true);
}
BMenu*
ExpressionPromptWindow::_BuildTypesMenu()
{
BMenu* menu = new BMenu("Types");
menu->SetLabelFromMarked(true);
BMessage message(MSG_CHANGE_EVALUATION_TYPE);
message.AddInt32("type", B_INT8_TYPE);
menu->AddItem(new BMenuItem("int8", new BMessage(message)));
message.ReplaceInt32("type", B_UINT8_TYPE);
menu->AddItem(new BMenuItem("uint8", new BMessage(message)));
message.ReplaceInt32("type", B_INT16_TYPE);
menu->AddItem(new BMenuItem("int16", new BMessage(message)));
message.ReplaceInt32("type", B_UINT16_TYPE);
menu->AddItem(new BMenuItem("uint16", new BMessage(message)));
message.ReplaceInt32("type", B_INT32_TYPE);
menu->AddItem(new BMenuItem("int32", new BMessage(message)));
message.ReplaceInt32("type", B_UINT32_TYPE);
menu->AddItem(new BMenuItem("uint32", new BMessage(message)));
message.ReplaceInt32("type", B_INT64_TYPE);
BMenuItem* item = new BMenuItem("int64", new BMessage(message));
menu->AddItem(item);
item->SetMarked(true);
message.ReplaceInt32("type", B_UINT64_TYPE);
menu->AddItem(new BMenuItem("uint64", new BMessage(message)));
message.ReplaceInt32("type", B_FLOAT_TYPE);
menu->AddItem(new BMenuItem("float", new BMessage(message)));
message.ReplaceInt32("type", B_DOUBLE_TYPE);
menu->AddItem(new BMenuItem("double", new BMessage(message)));
return menu;
}
void
ExpressionPromptWindow::Show()
{
CenterOnScreen();
BWindow::Show();
}
bool
ExpressionPromptWindow::QuitRequested()
{
BMessenger messenger(fCloseTarget);
messenger.SendMessage(MSG_EXPRESSION_PROMPT_WINDOW_CLOSED);
return BWindow::QuitRequested();
}
void
ExpressionPromptWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_CHANGE_EVALUATION_TYPE:
{
fCurrentType = message->FindInt32("type");
break;
}
case MSG_ADD_NEW_EXPRESSION:
{
BMessage addMessage(message->what);
addMessage.AddString("expression", fExpressionInput->Text());
addMessage.AddInt32("type", fCurrentType);
BMessenger(fAddTarget).SendMessage(&addMessage);
PostMessage(B_QUIT_REQUESTED);
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2014, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef EXPRESSION_PROMPT_WINDOW_H
#define EXPRESSION_PROMPT_WINDOW_H
#include <Window.h>
class BButton;
class BMenu;
class BTextControl;
class ExpressionPromptWindow : public BWindow
{
public:
ExpressionPromptWindow(BHandler* addTarget,
BHandler* closeTarget);
~ExpressionPromptWindow();
static ExpressionPromptWindow* Create(BHandler* addTarget,
BHandler* closeTarget);
// throws
virtual void MessageReceived(BMessage* message);
virtual void Show();
virtual bool QuitRequested();
private:
void _Init();
BMenu* _BuildTypesMenu();
private:
BTextControl* fExpressionInput;
BButton* fCancelButton;
BButton* fAddButton;
BHandler* fAddTarget;
BHandler* fCloseTarget;
type_code fCurrentType;
};
#endif // EXPRESSION_PROMPT_WINDOW_H