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.
*/
#include "FavoritesMenu.h"
#include <compat/sys/stat.h>
#include <Application.h>
#include <FindDirectory.h>
#include <FilePanel.h>
#include <Message.h>
#include <Path.h>
#include <Query.h>
@@ -43,7 +48,6 @@ All rights reserved.
#include <algorithm>
#include "EntryIterator.h"
#include "FavoritesMenu.h"
#include "IconMenuItem.h"
#include "NavMenu.h"
#include "PoseView.h"
@@ -54,14 +58,15 @@ All rights reserved.
FavoritesMenu::FavoritesMenu(const char *title, BMessage *openFolderMessage,
BMessage *openFileMessage, const BMessenger &target,
bool isSavePanel)
bool isSavePanel, BRefFilter *filter)
: BSlowMenu(title),
fOpenFolderMessage(openFolderMessage),
fOpenFileMessage(openFileMessage),
fTarget(target),
fContainer(NULL),
fInitialItemCount(0),
fIsSavePanel(isSavePanel)
fIsSavePanel(isSavePanel),
fRefFilter(filter)
{
}
@@ -74,6 +79,13 @@ FavoritesMenu::~FavoritesMenu()
}
void
FavoritesMenu::SetRefFilter(BRefFilter *filter)
{
fRefFilter = filter;
}
bool
FavoritesMenu::StartBuildingItemList()
{
@@ -143,6 +155,9 @@ FavoritesMenu::AddNextItem()
if (model.InitCheck() != B_OK)
return true;
if (!ShouldShowModel(&model))
return true;
BMenuItem *item = BNavMenu::NewModelItem(&model,
model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage,
fTarget);
@@ -184,10 +199,14 @@ FavoritesMenu::AddNextItem()
entry_ref ref;
if (fItems.FindRef("refs", fIndex++, &ref) != B_OK)
break;
Model model(&ref, true);
if (model.InitCheck() != B_OK)
return true;
if (!ShouldShowModel(&model))
return true;
BMenuItem *item = BNavMenu::NewModelItem(&model, fOpenFileMessage, fTarget);
if (item) {
if (!fAddedSeparatorForSection) {
@@ -232,6 +251,9 @@ FavoritesMenu::AddNextItem()
if (model.InitCheck() != B_OK)
return true;
if (!ShouldShowModel(&model))
return true;
BMenuItem *item = BNavMenu::NewModelItem(&model, fOpenFolderMessage,
fTarget, true);
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 -
+9 -2
View File
@@ -40,6 +40,8 @@ All rights reserved.
#include "NavMenu.h"
#include "ObjectList.h"
class BRefFilter;
namespace BPrivate {
class EntryListBase;
@@ -52,8 +54,10 @@ class FavoritesMenu : public BSlowMenu {
public:
FavoritesMenu(const char *title, BMessage *openFolderMessage,
BMessage *openFileMessage, const BMessenger &,
bool isSavePanel);
bool isSavePanel, BRefFilter *filter = NULL);
virtual ~FavoritesMenu();
void SetRefFilter(BRefFilter *filter);
private:
// override the necessary SlowMenu hooks
@@ -61,7 +65,9 @@ class FavoritesMenu : public BSlowMenu {
virtual bool AddNextItem();
virtual void DoneBuildingItemList();
virtual void ClearMenuBuildingState();
bool ShouldShowModel(const Model *model);
BMessage *fOpenFolderMessage;
BMessage *fOpenFileMessage;
BMessenger fTarget;
@@ -88,6 +94,7 @@ class FavoritesMenu : public BSlowMenu {
int32 fInitialItemCount;
std::vector<entry_ref> fUniqueRefCheck;
bool fIsSavePanel;
BRefFilter *fRefFilter;
typedef BSlowMenu _inherited;
};
+5 -1
View File
@@ -441,6 +441,10 @@ TFilePanel::SetRefFilter(BRefFilter *filter)
fPoseView->SetRefFilter(filter);
fPoseView->CommitActivePose();
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",
new BMessage(kSwitchDirectory), new BMessage(B_REFS_RECEIVED),
BMessenger(this), IsSavePanel());
BMessenger(this), IsSavePanel(), fPoseView->RefFilter());
favorites->AddItem(new BMenuItem("Add Current Folder",
new BMessage(kAddCurrentDir)));
favorites->AddItem(new BMenuItem("Edit Favorites"B_UTF8_ELLIPSIS,