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 2009-2010, Philippe Houdoin, [email protected]. All rights reserved.
* Copyright 2013, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -23,6 +24,11 @@
#include "TeamsListView.h" #include "TeamsListView.h"
enum {
MSG_UPDATE_TEAMS_LIST = 'uptl'
};
// #pragma mark - BitmapStringField // #pragma mark - BitmapStringField
@@ -279,10 +285,11 @@ TeamRow::_SetTo(team_info& info)
// #pragma mark - TeamsListView // #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), Inherited(name, 0),
fUpdateRunner(NULL) fUpdateRunner(NULL),
fCurrentTeam(currentTeam)
{ {
AddColumn(new TeamsColumn("Name", 400, 100, 600, AddColumn(new TeamsColumn("Name", 400, 100, 600,
B_TRUNCATE_BEGINNING), kNameColumn); B_TRUNCATE_BEGINNING), kNameColumn);
@@ -295,9 +302,6 @@ TeamsListView::TeamsListView(BRect frame, const char* name)
*/ */
SetSortingEnabled(false); SetSortingEnabled(false);
team_info tmi;
get_team_info(B_CURRENT_TEAM, &tmi);
fThisTeam = tmi.team;
/* /*
#ifdef __HAIKU__ #ifdef __HAIKU__
SetFlags(Flags() | B_SUBPIXEL_PRECISE); SetFlags(Flags() | B_SUBPIXEL_PRECISE);
@@ -322,7 +326,7 @@ TeamsListView::AttachedToWindow()
be_roster->StartWatching(this, B_REQUEST_LAUNCHED | B_REQUEST_QUIT); 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 fUpdateRunner = new BMessageRunner(this, &msg, 100000L); // 10Hz
} }
@@ -345,7 +349,7 @@ void
TeamsListView::MessageReceived(BMessage* message) TeamsListView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kMsgUpdateTeamsList: case MSG_UPDATE_TEAMS_LIST:
_UpdateList(); _UpdateList();
break; break;
@@ -415,7 +419,7 @@ TeamsListView::_InitList()
} }
if (tmi.team == B_SYSTEM_TEAM || if (tmi.team == B_SYSTEM_TEAM ||
tmi.team == fThisTeam) { tmi.team == fCurrentTeam) {
// We don't support debugging kernel and... ourself! // We don't support debugging kernel and... ourself!
row->SetEnabled(false); row->SetEnabled(false);
} }
@@ -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. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
* Rene Gollent
* Philippe Houdoin * Philippe Houdoin
*/ */
#ifndef TEAMS_LIST_ITEM_H #ifndef TEAMS_LIST_ITEM_H
@@ -86,7 +87,8 @@ private:
class TeamsListView : public BColumnListView { class TeamsListView : public BColumnListView {
typedef BColumnListView Inherited; typedef BColumnListView Inherited;
public: public:
TeamsListView(BRect frame, const char* name); TeamsListView(const char* name,
team_id currentTeam);
virtual ~TeamsListView(); virtual ~TeamsListView();
TeamRow* FindTeamRow(team_id teamId); TeamRow* FindTeamRow(team_id teamId);
@@ -103,9 +105,8 @@ private:
private: private:
BMessageRunner* fUpdateRunner; BMessageRunner* fUpdateRunner;
team_id fThisTeam; team_id fCurrentTeam;
}; };
static const uint32 kMsgUpdateTeamsList = 'uptl';
#endif // TEAMS_LIST_VIEW_H #endif // TEAMS_LIST_VIEW_H
@@ -1,5 +1,6 @@
/* /*
* Copyright 2009-2010, Philippe Houdoin, phoudoin@haiku-os.org. All rights reserved. * Copyright 2009-2010, Philippe Houdoin, phoudoin@haiku-os.org. All rights reserved.
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -11,11 +12,13 @@
#include <stdarg.h> #include <stdarg.h>
#include <Application.h> #include <Application.h>
#include <ListView.h> #include <Button.h>
#include <ScrollView.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <Path.h> #include <Path.h>
#include <ScrollView.h>
#include "MessageCodes.h" #include "MessageCodes.h"
#include "SettingsManager.h" #include "SettingsManager.h"
@@ -23,13 +26,24 @@
#include "TeamsListView.h" #include "TeamsListView.h"
enum {
MSG_CREATE_NEW_TEAM = 'crnt',
MSG_TEAM_SELECTION_CHANGED = 'tesc'
};
TeamsWindow::TeamsWindow(SettingsManager* settingsManager) TeamsWindow::TeamsWindow(SettingsManager* settingsManager)
: :
BWindow(BRect(100, 100, 500, 250), "Teams", B_DOCUMENT_WINDOW, BWindow(BRect(100, 100, 500, 250), "Teams", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS), B_ASYNCHRONOUS_CONTROLS),
fTeamsListView(NULL), fTeamsListView(NULL),
fAttachTeamButton(NULL),
fCreateTeamButton(NULL),
fSettingsManager(settingsManager) fSettingsManager(settingsManager)
{ {
team_info info;
get_team_info(B_CURRENT_TEAM, &info);
fCurrentTeam = info.team;
} }
@@ -58,9 +72,16 @@ void
TeamsWindow::MessageReceived(BMessage* message) TeamsWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { 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) { if (row != NULL) {
BMessage message(MSG_DEBUG_THIS_TEAM); BMessage message(MSG_DEBUG_THIS_TEAM);
message.AddInt32("team", row->TeamID()); message.AddInt32("team", row->TeamID());
@@ -69,6 +90,18 @@ TeamsWindow::MessageReceived(BMessage* message)
break; 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: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -101,17 +134,25 @@ TeamsWindow::_Init()
ResizeTo(frame.Width(), frame.Height()); ResizeTo(frame.Width(), frame.Height());
} }
// TODO: add button to start a team debugger BLayoutBuilder::Group<>(this, B_VERTICAL)
// TODO: add UI to setup arguments and environ, launch a program .Add(fTeamsListView = new TeamsListView("TeamsList", fCurrentTeam))
// and start his team debugger .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 fTeamsListView->SetInvocationMessage(new BMessage(MSG_DEBUG_THIS_TEAM));
frame = Bounds(); fTeamsListView->SetSelectionMessage(new BMessage(
frame.InsetBy(-1, -1); MSG_TEAM_SELECTION_CHANGED));
fTeamsListView = new TeamsListView(frame, "TeamsList");
fTeamsListView->SetInvocationMessage(new BMessage(kMsgDebugThisTeam));
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, phoudoin@haiku-os.org. All rights reserved. * Copyright 2009-2010, Philippe Houdoin, phoudoin@haiku-os.org. All rights reserved.
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef TEAMS_WINDOW_H #ifndef TEAMS_WINDOW_H
@@ -8,6 +9,7 @@
#include <Window.h> #include <Window.h>
class BButton;
class BListView; class BListView;
class BFile; class BFile;
class BMessage; class BMessage;
@@ -32,11 +34,13 @@ private:
status_t _SaveSettings(); status_t _SaveSettings();
private: private:
team_id fCurrentTeam;
TeamsListView* fTeamsListView; TeamsListView* fTeamsListView;
BButton* fAttachTeamButton;
BButton* fCreateTeamButton;
SettingsManager* fSettingsManager; SettingsManager* fSettingsManager;
}; };
static const uint32 kMsgDebugThisTeam = 'dbtm';
#endif // TEAMS_WINDOW_H #endif // TEAMS_WINDOW_H