Esempio n. 1
0
// Sets the context to be debugged.
bool Plugin::SetContext(Core::Context* context)
{
	// Remove the debug hook from the old context.
	if (debug_context != NULL &&
		hook_element != NULL)
	{
		debug_context->UnloadDocument(hook_element);
		hook_element->RemoveReference();
		hook_element = NULL;
	}

	// Add the debug hook into the new context.
	if (context != NULL)
	{
		Core::ElementDocument* element = context->CreateDocument("debug-hook");
		if (element == NULL)
			return false;

		hook_element = dynamic_cast< ElementContextHook* >(element);
		if (hook_element == NULL)
		{
			element->RemoveReference();
			context->UnloadDocument(element);
			return false;
		}

		hook_element->Initialise(this);
	}

	// Attach the info element to the new context.
	if (info_element != NULL)
	{
		if (debug_context != NULL)
		{
			debug_context->RemoveEventListener("click", info_element, true);
			debug_context->RemoveEventListener("mouseover", info_element, true);
		}

		if (context != NULL)
		{
			context->AddEventListener("click", info_element, true);
			context->AddEventListener("mouseover", info_element, true);
		}

		info_element->Reset();
	}

	debug_context = context;
	return true;
}