xref: /haiku/src/apps/debugger/user_interface/gui/util/GuiSettingsUtils.cpp (revision 25a7b01d15612846f332751841da3579db313082)
1 /*
2  * Copyright 2011, Rene Gollent, rene@gollent.com.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "GuiSettingsUtils.h"
8 
9 #include <Message.h>
10 #include <SplitView.h>
11 
12 #include "table/AbstractTable.h"
13 
14 
15 /*static*/ status_t
ArchiveSplitView(BMessage & settings,BSplitView * view)16 GuiSettingsUtils::ArchiveSplitView(BMessage& settings, BSplitView* view)
17 {
18 	settings.MakeEmpty();
19 	for (int32 i = 0; i < view->CountItems(); i++) {
20 		if (settings.AddFloat("weight", view->ItemWeight(i)) != B_OK)
21 			return B_NO_MEMORY;
22 
23 		if (settings.AddBool("collapsed", view->IsItemCollapsed(i)) != B_OK)
24 			return B_NO_MEMORY;
25 	}
26 
27 	return B_OK;
28 }
29 
30 
31 /*static*/ void
UnarchiveSplitView(const BMessage & settings,BSplitView * view)32 GuiSettingsUtils::UnarchiveSplitView(const BMessage& settings,
33 	BSplitView* view)
34 {
35 	for (int32 i = 0; i < view->CountItems(); i++) {
36 		float weight;
37 		if (settings.FindFloat("weight", i, &weight) == B_OK)
38 			view->SetItemWeight(i, weight, i == view->CountItems() - 1);
39 
40 		bool collapsed;
41 		if (settings.FindBool("collapsed", i, &collapsed) == B_OK)
42 			view->SetItemCollapsed(i, collapsed);
43 	}
44 }
45 
46 
47 /*static*/ status_t
ArchiveTableSettings(BMessage & settings,AbstractTable * table)48 GuiSettingsUtils::ArchiveTableSettings(BMessage& settings,
49 	AbstractTable* table)
50 {
51 	settings.MakeEmpty();
52 	table->SaveState(&settings);
53 
54 	return B_OK;
55 }
56 
57 
58 /*static*/ void
UnarchiveTableSettings(const BMessage & settings,AbstractTable * table)59 GuiSettingsUtils::UnarchiveTableSettings(const BMessage& settings,
60 	AbstractTable* table)
61 {
62 	BMessage settingsCopy(settings);
63 	table->LoadState(&settingsCopy);
64 }
65 
66