HaikuDepoStore and restore column state
* Better mechanism totore and restore window settiings.
This commit is contained in:
parent
81a828b660
commit
572c729258
@ -37,10 +37,12 @@ bool
|
||||
App::QuitRequested()
|
||||
{
|
||||
if (fMainWindow->LockLooperWithTimeout(1500000) == B_OK) {
|
||||
BRect windowFrame = fMainWindow->Frame();
|
||||
BMessage windowSettings;
|
||||
fMainWindow->StoreSettings(windowSettings);
|
||||
|
||||
fMainWindow->UnlockLooper();
|
||||
|
||||
_StoreSettings(windowFrame);
|
||||
_StoreSettings(windowSettings);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -60,7 +62,7 @@ App::ReadyToRun()
|
||||
|
||||
make_sure_frame_is_on_screen(frame);
|
||||
|
||||
fMainWindow = new MainWindow(frame);
|
||||
fMainWindow = new MainWindow(frame, settings);
|
||||
fMainWindow->Show();
|
||||
}
|
||||
|
||||
@ -71,9 +73,11 @@ App::MessageReceived(BMessage* message)
|
||||
switch (message->what) {
|
||||
case MSG_MAIN_WINDOW_CLOSED:
|
||||
{
|
||||
BRect windowFrame;
|
||||
if (message->FindRect("window frame", &windowFrame) == B_OK)
|
||||
_StoreSettings(windowFrame);
|
||||
BMessage windowSettings;
|
||||
if (message->FindMessage("window settings",
|
||||
&windowSettings) == B_OK) {
|
||||
_StoreSettings(windowSettings);
|
||||
}
|
||||
|
||||
Quit();
|
||||
break;
|
||||
@ -87,10 +91,8 @@ App::MessageReceived(BMessage* message)
|
||||
|
||||
|
||||
void
|
||||
App::_StoreSettings(const BRect& windowFrame)
|
||||
App::_StoreSettings(const BMessage& windowSettings)
|
||||
{
|
||||
BMessage settings;
|
||||
settings.AddRect("window frame", windowFrame);
|
||||
save_settings(&settings, "main_settings", "HaikuDepot");
|
||||
save_settings(&windowSettings, "main_settings", "HaikuDepot");
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void _StoreSettings(const BRect& windowFrame);
|
||||
void _StoreSettings(const BMessage& windowSettings);
|
||||
|
||||
MainWindow* fMainWindow;
|
||||
};
|
||||
|
@ -72,7 +72,7 @@ struct RefreshWorkerParameters {
|
||||
};
|
||||
|
||||
|
||||
MainWindow::MainWindow(BRect frame)
|
||||
MainWindow::MainWindow(BRect frame, const BMessage& settings)
|
||||
:
|
||||
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("HaikuDepot"),
|
||||
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
@ -106,6 +106,11 @@ MainWindow::MainWindow(BRect frame)
|
||||
fSplitView->SetCollapsible(0, false);
|
||||
fSplitView->SetCollapsible(1, false);
|
||||
|
||||
// Restore settings
|
||||
BMessage columnSettings;
|
||||
if (settings.FindMessage("column settings", &columnSettings) == B_OK)
|
||||
fPackageListView->LoadState(&columnSettings);
|
||||
|
||||
_StartRefreshWorker();
|
||||
|
||||
fPendingActionsSem = create_sem(0, "PendingPackageActions");
|
||||
@ -135,8 +140,12 @@ MainWindow::~MainWindow()
|
||||
bool
|
||||
MainWindow::QuitRequested()
|
||||
{
|
||||
BMessage settings;
|
||||
StoreSettings(settings);
|
||||
|
||||
BMessage message(MSG_MAIN_WINDOW_CLOSED);
|
||||
message.AddRect("window frame", Frame());
|
||||
message.AddMessage("window settings", &settings);
|
||||
|
||||
be_app->PostMessage(&message);
|
||||
|
||||
return true;
|
||||
@ -229,6 +238,18 @@ MainWindow::MessageReceived(BMessage* message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::StoreSettings(BMessage& settings) const
|
||||
{
|
||||
settings.AddRect("window frame", Frame());
|
||||
|
||||
BMessage columnSettings;
|
||||
fPackageListView->SaveState(&columnSettings);
|
||||
|
||||
settings.AddMessage("column settings", &columnSettings);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::PackageChanged(const PackageInfoEvent& event)
|
||||
{
|
||||
|
@ -29,13 +29,16 @@ enum {
|
||||
class MainWindow : public BWindow, private PackageInfoListener,
|
||||
private PackageActionHandler {
|
||||
public:
|
||||
MainWindow(BRect frame);
|
||||
MainWindow(BRect frame,
|
||||
const BMessage& settings);
|
||||
virtual ~MainWindow();
|
||||
|
||||
// BWindow interface
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
void StoreSettings(BMessage& message) const;
|
||||
|
||||
private:
|
||||
// PackageInfoListener
|
||||
virtual void PackageChanged(
|
||||
|
@ -46,7 +46,7 @@ load_settings(BMessage* message, const char* fileName, const char* folder)
|
||||
|
||||
|
||||
status_t
|
||||
save_settings(BMessage* message, const char* fileName, const char* folder)
|
||||
save_settings(const BMessage* message, const char* fileName, const char* folder)
|
||||
{
|
||||
if (message == NULL || fileName == NULL || fileName[0] == '\0')
|
||||
return B_BAD_VALUE;
|
||||
|
@ -17,7 +17,7 @@ class BWindow;
|
||||
status_t load_settings(BMessage* message, const char* fileName,
|
||||
const char* folder = NULL);
|
||||
|
||||
status_t save_settings(BMessage* message, const char* fileName,
|
||||
status_t save_settings(const BMessage* message, const char* fileName,
|
||||
const char* folder = NULL);
|
||||
|
||||
bool make_sure_frame_is_on_screen(BRect& frame, float borderWidth = 5.0f,
|
||||
|
Loading…
Reference in New Issue
Block a user