//..............................................................................
//
// Ninja document model: plugins (sessions and protocols)
//

import "doc_PluginHost.jnc"
import "doc_Storage.jnc"

namespace doc {

//! \addtogroup api-doc
//! @{

//..............................................................................

class Plugin
{
	PluginHost* readonly m_pluginHost;

	property m_logWriter
	{
		log.Writer* get()
		{
			return m_pluginHost.m_log.m_writer;
		}
	}

	construct(PluginHost* host)
	{
		m_pluginHost = host;
	}

	virtual void load(Storage* storage)
	{
	}

	virtual void save(Storage* storage)
	{
	}

	virtual void updateProperties()
	{
	}

	virtual bool errorcode applyProperties()
	{
		return true;
	}

	virtual void restoreDefaultProperties()
	{
	}

	abstract size_t errorcode transmit(
		void const* p,
		size_t size
		);

	ui.Action* createAction(
		char const* text,
		ui.Icon* icon = null,
		bool isCheckable = false,
		bool isChecked = false
		);

	ui.Action* createAction(
		char const* text,
		char const* iconFileName,
		bool isCheckable = false,
		bool isChecked = false
		)
	{
		return createAction(text, new ui.Icon(iconFileName), isCheckable, isChecked);
	}
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ui.Action* Plugin.createAction(
	char const* text,
	ui.Icon* icon,
	bool isCheckable,
	bool isChecked
	)
{
	ui.Action* action = new ui.Action(text, icon);
	action.m_isCheckable = isCheckable;
	if (isCheckable)
		action.m_isChecked = isChecked;

	m_pluginHost.m_menu.addAction(action);
	m_pluginHost.m_toolBar.addAction(action);
	return action;
}

//..............................................................................

// @}

} // namespace doc
