2 * Copyright 2004-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
10 #include "DirectoryFilePanel.h"
20 #include <compat/sys/stat.h>
23 DirectoryRefFilter::DirectoryRefFilter()
29 DirectoryRefFilter::Filter(const entry_ref
* ref
, BNode
* node
,
30 struct stat_beos
* stat
, const char* mimeType
)
32 if (S_ISDIR(stat
->st_mode
))
35 if (S_ISLNK(stat
->st_mode
)) {
37 BEntry
entry(ref
, true);
38 return entry
.IsDirectory();
45 // #pragma mark - DirectoryFilePanel
48 #undef B_TRANSLATION_CONTEXT
49 #define B_TRANSLATION_CONTEXT "DirectoryFilePanel"
52 DirectoryFilePanel::DirectoryFilePanel(file_panel_mode mode
,
53 BMessenger
* target
, const entry_ref
* startDirectory
, uint32 nodeFlavors
,
54 bool allowMultipleSelection
, BMessage
* message
, BRefFilter
* filter
,
55 bool modal
, bool hideWhenDone
)
57 BFilePanel(mode
, target
, startDirectory
, nodeFlavors
,
58 allowMultipleSelection
, message
, filter
, modal
, hideWhenDone
),
65 DirectoryFilePanel::Show()
67 if (fCurrentButton
== NULL
&& Window()->Lock()) {
68 BView
* background
= Window()->ChildAt(0);
69 BView
* cancel
= background
->FindView("cancel button");
73 rect
= cancel
->Frame();
75 rect
= background
->Bounds();
76 rect
.left
= rect
.right
;
77 rect
.top
= rect
.bottom
- 35;
81 rect
.right
= rect
.left
-= 30;
82 float width
= be_plain_font
->StringWidth(
83 B_TRANSLATE("Select current")) + 20;
84 rect
.left
= width
> 75 ? rect
.right
- width
: rect
.right
- 75;
85 fCurrentButton
= new BButton(rect
, "directoryButton",
86 B_TRANSLATE("Select current"), new BMessage(MSG_DIRECTORY
),
87 B_FOLLOW_RIGHT
| B_FOLLOW_BOTTOM
);
89 background
->AddChild(fCurrentButton
);
90 fCurrentButton
->SetTarget(Messenger());
92 SetButtonLabel(B_DEFAULT_BUTTON
, B_TRANSLATE("Select"));
93 Window()->SetTitle(B_TRANSLATE("Expander: Choose destination"));
105 DirectoryFilePanel::SelectionChanged()
107 // Resize button so that the label fits
108 // maximum width is dictated by the window's size limits
110 if (Window()->Lock()) {
113 Window()->GetSizeLimits(&maxWidth
, &dummy
, &dummy
, &dummy
);
114 maxWidth
-= Window()->Bounds().Width() + 8
115 - fCurrentButton
->Frame().right
;
117 BRect oldBounds
= fCurrentButton
->Bounds();
121 GetPanelDirectory(&ref
);
122 if (asprintf(&label
, B_TRANSLATE("Select '%s'" B_UTF8_ELLIPSIS
),
124 fCurrentButton
->SetLabel(label
);
130 fCurrentButton
->GetPreferredSize(&width
, &height
);
131 if (width
> maxWidth
)
134 fCurrentButton
->ResizeTo(width
, oldBounds
.Height());
135 fCurrentButton
->MoveBy(oldBounds
.Width() - width
, 0);
140 BFilePanel::SelectionChanged();