Commit 04ea51de authored by Arnaud Fontaine's avatar Arnaud Fontaine

erp5_code_mirror: Add support for alternative keymaps (Emacs and Vim).

This can be chosen through Preference => "User Interface" tab. CodeMirror
default keymap is used by default as until now.
parent 11f238c2
...@@ -38,6 +38,13 @@ ...@@ -38,6 +38,13 @@
<script type="text/javascript" src="&dtml-portal_url;/diff_match_patch/javascript/diff_match_patch_uncompressed.js"></script> <script type="text/javascript" src="&dtml-portal_url;/diff_match_patch/javascript/diff_match_patch_uncompressed.js"></script>
<script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/merge/merge.js"></script> <script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/merge/merge.js"></script>
<!-- Keymaps -->
<dtml-if expr="keymap == 'emacs'">
<script type="text/javascript" src="&dtml-portal_url;/codemirror/keymap/emacs.js"></script>
<dtml-elif expr="keymap == 'vim'">
<script type="text/javascript" src="&dtml-portal_url;/codemirror/keymap/vim.js"></script>
</dtml-if>
<!-- Linter --> <!-- Linter -->
<link rel="stylesheet" href="&dtml-portal_url;/codemirror/addon/lint/lint.css"> <link rel="stylesheet" href="&dtml-portal_url;/codemirror/addon/lint/lint.css">
<script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/lint/lint.js"></script> <script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/lint/lint.js"></script>
...@@ -484,6 +491,7 @@ ...@@ -484,6 +491,7 @@
var cm = CodeMirror.fromTextArea( var cm = CodeMirror.fromTextArea(
getTextareaField()[0], getTextareaField()[0],
{mode: mode, {mode: mode,
keyMap: "&dtml-keymap;",
lineNumbers: true, lineNumbers: true,
styleActiveLine: true, styleActiveLine: true,
showTrailingSpace: true, showTrailingSpace: true,
......
editor_list = [("Default", "default")]
if context.getPreferredSourceCodeEditor() == 'codemirror':
editor_list.extend([("Emacs", "emacs"), ("Vim", "vim")])
return editor_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Preference_getAvailableSourceCodeEditorKeymapList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
<list> <list>
<string>my_preferred_text_editor</string> <string>my_preferred_text_editor</string>
<string>my_preferred_source_code_editor</string> <string>my_preferred_source_code_editor</string>
<string>my_preferred_source_code_editor_keymap</string>
<string>my_preferred_text_format</string> <string>my_preferred_text_format</string>
</list> </list>
</value> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="RadioField" module="Products.Formulator.StandardFields"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_preferred_source_code_editor_keymap</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
<item>
<key> <string>unknown_selection</string> </key>
<value> <string>You selected an item that was not in the list.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>first_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>orientation</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>first_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>orientation</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>The source code editor keymap used by default</string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>first_item</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list>
<tuple>
<string>Default</string>
<string>default</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>orientation</string> </key>
<value> <string>horizontal</string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Source Code Editor Keymap</string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>here/Preference_getAvailableSourceCodeEditorKeymapList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/selection</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Preferred Source Code Editor Keymap</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>preferred_source_code_editor_keymap_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>preference</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python: \'default\'</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -112,7 +112,8 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -112,7 +112,8 @@ class EditorWidget(Widget.TextAreaWidget):
content=value, content=value,
field_id=key, field_id=key,
portal_url=site_root.absolute_url(), portal_url=site_root.absolute_url(),
mode=mode) mode=mode,
keymap=site_root.portal_preferences.getPreferredSourceCodeEditorKeymap())
elif text_editor != 'text_area': elif text_editor != 'text_area':
return here.fckeditor_wysiwyg_support.pt_render( return here.fckeditor_wysiwyg_support.pt_render(
extra_context= { extra_context= {
......
...@@ -84,6 +84,7 @@ def manage_page_footer(self): ...@@ -84,6 +84,7 @@ def manage_page_footer(self):
return default return default
if editor == 'codemirror' and getattr(portal, 'code_mirror_support', None) is not None: if editor == 'codemirror' and getattr(portal, 'code_mirror_support', None) is not None:
keymap = portal.portal_preferences.getPreferredSourceCodeEditorKeymap()
return '''<script type="text/javascript" src="%s/jquery/core/jquery.min.js"></script> return '''<script type="text/javascript" src="%s/jquery/core/jquery.min.js"></script>
%s %s
</body> </body>
...@@ -91,7 +92,8 @@ def manage_page_footer(self): ...@@ -91,7 +92,8 @@ def manage_page_footer(self):
portal.code_mirror_support(textarea_selector=textarea_selector, portal.code_mirror_support(textarea_selector=textarea_selector,
portal_url=portal_url, portal_url=portal_url,
bound_names=bound_names, bound_names=bound_names,
mode=mode)) mode=mode,
keymap=keymap))
else: else:
return ''' return '''
<script type="text/javascript" src="%(portal_url)s/jquery/core/jquery.min.js"></script> <script type="text/javascript" src="%(portal_url)s/jquery/core/jquery.min.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment