Files
haiku-beta6/src/apps/debugger/user_interface/gui/teams_window/TeamsWindow.cpp
T
Rene Gollent d9e4b4cec5 Debugger: Add initial version of TargetHostInterfaceRoster.
TargetHostInterfaceRoster:
- Provides a singleton interface to enumerate both the available interface
  types, and all currently running instances. This will provide clients like
  the TeamsWindow with a way to present the user with all available types,
  as well as the necessary information to configure/instantiate them.

TargetHostInterfaceInfo:
- Provides an information object for each available type of interface,
  including an optional description of the settings needed to configure it.
  Callers can then use this to provide a configuration UI as needed, and
  once complete, request a corresponding interface instance for the desired
  configuration.

{Local}TargetHostInterface:
- Add Settings parameter to Init(). Adjust LocalTargetHostInterface
  accordingly.

LocalTargetHostInterfaceInfo:
- Implementation of TargetHostInterfaceInfo for the local system case.
2016-04-10 17:03:10 -04:00

227 lines
4.6 KiB
C++

/*
* Copyright 2009-2010, Philippe Houdoin, [email protected]. All rights reserved.
* Copyright 2013-2016, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "TeamsWindow.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <Application.h>
#include <Button.h>
#include <File.h>
#include <FindDirectory.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <Path.h>
#include <Screen.h>
#include <ScrollView.h>
#include "MessageCodes.h"
#include "SettingsManager.h"
#include "LocalTargetHostInterface.h"
#include "TeamsListView.h"
enum {
MSG_TEAM_SELECTION_CHANGED = 'tesc'
};
TeamsWindow::TeamsWindow(SettingsManager* settingsManager)
:
BWindow(BRect(100, 100, 500, 250), "Teams", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS),
fTargetHostInterface(NULL),
fTeamsListView(NULL),
fAttachTeamButton(NULL),
fCreateTeamButton(NULL),
fSettingsManager(settingsManager)
{
team_info info;
get_team_info(B_CURRENT_TEAM, &info);
fCurrentTeam = info.team;
}
TeamsWindow::~TeamsWindow()
{
if (fTargetHostInterface != NULL)
fTargetHostInterface->ReleaseReference();
}
/*static*/ TeamsWindow*
TeamsWindow::Create(SettingsManager* settingsManager)
{
TeamsWindow* self = new TeamsWindow(settingsManager);
try {
self->_Init();
} catch (...) {
delete self;
throw;
}
return self;
}
void
TeamsWindow::Zoom(BPoint, float, float)
{
BSize preferredSize = fTeamsListView->PreferredSize();
ResizeBy(preferredSize.Width() - Bounds().Width(),
0.0);
// if the new size would extend us past the screen border,
// move sufficiently to the left to bring us back within the bounds
// + a bit of extra margin so we're not flush against the edge.
BScreen screen;
float offset = screen.Frame().right - Frame().right;
if (offset < 0)
MoveBy(offset - 5.0, 0.0);
}
void
TeamsWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_DEBUG_THIS_TEAM:
{
TeamRow* row = dynamic_cast<TeamRow*>(
fTeamsListView->CurrentSelection());
if (row != NULL) {
BMessage message(MSG_DEBUG_THIS_TEAM);
message.AddInt32("team", row->TeamID());
be_app_messenger.SendMessage(&message);
}
break;
}
case MSG_TEAM_SELECTION_CHANGED:
{
TeamRow* row = dynamic_cast<TeamRow*>(
fTeamsListView->CurrentSelection());
bool enabled = false;
if (row != NULL) {
team_id id = row->TeamID();
if (id != fCurrentTeam && id != B_SYSTEM_TEAM)
enabled = true;
}
fAttachTeamButton->SetEnabled(enabled);
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}
bool
TeamsWindow::QuitRequested()
{
_SaveSettings();
be_app_messenger.SendMessage(MSG_TEAMS_WINDOW_CLOSED);
return true;
}
// #pragma mark --
void
TeamsWindow::_Init()
{
BMessage settings;
_LoadSettings(settings);
fTargetHostInterface = new LocalTargetHostInterface();
if (fTargetHostInterface->Init(NULL) != B_OK)
throw std::bad_alloc();
BRect frame;
if (settings.FindRect("teams window frame", &frame) == B_OK) {
MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height());
}
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(fTeamsListView = new TeamsListView("TeamsList", fCurrentTeam,
fTargetHostInterface))
.SetInsets(1.0f, 1.0f, 1.0f, 1.0f)
.AddGroup(B_HORIZONTAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(fAttachTeamButton = new BButton("Attach", new BMessage(
MSG_DEBUG_THIS_TEAM)))
.Add(fCreateTeamButton = new BButton("Start new team"
B_UTF8_ELLIPSIS, new BMessage(MSG_SHOW_START_TEAM_WINDOW)))
.End()
.End();
fTeamsListView->SetInvocationMessage(new BMessage(MSG_DEBUG_THIS_TEAM));
fTeamsListView->SetSelectionMessage(new BMessage(
MSG_TEAM_SELECTION_CHANGED));
fAttachTeamButton->SetEnabled(false);
fCreateTeamButton->SetTarget(be_app);
}
status_t
TeamsWindow::_OpenSettings(BFile& file, uint32 mode)
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return B_ERROR;
path.Append("Debugger settings");
return file.SetTo(path.Path(), mode);
}
status_t
TeamsWindow::_LoadSettings(BMessage& settings)
{
BFile file;
status_t status = _OpenSettings(file, B_READ_ONLY);
if (status < B_OK)
return status;
return settings.Unflatten(&file);
}
status_t
TeamsWindow::_SaveSettings()
{
BFile file;
status_t status = _OpenSettings(file,
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (status < B_OK)
return status;
BMessage settings('hdbg');
status = settings.AddRect("teams window frame", Frame());
if (status != B_OK)
return status;
if (status == B_OK)
status = settings.Flatten(&file);
return status;
}