btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / debugger / user_interface / gui / utility_windows / StartTeamWindow.cpp
blob4d2172e44f19b64b5e7f65312fbea7584dfca384
1 /*
2 * Copyright 2013-2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "StartTeamWindow.h"
7 #include <Alert.h>
8 #include <Application.h>
9 #include <Button.h>
10 #include <FilePanel.h>
11 #include <LayoutBuilder.h>
12 #include <Path.h>
13 #include <String.h>
14 #include <StringView.h>
15 #include <TextControl.h>
17 #include "AppMessageCodes.h"
18 #include "UserInterface.h"
21 enum {
22 MSG_BROWSE_TEAM = 'brte',
23 MSG_SET_TEAM_PATH = 'setp'
27 StartTeamWindow::StartTeamWindow(TargetHostInterface* hostInterface)
29 BWindow(BRect(), "Start new team", B_TITLED_WINDOW,
30 B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
31 fGuideText(NULL),
32 fTeamTextControl(NULL),
33 fArgumentsTextControl(NULL),
34 fBrowseTeamButton(NULL),
35 fBrowseTeamPanel(NULL),
36 fStartButton(NULL),
37 fCancelButton(NULL),
38 fTargetHostInterface(hostInterface)
43 StartTeamWindow::~StartTeamWindow()
45 delete fBrowseTeamPanel;
49 StartTeamWindow*
50 StartTeamWindow::Create(TargetHostInterface* hostInterface)
52 StartTeamWindow* self = new StartTeamWindow(hostInterface);
54 try {
55 self->_Init();
56 } catch (...) {
57 delete self;
58 throw;
61 return self;
66 void
67 StartTeamWindow::_Init()
69 fGuideText = new BStringView("guide", "Set new team parameters below.");
70 fTeamTextControl = new BTextControl("Path: ", NULL, NULL);
71 fArgumentsTextControl = new BTextControl("Arguments: ", NULL, NULL);
72 fBrowseTeamButton = new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage(
73 MSG_BROWSE_TEAM));
74 fStartButton = new BButton("Start team", new BMessage(MSG_START_NEW_TEAM));
75 fCancelButton = new BButton("Cancel", new BMessage(B_QUIT_REQUESTED));
77 BLayoutBuilder::Group<>(this, B_VERTICAL)
78 .SetInsets(B_USE_DEFAULT_SPACING)
79 .Add(fGuideText)
80 .AddGroup(B_HORIZONTAL, 4.0f)
81 .Add(fTeamTextControl)
82 .Add(fBrowseTeamButton)
83 .End()
84 .AddGroup(B_HORIZONTAL, 4.0f)
85 .Add(fArgumentsTextControl)
86 .End()
87 .AddGroup(B_HORIZONTAL, 4.0f)
88 .AddGlue()
89 .Add(fCancelButton)
90 .Add(fStartButton)
91 .End();
93 fTeamTextControl->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET));
94 fGuideText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
96 fStartButton->SetTarget(this);
97 fCancelButton->SetTarget(this);
101 void
102 StartTeamWindow::Show()
104 CenterOnScreen();
105 BWindow::Show();
109 void
110 StartTeamWindow::MessageReceived(BMessage* message)
112 switch (message->what) {
113 case MSG_BROWSE_TEAM:
115 if (fBrowseTeamPanel == NULL) {
116 fBrowseTeamPanel = new(std::nothrow) BFilePanel(B_OPEN_PANEL,
117 new BMessenger(this));
118 if (fBrowseTeamPanel == NULL)
119 break;
120 BMessage* message = new(std::nothrow) BMessage(
121 MSG_SET_TEAM_PATH);
122 if (message == NULL) {
123 delete fBrowseTeamPanel;
124 fBrowseTeamPanel = NULL;
125 break;
127 fBrowseTeamPanel->SetMessage(message);
130 fBrowseTeamPanel->Show();
131 break;
133 case MSG_SET_TEAM_PATH:
135 entry_ref ref;
136 if (message->FindRef("refs", &ref) == B_OK) {
137 BPath path(&ref);
138 fTeamTextControl->TextView()->SetText(path.Path());
140 break;
142 case MSG_START_NEW_TEAM:
144 BMessage appMessage(MSG_START_NEW_TEAM);
145 appMessage.AddString("path", fTeamTextControl->TextView()->Text());
146 appMessage.AddString("arguments", fArgumentsTextControl->TextView()
147 ->Text());
148 appMessage.AddPointer("interface", fTargetHostInterface);
149 BMessage reply;
150 be_app_messenger.SendMessage(&appMessage, &reply);
151 status_t error = reply.FindInt32("status");
152 if (error != B_OK) {
153 BString messageString;
154 messageString.SetToFormat("Failed to start team: %s.",
155 strerror(error));
156 BAlert* alert = new(std::nothrow) BAlert("Start team failed",
157 messageString.String(), "Close");
158 if (alert != NULL)
159 alert->Go();
160 } else {
161 be_app->PostMessage(MSG_START_TEAM_WINDOW_CLOSED);
162 PostMessage(B_QUIT_REQUESTED);
164 break;
166 default:
167 BWindow::MessageReceived(message);
168 break;