Ejemplo n.º 1
0
status_t perform_edit(MTextAddOn *addon)
{
	status_t result = B_OK;
	entry_ref headerFile;
	BPoint where(0,0);

	if (addon->Window() && addon->Window()->Lock())
	{
		uint32 buttons;
		addon->Window()->ChildAt(0)->GetMouse(&where, &buttons);
		addon->Window()->ChildAt(0)->ConvertToScreen(&where);
		addon->Window()->Unlock();
		where += BPoint(-3,-3);
	}

	result = addon->GetRef(headerFile);
	BString fileName;
	if (result >= B_OK)
		fileName = headerFile.name;

	CLanguageInterface *languageInterface = NULL;
	if (addon->Window())
	{
		PDoc *doc = dynamic_cast<PDoc *>(addon->Window());
		if (doc && doc->TextView())
		{
			int lang = doc->TextView()->Language();
			if (lang > -1)
				languageInterface = CLanguageInterface::FindIntf(lang);
		}
	}

	BString header;
	result = RunPopUpMenu(where, header, fileName, languageInterface);
	//printf("result %s\n", strerror(result));
	if (result == B_CANCELED)
		return B_OK;
	if (result < B_OK)
		return result;

#if 0
	// Do not change the case if a shift key was pressed
	if ((modifiers() & B_SHIFT_KEY) == 0)
		fileName.ToUpper();
#endif

	addon->Select(0, 0);

	addon->Insert(header.String());
	
	return result;
}
Ejemplo n.º 2
0
void PApp::RefsReceived(BMessage	*inMessage)
{
	try
	{
		unsigned long type;
		long count;

		inMessage->GetInfo("refs", &type, &count);

		for (int i = 0; i < count; i++)
		{
			entry_ref doc;
			FailOSErr (inMessage->FindRef("refs", i, &doc));
			PDoc *d = dynamic_cast<PDoc*>(OpenWindow(doc));
			if (!d) continue;
			
			if (inMessage->HasData(kTokenIdentifier, kTokenIDType))
			{
				TokenIdentifier *ident;
				ssize_t size;

				FailOSErr(inMessage->FindData(kTokenIdentifier, kTokenIDType, (const void**)&ident, &size));

				BMessage msg(msg_SelectError);
				FailOSErr(msg.AddInt32("start", ident->eOffset));
				FailOSErr(msg.AddInt32("length", ident->eLength));

				BMessenger msgr(d->TextView());
				FailOSErr(msgr.SendMessage(&msg));
			}
			else if (inMessage->HasInt32("be:selection_offset"))
			{
				int32 offset, length;

				FailOSErr(inMessage->FindInt32("be:selection_offset", &offset));
				FailOSErr(inMessage->FindInt32("be:selection_length", &length));

				BMessage msg(msg_Select);
				FailOSErr(msg.AddInt32("anchor", offset));
				FailOSErr(msg.AddInt32("caret", offset + length));

				BMessenger msgr(d->TextView());
				FailOSErr(msgr.SendMessage(&msg));
			}
			else if (inMessage->HasInt32("be:line"))
			{
				int32 line;

				FailOSErr(inMessage->FindInt32("be:line", &line));

				BMessage msg(msg_SelectLines);
				FailOSErr(msg.AddInt32("from", line));
				FailOSErr(msg.AddInt32("to", line - 1));

				BMessenger msgr(d->TextView());
				FailOSErr(msgr.SendMessage(&msg));
			}
		}
	}
	catch (HErr& e)
	{
		e.DoError();
	}
} /* PApp::RefsReceived */