Pass the favorites menu a reference to the file panel's ref filter. This is necessary since favorites are no longer constrained to only being folders, and as such they need to likewise be constrained to only display supported types. Fixes another part of #4916.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34190 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2009-11-22 23:43:59 +00:00
parent 2795d5dca5
commit 0b0e9179c3
3 changed files with 56 additions and 6 deletions
+42 -3
View File
@@ -32,8 +32,13 @@ names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
#include "FavoritesMenu.h"
#include <compat/sys/stat.h>
#include <Application.h> #include <Application.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <FilePanel.h>
#include <Message.h> #include <Message.h>
#include <Path.h> #include <Path.h>
#include <Query.h> #include <Query.h>
@@ -43,7 +48,6 @@ All rights reserved.
#include <algorithm> #include <algorithm>
#include "EntryIterator.h" #include "EntryIterator.h"
#include "FavoritesMenu.h"
#include "IconMenuItem.h" #include "IconMenuItem.h"
#include "NavMenu.h" #include "NavMenu.h"
#include "PoseView.h" #include "PoseView.h"
@@ -54,14 +58,15 @@ All rights reserved.
FavoritesMenu::FavoritesMenu(const char *title, BMessage *openFolderMessage, FavoritesMenu::FavoritesMenu(const char *title, BMessage *openFolderMessage,
BMessage *openFileMessage, const BMessenger &target, BMessage *openFileMessage, const BMessenger &target,
bool isSavePanel) bool isSavePanel, BRefFilter *filter)
: BSlowMenu(title), : BSlowMenu(title),
fOpenFolderMessage(openFolderMessage), fOpenFolderMessage(openFolderMessage),
fOpenFileMessage(openFileMessage), fOpenFileMessage(openFileMessage),
fTarget(target), fTarget(target),
fContainer(NULL), fContainer(NULL),
fInitialItemCount(0), fInitialItemCount(0),
fIsSavePanel(isSavePanel) fIsSavePanel(isSavePanel),
fRefFilter(filter)
{ {
} }
@@ -74,6 +79,13 @@ FavoritesMenu::~FavoritesMenu()
} }
void
FavoritesMenu::SetRefFilter(BRefFilter *filter)
{
fRefFilter = filter;
}
bool bool
FavoritesMenu::StartBuildingItemList() FavoritesMenu::StartBuildingItemList()
{ {
@@ -143,6 +155,9 @@ FavoritesMenu::AddNextItem()
if (model.InitCheck() != B_OK) if (model.InitCheck() != B_OK)
return true; return true;
if (!ShouldShowModel(&model))
return true;
BMenuItem *item = BNavMenu::NewModelItem(&model, BMenuItem *item = BNavMenu::NewModelItem(&model,
model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage, model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage,
fTarget); fTarget);
@@ -184,10 +199,14 @@ FavoritesMenu::AddNextItem()
entry_ref ref; entry_ref ref;
if (fItems.FindRef("refs", fIndex++, &ref) != B_OK) if (fItems.FindRef("refs", fIndex++, &ref) != B_OK)
break; break;
Model model(&ref, true); Model model(&ref, true);
if (model.InitCheck() != B_OK) if (model.InitCheck() != B_OK)
return true; return true;
if (!ShouldShowModel(&model))
return true;
BMenuItem *item = BNavMenu::NewModelItem(&model, fOpenFileMessage, fTarget); BMenuItem *item = BNavMenu::NewModelItem(&model, fOpenFileMessage, fTarget);
if (item) { if (item) {
if (!fAddedSeparatorForSection) { if (!fAddedSeparatorForSection) {
@@ -232,6 +251,9 @@ FavoritesMenu::AddNextItem()
if (model.InitCheck() != B_OK) if (model.InitCheck() != B_OK)
return true; return true;
if (!ShouldShowModel(&model))
return true;
BMenuItem *item = BNavMenu::NewModelItem(&model, fOpenFolderMessage, BMenuItem *item = BNavMenu::NewModelItem(&model, fOpenFolderMessage,
fTarget, true); fTarget, true);
if (item) { if (item) {
@@ -270,6 +292,23 @@ FavoritesMenu::ClearMenuBuildingState()
} }
bool
FavoritesMenu::ShouldShowModel(const Model *model)
{
if (fIsSavePanel && model->IsFile())
return false;
if (!fRefFilter)
return true;
struct stat_beos statBeOS;
convert_to_stat_beos(model->StatBuf(), &statBeOS);
return fRefFilter->Filter(model->EntryRef(), model->Node(), &statBeOS,
model->MimeType());
}
// #pragma mark - // #pragma mark -
+9 -2
View File
@@ -40,6 +40,8 @@ All rights reserved.
#include "NavMenu.h" #include "NavMenu.h"
#include "ObjectList.h" #include "ObjectList.h"
class BRefFilter;
namespace BPrivate { namespace BPrivate {
class EntryListBase; class EntryListBase;
@@ -52,8 +54,10 @@ class FavoritesMenu : public BSlowMenu {
public: public:
FavoritesMenu(const char *title, BMessage *openFolderMessage, FavoritesMenu(const char *title, BMessage *openFolderMessage,
BMessage *openFileMessage, const BMessenger &, BMessage *openFileMessage, const BMessenger &,
bool isSavePanel); bool isSavePanel, BRefFilter *filter = NULL);
virtual ~FavoritesMenu(); virtual ~FavoritesMenu();
void SetRefFilter(BRefFilter *filter);
private: private:
// override the necessary SlowMenu hooks // override the necessary SlowMenu hooks
@@ -61,7 +65,9 @@ class FavoritesMenu : public BSlowMenu {
virtual bool AddNextItem(); virtual bool AddNextItem();
virtual void DoneBuildingItemList(); virtual void DoneBuildingItemList();
virtual void ClearMenuBuildingState(); virtual void ClearMenuBuildingState();
bool ShouldShowModel(const Model *model);
BMessage *fOpenFolderMessage; BMessage *fOpenFolderMessage;
BMessage *fOpenFileMessage; BMessage *fOpenFileMessage;
BMessenger fTarget; BMessenger fTarget;
@@ -88,6 +94,7 @@ class FavoritesMenu : public BSlowMenu {
int32 fInitialItemCount; int32 fInitialItemCount;
std::vector<entry_ref> fUniqueRefCheck; std::vector<entry_ref> fUniqueRefCheck;
bool fIsSavePanel; bool fIsSavePanel;
BRefFilter *fRefFilter;
typedef BSlowMenu _inherited; typedef BSlowMenu _inherited;
}; };
+5 -1
View File
@@ -441,6 +441,10 @@ TFilePanel::SetRefFilter(BRefFilter *filter)
fPoseView->SetRefFilter(filter); fPoseView->SetRefFilter(filter);
fPoseView->CommitActivePose(); fPoseView->CommitActivePose();
fPoseView->Refresh(); fPoseView->Refresh();
FavoritesMenu *menu = dynamic_cast<FavoritesMenu *>(
fMenuBar->FindItem("Favorites")->Submenu());
if (menu)
menu->SetRefFilter(filter);
} }
@@ -595,7 +599,7 @@ TFilePanel::Init(const BMessage *)
FavoritesMenu *favorites = new FavoritesMenu("Favorites", FavoritesMenu *favorites = new FavoritesMenu("Favorites",
new BMessage(kSwitchDirectory), new BMessage(B_REFS_RECEIVED), new BMessage(kSwitchDirectory), new BMessage(B_REFS_RECEIVED),
BMessenger(this), IsSavePanel()); BMessenger(this), IsSavePanel(), fPoseView->RefFilter());
favorites->AddItem(new BMenuItem("Add Current Folder", favorites->AddItem(new BMenuItem("Add Current Folder",
new BMessage(kAddCurrentDir))); new BMessage(kAddCurrentDir)));
favorites->AddItem(new BMenuItem("Edit Favorites"B_UTF8_ELLIPSIS, favorites->AddItem(new BMenuItem("Edit Favorites"B_UTF8_ELLIPSIS,