From 022152bc8191f5dda0ce2086ec17645711147fd9 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Mon, 31 Mar 2008 16:28:36 +0000 Subject: [PATCH] - Add shortcut for About window. - Created 'bootman' directory in config/settings. - Added file open/save dialog. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24705 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bootman/BootManager.cpp | 2 +- src/apps/bootman/BootManagerController.cpp | 14 +++- src/apps/bootman/BootManagerWindow.cpp | 8 +- src/apps/bootman/FileSelectionPage.cpp | 95 +++++++++++++++++++++- src/apps/bootman/FileSelectionPage.h | 13 ++- src/apps/bootman/TestBootDrive.cpp | 2 +- 6 files changed, 124 insertions(+), 10 deletions(-) diff --git a/src/apps/bootman/BootManager.cpp b/src/apps/bootman/BootManager.cpp index ddc792d73b..29986da8fc 100644 --- a/src/apps/bootman/BootManager.cpp +++ b/src/apps/bootman/BootManager.cpp @@ -42,7 +42,7 @@ BootManager::ReadyToRun() void BootManager::AboutRequested() { - BAlert *alert = new BAlert("about", "Haiku Boot Manager\n" + BAlert *alert = new BAlert("about", "Haiku Boot Manager\n\n" "\twritten by Michael Pfeiffer\n" "\tCopyright 2008, Haiku Inc.\n", "Ok"); BTextView *view = alert->TextView(); diff --git a/src/apps/bootman/BootManagerController.cpp b/src/apps/bootman/BootManagerController.cpp index da7459ce5f..fd74de6e81 100644 --- a/src/apps/bootman/BootManagerController.cpp +++ b/src/apps/bootman/BootManagerController.cpp @@ -47,7 +47,13 @@ BootManagerController::BootManagerController() BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { path.Append("bootman/MBR"); - fSettings.AddString("file", path.Path()); + fSettings.AddString("file", path.Path()); + // create directory + BPath parent; + if (path.GetParent(&parent) == B_OK) { + BDirectory directory; + directory.CreateDirectory(parent.Path(), NULL); + } } else { fSettings.AddString("file", ""); } @@ -266,7 +272,8 @@ BootManagerController::_CreateSaveMBRPage(BRect frame) "you later wish to remove the boot menu, simply run the " "bootman program and choose to 'Uninstall' option."; - FileSelectionPage* page = new FileSelectionPage(&fSettings, frame, "saveMBR", description.String()); + FileSelectionPage* page = new FileSelectionPage(&fSettings, frame, "saveMBR", description.String(), + B_SAVE_PANEL); return page; } @@ -353,7 +360,8 @@ BootManagerController::_CreateUninstallPage(BRect frame) "restore from. This is the file that was created when the " "boot manager was first installed."; - FileSelectionPage* page = new FileSelectionPage(&fSettings, frame, "restoreMBR", description.String()); + FileSelectionPage* page = new FileSelectionPage(&fSettings, frame, "restoreMBR", description.String(), + B_OPEN_PANEL); return page; } diff --git a/src/apps/bootman/BootManagerWindow.cpp b/src/apps/bootman/BootManagerWindow.cpp index 75d0a0b03b..1d4d46dda7 100644 --- a/src/apps/bootman/BootManagerWindow.cpp +++ b/src/apps/bootman/BootManagerWindow.cpp @@ -29,7 +29,9 @@ BootManagerWindow::BootManagerWindow() fWizardView = new WizardView(Bounds(), "wizard", B_FOLLOW_ALL); AddChild(fWizardView); - fController.Initialize(fWizardView); + fController.Initialize(fWizardView); + + AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED)); } @@ -50,6 +52,10 @@ BootManagerWindow::MessageReceived(BMessage* msg) fController.Previous(fWizardView); break; + case B_ABOUT_REQUESTED: + be_app_messenger.SendMessage(B_ABOUT_REQUESTED); + break; + default: BWindow::MessageReceived(msg); } diff --git a/src/apps/bootman/FileSelectionPage.cpp b/src/apps/bootman/FileSelectionPage.cpp index 55ffc1cb18..2d8c77f6f9 100644 --- a/src/apps/bootman/FileSelectionPage.cpp +++ b/src/apps/bootman/FileSelectionPage.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -16,10 +17,15 @@ #include +const uint32 kMsgOpenFilePanel = 'open'; + + FileSelectionPage::FileSelectionPage(BMessage* settings, BRect frame, const char* name, - const char* description) + const char* description, file_panel_mode mode) : WizardPageView(settings, frame, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) + , fMode(mode) + , fFilePanel(NULL) { _BuildUI(description); } @@ -38,6 +44,33 @@ FileSelectionPage::FrameResized(float width, float height) } +void +FileSelectionPage::AttachedToWindow() +{ + fSelect->SetTarget(this); +} + + +void +FileSelectionPage::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgOpenFilePanel: + _OpenFilePanel(); + break; + case B_REFS_RECEIVED: + case B_SAVE_REQUESTED: + _SetFileFromFilePanelMessage(message); + break; + case B_CANCEL: + _FilePanelCanceled(); + break; + default: + WizardPageView::MessageReceived(message); + } +} + + void FileSelectionPage::PageCompleted() { @@ -66,8 +99,7 @@ FileSelectionPage::_BuildUI(const char* description) fFile->SetDivider(be_plain_font->StringWidth(fFile->Label()) + 5); AddChild(fFile); - // TODO open file dialog - fSelect = new BButton(rect, "select", "Select", new BMessage(), + fSelect = new BButton(rect, "select", "Select", new BMessage(kMsgOpenFilePanel), B_FOLLOW_RIGHT); fSelect->ResizeToPreferred(); float left = rect.right - fSelect->Frame().Width(); @@ -95,3 +127,60 @@ FileSelectionPage::_Layout() fSelect->MoveTo(left, top); } + +void +FileSelectionPage::_OpenFilePanel() +{ + if (fFilePanel != NULL) + return; + + const entry_ref* directory = NULL; + entry_ref base; + BPath file(fFile->Text()); + BPath parent; + + if (file.GetParent(&parent) == B_OK && + get_ref_for_path(parent.Path(), &base) == B_OK) + directory = &base; + + BMessenger messenger(this); + fFilePanel = new BFilePanel(fMode, &messenger, directory, + B_FILE_NODE, + false, + NULL, + NULL, + true); + if (fMode == B_SAVE_PANEL && file.Leaf() != NULL) + fFilePanel->SetSaveText(file.Leaf()); + fFilePanel->Show(); +} + + +void +FileSelectionPage::_SetFileFromFilePanelMessage(BMessage* message) +{ + if (message->what == B_SAVE_REQUESTED) { + entry_ref directory; + BString name; + message->FindRef("directory", &directory); + message->FindString("name", &name); + BPath path(&directory); + if (path.Append(name.String()) == B_OK) + fFile->SetText(path.Path()); + } else { + entry_ref entryRef; + message->FindRef("refs", &entryRef); + BEntry entry(&entryRef); + BPath path; + if (entry.GetPath(&path) == B_OK) + fFile->SetText(path.Path()); + } +} + + +void +FileSelectionPage::_FilePanelCanceled() +{ + delete fFilePanel; + fFilePanel = NULL; +} diff --git a/src/apps/bootman/FileSelectionPage.h b/src/apps/bootman/FileSelectionPage.h index 363b56ecd5..2e4c4a4dd7 100644 --- a/src/apps/bootman/FileSelectionPage.h +++ b/src/apps/bootman/FileSelectionPage.h @@ -8,6 +8,8 @@ #include "WizardPageView.h" +#include + class BButton; class BTextControl; @@ -16,10 +18,13 @@ class BTextView; class FileSelectionPage : public WizardPageView { public: - FileSelectionPage(BMessage* settings, BRect frame, const char* name, const char* description); + FileSelectionPage(BMessage* settings, BRect frame, const char* name, const char* description, + file_panel_mode mode); virtual ~FileSelectionPage(); virtual void FrameResized(float width, float height); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); virtual void PageCompleted(); @@ -27,7 +32,13 @@ private: void _BuildUI(const char* description); void _Layout(); + void _OpenFilePanel(); + void _SetFileFromFilePanelMessage(BMessage* message); + void _FilePanelCanceled(); + file_panel_mode fMode; + BFilePanel* fFilePanel; + BTextView* fDescription; BTextControl* fFile; BButton* fSelect; diff --git a/src/apps/bootman/TestBootDrive.cpp b/src/apps/bootman/TestBootDrive.cpp index 1e3cc2ed04..5eb496f532 100644 --- a/src/apps/bootman/TestBootDrive.cpp +++ b/src/apps/bootman/TestBootDrive.cpp @@ -23,7 +23,7 @@ TestBootDrive::~TestBootDrive() bool TestBootDrive::IsBootMenuInstalled() { - return true; + return false; }