Style fixes

This commit is contained in:
John Scipione
2013-04-27 19:40:13 -04:00
parent 21fd5809a7
commit 1b98948370
+52 -50
View File
@@ -86,6 +86,7 @@ All rights reserved.
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "FindPanel" #define B_TRANSLATION_CONTEXT "FindPanel"
const char* kAllMimeTypes = "mime/ALLTYPES"; const char* kAllMimeTypes = "mime/ALLTYPES";
const BRect kInitialRect(100, 100, 0, 0); const BRect kInitialRect(100, 100, 0, 0);
@@ -140,6 +141,7 @@ class MostUsedNames {
int32 fCount; int32 fCount;
}; };
MostUsedNames gMostUsedMimeTypes("MostUsedMimeTypes", "Tracker"); MostUsedNames gMostUsedMimeTypes("MostUsedMimeTypes", "Tracker");
@@ -171,8 +173,9 @@ MoreOptionsStruct::QueryTemporary(const BNode* node)
if (ReadAttr(node, kAttrQueryMoreOptions, kAttrQueryMoreOptionsForeign, if (ReadAttr(node, kAttrQueryMoreOptions, kAttrQueryMoreOptionsForeign,
B_RAW_TYPE, 0, &saveMoreOptions, sizeof(MoreOptionsStruct), B_RAW_TYPE, 0, &saveMoreOptions, sizeof(MoreOptionsStruct),
&MoreOptionsStruct::EndianSwap) == kReadAttrFailed) &MoreOptionsStruct::EndianSwap) == kReadAttrFailed) {
return false; return false;
}
return saveMoreOptions.temporary; return saveMoreOptions.temporary;
} }
@@ -190,7 +193,7 @@ FindWindow::FindWindow(const entry_ref* newRef, bool editIfTemplateOnly)
fEditTemplateOnly(false), fEditTemplateOnly(false),
fSaveAsTemplatePanel(NULL) fSaveAsTemplatePanel(NULL)
{ {
if (fFile) { if (fFile != NULL) {
fRef = *newRef; fRef = *newRef;
if (editIfTemplateOnly) { if (editIfTemplateOnly) {
char type[B_MIME_TYPE_LENGTH]; char type[B_MIME_TYPE_LENGTH];
@@ -283,13 +286,7 @@ FindWindow::SwitchToTemplate(const entry_ref* ref)
BFile templateFile(&entry, O_RDONLY); BFile templateFile(&entry, O_RDONLY);
ThrowOnInitCheckError(&templateFile); ThrowOnInitCheckError(&templateFile);
//DisableUpdates();
// turn off updates to reduce flicker while re-populating the
// window
// #9689 : couldn't get to work since changing to Layout API
fBackground->SwitchToTemplate(&templateFile); fBackground->SwitchToTemplate(&templateFile);
//EnableUpdates();
} catch (...) { } catch (...) {
} }
} }
@@ -394,8 +391,7 @@ FindWindow::SaveQueryAttributes(BNode* file, bool queryTemplate)
status_t status_t
FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry, FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry,
bool queryTemplate, const BMessage* oldAttributes, bool queryTemplate, const BMessage* oldAttributes, const BPoint* oldLocation)
const BPoint* oldLocation)
{ {
if (oldAttributes) if (oldAttributes)
// revive old window settings // revive old window settings
@@ -422,10 +418,10 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry,
// write some useful info to help locate the volume to query // write some useful info to help locate the volume to query
BMenuItem* item = fBackground->VolMenu()->FindMarked(); BMenuItem* item = fBackground->VolMenu()->FindMarked();
if (item) { if (item != NULL) {
dev_t dev; dev_t dev;
BMessage message; BMessage message;
int32 count = 0; uint32 count = 0;
int32 itemCount = fBackground->VolMenu()->CountItems(); int32 itemCount = fBackground->VolMenu()->CountItems();
for (int32 index = 2; index < itemCount; index++) { for (int32 index = 2; index < itemCount; index++) {
@@ -442,7 +438,7 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry,
EmbedUniqueVolumeInfo(&message, &volume); EmbedUniqueVolumeInfo(&message, &volume);
} }
if (count) { if (count > 0) {
// do we need to embed any volumes // do we need to embed any volumes
ssize_t size = message.FlattenedSize(); ssize_t size = message.FlattenedSize();
BString buffer; BString buffer;
@@ -463,7 +459,7 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry,
// be reopened and edited later // be reopened and edited later
BView* focusedItem = CurrentFocus(); BView* focusedItem = CurrentFocus();
if (focusedItem) { if (focusedItem != NULL) {
// text controls never get the focus, their internal text views do // text controls never get the focus, their internal text views do
BView* parent = focusedItem->Parent(); BView* parent = focusedItem->Parent();
if (dynamic_cast<BTextControl*>(parent)) if (dynamic_cast<BTextControl*>(parent))
@@ -482,6 +478,7 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry,
&selEnd, sizeof(selEnd)); &selEnd, sizeof(selEnd));
} }
} }
return B_OK; return B_OK;
} }
@@ -505,10 +502,11 @@ FindWindow::Find()
TTracker* tracker = dynamic_cast<TTracker*>(be_app); TTracker* tracker = dynamic_cast<TTracker*>(be_app);
ASSERT(tracker); ASSERT(tracker);
for (int32 timeOut = 0; ; timeOut++) { for (int32 timeOut = 0; ; timeOut++) {
if (!tracker->EntryHasWindowOpen(&fRef)) if (!tracker->EntryHasWindowOpen(&fRef)) {
// window quit, we can post refs received to open a // window quit, we can post refs received to open a
// new copy // new copy
break; break;
}
// PRINT(("waiting for query window to quit, %d\n", timeOut)); // PRINT(("waiting for query window to quit, %d\n", timeOut));
if (timeOut == 5000) { if (timeOut == 5000) {
@@ -631,8 +629,7 @@ FindWindow::MessageReceived(BMessage* message)
fFile = TryOpening(&tmpRef); fFile = TryOpening(&tmpRef);
if (fFile) { if (fFile) {
fRef = tmpRef; fRef = tmpRef;
SaveQueryAsAttributes(fFile, &entry, queryTemplate, SaveQueryAsAttributes(fFile, &entry, queryTemplate, 0, 0);
0, 0);
// try to save whatever state we aleady have // try to save whatever state we aleady have
// to the new query so that if the user // to the new query so that if the user
// opens it before runing it from the find panel, // opens it before runing it from the find panel,
@@ -647,11 +644,12 @@ FindWindow::MessageReceived(BMessage* message)
entry_ref ref; entry_ref ref;
if (message->FindRef("refs", &ref) == B_OK) if (message->FindRef("refs", &ref) == B_OK)
SwitchToTemplate(&ref); SwitchToTemplate(&ref);
}
break; break;
}
case kRunSaveAsTemplatePanel: case kRunSaveAsTemplatePanel:
if (fSaveAsTemplatePanel) if (fSaveAsTemplatePanel != NULL)
fSaveAsTemplatePanel->Show(); fSaveAsTemplatePanel->Show();
else { else {
BMessenger panel(BackgroundView()); BMessenger panel(BackgroundView());
@@ -674,9 +672,10 @@ FindWindow::MessageReceived(BMessage* message)
// #pragma mark - // #pragma mark -
FindPanel::FindPanel(BFile* node, FindWindow* parent, FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate,
bool , bool editTemplateOnly) bool editTemplateOnly)
: BView("MainView", B_WILL_DRAW), :
BView("MainView", B_WILL_DRAW),
fMode(kByNameItem), fMode(kByNameItem),
fAttrGrid(NULL), fAttrGrid(NULL),
fDraggableIcon(NULL) fDraggableIcon(NULL)
@@ -716,7 +715,7 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent,
searchModeField->SetDivider(0.0f); searchModeField->SetDivider(0.0f);
// add popup for volume list // add popup for volume list
fVolMenu = new BPopUpMenu("", false, false); // don't radioMode fVolMenu = new BPopUpMenu("", false, false);
BMenuField* volumeField = new BMenuField("", B_TRANSLATE("On"), fVolMenu); BMenuField* volumeField = new BMenuField("", B_TRANSLATE("On"), fVolMenu);
volumeField->SetDivider(volumeField->StringWidth(volumeField->Label()) + 8); volumeField->SetDivider(volumeField->StringWidth(volumeField->Label()) + 8);
AddVolumes(fVolMenu); AddVolumes(fVolMenu);
@@ -738,7 +737,8 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent,
B_LARGE_ICON); B_LARGE_ICON);
fDraggableIcon = new DraggableQueryIcon(draggableRect, fDraggableIcon = new DraggableQueryIcon(draggableRect,
"saveHere", &dragNDropMessage, self, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); "saveHere", &dragNDropMessage, self, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fDraggableIcon->SetExplicitMaxSize(BSize(draggableRect.right - draggableRect.left, fDraggableIcon->SetExplicitMaxSize(
BSize(draggableRect.right - draggableRect.left,
draggableRect.bottom - draggableRect.top)); draggableRect.bottom - draggableRect.top));
} }
@@ -766,7 +766,8 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent,
fLatch->SetLabels(B_TRANSLATE("Fewer options"), B_TRANSLATE("More options")); fLatch->SetLabels(B_TRANSLATE("Fewer options"), B_TRANSLATE("More options"));
fLatch->SetValue(0); fLatch->SetValue(0);
fLatch->SetMessage(new BMessage(kLatchChanged)); fLatch->SetMessage(new BMessage(kLatchChanged));
fLatch->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); fLatch->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_CENTER));
fMoreOptions->Hide(); fMoreOptions->Hide();
// add Search button // add Search button
@@ -786,14 +787,16 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent,
icon->SetExplicitMaxSize(BSize(0, 0)); icon->SetExplicitMaxSize(BSize(0, 0));
} }
BView* mimeTypeFieldSpacer = new BBox("MimeTypeMenuSpacer", B_WILL_DRAW, B_NO_BORDER); BView* mimeTypeFieldSpacer = new BBox("MimeTypeMenuSpacer", B_WILL_DRAW,
B_NO_BORDER);
mimeTypeFieldSpacer->SetExplicitMaxSize(BSize(0, 0)); mimeTypeFieldSpacer->SetExplicitMaxSize(BSize(0, 0));
BBox* queryControls = new BBox("Box"); BBox* queryControls = new BBox("Box");
queryControls->SetBorder(B_NO_BORDER); queryControls->SetBorder(B_NO_BORDER);
BBox* queryBox = new BBox("Outer Controls"); BBox* queryBox = new BBox("Outer Controls");
BMenuField* recentQueriesMenuField = new BMenuField("RecentQueries", NULL, fRecentQueries); BMenuField* recentQueriesMenuField = new BMenuField("RecentQueries", NULL,
fRecentQueries);
queryBox->SetLabel(recentQueriesMenuField); queryBox->SetLabel(recentQueriesMenuField);
BGroupView* queryBoxView = new BGroupView(B_VERTICAL, 10.0); BGroupView* queryBoxView = new BGroupView(B_VERTICAL, 10.0);
@@ -862,7 +865,7 @@ FindPanel::AttachedToWindow()
// try to pick a good focus if we restore to one already // try to pick a good focus if we restore to one already
BTextControl* textControl BTextControl* textControl
= dynamic_cast<BTextControl*>(FindView("TextControl")); = dynamic_cast<BTextControl*>(FindView("TextControl"));
if (!textControl) { if (textControl == NULL) {
// pick the last text control in the attribute view // pick the last text control in the attribute view
BString title("TextEntry"); BString title("TextEntry");
title << (fAttrGrid->CountRows() - 1); title << (fAttrGrid->CountRows() - 1);
@@ -956,7 +959,7 @@ PopUpMenuSetTitle(BMenu* menu, const char* title)
ASSERT(bar); ASSERT(bar);
ASSERT(bar->ItemAt(0)); ASSERT(bar->ItemAt(0));
if (!bar || !bar->ItemAt(0)) if (bar == NULL || !bar->ItemAt(0))
return; return;
bar->ItemAt(0)->SetLabel(title); bar->ItemAt(0)->SetLabel(title);
@@ -1012,11 +1015,11 @@ FindPanel::Draw(BRect)
BMenuField* menuField BMenuField* menuField
= dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)); = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index));
if (!menuField) if (menuField == NULL)
return; return;
BMenuItem* item = menuField->Menu()->FindMarked(); BMenuItem* item = menuField->Menu()->FindMarked();
if (!item) if (item == NULL)
return; return;
if (item->Submenu()->FindMarked()) { if (item->Submenu()->FindMarked()) {
@@ -1288,16 +1291,16 @@ FindPanel::BuildAttrQuery(BQuery* query, bool &dynamicDate) const
BTextControl* textControl = dynamic_cast<BTextControl*> BTextControl* textControl = dynamic_cast<BTextControl*>
(FindAttrView(title, index)); (FindAttrView(title, index));
if (!textControl) if (textControl == NULL)
return; return;
BMenuField* menuField BMenuField* menuField
= dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)); = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index));
if (!menuField) if (menuField == NULL)
return; return;
BMenuItem* item = menuField->Menu()->FindMarked(); BMenuItem* item = menuField->Menu()->FindMarked();
if (!item) if (item == NULL)
continue; continue;
BMessage* message = item->Message(); BMessage* message = item->Message();
@@ -1596,9 +1599,9 @@ FindPanel::CurrentMimeType(const char** type) const
} }
} }
if (type && item != NULL) { if (type != NULL && item != NULL) {
BMessage* message = item->Message(); BMessage* message = item->Message();
if (!message) if (message == NULL)
return NULL; return NULL;
if (message->FindString("mimetype", type) != B_OK) if (message->FindString("mimetype", type) != B_OK)
@@ -1631,7 +1634,7 @@ FindPanel::SetCurrentMimeType(BMenuItem* item)
for (int32 i = 2; (search = MimeTypeMenu()->ItemAt(i)) != NULL; i++) { for (int32 i = 2; (search = MimeTypeMenu()->ItemAt(i)) != NULL; i++) {
if (item == search || !search->Label()) if (item == search || !search->Label())
continue; continue;
if (!strcmp(item->Label(),search->Label())) { if (strcmp(item->Label(),search->Label()) == 0) {
search->SetMarked(true); search->SetMarked(true);
break; break;
} }
@@ -1639,7 +1642,7 @@ FindPanel::SetCurrentMimeType(BMenuItem* item)
if (submenu) { if (submenu) {
for (int32 j = submenu->CountItems();j-- > 0;) { for (int32 j = submenu->CountItems();j-- > 0;) {
BMenuItem* sub = submenu->ItemAt(j); BMenuItem* sub = submenu->ItemAt(j);
if (!strcmp(item->Label(),sub->Label())) { if (strcmp(item->Label(),sub->Label()) == 0) {
sub->SetMarked(true); sub->SetMarked(true);
break; break;
} }
@@ -1676,14 +1679,14 @@ FindPanel::SetCurrentMimeType(const char* label)
for (int32 subIndex = submenu->CountItems(); subIndex-- > 0;) { for (int32 subIndex = submenu->CountItems(); subIndex-- > 0;) {
BMenuItem* subItem = submenu->ItemAt(subIndex); BMenuItem* subItem = submenu->ItemAt(subIndex);
if (subItem->Label() != NULL if (subItem->Label() != NULL
&& !strcmp(label, subItem->Label())) { && strcmp(label, subItem->Label()) == 0) {
subItem->SetMarked(true); subItem->SetMarked(true);
found = true; found = true;
} }
} }
} }
if (item->Label() != NULL && !strcmp(label, item->Label())) { if (item->Label() != NULL && strcmp(label, item->Label()) == 0) {
item->SetMarked(true); item->SetMarked(true);
return B_OK; return B_OK;
} }
@@ -1885,7 +1888,6 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem,
while (roster.GetNextVolume(&volume) == B_OK) { while (roster.GetNextVolume(&volume) == B_OK) {
if (volume.IsPersistent() && volume.KnowsQuery() if (volume.IsPersistent() && volume.KnowsQuery()
&& volume.KnowsAttr()) { && volume.KnowsAttr()) {
BQuery query; BQuery query;
query.SetVolume(&volume); query.SetVolume(&volume);
query.SetPredicate("_trk/recentQuery == 1"); query.SetPredicate("_trk/recentQuery == 1");
@@ -1912,7 +1914,6 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem,
recentQueries.AddItem(new EntryWithDate(ref, changeTime)); recentQueries.AddItem(new EntryWithDate(ref, changeTime));
} }
} }
} }
} }
@@ -2052,7 +2053,7 @@ FindPanel::RemoveAttrRow()
uint32 uint32
FindPanel::InitialMode(const BNode* node) FindPanel::InitialMode(const BNode* node)
{ {
if (!node || node->InitCheck() != B_OK) if (node == NULL || node->InitCheck() != B_OK)
return kByNameItem; return kByNameItem;
uint32 result; uint32 result;
@@ -2067,7 +2068,7 @@ FindPanel::InitialMode(const BNode* node)
int32 int32
FindPanel::InitialAttrCount(const BNode* node) FindPanel::InitialAttrCount(const BNode* node)
{ {
if (!node || node->InitCheck() != B_OK) if (node == NULL || node->InitCheck() != B_OK)
return 1; return 1;
int32 result; int32 result;
@@ -2184,8 +2185,10 @@ FindPanel::SwitchToTemplate(const BNode* node)
void void
FindPanel::RestoreMimeTypeMenuSelection(const BNode* node) FindPanel::RestoreMimeTypeMenuSelection(const BNode* node)
{ {
if (Mode() == (int32)kByFormulaItem || node == NULL || node->InitCheck() != B_OK) if (Mode() == (int32)kByFormulaItem || node == NULL
|| node->InitCheck() != B_OK) {
return; return;
}
BString buffer; BString buffer;
if (node->ReadAttrString(kAttrQueryInitialMime, &buffer) == B_OK) if (node->ReadAttrString(kAttrQueryInitialMime, &buffer) == B_OK)
@@ -2197,7 +2200,7 @@ void
FindPanel::RestoreWindowState(const BNode* node) FindPanel::RestoreWindowState(const BNode* node)
{ {
fMode = InitialMode(node); fMode = InitialMode(node);
if (!node || node->InitCheck() != B_OK) if (node == NULL || node->InitCheck() != B_OK)
return; return;
ShowOrHideMimeTypeMenu(); ShowOrHideMimeTypeMenu();
@@ -3108,7 +3111,7 @@ MostUsedNames::~MostUsedNames()
bool bool
MostUsedNames::ObtainList(BList* list) MostUsedNames::ObtainList(BList* list)
{ {
if (!list) if (list == NULL)
return false; return false;
if (!fLoaded) if (!fLoaded)
@@ -3163,9 +3166,8 @@ MostUsedNames::AddName(const char* name)
if (entry == NULL) { if (entry == NULL) {
for (int32 i = 0; for (int32 i = 0;
(entry = static_cast<list_entry*>(fList.ItemAt(i))) != NULL; (entry = static_cast<list_entry*>(fList.ItemAt(i))) != NULL; i++) {
i++) { if (strcmp(entry->name, name) == 0)
if (!strcmp(entry->name, name))
break; break;
} }
} }