Debugger: Change user interface quit and ask user semantics

* UserInterface::SynchronouslyAskUser() is now allowed to return -1 to
  indicate that the user cannot be asked at this point for whatever
  reason. The caller needs to handle that case.
* UserInterfaceListener::UserInterfaceQuitRequested(): Add new parameter
  "quitOption" to specify what is supposed to happen. The previous
  behavior (ask user) is only one of the options. The others are to kill
  the debugged team or to resume it.
This commit is contained in:
Ingo Weinhold 2012-07-27 23:04:16 +02:00
parent f58478507c
commit eba38eb503
4 changed files with 58 additions and 29 deletions

View File

@ -707,39 +707,56 @@ TeamDebugger::InspectRequested(target_addr_t address,
bool
TeamDebugger::UserInterfaceQuitRequested()
TeamDebugger::UserInterfaceQuitRequested(QuitOption quitOption)
{
AutoLocker< ::Team> locker(fTeam);
BString name(fTeam->Name());
locker.Unlock();
bool askUser = false;
switch (quitOption) {
case QUIT_OPTION_ASK_USER:
askUser = true;
break;
BString message;
message << "What shall be done about the debugged team '";
message << name;
message << "'?";
name.Remove(0, name.FindLast('/') + 1);
BString killLabel("Kill ");
killLabel << name;
BString resumeLabel("Resume ");
resumeLabel << name;
int32 choice = fUserInterface->SynchronouslyAskUser("Quit Debugger",
message, killLabel, "Cancel", resumeLabel);
switch (choice) {
case 0:
case QUIT_OPTION_ASK_KILL_TEAM:
fKillTeamOnQuit = true;
break;
case 1:
return false;
case 2:
// Detach from the team and resume and stopped threads.
case QUIT_OPTION_ASK_RESUME_TEAM:
break;
}
if (askUser) {
AutoLocker< ::Team> locker(fTeam);
BString name(fTeam->Name());
locker.Unlock();
BString message;
message << "What shall be done about the debugged team '";
message << name;
message << "'?";
name.Remove(0, name.FindLast('/') + 1);
BString killLabel("Kill ");
killLabel << name;
BString resumeLabel("Resume ");
resumeLabel << name;
int32 choice = fUserInterface->SynchronouslyAskUser("Quit Debugger",
message, killLabel, "Cancel", resumeLabel);
switch (choice) {
case 0:
fKillTeamOnQuit = true;
break;
case 1:
case -1:
return false;
case 2:
// Detach from the team and resume and stopped threads.
break;
}
}
PostMessage(B_QUIT_REQUESTED);
return true;

View File

@ -69,7 +69,8 @@ private:
UserBreakpoint* breakpoint);
virtual void InspectRequested(target_addr_t address,
TeamMemoryBlock::Listener* listener);
virtual bool UserInterfaceQuitRequested();
virtual bool UserInterfaceQuitRequested(
QuitOption quitOption);
// JobListener
virtual void JobDone(Job* job);

View File

@ -61,10 +61,19 @@ public:
const char* message, const char* choice1,
const char* choice2, const char* choice3)
= 0;
// returns -1, if not implemented or user
// cannot be asked
};
class UserInterfaceListener {
public:
enum QuitOption {
QUIT_OPTION_ASK_USER,
QUIT_OPTION_ASK_KILL_TEAM,
QUIT_OPTION_ASK_RESUME_TEAM
};
public:
virtual ~UserInterfaceListener();
@ -95,7 +104,9 @@ public:
target_addr_t address,
TeamMemoryBlock::Listener* listener) = 0;
virtual bool UserInterfaceQuitRequested() = 0;
virtual bool UserInterfaceQuitRequested(
QuitOption quitOption
= QUIT_OPTION_ASK_USER) = 0;
};

View File

@ -207,7 +207,7 @@ CommandLineUserInterface::SynchronouslyAskUser(const char* title,
const char* message, const char* choice1, const char* choice2,
const char* choice3)
{
return 0;
return -1;
}