0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Add ordering on hallo plugins to ensure toolbar buttons appear in the same order as before

This commit is contained in:
Matt Westcott 2017-07-15 18:42:18 +02:00
parent a05ada6a44
commit c7f612a7fd
2 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
import json import json
from collections import OrderedDict
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.templatetags.staticfiles import static from django.contrib.staticfiles.templatetags.staticfiles import static
@ -18,6 +19,7 @@ class HalloPlugin(object):
self.options = kwargs.get('options', {}) self.options = kwargs.get('options', {})
self.js = kwargs.get('js', None) self.js = kwargs.get('js', None)
self.css = kwargs.get('css', None) self.css = kwargs.get('css', None)
self.order = kwargs.get('order', 100)
def construct_plugins_list(self, plugins): def construct_plugins_list(self, plugins):
if self.name is not None: if self.name is not None:
@ -31,6 +33,7 @@ class HalloPlugin(object):
class HalloFormatPlugin(HalloPlugin): class HalloFormatPlugin(HalloPlugin):
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs.setdefault('name', 'halloformat') kwargs.setdefault('name', 'halloformat')
kwargs.setdefault('order', 10)
self.format_name = kwargs['format_name'] self.format_name = kwargs['format_name']
super(HalloFormatPlugin, self).__init__(**kwargs) super(HalloFormatPlugin, self).__init__(**kwargs)
@ -44,6 +47,7 @@ class HalloFormatPlugin(HalloPlugin):
class HalloHeadingPlugin(HalloPlugin): class HalloHeadingPlugin(HalloPlugin):
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs.setdefault('name', 'halloheadings') kwargs.setdefault('name', 'halloheadings')
kwargs.setdefault('order', 20)
self.element = kwargs.pop('element') self.element = kwargs.pop('element')
super(HalloHeadingPlugin, self).__init__(**kwargs) super(HalloHeadingPlugin, self).__init__(**kwargs)
@ -54,7 +58,7 @@ class HalloHeadingPlugin(HalloPlugin):
# Plugins which are always imported, and cannot be enabled/disabled via 'features' # Plugins which are always imported, and cannot be enabled/disabled via 'features'
CORE_HALLO_PLUGINS = [ CORE_HALLO_PLUGINS = [
HalloPlugin(name='halloreundo'), HalloPlugin(name='halloreundo', order=50),
HalloPlugin(name='hallorequireparagraphs', js=[ HalloPlugin(name='hallorequireparagraphs', js=[
static('wagtailadmin/js/hallo-plugins/hallo-requireparagraphs.js'), static('wagtailadmin/js/hallo-plugins/hallo-requireparagraphs.js'),
]) ])
@ -86,6 +90,7 @@ class HalloRichTextArea(WidgetWithScript, widgets.Textarea):
features.get_editor_plugin('hallo', feature_name) features.get_editor_plugin('hallo', feature_name)
for feature_name in self.features for feature_name in self.features
])) ]))
self.plugins.sort(key=lambda plugin: plugin.order)
super(HalloRichTextArea, self).__init__(*args, **kwargs) super(HalloRichTextArea, self).__init__(*args, **kwargs)
@ -106,7 +111,7 @@ class HalloRichTextArea(WidgetWithScript, widgets.Textarea):
# (so that it'll pick up the globally-defined halloPlugins list instead) # (so that it'll pick up the globally-defined halloPlugins list instead)
return "makeHalloRichTextEditable({0});".format(json.dumps(id_)) return "makeHalloRichTextEditable({0});".format(json.dumps(id_))
else: else:
plugin_data = {} plugin_data = OrderedDict()
for plugin in self.plugins: for plugin in self.plugins:
plugin.construct_plugins_list(plugin_data) plugin.construct_plugins_list(plugin_data)

View File

@ -188,6 +188,7 @@ def register_core_features(features):
HalloPlugin( HalloPlugin(
name='hallohr', name='hallohr',
js=[static('wagtailadmin/js/hallo-plugins/hallo-hr.js')], js=[static('wagtailadmin/js/hallo-plugins/hallo-hr.js')],
order=45,
) )
) )
features.default_features.append('hr') features.default_features.append('hr')