void BVolumeWindow::MenusBeginning() { _inherited::MenusBeginning(); if (!fMenuBar) return; BVolume boot; BVolumeRoster().GetBootVolume(&boot); bool ejectableVolumeSelected = false; int32 count = PoseView()->SelectionList()->CountItems(); for (int32 index = 0; index < count; index++) { Model *model = PoseView()->SelectionList()->ItemAt(index)->TargetModel(); if (model->IsVolume()) { BVolume volume; volume.SetTo(model->NodeRef()->device); if (volume != boot) { ejectableVolumeSelected = true; break; } } } BMenuItem* item = fMenuBar->FindItem(kUnmountVolume); if (item) item->SetEnabled(ejectableVolumeSelected); }
void BQueryContainerWindow::AddWindowMenu(BMenu *menu) { BMenuItem *item; item = new BMenuItem(B_TRANSLATE("Resize to fit"), new BMessage(kResizeToFit), 'Y'); item->SetTarget(this); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Select"B_UTF8_ELLIPSIS), new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY); item->SetTarget(PoseView()); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Select all"), new BMessage(B_SELECT_ALL), 'A'); item->SetTarget(PoseView()); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Invert selection"), new BMessage(kInvertSelection), 'S'); item->SetTarget(PoseView()); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED), 'W'); item->SetTarget(this); menu->AddItem(item); }
void OpenWithContainerWindow::MakeDefaultAndOpen() { int32 count = PoseView()->SelectionList()->CountItems(); ASSERT(count == 1); if (count == 0) return; BPose* selectedAppPose = PoseView()->SelectionList()->FirstItem(); ASSERT(selectedAppPose != NULL); if (selectedAppPose == NULL) return; // collect all the types of all the opened documents into a list BObjectList<BString> openedFileTypes(10, true); EachEntryRef(EntryList(), AddOneUniqueDocumentType, &openedFileTypes, 100); // set the default application to be the selected pose for all the // mime types in the list openedFileTypes.EachElement(SetDefaultAppForOneType, (void*)selectedAppPose->TargetModel()->EntryRef()); // done setting the default application, now launch the app with the // documents OpenWithSelection(); }
void TFilePanel::OpenParent() { if (!CanOpenParent()) return; BEntry parentEntry; BDirectory dir; Model oldModel(*PoseView()->TargetModel()); BEntry entry(oldModel.EntryRef()); if (entry.InitCheck() == B_OK && entry.GetParent(&dir) == B_OK && dir.GetEntry(&parentEntry) == B_OK && entry != parentEntry) { entry_ref ref; parentEntry.GetRef(&ref); PoseView()->SetIsDesktop(SwitchDirToDesktopIfNeeded(ref)); PoseView()->SwitchDir(&ref); SwitchDirMenuTo(&ref); // make sure the child get's selected in the new view once it // shows up fTaskLoop->RunLater(NewMemberFunctionObjectWithResult (&TFilePanel::SelectChildInParent, this, const_cast<const entry_ref*>(&ref), oldModel.NodeRef()), 100000, 200000, 5000000); } }
void TFilePanel::AddWindowContextMenus(BMenu* menu) { BMenuItem* item = new BMenuItem(B_TRANSLATE("New folder"), new BMessage(kNewFolder), 'N'); item->SetTarget(PoseView()); menu->AddItem(item); menu->AddSeparatorItem(); item = new BMenuItem(B_TRANSLATE("Paste"), new BMessage(B_PASTE), 'V'); item->SetTarget(PoseView()); menu->AddItem(item); menu->AddSeparatorItem(); item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS), new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY); item->SetTarget(PoseView()); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Select all"), new BMessage(B_SELECT_ALL), 'A'); item->SetTarget(PoseView()); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Invert selection"), new BMessage(kInvertSelection), 'S'); item->SetTarget(PoseView()); menu->AddItem(item); item = new BMenuItem(B_TRANSLATE("Go to parent"), new BMessage(kOpenParentDir), B_UP_ARROW); item->SetTarget(this); menu->AddItem(item); }
void OpenWithContainerWindow::OpenWithSelection() { int32 count = PoseView()->SelectionList()->CountItems(); ASSERT(count == 1); if (count == 0) return; PoseView()->OpenSelection(PoseView()->SelectionList()->FirstItem(), 0); }
void TFilePanel::RestoreState() { BNode defaultingNode; if (DefaultStateSourceNode(kDefaultFilePanelTemplate, &defaultingNode, false)) { AttributeStreamFileNode streamNodeSource(&defaultingNode); RestoreWindowState(&streamNodeSource); PoseView()->Init(&streamNodeSource); } else { RestoreWindowState(NULL); PoseView()->Init(NULL); } }
void BVolumeWindow::AddFileMenu(BMenu *menu) { menu->AddItem(new BMenuItem(B_TRANSLATE("Find"B_UTF8_ELLIPSIS), new BMessage(kFindButton), 'F')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Open"), new BMessage(kOpenSelection), 'O')); menu->AddItem(new BMenuItem(B_TRANSLATE("Get info"), new BMessage(kGetInfo), 'I')); menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"), new BMessage(kEditItem), 'E')); BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"), new BMessage(kUnmountVolume), 'U'); item->SetEnabled(false); menu->AddItem(item); menu->AddItem(new BMenuItem(B_TRANSLATE("Mount settings" B_UTF8_ELLIPSIS), new BMessage(kRunAutomounterSettings))); menu->AddSeparatorItem(); menu->AddItem(new BMenu(B_TRANSLATE("Add-ons"))); menu->SetTargetForItems(PoseView()); }
bool TFilePanel::SelectChildInParent(const entry_ref*, const node_ref* child) { AutoLock<TFilePanel> lock(this); if (!IsLocked()) return false; int32 index; BPose* pose = PoseView()->FindPose(child, &index); if (!pose) return false; PoseView()->UpdateScrollRange(); // ToDo: Scroll range should be updated by now, for some // reason sometimes it is not right, force it here PoseView()->SelectPose(pose, index, true); return true; }
void TFilePanel::HandleOpenButton() { PoseView()->CommitActivePose(); BObjectList<BPose>* selection = PoseView()->SelectionList(); // if we have only one directory and we're not opening dirs, enter. if ((fNodeFlavors & B_DIRECTORY_NODE) == 0 && selection->CountItems() == 1) { Model* model = selection->FirstItem()->TargetModel(); if (model->IsDirectory() || (model->IsSymLink() && !(fNodeFlavors & B_SYMLINK_NODE) && model->ResolveIfLink()->IsDirectory())) { BMessage message(B_REFS_RECEIVED); message.AddRef("refs", model->EntryRef()); PostMessage(&message); return; } } // don't do anything unless there are items selected // message->fMessage->message from here to end if (selection->CountItems()) { BMessage message(*fMessage); // go through selection and add appropriate items for (int32 index = 0; index < selection->CountItems(); index++) { Model* model = selection->ItemAt(index)->TargetModel(); if (((fNodeFlavors & B_DIRECTORY_NODE) != 0 && model->ResolveIfLink()->IsDirectory()) || ((fNodeFlavors & B_SYMLINK_NODE) != 0 && model->IsSymLink()) || ((fNodeFlavors & B_FILE_NODE) != 0 && model->ResolveIfLink()->IsFile())) { message.AddRef("refs", model->EntryRef()); } } OpenSelectionCommon(&message); } }
void TFilePanel::SaveState(bool) { BNode defaultingNode; if (DefaultStateSourceNode(kDefaultFilePanelTemplate, &defaultingNode, true, false)) { AttributeStreamFileNode streamNodeDestination(&defaultingNode); SaveWindowState(&streamNodeDestination); PoseView()->SaveState(&streamNodeDestination); } }
void TFilePanel::RestoreState() { BNode defaultingNode; if (DefaultStateSourceNode(kDefaultFilePanelTemplate, &defaultingNode, false)) { AttributeStreamFileNode streamNodeSource(&defaultingNode); RestoreWindowState(&streamNodeSource); PoseView()->Init(&streamNodeSource); } else { RestoreWindowState(NULL); PoseView()->Init(NULL); } // Finish UI creation now that the PoseView is initialized BLayoutItem* item = fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView()); BSize minSize = item->MinSize(); BSize maxSize = item->MaxSize(); item->SetExplicitMinSize(BSize(minSize.Width(), kTitleViewHeight)); item->SetExplicitMaxSize(BSize(maxSize.Width(), kTitleViewHeight)); BRect rect(fBorderedView->Frame()); rect.right = rect.left + kCountViewWidth; rect.top = rect.bottom + 1; rect.bottom = rect.top + PoseView()->HScrollBar()->Bounds().Height() - 1; PoseView()->CountView()->MoveTo(rect.LeftTop()); PoseView()->CountView()->ResizeTo(rect.Size()); PoseView()->CountView()->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); fBackView->AddChild(PoseView()->CountView(), fBorderedView); PoseView()->HScrollBar()->MoveBy(kCountViewWidth + 1, 0); PoseView()->HScrollBar()->ResizeBy(-kCountViewWidth - 1, 0); // The Be Book states that the BTitleView will have a name of "TitleView", // and so some apps will try to grab it by that name and move it around. // They don't need to, because resizing "PoseView" (really the BorderedView) // will resize the BTitleView as well. So just create a dummy view here // so that they don't get NULL when trying to find the view. BView* dummyTitleView = new BView(BRect(), "TitleView", B_FOLLOW_NONE, 0); fBackView->AddChild(dummyTitleView); dummyTitleView->Hide(); }
void TFilePanel::OpenDirectory() { BObjectList<BPose>* list = PoseView()->SelectionList(); if (list->CountItems() != 1) return; Model* model = list->FirstItem()->TargetModel(); if (model->ResolveIfLink()->IsDirectory()) { BMessage message(B_REFS_RECEIVED); message.AddRef("refs", model->EntryRef()); PostMessage(&message); } }
void BQueryContainerWindow::SetUpDefaultState() { BNode defaultingNode; WindowStateNodeOpener opener(this, true); // this is our destination node, whatever it is for this window if (!opener.StreamNode()) return; BString defaultStatePath(kQueryTemplates); BString sanitizedType(PoseView()->SearchForType()); defaultStatePath += '/'; int32 length = sanitizedType.Length(); char *buf = sanitizedType.LockBuffer(length); for (int32 index = length - 1; index >= 0; index--) if (buf[index] == '/') buf[index] = '_'; sanitizedType.UnlockBuffer(length); defaultStatePath += sanitizedType; PRINT(("looking for default query state at %s\n", defaultStatePath.String())); if (!DefaultStateSourceNode(defaultStatePath.String(), &defaultingNode, false)) { TRACE(); return; } // copy over the attributes // set up a filter of the attributes we want copied const char *allowAttrs[] = { kAttrWindowFrame, kAttrViewState, kAttrViewStateForeign, kAttrColumns, kAttrColumnsForeign, 0 }; // do it AttributeStreamMemoryNode memoryNode; NamesToAcceptAttrFilter filter(allowAttrs); AttributeStreamFileNode fileNode(&defaultingNode); *opener.StreamNode() << memoryNode << filter << fileNode; }
void BQueryContainerWindow::AddWindowContextMenus(BMenu *menu) { BMenuItem *resizeItem = new BMenuItem("Resize to Fit", new BMessage(kResizeToFit), 'Y'); menu->AddItem(resizeItem); menu->AddItem(new BMenuItem("Select"B_UTF8_ELLIPSIS, new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY)); menu->AddItem(new BMenuItem("Select all", new BMessage(B_SELECT_ALL), 'A')); BMenuItem *closeItem = new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'); menu->AddItem(closeItem); // target items as needed menu->SetTargetForItems(PoseView()); closeItem->SetTarget(this); resizeItem->SetTarget(this); }
void TFilePanel::MenusBeginning() { int32 count = PoseView()->SelectionList()->CountItems(); EnableNamedMenuItem(fMenuBar, kNewFolder, !TargetModel()->IsRoot()); EnableNamedMenuItem(fMenuBar, kMoveToTrash, !TargetModel()->IsRoot() && count); EnableNamedMenuItem(fMenuBar, kGetInfo, count != 0); EnableNamedMenuItem(fMenuBar, kEditItem, count == 1); SetCutItem(fMenuBar); SetCopyItem(fMenuBar); SetPasteItem(fMenuBar); fIsTrackingMenu = true; }
void BVolumeWindow::AddWindowContextMenus(BMenu *menu) { if (fPoseView != NULL && fPoseView->TargetModel() != NULL && !fPoseView->TargetModel()->IsRoot()) { _inherited::AddWindowContextMenus(menu); return; } menu->AddItem(new BMenuItem(B_TRANSLATE("Icon view"), new BMessage(kIconMode))); menu->AddItem(new BMenuItem(B_TRANSLATE("Mini icon view"), new BMessage(kMiniIconMode))); menu->AddItem(new BMenuItem(B_TRANSLATE("List view"), new BMessage(kListMode))); menu->AddSeparatorItem(); BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"), new BMessage(kResizeToFit), 'Y'); menu->AddItem(resizeItem); menu->AddItem(new BMenuItem(B_TRANSLATE("Clean up"), new BMessage(kCleanup), 'K')); menu->AddItem(new BMenuItem(B_TRANSLATE("Select"B_UTF8_ELLIPSIS), new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY)); menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"), new BMessage(B_SELECT_ALL), 'A')); menu->AddItem(new BMenuItem(B_TRANSLATE("Invert selection"), new BMessage(kInvertSelection), 'S')); BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED), 'W'); menu->AddItem(closeItem); menu->AddSeparatorItem(); menu->AddItem(new MountMenu(B_TRANSLATE("Mount"))); menu->AddSeparatorItem(); menu->AddItem(new BMenu(B_TRANSLATE("Add-ons"))); // target items as needed menu->SetTargetForItems(PoseView()); closeItem->SetTarget(this); resizeItem->SetTarget(this); }
void TFilePanel::AddVolumeContextMenus(BMenu* menu) { menu->AddItem(new BMenuItem(B_TRANSLATE("Open"), new BMessage(kOpenSelection), 'O')); menu->AddItem(new BMenuItem(B_TRANSLATE("Get info"), new BMessage(kGetInfo), 'I')); menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"), new BMessage(kEditItem), 'E')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Cut"), new BMessage(B_CUT), 'X')); menu->AddItem(new BMenuItem(B_TRANSLATE("Copy"), new BMessage(B_COPY), 'C')); //menu->AddItem(pasteItem = new BMenuItem("Paste", new BMessage(B_PASTE), // 'V')); menu->SetTargetForItems(PoseView()); }
void TFilePanel::AddFileContextMenus(BMenu* menu) { menu->AddItem(new BMenuItem(B_TRANSLATE("Get info"), new BMessage(kGetInfo), 'I')); menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"), new BMessage(kEditItem), 'E')); menu->AddItem(new BMenuItem(TrackerSettings().DontMoveFilesToTrash() ? B_TRANSLATE("Delete") : B_TRANSLATE("Move to Trash"), new BMessage(kMoveToTrash), 'T')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Cut"), new BMessage(B_CUT), 'X')); menu->AddItem(new BMenuItem(B_TRANSLATE("Copy"), new BMessage(B_COPY), 'C')); //menu->AddItem(pasteItem = new BMenuItem("Paste", new BMessage(B_PASTE), // 'V')); menu->SetTargetForItems(PoseView()); }
void TFilePanel::SetTo(const entry_ref* ref) { if (ref == NULL) return; entry_ref setToRef(*ref); bool isDesktop = SwitchDirToDesktopIfNeeded(setToRef); BEntry entry(&setToRef); if (entry.InitCheck() != B_OK || !entry.IsDirectory()) return; SwitchDirMenuTo(&setToRef); PoseView()->SetIsDesktop(isDesktop); fPoseView->SwitchDir(&setToRef); AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome)); // our shortcut got possibly removed because the home // menu item got removed - we shouldn't really have to do // this - this is a workaround for a kit bug. }
void TFilePanel::MessageReceived(BMessage* message) { entry_ref ref; switch (message->what) { case B_REFS_RECEIVED: // item was double clicked in file panel (PoseView) if (message->FindRef("refs", &ref) == B_OK) { BEntry entry(&ref, true); if (entry.InitCheck() == B_OK) { // Double-click on dir or link-to-dir ALWAYS opens the // dir. If more than one dir is selected, the first is // entered. if (entry.IsDirectory()) { entry.GetRef(&ref); bool isDesktop = SwitchDirToDesktopIfNeeded(ref); PoseView()->SetIsDesktop(isDesktop); entry.SetTo(&ref); PoseView()->SwitchDir(&ref); SwitchDirMenuTo(&ref); } else { // Otherwise, we have a file or a link to a file. // AdjustButton has already tested the flavor; // all we have to do is see if the button is enabled. BButton* button = dynamic_cast<BButton*>( FindView("default button")); if (button == NULL) break; if (IsSavePanel()) { int32 count = 0; type_code type; message->GetInfo("refs", &type, &count); // Don't allow saves of multiple files if (count > 1) { ShowCenteredAlert( B_TRANSLATE( "Sorry, saving more than one " "item is not allowed."), B_TRANSLATE("Cancel")); } else { // if we are a savepanel, set up the // filepanel correctly then pass control // so we follow the same path as if the user // clicked the save button // set the 'name' fld to the current ref's // name notify the panel that the default // button should be enabled SetSaveText(ref.name); SelectionChanged(); HandleSaveButton(); } break; } // send handler a message and close BMessage openMessage(*fMessage); for (int32 index = 0; ; index++) { if (message->FindRef("refs", index, &ref) != B_OK) break; openMessage.AddRef("refs", &ref); } OpenSelectionCommon(&openMessage); } } } break; case kSwitchDirectory: { entry_ref ref; // this comes from dir menu or nav menu, so switch directories if (message->FindRef("refs", &ref) == B_OK) { BEntry entry(&ref, true); if (entry.GetRef(&ref) == B_OK) SetTo(&ref); } break; } case kSwitchToHome: { BPath homePath; entry_ref ref; if (find_directory(B_USER_DIRECTORY, &homePath) != B_OK || get_ref_for_path(homePath.Path(), &ref) != B_OK) { break; } SetTo(&ref); break; } case kAddCurrentDir: { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK) { break; } path.Append(kGoDirectory); BDirectory goDirectory(path.Path()); if (goDirectory.InitCheck() == B_OK) { BEntry entry(TargetModel()->EntryRef()); entry.GetPath(&path); BSymLink link; goDirectory.CreateSymLink(TargetModel()->Name(), path.Path(), &link); } break; } case kEditFavorites: { BPath path; if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK) { break; } path.Append(kGoDirectory); BMessenger msgr(kTrackerSignature); if (msgr.IsValid()) { BMessage message(B_REFS_RECEIVED); entry_ref ref; if (get_ref_for_path(path.Path(), &ref) == B_OK) { message.AddRef("refs", &ref); msgr.SendMessage(&message); } } break; } case kCancelButton: PostMessage(B_QUIT_REQUESTED); break; case kResizeToFit: ResizeToFit(); break; case kOpenDir: OpenDirectory(); break; case kOpenParentDir: OpenParent(); break; case kDefaultButton: if (fIsSavePanel) { if (PoseView()->IsFocus() && PoseView()->SelectionList()->CountItems() == 1) { Model* model = (PoseView()->SelectionList()-> FirstItem())->TargetModel(); if (model->ResolveIfLink()->IsDirectory()) { PoseView()->CommitActivePose(); PoseView()->OpenSelection(); break; } } HandleSaveButton(); } else HandleOpenButton(); break; case B_OBSERVER_NOTICE_CHANGE: { int32 observerWhat; if (message->FindInt32("be:observe_change_what", &observerWhat) == B_OK) { switch (observerWhat) { case kDesktopFilePanelRootChanged: { bool desktopIsRoot = true; if (message->FindBool("DesktopFilePanelRoot", &desktopIsRoot) == B_OK) { TrackerSettings(). SetDesktopFilePanelRoot(desktopIsRoot); } SetTo(TargetModel()->EntryRef()); break; } } } break; } default: _inherited::MessageReceived(message); break; } }
bool BQueryContainerWindow::ActiveOnDevice(dev_t device) const { return PoseView()->ActiveOnDevice(device); }
void OpenWithContainerWindow::AddShortcuts() { AddShortcut('I', B_COMMAND_KEY, new BMessage(kGetInfo), PoseView()); AddShortcut('Y', B_COMMAND_KEY, new BMessage(kResizeToFit), PoseView()); }
void TFilePanel::Init(const BMessage*) { BRect windRect(Bounds()); AddChild(fBackView = new BackgroundView(windRect)); // add poseview menu bar fMenuBar = new BMenuBar(BRect(0, 0, windRect.Width(), 1), "MenuBar"); fMenuBar->SetBorder(B_BORDER_FRAME); fBackView->AddChild(fMenuBar); AddMenus(); AddContextMenus(); FavoritesMenu* favorites = new FavoritesMenu(B_TRANSLATE("Favorites"), new BMessage(kSwitchDirectory), new BMessage(B_REFS_RECEIVED), BMessenger(this), IsSavePanel(), fPoseView->RefFilter()); favorites->AddItem(new BMenuItem(B_TRANSLATE("Add current folder"), new BMessage(kAddCurrentDir))); favorites->AddItem(new BMenuItem( B_TRANSLATE("Edit favorites" B_UTF8_ELLIPSIS), new BMessage(kEditFavorites))); fMenuBar->AddItem(favorites); // configure menus BMenuItem* item = fMenuBar->FindItem(B_TRANSLATE("Window")); if (item) { fMenuBar->RemoveItem(item); delete item; } item = fMenuBar->FindItem(B_TRANSLATE("File")); if (item) { BMenu* menu = item->Submenu(); if (menu) { item = menu->FindItem(kOpenSelection); if (item && menu->RemoveItem(item)) delete item; item = menu->FindItem(kDuplicateSelection); if (item && menu->RemoveItem(item)) delete item; // remove add-ons menu, identifier menu, separator item = menu->FindItem(B_TRANSLATE("Add-ons")); if (item) { int32 index = menu->IndexOf(item); delete menu->RemoveItem(index); delete menu->RemoveItem(--index); delete menu->RemoveItem(--index); } // remove separator item = menu->FindItem(B_CUT); if (item) { item = menu->ItemAt(menu->IndexOf(item)-1); if (item && menu->RemoveItem(item)) delete item; } } } // add directory menu and menufield fDirMenu = new BDirMenu(0, this, kSwitchDirectory, "refs"); font_height ht; be_plain_font->GetHeight(&ht); float f_height = ht.ascent + ht.descent + ht.leading; BRect rect; rect.top = fMenuBar->Bounds().Height() + 8; rect.left = windRect.left + 8; rect.right = rect.left + 300; rect.bottom = rect.top + (f_height > 22 ? f_height : 22); fDirMenuField = new BMenuField(rect, "DirMenuField", "", fDirMenu); fDirMenuField->MenuBar()->SetFont(be_plain_font); fDirMenuField->SetDivider(0); fDirMenuField->MenuBar()->SetMaxContentWidth(rect.Width() - 26.0f); // Make room for the icon fDirMenuField->MenuBar()->RemoveItem((int32)0); fDirMenu->SetMenuBar(fDirMenuField->MenuBar()); // the above is a weird call from BDirMenu // ToDo: clean up BEntry entry(TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK) fDirMenu->Populate(&entry, 0, true, true, false, true); else fDirMenu->Populate(0, 0, true, true, false, true); fBackView->AddChild(fDirMenuField); // add file name text view if (fIsSavePanel) { BRect rect(windRect); rect.top = rect.bottom - 35; rect.left = 8; rect.right = rect.left + 170; rect.bottom = rect.top + 13; fTextControl = new BTextControl(rect, "text view", B_TRANSLATE("save text"), "", NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); DisallowMetaKeys(fTextControl->TextView()); DisallowFilenameKeys(fTextControl->TextView()); fBackView->AddChild(fTextControl); fTextControl->SetDivider(0.0f); fTextControl->TextView()->SetMaxBytes(B_FILE_NAME_LENGTH - 1); fButtonText.SetTo(B_TRANSLATE("Save")); } else fButtonText.SetTo(B_TRANSLATE("Open")); rect = windRect; rect.OffsetTo(10, fDirMenuField->Frame().bottom + 10); rect.bottom = windRect.bottom - 60; rect.right -= B_V_SCROLL_BAR_WIDTH + 20; // re-parent the poseview to our backview // ToDo: // This is terrible, fix it up PoseView()->RemoveSelf(); if (fIsSavePanel) fBackView->AddChild(PoseView(), fTextControl); else fBackView->AddChild(PoseView()); PoseView()->MoveTo(rect.LeftTop()); PoseView()->ResizeTo(rect.Width(), rect.Height()); PoseView()->AddScrollBars(); PoseView()->SetDragEnabled(false); PoseView()->SetDropEnabled(false); PoseView()->SetSelectionHandler(this); PoseView()->SetSelectionChangedHook(true); PoseView()->DisableSaveLocation(); PoseView()->VScrollBar()->MoveBy(0, -1); PoseView()->VScrollBar()->ResizeBy(0, 1); AddShortcut('W', B_COMMAND_KEY, new BMessage(kCancelButton)); AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome)); AddShortcut('A', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kShowSelectionWindow)); AddShortcut('A', B_COMMAND_KEY, new BMessage(B_SELECT_ALL), PoseView()); AddShortcut('S', B_COMMAND_KEY, new BMessage(kInvertSelection), PoseView()); AddShortcut('Y', B_COMMAND_KEY, new BMessage(kResizeToFit), PoseView()); AddShortcut(B_DOWN_ARROW, B_COMMAND_KEY, new BMessage(kOpenDir)); AddShortcut(B_DOWN_ARROW, B_COMMAND_KEY | B_OPTION_KEY, new BMessage(kOpenDir)); AddShortcut(B_UP_ARROW, B_COMMAND_KEY, new BMessage(kOpenParentDir)); AddShortcut(B_UP_ARROW, B_COMMAND_KEY | B_OPTION_KEY, new BMessage(kOpenParentDir)); // New code to make buttons font sensitive rect = windRect; rect.top = rect.bottom - 35; rect.bottom -= 10; rect.right -= 25; float default_width = be_plain_font->StringWidth(fButtonText.String()) + 20; rect.left = default_width > 75 ? rect.right - default_width : rect.right - 75; BButton* default_button = new BButton(rect, "default button", fButtonText.String(), new BMessage(kDefaultButton), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); fBackView->AddChild(default_button); rect.right = rect.left -= 10; float cancel_width = be_plain_font->StringWidth(B_TRANSLATE("Cancel")) + 20; rect.left = cancel_width > 75 ? rect.right - cancel_width : rect.right - 75; BButton* cancel_button = new BButton(rect, "cancel button", B_TRANSLATE("Cancel"), new BMessage(kCancelButton), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); fBackView->AddChild(cancel_button); if (!fIsSavePanel) default_button->SetEnabled(false); default_button->MakeDefault(true); RestoreState(); PoseView()->ScrollTo(B_ORIGIN); PoseView()->UpdateScrollRange(); PoseView()->ScrollTo(B_ORIGIN); if (fTextControl) { fTextControl->MakeFocus(); fTextControl->TextView()->SelectAll(); } else PoseView()->MakeFocus(); app_info info; BString title; if (be_app->GetAppInfo(&info) == B_OK) { if (!gLocalizedNamePreferred || BLocaleRoster::Default()->GetLocalizedFileName( title, info.ref, false) != B_OK) title = info.ref.name; title << ": "; } title << fButtonText; // Open or Save SetTitle(title.String()); SetSizeLimits(370, 10000, 200, 10000); }