//..............................................................................
//
// Ninja document model - plugins (sessions, layers, log filters)
//

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

namespace doc {

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

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

class PluginConfig {
	virtual void load(Storage* storage) {}
	virtual void save(Storage* storage) {}
	virtual void updateProperties() {}

	virtual bool errorcode applyProperties() {
		return true;
	}

	virtual void restoreDefaultProperties() {}
}

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

class Plugin: PluginConfig {
	PluginHost* readonly m_pluginHost;

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

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

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

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

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

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

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

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

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

// log filters, while not quite full plugins, also need UI and serialization

class LogFilter: PluginConfig {
	// construct(PluginHost* host) {}
}

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

// @}

} // namespace doc
