Ejemplo n.º 1
0
BStringItem*
CookieWindow::_AddDomain(BString domain, bool fake)
{
	BStringItem* parent = NULL;
	int firstDot = domain.FindFirst('.');
	if (firstDot >= 0) {
		BString parentDomain(domain);
		parentDomain.Remove(0, firstDot + 1);
		parent = _AddDomain(parentDomain, true);
	} else {
		parent = (BStringItem*)fDomains->FullListItemAt(0);
	}

	BListItem* existing;
	int i = 0;
	// check that we aren't already there
	while ((existing = fDomains->ItemUnderAt(parent, true, i++)) != NULL) {
		DomainItem* stringItem = (DomainItem*)existing;
		if (stringItem->Text() == domain) {
			if (fake == false)
				stringItem->fEmpty = false;
			return stringItem;
		}
	}

#if 0
	puts("==============================");
	for (i = 0; i < fDomains->FullListCountItems(); i++) {
		BStringItem* t = (BStringItem*)fDomains->FullListItemAt(i);
		for (unsigned j = 0; j < t->OutlineLevel(); j++)
			printf("  ");
		printf("%s\n", t->Text());
	}
#endif

	// Insert the new item, keeping the list alphabetically sorted
	BStringItem* domainItem = new DomainItem(domain, fake);
	domainItem->SetOutlineLevel(parent->OutlineLevel() + 1);
	BStringItem* sibling = NULL;
	int siblingCount = fDomains->CountItemsUnder(parent, true);
	for (i = 0; i < siblingCount; i++) {
		sibling = (BStringItem*)fDomains->ItemUnderAt(parent, true, i);
		if (strcmp(sibling->Text(), domainItem->Text()) > 0) {
			fDomains->AddItem(domainItem, fDomains->FullListIndexOf(sibling));
			return domainItem;
		}
	}

	if (sibling) {
		// There were siblings, but all smaller than what we try to insert.
		// Insert after the last one (and its subitems)
		fDomains->AddItem(domainItem, fDomains->FullListIndexOf(sibling)
			+ fDomains->CountItemsUnder(sibling, false) + 1);
	} else {
		// There were no siblings, insert right after the parent
		fDomains->AddItem(domainItem, fDomains->FullListIndexOf(parent) + 1);
	}

	return domainItem;
}
Ejemplo n.º 2
0
void
GrepWindow::_OnTrimSelection()
{
	if (fSearchResults->CurrentSelection() < 0) {
		BString text;
		text << B_TRANSLATE("Please select the files you wish to keep searching.");
		text << "\n";
		text << B_TRANSLATE("The unselected files will be removed from the list.");
		text << "\n";
		BAlert* alert = new BAlert(NULL, text.String(), B_TRANSLATE("OK"), NULL, NULL,
			B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		return;
	}

	BMessage message;
	BString path;

	for (int32 index = 0; ; index++) {
		BStringItem* item = dynamic_cast<BStringItem*>(
			fSearchResults->ItemAt(index));
		if (item == NULL)
			break;

		if (!item->IsSelected() || item->OutlineLevel() != 0)
			continue;

		if (path == item->Text())
			continue;

		path = item->Text();
		entry_ref ref;
		if (get_ref_for_path(path.String(), &ref) == B_OK)
			message.AddRef("refs", &ref);
	}

	fModel->fDirectory = entry_ref();
		// invalidated on purpose

	fModel->fSelectedFiles.MakeEmpty();
	fModel->fSelectedFiles = message;

	PostMessage(MSG_START_CANCEL);

	_SetWindowTitle();
}
Ejemplo n.º 3
0
void
GrepWindow::_OnSelectInTracker()
{
	if (fSearchResults->CurrentSelection() < 0) {
		BAlert* alert = new BAlert("Info",
			B_TRANSLATE("Please select the files you wish to have selected for you in "
				"Tracker."),
			B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		return;
	}

	BMessage message;
	BString filePath;
	BPath folderPath;
	BList folderList;
	BString lastFolderAddedToList;

	for (int32 index = 0; ; index++) {
		BStringItem* item = dynamic_cast<BStringItem*>(
			fSearchResults->ItemAt(index));
		if (item == NULL)
			break;

		// only open selected and top level (file) items
		if (!item->IsSelected() || item->OutlineLevel() > 0)
			continue;

		// check if this was previously opened
		if (filePath == item->Text())
			continue;

		filePath = item->Text();
		entry_ref file_ref;
		if (get_ref_for_path(filePath.String(), &file_ref) != B_OK)
			continue;

		message.AddRef("refs", &file_ref);

		// add parent folder to list of folders to open
		folderPath.SetTo(filePath.String());
		if (folderPath.GetParent(&folderPath) == B_OK) {
			BPath* path = new BPath(folderPath);
			if (path->Path() != lastFolderAddedToList) {
				// catches some duplicates
				folderList.AddItem(path);
				lastFolderAddedToList = path->Path();
			} else
				delete path;
		}
	}

	_RemoveFolderListDuplicates(&folderList);
	_OpenFoldersInTracker(&folderList);

	int32 aShortWhile = 100000;
	snooze(aShortWhile);

	if (!_AreAllFoldersOpenInTracker(&folderList)) {
		for (int32 x = 0; x < 5; x++) {
			aShortWhile += 100000;
			snooze(aShortWhile);
			_OpenFoldersInTracker(&folderList);
		}
	}

	if (!_AreAllFoldersOpenInTracker(&folderList)) {
		BString str1;
		str1 << B_TRANSLATE("%APP_NAME couldn't open one or more folders.");
		str1.ReplaceFirst("%APP_NAME",APP_NAME);
		BAlert* alert = new BAlert(NULL, str1.String(), B_TRANSLATE("OK"),
			NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		goto out;
	}

	_SelectFilesInTracker(&folderList, &message);

out:
	// delete folderList contents
	int32 folderCount = folderList.CountItems();
	for (int32 x = 0; x < folderCount; x++)
		delete static_cast<BPath*>(folderList.ItemAt(x));
}