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
= NULL
;
101 menu
= new ModelMenuItem(&model
, this, true, true);
102 fMenuBar
->AddItem(menu
);
105 BEntry
entry(*startEntry
);
107 bool showDesktop
, showDisksIcon
;
109 TrackerSettings settings
;
110 showDesktop
= settings
.DesktopFilePanelRoot();
111 showDisksIcon
= settings
.ShowDisksIcon();
114 // might start one level above startEntry
115 if (!includeStartEntry
) {
117 BDirectory
dir(&entry
);
119 if (!showDesktop
&& dir
.InitCheck() == B_OK
120 && dir
.IsRootDirectory()) {
121 // if we're at the root directory skip "mnt" and
122 // go straight to "/"
124 parent
.GetEntry(&entry
);
126 FSGetParentVirtualDirectoryAware(entry
, entry
);
129 BDirectory desktopDir
;
130 FSGetDeskDir(&desktopDir
);
132 desktopDir
.GetEntry(&desktopEntry
);
136 ThrowOnInitCheckError(&node
);
139 ReadAttrResult result
= ReadAttr(&node
, kAttrPoseInfo
,
140 kAttrPoseInfoForeign
, B_RAW_TYPE
, 0, &info
, sizeof(PoseInfo
),
141 &PoseInfo::EndianSwap
);
144 bool hitRoot
= false;
146 BDirectory
dir(&entry
);
147 if (!showDesktop
&& dir
.InitCheck() == B_OK
148 && dir
.IsRootDirectory()) {
149 // if we're at the root directory skip "mnt" and
150 // go straight to "/"
152 parentEntry
.SetTo("/");
154 FSGetParentVirtualDirectoryAware(entry
, parentEntry
);
158 // warp from "/" to Desktop properly
161 AddDisksIconToMenu(reverse
);
162 entry
= desktopEntry
;
165 if (entry
== desktopEntry
)
169 if (result
== kReadAttrFailed
|| !info
.fInvisible
170 || (showDesktop
&& desktopEntry
== entry
)) {
171 AddItemToDirMenu(&entry
, originatingWindow
, reverse
,
172 addShortcuts
, navMenuEntries
);
176 if (!showDesktop
&& showDisksIcon
&& *startEntry
!= "/")
177 AddDisksIconToMenu(reverse
);
182 if (entry
.InitCheck() != B_OK
)
186 // select last item in menu
191 = dynamic_cast<ModelMenuItem
*>(ItemAt(CountItems() - 1));
193 item
->SetMarked(true);
195 entry
.SetTo(item
->TargetModel()->EntryRef());
196 ThrowOnError(menu
->SetEntry(&entry
));
199 } catch (status_t err
) {
200 PRINT(("BDirMenu::Populate: caught error %s\n", strerror(err
)));
203 error
<< "Error [" << strerror(err
) << "] populating menu";
204 AddItem(new BMenuItem(error
.String(), 0));
211 BDirMenu::AddItemToDirMenu(const BEntry
* entry
, BWindow
* originatingWindow
,
212 bool atEnd
, bool addShortcuts
, bool navMenuEntries
)
215 if (model
.InitCheck() != B_OK
)
218 BMessage
* message
= new BMessage(fCommand
);
219 message
->AddRef(fEntryName
.String(), model
.EntryRef());
221 // add reference to the container windows model so that we can
222 // close the window if
223 BContainerWindow
* window
= originatingWindow
?
224 dynamic_cast<BContainerWindow
*>(originatingWindow
) : 0;
225 if (window
!= NULL
) {
226 message
->AddData("nodeRefsToClose", B_RAW_TYPE
,
227 window
->TargetModel()->NodeRef(), sizeof (node_ref
));
230 if (navMenuEntries
) {
231 BNavMenu
* subMenu
= new BNavMenu(model
.Name(), B_REFS_RECEIVED
,
235 subMenu
->SetNavDir(&ref
);
236 item
= new ModelMenuItem(&model
, subMenu
);
237 item
->SetLabel(model
.Name());
238 item
->SetMessage(message
);
240 item
= new ModelMenuItem(&model
, model
.Name(), message
);
244 if (model
.IsDesktop())
245 item
->SetShortcut('D', B_COMMAND_KEY
);
246 else if (FSIsHomeDir(entry
))
247 item
->SetShortcut('H', B_COMMAND_KEY
);
255 item
->SetTarget(fTarget
);
257 if (fMenuBar
!= NULL
) {
259 = dynamic_cast<ModelMenuItem
*>(fMenuBar
->ItemAt(0));
261 ThrowOnError(menu
->SetEntry(entry
));
262 item
->SetMarked(true);
269 BDirMenu::AddDisksIconToMenu(bool atEnd
)
273 if (model
.InitCheck() != B_OK
)
276 BMessage
* message
= new BMessage(fCommand
);
277 message
->AddRef(fEntryName
.String(), model
.EntryRef());
279 ModelMenuItem
* item
= new ModelMenuItem(&model
,
280 B_TRANSLATE(B_DISKS_DIR_NAME
), message
);