<?php

class MainCtrl extends Ctrl {



	public function show() {
		$v = new View();
		$v->template = 'app/Wiki.tpl';

		$html = $this->getPreview();
		$wiki = new TextArea('wikiTextArea');
		$button = new Button('genPreview');
		$button->text = 'Preview';

		$v->add($html);
		$v->add($wiki);
		$v->add($button);

		$wikiValue = $wiki->valueReader();
		$action = new Action('MainCtrl/getPreview', $wikiValue);
		$button->addListener(new ClickListener($action));
		$wiki->addListener(new KeyPressListener($action, 'Ctrl+Enter'));
		$wiki->addListener(new StopTypingListener(new Behaviour("if ($wikiValue != '') $action"), 1000)); // 1 second

		return $v;
	}



	public function getPreview($wikiText = '') {
		$preview = new Label('htmlPreviewArea');
		if ($wikiText) {
			$translator = new WikiTranslator();
			$preview->text = $translator->mtov($wikiText);
		} else {
			$preview->text = '&nbsp;';
		}
		return $preview;
	}



} // class MainCtrl

?>