annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
4 # Libervia: a Salut à Toi frontend
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2013, 2014 Adrien Cossa <souliane@mailoo.org>
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
10 # (at your option) any later version.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
15 # GNU Affero General Public License for more details.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
19
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 433
diff changeset
20 from sat_frontends.tools import composition
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 433
diff changeset
21 from sat.core.i18n import _
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 433
diff changeset
22
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from pyjamas.ui.TextArea import TextArea
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from pyjamas.ui.Button import Button
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
25 from pyjamas.ui.CheckBox import CheckBox
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from pyjamas.ui.DialogBox import DialogBox
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from pyjamas.ui.Label import Label
324
8131d0ccf21b browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents: 323
diff changeset
28 from pyjamas.ui.HTML import HTML
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from pyjamas.ui.FlexTable import FlexTable
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from pyjamas.ui.HorizontalPanel import HorizontalPanel
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
31 from pyjamas import Window
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
32 from pyjamas.ui.KeyboardListener import KeyboardHandler
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
33 from __pyjamas__ import doc
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 319
diff changeset
34
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
35 from constants import Const as C
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
36 import dialog
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
37 import base_panel
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
38 import editor_widget
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
39 import list_manager
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
40 import html_tools
616
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 593
diff changeset
41 import blog
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 593
diff changeset
42 import chat
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
43
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
44
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
45 class RichTextEditor(editor_widget.BaseTextEditor, FlexTable):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
46 """Panel for the rich text editor."""
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
47
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
48 def __init__(self, host, content=None, modifiedCb=None, afterEditCb=None, options=None, style=None):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
49 """
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
50 @param host: the SatWebFrontend instance
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
51 @param content: dict with at least a 'text' key
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
52 @param modifiedCb: method to be called when the text has been modified
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
53 @param afterEditCb: method to be called when the edition is done
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
54 @param options: list of UI options (see self.readOptions)
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
55 """
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
56 FlexTable.__init__(self) # FIXME
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
57 self.host = host
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
58 self._debug = False # TODO: don't forget to set it False before commit
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
59 self.wysiwyg = False
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
60 self.__readOptions(options)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
61 self.style = {'main': 'richTextEditor',
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
62 'title': 'richTextTitle',
412
9977de10b7da browser_side: editors do not listen for <escape> + display WYSIWIG in upper case
souliane <souliane@mailoo.org>
parents: 404
diff changeset
63 'toolbar': 'richTextToolbar',
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
64 'textarea': 'richTextArea'}
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
65 if isinstance(style, dict):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
66 self.style.update(style)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
67 self._prepareUI()
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
68 editor_widget.BaseTextEditor.__init__(self, content, None, modifiedCb, afterEditCb)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
69
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
70 def __readOptions(self, options):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
71 """Set the internal flags according to the given options."""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
72 if options is None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
73 options = []
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
74 self.read_only = 'read_only' in options
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
75 self.update_msg = 'update_msg' in options
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
76 self.no_title = 'no_title' in options or self.read_only
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
77 self.no_command = 'no_command' in options or self.read_only
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
78
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
79 def _prepareUI(self, y_offset=0):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
80 """Prepare the UI to host title panel, toolbar, text area...
359
151bf1afd97e browser_side: fix error when displaying the microblogs of a contact
souliane <souliane@mailoo.org>
parents: 357
diff changeset
81 @param y_offset: Y offset to start from (extra rows on top)"""
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
82 if not self.read_only:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
83 self.title_offset = y_offset
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
84 self.toolbar_offset = self.title_offset + (0 if self.no_title else 1)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
85 self.content_offset = self.toolbar_offset + (len(composition.RICH_SYNTAXES) if self._debug else 1)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
86 self.command_offset = self.content_offset + 1
359
151bf1afd97e browser_side: fix error when displaying the microblogs of a contact
souliane <souliane@mailoo.org>
parents: 357
diff changeset
87 else:
151bf1afd97e browser_side: fix error when displaying the microblogs of a contact
souliane <souliane@mailoo.org>
parents: 357
diff changeset
88 self.title_offset = self.toolbar_offset = self.content_offset = y_offset
151bf1afd97e browser_side: fix error when displaying the microblogs of a contact
souliane <souliane@mailoo.org>
parents: 357
diff changeset
89 self.command_offset = self.content_offset + 1
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
90 # FlexTable.__init__(self, rowspan=self.command_offset + (0 if self.no_command else 1), colspan=2) # FIXME
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
91 self.addStyleName(self.style['main'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
92
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
93 def addEditListener(self, listener):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
94 """Add a method to be called whenever the text is edited.
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
95 @param listener: method taking two arguments: sender, keycode"""
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
96 editor_widget.BaseTextEditor.addEditListener(self, listener)
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
97 if hasattr(self, 'display'):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
98 self.display.addEditListener(listener)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
99
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
100 def refresh(self, edit=None):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
101 """Refresh the UI for edition/display mode
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
102 @param edit: set to True to display the edition mode"""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
103 if edit is None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
104 edit = hasattr(self, 'textarea') and self.textarea.getVisible()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
105
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
106 for widget in ['title_panel', 'command']:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
107 if hasattr(self, widget):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
108 getattr(self, widget).setVisible(edit)
324
8131d0ccf21b browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents: 323
diff changeset
109
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
110 if hasattr(self, 'toolbar'):
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
111 self.toolbar.setVisible(False)
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
112 if not hasattr(self, 'display'):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
113 self.display = editor_widget.HTMLTextEditor(options={'enhance_display': False, 'listen_keyboard': False}) # for display mode
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
114 for listener in self.edit_listeners:
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
115 self.display.addEditListener(listener)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
116 if not self.read_only and not hasattr(self, 'textarea'):
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
117 self.textarea = EditTextArea(self) # for edition mode
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
118 self.textarea.addStyleName(self.style['textarea'])
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
119
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
120 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
121 if edit and not self.wysiwyg:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
122 self.textarea.setWidth('100%') # CSS width doesn't do it, don't know why
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
123 self.setWidget(self.content_offset, 0, self.textarea)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
124 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
125 self.setWidget(self.content_offset, 0, self.display)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
126 if not edit:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
127 return
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
128
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
129 if not self.no_title and not hasattr(self, 'title_panel'):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
130 self.title_panel = base_panel.TitlePanel()
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
131 self.title_panel.addStyleName(self.style['title'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
132 self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
133 self.setWidget(self.title_offset, 0, self.title_panel)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
134
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
135 if not self.no_command and not hasattr(self, 'command'):
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
136 self.command = HorizontalPanel()
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
137 self.command.addStyleName("marginAuto")
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
138 self.command.add(Button("Cancel", lambda: self.edit(True, True)))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
139 self.command.add(Button("Update" if self.update_msg else "Send message", lambda: self.edit(False)))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
140 self.getFlexCellFormatter().setColSpan(self.command_offset, 0, 2)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
141 self.setWidget(self.command_offset, 0, self.command)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
142
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
143 def setToolBar(self, syntax):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
144 """This method is called asynchronously after the parameter
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
145 holding the rich text syntax is retrieved. It is called at
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
146 each call of self.edit(True) because the user may
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
147 have change his setting since the last time."""
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
148 if syntax is None or syntax not in composition.RICH_SYNTAXES.keys():
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
149 syntax = composition.RICH_SYNTAXES.keys()[0]
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
150 if hasattr(self, "toolbar") and self.toolbar.syntax == syntax:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
151 self.toolbar.setVisible(True)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
152 return
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
153 count = 0
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
154 for syntax in composition.RICH_SYNTAXES.keys() if self._debug else [syntax]:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
155 self.toolbar = HorizontalPanel()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
156 self.toolbar.syntax = syntax
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
157 self.toolbar.addStyleName(self.style['toolbar'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
158 for key in composition.RICH_SYNTAXES[syntax].keys():
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
159 self.addToolbarButton(syntax, key)
412
9977de10b7da browser_side: editors do not listen for <escape> + display WYSIWIG in upper case
souliane <souliane@mailoo.org>
parents: 404
diff changeset
160 self.wysiwyg_button = CheckBox(_('WYSIWYG edition'))
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
161 wysiywgCb = lambda sender: self.setWysiwyg(sender.getChecked())
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
162 self.wysiwyg_button.addClickListener(wysiywgCb)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
163 self.toolbar.add(self.wysiwyg_button)
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
164 self.syntax_label = Label(_("Syntax: %s") % syntax)
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
165 self.syntax_label.addStyleName("richTextSyntaxLabel")
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
166 self.toolbar.add(self.syntax_label)
425
19bd203daa27 browser_side: set microblog editor width to 80%
souliane <souliane@mailoo.org>
parents: 412
diff changeset
167 self.toolbar.setCellWidth(self.syntax_label, "100%")
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
168 self.getFlexCellFormatter().setColSpan(self.toolbar_offset + count, 0, 2)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
169 self.setWidget(self.toolbar_offset + count, 0, self.toolbar)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
170 count += 1
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
171
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
172 def setWysiwyg(self, wysiwyg, init=False):
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
173 """Toggle the edition mode between rich content syntax and wysiwyg.
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
174 @param wysiwyg: boolean value
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
175 @param init: set to True to re-init without switching the widgets."""
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
176 def setWysiwyg():
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
177 self.wysiwyg = wysiwyg
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
178 try:
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
179 self.wysiwyg_button.setChecked(wysiwyg)
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
180 except (AttributeError, TypeError):
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
181 pass
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
182 try:
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
183 if wysiwyg:
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
184 self.syntax_label.addStyleName('transparent')
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
185 else:
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
186 self.syntax_label.removeStyleName('transparent')
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
187 except (AttributeError, TypeError):
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
188 pass
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
189 if not wysiwyg:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
190 self.display.removeStyleName('richTextWysiwyg')
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
191
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
192 if init:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
193 setWysiwyg()
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
194 return
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
195
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
196 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
197 if wysiwyg:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
198 def syntaxConvertCb(text):
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
199 self.display.setContent({'text': text})
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
200 self.textarea.removeFromParent() # XXX: force as it is not always done...
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
201 self.setWidget(self.content_offset, 0, self.display)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
202 self.display.addStyleName('richTextWysiwyg')
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
203 self.display.edit(True)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
204 content = self.getContent()
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
205 if content['text'] and content['syntax'] != C.SYNTAX_XHTML:
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
206 self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'], C.SYNTAX_XHTML)
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
207 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
208 syntaxConvertCb(content['text'])
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
209 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
210 syntaxConvertCb = lambda text: self.textarea.setText(text)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
211 text = self.display.getContent()['text']
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
212 if text and self.toolbar.syntax != C.SYNTAX_XHTML:
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
213 self.host.bridge.call('syntaxConvert', syntaxConvertCb, text)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
214 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
215 syntaxConvertCb(text)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
216 self.setWidget(self.content_offset, 0, self.textarea)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
217 self.textarea.setWidth('100%') # CSS width doesn't do it, don't know why
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
218
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
219 setWysiwyg() # do it in the end because it affects self.getContent
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
220
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
221 def addToolbarButton(self, syntax, key):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
222 """Add a button with the defined parameters."""
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
223 button = Button('<img src="%s" class="richTextIcon" />' %
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
224 composition.RICH_BUTTONS[key]["icon"])
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
225 button.setTitle(composition.RICH_BUTTONS[key]["tip"])
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
226 button.addStyleName('richTextToolButton')
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
227 self.toolbar.add(button)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
228
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
229 def buttonCb():
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
230 """Generic callback for a toolbar button."""
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
231 text = self.textarea.getText()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
232 cursor_pos = self.textarea.getCursorPos()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
233 selection_length = self.textarea.getSelectionLength()
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
234 data = composition.RICH_SYNTAXES[syntax][key]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
235 if selection_length == 0:
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
236 middle_text = data[1]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
237 else:
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
238 middle_text = text[cursor_pos:cursor_pos + selection_length]
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
239 self.textarea.setText(text[:cursor_pos]
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
240 + data[0]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
241 + middle_text
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
242 + data[2]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
243 + text[cursor_pos + selection_length:])
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
244 self.textarea.setCursorPos(cursor_pos + len(data[0]) + len(middle_text))
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
245 self.textarea.setFocus(True)
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
246 self.textarea.onKeyDown()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
247
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
248 def wysiwygCb():
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
249 """Callback for a toolbar button while wysiwyg mode is enabled."""
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
250 data = composition.COMMANDS[key]
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
251
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
252 def execCommand(command, arg):
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
253 self.display.setFocus(True)
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
254 doc().execCommand(command, False, arg.strip() if arg else '')
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
255 # use Window.prompt instead of dialog.PromptDialog to not loose the focus
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
256 prompt = lambda command, text: execCommand(command, Window.prompt(text))
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
257 if isinstance(data, tuple) or isinstance(data, list):
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
258 if data[1]:
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
259 prompt(data[0], data[1])
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
260 else:
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
261 execCommand(data[0], data[2])
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
262 else:
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
263 execCommand(data, False, '')
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
264 self.textarea.onKeyDown()
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
265
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
266 button.addClickListener(lambda: wysiwygCb() if self.wysiwyg else buttonCb())
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
267
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
268 def getContent(self):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
269 assert(hasattr(self, 'textarea'))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
270 assert(hasattr(self, 'toolbar'))
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
271 if self.wysiwyg:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
272 content = {'text': self.display.getContent()['text'], 'syntax': C.SYNTAX_XHTML}
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
273 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
274 content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax}
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
275 if hasattr(self, 'title_panel'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
276 content.update({'title': self.strproc(self.title_panel.getText())})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
277 return content
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
278
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
279 def edit(self, edit=False, abort=False, sync=False):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
280 """
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
281 Remark: the editor must be visible before you call this method.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
282 @param edit: set to True to edit the content or False to only display it
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
283 @param abort: set to True to cancel the edition and loose the changes.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
284 If edit and abort are both True, self.abortEdition can be used to ask for a
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
285 confirmation. When edit is False and abort is True, abortion is actually done.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
286 @param sync: set to True to cancel the edition after the content has been saved somewhere else
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
287 """
357
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
288 if not (edit and abort):
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
289 self.refresh(edit) # not when we are asking for a confirmation
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
290 editor_widget.BaseTextEditor.edit(self, edit, abort, sync) # after the UI has been refreshed
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
291 if (edit and abort):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
292 return # self.abortEdition is called by editor_widget.BaseTextEditor.edit
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
293 self.setWysiwyg(False, init=True) # after editor_widget.BaseTextEditor (it affects self.getContent)
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
294 if sync:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
295 return
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
296 # the following must NOT be done at each UI refresh!
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
297 content = self._original_content
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
298 if edit:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
299 def getParamCb(syntax):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
300 # set the editable text in the current user-selected syntax
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
301 def syntaxConvertCb(text=None):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
302 if text is not None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
303 # Important: this also update self._original_content
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
304 content.update({'text': text})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
305 content.update({'syntax': syntax})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
306 self.textarea.setText(content['text'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
307 if hasattr(self, 'title_panel') and 'title' in content:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
308 self.title_panel.setText(content['title'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
309 self.title_panel.setStackVisible(0, content['title'] != '')
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
310 self.setToolBar(syntax)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
311 if content['text'] and content['syntax'] != syntax:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
312 self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
313 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
314 syntaxConvertCb()
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
315 self.host.bridge.call('asyncGetParamA', getParamCb, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
316 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
317 if not self.initialized:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
318 # set the display text in XHTML only during init because a new MicroblogEntry instance is created after each modification
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
319 self.setDisplayContent()
357
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
320 self.display.edit(False)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
321
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
322 def setDisplayContent(self):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
323 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg"""
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
324 content = self._original_content
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
325 text = content['text']
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
326 if 'title' in content and content['title']:
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
327 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), content['text'])
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
328 self.display.setContent({'text': text})
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
329
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
330 def setFocus(self, focus):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
331 self.textarea.setFocus(focus)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
332
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
333 def abortEdition(self, content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
334 """Ask for confirmation before closing the dialog."""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
335 def confirm_cb(answer):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
336 if answer:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
337 self.edit(False, True)
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
338 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to %s?" % ("cancel your changes" if self.update_msg else "cancel this message"))
357
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
339 _dialog.cancel_button.setText(_("No"))
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
340 _dialog.show()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
341
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
342
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
343 class RichMessageEditor(RichTextEditor):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
344 """Use the rich text editor for sending messages with extended addressing.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
345 Recipient panels are on top and data may be synchronized from/to the unibox."""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
346
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
347 @classmethod
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
348 def getOrCreate(cls, host, parent=None, callback=None):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
349 """Get or create the message editor associated to that host.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
350 Add it to parent if parent is not None, otherwise display it
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
351 in a popup dialog.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
352 @param host: the host
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
353 @param parent: parent panel (or None to display in a popup).
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
354 @return: the RichTextEditor instance if parent is not None,
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
355 otherwise a popup DialogBox containing the RichTextEditor.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
356 """
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
357 if not hasattr(host, 'richtext'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
358 modifiedCb = lambda content: True
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
359
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
360 def afterEditCb(content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
361 if hasattr(host.richtext, 'popup'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
362 host.richtext.popup.hide()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
363 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
364 host.richtext.setVisible(False)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
365 callback()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
366 options = ['no_title']
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
367 style = {'main': 'richMessageEditor', 'textarea': 'richMessageArea'}
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
368 host.richtext = RichMessageEditor(host, None, modifiedCb, afterEditCb, options, style)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
369
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
370 def add(widget, parent):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
371 if widget.getParent() is not None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
372 if widget.getParent() != parent:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
373 widget.removeFromParent()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
374 parent.add(widget)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
375 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
376 parent.add(widget)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
377 widget.setVisible(True)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
378 widget.initialized = False # fake a new creation
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
379 widget.edit(True)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
380
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
381 if parent is None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
382 if not hasattr(host.richtext, 'popup'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
383 host.richtext.popup = DialogBox(autoHide=False, centered=True)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
384 host.richtext.popup.setHTML("Compose your message")
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
385 host.richtext.popup.add(host.richtext)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
386 add(host.richtext, host.richtext.popup)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
387 host.richtext.popup.center()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
388 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
389 add(host.richtext, parent)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
390 return host.richtext.popup if parent is None else host.richtext
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
391
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
392 def _prepareUI(self, y_offset=0):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
393 """Prepare the UI to host recipients panel, toolbar, text area...
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
394 @param y_offset: Y offset to start from (extra rows on top)"""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
395 self.recipient_offset = y_offset
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
396 self.recipient_spacer_offset = self.recipient_offset + len(composition.RECIPIENT_TYPES)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
397 RichTextEditor._prepareUI(self, self.recipient_spacer_offset + 1)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
398
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
399 def refresh(self, edit=None):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
400 """Refresh the UI between edition/display mode
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
401 @param edit: set to True to display the edition mode"""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
402 if edit is None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
403 edit = hasattr(self, 'textarea') and self.textarea.getVisible()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
404 RichTextEditor.refresh(self, edit)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
405
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
406 for widget in ['recipient', 'recipient_spacer']:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
407 if hasattr(self, widget):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
408 getattr(self, widget).setVisible(edit)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
409
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
410 if not edit:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
411 return
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
412
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
413 if not hasattr(self, 'recipient'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
414 # recipient types sub-panels are automatically added by the manager
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
415 self.recipient = RecipientManager(self, self.recipient_offset)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
416 self.recipient.createWidgets(title_format="%s: ")
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
417 self.recipient_spacer = HTML('')
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
418 self.recipient_spacer.setStyleName('recipientSpacer')
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
419 self.getFlexCellFormatter().setColSpan(self.recipient_spacer_offset, 0, 2)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
420 self.setWidget(self.recipient_spacer_offset, 0, self.recipient_spacer)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
421
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
422 if not hasattr(self, 'sync_button'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
423 self.sync_button = Button("Back to quick box", lambda: self.edit(True, sync=True))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
424 self.command.insert(self.sync_button, 1)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
425
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
426 def syncToEditor(self):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
427 """Synchronize from unibox."""
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
428 def setContent(target, data):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
429 if hasattr(self, 'recipient'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
430 self.recipient.setContacts({"To": [target]} if target else {})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
431 self.setContent({'text': data if data else '', 'syntax': ''})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
432 self.textarea.setText(data if data else '')
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
433 data, target = self.host.uni_box.getTargetAndData() if self.host.uni_box else (None, None)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
434 setContent(target, data)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
435
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
436 def __syncToUniBox(self, recipients=None, emptyText=False):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
437 """Synchronize to unibox if a maximum of one recipient is set.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
438 @return True if the sync could be done, False otherwise"""
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 282
diff changeset
439 if not self.host.uni_box:
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 282
diff changeset
440 return
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
441 setText = lambda: self.host.uni_box.setText("" if emptyText else self.getContent()['text'])
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
442 if not hasattr(self, 'recipient'):
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
443 setText()
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
444 return True
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
445 if recipients is None:
624
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
446 recipients = self.recipient.getItemsByKey()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
447 target = ""
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
448 # we could eventually allow more in the future
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
449 allowed = 1
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
450 for key in recipients:
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
451 count = len(recipients[key])
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
452 if count == 0:
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
453 continue
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
454 allowed -= count
280
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
455 if allowed < 0:
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
456 return False
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
457 # TODO: change this if later more then one recipients are allowed
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
458 target = recipients[key][0]
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
459 setText()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
460 if target == "":
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
461 return True
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
462 if target.startswith("@"):
616
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 593
diff changeset
463 _class = blog.MicroblogPanel
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
464 target = None if target == "@@" else target[1:]
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
465 else:
616
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 593
diff changeset
466 _class = chat.Chat
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 593
diff changeset
467 self.host.displayWidget(_class, target)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
468 return True
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
469
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
470 def syncFromEditor(self, content):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
471 """Synchronize to unibox and close the dialog afterward. Display
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
472 a message and leave the dialog open if the sync was not possible."""
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
473 if self.__syncToUniBox():
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
474 self._afterEditCb(content)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
475 return
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
476 dialog.InfoDialog("Too many recipients",
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
477 "A message with more than one direct recipient (To)," +
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
478 " or with any special recipient (Cc or Bcc), could not be" +
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
479 " stored in the quick box.\n\nPlease finish your composing" +
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
480 " in the rich text editor, and send your message directly" +
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
481 " from here.", Width="400px").center()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
482
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
483 def edit(self, edit=True, abort=False, sync=False):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
484 if not edit and not abort and not sync: # force sending message even when the text has not been modified
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
485 if not self.__sendMessage(): # message has not been sent (missing information), do nothing
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
486 return
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
487 RichTextEditor.edit(self, edit, abort, sync)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
488
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
489 def __sendMessage(self):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
490 """Send the message."""
624
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
491 recipients = self.recipient.getItemsByKey()
280
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
492 targets = []
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
493 for addr in recipients:
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
494 for recipient in recipients[addr]:
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
495 if recipient.startswith("@"):
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
496 targets.append(("PUBLIC", None, addr) if recipient == "@@" else ("GROUP", recipient[1:], addr))
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
497 else:
1ccdc34cfb60 browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents: 276
diff changeset
498 targets.append(("chat", recipient, addr))
270
52e60dd2bc43 browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
499 # check that we actually have a message target and data
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
500 content = self.getContent()
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
501 if content['text'] == "" or len(targets) == 0:
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
502 dialog.InfoDialog("Missing information",
270
52e60dd2bc43 browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
503 "Some information are missing and the message hasn't been sent.", Width="400px").center()
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
504 return None
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
505 self.__syncToUniBox(recipients, emptyText=True)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
506 extra = {'content_rich': content['text']}
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
507 if hasattr(self, 'title_panel'):
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
508 extra.update({'title': content['title']})
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
509 self.host.send(targets, content['text'], extra=extra)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
510 return True
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
511
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
512
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
513 class RecipientManager(list_manager.ListManager):
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
514 """A manager for sub-panels to set the recipients for each recipient type."""
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
515
324
8131d0ccf21b browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents: 323
diff changeset
516 def __init__(self, parent, y_offset=0):
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
517 # TODO: be sure we also display empty groups and disconnected contacts + their groups
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
518 # store the full list of potential recipients (groups and contacts)
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
519 list_ = []
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 254
diff changeset
520 list_.append("@@")
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
521 list_.extend("@%s" % group for group in parent.host.contact_panel.getGroups())
624
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
522 list_.extend(contact for contact in parent.host.contact_list.roster_entities)
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
523 list_manager.ListManager.__init__(self, parent, composition.RECIPIENT_TYPES, list_, {'y': y_offset})
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
524
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
525 self.registerPopupMenuPanel(entries=composition.RECIPIENT_TYPES,
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
526 hide=lambda sender, key: self.__children[key]["panel"].isVisible(),
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 234
diff changeset
527 callback=self.setContactPanelVisible)
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
528
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
529
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
530 class EditTextArea(TextArea, KeyboardHandler):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
531 def __init__(self, _parent):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
532 TextArea.__init__(self)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
533 self._parent = _parent
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
534 KeyboardHandler.__init__(self)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
535 self.addKeyboardListener(self)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
536
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
537 def onKeyDown(self, sender=None, keycode=None, modifiers=None):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
538 for listener in self._parent.edit_listeners:
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
539 listener(self, keycode)