xref: /haiku/src/apps/expander/DirectoryFilePanel.cpp (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 /*****************************************************************************/
2 // Expander
3 // Written by Jérôme Duval
4 //
5 // DirectoryFilePanel.cpp
6 //
7 // Copyright (c) 2004 OpenBeOS Project
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included
17 // in all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 /*****************************************************************************/
27 
28 #include "DirectoryFilePanel.h"
29 #include <Window.h>
30 #include <stdio.h>
31 
32 DirectoryRefFilter::DirectoryRefFilter()
33 	: BRefFilter()
34 {
35 }
36 
37 
38 bool
39 DirectoryRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat *st,
40 	const char *filetype)
41 {
42 	return (node->IsDirectory());
43 }
44 
45 
46 DirectoryFilePanel::DirectoryFilePanel(file_panel_mode mode, BMessenger *target,
47 	const entry_ref *start_directory, uint32 node_flavors,
48 	bool allow_multiple_selection, BMessage *message, BRefFilter *filter,
49 	bool modal,	bool hide_when_done)
50 	:BFilePanel(mode,target,start_directory, node_flavors,
51 		allow_multiple_selection,message,filter,modal,hide_when_done),
52 		fCurrentButton(NULL)
53 {
54 }
55 
56 
57 void
58 DirectoryFilePanel::Show()
59 {
60 	if (!fCurrentButton) {
61 		entry_ref ref;
62 		char label[50];
63 		GetPanelDirectory(&ref);
64 		sprintf(label, "Select '%s'", ref.name);
65 		Window()->Lock();
66 		BView *background = Window()->ChildAt(0);
67 		fCurrentButton = new BButton(
68 			BRect(113, background->Bounds().bottom-35, 269, background->Bounds().bottom-10),
69 			"directoryButton", label, new BMessage(MSG_DIRECTORY), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
70 		background->AddChild(fCurrentButton);
71 		SetButtonLabel(B_DEFAULT_BUTTON, "Select");
72 		fCurrentButton->SetTarget(Messenger());
73 		Window()->Unlock();
74 	}
75 	BFilePanel::Show();
76 }
77 
78 void
79 DirectoryFilePanel::SelectionChanged(void)
80 {
81 	entry_ref ref;
82 	char label[50];
83 	GetPanelDirectory(&ref);
84 	Window()->Lock();
85 	sprintf(label, "Select '%s'", ref.name);
86 	fCurrentButton->SetLabel(label);
87 	Window()->Unlock();
88 	BFilePanel::SelectionChanged();
89 }
90