* 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.
*/
#include "RecentItems.h"
#include <Roster.h>
#include "Attributes.h"
@@ -39,11 +42,11 @@ All rights reserved.
#include "Model.h"
#include "NavMenu.h"
#include "PoseView.h"
#include "RecentItems.h"
#include "SlowMenu.h"
#include "Tracker.h"
#include "Utilities.h"
class RecentItemsMenu : public BSlowMenu {
public:
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()
{
delete fTterator;
delete fTargetMesage;
}
bool
RecentItemsMenu::AddNextItem()
{
@@ -97,6 +142,8 @@ RecentItemsMenu::AddNextItem()
// fSanityCount is a hacky way of dealing with a lot of stale
// recent apps
}
bool
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)
: fMaxItems(maxItems),
fNavMenuFolders(navMenuFolders)
:
fMaxItems(maxItems),
fNavMenuFolders(navMenuFolders)
{
InitIconPreloader();
// need the icon cache
@@ -141,8 +251,8 @@ BRecentItemsList::Rewind()
BMenuItem *
BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage,
const BMessage *containerOpenInvokeMessage,
BHandler *target, entry_ref *currentItemRef)
const BMessage *containerOpenInvokeMessage, BHandler *target,
entry_ref *currentItemRef)
{
entry_ref ref;
if (GetNextRef(&ref) != B_OK)
@@ -219,7 +329,7 @@ BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage,
target, 0);
menu->SetNavDir(&ref);
ModelMenuItem *item = new ModelMenuItem(&model, menu);
item = new ModelMenuItem(&model, menu);
item->SetMessage(message);
}
@@ -229,32 +339,37 @@ BRecentItemsList::GetNextMenuItem(const BMessage *fileOpenInvokeMessage,
return item;
}
status_t
BRecentItemsList::GetNextRef(entry_ref *result)
{
return fItems.FindRef("refs", fIndex++, result);
}
// #pragma mark -
BRecentFilesList::BRecentFilesList(int32 maxItems, bool navMenuFolders,
const char *ofType, const char *openedByAppSig)
: BRecentItemsList(maxItems, navMenuFolders),
fType(ofType),
fTypes(NULL),
fTypeCount(0),
fAppSig(openedByAppSig)
:
BRecentItemsList(maxItems, navMenuFolders),
fType(ofType),
fTypes(NULL),
fTypeCount(0),
fAppSig(openedByAppSig)
{
}
BRecentFilesList::BRecentFilesList(int32 maxItems, bool navMenuFolders,
const char *ofTypeList[], int32 ofTypeListCount, const char *openedByAppSig)
: BRecentItemsList(maxItems, navMenuFolders),
fType(NULL),
fTypes(NULL),
fTypeCount(ofTypeListCount),
fAppSig(openedByAppSig)
:
BRecentItemsList(maxItems, navMenuFolders),
fType(NULL),
fTypes(NULL),
fTypeCount(ofTypeListCount),
fAppSig(openedByAppSig)
{
if (fTypeCount) {
fTypes = new char *[ofTypeListCount];
@@ -273,6 +388,7 @@ BRecentFilesList::~BRecentFilesList()
}
}
status_t
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 *
BRecentFilesList::NewFileListMenu(const char *title,
BMessage *openFileMessage, BMessage *openFolderMessage,
@@ -352,6 +418,7 @@ BRecentFilesList::NewFileListMenu(const char *title,
openFolderMessage, target, maxItems, navMenuFolders, ofType, openedByAppSig);
}
BMenu *
BRecentFilesList::NewFileListMenu(const char *title,
BMessage *openFileMessage, BMessage *openFolderMessage,
@@ -363,22 +430,9 @@ BRecentFilesList::NewFileListMenu(const char *title,
ofTypeListCount, openedByAppSig);
}
// #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 *
BRecentFoldersList::NewFolderListMenu(const char *title,
@@ -389,13 +443,16 @@ BRecentFoldersList::NewFolderListMenu(const char *title,
navMenuFolders, openedByAppSig);
}
BRecentFoldersList::BRecentFoldersList(int32 maxItems, bool navMenuFolders,
const char *openedByAppSig)
: BRecentItemsList(maxItems, navMenuFolders),
fAppSig(openedByAppSig)
:
BRecentItemsList(maxItems, navMenuFolders),
fAppSig(openedByAppSig)
{
}
status_t
BRecentFoldersList::GetNextRef(entry_ref *ref)
{
@@ -408,13 +465,17 @@ BRecentFoldersList::GetNextRef(entry_ref *ref)
return BRecentItemsList::GetNextRef(ref);
}
// #pragma mark -
BRecentAppsList::BRecentAppsList(int32 maxItems)
: BRecentItemsList(maxItems, false)
:
BRecentItemsList(maxItems, false)
{
}
status_t
BRecentAppsList::GetNextRef(entry_ref *ref)
{
@@ -425,20 +486,6 @@ BRecentAppsList::GetNextRef(entry_ref *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 *
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);
}