* ThreadListView:

- Got rid of superfluous SetTeam().
  - Aded SetThread() to select a thread.
* TeamWindow: When a thread hits a debug event and no thread is selected or
  the selected thread is running, select the stopped thread and switch to the
  "Threads" tab view.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31390 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-07-03 12:25:09 +00:00
parent 4e23bc0383
commit e59fc195db
3 changed files with 65 additions and 31 deletions
@@ -27,6 +27,12 @@
#include "StackTraceView.h" #include "StackTraceView.h"
enum {
MAIN_TAB_INDEX_THREADS = 0,
MAIN_TAB_INDEX_IMAGES = 1
};
// #pragma mark - TeamWindow // #pragma mark - TeamWindow
@@ -286,6 +292,8 @@ function, function->GetSourceCode(), function->SourceCodeState());
void void
TeamWindow::_Init() TeamWindow::_Init()
{ {
::Team* team = fDebugModel->GetTeam();
BScrollView* sourceScrollView; BScrollView* sourceScrollView;
BLayoutBuilder::Group<>(this, B_VERTICAL) BLayoutBuilder::Group<>(this, B_VERTICAL)
@@ -317,7 +325,7 @@ TeamWindow::_Init()
threadGroup->SetName("Threads"); threadGroup->SetName("Threads");
fTabView->AddTab(threadGroup); fTabView->AddTab(threadGroup);
BLayoutBuilder::Split<>(threadGroup) BLayoutBuilder::Split<>(threadGroup)
.Add(fThreadListView = ThreadListView::Create(this)) .Add(fThreadListView = ThreadListView::Create(team, this))
.Add(fStackTraceView = StackTraceView::Create(this)); .Add(fStackTraceView = StackTraceView::Create(this));
// add images tab // add images tab
@@ -325,8 +333,7 @@ TeamWindow::_Init()
imagesGroup->SetName("Images"); imagesGroup->SetName("Images");
fTabView->AddTab(imagesGroup); fTabView->AddTab(imagesGroup);
BLayoutBuilder::Split<>(imagesGroup) BLayoutBuilder::Split<>(imagesGroup)
.Add(fImageListView = ImageListView::Create(fDebugModel->GetTeam(), .Add(fImageListView = ImageListView::Create(team, this))
this))
.Add(fImageFunctionsView = ImageFunctionsView::Create(this)); .Add(fImageFunctionsView = ImageFunctionsView::Create(this));
// add local variables tab // add local variables tab
@@ -337,8 +344,6 @@ TeamWindow::_Init()
tab = fRegisterView = RegisterView::Create(fDebugModel->GetArchitecture()); tab = fRegisterView = RegisterView::Create(fDebugModel->GetArchitecture());
fLocalsTabView->AddTab(tab); fLocalsTabView->AddTab(tab);
fThreadListView->SetTeam(fDebugModel->GetTeam());
fRunButton->SetMessage(new BMessage(MSG_THREAD_RUN)); fRunButton->SetMessage(new BMessage(MSG_THREAD_RUN));
fStepOverButton->SetMessage(new BMessage(MSG_THREAD_STEP_OVER)); fStepOverButton->SetMessage(new BMessage(MSG_THREAD_STEP_OVER));
fStepIntoButton->SetMessage(new BMessage(MSG_THREAD_STEP_INTO)); fStepIntoButton->SetMessage(new BMessage(MSG_THREAD_STEP_INTO));
@@ -377,6 +382,8 @@ TeamWindow::_SetActiveThread(::Thread* thread)
locker.Unlock(); locker.Unlock();
fThreadListView->SetThread(fActiveThread);
_SetActiveStackTrace(stackTrace); _SetActiveStackTrace(stackTrace);
_UpdateCpuState(); _UpdateCpuState();
} }
@@ -597,11 +604,28 @@ TeamWindow::_UpdateRunButtons()
void void
TeamWindow::_HandleThreadStateChanged(thread_id threadID) TeamWindow::_HandleThreadStateChanged(thread_id threadID)
{ {
// ATM we're only interested in the currently selected thread AutoLocker<TeamDebugModel> locker(fDebugModel);
if (fActiveThread == NULL || threadID != fActiveThread->ID())
::Thread* thread = fDebugModel->GetTeam()->ThreadByID(threadID);
if (thread == NULL)
return; return;
AutoLocker<TeamDebugModel> locker(fDebugModel); // If the thread has been stopped and we don't have an active thread yet
// (or it isn't stopped), switch to this thread. Otherwise ignore the event.
if (thread->State() == THREAD_STATE_STOPPED
&& (fActiveThread == NULL
|| (thread != fActiveThread
&& fActiveThread->State() != THREAD_STATE_STOPPED))) {
_SetActiveThread(thread);
} else if (thread != fActiveThread) {
// otherwise ignore the event, if the thread is not the active one
return;
}
// Switch to the threads tab view when the thread has stopped.
if (thread->State() == THREAD_STATE_STOPPED)
fTabView->Select(MAIN_TAB_INDEX_THREADS);
_UpdateRunButtons(); _UpdateRunButtons();
} }
@@ -129,10 +129,11 @@ private:
// #pragma mark - ThreadListView // #pragma mark - ThreadListView
ThreadListView::ThreadListView(Listener* listener) ThreadListView::ThreadListView(Team* team, Listener* listener)
: :
BGroupView(B_VERTICAL), BGroupView(B_VERTICAL),
fTeam(NULL), fTeam(team),
fThread(NULL),
fThreadsTable(NULL), fThreadsTable(NULL),
fThreadsTableModel(NULL), fThreadsTableModel(NULL),
fListener(listener) fListener(listener)
@@ -143,16 +144,16 @@ ThreadListView::ThreadListView(Listener* listener)
ThreadListView::~ThreadListView() ThreadListView::~ThreadListView()
{ {
SetTeam(NULL); fTeam->RemoveListener(this);
fThreadsTable->SetTableModel(NULL); fThreadsTable->SetTableModel(NULL);
delete fThreadsTableModel; delete fThreadsTableModel;
} }
/*static*/ ThreadListView* /*static*/ ThreadListView*
ThreadListView::Create(Listener* listener) ThreadListView::Create(Team* team, Listener* listener)
{ {
ThreadListView* self = new ThreadListView(listener); ThreadListView* self = new ThreadListView(team, listener);
try { try {
self->_Init(); self->_Init();
@@ -173,26 +174,29 @@ ThreadListView::UnsetListener()
void void
ThreadListView::SetTeam(Team* team) ThreadListView::SetThread(Thread* thread)
{ {
if (team == fTeam) if (thread == fThread)
return; return;
if (fTeam != NULL) { if (fThread != NULL)
fTeam->RemoveListener(this); fThread->ReleaseReference();
fThreadsTable->SetTableModel(NULL);
delete fThreadsTableModel; fThread = thread;
fThreadsTableModel = NULL;
if (fThread != NULL) {
fThread->AcquireReference();
for (int32 i = 0; Thread* other = fThreadsTableModel->ThreadAt(i);
i++) {
if (fThread == other) {
fThreadsTable->SelectRow(i, false);
return;
}
}
} }
fTeam = team; fThreadsTable->DeselectAllRows();
if (fTeam != NULL) {
fThreadsTableModel = new(std::nothrow) ThreadsTableModel(fTeam);
fThreadsTable->SetTableModel(fThreadsTableModel);
fThreadsTable->ResizeAllColumnsToPreferred();
fTeam->AddListener(this);
}
} }
@@ -256,6 +260,11 @@ ThreadListView::_Init()
fThreadsTable->SetSelectionMode(B_SINGLE_SELECTION_LIST); fThreadsTable->SetSelectionMode(B_SINGLE_SELECTION_LIST);
fThreadsTable->AddTableListener(this); fThreadsTable->AddTableListener(this);
fThreadsTableModel = new(std::nothrow) ThreadsTableModel(fTeam);
fThreadsTable->SetTableModel(fThreadsTableModel);
fThreadsTable->ResizeAllColumnsToPreferred();
fTeam->AddListener(this);
} }
@@ -20,15 +20,15 @@ public:
class Listener; class Listener;
public: public:
ThreadListView(Listener* listener); ThreadListView(Team* team, Listener* listener);
~ThreadListView(); ~ThreadListView();
static ThreadListView* Create(Listener* listener); static ThreadListView* Create(Team* team, Listener* listener);
// throws // throws
void UnsetListener(); void UnsetListener();
void SetTeam(Team* team); void SetThread(Thread* thread);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@@ -47,6 +47,7 @@ private:
private: private:
Team* fTeam; Team* fTeam;
Thread* fThread;
Table* fThreadsTable; Table* fThreadsTable;
ThreadsTableModel* fThreadsTableModel; ThreadsTableModel* fThreadsTableModel;
Listener* fListener; Listener* fListener;