Reworked GUI settings storage.

- Simplified things so each window simply records all its settings into
  a BMessage, which is what ultimately goes into the actual UI settings.

- Added settings storage/retrieval to the various sub views of the
  team window. This means that the column widths/positioning on all
  views hosting a column list view are now also preserved and restored.
This commit is contained in:
Rene Gollent 2011-11-19 18:14:45 -05:00
parent 79dbafbc66
commit 11102e3848
19 changed files with 378 additions and 73 deletions

View File

@ -267,7 +267,7 @@ bool
InspectorWindow::QuitRequested()
{
BMessage settings(MSG_INSPECTOR_WINDOW_CLOSED);
SaveSettings(&settings);
SaveSettings(settings);
BMessenger(fTarget).SendMessage(&settings);
return true;
@ -288,35 +288,40 @@ InspectorWindow::MemoryBlockRetrieved(TeamMemoryBlock* block)
status_t
InspectorWindow::LoadSettings(const GUITeamUISettings* settings)
InspectorWindow::LoadSettings(const GUITeamUISettings& settings)
{
AutoLocker<BLooper> lock(this);
if (!lock.IsLocked())
return B_ERROR;
BVariant value;
if (settings->Value("inspectorWindowFrame", value) == B_OK) {
BRect frameRect = value.ToRect();
BMessage inspectorSettings;
if (settings.Settings("inspectorWindow", inspectorSettings) == B_OK)
return B_OK;
BRect frameRect;
if (inspectorSettings.FindRect("frame", &frameRect) == B_OK) {
ResizeTo(frameRect.Width(), frameRect.Height());
MoveTo(frameRect.left, frameRect.top);
}
_LoadMenuFieldMode(fHexMode, "Hex", settings);
_LoadMenuFieldMode(fEndianMode, "Endian", settings);
_LoadMenuFieldMode(fTextMode, "Text", settings);
_LoadMenuFieldMode(fHexMode, "Hex", inspectorSettings);
_LoadMenuFieldMode(fEndianMode, "Endian", inspectorSettings);
_LoadMenuFieldMode(fTextMode, "Text", inspectorSettings);
return B_OK;
}
status_t
InspectorWindow::SaveSettings(BMessage* settings)
InspectorWindow::SaveSettings(BMessage& settings)
{
AutoLocker<BLooper> lock(this);
if (!lock.IsLocked())
return B_ERROR;
status_t error = settings->AddRect("inspectorWindowFrame", Frame());
settings.MakeEmpty();
status_t error = settings.AddRect("frame", Frame());
if (error != B_OK)
return error;
@ -338,17 +343,16 @@ InspectorWindow::SaveSettings(BMessage* settings)
void
InspectorWindow::_LoadMenuFieldMode(BMenuField* field, const char* name,
const GUITeamUISettings* settings)
const BMessage& settings)
{
BVariant value;
BString fieldName;
fieldName.SetToFormat("inspectorWindow%sMode", name);
status_t error = settings->Value(fieldName.String(), value);
if (error == B_OK) {
int32 mode;
fieldName.SetToFormat("%sMode", name);
if (settings.FindInt32(fieldName.String(), &mode) == B_OK) {
BMenu* menu = field->Menu();
for (int32 i = 0; i < menu->CountItems(); i++) {
BInvoker* item = menu->ItemAt(i);
if (item->Message()->FindInt32("mode") == value.ToInt32()) {
if (item->Message()->FindInt32("mode") == mode) {
item->Invoke();
break;
}
@ -359,14 +363,14 @@ InspectorWindow::_LoadMenuFieldMode(BMenuField* field, const char* name,
status_t
InspectorWindow::_SaveMenuFieldMode(BMenuField* field, const char* name,
BMessage* settings)
BMessage& settings)
{
BMenuItem* item = field->Menu()->FindMarked();
if (item && item->Message()) {
int32 mode = item->Message()->FindInt32("mode");
BString fieldName;
fieldName.SetToFormat("inspectorWindow%sMode", name);
return settings->AddInt32(fieldName.String(), mode);
fieldName.SetToFormat("%sMode", name);
return settings.AddInt32(fieldName.String(), mode);
}
return B_OK;

View File

@ -41,18 +41,18 @@ public:
virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);
status_t LoadSettings(
const GUITeamUISettings* settings);
const GUITeamUISettings& settings);
status_t SaveSettings(
BMessage* settings);
BMessage& settings);
private:
void _Init();
void _LoadMenuFieldMode(BMenuField* field,
const char* name,
const GUITeamUISettings* settings);
const BMessage& settings);
status_t _SaveMenuFieldMode(BMenuField* field,
const char* name,
BMessage* settings);
BMessage& settings);
private:
UserInterfaceListener* fListener;

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -14,6 +15,7 @@
#include <ObjectList.h>
#include "FunctionID.h"
#include "GUISettingsUtils.h"
#include "LocatableFile.h"
#include "table/TableColumns.h"
#include "Team.h"
@ -234,6 +236,32 @@ BreakpointListView::UserBreakpointChanged(UserBreakpoint* breakpoint)
}
void
BreakpointListView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("breakpointsTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fBreakpointsTable);
}
}
status_t
BreakpointListView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fBreakpointsTable);
if (result == B_OK)
result = settings.AddMessage("breakpointsTable", &tableSettings);
return result;
}
void
BreakpointListView::TableSelectionChanged(Table* table)
{

View File

@ -33,6 +33,9 @@ public:
void UserBreakpointChanged(
UserBreakpoint* breakpoint);
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
class BreakpointsTableModel;

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -126,6 +127,30 @@ BreakpointsView::AttachedToWindow()
}
void
BreakpointsView::LoadSettings(const BMessage& settings)
{
BMessage breakpointListSettings;
if (settings.FindMessage("breakpointList", &breakpointListSettings)
== B_OK)
fListView->LoadSettings(breakpointListSettings);
}
status_t
BreakpointsView::SaveSettings(BMessage& settings)
{
BMessage breakpointListSettings;
if (fListView->SaveSettings(breakpointListSettings) != B_OK)
return B_NO_MEMORY;
if (settings.AddMessage("breakpointList", &breakpointListSettings) != B_OK)
return B_NO_MEMORY;
return B_OK;
}
void
BreakpointsView::BreakpointSelectionChanged(UserBreakpoint* breakpoint)
{

View File

@ -35,6 +35,9 @@ public:
virtual void MessageReceived(BMessage* message);
virtual void AttachedToWindow();
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
// BreakpointListView::Listener
virtual void BreakpointSelectionChanged(

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -15,6 +16,7 @@
#include "table/TableColumns.h"
#include "FunctionInstance.h"
#include "GUISettingsUtils.h"
#include "Image.h"
#include "ImageDebugInfo.h"
#include "LocatableFile.h"
@ -391,6 +393,32 @@ ImageFunctionsView::SetFunction(FunctionInstance* function)
}
void
ImageFunctionsView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("functionsTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fFunctionsTable);
}
}
status_t
ImageFunctionsView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fFunctionsTable);
if (result == B_OK)
result = settings.AddMessage("functionsTable", &tableSettings);
return result;
}
void
ImageFunctionsView::TreeTableSelectionChanged(TreeTable* table)
{

View File

@ -31,6 +31,9 @@ public:
ImageDebugInfo* imageDebugInfo);
void SetFunction(FunctionInstance* function);
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
class FunctionsTableModel;

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -15,6 +16,7 @@
#include <AutoLocker.h>
#include <ObjectList.h>
#include "GUISettingsUtils.h"
#include "table/TableColumns.h"
#include "Tracing.h"
@ -224,6 +226,32 @@ ImageListView::MessageReceived(BMessage* message)
}
void
ImageListView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("imagesTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fImagesTable);
}
}
status_t
ImageListView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fImagesTable);
if (result == B_OK)
result = settings.AddMessage("imagesTable", &tableSettings);
return result;
}
void
ImageListView::ImageAdded(const Team::ImageEvent& event)
{

View File

@ -29,6 +29,9 @@ public:
virtual void MessageReceived(BMessage* message);
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
class ImagesTableModel;

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -15,6 +16,7 @@
#include "Architecture.h"
#include "CpuState.h"
#include "GUISettingsUtils.h"
#include "Register.h"
@ -226,6 +228,32 @@ RegistersView::SetCpuState(CpuState* cpuState)
}
void
RegistersView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("registerTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fRegisterTable);
}
}
status_t
RegistersView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fRegisterTable);
if (result == B_OK)
result = settings.AddMessage("registerTable", &tableSettings);
return result;
}
void
RegistersView::TableRowInvoked(Table* table, int32 rowIndex)
{

View File

@ -24,6 +24,9 @@ public:
void SetCpuState(CpuState* cpuState);
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
class RegisterValueColumn;
class RegisterTableModel;

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -15,6 +16,7 @@
#include "table/TableColumns.h"
#include "FunctionInstance.h"
#include "GUISettingsUtils.h"
#include "Image.h"
#include "StackTrace.h"
#include "TargetAddressTableColumn.h"
@ -196,6 +198,32 @@ StackTraceView::SetStackFrame(StackFrame* stackFrame)
}
void
StackTraceView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("framesTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fFramesTable);
}
}
status_t
StackTraceView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fFramesTable);
if (result == B_OK)
result = settings.AddMessage("framesTable", &tableSettings);
return result;
}
void
StackTraceView::TableSelectionChanged(Table* table)
{

View File

@ -30,6 +30,9 @@ public:
void SetStackTrace(StackTrace* stackTrace);
void SetStackFrame(StackFrame* stackFrame);
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
class FramesTableModel;

View File

@ -224,7 +224,8 @@ TeamWindow::MessageReceived(BMessage* message)
fInspectorWindow = InspectorWindow::Create(fTeam, fListener,
this);
if (fInspectorWindow != NULL) {
fInspectorWindow->LoadSettings(&fUISettings);
BMessage settings;
fInspectorWindow->LoadSettings(fUISettings);
fInspectorWindow->Show();
}
} catch (...) {
@ -354,22 +355,50 @@ TeamWindow::LoadSettings(const GUITeamUISettings* settings)
if (!lock.IsLocked())
return B_ERROR;
BVariant value;
status_t error = settings->Value("teamWindowFrame", value);
if (error == B_OK) {
BRect rect = value.ToRect();
ResizeTo(rect.Width(), rect.Height());
MoveTo(rect.left, rect.top);
BMessage teamWindowSettings;
// no settings stored yet
if (settings->Settings("teamWindow", teamWindowSettings) != B_OK)
return B_OK;
BRect frame;
if (teamWindowSettings.FindRect("frame", &frame) == B_OK) {
ResizeTo(frame.Width(), frame.Height());
MoveTo(frame.left, frame.top);
}
GUISettingsUtils::UnarchiveSplitView(Name(), "Source", settings,
fSourceSplitView);
GUISettingsUtils::UnarchiveSplitView(Name(), "Function", settings,
fFunctionSplitView);
GUISettingsUtils::UnarchiveSplitView(Name(), "Image", settings,
fImageSplitView);
GUISettingsUtils::UnarchiveSplitView(Name(), "Thread", settings,
fThreadSplitView);
BMessage archive;
if (teamWindowSettings.FindMessage("sourceSplit", &archive) == B_OK)
GUISettingsUtils::UnarchiveSplitView(archive, fSourceSplitView);
if (teamWindowSettings.FindMessage("functionSplit", &archive) == B_OK)
GUISettingsUtils::UnarchiveSplitView(archive, fFunctionSplitView);
if (teamWindowSettings.FindMessage("imageSplit", &archive) == B_OK)
GUISettingsUtils::UnarchiveSplitView(archive, fImageSplitView);
if (teamWindowSettings.FindMessage("threadSplit", &archive) == B_OK)
GUISettingsUtils::UnarchiveSplitView(archive, fThreadSplitView);
if (teamWindowSettings.FindMessage("imageListView", &archive) == B_OK)
fImageListView->LoadSettings(archive);
if (teamWindowSettings.FindMessage("imageFunctionsView", &archive) == B_OK)
fImageFunctionsView->LoadSettings(archive);
if (teamWindowSettings.FindMessage("threadListView", &archive) == B_OK)
fThreadListView->LoadSettings(archive);
if (teamWindowSettings.FindMessage("variablesView", &archive) == B_OK)
fVariablesView->LoadSettings(archive);
if (teamWindowSettings.FindMessage("registersView", &archive) == B_OK)
fRegistersView->LoadSettings(archive);
if (teamWindowSettings.FindMessage("stackTraceView", &archive) == B_OK)
fStackTraceView->LoadSettings(archive);
if (teamWindowSettings.FindMessage("breakpointsView", &archive) == B_OK)
fBreakpointsView->LoadSettings(archive);
fUISettings = *settings;
@ -384,40 +413,73 @@ TeamWindow::SaveSettings(GUITeamUISettings* settings)
if (!lock.IsLocked())
return B_ERROR;
// save the settings from the cached copy first,
// then overwrite them with our most current set
// this is necessary in order to preserve the settings
// of things like the inspector in case we haven't actually
// invoked them at all in this session
const BMessage& values = fUISettings.Values();
char *name;
type_code type;
BVariant value;
for (int32 i = 0; values.GetInfo(B_ANY_TYPE, i, &name, &type) == B_OK;
i++) {
if (value.SetFromMessage(values, name) == B_OK) {
if (!settings->SetValue(name, value))
return B_NO_MEMORY;
}
BMessage inspectorSettings;
if (fUISettings.Settings("inspectorWindow", inspectorSettings) == B_OK) {
if (!settings->AddSettings("inspectorWindow", inspectorSettings))
return B_NO_MEMORY;
}
if (!settings->SetValue("teamWindowFrame", Frame()))
BMessage archive;
BMessage teamWindowSettings;
if (teamWindowSettings.AddRect("frame", Frame()) != B_OK)
return B_NO_MEMORY;
if (GUISettingsUtils::ArchiveSplitView(Name(), "Source",
settings, fSourceSplitView) != B_OK)
if (GUISettingsUtils::ArchiveSplitView(archive, fSourceSplitView) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("sourceSplit", &archive) != B_OK)
return B_NO_MEMORY;
if (GUISettingsUtils::ArchiveSplitView(Name(), "Function",
settings, fFunctionSplitView) != B_OK)
if (GUISettingsUtils::ArchiveSplitView(archive, fFunctionSplitView) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("functionSplit", &archive) != B_OK)
return B_NO_MEMORY;
if (GUISettingsUtils::ArchiveSplitView(Name(), "Image",
settings, fImageSplitView) != B_OK)
if (GUISettingsUtils::ArchiveSplitView(archive, fImageSplitView) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("imageSplit", &archive))
return B_NO_MEMORY;
if (GUISettingsUtils::ArchiveSplitView(Name(), "Thread",
settings, fThreadSplitView) != B_OK)
if (GUISettingsUtils::ArchiveSplitView(archive, fThreadSplitView) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("threadSplit", &archive))
return B_NO_MEMORY;
if (fImageListView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("imageListView", &archive))
return B_NO_MEMORY;
if (fImageFunctionsView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("imageFunctionsView", &archive))
return B_NO_MEMORY;
if (fThreadListView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("threadListView", &archive))
return B_NO_MEMORY;
if (fVariablesView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("variablesView", &archive))
return B_NO_MEMORY;
if (fRegistersView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("registersView", &archive))
return B_NO_MEMORY;
if (fStackTraceView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("stackTraceView", &archive))
return B_NO_MEMORY;
if (fBreakpointsView->SaveSettings(archive) != B_OK)
return B_NO_MEMORY;
if (teamWindowSettings.AddMessage("breakpointsView", &archive))
return B_NO_MEMORY;
if (!settings->AddSettings("teamWindow", teamWindowSettings))
return B_NO_MEMORY;
return B_OK;
@ -1186,17 +1248,8 @@ TeamWindow::_HandleResolveMissingSourceFile(entry_ref& locatedPath)
status_t
TeamWindow::_SaveInspectorSettings(const BMessage* settings)
{
char *name;
type_code type;
BVariant value;
for (int32 i = 0; settings->GetInfo(B_ANY_TYPE, i, &name, &type) == B_OK;
i++) {
if (value.SetFromMessage(*settings, name) == B_OK) {
if (!fUISettings.SetValue(name, value))
return B_NO_MEMORY;
}
}
if (fUISettings.AddSettings("inspectorWindow", *settings) != B_OK)
return B_NO_MEMORY;
return B_OK;
}

View File

@ -1,5 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -15,6 +16,7 @@
#include <ObjectList.h>
#include <ToolTip.h>
#include "GUISettingsUtils.h"
#include "table/TableColumns.h"
@ -306,6 +308,34 @@ ThreadListView::MessageReceived(BMessage* message)
}
void
ThreadListView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("threadsTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fThreadsTable);
}
}
status_t
ThreadListView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fThreadsTable);
if (result == B_OK)
result = settings.AddMessage("threadsTable", &tableSettings);
return result;
}
void
ThreadListView::ThreadAdded(const Team::ThreadEvent& event)
{

View File

@ -33,6 +33,9 @@ public:
virtual void MessageReceived(BMessage* message);
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
class ThreadsTableModel;

View File

@ -22,6 +22,7 @@
#include "Architecture.h"
#include "FunctionID.h"
#include "FunctionInstance.h"
#include "GUISettingsUtils.h"
#include "MessageCodes.h"
#include "SettingsMenu.h"
#include "StackFrame.h"
@ -1519,6 +1520,34 @@ VariablesView::DetachedFromWindow()
}
void
VariablesView::LoadSettings(const BMessage& settings)
{
BMessage tableSettings;
if (settings.FindMessage("variableTable", &tableSettings) == B_OK) {
GUISettingsUtils::UnarchiveTableSettings(tableSettings,
fVariableTable);
}
}
status_t
VariablesView::SaveSettings(BMessage& settings)
{
settings.MakeEmpty();
BMessage tableSettings;
status_t result = GUISettingsUtils::ArchiveTableSettings(tableSettings,
fVariableTable);
if (result == B_OK)
result = settings.AddMessage("variableTable", &tableSettings);
return result;
}
void
VariablesView::TreeTableNodeExpandedChanged(TreeTable* table,
const TreeTablePath& path, bool expanded)

View File

@ -41,6 +41,9 @@ public:
virtual void DetachedFromWindow();
void LoadSettings(const BMessage& settings);
status_t SaveSettings(BMessage& settings);
private:
// TreeTableListener
virtual void TreeTableNodeExpandedChanged(TreeTable* table,