From 71dc3c41c30ddfb0c1ce9dc2a1ef427ed96bfbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 9 Nov 2010 21:58:54 +0000 Subject: [PATCH] * 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 --- src/apps/showimage/ShowImageStatusView.cpp | 4 +- src/kits/tracker/CountView.cpp | 3 +- src/kits/tracker/DirMenu.cpp | 60 ++++++++++++---------- src/kits/tracker/DirMenu.h | 8 +-- src/kits/tracker/FilePanelPriv.cpp | 2 +- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/apps/showimage/ShowImageStatusView.cpp b/src/apps/showimage/ShowImageStatusView.cpp index 4518028e47..0092b4e013 100644 --- a/src/apps/showimage/ShowImageStatusView.cpp +++ b/src/apps/showimage/ShowImageStatusView.cpp @@ -82,14 +82,14 @@ ShowImageStatusView::Draw(BRect updateRect) void 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; if (entry.SetTo(&fRef) == B_OK) menu->Populate(&entry, Window(), false, false, true, false, true); else menu->Populate(NULL, Window(), false, false, true, false, true); - menu->SetTargetForItems(BMessenger(kTrackerSignature)); BPoint point = Bounds().LeftBottom(); point.y += 3; ConvertToScreen(&point); diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp index 52366c3889..0f1ee9bf47 100644 --- a/src/kits/tracker/CountView.cpp +++ b/src/kits/tracker/CountView.cpp @@ -308,14 +308,13 @@ BCountView::MouseDown(BPoint) return; if (!window->TargetModel()->IsRoot()) { - BDirMenu *menu = new BDirMenu(NULL, B_REFS_RECEIVED); + BDirMenu *menu = new BDirMenu(NULL, be_app, B_REFS_RECEIVED); BEntry entry; if (entry.SetTo(window->TargetModel()->EntryRef()) == B_OK) menu->Populate(&entry, Window(), false, false, true, false, true); else menu->Populate(NULL, Window(), false, false, true, false, true); - menu->SetTargetForItems(be_app); BPoint point = Bounds().LeftBottom(); point.y += 3; ConvertToScreen(&point); diff --git a/src/kits/tracker/DirMenu.cpp b/src/kits/tracker/DirMenu.cpp index a7a58445fb..52f2329f81 100644 --- a/src/kits/tracker/DirMenu.cpp +++ b/src/kits/tracker/DirMenu.cpp @@ -57,10 +57,14 @@ All rights reserved. #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "DirMenu" -BDirMenu::BDirMenu(BMenuBar *bar, uint32 command, const char *entryName) - : BPopUpMenu("directories"), - fMenuBar(bar), - fCommand(command) + +BDirMenu::BDirMenu(BMenuBar *bar, BMessenger target, uint32 command, + const char *entryName) + : + BPopUpMenu("directories"), + fTarget(target), + fMenuBar(bar), + fCommand(command) { SetFont(be_plain_font); if (entryName) @@ -83,20 +87,20 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow, try { if (!startEntry) throw (status_t)B_ERROR; - + Model model(startEntry); ThrowOnInitCheckError(&model); - + ModelMenuItem *menu = new ModelMenuItem(&model, this, true, true); - + if (fMenuBar) fMenuBar->AddItem(menu); - + BEntry entry(*startEntry); bool showDesktop, showDisksIcon; { - TrackerSettings settings; + TrackerSettings settings; showDesktop = settings.DesktopFilePanelRoot(); showDisksIcon = settings.ShowDisksIcon(); } @@ -110,7 +114,7 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow, parent.SetTo("/"); else entry.GetParent(&parent); - + parent.GetEntry(&entry); } @@ -118,28 +122,28 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow, FSGetDeskDir(&desktopDir); BEntry desktopEntry; desktopDir.GetEntry(&desktopEntry); - + for (;;) { BNode node(&entry); ThrowOnInitCheckError(&node); - + PoseInfo info; ReadAttrResult result = ReadAttr(&node, kAttrPoseInfo, kAttrPoseInfoForeign, B_RAW_TYPE, 0, &info, sizeof(PoseInfo), &PoseInfo::EndianSwap); - + BDirectory parent; entry.GetParent(&parent); - + bool hitRoot = false; - + // if we're at the root directory skip "mnt" and go straight to "/" BDirectory dir(&entry); if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { hitRoot = true; parent.SetTo("/"); } - + if (showDesktop) { BEntry root("/"); // warp from "/" to Desktop properly @@ -148,16 +152,17 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow, AddDisksIconToMenu(reverse); entry = desktopEntry; } - + if (entry == desktopEntry) hitRoot = true; } - + if (result == kReadAttrFailed || !info.fInvisible - || (showDesktop && desktopEntry == entry)) + || (showDesktop && desktopEntry == entry)) { AddItemToDirMenu(&entry, originatingWindow, reverse, addShortcuts, navMenuEntries); - + } + if (hitRoot) { if (!showDesktop && showDisksIcon && *startEntry != "/") AddDisksIconToMenu(reverse); @@ -166,11 +171,11 @@ BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow, parent.GetEntry(&entry); } - + // select last item in menu if (!select) return; - + ModelMenuItem *item = dynamic_cast(ItemAt(CountItems() - 1)); if (item) { item->SetMarked(true); @@ -195,14 +200,14 @@ BDirMenu::AddItemToDirMenu(const BEntry *entry, BWindow *originatingWindow, bool atEnd, bool addShortcuts, bool navMenuEntries) { Model model(entry); - if (model.InitCheck() != B_OK) + if (model.InitCheck() != B_OK) return; BMessage *message = new BMessage(fCommand); message->AddRef(fEntryName.String(), model.EntryRef()); // add reference to the container windows model so that we can - // close the window if + // close the window if BContainerWindow *window = originatingWindow ? dynamic_cast(originatingWindow) : 0; if (window) @@ -210,7 +215,8 @@ BDirMenu::AddItemToDirMenu(const BEntry *entry, BWindow *originatingWindow, sizeof (node_ref)); ModelMenuItem *item; 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->GetRef(&ref); subMenu->SetNavDir(&ref); @@ -233,6 +239,8 @@ BDirMenu::AddItemToDirMenu(const BEntry *entry, BWindow *originatingWindow, else AddItem(item, 0); + item->SetTarget(fTarget); + if (fMenuBar) { ModelMenuItem *menu = dynamic_cast(fMenuBar->ItemAt(0)); if (menu) { @@ -248,7 +256,7 @@ BDirMenu::AddDisksIconToMenu(bool atEnd) { BEntry entry("/"); Model model(&entry); - if (model.InitCheck() != B_OK) + if (model.InitCheck() != B_OK) return; BMessage *message = new BMessage(fCommand); diff --git a/src/kits/tracker/DirMenu.h b/src/kits/tracker/DirMenu.h index cda6694837..7cef53b352 100644 --- a/src/kits/tracker/DirMenu.h +++ b/src/kits/tracker/DirMenu.h @@ -44,7 +44,8 @@ namespace BPrivate { class BDirMenu : public BPopUpMenu { public: - BDirMenu(BMenuBar *, uint32 command, const char *entryName = 0); + BDirMenu(BMenuBar *, BMessenger target, uint32 command, + const char *entryName = 0); virtual ~BDirMenu(); void Populate(const BEntry *startDir, BWindow *originatingWindow, @@ -53,10 +54,11 @@ public: void AddItemToDirMenu(const BEntry *, BWindow *originatingWindow, bool atEnd, bool addShortcuts, bool navMenuEntries = false); void AddDisksIconToMenu(bool reverse = false); - + void SetMenuBar(BMenuBar *); - + private: + BMessenger fTarget; BMenuBar *fMenuBar; uint32 fCommand; BString fEntryName; diff --git a/src/kits/tracker/FilePanelPriv.cpp b/src/kits/tracker/FilePanelPriv.cpp index c9545f2f34..b517723a7f 100644 --- a/src/kits/tracker/FilePanelPriv.cpp +++ b/src/kits/tracker/FilePanelPriv.cpp @@ -652,7 +652,7 @@ TFilePanel::Init(const BMessage *) } // add directory menu and menufield - fDirMenu = new BDirMenu(0, kSwitchDirectory, "refs"); + fDirMenu = new BDirMenu(0, this, kSwitchDirectory, "refs"); font_height ht; be_plain_font->GetHeight(&ht);