comparison src/browser/sat_browser/richtext.py @ 648:6d3142b782c3 frontends_multi_profiles

browser_side: classes reorganisation: - moved widgets in dedicated modules (base, contact, editor, libervia) and a widget module for single classes - same thing for panels (base, main, contact) - libervia_widget mix main panels and widget and drag n drop for technical reasons (see comments) - renamed WebPanel to WebWidget
author Goffi <goffi@goffi.org>
date Thu, 26 Feb 2015 18:10:54 +0100
parents 9092e624bb27
children 9877607c719a
comparison
equal deleted inserted replaced
647:e0021d571eef 648:6d3142b782c3
32 from pyjamas.ui.KeyboardListener import KeyboardHandler 32 from pyjamas.ui.KeyboardListener import KeyboardHandler
33 from __pyjamas__ import doc 33 from __pyjamas__ import doc
34 34
35 from constants import Const as C 35 from constants import Const as C
36 import dialog 36 import dialog
37 import base_panels 37 import base_panel
38 import editor_widget
38 import list_manager 39 import list_manager
39 import html_tools 40 import html_tools
40 import blog 41 import blog
41 import chat 42 import chat
42 43
43 44
44 class RichTextEditor(base_panels.BaseTextEditor, FlexTable): 45 class RichTextEditor(editor_widget.BaseTextEditor, FlexTable):
45 """Panel for the rich text editor.""" 46 """Panel for the rich text editor."""
46 47
47 def __init__(self, host, content=None, modifiedCb=None, afterEditCb=None, options=None, style=None): 48 def __init__(self, host, content=None, modifiedCb=None, afterEditCb=None, options=None, style=None):
48 """ 49 """
49 @param host: the SatWebFrontend instance 50 @param host: the SatWebFrontend instance
62 'toolbar': 'richTextToolbar', 63 'toolbar': 'richTextToolbar',
63 'textarea': 'richTextArea'} 64 'textarea': 'richTextArea'}
64 if isinstance(style, dict): 65 if isinstance(style, dict):
65 self.style.update(style) 66 self.style.update(style)
66 self._prepareUI() 67 self._prepareUI()
67 base_panels.BaseTextEditor.__init__(self, content, None, modifiedCb, afterEditCb) 68 editor_widget.BaseTextEditor.__init__(self, content, None, modifiedCb, afterEditCb)
68 69
69 def __readOptions(self, options): 70 def __readOptions(self, options):
70 """Set the internal flags according to the given options.""" 71 """Set the internal flags according to the given options."""
71 if options is None: 72 if options is None:
72 options = [] 73 options = []
90 self.addStyleName(self.style['main']) 91 self.addStyleName(self.style['main'])
91 92
92 def addEditListener(self, listener): 93 def addEditListener(self, listener):
93 """Add a method to be called whenever the text is edited. 94 """Add a method to be called whenever the text is edited.
94 @param listener: method taking two arguments: sender, keycode""" 95 @param listener: method taking two arguments: sender, keycode"""
95 base_panels.BaseTextEditor.addEditListener(self, listener) 96 editor_widget.BaseTextEditor.addEditListener(self, listener)
96 if hasattr(self, 'display'): 97 if hasattr(self, 'display'):
97 self.display.addEditListener(listener) 98 self.display.addEditListener(listener)
98 99
99 def refresh(self, edit=None): 100 def refresh(self, edit=None):
100 """Refresh the UI for edition/display mode 101 """Refresh the UI for edition/display mode
107 getattr(self, widget).setVisible(edit) 108 getattr(self, widget).setVisible(edit)
108 109
109 if hasattr(self, 'toolbar'): 110 if hasattr(self, 'toolbar'):
110 self.toolbar.setVisible(False) 111 self.toolbar.setVisible(False)
111 if not hasattr(self, 'display'): 112 if not hasattr(self, 'display'):
112 self.display = base_panels.HTMLTextEditor(options={'enhance_display': False, 'listen_keyboard': False}) # for display mode 113 self.display = editor_widget.HTMLTextEditor(options={'enhance_display': False, 'listen_keyboard': False}) # for display mode
113 for listener in self.edit_listeners: 114 for listener in self.edit_listeners:
114 self.display.addEditListener(listener) 115 self.display.addEditListener(listener)
115 if not self.read_only and not hasattr(self, 'textarea'): 116 if not self.read_only and not hasattr(self, 'textarea'):
116 self.textarea = EditTextArea(self) # for edition mode 117 self.textarea = EditTextArea(self) # for edition mode
117 self.textarea.addStyleName(self.style['textarea']) 118 self.textarea.addStyleName(self.style['textarea'])
124 self.setWidget(self.content_offset, 0, self.display) 125 self.setWidget(self.content_offset, 0, self.display)
125 if not edit: 126 if not edit:
126 return 127 return
127 128
128 if not self.no_title and not hasattr(self, 'title_panel'): 129 if not self.no_title and not hasattr(self, 'title_panel'):
129 self.title_panel = base_panels.TitlePanel() 130 self.title_panel = base_panel.TitlePanel()
130 self.title_panel.addStyleName(self.style['title']) 131 self.title_panel.addStyleName(self.style['title'])
131 self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2) 132 self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2)
132 self.setWidget(self.title_offset, 0, self.title_panel) 133 self.setWidget(self.title_offset, 0, self.title_panel)
133 134
134 if not self.no_command and not hasattr(self, 'command'): 135 if not self.no_command and not hasattr(self, 'command'):
284 confirmation. When edit is False and abort is True, abortion is actually done. 285 confirmation. When edit is False and abort is True, abortion is actually done.
285 @param sync: set to True to cancel the edition after the content has been saved somewhere else 286 @param sync: set to True to cancel the edition after the content has been saved somewhere else
286 """ 287 """
287 if not (edit and abort): 288 if not (edit and abort):
288 self.refresh(edit) # not when we are asking for a confirmation 289 self.refresh(edit) # not when we are asking for a confirmation
289 base_panels.BaseTextEditor.edit(self, edit, abort, sync) # after the UI has been refreshed 290 editor_widget.BaseTextEditor.edit(self, edit, abort, sync) # after the UI has been refreshed
290 if (edit and abort): 291 if (edit and abort):
291 return # self.abortEdition is called by base_panels.BaseTextEditor.edit 292 return # self.abortEdition is called by editor_widget.BaseTextEditor.edit
292 self.setWysiwyg(False, init=True) # after base_panels.BaseTextEditor (it affects self.getContent) 293 self.setWysiwyg(False, init=True) # after editor_widget.BaseTextEditor (it affects self.getContent)
293 if sync: 294 if sync:
294 return 295 return
295 # the following must NOT be done at each UI refresh! 296 # the following must NOT be done at each UI refresh!
296 content = self._original_content 297 content = self._original_content
297 if edit: 298 if edit:
317 # set the display text in XHTML only during init because a new MicroblogEntry instance is created after each modification 318 # set the display text in XHTML only during init because a new MicroblogEntry instance is created after each modification
318 self.setDisplayContent() 319 self.setDisplayContent()
319 self.display.edit(False) 320 self.display.edit(False)
320 321
321 def setDisplayContent(self): 322 def setDisplayContent(self):
322 """Set the content of the base_panels.HTMLTextEditor which is used for display/wysiwyg""" 323 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg"""
323 content = self._original_content 324 content = self._original_content
324 text = content['text'] 325 text = content['text']
325 if 'title' in content and content['title']: 326 if 'title' in content and content['title']:
326 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), content['text']) 327 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), content['text'])
327 self.display.setContent({'text': text}) 328 self.display.setContent({'text': text})