Tracker: Style fixes to OpenWithWindow

This commit is contained in:
John Scipione 2014-06-20 18:50:14 -04:00
parent 01579713f8
commit c513839558
2 changed files with 316 additions and 283 deletions

View File

@ -73,13 +73,18 @@ const int32 kOpenAndMakeDefault = 'OpDf';
const rgb_color kOpenWithDefaultColor = { 0xFF, 0xFF, 0xCC, 255}; const rgb_color kOpenWithDefaultColor = { 0xFF, 0xFF, 0xCC, 255};
// #pragma mark - OpenWithContainerWindow
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "OpenWithWindow" #define B_TRANSLATION_CONTEXT "OpenWithWindow"
OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen, OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen,
LockingList<BWindow>* windowList, window_look look, window_feel feel, LockingList<BWindow>* windowList, window_look look, window_feel feel,
uint32 flags, uint32 workspace) uint32 flags, uint32 workspace)
: BContainerWindow(windowList, 0, look, feel, flags, workspace), :
BContainerWindow(windowList, 0, look, feel, flags, workspace),
fEntriesToOpen(entriesToOpen) fEntriesToOpen(entriesToOpen)
{ {
AutoLock<BWindow> lock(this); AutoLock<BWindow> lock(this);
@ -108,12 +113,12 @@ OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen,
BRect buttonRect = fLaunchButton->Frame(); BRect buttonRect = fLaunchButton->Frame();
fLaunchAndMakeDefaultButton = new BButton(buttonRect, "make default", fLaunchAndMakeDefaultButton = new BButton(buttonRect, "make default",
B_TRANSLATE("Open and make preferred"), new BMessage(kOpenAndMakeDefault), B_TRANSLATE("Open and make preferred"),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(kOpenAndMakeDefault), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
// wide button, have to resize to fit text // wide button, have to resize to fit text
fLaunchAndMakeDefaultButton->ResizeToPreferred(); fLaunchAndMakeDefaultButton->ResizeToPreferred();
fLaunchAndMakeDefaultButton->MoveBy( fLaunchAndMakeDefaultButton->MoveBy(-10
- 10 - fLaunchAndMakeDefaultButton->Bounds().Width(), 0); - fLaunchAndMakeDefaultButton->Bounds().Width(), 0);
backgroundView->AddChild(fLaunchAndMakeDefaultButton); backgroundView->AddChild(fLaunchAndMakeDefaultButton);
fLaunchAndMakeDefaultButton->SetEnabled(false); fLaunchAndMakeDefaultButton->SetEnabled(false);
@ -121,11 +126,12 @@ OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen,
BButton* button = new BButton(buttonRect, "cancel", B_TRANSLATE("Cancel"), BButton* button = new BButton(buttonRect, "cancel", B_TRANSLATE("Cancel"),
new BMessage(kCancelButton), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(kCancelButton), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred(); button->ResizeToPreferred();
button->MoveBy(- 10 - button->Bounds().Width(), 0); button->MoveBy(-10 - button->Bounds().Width(), 0);
backgroundView->AddChild(button); backgroundView->AddChild(button);
fMinimalWidth = button->Bounds().Width() + fLaunchButton->Bounds().Width() fMinimalWidth = button->Bounds().Width() + fLaunchButton->Bounds().Width()
+ fLaunchAndMakeDefaultButton->Bounds().Width() + kDocumentKnobWidth + 40; + fLaunchAndMakeDefaultButton->Bounds().Width() + kDocumentKnobWidth
+ 40;
fLaunchButton->MakeDefault(true); fLaunchButton->MakeDefault(true);
@ -152,11 +158,13 @@ OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen,
buffer.ReplaceFirst("%name", ref.name); buffer.ReplaceFirst("%name", ref.name);
SetTitle(buffer.String()); SetTitle(buffer.String());
} else } else {
// use generic title // use generic title
SetTitle(B_TRANSLATE("Open selection with:")); SetTitle(B_TRANSLATE("Open selection with:"));
}
AddCommonFilter(new BMessageFilter(B_KEY_DOWN, &OpenWithContainerWindow::KeyDownFilter)); AddCommonFilter(new BMessageFilter(B_KEY_DOWN,
&OpenWithContainerWindow::KeyDownFilter));
} }
@ -177,6 +185,7 @@ OpenWithPoseView*
OpenWithContainerWindow::PoseView() const OpenWithContainerWindow::PoseView() const
{ {
ASSERT(dynamic_cast<OpenWithPoseView*>(fPoseView)); ASSERT(dynamic_cast<OpenWithPoseView*>(fPoseView));
return static_cast<OpenWithPoseView*>(fPoseView); return static_cast<OpenWithPoseView*>(fPoseView);
} }
@ -193,7 +202,7 @@ OpenWithContainerWindow::OpenWithSelection()
{ {
int32 count = PoseView()->SelectionList()->CountItems(); int32 count = PoseView()->SelectionList()->CountItems();
ASSERT(count == 1); ASSERT(count == 1);
if (!count) if (count == 0)
return; return;
PoseView()->OpenSelection(PoseView()->SelectionList()->FirstItem(), 0); PoseView()->OpenSelection(PoseView()->SelectionList()->FirstItem(), 0);
@ -234,6 +243,7 @@ AddOneUniqueDocumentType(const entry_ref* ref, void* castToList)
// add type to list // add type to list
list->AddItem(new BString(type)); list->AddItem(new BString(type));
return 0; return 0;
} }
@ -285,12 +295,12 @@ OpenWithContainerWindow::MakeDefaultAndOpen()
{ {
int32 count = PoseView()->SelectionList()->CountItems(); int32 count = PoseView()->SelectionList()->CountItems();
ASSERT(count == 1); ASSERT(count == 1);
if (!count) if (count == 0)
return; return;
BPose* selectedAppPose = PoseView()->SelectionList()->FirstItem(); BPose* selectedAppPose = PoseView()->SelectionList()->FirstItem();
ASSERT(selectedAppPose); ASSERT(selectedAppPose != NULL);
if (!selectedAppPose) if (selectedAppPose == NULL)
return; return;
// collect all the types of all the opened documents into a list // collect all the types of all the opened documents into a list
@ -333,6 +343,7 @@ OpenWithContainerWindow::MessageReceived(BMessage* message)
ResizeToFit(); ResizeToFit();
break; break;
} }
_inherited::MessageReceived(message); _inherited::MessageReceived(message);
} }
@ -345,9 +356,9 @@ OpenWithContainerWindow::KeyDownFilter(BMessage* message, BHandler**,
if (message->FindInt8("byte", (int8*)&key) != B_OK) if (message->FindInt8("byte", (int8*)&key) != B_OK)
return B_DISPATCH_MESSAGE; return B_DISPATCH_MESSAGE;
int32 modifier=0; int32 modifiers = 0;
message->FindInt32("modifiers", &modifier); message->FindInt32("modifiers", &modifiers);
if (!modifier && key == B_ESCAPE) { if (modifiers == 0 && key == B_ESCAPE) {
filter->Looper()->PostMessage(kCancelButton); filter->Looper()->PostMessage(kCancelButton);
return B_SKIP_MESSAGE; return B_SKIP_MESSAGE;
} }
@ -381,24 +392,29 @@ void
OpenWithContainerWindow::NewAttributeMenu(BMenu* menu) OpenWithContainerWindow::NewAttributeMenu(BMenu* menu)
{ {
_inherited::NewAttributeMenu(menu); _inherited::NewAttributeMenu(menu);
BMessage* message = new BMessage(kAttributeItem); BMessage* message = new BMessage(kAttributeItem);
message->AddString("attr_name", kAttrOpenWithRelation); message->AddString("attr_name", kAttrOpenWithRelation);
message->AddInt32("attr_type", B_STRING_TYPE); message->AddInt32("attr_type", B_STRING_TYPE);
message->AddInt32("attr_hash", (int32)AttrHashString(kAttrOpenWithRelation, B_STRING_TYPE)); message->AddInt32("attr_hash",
(int32)AttrHashString(kAttrOpenWithRelation, B_STRING_TYPE));
message->AddFloat("attr_width", 180); message->AddFloat("attr_width", 180);
message->AddInt32("attr_align", B_ALIGN_LEFT); message->AddInt32("attr_align", B_ALIGN_LEFT);
message->AddBool("attr_editable", false); message->AddBool("attr_editable", false);
message->AddBool("attr_statfield", false); message->AddBool("attr_statfield", false);
BMenuItem* item = new BMenuItem(B_TRANSLATE("Relation"), message); BMenuItem* item = new BMenuItem(B_TRANSLATE("Relation"), message);
menu->AddItem(item); menu->AddItem(item);
message = new BMessage(kAttributeItem); message = new BMessage(kAttributeItem);
message->AddString("attr_name", kAttrAppVersion); message->AddString("attr_name", kAttrAppVersion);
message->AddInt32("attr_type", B_STRING_TYPE); message->AddInt32("attr_type", B_STRING_TYPE);
message->AddInt32("attr_hash", (int32)AttrHashString(kAttrAppVersion, B_STRING_TYPE)); message->AddInt32("attr_hash",
(int32)AttrHashString(kAttrAppVersion, B_STRING_TYPE));
message->AddFloat("attr_width", 70); message->AddFloat("attr_width", 70);
message->AddInt32("attr_align", B_ALIGN_LEFT); message->AddInt32("attr_align", B_ALIGN_LEFT);
message->AddBool("attr_editable", false); message->AddBool("attr_editable", false);
message->AddBool("attr_statfield", false); message->AddBool("attr_statfield", false);
item = new BMenuItem(B_TRANSLATE("Version"), message); item = new BMenuItem(B_TRANSLATE("Version"), message);
menu->AddItem(item); menu->AddItem(item);
} }
@ -435,7 +451,8 @@ void
OpenWithContainerWindow::RestoreState() OpenWithContainerWindow::RestoreState()
{ {
BNode defaultingNode; BNode defaultingNode;
if (DefaultStateSourceNode(kDefaultOpenWithTemplate, &defaultingNode, false)) { if (DefaultStateSourceNode(kDefaultOpenWithTemplate, &defaultingNode,
false)) {
AttributeStreamFileNode streamNodeSource(&defaultingNode); AttributeStreamFileNode streamNodeSource(&defaultingNode);
RestoreWindowState(&streamNodeSource); RestoreWindowState(&streamNodeSource);
fPoseView->Init(&streamNodeSource); fPoseView->Init(&streamNodeSource);
@ -457,7 +474,7 @@ void
OpenWithContainerWindow::RestoreWindowState(AttributeStreamNode* node) OpenWithContainerWindow::RestoreWindowState(AttributeStreamNode* node)
{ {
SetSizeLimits(fMinimalWidth, 10000, 160, 10000); SetSizeLimits(fMinimalWidth, 10000, 160, 10000);
if (!node) if (node == NULL)
return; return;
const char* rectAttributeName = kAttrWindowFrame; const char* rectAttributeName = kAttrWindowFrame;
@ -518,11 +535,12 @@ OpenWithContainerWindow::SetCanOpen(bool on)
} }
// #pragma mark - // #pragma mark - OpenWithPoseView
OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask) OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask)
: BPoseView(0, frame, kListMode, resizeMask), :
BPoseView(0, frame, kListMode, resizeMask),
fHaveCommonPreferredApp(false), fHaveCommonPreferredApp(false),
fIterator(NULL) fIterator(NULL)
{ {
@ -602,7 +620,8 @@ AddOneRefSignatures(const entry_ref* ref, void* castToIterator)
// add preferred app for file, if any // add preferred app for file, if any
if (model.PreferredAppSignature()[0]) { if (model.PreferredAppSignature()[0]) {
// got one, mark it as preferred for this node // got one, mark it as preferred for this node
if (be_roster->FindApp(model.PreferredAppSignature(), &preferredRef) == B_OK) { if (be_roster->FindApp(model.PreferredAppSignature(), &preferredRef)
== B_OK) {
queryIterator->PushUniqueSignature(model.PreferredAppSignature()); queryIterator->PushUniqueSignature(model.PreferredAppSignature());
queryIterator->TrySettingPreferredAppForFile(&preferredRef); queryIterator->TrySettingPreferredAppForFile(&preferredRef);
} }
@ -649,7 +668,8 @@ OpenWithPoseView::InitDirentIterator(const entry_ref*)
return NULL; return NULL;
} }
SetRefFilter(new OpenWithRefFilter(fIterator, entryList, SetRefFilter(new OpenWithRefFilter(fIterator, entryList,
(fHaveCommonPreferredApp ? &fPreferredRef : 0))); fHaveCommonPreferredApp ? &fPreferredRef : 0));
return fIterator; return fIterator;
} }
@ -660,10 +680,10 @@ OpenWithPoseView::OpenSelection(BPose* pose, int32*)
OpenWithContainerWindow* window = ContainerWindow(); OpenWithContainerWindow* window = ContainerWindow();
int32 count = fSelectionList->CountItems(); int32 count = fSelectionList->CountItems();
if (!count) if (count == 0)
return; return;
if (!pose) if (pose == NULL)
pose = fSelectionList->FirstItem(); pose = fSelectionList->FirstItem();
ASSERT(pose); ASSERT(pose);
@ -710,9 +730,8 @@ OpenWithPoseView::OpenSelection(BPose* pose, int32*)
message.AddRef("handler", pose->TargetModel()->EntryRef()); message.AddRef("handler", pose->TargetModel()->EntryRef());
// add ref of the selected handler // add ref of the selected handler
ASSERT(fSelectionHandler); ASSERT(fSelectionHandler != NULL);
if (fSelectionHandler != NULL)
if (fSelectionHandler)
fSelectionHandler->PostMessage(&message); fSelectionHandler->PostMessage(&message);
window->PostMessage(B_QUIT_REQUESTED); window->PostMessage(B_QUIT_REQUESTED);
@ -797,20 +816,21 @@ OpenWithPoseView::AddPosesThreadValid(const entry_ref*) const
void void
OpenWithPoseView::CreatePoses(Model** models, PoseInfo* poseInfoArray, int32 count, OpenWithPoseView::CreatePoses(Model** models, PoseInfo* poseInfoArray,
BPose** resultingPoses, bool insertionSort, int32* lastPoseIndexPtr, int32 count, BPose** resultingPoses, bool insertionSort,
BRect* boundsPtr, bool forceDraw) int32* lastPoseIndexPtr, BRect* boundsPtr, bool forceDraw)
{ {
// overridden to try to select the preferred handling app // overridden to try to select the preferred handling app
_inherited::CreatePoses(models, poseInfoArray, count, resultingPoses, insertionSort, _inherited::CreatePoses(models, poseInfoArray, count, resultingPoses,
lastPoseIndexPtr, boundsPtr, forceDraw); insertionSort, lastPoseIndexPtr, boundsPtr, forceDraw);
if (resultingPoses) { if (resultingPoses != NULL) {
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
if (resultingPoses[index] && fHaveCommonPreferredApp if (resultingPoses[index] && fHaveCommonPreferredApp
&& *(models[index]->EntryRef()) == fPreferredRef) { && *(models[index]->EntryRef()) == fPreferredRef) {
// this is our preferred app, select it's pose // this is our preferred app, select it's pose
SelectPose(resultingPoses[index], IndexOfPose(resultingPoses[index])); SelectPose(resultingPoses[index],
IndexOfPose(resultingPoses[index]));
} }
} }
} }
@ -861,7 +881,6 @@ OpenWithPoseView::RestoreState(const BMessage &message)
void void
OpenWithPoseView::SavePoseLocations(BRect*) OpenWithPoseView::SavePoseLocations(BRect*)
{ {
// do nothing
} }
@ -905,7 +924,8 @@ OpenWithPoseView::HandleMessageDropped(BMessage* DEBUG_ONLY(message))
const rgb_color* color; const rgb_color* color;
ssize_t size; ssize_t size;
// handle roColour-style color drops // handle roColour-style color drops
if (message->FindData("RGBColor", 'RGBC', (const void**)&color, &size) == B_OK) { if (message->FindData("RGBColor", 'RGBC', (const void**)&color, &size)
== B_OK) {
SetViewColor(*color); SetViewColor(*color);
SetLowColor(*color); SetLowColor(*color);
Invalidate(); Invalidate();
@ -937,7 +957,7 @@ OpenWithPoseView::OpenWithRelationDescription(const Model* model,
} }
// #pragma mark - // #pragma mark - OpenWithRefFilter
OpenWithRefFilter::OpenWithRefFilter(SearchForSignatureEntryList* iterator, OpenWithRefFilter::OpenWithRefFilter(SearchForSignatureEntryList* iterator,
@ -958,6 +978,7 @@ OpenWithRefFilter::Filter(const entry_ref* ref, BNode* node, stat_beos* st,
bool canOpen = fIterator->CanOpenWithFilter(model, fEntryList, bool canOpen = fIterator->CanOpenWithFilter(model, fEntryList,
fPreferredRef); fPreferredRef);
delete model; delete model;
return canOpen; return canOpen;
} }
@ -990,12 +1011,13 @@ RelationCachingModelProxy::Relation(SearchForSignatureEntryList* iterator,
} }
// #pragma mark - // #pragma mark - OpenWithMenu
OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen, OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen,
BWindow* parentWindow, BHandler* target) BWindow* parentWindow, BHandler* target)
: BSlowMenu(label), :
BSlowMenu(label),
fEntriesToOpen(*entriesToOpen), fEntriesToOpen(*entriesToOpen),
target(target), target(target),
fIterator(NULL), fIterator(NULL),
@ -1013,7 +1035,8 @@ OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen,
OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen, OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen,
BWindow* parentWindow, const BMessenger &messenger) BWindow* parentWindow, const BMessenger &messenger)
: BSlowMenu(label), :
BSlowMenu(label),
fEntriesToOpen(*entriesToOpen), fEntriesToOpen(*entriesToOpen),
target(NULL), target(NULL),
fMessenger(messenger), fMessenger(messenger),
@ -1090,9 +1113,8 @@ OpenWithMenu::AddNextItem()
if (model->InitCheck() != B_OK if (model->InitCheck() != B_OK
|| !fIterator->CanOpenWithFilter(model, &fEntriesToOpen, || !fIterator->CanOpenWithFilter(model, &fEntriesToOpen,
fHaveCommonPreferredApp ? &fPreferredRef : 0)) { fHaveCommonPreferredApp ? &fPreferredRef : 0)) {
// only allow executables, filter out multiple copies of the // only allow executables, filter out multiple copies of the Tracker,
// Tracker, filter out version that don't list the correct types, // filter out version that don't list the correct types, etc.
// etc.
delete model; delete model;
} else } else
fSupportingAppList->AddItem(new RelationCachingModelProxy(model)); fSupportingAppList->AddItem(new RelationCachingModelProxy(model));
@ -1108,13 +1130,13 @@ OpenWithMenu::DoneBuildingItemList()
fSupportingAppList->SortItems(SortByRelationAndName, this); fSupportingAppList->SortItems(SortByRelationAndName, this);
// check if each app is unique // check if each app is unique
bool unique = true; bool isUnique = true;
int32 count = fSupportingAppList->CountItems(); int32 count = fSupportingAppList->CountItems();
for (int32 index = 0; index < count - 1; index++) { for (int32 index = 0; index < count - 1; index++) {
// the list is sorted, just compare two adjacent models // the list is sorted, just compare two adjacent models
if (strcmp(fSupportingAppList->ItemAt(index)->fModel->Name(), if (strcmp(fSupportingAppList->ItemAt(index)->fModel->Name(),
fSupportingAppList->ItemAt(index + 1)->fModel->Name()) == 0) { fSupportingAppList->ItemAt(index + 1)->fModel->Name()) == 0) {
unique = false; isUnique = false;
break; break;
} }
} }
@ -1125,17 +1147,20 @@ OpenWithMenu::DoneBuildingItemList()
int32 lastRelation = -1; int32 lastRelation = -1;
for (int32 index = 0; index < count ; index++) { for (int32 index = 0; index < count ; index++) {
RelationCachingModelProxy* modelProxy = fSupportingAppList->ItemAt(index); RelationCachingModelProxy* modelProxy
= fSupportingAppList->ItemAt(index);
Model* model = modelProxy->fModel; Model* model = modelProxy->fModel;
BMessage* message = new BMessage(fEntriesToOpen); BMessage* message = new BMessage(fEntriesToOpen);
message->AddRef("handler", model->EntryRef()); message->AddRef("handler", model->EntryRef());
BContainerWindow* window = dynamic_cast<BContainerWindow*>(fParentWindow); BContainerWindow* window
if (window) = dynamic_cast<BContainerWindow*>(fParentWindow);
message->AddData("nodeRefsToClose", B_RAW_TYPE, window->TargetModel()->NodeRef(), if (window != NULL) {
sizeof (node_ref)); message->AddData("nodeRefsToClose", B_RAW_TYPE,
window->TargetModel()->NodeRef(), sizeof(node_ref));
}
BString result; BString result;
if (unique) { if (isUnique) {
// just use the app name // just use the app name
result = model->Name(); result = model->Name();
} else { } else {
@ -1164,7 +1189,8 @@ OpenWithMenu::DoneBuildingItemList()
AddSeparatorItem(); AddSeparatorItem();
lastRelation = relation; lastRelation = relation;
ModelMenuItem* item = new ModelMenuItem(model, result.String(), message); ModelMenuItem* item = new ModelMenuItem(model, result.String(),
message);
AddItem(item); AddItem(item);
// mark item if it represents the preferred app // mark item if it represents the preferred app
if (fHaveCommonPreferredApp && *(model->EntryRef()) == fPreferredRef) { if (fHaveCommonPreferredApp && *(model->EntryRef()) == fPreferredRef) {
@ -1174,12 +1200,12 @@ OpenWithMenu::DoneBuildingItemList()
} }
// target the menu // target the menu
if (target) if (target != NULL)
SetTargetForItems(target); SetTargetForItems(target);
else else
SetTargetForItems(fMessenger); SetTargetForItems(fMessenger);
if (!CountItems()) { if (CountItems() == 0) {
BMenuItem* item = new BMenuItem(B_TRANSLATE("no supporting apps"), 0); BMenuItem* item = new BMenuItem(B_TRANSLATE("no supporting apps"), 0);
item->SetEnabled(false); item->SetEnabled(false);
AddItem(item); AddItem(item);
@ -1197,7 +1223,7 @@ OpenWithMenu::ClearMenuBuildingState()
} }
// #pragma mark - // #pragma mark - SearchForSignatureEntryList
SearchForSignatureEntryList::SearchForSignatureEntryList(bool canAddAllApps) SearchForSignatureEntryList::SearchForSignatureEntryList(bool canAddAllApps)
@ -1257,6 +1283,7 @@ struct AddOneTermParams {
bool first; bool first;
}; };
static const BString* static const BString*
AddOnePredicateTerm(const BString* item, void* castToParams) AddOnePredicateTerm(const BString* item, void* castToParams)
{ {
@ -1328,9 +1355,10 @@ SearchForSignatureEntryList::TrySettingPreferredApp(const entry_ref* ref)
if (!fPreferredAppCount) { if (!fPreferredAppCount) {
fPreferredRef = *ref; fPreferredRef = *ref;
fPreferredAppCount++; fPreferredAppCount++;
} else if (fPreferredRef != *ref) } else if (fPreferredRef != *ref) {
// if more than one, will not return any // if more than one, will not return any
fPreferredAppCount++; fPreferredAppCount++;
}
} }
@ -1372,7 +1400,9 @@ int32
SearchForSignatureEntryList::Relation(const Model* nodeModel, SearchForSignatureEntryList::Relation(const Model* nodeModel,
const Model* applicationModel) const Model* applicationModel)
{ {
switch (applicationModel->SupportsMimeType(nodeModel->MimeType(), 0, true)) { int32 supportsMimeType = applicationModel->SupportsMimeType(
nodeModel->MimeType(), 0, true);
switch (supportsMimeType) {
case kDoesNotSupportType: case kDoesNotSupportType:
return kNoRelation; return kNoRelation;
@ -1421,8 +1451,8 @@ SearchForSignatureEntryList::Relation(const BMessage* entriesToOpen,
if (entriesToOpen->FindRef("refs", index, &ref) != B_OK) if (entriesToOpen->FindRef("refs", index, &ref) != B_OK)
break; break;
// need to init a model so that typeless folders etc. will still appear to // need to init a model so that typeless folders etc. will still
// have a mime type // appear to have a mime type
Model model(&ref, true, true); Model model(&ref, true, true);
if (model.InitCheck()) if (model.InitCheck())
@ -1431,13 +1461,15 @@ SearchForSignatureEntryList::Relation(const BMessage* entriesToOpen,
int32 result = Relation(&model, applicationModel); int32 result = Relation(&model, applicationModel);
if (result != kNoRelation) { if (result != kNoRelation) {
if (preferredAppForFile if (preferredAppForFile
&& *applicationModel->EntryRef() == *preferredAppForFile) && *applicationModel->EntryRef() == *preferredAppForFile) {
return kPreferredForFile; return kPreferredForFile;
}
if (result == kSupportsType && preferredApp if (result == kSupportsType && preferredApp
&& *applicationModel->EntryRef() == *preferredApp) && *applicationModel->EntryRef() == *preferredApp) {
// application matches cached preferred app, we are done // application matches cached preferred app, we are done
return kPreferredForType; return kPreferredForType;
}
return result; return result;
} }
@ -1483,13 +1515,13 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen,
char* type = (char*)mimeType.Type(); char* type = (char*)mimeType.Type();
char* tmp = strchr(type, '/'); char* tmp = strchr(type, '/');
if (tmp) if (tmp != NULL)
*tmp = '\0'; *tmp = '\0';
//PRINT(("getting supertype for %s, result %s, got %s\n", //PRINT(("getting supertype for %s, result %s, got %s\n",
// model.MimeType(), strerror(result), mimeType.Type())); // model.MimeType(), strerror(result), mimeType.Type()));
description->SetTo(B_TRANSLATE("Handles any %type")); description->SetTo(B_TRANSLATE("Handles any %type"));
// *description += mimeType.Type(); //*description += mimeType.Type();
description->ReplaceFirst("%type", type); description->ReplaceFirst("%type", type);
return; return;
} }
@ -1498,7 +1530,7 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen,
{ {
mimeType.SetTo(model.MimeType()); mimeType.SetTo(model.MimeType());
if (preferredApp if (preferredApp != NULL
&& *applicationModel->EntryRef() == *preferredApp) { && *applicationModel->EntryRef() == *preferredApp) {
// application matches cached preferred app, we are done // application matches cached preferred app, we are done
description->SetTo(B_TRANSLATE("Preferred for %type")); description->SetTo(B_TRANSLATE("Preferred for %type"));
@ -1510,6 +1542,7 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen,
description->ReplaceFirst("%type", shortDescription); description->ReplaceFirst("%type", shortDescription);
else else
description->ReplaceFirst("%type", mimeType.Type()); description->ReplaceFirst("%type", mimeType.Type());
return; return;
} }
} }
@ -1613,7 +1646,7 @@ SearchForSignatureEntryList::CanOpenWithFilter(const Model* appModel,
} }
// #pragma mark - // #pragma mark - ConditionalAllAppsIterator
ConditionalAllAppsIterator::ConditionalAllAppsIterator( ConditionalAllAppsIterator::ConditionalAllAppsIterator(
@ -1628,7 +1661,7 @@ ConditionalAllAppsIterator::ConditionalAllAppsIterator(
void void
ConditionalAllAppsIterator::Instantiate() ConditionalAllAppsIterator::Instantiate()
{ {
if (fWalker) if (fWalker == NULL)
return; return;
BString lookForAppsPredicate; BString lookForAppsPredicate;

View File

@ -51,8 +51,6 @@ All rights reserved.
namespace BPrivate { namespace BPrivate {
class OpenWithPoseView;
enum { enum {
kUnknownRelation = -1, kUnknownRelation = -1,
kNoRelation = 0, kNoRelation = 0,
@ -64,10 +62,12 @@ enum {
}; };
class OpenWithPoseView;
// pass in a predicate; a query will search for matches // pass in a predicate; a query will search for matches
// matches will be returned in iteration // matches will be returned in iteration
class SearchForSignatureEntryList : public EntryListBase { class SearchForSignatureEntryList : public EntryListBase {
public: public:
SearchForSignatureEntryList(bool canAddAllApps); SearchForSignatureEntryList(bool canAddAllApps);
virtual ~SearchForSignatureEntryList(); virtual ~SearchForSignatureEntryList();
@ -117,7 +117,7 @@ class SearchForSignatureEntryList : public EntryListBase {
bool ShowAllApplications() const; bool ShowAllApplications() const;
private: private:
static int32 Relation(const Model* node, const Model* app); static int32 Relation(const Model* node, const Model* app);
// returns the reason why an application is shown in // returns the reason why an application is shown in
// Open With window // Open With window
@ -136,7 +136,7 @@ class SearchForSignatureEntryList : public EntryListBase {
class OpenWithContainerWindow : public BContainerWindow { class OpenWithContainerWindow : public BContainerWindow {
public: public:
OpenWithContainerWindow(BMessage* entriesToOpen, OpenWithContainerWindow(BMessage* entriesToOpen,
LockingList<BWindow>* windowList, LockingList<BWindow>* windowList,
window_look look = B_DOCUMENT_WINDOW_LOOK, window_look look = B_DOCUMENT_WINDOW_LOOK,
@ -155,7 +155,7 @@ class OpenWithContainerWindow : public BContainerWindow {
OpenWithPoseView* PoseView() const; OpenWithPoseView* PoseView() const;
protected: protected:
virtual BPoseView* NewPoseView(Model* model, BRect rect, virtual BPoseView* NewPoseView(Model* model, BRect rect,
uint32 viewMode); uint32 viewMode);
@ -184,7 +184,7 @@ class OpenWithContainerWindow : public BContainerWindow {
// open entries with the selected app and make it // open entries with the selected app and make it
// the default handler // the default handler
private: private:
static filter_result KeyDownFilter(BMessage*, BHandler**, static filter_result KeyDownFilter(BMessage*, BHandler**,
BMessageFilter*); BMessageFilter*);
@ -198,7 +198,7 @@ class OpenWithContainerWindow : public BContainerWindow {
class OpenWithPoseView : public BPoseView { class OpenWithPoseView : public BPoseView {
public: public:
OpenWithPoseView(BRect, uint32 resizeMask = B_FOLLOW_ALL); OpenWithPoseView(BRect, uint32 resizeMask = B_FOLLOW_ALL);
virtual void OpenSelection(BPose*, int32*); virtual void OpenSelection(BPose*, int32*);
@ -215,7 +215,7 @@ class OpenWithPoseView : public BPoseView {
virtual bool AddPosesThreadValid(const entry_ref*) const; virtual bool AddPosesThreadValid(const entry_ref*) const;
protected: protected:
// don't do any volume watching and memtamime watching in open with // don't do any volume watching and memtamime watching in open with
// panels for now // panels for now
virtual void InitialStartWatching() {} virtual void InitialStartWatching() {}
@ -256,7 +256,7 @@ class OpenWithPoseView : public BPoseView {
virtual void KeyDown(const char* bytes, int32 count); virtual void KeyDown(const char* bytes, int32 count);
private: private:
entry_ref fPreferredRef; entry_ref fPreferredRef;
bool fHaveCommonPreferredApp; bool fHaveCommonPreferredApp;
@ -267,15 +267,14 @@ class OpenWithPoseView : public BPoseView {
}; };
class OpenWithRefFilter: public BRefFilter class OpenWithRefFilter: public BRefFilter {
{ public:
public:
OpenWithRefFilter(SearchForSignatureEntryList*, const BMessage*, OpenWithRefFilter(SearchForSignatureEntryList*, const BMessage*,
entry_ref*); entry_ref*);
bool Filter(const entry_ref* ref, BNode* node, stat_beos* st, bool Filter(const entry_ref* ref, BNode* node, stat_beos* st,
const char* filetype); const char* filetype);
private: private:
SearchForSignatureEntryList* fIterator; SearchForSignatureEntryList* fIterator;
const BMessage *fEntryList; const BMessage *fEntryList;
entry_ref* fPreferredRef; entry_ref* fPreferredRef;
@ -283,7 +282,7 @@ class OpenWithRefFilter: public BRefFilter
class RelationCachingModelProxy { class RelationCachingModelProxy {
public: public:
RelationCachingModelProxy(Model* model); RelationCachingModelProxy(Model* model);
~RelationCachingModelProxy(); ~RelationCachingModelProxy();
@ -296,13 +295,13 @@ class RelationCachingModelProxy {
class OpenWithMenu : public BSlowMenu { class OpenWithMenu : public BSlowMenu {
public: public:
OpenWithMenu(const char* label, const BMessage* entriesToOpen, OpenWithMenu(const char* label, const BMessage* entriesToOpen,
BWindow* parentWindow, BHandler* target); BWindow* parentWindow, BHandler* target);
OpenWithMenu(const char* label, const BMessage* entriesToOpen, OpenWithMenu(const char* label, const BMessage* entriesToOpen,
BWindow* parentWindow, const BMessenger &target); BWindow* parentWindow, const BMessenger &target);
private: private:
friend int SortByRelationAndName(const RelationCachingModelProxy*, friend int SortByRelationAndName(const RelationCachingModelProxy*,
const RelationCachingModelProxy*, void*); const RelationCachingModelProxy*, void*);
@ -329,7 +328,7 @@ class OpenWithMenu : public BSlowMenu {
// used for optionally showing the list of all apps. Do nothing // used for optionally showing the list of all apps. Do nothing
// until asked to iterate and only if supposed to do so // until asked to iterate and only if supposed to do so
class ConditionalAllAppsIterator : public EntryListBase { class ConditionalAllAppsIterator : public EntryListBase {
public: public:
ConditionalAllAppsIterator(SearchForSignatureEntryList* parent); ConditionalAllAppsIterator(SearchForSignatureEntryList* parent);
~ConditionalAllAppsIterator(); ~ConditionalAllAppsIterator();
@ -341,11 +340,11 @@ class ConditionalAllAppsIterator : public EntryListBase {
virtual status_t Rewind(); virtual status_t Rewind();
virtual int32 CountEntries(); virtual int32 CountEntries();
protected: protected:
bool Iterate() const; bool Iterate() const;
void Instantiate(); void Instantiate();
private: private:
SearchForSignatureEntryList* fParent; SearchForSignatureEntryList* fParent;
BTrackerPrivate::TWalker* fWalker; BTrackerPrivate::TWalker* fWalker;
}; };
@ -354,4 +353,5 @@ class ConditionalAllAppsIterator : public EntryListBase {
using namespace BPrivate; using namespace BPrivate;
#endif // _OPEN_WITH_WINDOW_H #endif // _OPEN_WITH_WINDOW_H