# HG changeset patch # User souliane # Date 1392283946 -3600 # Node ID 9bb78c09e9fc68b4d355bc4761912b8f721497ca # Parent c417a7acfe44404564a941c0d8470404b0ac6f27 browser_side: wysiwyg edition handles the toolbar buttons diff -r c417a7acfe44 -r 9bb78c09e9fc browser_side/richtext.py --- a/browser_side/richtext.py Thu Feb 13 10:30:38 2014 +0100 +++ b/browser_side/richtext.py Thu Feb 13 10:32:26 2014 +0100 @@ -25,6 +25,8 @@ from pyjamas.ui.HTML import HTML from pyjamas.ui.FlexTable import FlexTable from pyjamas.ui.HorizontalPanel import HorizontalPanel +from pyjamas import Window +from __pyjamas__ import doc from constants import Const from dialog import ConfirmDialog, InfoDialog @@ -197,25 +199,42 @@ button.addStyleName('richTextToolButton') self.toolbar.add(button) - def button_callback(): + def buttonCb(): """Generic callback for a toolbar button.""" text = self.textarea.getText() cursor_pos = self.textarea.getCursorPos() selection_length = self.textarea.getSelectionLength() - infos = composition.RICH_SYNTAXES[syntax][key] + data = composition.RICH_SYNTAXES[syntax][key] if selection_length == 0: - middle_text = infos[1] + middle_text = data[1] else: middle_text = text[cursor_pos:cursor_pos + selection_length] self.textarea.setText(text[:cursor_pos] - + infos[0] + + data[0] + middle_text - + infos[2] + + data[2] + text[cursor_pos + selection_length:]) - self.textarea.setCursorPos(cursor_pos + len(infos[0]) + len(middle_text)) + self.textarea.setCursorPos(cursor_pos + len(data[0]) + len(middle_text)) self.textarea.setFocus(True) - button.addClickListener(button_callback) + def wysiwygCb(): + """Callback for a toolbar button while wysiwyg mode is enabled.""" + data = composition.COMMANDS[key] + + def execCommand(command, arg): + self.display.setFocus(True) + doc().execCommand(command, False, arg.strip() if arg else '') + # use Window.prompt instead of dialog.PromptDialog to not loose the focus + prompt = lambda command, text: execCommand(command, Window.prompt(text)) + if isinstance(data, tuple) or isinstance(data, list): + if data[1]: + prompt(data[0], data[1]) + else: + execCommand(data[0], data[2]) + else: + execCommand(data, False, '') + + button.addClickListener(lambda: wysiwygCb() if self.wysiwyg else buttonCb()) def getContent(self): assert(hasattr(self, 'textarea')) diff -r c417a7acfe44 -r 9bb78c09e9fc public/libervia.css --- a/public/libervia.css Thu Feb 13 10:30:38 2014 +0100 +++ b/public/libervia.css Thu Feb 13 10:32:26 2014 +0100 @@ -1290,6 +1290,9 @@ background-color: white; border: 1px solid #a0a0a0; border-radius: 5px; + display: block; + font-size: larger; + white-space: pre; } .richTextSyntaxLabel {