Tracker: Style fixes to OpenWithWindow

This commit is contained in:
John Scipione
2014-06-20 21:02:10 -04:00
parent 01579713f8
commit c513839558
2 changed files with 316 additions and 283 deletions
+110 -77
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,24 +113,25 @@ 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);
buttonRect = fLaunchAndMakeDefaultButton->Frame(); buttonRect = fLaunchAndMakeDefaultButton->Frame();
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,13 +474,13 @@ 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;
BRect frame(Frame()); BRect frame(Frame());
if (node->Read(rectAttributeName, 0, B_RECT_TYPE, sizeof(BRect), &frame) if (node->Read(rectAttributeName, 0, B_RECT_TYPE, sizeof(BRect), &frame)
== sizeof(BRect)) { == sizeof(BRect)) {
MoveTo(frame.LeftTop()); MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height()); ResizeTo(frame.Width(), frame.Height());
} }
@@ -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),
@@ -1012,8 +1034,9 @@ 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),
@@ -1089,10 +1112,9 @@ OpenWithMenu::AddNextItem()
Model* model = new Model(&entry, true); Model* model = new Model(&entry, true);
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)
{ {
@@ -1296,7 +1323,7 @@ SearchForSignatureEntryList::Rewind()
fSignatures.EachElement(AddOnePredicateTerm, &params); fSignatures.EachElement(AddOnePredicateTerm, &params);
ASSERT(predicateString.Length()); ASSERT(predicateString.Length());
// PRINT(("query predicate %s\n", predicateString.String())); // PRINT(("query predicate %s\n", predicateString.String()));
fIteratorList->AddItem(new TWalkerWrapper( fIteratorList->AddItem(new TWalkerWrapper(
new BTrackerPrivate::TQueryWalker(predicateString.String()))); new BTrackerPrivate::TQueryWalker(predicateString.String())));
fIteratorList->AddItem(new ConditionalAllAppsIterator(this)); fIteratorList->AddItem(new ConditionalAllAppsIterator(this));
@@ -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,11 +1646,11 @@ SearchForSignatureEntryList::CanOpenWithFilter(const Model* appModel,
} }
// #pragma mark - // #pragma mark - ConditionalAllAppsIterator
ConditionalAllAppsIterator::ConditionalAllAppsIterator( ConditionalAllAppsIterator::ConditionalAllAppsIterator(
SearchForSignatureEntryList* parent) SearchForSignatureEntryList* parent)
: :
fParent(parent), fParent(parent),
fWalker(NULL) fWalker(NULL)
@@ -1628,7 +1661,7 @@ ConditionalAllAppsIterator::ConditionalAllAppsIterator(
void void
ConditionalAllAppsIterator::Instantiate() ConditionalAllAppsIterator::Instantiate()
{ {
if (fWalker) if (fWalker == NULL)
return; return;
BString lookForAppsPredicate; BString lookForAppsPredicate;
+206 -206
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,294 +62,296 @@ 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();
void PushUniqueSignature(const char*); void PushUniqueSignature(const char*);
// add one signature to search for // add one signature to search for
// entry list iterators // entry list iterators
virtual status_t GetNextEntry(BEntry* entry, bool traverse = false); virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
virtual status_t GetNextRef(entry_ref* ref); virtual status_t GetNextRef(entry_ref* ref);
virtual int32 GetNextDirents(struct dirent* buffer, size_t length, virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
int32 count = INT_MAX); int32 count = INT_MAX);
virtual status_t Rewind(); virtual status_t Rewind();
virtual int32 CountEntries(); virtual int32 CountEntries();
bool GetPreferredApp(entry_ref* ref) const; bool GetPreferredApp(entry_ref* ref) const;
// gets the preferred app for all the files it was asked to // gets the preferred app for all the files it was asked to
// find supporting apps for, returns false if no preferred app // find supporting apps for, returns false if no preferred app
// found or if more than one found // found or if more than one found
void TrySettingPreferredApp(const entry_ref*); void TrySettingPreferredApp(const entry_ref*);
void TrySettingPreferredAppForFile(const entry_ref*); void TrySettingPreferredAppForFile(const entry_ref*);
int32 Relation(const BMessage* entriesToOpen, const Model*) const; int32 Relation(const BMessage* entriesToOpen, const Model*) const;
// returns the reason why an application is shown in // returns the reason why an application is shown in
// Open With window // Open With window
void RelationDescription(const BMessage* entriesToOpen, const Model*, void RelationDescription(const BMessage* entriesToOpen, const Model*,
BString*) const; BString*) const;
// returns a string describing why application handles files // returns a string describing why application handles files
// to open // to open
static int32 Relation(const BMessage* entriesToOpen, static int32 Relation(const BMessage* entriesToOpen,
const Model*, const entry_ref* preferredApp, const Model*, const entry_ref* preferredApp,
const entry_ref* preferredAppForFile); const entry_ref* preferredAppForFile);
// returns the reason why an application is shown in Open With // returns the reason why an application is shown in Open With
// window static version, needs the preferred app for preformance // window static version, needs the preferred app for preformance
static void RelationDescription(const BMessage* entriesToOpen, static void RelationDescription(const BMessage* entriesToOpen,
const Model*, BString*, const entry_ref* preferredApp, const Model*, BString*, const entry_ref* preferredApp,
const entry_ref* preferredAppForFile); const entry_ref* preferredAppForFile);
// returns a string describing why application handles files // returns a string describing why application handles files
// to open // to open
bool CanOpenWithFilter(const Model* appModel, bool CanOpenWithFilter(const Model* appModel,
const BMessage* entriesToOpen, const entry_ref* preferredApp); const BMessage* entriesToOpen, const entry_ref* preferredApp);
void NonGenericFileFound(); void NonGenericFileFound();
bool GenericFilesOnly() const; bool GenericFilesOnly() const;
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
CachedEntryIteratorList* fIteratorList; CachedEntryIteratorList* fIteratorList;
BObjectList<BString> fSignatures; BObjectList<BString> fSignatures;
entry_ref fPreferredRef; entry_ref fPreferredRef;
int32 fPreferredAppCount; int32 fPreferredAppCount;
entry_ref fPreferredRefForFile; entry_ref fPreferredRefForFile;
int32 fPreferredAppForFileCount; int32 fPreferredAppForFileCount;
bool fGenericFilesOnly; bool fGenericFilesOnly;
bool fCanAddAllApps; bool fCanAddAllApps;
bool fFoundOneNonSuperHandler; bool fFoundOneNonSuperHandler;
}; };
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,
window_feel feel = B_NORMAL_WINDOW_FEEL, window_feel feel = B_NORMAL_WINDOW_FEEL,
uint32 flags = 0, uint32 workspace = B_CURRENT_WORKSPACE); uint32 flags = 0, uint32 workspace = B_CURRENT_WORKSPACE);
// <entriesToOpen> eventually get opened by the selected app // <entriesToOpen> eventually get opened by the selected app
virtual ~OpenWithContainerWindow(); virtual ~OpenWithContainerWindow();
virtual void Init(const BMessage* message); virtual void Init(const BMessage* message);
const BMessage* EntryList() const; const BMessage* EntryList() const;
// return the list of the entries we are supposed to open // return the list of the entries we are supposed to open
void SetCanSetAppAsDefault(bool); void SetCanSetAppAsDefault(bool);
void SetCanOpen(bool); void SetCanOpen(bool);
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);
virtual bool ShouldAddMenus() const; virtual bool ShouldAddMenus() const;
virtual void ShowContextMenu(BPoint, const entry_ref*, BView*); virtual void ShowContextMenu(BPoint, const entry_ref*, BView*);
virtual void AddShortcuts(); virtual void AddShortcuts();
virtual void NewAttributeMenu(BMenu*); virtual void NewAttributeMenu(BMenu*);
virtual void RestoreState(); virtual void RestoreState();
virtual void RestoreState(const BMessage&); virtual void RestoreState(const BMessage&);
virtual void RestoreWindowState(AttributeStreamNode*); virtual void RestoreWindowState(AttributeStreamNode*);
virtual void RestoreWindowState(const BMessage&); virtual void RestoreWindowState(const BMessage&);
virtual bool NeedsDefaultStateSetup(); virtual bool NeedsDefaultStateSetup();
virtual void SaveState(bool hide = true); virtual void SaveState(bool hide = true);
virtual void SaveState(BMessage&) const; virtual void SaveState(BMessage&) const;
virtual void SetUpDefaultState(); virtual void SetUpDefaultState();
virtual bool IsShowing(const node_ref*) const; virtual bool IsShowing(const node_ref*) const;
virtual bool IsShowing(const entry_ref*) const; virtual bool IsShowing(const entry_ref*) const;
virtual void MessageReceived(BMessage*); virtual void MessageReceived(BMessage*);
void OpenWithSelection(); void OpenWithSelection();
// open entries with the selected app // open entries with the selected app
void MakeDefaultAndOpen(); void MakeDefaultAndOpen();
// 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*);
BMessage* fEntriesToOpen; BMessage* fEntriesToOpen;
BButton* fLaunchButton; BButton* fLaunchButton;
BButton* fLaunchAndMakeDefaultButton; BButton* fLaunchAndMakeDefaultButton;
float fMinimalWidth; float fMinimalWidth;
typedef BContainerWindow _inherited; typedef BContainerWindow _inherited;
}; };
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*);
// open entries with the selected app // open entries with the selected app
int32 OpenWithRelation(const Model*) const; int32 OpenWithRelation(const Model*) const;
// returns the reason why an application is shown in // returns the reason why an application is shown in
// Open With window // Open With window
void OpenWithRelationDescription(const Model*, BString*) const; void OpenWithRelationDescription(const Model*, BString*) const;
// returns a string describing why application handles files // returns a string describing why application handles files
// to open // to open
OpenWithContainerWindow* ContainerWindow() const; OpenWithContainerWindow* ContainerWindow() const;
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() {}
virtual void FinalStopWatching() {} virtual void FinalStopWatching() {}
virtual void AttachedToWindow(); virtual void AttachedToWindow();
EntryListBase* InitDirentIterator(const entry_ref* ref); EntryListBase* InitDirentIterator(const entry_ref* ref);
virtual void SetUpDefaultColumnsIfNeeded(); virtual void SetUpDefaultColumnsIfNeeded();
// show launch window specific columns // show launch window specific columns
// empty overrides for functions that depend on having an fModel // empty overrides for functions that depend on having an fModel
virtual void SaveState(AttributeStreamNode*); virtual void SaveState(AttributeStreamNode*);
virtual void RestoreState(AttributeStreamNode*); virtual void RestoreState(AttributeStreamNode*);
virtual void SaveState(BMessage&) const; virtual void SaveState(BMessage&) const;
virtual void RestoreState(const BMessage&); virtual void RestoreState(const BMessage&);
virtual void SavePoseLocations(BRect* = NULL); virtual void SavePoseLocations(BRect* = NULL);
virtual void MoveSelectionToTrash(bool selectNext = true); virtual void MoveSelectionToTrash(bool selectNext = true);
virtual void MoveSelectionTo(BPoint, BPoint, BContainerWindow*); virtual void MoveSelectionTo(BPoint, BPoint, BContainerWindow*);
virtual void MoveSelectionInto(Model* destFolder, virtual void MoveSelectionInto(Model* destFolder,
BContainerWindow* srcWindow, bool forceCopy, BContainerWindow* srcWindow, bool forceCopy,
bool create_link = false); bool create_link = false);
virtual bool HandleMessageDropped(BMessage*); virtual bool HandleMessageDropped(BMessage*);
virtual bool CanHandleDragSelection(const Model*, const BMessage*, virtual bool CanHandleDragSelection(const Model*, const BMessage*,
bool); bool);
virtual bool Represents(const node_ref*) const; virtual bool Represents(const node_ref*) const;
virtual bool Represents(const entry_ref*) const; virtual bool Represents(const entry_ref*) const;
virtual void CreatePoses(Model** models, PoseInfo* poseInfoArray, virtual void CreatePoses(Model** models, PoseInfo* poseInfoArray,
int32 count, BPose** resultingPoses, bool insertionSort = true, int32 count, BPose** resultingPoses, bool insertionSort = true,
int32* lastPoseIndexPtr = NULL, BRect* boundsPtr = NULL, int32* lastPoseIndexPtr = NULL, BRect* boundsPtr = NULL,
bool forceDraw = false); bool forceDraw = false);
// override to add selecting the default handling app // override to add selecting the default handling app
// for selection // for selection
virtual void Pulse(); virtual void Pulse();
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;
SearchForSignatureEntryList* fIterator; SearchForSignatureEntryList* fIterator;
// private copy of the iterator pointer // private copy of the iterator pointer
typedef BPoseView _inherited; typedef BPoseView _inherited;
}; };
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;
}; };
class RelationCachingModelProxy { class RelationCachingModelProxy {
public: public:
RelationCachingModelProxy(Model* model); RelationCachingModelProxy(Model* model);
~RelationCachingModelProxy(); ~RelationCachingModelProxy();
int32 Relation(SearchForSignatureEntryList* iterator, int32 Relation(SearchForSignatureEntryList* iterator,
BMessage* entries) const; BMessage* entries) const;
Model* fModel; Model* fModel;
mutable int32 fRelation; mutable int32 fRelation;
}; };
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*);
virtual bool StartBuildingItemList(); virtual bool StartBuildingItemList();
virtual bool AddNextItem(); virtual bool AddNextItem();
virtual void DoneBuildingItemList(); virtual void DoneBuildingItemList();
virtual void ClearMenuBuildingState(); virtual void ClearMenuBuildingState();
BMessage fEntriesToOpen; BMessage fEntriesToOpen;
BHandler* target; BHandler* target;
BMessenger fMessenger; BMessenger fMessenger;
// menu building state // menu building state
SearchForSignatureEntryList* fIterator; SearchForSignatureEntryList* fIterator;
entry_ref fPreferredRef; entry_ref fPreferredRef;
BObjectList<RelationCachingModelProxy>* fSupportingAppList; BObjectList<RelationCachingModelProxy>* fSupportingAppList;
bool fHaveCommonPreferredApp; bool fHaveCommonPreferredApp;
BWindow* fParentWindow; BWindow* fParentWindow;
typedef BSlowMenu _inherited; typedef BSlowMenu _inherited;
}; };
// 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();
virtual status_t GetNextEntry(BEntry* entry, bool traverse = false); virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
virtual status_t GetNextRef(entry_ref* ref); virtual status_t GetNextRef(entry_ref* ref);
virtual int32 GetNextDirents(struct dirent* buffer, size_t length, virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
int32 count = INT_MAX); int32 count = INT_MAX);
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;
}; };
} // namespace BPrivate } // namespace BPrivate
using namespace BPrivate; using namespace BPrivate;
#endif // _OPEN_WITH_WINDOW_H #endif // _OPEN_WITH_WINDOW_H