Tracker: NavMenu style fixes
This commit is contained in:
+120
-103
@@ -79,51 +79,52 @@ enum nav_flags {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
SpringLoadedFolderCompareMessages(const BMessage* incoming,
|
SpringLoadedFolderCompareMessages(const BMessage* incoming,
|
||||||
const BMessage* dragmessage)
|
const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
if (!dragmessage || !incoming)
|
if (incoming == NULL || dragMessage == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool retvalue = false;
|
bool refsMatch = false;
|
||||||
for (int32 inIndex = 0; incoming->HasRef("refs", inIndex); inIndex++) {
|
for (int32 inIndex = 0; incoming->HasRef("refs", inIndex); inIndex++) {
|
||||||
entry_ref inRef;
|
entry_ref inRef;
|
||||||
if (incoming->FindRef("refs", inIndex, &inRef) != B_OK) {
|
if (incoming->FindRef("refs", inIndex, &inRef) != B_OK) {
|
||||||
retvalue = false;
|
refsMatch = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool inRefMatch = false;
|
bool inRefMatch = false;
|
||||||
for (int32 dragIndex = 0; dragmessage->HasRef("refs", dragIndex);
|
for (int32 dragIndex = 0; dragMessage->HasRef("refs", dragIndex);
|
||||||
dragIndex++) {
|
dragIndex++) {
|
||||||
entry_ref dragRef;
|
entry_ref dragRef;
|
||||||
if (dragmessage->FindRef("refs", dragIndex, &dragRef) != B_OK) {
|
if (dragMessage->FindRef("refs", dragIndex, &dragRef) != B_OK) {
|
||||||
inRefMatch = false;
|
inRefMatch = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// if the incoming ref matches any ref in the drag ref
|
// if the incoming ref matches any ref in the drag ref
|
||||||
// then we can try the next incoming ref
|
// then we can try the next incoming ref
|
||||||
if (inRef == dragRef) {
|
if (inRef == dragRef) {
|
||||||
inRefMatch = true;
|
inRefMatch = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retvalue = inRefMatch;
|
refsMatch = inRefMatch;
|
||||||
if (!inRefMatch)
|
if (!inRefMatch)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retvalue) {
|
if (refsMatch) {
|
||||||
// if all the refs match
|
// If all the refs match try and see if this is a new drag with
|
||||||
// try and see if this is another instance of the same
|
// the same drag contents.
|
||||||
// drag contents, but new drag
|
refsMatch = false;
|
||||||
retvalue = false;
|
BPoint incomingPoint;
|
||||||
BPoint inPt, dPt;
|
BPoint dragPoint;
|
||||||
if (incoming->FindPoint("click_pt", &inPt) == B_OK)
|
if (incoming->FindPoint("click_pt", &incomingPoint) == B_OK
|
||||||
if (dragmessage->FindPoint("click_pt", &dPt) == B_OK)
|
&& dragMessage->FindPoint("click_pt", &dragPoint) == B_OK) {
|
||||||
retvalue = (inPt == dPt);
|
refsMatch = incomingPoint == dragPoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retvalue;
|
return refsMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -131,13 +132,11 @@ void
|
|||||||
SpringLoadedFolderSetMenuStates(const BMenu* menu,
|
SpringLoadedFolderSetMenuStates(const BMenu* menu,
|
||||||
const BObjectList<BString>* typeslist)
|
const BObjectList<BString>* typeslist)
|
||||||
{
|
{
|
||||||
if (!menu || !typeslist || typeslist->IsEmpty())
|
if (menu == NULL || typeslist == NULL || typeslist->IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if a types list exists
|
// If a types list exists iterate through the list and see if each item
|
||||||
// iterate through the list and see if each item
|
// can support any item in the list and set the enabled state of the item.
|
||||||
// can support any item in the list
|
|
||||||
// set the enabled state of the item
|
|
||||||
int32 count = menu->CountItems();
|
int32 count = menu->CountItems();
|
||||||
for (int32 index = 0 ; index < count ; index++) {
|
for (int32 index = 0 ; index < count ; index++) {
|
||||||
ModelMenuItem* item = dynamic_cast<ModelMenuItem*>(menu->ItemAt(index));
|
ModelMenuItem* item = dynamic_cast<ModelMenuItem*>(menu->ItemAt(index));
|
||||||
@@ -149,23 +148,25 @@ SpringLoadedFolderSetMenuStates(const BMenu* menu,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (model->IsSymLink()) {
|
if (model->IsSymLink()) {
|
||||||
// find out what the model is, resolve if symlink
|
// find out what the model is, resolve if symlink
|
||||||
BEntry entry(model->EntryRef(), true);
|
BEntry entry(model->EntryRef(), true);
|
||||||
if (entry.InitCheck() == B_OK) {
|
if (entry.InitCheck() == B_OK) {
|
||||||
if (entry.IsDirectory()) {
|
if (entry.IsDirectory()) {
|
||||||
// folder? always keep enabled
|
// folder? always keep enabled
|
||||||
item->SetEnabled(true);
|
item->SetEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
// other, check its support
|
// other, check its support
|
||||||
Model resolvedModel(&entry);
|
Model resolvedModel(&entry);
|
||||||
int32 supported = resolvedModel.SupportsMimeType(NULL, typeslist);
|
int32 supported
|
||||||
|
= resolvedModel.SupportsMimeType(NULL, typeslist);
|
||||||
item->SetEnabled(supported != kDoesNotSupportType);
|
item->SetEnabled(supported != kDoesNotSupportType);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
// bad entry ref (bad symlink?), disable
|
// bad entry ref (bad symlink?), disable
|
||||||
item->SetEnabled(false);
|
item->SetEnabled(false);
|
||||||
|
}
|
||||||
} else if (model->IsDirectory() || model->IsRoot() || model->IsVolume())
|
} else if (model->IsDirectory() || model->IsRoot() || model->IsVolume())
|
||||||
// always enabled if a container
|
// always enabled if a container
|
||||||
item->SetEnabled(true);
|
item->SetEnabled(true);
|
||||||
else if (model->IsFile() || model->IsExecutable()) {
|
else if (model->IsFile() || model->IsExecutable()) {
|
||||||
int32 supported = model->SupportsMimeType(NULL, typeslist);
|
int32 supported = model->SupportsMimeType(NULL, typeslist);
|
||||||
@@ -180,10 +181,10 @@ void
|
|||||||
SpringLoadedFolderAddUniqueTypeToList(entry_ref* ref,
|
SpringLoadedFolderAddUniqueTypeToList(entry_ref* ref,
|
||||||
BObjectList<BString>* typeslist)
|
BObjectList<BString>* typeslist)
|
||||||
{
|
{
|
||||||
if (!ref || !typeslist)
|
if (ref == NULL || typeslist == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// get the mime type for the current ref
|
// get the mime type for the current ref
|
||||||
BNodeInfo nodeinfo;
|
BNodeInfo nodeinfo;
|
||||||
BNode node(ref);
|
BNode node(ref);
|
||||||
if (node.InitCheck() != B_OK)
|
if (node.InitCheck() != B_OK)
|
||||||
@@ -192,30 +193,30 @@ SpringLoadedFolderAddUniqueTypeToList(entry_ref* ref,
|
|||||||
nodeinfo.SetTo(&node);
|
nodeinfo.SetTo(&node);
|
||||||
|
|
||||||
char mimestr[B_MIME_TYPE_LENGTH];
|
char mimestr[B_MIME_TYPE_LENGTH];
|
||||||
// add it to the list
|
// add it to the list
|
||||||
if (nodeinfo.GetType(mimestr) == B_OK && strlen(mimestr) > 0) {
|
if (nodeinfo.GetType(mimestr) == B_OK && strlen(mimestr) > 0) {
|
||||||
// if this is a symlink, add symlink to the list (below)
|
// If this is a symlink, add symlink to the list (below)
|
||||||
// resolve the symlink, add the resolved type
|
// resolve the symlink, add the resolved type to the list.
|
||||||
// to the list
|
|
||||||
if (strcmp(B_LINK_MIMETYPE, mimestr) == 0) {
|
if (strcmp(B_LINK_MIMETYPE, mimestr) == 0) {
|
||||||
BEntry entry(ref, true);
|
BEntry entry(ref, true);
|
||||||
if (entry.InitCheck() == B_OK) {
|
if (entry.InitCheck() == B_OK) {
|
||||||
entry_ref resolvedRef;
|
entry_ref resolvedRef;
|
||||||
if (entry.GetRef(&resolvedRef) == B_OK)
|
if (entry.GetRef(&resolvedRef) == B_OK)
|
||||||
SpringLoadedFolderAddUniqueTypeToList(&resolvedRef, typeslist);
|
SpringLoadedFolderAddUniqueTypeToList(&resolvedRef,
|
||||||
|
typeslist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// scan the current list, don't add dups
|
// scan the current list, don't add dups
|
||||||
bool unique = true;
|
bool isUnique = true;
|
||||||
int32 count = typeslist->CountItems();
|
int32 count = typeslist->CountItems();
|
||||||
for (int32 index = 0 ; index < count ; index++) {
|
for (int32 index = 0 ; index < count ; index++) {
|
||||||
if (typeslist->ItemAt(index)->Compare(mimestr) == 0) {
|
if (typeslist->ItemAt(index)->Compare(mimestr) == 0) {
|
||||||
unique = false;
|
isUnique = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unique)
|
if (isUnique)
|
||||||
typeslist->AddItem(new BString(mimestr));
|
typeslist->AddItem(new BString(mimestr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,7 +226,7 @@ void
|
|||||||
SpringLoadedFolderCacheDragData(const BMessage* incoming, BMessage** message,
|
SpringLoadedFolderCacheDragData(const BMessage* incoming, BMessage** message,
|
||||||
BObjectList<BString>** typeslist)
|
BObjectList<BString>** typeslist)
|
||||||
{
|
{
|
||||||
if (!incoming)
|
if (incoming == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete* message;
|
delete* message;
|
||||||
@@ -249,25 +250,28 @@ SpringLoadedFolderCacheDragData(const BMessage* incoming, BMessage** message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark - BNavMenu
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "NavMenu"
|
#define B_TRANSLATION_CONTEXT "NavMenu"
|
||||||
|
|
||||||
|
|
||||||
BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
|
BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
|
||||||
BWindow* parentWindow, const BObjectList<BString>* list)
|
BWindow* parentWindow, const BObjectList<BString>* list)
|
||||||
: BSlowMenu(title),
|
:
|
||||||
fMessage(message),
|
BSlowMenu(title),
|
||||||
fMessenger(target, target->Looper()),
|
fMessage(message),
|
||||||
fParentWindow(parentWindow),
|
fMessenger(target, target->Looper()),
|
||||||
fFlags(0),
|
fParentWindow(parentWindow),
|
||||||
fItemList(0),
|
fFlags(0),
|
||||||
fContainer(0),
|
fItemList(0),
|
||||||
fTypesList(new BObjectList<BString>(10, true))
|
fContainer(0),
|
||||||
|
fTypesList(new BObjectList<BString>(10, true))
|
||||||
{
|
{
|
||||||
if (list != NULL)
|
if (list != NULL)
|
||||||
*fTypesList = *list;
|
*fTypesList = *list;
|
||||||
|
|
||||||
InitIconPreloader();
|
InitIconPreloader();
|
||||||
|
|
||||||
SetFont(be_plain_font);
|
SetFont(be_plain_font);
|
||||||
@@ -276,9 +280,10 @@ BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
|
|||||||
// can be closed if option modifier held down during invocation
|
// can be closed if option modifier held down during invocation
|
||||||
BContainerWindow* originatingWindow =
|
BContainerWindow* originatingWindow =
|
||||||
dynamic_cast<BContainerWindow*>(fParentWindow);
|
dynamic_cast<BContainerWindow*>(fParentWindow);
|
||||||
if (originatingWindow)
|
if (originatingWindow != NULL) {
|
||||||
fMessage.AddData("nodeRefsToClose", B_RAW_TYPE,
|
fMessage.AddData("nodeRefsToClose", B_RAW_TYPE,
|
||||||
originatingWindow->TargetModel()->NodeRef(), sizeof (node_ref));
|
originatingWindow->TargetModel()->NodeRef(), sizeof(node_ref));
|
||||||
|
}
|
||||||
|
|
||||||
// too long to have triggers
|
// too long to have triggers
|
||||||
SetTriggersEnabled(false);
|
SetTriggersEnabled(false);
|
||||||
@@ -288,17 +293,19 @@ BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
|
|||||||
BNavMenu::BNavMenu(const char* title, uint32 message,
|
BNavMenu::BNavMenu(const char* title, uint32 message,
|
||||||
const BMessenger& messenger, BWindow* parentWindow,
|
const BMessenger& messenger, BWindow* parentWindow,
|
||||||
const BObjectList<BString>* list)
|
const BObjectList<BString>* list)
|
||||||
: BSlowMenu(title),
|
:
|
||||||
fMessage(message),
|
BSlowMenu(title),
|
||||||
fMessenger(messenger),
|
fMessage(message),
|
||||||
fParentWindow(parentWindow),
|
fMessenger(messenger),
|
||||||
fFlags(0),
|
fParentWindow(parentWindow),
|
||||||
fItemList(0),
|
fFlags(0),
|
||||||
fContainer(0),
|
fItemList(NULL),
|
||||||
fTypesList(new BObjectList<BString>(10, true))
|
fContainer(NULL),
|
||||||
|
fTypesList(new BObjectList<BString>(10, true))
|
||||||
{
|
{
|
||||||
if (list != NULL)
|
if (list != NULL)
|
||||||
*fTypesList = *list;
|
*fTypesList = *list;
|
||||||
|
|
||||||
InitIconPreloader();
|
InitIconPreloader();
|
||||||
|
|
||||||
SetFont(be_plain_font);
|
SetFont(be_plain_font);
|
||||||
@@ -307,9 +314,10 @@ BNavMenu::BNavMenu(const char* title, uint32 message,
|
|||||||
// can be closed if option modifier held down during invocation
|
// can be closed if option modifier held down during invocation
|
||||||
BContainerWindow* originatingWindow =
|
BContainerWindow* originatingWindow =
|
||||||
dynamic_cast<BContainerWindow*>(fParentWindow);
|
dynamic_cast<BContainerWindow*>(fParentWindow);
|
||||||
if (originatingWindow)
|
if (originatingWindow != NULL) {
|
||||||
fMessage.AddData("nodeRefsToClose", B_RAW_TYPE,
|
fMessage.AddData("nodeRefsToClose", B_RAW_TYPE,
|
||||||
originatingWindow->TargetModel()->NodeRef(), sizeof (node_ref));
|
originatingWindow->TargetModel()->NodeRef(), sizeof (node_ref));
|
||||||
|
}
|
||||||
|
|
||||||
// too long to have triggers
|
// too long to have triggers
|
||||||
SetTriggersEnabled(false);
|
SetTriggersEnabled(false);
|
||||||
@@ -328,12 +336,10 @@ BNavMenu::AttachedToWindow()
|
|||||||
BSlowMenu::AttachedToWindow();
|
BSlowMenu::AttachedToWindow();
|
||||||
|
|
||||||
SpringLoadedFolderSetMenuStates(this, fTypesList);
|
SpringLoadedFolderSetMenuStates(this, fTypesList);
|
||||||
// if dragging (fTypesList != NULL)
|
// If dragging, (fTypesList != NULL) set the menu items enabled state
|
||||||
// set the menu items enabled state
|
// relative to the ability to handle an item in the drag message.
|
||||||
// relative to the ability to handle an item in the
|
|
||||||
// drag message
|
|
||||||
ResetTargets();
|
ResetTargets();
|
||||||
// allow an opportunity to reset the target for each of the items
|
// allow an opportunity to reset the target for each of the items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -383,7 +389,7 @@ BNavMenu::ClearMenuBuildingState()
|
|||||||
|
|
||||||
// item list is non-owning, need to delete the items because
|
// item list is non-owning, need to delete the items because
|
||||||
// they didn't get added to the menu
|
// they didn't get added to the menu
|
||||||
if (fItemList) {
|
if (fItemList != NULL) {
|
||||||
int32 count = fItemList->CountItems();
|
int32 count = fItemList->CountItems();
|
||||||
for (int32 index = count - 1; index >= 0; index--)
|
for (int32 index = count - 1; index >= 0; index--)
|
||||||
delete RemoveItem(index);
|
delete RemoveItem(index);
|
||||||
@@ -399,8 +405,9 @@ BNavMenu::StartBuildingItemList()
|
|||||||
BEntry entry;
|
BEntry entry;
|
||||||
|
|
||||||
if (fNavDir.device < 0 || entry.SetTo(&fNavDir, true) != B_OK
|
if (fNavDir.device < 0 || entry.SetTo(&fNavDir, true) != B_OK
|
||||||
|| !entry.Exists())
|
|| !entry.Exists()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fItemList = new BObjectList<BMenuItem>(50);
|
fItemList = new BObjectList<BMenuItem>(50);
|
||||||
|
|
||||||
@@ -443,13 +450,15 @@ BNavMenu::StartBuildingItemList()
|
|||||||
|
|
||||||
BDirectory trashDir;
|
BDirectory trashDir;
|
||||||
|
|
||||||
if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK)
|
if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) {
|
||||||
dynamic_cast<EntryIteratorList*>(fContainer)->
|
dynamic_cast<EntryIteratorList*>(fContainer)->
|
||||||
AddItem(new DirectoryEntryList(trashDir));
|
AddItem(new DirectoryEntryList(trashDir));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*>
|
fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*>(
|
||||||
(startModel.Node()));
|
startModel.Node()));
|
||||||
|
}
|
||||||
|
|
||||||
if (fContainer == NULL || fContainer->InitCheck() != B_OK)
|
if (fContainer == NULL || fContainer->InitCheck() != B_OK)
|
||||||
return false;
|
return false;
|
||||||
@@ -467,13 +476,13 @@ BNavMenu::AddRootItemsIfNeeded()
|
|||||||
roster.Rewind();
|
roster.Rewind();
|
||||||
BVolume volume;
|
BVolume volume;
|
||||||
while (roster.GetNextVolume(&volume) == B_OK) {
|
while (roster.GetNextVolume(&volume) == B_OK) {
|
||||||
|
|
||||||
BDirectory root;
|
BDirectory root;
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
if (!volume.IsPersistent()
|
if (!volume.IsPersistent()
|
||||||
|| volume.GetRootDirectory(&root) != B_OK
|
|| volume.GetRootDirectory(&root) != B_OK
|
||||||
|| root.GetEntry(&entry) != B_OK)
|
|| root.GetEntry(&entry) != B_OK) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Model model(&entry);
|
Model model(&entry);
|
||||||
AddOneItem(&model);
|
AddOneItem(&model);
|
||||||
@@ -496,7 +505,7 @@ BNavMenu::AddTrashItem()
|
|||||||
bool
|
bool
|
||||||
BNavMenu::AddNextItem()
|
BNavMenu::AddNextItem()
|
||||||
{
|
{
|
||||||
if (fFlags & kVolumesOnly) {
|
if ((fFlags & kVolumesOnly) != 0) {
|
||||||
BuildVolumeMenu();
|
BuildVolumeMenu();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -529,19 +538,21 @@ BNavMenu::AddNextItem()
|
|||||||
|
|
||||||
ssize_t size = -1;
|
ssize_t size = -1;
|
||||||
PoseInfo poseInfo;
|
PoseInfo poseInfo;
|
||||||
|
if (model.Node() != NULL) {
|
||||||
if (model.Node())
|
|
||||||
size = model.Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
|
size = model.Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
|
||||||
&poseInfo, sizeof(poseInfo));
|
&poseInfo, sizeof(poseInfo));
|
||||||
|
}
|
||||||
|
|
||||||
model.CloseNode();
|
model.CloseNode();
|
||||||
|
|
||||||
// item might be in invisible
|
// item might be in invisible
|
||||||
if (size == sizeof(poseInfo)
|
if (size == sizeof(poseInfo)
|
||||||
&& !BPoseView::PoseVisible(&model, &poseInfo))
|
&& !BPoseView::PoseVisible(&model, &poseInfo)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
AddOneItem(&model);
|
AddOneItem(&model);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +564,7 @@ BNavMenu::AddOneItem(Model* model)
|
|||||||
dynamic_cast<BContainerWindow*>(fParentWindow),
|
dynamic_cast<BContainerWindow*>(fParentWindow),
|
||||||
fTypesList, &fTrackingHook);
|
fTypesList, &fTrackingHook);
|
||||||
|
|
||||||
if (item)
|
if (item != NULL)
|
||||||
fItemList->AddItem(item);
|
fItemList->AddItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,14 +577,14 @@ BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage,
|
|||||||
{
|
{
|
||||||
if (model->InitCheck() != B_OK)
|
if (model->InitCheck() != B_OK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
bool container = false;
|
bool container = false;
|
||||||
if (model->IsSymLink()) {
|
if (model->IsSymLink()) {
|
||||||
|
|
||||||
Model* newResolvedModel = 0;
|
Model* newResolvedModel = 0;
|
||||||
Model* result = model->LinkTo();
|
Model* result = model->LinkTo();
|
||||||
|
|
||||||
if (!result) {
|
if (result != NULL) {
|
||||||
newResolvedModel = new Model(model->EntryRef(), true, true);
|
newResolvedModel = new Model(model->EntryRef(), true, true);
|
||||||
|
|
||||||
if (newResolvedModel->InitCheck() != B_OK) {
|
if (newResolvedModel->InitCheck() != B_OK) {
|
||||||
@@ -584,16 +595,17 @@ BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage,
|
|||||||
result = newResolvedModel;
|
result = newResolvedModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result != NULL) {
|
||||||
BModelOpener opener(result);
|
BModelOpener opener(result);
|
||||||
// open the model, if it ain't open already
|
// open the model, if it ain't open already
|
||||||
|
|
||||||
PoseInfo poseInfo;
|
PoseInfo poseInfo;
|
||||||
ssize_t size = -1;
|
ssize_t size = -1;
|
||||||
|
|
||||||
if (result->Node())
|
if (result->Node() != NULL) {
|
||||||
size = result->Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
|
size = result->Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
|
||||||
&poseInfo, sizeof(poseInfo));
|
&poseInfo, sizeof(poseInfo));
|
||||||
|
}
|
||||||
|
|
||||||
result->CloseNode();
|
result->CloseNode();
|
||||||
|
|
||||||
@@ -607,6 +619,7 @@ BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage,
|
|||||||
ref = *result->EntryRef();
|
ref = *result->EntryRef();
|
||||||
container = result->IsContainer();
|
container = result->IsContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
model->SetLinkTo(result);
|
model->SetLinkTo(result);
|
||||||
} else {
|
} else {
|
||||||
ref = *model->EntryRef();
|
ref = *model->EntryRef();
|
||||||
@@ -616,13 +629,13 @@ BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage,
|
|||||||
BMessage* message = new BMessage(*invokeMessage);
|
BMessage* message = new BMessage(*invokeMessage);
|
||||||
message->AddRef("refs", model->EntryRef());
|
message->AddRef("refs", model->EntryRef());
|
||||||
|
|
||||||
// Truncate the name if necessary
|
// truncate name if necessary
|
||||||
BString truncatedString(model->Name());
|
BString truncatedString(model->Name());
|
||||||
be_plain_font->TruncateString(&truncatedString, B_TRUNCATE_END,
|
be_plain_font->TruncateString(&truncatedString, B_TRUNCATE_END,
|
||||||
GetMaxMenuWidth());
|
GetMaxMenuWidth());
|
||||||
|
|
||||||
ModelMenuItem* item = NULL;
|
ModelMenuItem* item = NULL;
|
||||||
if (!container || suppressFolderHierarchy) {
|
if (container || suppressFolderHierarchy) {
|
||||||
item = new ModelMenuItem(model, truncatedString.String(), message);
|
item = new ModelMenuItem(model, truncatedString.String(), message);
|
||||||
if (invokeMessage->what != B_REFS_RECEIVED)
|
if (invokeMessage->what != B_REFS_RECEIVED)
|
||||||
item->SetEnabled(false);
|
item->SetEnabled(false);
|
||||||
@@ -633,9 +646,10 @@ BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage,
|
|||||||
invokeMessage->what, target, parentWindow, typeslist);
|
invokeMessage->what, target, parentWindow, typeslist);
|
||||||
|
|
||||||
menu->SetNavDir(&ref);
|
menu->SetNavDir(&ref);
|
||||||
if (hook)
|
if (hook != NULL) {
|
||||||
menu->InitTrackingHook(hook->fTrackingHook, &(hook->fTarget),
|
menu->InitTrackingHook(hook->fTrackingHook, &(hook->fTarget),
|
||||||
hook->fDragMessage);
|
hook->fDragMessage);
|
||||||
|
}
|
||||||
|
|
||||||
item = new ModelMenuItem(model, menu);
|
item = new ModelMenuItem(model, menu);
|
||||||
item->SetMessage(message);
|
item->SetMessage(message);
|
||||||
@@ -649,11 +663,10 @@ void
|
|||||||
BNavMenu::BuildVolumeMenu()
|
BNavMenu::BuildVolumeMenu()
|
||||||
{
|
{
|
||||||
BVolumeRoster roster;
|
BVolumeRoster roster;
|
||||||
BVolume volume;
|
BVolume volume;
|
||||||
|
|
||||||
roster.Rewind();
|
roster.Rewind();
|
||||||
while (roster.GetNextVolume(&volume) == B_OK) {
|
while (roster.GetNextVolume(&volume) == B_OK) {
|
||||||
|
|
||||||
if (!volume.IsPersistent())
|
if (!volume.IsPersistent())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -682,8 +695,7 @@ BNavMenu::BuildVolumeMenu()
|
|||||||
|
|
||||||
item->SetMessage(message);
|
item->SetMessage(message);
|
||||||
fItemList->AddItem(item);
|
fItemList->AddItem(item);
|
||||||
ASSERT(item->Label());
|
ASSERT(item->Label() != NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -695,8 +707,10 @@ BNavMenu::CompareFolderNamesFirstOne(const BMenuItem* i1, const BMenuItem* i2)
|
|||||||
const ModelMenuItem* item1 = dynamic_cast<const ModelMenuItem*>(i1);
|
const ModelMenuItem* item1 = dynamic_cast<const ModelMenuItem*>(i1);
|
||||||
const ModelMenuItem* item2 = dynamic_cast<const ModelMenuItem*>(i2);
|
const ModelMenuItem* item2 = dynamic_cast<const ModelMenuItem*>(i2);
|
||||||
|
|
||||||
if (item1 != NULL && item2 != NULL)
|
if (item1 != NULL && item2 != NULL) {
|
||||||
return item1->TargetModel()->CompareFolderNamesFirst(item2->TargetModel());
|
return item1->TargetModel()->CompareFolderNamesFirst(
|
||||||
|
item2->TargetModel());
|
||||||
|
}
|
||||||
|
|
||||||
return strcasecmp(i1->Label(), i2->Label());
|
return strcasecmp(i1->Label(), i2->Label());
|
||||||
}
|
}
|
||||||
@@ -721,7 +735,7 @@ BNavMenu::DoneBuildingItemList()
|
|||||||
// if the parent link should be shown, it will be the first
|
// if the parent link should be shown, it will be the first
|
||||||
// entry in the menu - but don't add the item if we're already
|
// entry in the menu - but don't add the item if we're already
|
||||||
// at the file system's root
|
// at the file system's root
|
||||||
if (fFlags & kShowParent) {
|
if ((fFlags & kShowParent) != 0) {
|
||||||
BDirectory directory(&fNavDir);
|
BDirectory directory(&fNavDir);
|
||||||
BEntry entry(&fNavDir);
|
BEntry entry(&fNavDir);
|
||||||
if (!directory.IsRootDirectory()
|
if (!directory.IsRootDirectory()
|
||||||
@@ -736,9 +750,10 @@ BNavMenu::DoneBuildingItemList()
|
|||||||
int32 count = fItemList->CountItems();
|
int32 count = fItemList->CountItems();
|
||||||
for (int32 index = 0; index < count; index++)
|
for (int32 index = 0; index < count; index++)
|
||||||
AddItem(fItemList->ItemAt(index));
|
AddItem(fItemList->ItemAt(index));
|
||||||
|
|
||||||
fItemList->MakeEmpty();
|
fItemList->MakeEmpty();
|
||||||
|
|
||||||
if (!count) {
|
if (count == 0) {
|
||||||
BMenuItem* item = new BMenuItem(B_TRANSLATE("Empty folder"), 0);
|
BMenuItem* item = new BMenuItem(B_TRANSLATE("Empty folder"), 0);
|
||||||
item->SetEnabled(false);
|
item->SetEnabled(false);
|
||||||
AddItem(item);
|
AddItem(item);
|
||||||
@@ -785,8 +800,8 @@ BNavMenu::AddNavParentDir(const char* name,const Model* model,
|
|||||||
BNavMenu* menu = new BNavMenu(name, what, target);
|
BNavMenu* menu = new BNavMenu(name, what, target);
|
||||||
menu->SetNavDir(model->EntryRef());
|
menu->SetNavDir(model->EntryRef());
|
||||||
menu->SetShowParent(true);
|
menu->SetShowParent(true);
|
||||||
menu->InitTrackingHook(fTrackingHook.fTrackingHook, &(fTrackingHook.fTarget),
|
menu->InitTrackingHook(fTrackingHook.fTrackingHook,
|
||||||
fTrackingHook.fDragMessage);
|
&fTrackingHook.fTarget, fTrackingHook.fDragMessage);
|
||||||
|
|
||||||
BMenuItem* item = new SpecialModelMenuItem(model, menu);
|
BMenuItem* item = new SpecialModelMenuItem(model, menu);
|
||||||
|
|
||||||
@@ -830,9 +845,9 @@ BNavMenu::TypesList() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BNavMenu::SetTarget(const BMessenger& msngr)
|
BNavMenu::SetTarget(const BMessenger& messenger)
|
||||||
{
|
{
|
||||||
fMessenger = msngr;
|
fMessenger = messenger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -848,10 +863,12 @@ BNavMenu::InitTrackingHook(bool (*hook)(BMenu*, void*),
|
|||||||
const BMessenger* target, const BMessage* dragMessage)
|
const BMessenger* target, const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
fTrackingHook.fTrackingHook = hook;
|
fTrackingHook.fTrackingHook = hook;
|
||||||
if (target)
|
if (target != NULL)
|
||||||
fTrackingHook.fTarget = *target;
|
fTrackingHook.fTarget = *target;
|
||||||
|
|
||||||
fTrackingHook.fDragMessage = dragMessage;
|
fTrackingHook.fDragMessage = dragMessage;
|
||||||
SetTrackingHookDeep(this, hook, &fTrackingHook);
|
SetTrackingHookDeep(this, hook, &fTrackingHook);
|
||||||
|
|
||||||
return &fTrackingHook;
|
return &fTrackingHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,11 +881,11 @@ BNavMenu::SetTrackingHookDeep(BMenu* menu, bool (*func)(BMenu*, void*),
|
|||||||
int32 count = menu->CountItems();
|
int32 count = menu->CountItems();
|
||||||
for (int32 index = 0 ; index < count; index++) {
|
for (int32 index = 0 ; index < count; index++) {
|
||||||
BMenuItem* item = menu->ItemAt(index);
|
BMenuItem* item = menu->ItemAt(index);
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BMenu* submenu = item->Submenu();
|
BMenu* submenu = item->Submenu();
|
||||||
if (submenu)
|
if (submenu != NULL)
|
||||||
SetTrackingHookDeep(submenu, func, state);
|
SetTrackingHookDeep(submenu, func, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user