comparison src/browser/sat_browser/richtext.py @ 741:c3cb68227cca

browser_side: read and write tags from microblog data: - not tested! - implementation missing in quick_blog.Item and quick_blog.Entry
author souliane <souliane@mailoo.org>
date Thu, 19 Nov 2015 17:20:37 +0100
parents b6510fd9ae15
children d123e27fc386
comparison
equal deleted inserted replaced
740:b6510fd9ae15 741:c3cb68227cca
87 @param edit: set to True to display the edition mode 87 @param edit: set to True to display the edition mode
88 """ 88 """
89 if edit is None: 89 if edit is None:
90 edit = hasattr(self, 'textarea') and self.textarea.getVisible() 90 edit = hasattr(self, 'textarea') and self.textarea.getVisible()
91 91
92 for widget in ['title_panel', 'command']: 92 for widget in ['title_panel', 'tags_panel', 'command']:
93 if hasattr(self, widget): 93 if hasattr(self, widget):
94 getattr(self, widget).setVisible(edit) 94 getattr(self, widget).setVisible(edit)
95 95
96 if hasattr(self, 'toolbar'): 96 if hasattr(self, 'toolbar'):
97 self.toolbar.setVisible(False) 97 self.toolbar.setVisible(False)
118 self.title_panel = base_panel.TitlePanel() 118 self.title_panel = base_panel.TitlePanel()
119 self.title_panel.addStyleName(self.STYLE['title']) 119 self.title_panel.addStyleName(self.STYLE['title'])
120 self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2) 120 self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2)
121 self.setWidget(self.title_offset, 0, self.title_panel) 121 self.setWidget(self.title_offset, 0, self.title_panel)
122 122
123 if not self.read_only and not hasattr(self, 'tags'): 123 if not self.read_only and not hasattr(self, 'tags_panel'):
124 suggested_tags = [] # TODO: feed this list with tags suggestion 124 suggested_tags = [] # TODO: feed this list with tags suggestion
125 tags = [] # TODO: feed this list with tags already assigned to this message 125 self.tags_panel = list_manager.TagsPanel(suggested_tags)
126 self.tags = list_manager.TagsPanel(suggested_tags, tags)
127 self.getFlexCellFormatter().setColSpan(self.tags_offset, 0, 2) 126 self.getFlexCellFormatter().setColSpan(self.tags_offset, 0, 2)
128 self.setWidget(self.tags_offset, 0, self.tags) 127 self.setWidget(self.tags_offset, 0, self.tags_panel)
129 128
130 if not self.read_only and not hasattr(self, 'command'): 129 if not self.read_only and not hasattr(self, 'command'):
131 self.command = HorizontalPanel() 130 self.command = HorizontalPanel()
132 self.command.addStyleName("marginAuto") 131 self.command.addStyleName("marginAuto")
133 self.command.add(Button("Cancel", lambda: self.edit(True, True))) 132 self.command.add(Button("Cancel", lambda: self.edit(True, True)))
264 content = {'text': self.display.getContent()['text'], 'syntax': C.SYNTAX_XHTML} 263 content = {'text': self.display.getContent()['text'], 'syntax': C.SYNTAX_XHTML}
265 else: 264 else:
266 content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax} 265 content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax}
267 if hasattr(self, 'title_panel'): 266 if hasattr(self, 'title_panel'):
268 content.update({'title': self.strproc(self.title_panel.getText())}) 267 content.update({'title': self.strproc(self.title_panel.getText())})
268 if hasattr(self, 'tags_panel'):
269 count = 0
270 for tag in self.tags_panel.getTags():
271 content['tag#%i' % count if count else 'tag'] = tag
272 count += 1
269 return content 273 return content
270 274
271 def edit(self, edit=False, abort=False, sync=False): 275 def edit(self, edit=False, abort=False, sync=False):
272 """ 276 """
273 Remark: the editor must be visible before you call this method. 277 Remark: the editor must be visible before you call this method.
294 if text is not None: 298 if text is not None:
295 # Important: this also update self._original_content 299 # Important: this also update self._original_content
296 content.update({'text': text}) 300 content.update({'text': text})
297 content.update({'syntax': syntax}) 301 content.update({'syntax': syntax})
298 self.textarea.setText(content['text']) 302 self.textarea.setText(content['text'])
303
299 if hasattr(self, 'title_panel') and 'title' in content: 304 if hasattr(self, 'title_panel') and 'title' in content:
300 self.title_panel.setText(content['title']) 305 self.title_panel.setText(content['title'])
301 self.title_panel.setStackVisible(0, content['title'] != '') 306 self.title_panel.setStackVisible(0, content['title'] != '')
307
308 if hasattr(self, 'tags_panel') and 'tag' in content:
309 tags = [tag for key, tag in content.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
310 self.tags_panel.setTags(tags)
311 self.tags_panel.setStackVisible(0, len(tags) > 0)
312
302 self.setToolBar(syntax) 313 self.setToolBar(syntax)
303 if content['text'] and content['syntax'] != syntax: 314 if content['text'] and content['syntax'] != syntax:
304 self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax']) 315 self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'])
305 else: 316 else:
306 syntaxConvertCb() 317 syntaxConvertCb()
314 def setDisplayContent(self): 325 def setDisplayContent(self):
315 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg""" 326 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg"""
316 content = self._original_content 327 content = self._original_content
317 text = content['text'] 328 text = content['text']
318 if 'title' in content and content['title']: 329 if 'title' in content and content['title']:
319 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), content['text']) 330 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), text)
331 if 'tag' in content: # FIXME: display it more beautiful
332 tags = [tag for key, tag in content.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
333 text = '%s<h3>%s %s</h3>' % (text, _("Tags:"), html_tools.html_sanitize(", ".join(tags)))
320 self.display.setContent({'text': text}) 334 self.display.setContent({'text': text})
321 335
322 def setFocus(self, focus): 336 def setFocus(self, focus):
323 self.textarea.setFocus(focus) 337 self.textarea.setFocus(focus)
324 338