* Fixed a bug in BRecentItemsList::GetNextMenuItem() that would prevent it from

correctly adding navigable folders (it did just hide (and leak) any folders
  before).
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38896 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-10-08 13:13:31 +00:00
parent c5e2c3ec4d
commit 3f7a0ba1b0
+144 -98
View File
@@ -32,6 +32,9 @@ names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
#include "RecentItems.h"
#include <Roster.h> #include <Roster.h>
#include "Attributes.h" #include "Attributes.h"
@@ -39,11 +42,11 @@ All rights reserved.
#include "Model.h" #include "Model.h"
#include "NavMenu.h" #include "NavMenu.h"
#include "PoseView.h" #include "PoseView.h"
#include "RecentItems.h"
#include "SlowMenu.h" #include "SlowMenu.h"
#include "Tracker.h" #include "Tracker.h"
#include "Utilities.h" #include "Utilities.h"
class RecentItemsMenu : public BSlowMenu { class RecentItemsMenu : public BSlowMenu {
public: public:
RecentItemsMenu(const char *title, BMessage *openMessage, RecentItemsMenu(const char *title, BMessage *openMessage,
@@ -75,12 +78,54 @@ protected:
}; };
class RecentFilesMenu : public RecentItemsMenu {
public:
RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target,
int32 maxItems, bool navMenuFolders, const char *ofType,
const char *openedByAppSig);
RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target,
int32 maxItems, bool navMenuFolders, const char *ofTypeList[],
int32 ofTypeListCount, const char *openedByAppSig);
virtual ~RecentFilesMenu();
protected:
virtual const BMessage *ContainerMessage()
{ return openFolderMessage; }
private:
BMessage *openFolderMessage;
};
class RecentFoldersMenu : public RecentItemsMenu {
public:
RecentFoldersMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems, bool navMenuFolders,
const char *openedByAppSig);
};
class RecentAppsMenu : public RecentItemsMenu {
public:
RecentAppsMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems);
};
// #pragma mark -
RecentItemsMenu::~RecentItemsMenu() RecentItemsMenu::~RecentItemsMenu()
{ {
delete fTterator; delete fTterator;
delete fTargetMesage; delete fTargetMesage;
} }
bool bool
RecentItemsMenu::AddNextItem() RecentItemsMenu::AddNextItem()
{ {
@@ -97,6 +142,8 @@ RecentItemsMenu::AddNextItem()
// fSanityCount is a hacky way of dealing with a lot of stale // fSanityCount is a hacky way of dealing with a lot of stale
// recent apps // recent apps
} }
bool bool
RecentItemsMenu::StartBuildingItemList() RecentItemsMenu::StartBuildingItemList()
{ {
@@ -121,9 +168,72 @@ RecentItemsMenu::ClearMenuBuildingState()
} }
// #pragma mark -
RecentFilesMenu::RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target, int32 maxItems,
bool navMenuFolders, const char *ofType, const char *openedByAppSig)
:
RecentItemsMenu(title, openFileMessage, target, maxItems),
openFolderMessage(openFolderMessage)
{
fTterator = new BRecentFilesList(maxItems + 10, navMenuFolders,
ofType, openedByAppSig);
}
RecentFilesMenu::RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target, int32 maxItems,
bool navMenuFolders, const char *ofTypeList[], int32 ofTypeListCount,
const char *openedByAppSig)
:
RecentItemsMenu(title, openFileMessage, target, maxItems),
openFolderMessage(openFolderMessage)
{
fTterator = new BRecentFilesList(maxItems + 10, navMenuFolders,
ofTypeList, ofTypeListCount, openedByAppSig);
}
RecentFilesMenu::~RecentFilesMenu()
{
delete openFolderMessage;
}
// #pragma mark -
RecentFoldersMenu::RecentFoldersMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems, bool navMenuFolders,
const char *openedByAppSig)
:
RecentItemsMenu(title, openMessage, target, maxItems)
{
fTterator = new BRecentFoldersList(maxItems + 10, navMenuFolders,
openedByAppSig);
}
// #pragma mark -
RecentAppsMenu::RecentAppsMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems)
: RecentItemsMenu(title, openMessage, target, maxItems)
{
fTterator = new BRecentAppsList(maxItems);
}
// #pragma mark -
BRecentItemsList::BRecentItemsList(int32 maxItems, bool navMenuFolders) BRecentItemsList::BRecentItemsList(int32 maxItems, bool navMenuFolders)
: fMaxItems(maxItems), :
fNavMenuFolders(navMenuFolders) fMaxItems(maxItems),
fNavMenuFolders(navMenuFolders)
{ {
InitIconPreloader(); InitIconPreloader();
// need the icon cache // need the icon cache
@@ -141,8 +251,8 @@ BRecentItemsList::Rewind()
BMenuItem * BMenuItem *
BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage, BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage,
const BMessage *containerOpenInvokeMessage, const BMessage *containerOpenInvokeMessage, BHandler *target,
BHandler *target, entry_ref *currentItemRef) entry_ref *currentItemRef)
{ {
entry_ref ref; entry_ref ref;
if (GetNextRef(&ref) != B_OK) if (GetNextRef(&ref) != B_OK)
@@ -219,7 +329,7 @@ BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage,
target, 0); target, 0);
menu->SetNavDir(&ref); menu->SetNavDir(&ref);
ModelMenuItem *item = new ModelMenuItem(&model, menu); item = new ModelMenuItem(&model, menu);
item->SetMessage(message); item->SetMessage(message);
} }
@@ -229,32 +339,37 @@ BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage,
return item; return item;
} }
status_t status_t
BRecentItemsList::GetNextRef(entry_ref *result) BRecentItemsList::GetNextRef(entry_ref *result)
{ {
return fItems.FindRef("refs", fIndex++, result); return fItems.FindRef("refs", fIndex++, result);
} }
// #pragma mark - // #pragma mark -
BRecentFilesList::BRecentFilesList(int32 maxItems, bool navMenuFolders, BRecentFilesList::BRecentFilesList(int32 maxItems, bool navMenuFolders,
const char *ofType, const char *openedByAppSig) const char *ofType, const char *openedByAppSig)
: BRecentItemsList(maxItems, navMenuFolders), :
fType(ofType), BRecentItemsList(maxItems, navMenuFolders),
fTypes(NULL), fType(ofType),
fTypeCount(0), fTypes(NULL),
fAppSig(openedByAppSig) fTypeCount(0),
fAppSig(openedByAppSig)
{ {
} }
BRecentFilesList::BRecentFilesList(int32 maxItems, bool navMenuFolders, BRecentFilesList::BRecentFilesList(int32 maxItems, bool navMenuFolders,
const char *ofTypeList[], int32 ofTypeListCount, const char *openedByAppSig) const char *ofTypeList[], int32 ofTypeListCount, const char *openedByAppSig)
: BRecentItemsList(maxItems, navMenuFolders), :
fType(NULL), BRecentItemsList(maxItems, navMenuFolders),
fTypes(NULL), fType(NULL),
fTypeCount(ofTypeListCount), fTypes(NULL),
fAppSig(openedByAppSig) fTypeCount(ofTypeListCount),
fAppSig(openedByAppSig)
{ {
if (fTypeCount) { if (fTypeCount) {
fTypes = new char *[ofTypeListCount]; fTypes = new char *[ofTypeListCount];
@@ -273,6 +388,7 @@ BRecentFilesList::~BRecentFilesList()
} }
} }
status_t status_t
BRecentFilesList::GetNextRef(entry_ref *ref) BRecentFilesList::GetNextRef(entry_ref *ref)
{ {
@@ -292,56 +408,6 @@ BRecentFilesList::GetNextRef(entry_ref *ref)
} }
class RecentFilesMenu : public RecentItemsMenu {
public:
RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target,
int32 maxItems, bool navMenuFolders, const char *ofType,
const char *openedByAppSig);
RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target,
int32 maxItems, bool navMenuFolders, const char *ofTypeList[],
int32 ofTypeListCount, const char *openedByAppSig);
virtual ~RecentFilesMenu();
protected:
virtual const BMessage *ContainerMessage()
{ return openFolderMessage; }
private:
BMessage *openFolderMessage;
};
RecentFilesMenu::RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target, int32 maxItems,
bool navMenuFolders, const char *ofType, const char *openedByAppSig)
: RecentItemsMenu(title, openFileMessage, target, maxItems),
openFolderMessage(openFolderMessage)
{
fTterator = new BRecentFilesList(maxItems + 10, navMenuFolders,
ofType, openedByAppSig);
}
RecentFilesMenu::RecentFilesMenu(const char *title, BMessage *openFileMessage,
BMessage *openFolderMessage, BHandler *target, int32 maxItems,
bool navMenuFolders, const char *ofTypeList[], int32 ofTypeListCount,
const char *openedByAppSig)
: RecentItemsMenu(title, openFileMessage, target, maxItems),
openFolderMessage(openFolderMessage)
{
fTterator = new BRecentFilesList(maxItems + 10, navMenuFolders,
ofTypeList, ofTypeListCount, openedByAppSig);
}
RecentFilesMenu::~RecentFilesMenu()
{
delete openFolderMessage;
}
BMenu * BMenu *
BRecentFilesList::NewFileListMenu(const char *title, BRecentFilesList::NewFileListMenu(const char *title,
BMessage *openFileMessage, BMessage *openFolderMessage, BMessage *openFileMessage, BMessage *openFolderMessage,
@@ -352,6 +418,7 @@ BRecentFilesList::NewFileListMenu(const char *title,
openFolderMessage, target, maxItems, navMenuFolders, ofType, openedByAppSig); openFolderMessage, target, maxItems, navMenuFolders, ofType, openedByAppSig);
} }
BMenu * BMenu *
BRecentFilesList::NewFileListMenu(const char *title, BRecentFilesList::NewFileListMenu(const char *title,
BMessage *openFileMessage, BMessage *openFolderMessage, BMessage *openFileMessage, BMessage *openFolderMessage,
@@ -363,22 +430,9 @@ BRecentFilesList::NewFileListMenu(const char *title,
ofTypeListCount, openedByAppSig); ofTypeListCount, openedByAppSig);
} }
// #pragma mark - // #pragma mark -
class RecentFoldersMenu : public RecentItemsMenu {
public:
RecentFoldersMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems, bool navMenuFolders,
const char *openedByAppSig);
};
RecentFoldersMenu::RecentFoldersMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems, bool navMenuFolders, const char *openedByAppSig)
: RecentItemsMenu(title, openMessage, target, maxItems)
{
fTterator = new BRecentFoldersList(maxItems + 10, navMenuFolders,
openedByAppSig);
}
BMenu * BMenu *
BRecentFoldersList::NewFolderListMenu(const char *title, BRecentFoldersList::NewFolderListMenu(const char *title,
@@ -389,13 +443,16 @@ BRecentFoldersList::NewFolderListMenu(const char *title,
navMenuFolders, openedByAppSig); navMenuFolders, openedByAppSig);
} }
BRecentFoldersList::BRecentFoldersList(int32 maxItems, bool navMenuFolders, BRecentFoldersList::BRecentFoldersList(int32 maxItems, bool navMenuFolders,
const char *openedByAppSig) const char *openedByAppSig)
: BRecentItemsList(maxItems, navMenuFolders), :
fAppSig(openedByAppSig) BRecentItemsList(maxItems, navMenuFolders),
fAppSig(openedByAppSig)
{ {
} }
status_t status_t
BRecentFoldersList::GetNextRef(entry_ref *ref) BRecentFoldersList::GetNextRef(entry_ref *ref)
{ {
@@ -408,13 +465,17 @@ BRecentFoldersList::GetNextRef(entry_ref *ref)
return BRecentItemsList::GetNextRef(ref); return BRecentItemsList::GetNextRef(ref);
} }
// #pragma mark - // #pragma mark -
BRecentAppsList::BRecentAppsList(int32 maxItems) BRecentAppsList::BRecentAppsList(int32 maxItems)
: BRecentItemsList(maxItems, false) :
BRecentItemsList(maxItems, false)
{ {
} }
status_t status_t
BRecentAppsList::GetNextRef(entry_ref *ref) BRecentAppsList::GetNextRef(entry_ref *ref)
{ {
@@ -425,20 +486,6 @@ BRecentAppsList::GetNextRef(entry_ref *ref)
return BRecentItemsList::GetNextRef(ref); return BRecentItemsList::GetNextRef(ref);
} }
class RecentAppsMenu : public RecentItemsMenu {
public:
RecentAppsMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems);
};
RecentAppsMenu::RecentAppsMenu(const char *title, BMessage *openMessage,
BHandler *target, int32 maxItems)
: RecentItemsMenu(title, openMessage, target, maxItems)
{
fTterator = new BRecentAppsList(maxItems);
}
BMenu * BMenu *
BRecentAppsList::NewAppListMenu(const char *title, BMessage *openMessage, BRecentAppsList::NewAppListMenu(const char *title, BMessage *openMessage,
@@ -446,4 +493,3 @@ BRecentAppsList::NewAppListMenu(const char *title, BMessage *openMessage,
{ {
return new RecentAppsMenu(title, openMessage, target, maxItems); return new RecentAppsMenu(title, openMessage, target, maxItems);
} }