Commit 90c7c7aa 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 053e3966
......@@ -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;/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 -->
<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>
......@@ -484,6 +491,7 @@
var cm = CodeMirror.fromTextArea(
getTextareaField()[0],
{mode: mode,
keyMap: "&dtml-keymap;",
lineNumbers: true,
styleActiveLine: 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 @@
<list>
<string>my_preferred_text_editor</string>
<string>my_preferred_source_code_editor</string>
<string>my_preferred_source_code_editor_keymap</string>
<string>my_preferred_text_format</string>
</list>
</value>
......
<?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>
......@@ -114,7 +114,8 @@ class EditorWidget(Widget.TextAreaWidget):
content=value,
field_id=key,
portal_url=site_root.absolute_url(),
mode=mode)
mode=mode,
keymap=site_root.portal_preferences.getPreferredSourceCodeEditorKeymap())
elif text_editor != 'text_area':
return here.fckeditor_wysiwyg_support.pt_render(
extra_context= {
......
......@@ -84,6 +84,7 @@ def manage_page_footer(self):
return default
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>
%s
</body>
......@@ -91,7 +92,8 @@ def manage_page_footer(self):
portal.code_mirror_support(textarea_selector=textarea_selector,
portal_url=portal_url,
bound_names=bound_names,
mode=mode))
mode=mode,
keymap=keymap))
else:
return '''
<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