2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace Backend\FormWidgets;
|
|
|
|
|
2014-07-01 17:17:53 +10:00
|
|
|
use Backend\Models\EditorPreferences;
|
2014-05-14 23:24:20 +10:00
|
|
|
use Backend\Classes\FormWidgetBase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code Editor
|
|
|
|
* Renders a code editor field.
|
|
|
|
*
|
|
|
|
* @package october\backend
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
class CodeEditor extends FormWidgetBase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2015-02-28 12:43:53 +11:00
|
|
|
protected $defaultAlias = 'codeeditor';
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string Code language to display (php, twig)
|
|
|
|
*/
|
|
|
|
public $language = 'php';
|
|
|
|
|
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var boolean Determines whether the gutter is visible.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
public $showGutter = true;
|
|
|
|
|
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var boolean Indicates whether the the word wrapping is enabled.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
2014-06-12 18:29:12 +10:00
|
|
|
public $wordWrap = true;
|
2014-05-14 23:24:20 +10:00
|
|
|
|
2014-06-10 19:30:06 +10:00
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var string Cold folding mode: manual, markbegin, markbeginend.
|
|
|
|
*/
|
|
|
|
public $codeFolding = 'manual';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var boolean Automatically close tags and special characters,
|
|
|
|
* like quotation marks, parenthesis, or brackets.
|
|
|
|
*/
|
|
|
|
public $autoClosing = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var boolean Indicates whether the the editor uses spaces for indentation.
|
2014-06-10 19:30:06 +10:00
|
|
|
*/
|
|
|
|
public $useSoftTabs = true;
|
|
|
|
|
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var boolean Sets the size of the indentation.
|
2014-06-10 19:30:06 +10:00
|
|
|
*/
|
|
|
|
public $tabSize = 4;
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var integer Sets the font size.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
public $fontSize = 12;
|
|
|
|
|
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var integer Sets the editor margin size.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
public $margin = 10;
|
|
|
|
|
|
|
|
/**
|
2015-02-14 19:50:12 +11:00
|
|
|
* @var $theme Ace Editor theme to use.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
public $theme = 'twilight';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2014-06-10 19:30:06 +10:00
|
|
|
// Load the editor system settings
|
2014-07-01 17:17:53 +10:00
|
|
|
$editorSettings = EditorPreferences::instance();
|
2014-06-10 19:30:06 +10:00
|
|
|
|
|
|
|
$this->fontSize = $this->getConfig('fontSize', $editorSettings->font_size);
|
2014-06-12 18:29:12 +10:00
|
|
|
$this->wordWrap = $this->getConfig('wordWrap', $editorSettings->word_wrap);
|
|
|
|
$this->codeFolding = $this->getConfig('codeFolding', $editorSettings->code_folding);
|
2015-02-14 19:50:12 +11:00
|
|
|
$this->autoClosing = $this->getConfig('autoClosing', $editorSettings->auto_closing);
|
2014-06-10 19:30:06 +10:00
|
|
|
$this->tabSize = $this->getConfig('tabSize', $editorSettings->tab_size);
|
2014-06-12 18:29:12 +10:00
|
|
|
$this->theme = $this->getConfig('theme', $editorSettings->theme);
|
|
|
|
$this->showInvisibles = $this->getConfig('showInvisibles', $editorSettings->show_invisibles);
|
|
|
|
$this->highlightActiveLine = $this->getConfig('highlightActiveLine', $editorSettings->highlight_active_line);
|
2014-06-10 19:30:06 +10:00
|
|
|
$this->useSoftTabs = $this->getConfig('useSoftTabs', !$editorSettings->use_hard_tabs);
|
2014-06-12 18:29:12 +10:00
|
|
|
$this->showGutter = $this->getConfig('showGutter', $editorSettings->show_gutter);
|
|
|
|
$this->language = $this->getConfig('language', 'php');
|
2014-05-14 23:24:20 +10:00
|
|
|
$this->margin = $this->getConfig('margin', 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$this->prepareVars();
|
|
|
|
return $this->makePartial('codeeditor');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-10-16 20:47:23 -07:00
|
|
|
* Prepares the widget data
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
public function prepareVars()
|
|
|
|
{
|
|
|
|
$this->vars['fontSize'] = $this->fontSize;
|
2014-06-12 18:29:12 +10:00
|
|
|
$this->vars['wordWrap'] = $this->wordWrap;
|
|
|
|
$this->vars['codeFolding'] = $this->codeFolding;
|
2015-02-14 19:50:12 +11:00
|
|
|
$this->vars['autoClosing'] = $this->autoClosing;
|
2014-06-10 19:30:06 +10:00
|
|
|
$this->vars['tabSize'] = $this->tabSize;
|
2014-05-14 23:24:20 +10:00
|
|
|
$this->vars['theme'] = $this->theme;
|
2014-06-12 18:29:12 +10:00
|
|
|
$this->vars['showInvisibles'] = $this->showInvisibles;
|
|
|
|
$this->vars['highlightActiveLine'] = $this->highlightActiveLine;
|
|
|
|
$this->vars['useSoftTabs'] = $this->useSoftTabs;
|
|
|
|
$this->vars['showGutter'] = $this->showGutter;
|
|
|
|
$this->vars['language'] = $this->language;
|
|
|
|
$this->vars['margin'] = $this->margin;
|
|
|
|
$this->vars['stretch'] = $this->formField->stretch;
|
|
|
|
$this->vars['size'] = $this->formField->size;
|
2014-05-14 23:24:20 +10:00
|
|
|
$this->vars['name'] = $this->formField->getName();
|
2015-02-28 10:38:04 +11:00
|
|
|
|
|
|
|
// Double encode when escaping
|
|
|
|
$this->vars['value'] = htmlentities($this->getLoadValue(), ENT_QUOTES, 'UTF-8', true);
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function loadAssets()
|
|
|
|
{
|
2014-05-24 16:57:38 +10:00
|
|
|
$this->addCss('css/codeeditor.css', 'core');
|
2015-02-18 20:54:36 +01:00
|
|
|
$this->addJs('vendor/emmet/emmet.js', 'core');
|
2014-05-24 16:57:38 +10:00
|
|
|
$this->addJs('vendor/ace/ace.js', 'core');
|
2015-02-18 20:54:36 +01:00
|
|
|
$this->addJs('vendor/ace/ext-emmet.js', 'core');
|
2014-05-24 16:57:38 +10:00
|
|
|
$this->addJs('js/codeeditor.js', 'core');
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
2014-10-10 23:50:05 +02:00
|
|
|
}
|