From 04f0e3d37b9730b5e2934775a4efeaee73d8cf2e Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 2 Nov 2011 21:06:02 +0000 Subject: [PATCH] * Simplify GUITeamUISettings to just use variants mapped by string keys. The Setting classes didn't wind up being quite as useful for that purpose as I'd originally hoped, so they remain with their primary purpose of programmatically generating menus and such. * When GraphicalUserInterface constructs the team window, immediately start the message loop. This allows us to reorder startup so we only activate the user interface after having restored settings. * TeamWindow now saves/restores its frame on a per-team basis. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43131 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/TeamDebugger.cpp | 3 +- .../debugger/settings/GUITeamUISettings.cpp | 64 +++---------------- .../debugger/settings/GUITeamUISettings.h | 10 +-- .../gui/GraphicalUserInterface.cpp | 10 ++- .../gui/team_window/TeamWindow.cpp | 25 ++++++++ .../gui/team_window/TeamWindow.h | 7 ++ 6 files changed, 52 insertions(+), 67 deletions(-) diff --git a/src/apps/debugger/TeamDebugger.cpp b/src/apps/debugger/TeamDebugger.cpp index 0c6225e820..a7d098c721 100644 --- a/src/apps/debugger/TeamDebugger.cpp +++ b/src/apps/debugger/TeamDebugger.cpp @@ -379,8 +379,6 @@ TeamDebugger::Init(team_id teamID, thread_id threadID, bool stopInMain) return error; } - Activate(); - // if requested, stop the given thread if (threadID >= 0) { if (stopInMain) { @@ -548,6 +546,7 @@ TeamDebugger::MessageReceived(BMessage* message) case MSG_LOAD_SETTINGS: _LoadSettings(); + Activate(); break; default: diff --git a/src/apps/debugger/settings/GUITeamUISettings.cpp b/src/apps/debugger/settings/GUITeamUISettings.cpp index e68400a544..f1f5d4654e 100644 --- a/src/apps/debugger/settings/GUITeamUISettings.cpp +++ b/src/apps/debugger/settings/GUITeamUISettings.cpp @@ -64,6 +64,7 @@ GUITeamUISettings::SetTo(const BMessage& archive) status_t GUITeamUISettings::WriteTo(BMessage& archive) const { + archive.MakeEmpty(); status_t error = archive.AddString("ID", fID); if (error != B_OK) return error; @@ -81,7 +82,7 @@ GUITeamUISettings::WriteTo(BMessage& archive) const TeamUISettings* GUITeamUISettings::Clone() const { - GUITeamUISettings* settings = new(std::nothrow) GUITeamUISettings(); + GUITeamUISettings* settings = new(std::nothrow) GUITeamUISettings(fID); if (settings == NULL) return NULL; @@ -95,56 +96,19 @@ GUITeamUISettings::Clone() const } -status_t -GUITeamUISettings::AddSetting(Setting* setting) -{ - if (!fSettings.AddItem(setting)) - return B_NO_MEMORY; - - setting->AcquireReference(); - - return B_OK; -} - - bool -GUITeamUISettings::SetValue(const Setting* setting, const BVariant& value) +GUITeamUISettings::SetValue(const char* settingID, const BVariant& value) { - const char* fieldName = setting->ID(); - fValues.RemoveName(fieldName); + fValues.RemoveName(settingID); - return value.AddToMessage(fValues, fieldName) == B_OK; + return value.AddToMessage(fValues, settingID) == B_OK; } -BVariant -GUITeamUISettings::Value(const Setting* setting) const +status_t +GUITeamUISettings::Value(const char* settingID, BVariant &value) const { - BVariant value; - - return value.SetFromMessage(fValues, setting->ID()) == B_OK ? - value : setting->DefaultValue(); -} - - -BVariant -GUITeamUISettings::Value(const char* settingID) const -{ - BVariant value; - - status_t result = value.SetFromMessage(fValues, settingID); - - if (result != B_OK) { - for (int32 i = 0; i < fSettings.CountItems(); i++) { - Setting* setting = fSettings.ItemAt(i); - if (strcmp(setting->ID(), settingID) == 0) { - value = setting->DefaultValue(); - break; - } - } - } - - return value; + return value.SetFromMessage(fValues, settingID); } @@ -163,13 +127,7 @@ GUITeamUISettings::_SetTo(const GUITeamUISettings& other) { _Unset(); - for (int32 i = 0; i < other.fSettings.CountItems(); i++) { - Setting* setting = other.fSettings.ItemAt(i); - if (!fSettings.AddItem(setting)) - return B_NO_MEMORY; - - setting->AcquireReference(); - } + fID = other.fID; fValues = other.fValues; @@ -182,9 +140,5 @@ GUITeamUISettings::_Unset() { fID.Truncate(0); - for (int32 i = 0; i < fSettings.CountItems(); i++) - fSettings.ItemAt(i)->ReleaseReference(); - - fSettings.MakeEmpty(); fValues.MakeEmpty(); } diff --git a/src/apps/debugger/settings/GUITeamUISettings.h b/src/apps/debugger/settings/GUITeamUISettings.h index 242b043f04..c7999a6d7c 100644 --- a/src/apps/debugger/settings/GUITeamUISettings.h +++ b/src/apps/debugger/settings/GUITeamUISettings.h @@ -30,23 +30,19 @@ public: virtual status_t WriteTo(BMessage& archive) const; virtual TeamUISettings* Clone() const; - status_t AddSetting(Setting* setting); - bool SetValue(const Setting* setting, + bool SetValue(const char* settingID, const BVariant& value); - BVariant Value(const Setting* setting) const; - BVariant Value(const char* settingID) const; + status_t Value(const char* settingID, + BVariant& value) const; GUITeamUISettings& operator=(const GUITeamUISettings& other); // throws std::bad_alloc -private: - typedef BObjectList SettingsList; private: status_t _SetTo(const GUITeamUISettings& other); void _Unset(); - SettingsList fSettings; BMessage fValues; BString fID; }; diff --git a/src/apps/debugger/user_interface/gui/GraphicalUserInterface.cpp b/src/apps/debugger/user_interface/gui/GraphicalUserInterface.cpp index eb0afe63d9..2267f65f45 100644 --- a/src/apps/debugger/user_interface/gui/GraphicalUserInterface.cpp +++ b/src/apps/debugger/user_interface/gui/GraphicalUserInterface.cpp @@ -41,6 +41,10 @@ GraphicalUserInterface::Init(Team* team, UserInterfaceListener* listener) try { fTeamWindow = TeamWindow::Create(team, listener); fTeamWindowMessenger = new BMessenger(fTeamWindow); + + // start the message loop + fTeamWindow->Hide(); + fTeamWindow->Show(); } catch (...) { // TODO: Notify the user! ERROR("Error: Failed to create team window!\n"); @@ -70,9 +74,9 @@ GraphicalUserInterface::Terminate() status_t GraphicalUserInterface::LoadSettings(const TeamUISettings* settings) { - // TODO: restore settings + status_t result = fTeamWindow->LoadSettings((GUITeamUISettings*)settings); - return B_OK; + return result; } @@ -83,7 +87,7 @@ GraphicalUserInterface::SaveSettings(TeamUISettings*& settings) const if (settings == NULL) return B_NO_MEMORY; - // TODO: fill in settings + fTeamWindow->SaveSettings((GUITeamUISettings*)settings); return B_OK; } diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp index 4487797336..65de8569bc 100644 --- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp @@ -30,6 +30,7 @@ #include "CpuState.h" #include "DisassembledCode.h" #include "FileSourceCode.h" +#include "GUITeamUISettings.h" #include "Image.h" #include "ImageDebugInfo.h" #include "InspectorWindow.h" @@ -334,6 +335,30 @@ TeamWindow::QuitRequested() } +status_t +TeamWindow::LoadSettings(const GUITeamUISettings* settings) +{ + BVariant value; + status_t result = settings->Value("teamWindowFrame", value); + if (result == B_OK) { + BRect rect = value.ToRect(); + ResizeTo(rect.Width(), rect.Height()); + MoveTo(rect.left, rect.top); + } + + return B_OK; +} + + +status_t +TeamWindow::SaveSettings(GUITeamUISettings* settings) +{ + status_t error = settings->SetValue("teamWindowFrame", Frame()); + + return error; +} + + void TeamWindow::ThreadSelectionChanged(::Thread* thread) { diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h index 03239ba818..233c0f6ea4 100644 --- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h +++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h @@ -26,6 +26,7 @@ class BButton; class BMenuBar; class BStringView; class BTabView; +class GUITeamUISettings; class Image; class InspectorWindow; class RegistersView; @@ -55,6 +56,12 @@ public: virtual void MessageReceived(BMessage* message); virtual bool QuitRequested(); + status_t LoadSettings( + const GUITeamUISettings* settings); + status_t SaveSettings( + GUITeamUISettings* settings); + + private: enum ActiveSourceObject { ACTIVE_SOURCE_NONE,