From c513839558e708fe7c8171a8fd4f9dd99387cd4d Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 20 Jun 2014 18:50:14 -0400 Subject: [PATCH] Tracker: Style fixes to OpenWithWindow --- src/kits/tracker/OpenWithWindow.cpp | 187 +++++++------ src/kits/tracker/OpenWithWindow.h | 412 ++++++++++++++-------------- 2 files changed, 316 insertions(+), 283 deletions(-) diff --git a/src/kits/tracker/OpenWithWindow.cpp b/src/kits/tracker/OpenWithWindow.cpp index fb2414037d..1a0d3822cd 100644 --- a/src/kits/tracker/OpenWithWindow.cpp +++ b/src/kits/tracker/OpenWithWindow.cpp @@ -73,13 +73,18 @@ const int32 kOpenAndMakeDefault = 'OpDf'; const rgb_color kOpenWithDefaultColor = { 0xFF, 0xFF, 0xCC, 255}; +// #pragma mark - OpenWithContainerWindow + + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "OpenWithWindow" + OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen, - LockingList* windowList, window_look look, window_feel feel, - uint32 flags, uint32 workspace) - : BContainerWindow(windowList, 0, look, feel, flags, workspace), + LockingList* windowList, window_look look, window_feel feel, + uint32 flags, uint32 workspace) + : + BContainerWindow(windowList, 0, look, feel, flags, workspace), fEntriesToOpen(entriesToOpen) { AutoLock lock(this); @@ -108,24 +113,25 @@ OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen, BRect buttonRect = fLaunchButton->Frame(); fLaunchAndMakeDefaultButton = new BButton(buttonRect, "make default", - B_TRANSLATE("Open and make preferred"), new BMessage(kOpenAndMakeDefault), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + B_TRANSLATE("Open and make preferred"), + new BMessage(kOpenAndMakeDefault), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); // wide button, have to resize to fit text fLaunchAndMakeDefaultButton->ResizeToPreferred(); - fLaunchAndMakeDefaultButton->MoveBy( - - 10 - fLaunchAndMakeDefaultButton->Bounds().Width(), 0); + fLaunchAndMakeDefaultButton->MoveBy(-10 + - fLaunchAndMakeDefaultButton->Bounds().Width(), 0); backgroundView->AddChild(fLaunchAndMakeDefaultButton); fLaunchAndMakeDefaultButton->SetEnabled(false); 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); button->ResizeToPreferred(); - button->MoveBy(- 10 - button->Bounds().Width(), 0); + button->MoveBy(-10 - button->Bounds().Width(), 0); backgroundView->AddChild(button); fMinimalWidth = button->Bounds().Width() + fLaunchButton->Bounds().Width() - + fLaunchAndMakeDefaultButton->Bounds().Width() + kDocumentKnobWidth + 40; + + fLaunchAndMakeDefaultButton->Bounds().Width() + kDocumentKnobWidth + + 40; fLaunchButton->MakeDefault(true); @@ -152,11 +158,13 @@ OpenWithContainerWindow::OpenWithContainerWindow(BMessage* entriesToOpen, buffer.ReplaceFirst("%name", ref.name); SetTitle(buffer.String()); - } else + } else { // use generic title 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 { ASSERT(dynamic_cast(fPoseView)); + return static_cast(fPoseView); } @@ -193,7 +202,7 @@ OpenWithContainerWindow::OpenWithSelection() { int32 count = PoseView()->SelectionList()->CountItems(); ASSERT(count == 1); - if (!count) + if (count == 0) return; PoseView()->OpenSelection(PoseView()->SelectionList()->FirstItem(), 0); @@ -234,6 +243,7 @@ AddOneUniqueDocumentType(const entry_ref* ref, void* castToList) // add type to list list->AddItem(new BString(type)); + return 0; } @@ -285,12 +295,12 @@ OpenWithContainerWindow::MakeDefaultAndOpen() { int32 count = PoseView()->SelectionList()->CountItems(); ASSERT(count == 1); - if (!count) + if (count == 0) return; BPose* selectedAppPose = PoseView()->SelectionList()->FirstItem(); - ASSERT(selectedAppPose); - if (!selectedAppPose) + ASSERT(selectedAppPose != NULL); + if (selectedAppPose == NULL) return; // collect all the types of all the opened documents into a list @@ -333,6 +343,7 @@ OpenWithContainerWindow::MessageReceived(BMessage* message) ResizeToFit(); break; } + _inherited::MessageReceived(message); } @@ -345,9 +356,9 @@ OpenWithContainerWindow::KeyDownFilter(BMessage* message, BHandler**, if (message->FindInt8("byte", (int8*)&key) != B_OK) return B_DISPATCH_MESSAGE; - int32 modifier=0; - message->FindInt32("modifiers", &modifier); - if (!modifier && key == B_ESCAPE) { + int32 modifiers = 0; + message->FindInt32("modifiers", &modifiers); + if (modifiers == 0 && key == B_ESCAPE) { filter->Looper()->PostMessage(kCancelButton); return B_SKIP_MESSAGE; } @@ -381,24 +392,29 @@ void OpenWithContainerWindow::NewAttributeMenu(BMenu* menu) { _inherited::NewAttributeMenu(menu); + BMessage* message = new BMessage(kAttributeItem); message->AddString("attr_name", kAttrOpenWithRelation); 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->AddInt32("attr_align", B_ALIGN_LEFT); message->AddBool("attr_editable", false); message->AddBool("attr_statfield", false); + BMenuItem* item = new BMenuItem(B_TRANSLATE("Relation"), message); menu->AddItem(item); message = new BMessage(kAttributeItem); message->AddString("attr_name", kAttrAppVersion); 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->AddInt32("attr_align", B_ALIGN_LEFT); message->AddBool("attr_editable", false); message->AddBool("attr_statfield", false); + item = new BMenuItem(B_TRANSLATE("Version"), message); menu->AddItem(item); } @@ -435,7 +451,8 @@ void OpenWithContainerWindow::RestoreState() { BNode defaultingNode; - if (DefaultStateSourceNode(kDefaultOpenWithTemplate, &defaultingNode, false)) { + if (DefaultStateSourceNode(kDefaultOpenWithTemplate, &defaultingNode, + false)) { AttributeStreamFileNode streamNodeSource(&defaultingNode); RestoreWindowState(&streamNodeSource); fPoseView->Init(&streamNodeSource); @@ -457,13 +474,13 @@ void OpenWithContainerWindow::RestoreWindowState(AttributeStreamNode* node) { SetSizeLimits(fMinimalWidth, 10000, 160, 10000); - if (!node) + if (node == NULL) return; const char* rectAttributeName = kAttrWindowFrame; BRect frame(Frame()); if (node->Read(rectAttributeName, 0, B_RECT_TYPE, sizeof(BRect), &frame) - == sizeof(BRect)) { + == sizeof(BRect)) { MoveTo(frame.LeftTop()); ResizeTo(frame.Width(), frame.Height()); } @@ -518,11 +535,12 @@ OpenWithContainerWindow::SetCanOpen(bool on) } -// #pragma mark - +// #pragma mark - OpenWithPoseView OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask) - : BPoseView(0, frame, kListMode, resizeMask), + : + BPoseView(0, frame, kListMode, resizeMask), fHaveCommonPreferredApp(false), fIterator(NULL) { @@ -602,7 +620,8 @@ AddOneRefSignatures(const entry_ref* ref, void* castToIterator) // add preferred app for file, if any if (model.PreferredAppSignature()[0]) { // 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->TrySettingPreferredAppForFile(&preferredRef); } @@ -649,7 +668,8 @@ OpenWithPoseView::InitDirentIterator(const entry_ref*) return NULL; } SetRefFilter(new OpenWithRefFilter(fIterator, entryList, - (fHaveCommonPreferredApp ? &fPreferredRef : 0))); + fHaveCommonPreferredApp ? &fPreferredRef : 0)); + return fIterator; } @@ -660,10 +680,10 @@ OpenWithPoseView::OpenSelection(BPose* pose, int32*) OpenWithContainerWindow* window = ContainerWindow(); int32 count = fSelectionList->CountItems(); - if (!count) + if (count == 0) return; - if (!pose) + if (pose == NULL) pose = fSelectionList->FirstItem(); ASSERT(pose); @@ -710,9 +730,8 @@ OpenWithPoseView::OpenSelection(BPose* pose, int32*) message.AddRef("handler", pose->TargetModel()->EntryRef()); // add ref of the selected handler - ASSERT(fSelectionHandler); - - if (fSelectionHandler) + ASSERT(fSelectionHandler != NULL); + if (fSelectionHandler != NULL) fSelectionHandler->PostMessage(&message); window->PostMessage(B_QUIT_REQUESTED); @@ -797,20 +816,21 @@ OpenWithPoseView::AddPosesThreadValid(const entry_ref*) const void -OpenWithPoseView::CreatePoses(Model** models, PoseInfo* poseInfoArray, int32 count, - BPose** resultingPoses, bool insertionSort, int32* lastPoseIndexPtr, - BRect* boundsPtr, bool forceDraw) +OpenWithPoseView::CreatePoses(Model** models, PoseInfo* poseInfoArray, + int32 count, BPose** resultingPoses, bool insertionSort, + int32* lastPoseIndexPtr, BRect* boundsPtr, bool forceDraw) { // overridden to try to select the preferred handling app - _inherited::CreatePoses(models, poseInfoArray, count, resultingPoses, insertionSort, - lastPoseIndexPtr, boundsPtr, forceDraw); + _inherited::CreatePoses(models, poseInfoArray, count, resultingPoses, + insertionSort, lastPoseIndexPtr, boundsPtr, forceDraw); - if (resultingPoses) { + if (resultingPoses != NULL) { for (int32 index = 0; index < count; index++) { if (resultingPoses[index] && fHaveCommonPreferredApp && *(models[index]->EntryRef()) == fPreferredRef) { // 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 OpenWithPoseView::SavePoseLocations(BRect*) { - // do nothing } @@ -905,7 +924,8 @@ OpenWithPoseView::HandleMessageDropped(BMessage* DEBUG_ONLY(message)) const rgb_color* color; ssize_t size; // 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); SetLowColor(*color); Invalidate(); @@ -937,7 +957,7 @@ OpenWithPoseView::OpenWithRelationDescription(const Model* model, } -// #pragma mark - +// #pragma mark - OpenWithRefFilter 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, fPreferredRef); delete model; + return canOpen; } @@ -990,12 +1011,13 @@ RelationCachingModelProxy::Relation(SearchForSignatureEntryList* iterator, } -// #pragma mark - +// #pragma mark - OpenWithMenu OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen, - BWindow* parentWindow, BHandler* target) - : BSlowMenu(label), + BWindow* parentWindow, BHandler* target) + : + BSlowMenu(label), fEntriesToOpen(*entriesToOpen), target(target), fIterator(NULL), @@ -1012,8 +1034,9 @@ OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen, OpenWithMenu::OpenWithMenu(const char* label, const BMessage* entriesToOpen, - BWindow* parentWindow, const BMessenger &messenger) - : BSlowMenu(label), + BWindow* parentWindow, const BMessenger &messenger) + : + BSlowMenu(label), fEntriesToOpen(*entriesToOpen), target(NULL), fMessenger(messenger), @@ -1089,10 +1112,9 @@ OpenWithMenu::AddNextItem() Model* model = new Model(&entry, true); if (model->InitCheck() != B_OK || !fIterator->CanOpenWithFilter(model, &fEntriesToOpen, - fHaveCommonPreferredApp ? &fPreferredRef : 0)) { - // only allow executables, filter out multiple copies of the - // Tracker, filter out version that don't list the correct types, - // etc. + fHaveCommonPreferredApp ? &fPreferredRef : 0)) { + // only allow executables, filter out multiple copies of the Tracker, + // filter out version that don't list the correct types, etc. delete model; } else fSupportingAppList->AddItem(new RelationCachingModelProxy(model)); @@ -1108,13 +1130,13 @@ OpenWithMenu::DoneBuildingItemList() fSupportingAppList->SortItems(SortByRelationAndName, this); // check if each app is unique - bool unique = true; + bool isUnique = true; int32 count = fSupportingAppList->CountItems(); for (int32 index = 0; index < count - 1; index++) { // the list is sorted, just compare two adjacent models if (strcmp(fSupportingAppList->ItemAt(index)->fModel->Name(), fSupportingAppList->ItemAt(index + 1)->fModel->Name()) == 0) { - unique = false; + isUnique = false; break; } } @@ -1125,17 +1147,20 @@ OpenWithMenu::DoneBuildingItemList() int32 lastRelation = -1; for (int32 index = 0; index < count ; index++) { - RelationCachingModelProxy* modelProxy = fSupportingAppList->ItemAt(index); + RelationCachingModelProxy* modelProxy + = fSupportingAppList->ItemAt(index); Model* model = modelProxy->fModel; BMessage* message = new BMessage(fEntriesToOpen); message->AddRef("handler", model->EntryRef()); - BContainerWindow* window = dynamic_cast(fParentWindow); - if (window) - message->AddData("nodeRefsToClose", B_RAW_TYPE, window->TargetModel()->NodeRef(), - sizeof (node_ref)); + BContainerWindow* window + = dynamic_cast(fParentWindow); + if (window != NULL) { + message->AddData("nodeRefsToClose", B_RAW_TYPE, + window->TargetModel()->NodeRef(), sizeof(node_ref)); + } BString result; - if (unique) { + if (isUnique) { // just use the app name result = model->Name(); } else { @@ -1164,7 +1189,8 @@ OpenWithMenu::DoneBuildingItemList() AddSeparatorItem(); lastRelation = relation; - ModelMenuItem* item = new ModelMenuItem(model, result.String(), message); + ModelMenuItem* item = new ModelMenuItem(model, result.String(), + message); AddItem(item); // mark item if it represents the preferred app if (fHaveCommonPreferredApp && *(model->EntryRef()) == fPreferredRef) { @@ -1174,12 +1200,12 @@ OpenWithMenu::DoneBuildingItemList() } // target the menu - if (target) + if (target != NULL) SetTargetForItems(target); else SetTargetForItems(fMessenger); - if (!CountItems()) { + if (CountItems() == 0) { BMenuItem* item = new BMenuItem(B_TRANSLATE("no supporting apps"), 0); item->SetEnabled(false); AddItem(item); @@ -1197,7 +1223,7 @@ OpenWithMenu::ClearMenuBuildingState() } -// #pragma mark - +// #pragma mark - SearchForSignatureEntryList SearchForSignatureEntryList::SearchForSignatureEntryList(bool canAddAllApps) @@ -1257,6 +1283,7 @@ struct AddOneTermParams { bool first; }; + static const BString* AddOnePredicateTerm(const BString* item, void* castToParams) { @@ -1296,7 +1323,7 @@ SearchForSignatureEntryList::Rewind() fSignatures.EachElement(AddOnePredicateTerm, ¶ms); ASSERT(predicateString.Length()); -// PRINT(("query predicate %s\n", predicateString.String())); +// PRINT(("query predicate %s\n", predicateString.String())); fIteratorList->AddItem(new TWalkerWrapper( new BTrackerPrivate::TQueryWalker(predicateString.String()))); fIteratorList->AddItem(new ConditionalAllAppsIterator(this)); @@ -1328,9 +1355,10 @@ SearchForSignatureEntryList::TrySettingPreferredApp(const entry_ref* ref) if (!fPreferredAppCount) { fPreferredRef = *ref; fPreferredAppCount++; - } else if (fPreferredRef != *ref) + } else if (fPreferredRef != *ref) { // if more than one, will not return any fPreferredAppCount++; + } } @@ -1372,7 +1400,9 @@ int32 SearchForSignatureEntryList::Relation(const Model* nodeModel, const Model* applicationModel) { - switch (applicationModel->SupportsMimeType(nodeModel->MimeType(), 0, true)) { + int32 supportsMimeType = applicationModel->SupportsMimeType( + nodeModel->MimeType(), 0, true); + switch (supportsMimeType) { case kDoesNotSupportType: return kNoRelation; @@ -1421,8 +1451,8 @@ SearchForSignatureEntryList::Relation(const BMessage* entriesToOpen, if (entriesToOpen->FindRef("refs", index, &ref) != B_OK) break; - // need to init a model so that typeless folders etc. will still appear to - // have a mime type + // need to init a model so that typeless folders etc. will still + // appear to have a mime type Model model(&ref, true, true); if (model.InitCheck()) @@ -1431,13 +1461,15 @@ SearchForSignatureEntryList::Relation(const BMessage* entriesToOpen, int32 result = Relation(&model, applicationModel); if (result != kNoRelation) { if (preferredAppForFile - && *applicationModel->EntryRef() == *preferredAppForFile) + && *applicationModel->EntryRef() == *preferredAppForFile) { return kPreferredForFile; + } if (result == kSupportsType && preferredApp - && *applicationModel->EntryRef() == *preferredApp) + && *applicationModel->EntryRef() == *preferredApp) { // application matches cached preferred app, we are done return kPreferredForType; + } return result; } @@ -1483,13 +1515,13 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen, char* type = (char*)mimeType.Type(); char* tmp = strchr(type, '/'); - if (tmp) + if (tmp != NULL) *tmp = '\0'; //PRINT(("getting supertype for %s, result %s, got %s\n", // model.MimeType(), strerror(result), mimeType.Type())); description->SetTo(B_TRANSLATE("Handles any %type")); - // *description += mimeType.Type(); + //*description += mimeType.Type(); description->ReplaceFirst("%type", type); return; } @@ -1498,7 +1530,7 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen, { mimeType.SetTo(model.MimeType()); - if (preferredApp + if (preferredApp != NULL && *applicationModel->EntryRef() == *preferredApp) { // application matches cached preferred app, we are done description->SetTo(B_TRANSLATE("Preferred for %type")); @@ -1510,6 +1542,7 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen, description->ReplaceFirst("%type", shortDescription); else description->ReplaceFirst("%type", mimeType.Type()); + return; } } @@ -1613,11 +1646,11 @@ SearchForSignatureEntryList::CanOpenWithFilter(const Model* appModel, } -// #pragma mark - +// #pragma mark - ConditionalAllAppsIterator ConditionalAllAppsIterator::ConditionalAllAppsIterator( - SearchForSignatureEntryList* parent) + SearchForSignatureEntryList* parent) : fParent(parent), fWalker(NULL) @@ -1628,7 +1661,7 @@ ConditionalAllAppsIterator::ConditionalAllAppsIterator( void ConditionalAllAppsIterator::Instantiate() { - if (fWalker) + if (fWalker == NULL) return; BString lookForAppsPredicate; diff --git a/src/kits/tracker/OpenWithWindow.h b/src/kits/tracker/OpenWithWindow.h index e3a4c6f557..cb4c111f59 100644 --- a/src/kits/tracker/OpenWithWindow.h +++ b/src/kits/tracker/OpenWithWindow.h @@ -51,8 +51,6 @@ All rights reserved. namespace BPrivate { -class OpenWithPoseView; - enum { kUnknownRelation = -1, kNoRelation = 0, @@ -64,294 +62,296 @@ enum { }; +class OpenWithPoseView; + // pass in a predicate; a query will search for matches // matches will be returned in iteration class SearchForSignatureEntryList : public EntryListBase { - public: - SearchForSignatureEntryList(bool canAddAllApps); - virtual ~SearchForSignatureEntryList(); +public: + SearchForSignatureEntryList(bool canAddAllApps); + virtual ~SearchForSignatureEntryList(); - void PushUniqueSignature(const char*); - // add one signature to search for + void PushUniqueSignature(const char*); + // add one signature to search for - // entry list iterators - virtual status_t GetNextEntry(BEntry* entry, bool traverse = false); - virtual status_t GetNextRef(entry_ref* ref); - virtual int32 GetNextDirents(struct dirent* buffer, size_t length, - int32 count = INT_MAX); + // entry list iterators + virtual status_t GetNextEntry(BEntry* entry, bool traverse = false); + virtual status_t GetNextRef(entry_ref* ref); + virtual int32 GetNextDirents(struct dirent* buffer, size_t length, + int32 count = INT_MAX); - virtual status_t Rewind(); - virtual int32 CountEntries(); + virtual status_t Rewind(); + virtual int32 CountEntries(); - bool GetPreferredApp(entry_ref* ref) const; - // gets the preferred app for all the files it was asked to - // find supporting apps for, returns false if no preferred app - // found or if more than one found - void TrySettingPreferredApp(const entry_ref*); - void TrySettingPreferredAppForFile(const entry_ref*); + bool GetPreferredApp(entry_ref* ref) const; + // gets the preferred app for all the files it was asked to + // find supporting apps for, returns false if no preferred app + // found or if more than one found + void TrySettingPreferredApp(const entry_ref*); + void TrySettingPreferredAppForFile(const entry_ref*); - int32 Relation(const BMessage* entriesToOpen, const Model*) const; - // returns the reason why an application is shown in - // Open With window - void RelationDescription(const BMessage* entriesToOpen, const Model*, - BString*) const; - // returns a string describing why application handles files - // to open + int32 Relation(const BMessage* entriesToOpen, const Model*) const; + // returns the reason why an application is shown in + // Open With window + void RelationDescription(const BMessage* entriesToOpen, const Model*, + BString*) const; + // returns a string describing why application handles files + // to open - static int32 Relation(const BMessage* entriesToOpen, - const Model*, const entry_ref* preferredApp, - const entry_ref* preferredAppForFile); - // returns the reason why an application is shown in Open With - // window static version, needs the preferred app for preformance - static void RelationDescription(const BMessage* entriesToOpen, - const Model*, BString*, const entry_ref* preferredApp, - const entry_ref* preferredAppForFile); - // returns a string describing why application handles files - // to open + static int32 Relation(const BMessage* entriesToOpen, + const Model*, const entry_ref* preferredApp, + const entry_ref* preferredAppForFile); + // returns the reason why an application is shown in Open With + // window static version, needs the preferred app for preformance + static void RelationDescription(const BMessage* entriesToOpen, + const Model*, BString*, const entry_ref* preferredApp, + const entry_ref* preferredAppForFile); + // returns a string describing why application handles files + // to open - bool CanOpenWithFilter(const Model* appModel, - const BMessage* entriesToOpen, const entry_ref* preferredApp); + bool CanOpenWithFilter(const Model* appModel, + const BMessage* entriesToOpen, const entry_ref* preferredApp); - void NonGenericFileFound(); - bool GenericFilesOnly() const; + void NonGenericFileFound(); + bool GenericFilesOnly() const; - bool ShowAllApplications() const; + bool ShowAllApplications() const; - private: - static int32 Relation(const Model* node, const Model* app); - // returns the reason why an application is shown in - // Open With window +private: + static int32 Relation(const Model* node, const Model* app); + // returns the reason why an application is shown in + // Open With window - CachedEntryIteratorList* fIteratorList; - BObjectList fSignatures; + CachedEntryIteratorList* fIteratorList; + BObjectList fSignatures; - entry_ref fPreferredRef; - int32 fPreferredAppCount; - entry_ref fPreferredRefForFile; - int32 fPreferredAppForFileCount; - bool fGenericFilesOnly; - bool fCanAddAllApps; - bool fFoundOneNonSuperHandler; + entry_ref fPreferredRef; + int32 fPreferredAppCount; + entry_ref fPreferredRefForFile; + int32 fPreferredAppForFileCount; + bool fGenericFilesOnly; + bool fCanAddAllApps; + bool fFoundOneNonSuperHandler; }; class OpenWithContainerWindow : public BContainerWindow { - public: - OpenWithContainerWindow(BMessage* entriesToOpen, - LockingList* windowList, - window_look look = B_DOCUMENT_WINDOW_LOOK, - window_feel feel = B_NORMAL_WINDOW_FEEL, - uint32 flags = 0, uint32 workspace = B_CURRENT_WORKSPACE); - // eventually get opened by the selected app - virtual ~OpenWithContainerWindow(); +public: + OpenWithContainerWindow(BMessage* entriesToOpen, + LockingList* windowList, + window_look look = B_DOCUMENT_WINDOW_LOOK, + window_feel feel = B_NORMAL_WINDOW_FEEL, + uint32 flags = 0, uint32 workspace = B_CURRENT_WORKSPACE); + // eventually get opened by the selected app + virtual ~OpenWithContainerWindow(); - virtual void Init(const BMessage* message); + virtual void Init(const BMessage* message); - const BMessage* EntryList() const; - // return the list of the entries we are supposed to open + const BMessage* EntryList() const; + // return the list of the entries we are supposed to open - void SetCanSetAppAsDefault(bool); - void SetCanOpen(bool); + void SetCanSetAppAsDefault(bool); + void SetCanOpen(bool); - OpenWithPoseView* PoseView() const; + OpenWithPoseView* PoseView() const; - protected: - virtual BPoseView* NewPoseView(Model* model, BRect rect, - uint32 viewMode); +protected: + virtual BPoseView* NewPoseView(Model* model, BRect rect, + uint32 viewMode); - virtual bool ShouldAddMenus() const; - virtual void ShowContextMenu(BPoint, const entry_ref*, BView*); - virtual void AddShortcuts(); - virtual void NewAttributeMenu(BMenu*); + virtual bool ShouldAddMenus() const; + virtual void ShowContextMenu(BPoint, const entry_ref*, BView*); + virtual void AddShortcuts(); + virtual void NewAttributeMenu(BMenu*); - virtual void RestoreState(); - virtual void RestoreState(const BMessage&); - virtual void RestoreWindowState(AttributeStreamNode*); - virtual void RestoreWindowState(const BMessage&); - virtual bool NeedsDefaultStateSetup(); - virtual void SaveState(bool hide = true); - virtual void SaveState(BMessage&) const; - virtual void SetUpDefaultState(); + virtual void RestoreState(); + virtual void RestoreState(const BMessage&); + virtual void RestoreWindowState(AttributeStreamNode*); + virtual void RestoreWindowState(const BMessage&); + virtual bool NeedsDefaultStateSetup(); + virtual void SaveState(bool hide = true); + virtual void SaveState(BMessage&) const; + virtual void SetUpDefaultState(); - virtual bool IsShowing(const node_ref*) const; - virtual bool IsShowing(const entry_ref*) const; + virtual bool IsShowing(const node_ref*) const; + virtual bool IsShowing(const entry_ref*) const; - virtual void MessageReceived(BMessage*); + virtual void MessageReceived(BMessage*); - void OpenWithSelection(); - // open entries with the selected app - void MakeDefaultAndOpen(); - // open entries with the selected app and make it - // the default handler + void OpenWithSelection(); + // open entries with the selected app + void MakeDefaultAndOpen(); + // open entries with the selected app and make it + // the default handler - private: - static filter_result KeyDownFilter(BMessage*, BHandler**, - BMessageFilter*); +private: + static filter_result KeyDownFilter(BMessage*, BHandler**, + BMessageFilter*); - BMessage* fEntriesToOpen; - BButton* fLaunchButton; - BButton* fLaunchAndMakeDefaultButton; - float fMinimalWidth; + BMessage* fEntriesToOpen; + BButton* fLaunchButton; + BButton* fLaunchAndMakeDefaultButton; + float fMinimalWidth; - typedef BContainerWindow _inherited; + typedef BContainerWindow _inherited; }; class OpenWithPoseView : public BPoseView { - public: - OpenWithPoseView(BRect, uint32 resizeMask = B_FOLLOW_ALL); +public: + OpenWithPoseView(BRect, uint32 resizeMask = B_FOLLOW_ALL); - virtual void OpenSelection(BPose*, int32*); - // open entries with the selected app + virtual void OpenSelection(BPose*, int32*); + // open entries with the selected app - int32 OpenWithRelation(const Model*) const; - // returns the reason why an application is shown in - // Open With window - void OpenWithRelationDescription(const Model*, BString*) const; - // returns a string describing why application handles files - // to open + int32 OpenWithRelation(const Model*) const; + // returns the reason why an application is shown in + // Open With window + void OpenWithRelationDescription(const Model*, BString*) const; + // returns a string describing why application handles files + // to open - OpenWithContainerWindow* ContainerWindow() const; + OpenWithContainerWindow* ContainerWindow() const; - virtual bool AddPosesThreadValid(const entry_ref*) const; + virtual bool AddPosesThreadValid(const entry_ref*) const; - protected: - // don't do any volume watching and memtamime watching in open with - // panels for now - virtual void InitialStartWatching() {} - virtual void FinalStopWatching() {} +protected: + // don't do any volume watching and memtamime watching in open with + // panels for now + virtual void InitialStartWatching() {} + virtual void FinalStopWatching() {} - virtual void AttachedToWindow(); - EntryListBase* InitDirentIterator(const entry_ref* ref); + virtual void AttachedToWindow(); + EntryListBase* InitDirentIterator(const entry_ref* ref); - virtual void SetUpDefaultColumnsIfNeeded(); - // show launch window specific columns + virtual void SetUpDefaultColumnsIfNeeded(); + // show launch window specific columns - // empty overrides for functions that depend on having an fModel - virtual void SaveState(AttributeStreamNode*); - virtual void RestoreState(AttributeStreamNode*); - virtual void SaveState(BMessage&) const; - virtual void RestoreState(const BMessage&); - virtual void SavePoseLocations(BRect* = NULL); - virtual void MoveSelectionToTrash(bool selectNext = true); - virtual void MoveSelectionTo(BPoint, BPoint, BContainerWindow*); - virtual void MoveSelectionInto(Model* destFolder, - BContainerWindow* srcWindow, bool forceCopy, - bool create_link = false); - virtual bool HandleMessageDropped(BMessage*); - virtual bool CanHandleDragSelection(const Model*, const BMessage*, - bool); + // empty overrides for functions that depend on having an fModel + virtual void SaveState(AttributeStreamNode*); + virtual void RestoreState(AttributeStreamNode*); + virtual void SaveState(BMessage&) const; + virtual void RestoreState(const BMessage&); + virtual void SavePoseLocations(BRect* = NULL); + virtual void MoveSelectionToTrash(bool selectNext = true); + virtual void MoveSelectionTo(BPoint, BPoint, BContainerWindow*); + virtual void MoveSelectionInto(Model* destFolder, + BContainerWindow* srcWindow, bool forceCopy, + bool create_link = false); + virtual bool HandleMessageDropped(BMessage*); + virtual bool CanHandleDragSelection(const Model*, const BMessage*, + bool); - virtual bool Represents(const node_ref*) const; - virtual bool Represents(const entry_ref*) const; + virtual bool Represents(const node_ref*) const; + virtual bool Represents(const entry_ref*) const; - virtual void CreatePoses(Model** models, PoseInfo* poseInfoArray, - int32 count, BPose** resultingPoses, bool insertionSort = true, - int32* lastPoseIndexPtr = NULL, BRect* boundsPtr = NULL, - bool forceDraw = false); - // override to add selecting the default handling app - // for selection + virtual void CreatePoses(Model** models, PoseInfo* poseInfoArray, + int32 count, BPose** resultingPoses, bool insertionSort = true, + int32* lastPoseIndexPtr = NULL, BRect* boundsPtr = NULL, + bool forceDraw = false); + // override to add selecting the default handling app + // 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: - entry_ref fPreferredRef; - bool fHaveCommonPreferredApp; +private: + entry_ref fPreferredRef; + bool fHaveCommonPreferredApp; - SearchForSignatureEntryList* fIterator; - // private copy of the iterator pointer + SearchForSignatureEntryList* fIterator; + // private copy of the iterator pointer - typedef BPoseView _inherited; + typedef BPoseView _inherited; }; -class OpenWithRefFilter: public BRefFilter -{ - public: - OpenWithRefFilter(SearchForSignatureEntryList*, const BMessage*, - entry_ref*); - bool Filter(const entry_ref* ref, BNode* node, stat_beos* st, - const char* filetype); +class OpenWithRefFilter: public BRefFilter { +public: + OpenWithRefFilter(SearchForSignatureEntryList*, const BMessage*, + entry_ref*); + bool Filter(const entry_ref* ref, BNode* node, stat_beos* st, + const char* filetype); - private: - SearchForSignatureEntryList* fIterator; - const BMessage *fEntryList; - entry_ref* fPreferredRef; +private: + SearchForSignatureEntryList* fIterator; + const BMessage *fEntryList; + entry_ref* fPreferredRef; }; class RelationCachingModelProxy { - public: - RelationCachingModelProxy(Model* model); - ~RelationCachingModelProxy(); +public: + RelationCachingModelProxy(Model* model); + ~RelationCachingModelProxy(); - int32 Relation(SearchForSignatureEntryList* iterator, - BMessage* entries) const; + int32 Relation(SearchForSignatureEntryList* iterator, + BMessage* entries) const; - Model* fModel; - mutable int32 fRelation; + Model* fModel; + mutable int32 fRelation; }; class OpenWithMenu : public BSlowMenu { - public: - OpenWithMenu(const char* label, const BMessage* entriesToOpen, - BWindow* parentWindow, BHandler* target); - OpenWithMenu(const char* label, const BMessage* entriesToOpen, - BWindow* parentWindow, const BMessenger &target); +public: + OpenWithMenu(const char* label, const BMessage* entriesToOpen, + BWindow* parentWindow, BHandler* target); + OpenWithMenu(const char* label, const BMessage* entriesToOpen, + BWindow* parentWindow, const BMessenger &target); - private: - friend int SortByRelationAndName(const RelationCachingModelProxy*, - const RelationCachingModelProxy*, void*); +private: + friend int SortByRelationAndName(const RelationCachingModelProxy*, + const RelationCachingModelProxy*, void*); - virtual bool StartBuildingItemList(); - virtual bool AddNextItem(); - virtual void DoneBuildingItemList(); - virtual void ClearMenuBuildingState(); + virtual bool StartBuildingItemList(); + virtual bool AddNextItem(); + virtual void DoneBuildingItemList(); + virtual void ClearMenuBuildingState(); - BMessage fEntriesToOpen; - BHandler* target; - BMessenger fMessenger; + BMessage fEntriesToOpen; + BHandler* target; + BMessenger fMessenger; - // menu building state - SearchForSignatureEntryList* fIterator; - entry_ref fPreferredRef; - BObjectList* fSupportingAppList; - bool fHaveCommonPreferredApp; - BWindow* fParentWindow; + // menu building state + SearchForSignatureEntryList* fIterator; + entry_ref fPreferredRef; + BObjectList* fSupportingAppList; + bool fHaveCommonPreferredApp; + BWindow* fParentWindow; - typedef BSlowMenu _inherited; + typedef BSlowMenu _inherited; }; // used for optionally showing the list of all apps. Do nothing // until asked to iterate and only if supposed to do so class ConditionalAllAppsIterator : public EntryListBase { - public: - ConditionalAllAppsIterator(SearchForSignatureEntryList* parent); - ~ConditionalAllAppsIterator(); +public: + ConditionalAllAppsIterator(SearchForSignatureEntryList* parent); + ~ConditionalAllAppsIterator(); - virtual status_t GetNextEntry(BEntry* entry, bool traverse = false); - virtual status_t GetNextRef(entry_ref* ref); - virtual int32 GetNextDirents(struct dirent* buffer, size_t length, - int32 count = INT_MAX); + virtual status_t GetNextEntry(BEntry* entry, bool traverse = false); + virtual status_t GetNextRef(entry_ref* ref); + virtual int32 GetNextDirents(struct dirent* buffer, size_t length, + int32 count = INT_MAX); - virtual status_t Rewind(); - virtual int32 CountEntries(); + virtual status_t Rewind(); + virtual int32 CountEntries(); - protected: - bool Iterate() const; - void Instantiate(); +protected: + bool Iterate() const; + void Instantiate(); - private: - SearchForSignatureEntryList* fParent; - BTrackerPrivate::TWalker* fWalker; +private: + SearchForSignatureEntryList* fParent; + BTrackerPrivate::TWalker* fWalker; }; } // namespace BPrivate using namespace BPrivate; + #endif // _OPEN_WITH_WINDOW_H