2 * Copyright 2013-2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
5 #include "StartTeamWindow.h"
8 #include <Application.h>
10 #include <FilePanel.h>
11 #include <LayoutBuilder.h>
14 #include <StringView.h>
15 #include <TextControl.h>
17 #include "AppMessageCodes.h"
18 #include "UserInterface.h"
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
),
32 fTeamTextControl(NULL
),
33 fArgumentsTextControl(NULL
),
34 fBrowseTeamButton(NULL
),
35 fBrowseTeamPanel(NULL
),
38 fTargetHostInterface(hostInterface
)
43 StartTeamWindow::~StartTeamWindow()
45 delete fBrowseTeamPanel
;
50 StartTeamWindow::Create(TargetHostInterface
* hostInterface
)
52 StartTeamWindow
* self
= new StartTeamWindow(hostInterface
);
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(
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
)
80 .AddGroup(B_HORIZONTAL
, 4.0f
)
81 .Add(fTeamTextControl
)
82 .Add(fBrowseTeamButton
)
84 .AddGroup(B_HORIZONTAL
, 4.0f
)
85 .Add(fArgumentsTextControl
)
87 .AddGroup(B_HORIZONTAL
, 4.0f
)
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);
102 StartTeamWindow::Show()
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
)
120 BMessage
* message
= new(std::nothrow
) BMessage(
122 if (message
== NULL
) {
123 delete fBrowseTeamPanel
;
124 fBrowseTeamPanel
= NULL
;
127 fBrowseTeamPanel
->SetMessage(message
);
130 fBrowseTeamPanel
->Show();
133 case MSG_SET_TEAM_PATH
:
136 if (message
->FindRef("refs", &ref
) == B_OK
) {
138 fTeamTextControl
->TextView()->SetText(path
.Path());
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()
148 appMessage
.AddPointer("interface", fTargetHostInterface
);
150 be_app_messenger
.SendMessage(&appMessage
, &reply
);
151 status_t error
= reply
.FindInt32("status");
153 BString messageString
;
154 messageString
.SetToFormat("Failed to start team: %s.",
156 BAlert
* alert
= new(std::nothrow
) BAlert("Start team failed",
157 messageString
.String(), "Close");
161 be_app
->PostMessage(MSG_START_TEAM_WINDOW_CLOSED
);
162 PostMessage(B_QUIT_REQUESTED
);
167 BWindow::MessageReceived(message
);