Author: stpere Date: 2011-03-06 15:14:37 +0100 (Sun, 06 Mar 2011) New Revision: 40843 Changeset: http://dev.haiku-os.org/changeset/40843 Modified: haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp Log: Screenshot * Fix violations to coding guidelines * Error checks on the received entry_refs * Typo in comment Thanks Axel! Modified: haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp 2011-03-06 13:31:56 UTC (rev 40842) +++ haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp 2011-03-06 14:14:37 UTC (rev 40843) @@ -332,10 +332,14 @@ entry_ref ref; if (message->FindRef("refs", &ref) == B_OK) { BEntry entry(&ref, true); - BPath path; - entry.GetPath(&path); - BString label(path.Path()); - _AddItemToPathMenu(path.Path(), label, 3, true); + if (entry.InitCheck() == B_OK) { + BPath path; + // Could return B_BUSY + if (entry.GetPath(&path) == B_OK) { + BString label(path.Path()); + _AddItemToPathMenu(path.Path(), label, 3, true); + } + } } break; } @@ -514,21 +518,20 @@ ScreenshotWindow::_AddItemToPathMenu(const char* path, BString& label, int32 index, bool markItem) { - /* Make sure that item won't be a duplicata of an existing one */ - for (int32 i = fOutputPathMenu->CountItems(); i > 0; --i) { - BMenuItem* menuItem = fOutputPathMenu->ItemAt(i - 1); + // Make sure that item won't be a duplicate of an existing one + for (int32 i = fOutputPathMenu->CountItems() - 1; i >= 0; --i) { + BMenuItem* menuItem = fOutputPathMenu->ItemAt(i); BMessage* message = menuItem->Message(); const char* pathFromItem; - if (message != NULL && message->what == kLocationChanged) { - if (message->FindString("path", &pathFromItem) == B_OK) { - if (!strcmp(path, pathFromItem)) { - if (markItem) { - fOutputPathMenu->ItemAt(i - 1)->SetMarked(true); - fLastSelectedPath = fOutputPathMenu->ItemAt(i - 1); - } - return; - } + if (message != NULL && message->what == kLocationChanged + && message->FindString("path", &pathFromItem) == B_OK + && !strcmp(path, pathFromItem)) { + + if (markItem) { + fOutputPathMenu->ItemAt(i)->SetMarked(true); + fLastSelectedPath = fOutputPathMenu->ItemAt(i); } + return; } }