Various cleanups to Teams window.

- Convert to using layout APIs.
- Add buttons to attach to an existing team or create a new one (not
  implemented yet).
- Various minor style cleanups.
This commit is contained in:
Rene Gollent
2013-05-02 22:02:52 -04:00
parent a56ddb2bea
commit 12abf3b280
4 changed files with 86 additions and 36 deletions
@@ -1,5 +1,6 @@
/*
* Copyright 2009-2010, Philippe Houdoin, [email protected]. All rights reserved.
* Copyright 2013, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -23,6 +24,11 @@
#include "TeamsListView.h"
enum {
MSG_UPDATE_TEAMS_LIST = 'uptl'
};
// #pragma mark - BitmapStringField
@@ -204,17 +210,17 @@ TeamRow::TeamRow(team_id team)
bool
TeamRow::NeedsUpdate(team_info& info)
{
// Check if we need to rebuilt the row's fields because the team critical
// Check if we need to rebuilt the row's fields because the team critical
// info (basically, app image running under that team ID) has changed
if (info.argc != fTeamInfo.argc
if (info.argc != fTeamInfo.argc
|| strncmp(info.args, fTeamInfo.args, sizeof(fTeamInfo.args)) != 0) {
_SetTo(info);
return true;
}
return false;
}
}
status_t
@@ -227,12 +233,12 @@ TeamRow::_SetTo(team_info& info)
len >= 0 && teamInfo.args[len] == ' '; len--) {
teamInfo.args[len] = 0;
}
app_info appInfo;
status_t status = be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
if (status != B_OK) {
// Not an application known to be_roster
if (teamInfo.team == B_SYSTEM_TEAM) {
// Get icon and name from kernel image
system_info systemInfo;
@@ -243,7 +249,7 @@ TeamRow::_SetTo(team_info& info)
kernelPath.Append(systemInfo.kernel_name);
get_ref_for_path(kernelPath.Path(), &appInfo.ref);
} else
BPrivate::get_app_ref(teamInfo.team, &appInfo.ref);
}
@@ -279,10 +285,11 @@ TeamRow::_SetTo(team_info& info)
// #pragma mark - TeamsListView
TeamsListView::TeamsListView(BRect frame, const char* name)
TeamsListView::TeamsListView(const char* name, team_id currentTeam)
:
Inherited(frame, name, B_FOLLOW_ALL, 0, B_NO_BORDER, true),
fUpdateRunner(NULL)
Inherited(name, 0),
fUpdateRunner(NULL),
fCurrentTeam(currentTeam)
{
AddColumn(new TeamsColumn("Name", 400, 100, 600,
B_TRUNCATE_BEGINNING), kNameColumn);
@@ -295,9 +302,6 @@ TeamsListView::TeamsListView(BRect frame, const char* name)
*/
SetSortingEnabled(false);
team_info tmi;
get_team_info(B_CURRENT_TEAM, &tmi);
fThisTeam = tmi.team;
/*
#ifdef __HAIKU__
SetFlags(Flags() | B_SUBPIXEL_PRECISE);
@@ -322,7 +326,7 @@ TeamsListView::AttachedToWindow()
be_roster->StartWatching(this, B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
BMessage msg(kMsgUpdateTeamsList);
BMessage msg(MSG_UPDATE_TEAMS_LIST);
fUpdateRunner = new BMessageRunner(this, &msg, 100000L); // 10Hz
}
@@ -345,7 +349,7 @@ void
TeamsListView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kMsgUpdateTeamsList:
case MSG_UPDATE_TEAMS_LIST:
_UpdateList();
break;
@@ -415,7 +419,7 @@ TeamsListView::_InitList()
}
if (tmi.team == B_SYSTEM_TEAM ||
tmi.team == fThisTeam) {
tmi.team == fCurrentTeam) {
// We don't support debugging kernel and... ourself!
row->SetEnabled(false);
}
@@ -445,7 +449,7 @@ TeamsListView::_UpdateList()
if (row != NULL && tmi.team == row->TeamID()
&& row->NeedsUpdate(tmi)) {
// The team image app could have change due after an exec*() call,
// The team image app could have change due after an exec*() call,
UpdateRow(row);
} else if (row == NULL || tmi.team != row->TeamID()) {
// Team not found in previously known teams list: insert a new row
@@ -1,8 +1,9 @@
/*
* Copyright 2009-2010 Haiku Inc. All rights reserved.
* Copyright 2009-2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Rene Gollent
* Philippe Houdoin
*/
#ifndef TEAMS_LIST_ITEM_H
@@ -86,7 +87,8 @@ private:
class TeamsListView : public BColumnListView {
typedef BColumnListView Inherited;
public:
TeamsListView(BRect frame, const char* name);
TeamsListView(const char* name,
team_id currentTeam);
virtual ~TeamsListView();
TeamRow* FindTeamRow(team_id teamId);
@@ -103,9 +105,8 @@ private:
private:
BMessageRunner* fUpdateRunner;
team_id fThisTeam;
team_id fCurrentTeam;
};
static const uint32 kMsgUpdateTeamsList = 'uptl';
#endif // TEAMS_LIST_VIEW_H
@@ -1,5 +1,6 @@
/*
* Copyright 2009-2010, Philippe Houdoin, [email protected]. All rights reserved.
* Copyright 2013, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -11,11 +12,13 @@
#include <stdarg.h>
#include <Application.h>
#include <ListView.h>
#include <ScrollView.h>
#include <Button.h>
#include <File.h>
#include <FindDirectory.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <Path.h>
#include <ScrollView.h>
#include "MessageCodes.h"
#include "SettingsManager.h"
@@ -23,13 +26,24 @@
#include "TeamsListView.h"
enum {
MSG_CREATE_NEW_TEAM = 'crnt',
MSG_TEAM_SELECTION_CHANGED = 'tesc'
};
TeamsWindow::TeamsWindow(SettingsManager* settingsManager)
:
BWindow(BRect(100, 100, 500, 250), "Teams", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS),
fTeamsListView(NULL),
fAttachTeamButton(NULL),
fCreateTeamButton(NULL),
fSettingsManager(settingsManager)
{
team_info info;
get_team_info(B_CURRENT_TEAM, &info);
fCurrentTeam = info.team;
}
@@ -58,9 +72,16 @@ void
TeamsWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case kMsgDebugThisTeam:
case MSG_CREATE_NEW_TEAM:
{
TeamRow* row = dynamic_cast<TeamRow*>(fTeamsListView->CurrentSelection());
// TODO: implement
break;
}
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());
@@ -69,6 +90,18 @@ TeamsWindow::MessageReceived(BMessage* message)
break;
}
case MSG_TEAM_SELECTION_CHANGED:
{
TeamRow* row = dynamic_cast<TeamRow*>(
fTeamsListView->CurrentSelection());
bool enabled = false;
if (row != NULL && row->TeamID() != fCurrentTeam)
enabled = true;
fAttachTeamButton->SetEnabled(enabled);
break;
}
default:
BWindow::MessageReceived(message);
break;
@@ -101,17 +134,25 @@ TeamsWindow::_Init()
ResizeTo(frame.Width(), frame.Height());
}
// TODO: add button to start a team debugger
// TODO: add UI to setup arguments and environ, launch a program
// and start his team debugger
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(fTeamsListView = new TeamsListView("TeamsList", fCurrentTeam))
.SetInsets(1.0f, 1.0f, 1.0f, 1.0f)
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(fAttachTeamButton = new BButton("Attach"))
.Add(fCreateTeamButton = new BButton("Create new team"
B_UTF8_ELLIPSIS))
.End()
.End();
// Add a teams list view
frame = Bounds();
frame.InsetBy(-1, -1);
fTeamsListView = new TeamsListView(frame, "TeamsList");
fTeamsListView->SetInvocationMessage(new BMessage(kMsgDebugThisTeam));
fTeamsListView->SetInvocationMessage(new BMessage(MSG_DEBUG_THIS_TEAM));
fTeamsListView->SetSelectionMessage(new BMessage(
MSG_TEAM_SELECTION_CHANGED));
AddChild(fTeamsListView);
fAttachTeamButton->SetMessage(new BMessage(MSG_DEBUG_THIS_TEAM));
fAttachTeamButton->SetEnabled(false);
fCreateTeamButton->SetMessage(new BMessage(MSG_CREATE_NEW_TEAM));
// TODO: re-enable once action is implemented
fAttachTeamButton->SetEnabled(false);
}
@@ -1,5 +1,6 @@
/*
* Copyright 2009-2010, Philippe Houdoin, [email protected]. All rights reserved.
* Copyright 2013, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef TEAMS_WINDOW_H
@@ -8,6 +9,7 @@
#include <Window.h>
class BButton;
class BListView;
class BFile;
class BMessage;
@@ -32,11 +34,13 @@ private:
status_t _SaveSettings();
private:
team_id fCurrentTeam;
TeamsListView* fTeamsListView;
BButton* fAttachTeamButton;
BButton* fCreateTeamButton;
SettingsManager* fSettingsManager;
};
static const uint32 kMsgDebugThisTeam = 'dbtm';
#endif // TEAMS_WINDOW_H