Mercurial > libervia-web
diff browser_side/richtext.py @ 362:019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 19 Feb 2014 16:38:13 +0100 |
parents | 151bf1afd97e |
children | 4cf735b40304 |
line wrap: on
line diff
--- a/browser_side/richtext.py Wed Feb 19 14:17:03 2014 +0100 +++ b/browser_side/richtext.py Wed Feb 19 16:38:13 2014 +0100 @@ -26,6 +26,7 @@ from pyjamas.ui.FlexTable import FlexTable from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas import Window +from pyjamas.ui.KeyboardListener import KeyboardHandler from __pyjamas__ import doc from constants import Const @@ -85,6 +86,13 @@ FlexTable.__init__(self, self.command_offset + (0 if self.no_command else 1), 2) self.addStyleName(self.style['main']) + def addEditListener(self, listener): + """Add a method to be called whenever the text is edited. + @param listener: method taking two arguments: sender, keycode""" + BaseTextEditor.addEditListener(self, listener) + if hasattr(self, 'display'): + self.display.addEditListener(listener) + def refresh(self, edit=None): """Refresh the UI for edition/display mode @param edit: set to True to display the edition mode""" @@ -99,8 +107,10 @@ self.toolbar.setVisible(False) if not hasattr(self, 'display'): self.display = LightTextEditor(enhance_display=False) # for display mode + for listener in self.edit_listeners: + self.display.addEditListener(listener) if not self.read_only and not hasattr(self, 'textarea'): - self.textarea = TextArea() # for edition mode + self.textarea = EditTextArea(self) # for edition mode self.textarea.addStyleName(self.style['textarea']) self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2) @@ -219,6 +229,7 @@ + text[cursor_pos + selection_length:]) self.textarea.setCursorPos(cursor_pos + len(data[0]) + len(middle_text)) self.textarea.setFocus(True) + self.textarea.onKeyDown() def wysiwygCb(): """Callback for a toolbar button while wysiwyg mode is enabled.""" @@ -236,6 +247,7 @@ execCommand(data[0], data[2]) else: execCommand(data, False, '') + self.textarea.onKeyDown() button.addClickListener(lambda: wysiwygCb() if self.wysiwyg else buttonCb()) @@ -494,3 +506,15 @@ self.registerPopupMenuPanel(entries=composition.RECIPIENT_TYPES, hide=lambda sender, key: self.__children[key]["panel"].isVisible(), callback=self.setContactPanelVisible) + + +class EditTextArea(TextArea, KeyboardHandler): + def __init__(self, _parent): + TextArea.__init__(self) + self._parent = _parent + KeyboardHandler.__init__(self) + self.addKeyboardListener(self) + + def onKeyDown(self, sender=None, keycode=None, modifiers=None): + for listener in self._parent.edit_listeners: + listener(self, keycode)