* Added a way to set the target for a BDirMenu; this didn't work well with

BNavMenus, anyway.
* This fixes ShowImage trying to open anything that is not on top level.
* Automatic white space cleanup in DirMenu.* - I hope Alex doesn't have any
  changes in this file...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39381 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-11-09 21:58:54 +00:00
parent bd13a264f7
commit 71dc3c41c3
5 changed files with 43 additions and 34 deletions
+2 -2
View File
@@ -82,14 +82,14 @@ ShowImageStatusView::Draw(BRect updateRect)
void void
ShowImageStatusView::MouseDown(BPoint where) ShowImageStatusView::MouseDown(BPoint where)
{ {
BPrivate::BDirMenu* menu = new BDirMenu(NULL, B_REFS_RECEIVED); BPrivate::BDirMenu* menu = new BDirMenu(NULL, BMessenger(kTrackerSignature),
B_REFS_RECEIVED);
BEntry entry; BEntry entry;
if (entry.SetTo(&fRef) == B_OK) if (entry.SetTo(&fRef) == B_OK)
menu->Populate(&entry, Window(), false, false, true, false, true); menu->Populate(&entry, Window(), false, false, true, false, true);
else else
menu->Populate(NULL, Window(), false, false, true, false, true); menu->Populate(NULL, Window(), false, false, true, false, true);
menu->SetTargetForItems(BMessenger(kTrackerSignature));
BPoint point = Bounds().LeftBottom(); BPoint point = Bounds().LeftBottom();
point.y += 3; point.y += 3;
ConvertToScreen(&point); ConvertToScreen(&point);
+1 -2
View File
@@ -308,14 +308,13 @@ BCountView::MouseDown(BPoint)
return; return;
if (!window->TargetModel()->IsRoot()) { if (!window->TargetModel()->IsRoot()) {
BDirMenu *menu = new BDirMenu(NULL, B_REFS_RECEIVED); BDirMenu *menu = new BDirMenu(NULL, be_app, B_REFS_RECEIVED);
BEntry entry; BEntry entry;
if (entry.SetTo(window->TargetModel()->EntryRef()) == B_OK) if (entry.SetTo(window->TargetModel()->EntryRef()) == B_OK)
menu->Populate(&entry, Window(), false, false, true, false, true); menu->Populate(&entry, Window(), false, false, true, false, true);
else else
menu->Populate(NULL, Window(), false, false, true, false, true); menu->Populate(NULL, Window(), false, false, true, false, true);
menu->SetTargetForItems(be_app);
BPoint point = Bounds().LeftBottom(); BPoint point = Bounds().LeftBottom();
point.y += 3; point.y += 3;
ConvertToScreen(&point); ConvertToScreen(&point);
+34 -26
View File
@@ -57,10 +57,14 @@ All rights reserved.
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "DirMenu" #define B_TRANSLATE_CONTEXT "DirMenu"
BDirMenu::BDirMenu(BMenuBar *bar, uint32 command, const char *entryName)
: BPopUpMenu("directories"), BDirMenu::BDirMenu(BMenuBar *bar, BMessenger target, uint32 command,
fMenuBar(bar), const char *entryName)
fCommand(command) :
BPopUpMenu("directories"),
fTarget(target),
fMenuBar(bar),
fCommand(command)
{ {
SetFont(be_plain_font); SetFont(be_plain_font);
if (entryName) if (entryName)
@@ -83,20 +87,20 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow,
try { try {
if (!startEntry) if (!startEntry)
throw (status_t)B_ERROR; throw (status_t)B_ERROR;
Model model(startEntry); Model model(startEntry);
ThrowOnInitCheckError(&model); ThrowOnInitCheckError(&model);
ModelMenuItem *menu = new ModelMenuItem(&model, this, true, true); ModelMenuItem *menu = new ModelMenuItem(&model, this, true, true);
if (fMenuBar) if (fMenuBar)
fMenuBar->AddItem(menu); fMenuBar->AddItem(menu);
BEntry entry(*startEntry); BEntry entry(*startEntry);
bool showDesktop, showDisksIcon; bool showDesktop, showDisksIcon;
{ {
TrackerSettings settings; TrackerSettings settings;
showDesktop = settings.DesktopFilePanelRoot(); showDesktop = settings.DesktopFilePanelRoot();
showDisksIcon = settings.ShowDisksIcon(); showDisksIcon = settings.ShowDisksIcon();
} }
@@ -110,7 +114,7 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow,
parent.SetTo("/"); parent.SetTo("/");
else else
entry.GetParent(&parent); entry.GetParent(&parent);
parent.GetEntry(&entry); parent.GetEntry(&entry);
} }
@@ -118,28 +122,28 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow,
FSGetDeskDir(&desktopDir); FSGetDeskDir(&desktopDir);
BEntry desktopEntry; BEntry desktopEntry;
desktopDir.GetEntry(&desktopEntry); desktopDir.GetEntry(&desktopEntry);
for (;;) { for (;;) {
BNode node(&entry); BNode node(&entry);
ThrowOnInitCheckError(&node); ThrowOnInitCheckError(&node);
PoseInfo info; PoseInfo info;
ReadAttrResult result = ReadAttr(&node, kAttrPoseInfo, ReadAttrResult result = ReadAttr(&node, kAttrPoseInfo,
kAttrPoseInfoForeign, B_RAW_TYPE, 0, &info, sizeof(PoseInfo), kAttrPoseInfoForeign, B_RAW_TYPE, 0, &info, sizeof(PoseInfo),
&PoseInfo::EndianSwap); &PoseInfo::EndianSwap);
BDirectory parent; BDirectory parent;
entry.GetParent(&parent); entry.GetParent(&parent);
bool hitRoot = false; bool hitRoot = false;
// if we're at the root directory skip "mnt" and go straight to "/" // if we're at the root directory skip "mnt" and go straight to "/"
BDirectory dir(&entry); BDirectory dir(&entry);
if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) {
hitRoot = true; hitRoot = true;
parent.SetTo("/"); parent.SetTo("/");
} }
if (showDesktop) { if (showDesktop) {
BEntry root("/"); BEntry root("/");
// warp from "/" to Desktop properly // warp from "/" to Desktop properly
@@ -148,16 +152,17 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow,
AddDisksIconToMenu(reverse); AddDisksIconToMenu(reverse);
entry = desktopEntry; entry = desktopEntry;
} }
if (entry == desktopEntry) if (entry == desktopEntry)
hitRoot = true; hitRoot = true;
} }
if (result == kReadAttrFailed || !info.fInvisible if (result == kReadAttrFailed || !info.fInvisible
|| (showDesktop && desktopEntry == entry)) || (showDesktop && desktopEntry == entry)) {
AddItemToDirMenu(&entry, originatingWindow, reverse, AddItemToDirMenu(&entry, originatingWindow, reverse,
addShortcuts, navMenuEntries); addShortcuts, navMenuEntries);
}
if (hitRoot) { if (hitRoot) {
if (!showDesktop && showDisksIcon && *startEntry != "/") if (!showDesktop && showDisksIcon && *startEntry != "/")
AddDisksIconToMenu(reverse); AddDisksIconToMenu(reverse);
@@ -166,11 +171,11 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow,
parent.GetEntry(&entry); parent.GetEntry(&entry);
} }
// select last item in menu // select last item in menu
if (!select) if (!select)
return; return;
ModelMenuItem *item = dynamic_cast<ModelMenuItem *>(ItemAt(CountItems() - 1)); ModelMenuItem *item = dynamic_cast<ModelMenuItem *>(ItemAt(CountItems() - 1));
if (item) { if (item) {
item->SetMarked(true); item->SetMarked(true);
@@ -195,14 +200,14 @@ BDirMenu::AddItemToDirMenu(const BEntry *entry, BWindow *originatingWindow,
bool atEnd, bool addShortcuts, bool navMenuEntries) bool atEnd, bool addShortcuts, bool navMenuEntries)
{ {
Model model(entry); Model model(entry);
if (model.InitCheck() != B_OK) if (model.InitCheck() != B_OK)
return; return;
BMessage *message = new BMessage(fCommand); BMessage *message = new BMessage(fCommand);
message->AddRef(fEntryName.String(), model.EntryRef()); message->AddRef(fEntryName.String(), model.EntryRef());
// add reference to the container windows model so that we can // add reference to the container windows model so that we can
// close the window if // close the window if
BContainerWindow *window = originatingWindow ? BContainerWindow *window = originatingWindow ?
dynamic_cast<BContainerWindow *>(originatingWindow) : 0; dynamic_cast<BContainerWindow *>(originatingWindow) : 0;
if (window) if (window)
@@ -210,7 +215,8 @@ BDirMenu::AddItemToDirMenu(const BEntry *entry, BWindow *originatingWindow,
sizeof (node_ref)); sizeof (node_ref));
ModelMenuItem *item; ModelMenuItem *item;
if (navMenuEntries) { if (navMenuEntries) {
BNavMenu* subMenu = new BNavMenu(model.Name(), B_REFS_RECEIVED, be_app, window); BNavMenu* subMenu = new BNavMenu(model.Name(), B_REFS_RECEIVED, fTarget,
window);
entry_ref ref; entry_ref ref;
entry->GetRef(&ref); entry->GetRef(&ref);
subMenu->SetNavDir(&ref); subMenu->SetNavDir(&ref);
@@ -233,6 +239,8 @@ BDirMenu::AddItemToDirMenu(const BEntry *entry, BWindow *originatingWindow,
else else
AddItem(item, 0); AddItem(item, 0);
item->SetTarget(fTarget);
if (fMenuBar) { if (fMenuBar) {
ModelMenuItem *menu = dynamic_cast<ModelMenuItem *>(fMenuBar->ItemAt(0)); ModelMenuItem *menu = dynamic_cast<ModelMenuItem *>(fMenuBar->ItemAt(0));
if (menu) { if (menu) {
@@ -248,7 +256,7 @@ BDirMenu::AddDisksIconToMenu(bool atEnd)
{ {
BEntry entry("/"); BEntry entry("/");
Model model(&entry); Model model(&entry);
if (model.InitCheck() != B_OK) if (model.InitCheck() != B_OK)
return; return;
BMessage *message = new BMessage(fCommand); BMessage *message = new BMessage(fCommand);
+5 -3
View File
@@ -44,7 +44,8 @@ namespace BPrivate {
class BDirMenu : public BPopUpMenu { class BDirMenu : public BPopUpMenu {
public: public:
BDirMenu(BMenuBar *, uint32 command, const char *entryName = 0); BDirMenu(BMenuBar *, BMessenger target, uint32 command,
const char *entryName = 0);
virtual ~BDirMenu(); virtual ~BDirMenu();
void Populate(const BEntry *startDir, BWindow *originatingWindow, void Populate(const BEntry *startDir, BWindow *originatingWindow,
@@ -53,10 +54,11 @@ public:
void AddItemToDirMenu(const BEntry *, BWindow *originatingWindow, void AddItemToDirMenu(const BEntry *, BWindow *originatingWindow,
bool atEnd, bool addShortcuts, bool navMenuEntries = false); bool atEnd, bool addShortcuts, bool navMenuEntries = false);
void AddDisksIconToMenu(bool reverse = false); void AddDisksIconToMenu(bool reverse = false);
void SetMenuBar(BMenuBar *); void SetMenuBar(BMenuBar *);
private: private:
BMessenger fTarget;
BMenuBar *fMenuBar; BMenuBar *fMenuBar;
uint32 fCommand; uint32 fCommand;
BString fEntryName; BString fEntryName;
+1 -1
View File
@@ -652,7 +652,7 @@ TFilePanel::Init(const BMessage *)
} }
// add directory menu and menufield // add directory menu and menufield
fDirMenu = new BDirMenu(0, kSwitchDirectory, "refs"); fDirMenu = new BDirMenu(0, this, kSwitchDirectory, "refs");
font_height ht; font_height ht;
be_plain_font->GetHeight(&ht); be_plain_font->GetHeight(&ht);