From 1953ec9d1da2b88831fdb8de66e7c84c023ea9bb Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 3 May 2013 20:14:13 -0400 Subject: [PATCH] Add UI window for starting a new team. --- src/apps/debugger/Jamfile | 1 + src/apps/debugger/MessageCodes.h | 1 + .../gui/teams_window/StartTeamWindow.cpp | 163 ++++++++++++++++++ .../gui/teams_window/StartTeamWindow.h | 47 +++++ 4 files changed, 212 insertions(+) create mode 100644 src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.cpp create mode 100644 src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index caa8f1caef..0f5eab137c 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -227,6 +227,7 @@ Application Debugger : MemoryView.cpp # user_interface/gui/teams_window + StartTeamWindow.cpp TeamsWindow.cpp TeamsListView.cpp diff --git a/src/apps/debugger/MessageCodes.h b/src/apps/debugger/MessageCodes.h index 7eba27d74f..f35929fde1 100644 --- a/src/apps/debugger/MessageCodes.h +++ b/src/apps/debugger/MessageCodes.h @@ -49,6 +49,7 @@ enum { MSG_TEAM_DEBUGGER_QUIT = 'dbqt', MSG_SHOW_TEAMS_WINDOW = 'stsw', MSG_TEAMS_WINDOW_CLOSED = 'tswc', + MSG_START_NEW_TEAM = 'sttt', MSG_DEBUG_THIS_TEAM = 'dbtt', MSG_SHOW_INSPECTOR_WINDOW = 'sirw', MSG_INSPECTOR_WINDOW_CLOSED = 'irwc', diff --git a/src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.cpp b/src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.cpp new file mode 100644 index 0000000000..26a798aeb2 --- /dev/null +++ b/src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.cpp @@ -0,0 +1,163 @@ +/* + * Copyright 2013, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#include "StartTeamWindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "MessageCodes.h" +#include "UserInterface.h" + + +enum { + MSG_BROWSE_TEAM = 'brte', + MSG_SET_TEAM_PATH = 'setp' +}; + + +StartTeamWindow::StartTeamWindow() + : + BWindow(BRect(), "Start new team", B_TITLED_WINDOW, + B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), + fGuideText(NULL), + fTeamTextControl(NULL), + fArgumentsTextControl(NULL), + fBrowseTeamButton(NULL), + fBrowseTeamPanel(NULL), + fStartButton(NULL), + fCancelButton(NULL) +{ +} + + +StartTeamWindow::~StartTeamWindow() +{ + delete fBrowseTeamPanel; +} + + +StartTeamWindow* +StartTeamWindow::Create() +{ + StartTeamWindow* self = new StartTeamWindow; + + try { + self->_Init(); + } catch (...) { + delete self; + throw; + } + + return self; + +} + +void +StartTeamWindow::_Init() +{ + fGuideText = new BStringView("guide", "Set new team parameters below."); + fTeamTextControl = new BTextControl("Path: ", NULL, NULL); + fArgumentsTextControl = new BTextControl("Arguments: ", NULL, NULL); + fBrowseTeamButton = new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage( + MSG_BROWSE_TEAM)); + fStartButton = new BButton("Start team", new BMessage(MSG_START_NEW_TEAM)); + fCancelButton = new BButton("Cancel", new BMessage(B_QUIT_REQUESTED)); + + BLayoutBuilder::Group<>(this, B_VERTICAL) + .SetInsets(4.0f, 4.0f, 4.0f, 4.0f) + .Add(fGuideText) + .AddGroup(B_HORIZONTAL, 4.0f) + .Add(fTeamTextControl) + .Add(fBrowseTeamButton) + .End() + .AddGroup(B_HORIZONTAL, 4.0f) + .Add(fArgumentsTextControl) + .End() + .AddGroup(B_HORIZONTAL, 4.0f) + .AddGlue() + .Add(fCancelButton) + .Add(fStartButton) + .End(); + + fTeamTextControl->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET)); + + fStartButton->SetTarget(this); + fCancelButton->SetTarget(this); +} + +void +StartTeamWindow::Show() +{ + CenterOnScreen(); + BWindow::Show(); +} + +void +StartTeamWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_BROWSE_TEAM: + { + if (fBrowseTeamPanel == NULL) { + fBrowseTeamPanel = new(std::nothrow) BFilePanel(B_OPEN_PANEL, + new BMessenger(this)); + if (fBrowseTeamPanel == NULL) + break; + BMessage* message = new(std::nothrow) BMessage( + MSG_SET_TEAM_PATH); + if (message == NULL) { + delete fBrowseTeamPanel; + fBrowseTeamPanel = NULL; + break; + } + fBrowseTeamPanel->SetMessage(message); + } + + fBrowseTeamPanel->Show(); + break; + } + case MSG_SET_TEAM_PATH: + { + entry_ref ref; + if (message->FindRef("refs", &ref) == B_OK) { + BPath path(&ref); + fTeamTextControl->TextView()->SetText(path.Path()); + } + break; + } + case MSG_START_NEW_TEAM: + { + BMessage appMessage(MSG_START_NEW_TEAM); + appMessage.AddString("path", fTeamTextControl->TextView()->Text()); + appMessage.AddString("arguments", fArgumentsTextControl->TextView() + ->Text()); + BMessage reply; + be_app_messenger.SendMessage(&appMessage, &reply); + status_t error = reply.FindInt32("status"); + if (error != B_OK) { + BString messageString; + messageString.SetToFormat("Failed to start team: %s.", + strerror(error)); + BAlert* alert = new(std::nothrow) BAlert("Start team failed", + messageString.String(), "Close"); + if (alert != NULL) + alert->Go(); + } else + PostMessage(B_QUIT_REQUESTED); + break; + } + default: + BWindow::MessageReceived(message); + break; + } + +} diff --git a/src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.h b/src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.h new file mode 100644 index 0000000000..c81059e7b8 --- /dev/null +++ b/src/apps/debugger/user_interface/gui/teams_window/StartTeamWindow.h @@ -0,0 +1,47 @@ +/* + * Copyright 2013, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#ifndef START_TEAM_WINDOW_H +#define START_TEAM_WINDOW_H + + +#include + + +class BButton; +class BFilePanel; +class BStringView; +class BTextControl; + + +class StartTeamWindow : public BWindow +{ +public: + StartTeamWindow(); + + ~StartTeamWindow(); + + static StartTeamWindow* Create(); + // throws + + + virtual void MessageReceived(BMessage* message); + + virtual void Show(); + +private: + void _Init(); + + +private: + BStringView* fGuideText; + BTextControl* fTeamTextControl; + BTextControl* fArgumentsTextControl; + BButton* fBrowseTeamButton; + BFilePanel* fBrowseTeamPanel; + BButton* fStartButton; + BButton* fCancelButton; +}; + +#endif // START_TEAM_WINDOW_H