Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
361:f4efffb9627c | 362:019e1e706e74 |
---|---|
24 from pyjamas.ui.Label import Label | 24 from pyjamas.ui.Label import Label |
25 from pyjamas.ui.HTML import HTML | 25 from pyjamas.ui.HTML import HTML |
26 from pyjamas.ui.FlexTable import FlexTable | 26 from pyjamas.ui.FlexTable import FlexTable |
27 from pyjamas.ui.HorizontalPanel import HorizontalPanel | 27 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
28 from pyjamas import Window | 28 from pyjamas import Window |
29 from pyjamas.ui.KeyboardListener import KeyboardHandler | |
29 from __pyjamas__ import doc | 30 from __pyjamas__ import doc |
30 | 31 |
31 from constants import Const | 32 from constants import Const |
32 from dialog import ConfirmDialog, InfoDialog | 33 from dialog import ConfirmDialog, InfoDialog |
33 from base_panels import TitlePanel, BaseTextEditor, LightTextEditor | 34 from base_panels import TitlePanel, BaseTextEditor, LightTextEditor |
83 self.title_offset = self.toolbar_offset = self.content_offset = y_offset | 84 self.title_offset = self.toolbar_offset = self.content_offset = y_offset |
84 self.command_offset = self.content_offset + 1 | 85 self.command_offset = self.content_offset + 1 |
85 FlexTable.__init__(self, self.command_offset + (0 if self.no_command else 1), 2) | 86 FlexTable.__init__(self, self.command_offset + (0 if self.no_command else 1), 2) |
86 self.addStyleName(self.style['main']) | 87 self.addStyleName(self.style['main']) |
87 | 88 |
89 def addEditListener(self, listener): | |
90 """Add a method to be called whenever the text is edited. | |
91 @param listener: method taking two arguments: sender, keycode""" | |
92 BaseTextEditor.addEditListener(self, listener) | |
93 if hasattr(self, 'display'): | |
94 self.display.addEditListener(listener) | |
95 | |
88 def refresh(self, edit=None): | 96 def refresh(self, edit=None): |
89 """Refresh the UI for edition/display mode | 97 """Refresh the UI for edition/display mode |
90 @param edit: set to True to display the edition mode""" | 98 @param edit: set to True to display the edition mode""" |
91 if edit is None: | 99 if edit is None: |
92 edit = hasattr(self, 'textarea') and self.textarea.getVisible() | 100 edit = hasattr(self, 'textarea') and self.textarea.getVisible() |
97 | 105 |
98 if hasattr(self, 'toolbar'): | 106 if hasattr(self, 'toolbar'): |
99 self.toolbar.setVisible(False) | 107 self.toolbar.setVisible(False) |
100 if not hasattr(self, 'display'): | 108 if not hasattr(self, 'display'): |
101 self.display = LightTextEditor(enhance_display=False) # for display mode | 109 self.display = LightTextEditor(enhance_display=False) # for display mode |
110 for listener in self.edit_listeners: | |
111 self.display.addEditListener(listener) | |
102 if not self.read_only and not hasattr(self, 'textarea'): | 112 if not self.read_only and not hasattr(self, 'textarea'): |
103 self.textarea = TextArea() # for edition mode | 113 self.textarea = EditTextArea(self) # for edition mode |
104 self.textarea.addStyleName(self.style['textarea']) | 114 self.textarea.addStyleName(self.style['textarea']) |
105 | 115 |
106 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2) | 116 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2) |
107 if edit and not self.wysiwyg: | 117 if edit and not self.wysiwyg: |
108 self.textarea.setWidth('100%') # CSS width doesn't do it, don't know why | 118 self.textarea.setWidth('100%') # CSS width doesn't do it, don't know why |
217 + middle_text | 227 + middle_text |
218 + data[2] | 228 + data[2] |
219 + text[cursor_pos + selection_length:]) | 229 + text[cursor_pos + selection_length:]) |
220 self.textarea.setCursorPos(cursor_pos + len(data[0]) + len(middle_text)) | 230 self.textarea.setCursorPos(cursor_pos + len(data[0]) + len(middle_text)) |
221 self.textarea.setFocus(True) | 231 self.textarea.setFocus(True) |
232 self.textarea.onKeyDown() | |
222 | 233 |
223 def wysiwygCb(): | 234 def wysiwygCb(): |
224 """Callback for a toolbar button while wysiwyg mode is enabled.""" | 235 """Callback for a toolbar button while wysiwyg mode is enabled.""" |
225 data = composition.COMMANDS[key] | 236 data = composition.COMMANDS[key] |
226 | 237 |
234 prompt(data[0], data[1]) | 245 prompt(data[0], data[1]) |
235 else: | 246 else: |
236 execCommand(data[0], data[2]) | 247 execCommand(data[0], data[2]) |
237 else: | 248 else: |
238 execCommand(data, False, '') | 249 execCommand(data, False, '') |
250 self.textarea.onKeyDown() | |
239 | 251 |
240 button.addClickListener(lambda: wysiwygCb() if self.wysiwyg else buttonCb()) | 252 button.addClickListener(lambda: wysiwygCb() if self.wysiwyg else buttonCb()) |
241 | 253 |
242 def getContent(self): | 254 def getContent(self): |
243 assert(hasattr(self, 'textarea')) | 255 assert(hasattr(self, 'textarea')) |
492 ListManager.__init__(self, parent, composition.RECIPIENT_TYPES, list_, {'y': y_offset}) | 504 ListManager.__init__(self, parent, composition.RECIPIENT_TYPES, list_, {'y': y_offset}) |
493 | 505 |
494 self.registerPopupMenuPanel(entries=composition.RECIPIENT_TYPES, | 506 self.registerPopupMenuPanel(entries=composition.RECIPIENT_TYPES, |
495 hide=lambda sender, key: self.__children[key]["panel"].isVisible(), | 507 hide=lambda sender, key: self.__children[key]["panel"].isVisible(), |
496 callback=self.setContactPanelVisible) | 508 callback=self.setContactPanelVisible) |
509 | |
510 | |
511 class EditTextArea(TextArea, KeyboardHandler): | |
512 def __init__(self, _parent): | |
513 TextArea.__init__(self) | |
514 self._parent = _parent | |
515 KeyboardHandler.__init__(self) | |
516 self.addKeyboardListener(self) | |
517 | |
518 def onKeyDown(self, sender=None, keycode=None, modifiers=None): | |
519 for listener in self._parent.edit_listeners: | |
520 listener(self, keycode) |