Example #1
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();
}
Example #2
0
void
GrepWindow::_OnCopyText()
{
	bool onlyCopySelection = true;

	if (fSearchResults->CurrentSelection() < 0)
		onlyCopySelection = false;

	BString buffer;

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

		if (onlyCopySelection) {
			if (item->IsSelected())
				buffer << item->Text() << "\n";
		} else
			buffer << item->Text() << "\n";
	}

	status_t status = B_OK;

	BMessage* clip = NULL;

	if (be_clipboard->Lock()) {
		be_clipboard->Clear();

		clip = be_clipboard->Data();

		clip->AddData("text/plain", B_MIME_TYPE, buffer.String(),
			buffer.Length());

		status = be_clipboard->Commit();

		if (status != B_OK) {
			be_clipboard->Unlock();
			return;
		}

		be_clipboard->Unlock();
	}
}
void
ProjectSettingsWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case M_SHOW_ADD_PATH:
		{
			fFilePanel->Show();
			break;
		}

		case M_DROP_PATH:
		{
			BString path;
			if (message->FindString("path",&path) == B_OK)
				fProject->AddLocalInclude(path.String());
			break;
		}

		case M_ADD_PATH:
		{
			entry_ref ref;
			int32 i = 0;
			while (message->FindRef("refs", i++, &ref) == B_OK) {
				fDirty = true;
				AddInclude(ref);
			}
			break;
		}

		case M_REMOVE_PATH:
		{
			int32 selection = fIncludeList->CurrentSelection();
			if (selection < 0)
				break;
			
			fDirty = true;
			
			for (int32 i = fIncludeList->CountItems() - 1; i >= 0; i--) {
				BStringItem* item = (BStringItem*)fIncludeList->ItemAt(i);
				if (item->IsSelected()) {
					fIncludeList->RemoveItem(item);
					fProject->RemoveLocalInclude(item->Text());
					delete item;
				}
			}
			break;
		}

		case M_TARGET_NAME_CHANGED:
		{
			if (fTargetText->Text() && strlen(fTargetText->Text()) > 0)
				fProject->SetTargetName(fTargetText->Text());

			fDirty = true;
		}

		case M_TOGGLE_DEBUG:
		{
			if (fDebugBox->Value() == B_CONTROL_ON) {
				fProject->SetDebug(true);
				fOpField->SetEnabled(false);
				fOpSizeBox->SetEnabled(false);
			} else {
				fProject->SetDebug(false);
				fOpField->SetEnabled(true);
				fOpSizeBox->SetEnabled(true);
			}
			fDirty = true;
			break;
		}

		case M_TOGGLE_PROFILE:
		{
			if (fProfileBox->Value() == B_CONTROL_ON)
				fProject->SetProfiling(true);
			else
				fProject->SetProfiling(false);

			fDirty = true;
			break;
		}

		case M_TOGGLE_OPSIZE:
		{
			if (fOpSizeBox->Value() == B_CONTROL_ON)
				fProject->SetOpForSize(true);
			else
				fProject->SetOpForSize(false);

			fDirty = true;
			break;
		}

		case M_SET_OP_VALUE:
		{
			BMenuItem *item = fOpField->Menu()->FindMarked();
			if (item)
				fProject->SetOpLevel(fOpField->Menu()->IndexOf(item));

			fDirty = true;
			break;
		}

		case M_SET_TARGET_TYPE:
		{
			BMenuItem *item = fTypeField->Menu()->FindMarked();
			if (item)
				fProject->SetTargetType(fTypeField->Menu()->IndexOf(item));

			fDirty = true;
			break;
		}

		case M_CCOPTS_CHANGED:
		{
			fProject->SetExtraCompilerOptions(fCompileText->Text());
			fDirty = true;
			break;
		}

		case M_LDOPTS_CHANGED:
		{
			fProject->SetExtraLinkerOptions(fLinkText->Text());
			fDirty = true;
			break;
		}

		default:
			BWindow::MessageReceived(message);
	}
}
Example #4
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));
}