From f7a0f575a88b6a68498ee22393eb9201f912831c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 31 Aug 2009 11:42:18 +0000 Subject: [PATCH] When no settings file is found, resize the list view and the window such that all columns are seen (taking care not to become bigger than the screen) and center the window on screen. +alphabranch git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32853 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/drivesetup/DriveSetup.cpp | 3 ++- src/apps/drivesetup/MainWindow.cpp | 26 ++++++++++++++++++++++++++ src/apps/drivesetup/MainWindow.h | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/apps/drivesetup/DriveSetup.cpp b/src/apps/drivesetup/DriveSetup.cpp index 2f4d4a8649..a46ad8d84a 100644 --- a/src/apps/drivesetup/DriveSetup.cpp +++ b/src/apps/drivesetup/DriveSetup.cpp @@ -36,7 +36,8 @@ void DriveSetup::ReadyToRun() { fWindow = new MainWindow(BRect(50, 50, 600, 450)); - _RestoreSettings(); + if (_RestoreSettings() != B_OK) + fWindow->ApplyDefaultSettings(); fWindow->Show(); } diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index 7c77346082..f3dc0f7257 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -372,6 +372,32 @@ MainWindow::RestoreSettings(BMessage* archive) } +void +MainWindow::ApplyDefaultSettings() +{ + if (!Lock()) + return; + + fListView->ResizeAllColumnsToPreferred(); + + // Adjust window size for convenience + float enlargeBy = fListView->PreferredSize().width + - fListView->Bounds().Width(); + if (enlargeBy > 0.0f) { + BScreen screen(this); + float windowWidth = Frame().Width() + enlargeBy; + if (windowWidth > screen.Frame().Width() - 20.0f) + windowWidth = screen.Frame().Width() - 20.0f; + + ResizeTo(windowWidth, Frame().Height()); + } + + CenterOnScreen(); + + Unlock(); +} + + // #pragma mark - diff --git a/src/apps/drivesetup/MainWindow.h b/src/apps/drivesetup/MainWindow.h index 11c1bad119..b034a0740f 100644 --- a/src/apps/drivesetup/MainWindow.h +++ b/src/apps/drivesetup/MainWindow.h @@ -41,6 +41,7 @@ public: // MainWindow status_t StoreSettings(BMessage* archive) const; status_t RestoreSettings(BMessage* archive); + void ApplyDefaultSettings(); private: void _ScanDrives(); @@ -68,7 +69,7 @@ private: const BString& diskSystemName); void _Create(BDiskDevice* disk, partition_id selectedPartition); - void _Delete(BDiskDevice* disk, + void _Delete(BDiskDevice* disk, partition_id selectedPartition);