6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
36 // get rid of fMenuBar, SetMenuBar and related mess
41 #include <Directory.h>
46 #include <VolumeRoster.h>
48 #include "Attributes.h"
49 #include "ContainerWindow.h"
52 #include "IconMenuItem.h"
54 #include "TrackerSettings.h"
55 #include "Utilities.h"
58 #undef B_TRANSLATION_CONTEXT
59 #define B_TRANSLATION_CONTEXT "DirMenu"
62 // #pragma mark - BDirMenu
65 BDirMenu::BDirMenu(BMenuBar
* bar
, BMessenger target
, uint32 command
,
66 const char* entryName
)
68 BPopUpMenu("directories"),
73 SetFont(be_plain_font
);
75 fEntryName
= entryName
;
87 BDirMenu::Populate(const BEntry
* startEntry
, BWindow
* originatingWindow
,
88 bool includeStartEntry
, bool select
, bool reverse
, bool addShortcuts
,
93 throw (status_t
)B_ERROR
;
95 Model
model(startEntry
);
96 ThrowOnInitCheckError(&model
);
98 ModelMenuItem
* menu
= new ModelMenuItem(&model
, this, true, true);
101 fMenuBar
->AddItem(menu
);
103 BEntry
entry(*startEntry
);
105 bool showDesktop
, showDisksIcon
;
107 TrackerSettings settings
;
108 showDesktop
= settings
.DesktopFilePanelRoot();
109 showDisksIcon
= settings
.ShowDisksIcon();
112 // might start one level above startEntry
113 if (!includeStartEntry
) {
115 BDirectory
dir(&entry
);
117 if (!showDesktop
&& dir
.InitCheck() == B_OK
118 && dir
.IsRootDirectory()) {
119 // if we're at the root directory skip "mnt" and
120 // go straight to "/"
122 parent
.GetEntry(&entry
);
124 FSGetParentVirtualDirectoryAware(entry
, entry
);
127 BDirectory desktopDir
;
128 FSGetDeskDir(&desktopDir
);
130 desktopDir
.GetEntry(&desktopEntry
);
134 ThrowOnInitCheckError(&node
);
137 ReadAttrResult result
= ReadAttr(&node
, kAttrPoseInfo
,
138 kAttrPoseInfoForeign
, B_RAW_TYPE
, 0, &info
, sizeof(PoseInfo
),
139 &PoseInfo::EndianSwap
);
142 bool hitRoot
= false;
144 BDirectory
dir(&entry
);
145 if (!showDesktop
&& dir
.InitCheck() == B_OK
146 && dir
.IsRootDirectory()) {
147 // if we're at the root directory skip "mnt" and
148 // go straight to "/"
150 parentEntry
.SetTo("/");
152 FSGetParentVirtualDirectoryAware(entry
, parentEntry
);
156 // warp from "/" to Desktop properly
159 AddDisksIconToMenu(reverse
);
160 entry
= desktopEntry
;
163 if (entry
== desktopEntry
)
167 if (result
== kReadAttrFailed
|| !info
.fInvisible
168 || (showDesktop
&& desktopEntry
== entry
)) {
169 AddItemToDirMenu(&entry
, originatingWindow
, reverse
,
170 addShortcuts
, navMenuEntries
);
174 if (!showDesktop
&& showDisksIcon
&& *startEntry
!= "/")
175 AddDisksIconToMenu(reverse
);
180 if (entry
.InitCheck() != B_OK
)
184 // select last item in menu
189 = dynamic_cast<ModelMenuItem
*>(ItemAt(CountItems() - 1));
191 item
->SetMarked(true);
193 entry
.SetTo(item
->TargetModel()->EntryRef());
194 ThrowOnError(menu
->SetEntry(&entry
));
197 } catch (status_t err
) {
198 PRINT(("BDirMenu::Populate: caught error %s\n", strerror(err
)));
201 error
<< "Error [" << strerror(err
) << "] populating menu";
202 AddItem(new BMenuItem(error
.String(), 0));
209 BDirMenu::AddItemToDirMenu(const BEntry
* entry
, BWindow
* originatingWindow
,
210 bool atEnd
, bool addShortcuts
, bool navMenuEntries
)
213 if (model
.InitCheck() != B_OK
)
216 BMessage
* message
= new BMessage(fCommand
);
217 message
->AddRef(fEntryName
.String(), model
.EntryRef());
219 // add reference to the container windows model so that we can
220 // close the window if
221 BContainerWindow
* window
= originatingWindow
?
222 dynamic_cast<BContainerWindow
*>(originatingWindow
) : 0;
223 if (window
!= NULL
) {
224 message
->AddData("nodeRefsToClose", B_RAW_TYPE
,
225 window
->TargetModel()->NodeRef(), sizeof (node_ref
));
228 if (navMenuEntries
) {
229 BNavMenu
* subMenu
= new BNavMenu(model
.Name(), B_REFS_RECEIVED
,
233 subMenu
->SetNavDir(&ref
);
234 item
= new ModelMenuItem(&model
, subMenu
);
235 item
->SetLabel(model
.Name());
236 item
->SetMessage(message
);
238 item
= new ModelMenuItem(&model
, model
.Name(), message
);
242 if (model
.IsDesktop())
243 item
->SetShortcut('D', B_COMMAND_KEY
);
244 else if (FSIsHomeDir(entry
))
245 item
->SetShortcut('H', B_COMMAND_KEY
);
253 item
->SetTarget(fTarget
);
255 if (fMenuBar
!= NULL
) {
257 = dynamic_cast<ModelMenuItem
*>(fMenuBar
->ItemAt(0));
259 ThrowOnError(menu
->SetEntry(entry
));
260 item
->SetMarked(true);
267 BDirMenu::AddDisksIconToMenu(bool atEnd
)
271 if (model
.InitCheck() != B_OK
)
274 BMessage
* message
= new BMessage(fCommand
);
275 message
->AddRef(fEntryName
.String(), model
.EntryRef());
277 ModelMenuItem
* item
= new ModelMenuItem(&model
,
278 B_TRANSLATE(B_DISKS_DIR_NAME
), message
);