Mercurial > libervia-web
annotate src/browser/sat_browser/editor_widget.py @ 712:bf562fb9c273
server_side: use Jinja2 template engine for static blog
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 13 Jul 2015 18:11:38 +0200 |
parents | c2f22ca12e23 |
children | 3b91225b457a |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
685 | 5 # Copyright (C) 2011, 2012, 2013, 2014, 2015 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
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:
323
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:
323
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:
323
diff
changeset
|
10 # (at your option) any later version. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
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:
323
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:
323
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:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
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:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
20 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
21 log = getLogger(__name__) |
467 | 22 from sat_frontends.tools import strings |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
23 |
33 | 24 from pyjamas.ui.HTML import HTML |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
25 from pyjamas.ui.SimplePanel import SimplePanel |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
26 from pyjamas.ui.TextArea import TextArea |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
27 from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_SHIFT, KEY_UP, KEY_DOWN, KeyboardHandler |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
28 from pyjamas.ui.FocusListener import FocusHandler |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
29 from pyjamas.ui.ClickListener import ClickHandler |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
30 from pyjamas.ui.MouseListener import MouseHandler |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
31 from pyjamas.Timer import Timer |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from pyjamas import DOM |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
33 |
467 | 34 import html_tools |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
35 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
36 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
37 class MessageBox(TextArea): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
38 """A basic text area for entering messages""" |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
39 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
40 def __init__(self, host): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
41 TextArea.__init__(self) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
42 self.host = host |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
43 self.size = (0, 0) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
44 self.setStyleName('messageBox') |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
45 self.addKeyboardListener(self) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
46 MouseHandler.__init__(self) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
47 self.addMouseListener(self) |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
48 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
49 def onBrowserEvent(self, event): |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
50 # XXX: woraroung a pyjamas bug: self.currentEvent is not set |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
51 # so the TextBox's cancelKey doens't work. This is a workaround |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
52 # FIXME: fix the bug upstream |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
53 self.currentEvent = event |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
54 TextArea.onBrowserEvent(self, event) |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
55 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
56 def onKeyPress(self, sender, keycode, modifiers): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
57 _txt = self.getText() |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
58 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
59 def history_cb(text): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
60 self.setText(text) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
61 Timer(5, lambda timer: self.setCursorPos(len(text))) |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
62 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
63 if keycode == KEY_ENTER: |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
64 if _txt: |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
65 self.host.selected_widget.onTextEntered(_txt) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
66 self.host._updateInputHistory(_txt) # FIXME: why using a global variable ? |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
67 self.setText('') |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
68 sender.cancelKey() |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
69 elif keycode == KEY_UP: |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
70 self.host._updateInputHistory(_txt, -1, history_cb) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
71 elif keycode == KEY_DOWN: |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
72 self.host._updateInputHistory(_txt, +1, history_cb) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
73 else: |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
74 self._onComposing() |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
75 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
76 def _onComposing(self): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
77 """Callback when the user is composing a text.""" |
684
e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents:
648
diff
changeset
|
78 self.host.selected_widget.chat_state_machine._onEvent("composing") |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
79 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
80 def onMouseUp(self, sender, x, y): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
81 size = (self.getOffsetWidth(), self.getOffsetHeight()) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
82 if size != self.size: |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
83 self.size = size |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
84 self.host.resize() |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
85 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
86 def onSelectedChange(self, selected): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
87 self._selected_cache = selected |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
88 |
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
89 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
90 class BaseTextEditor(object): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
91 """Basic definition of a text editor. The method edit gets a boolean parameter which |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
92 should be set to True when you want to edit the text and False to only display it.""" |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
93 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
94 def __init__(self, content=None, strproc=None, modifiedCb=None, afterEditCb=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
95 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
96 Remark when inheriting this class: since the setContent method could be |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
97 overwritten by the child class, you should consider calling this __init__ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
98 after all the parameters affecting this setContent method have been set. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
99 @param content: dict with at least a 'text' key |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
100 @param strproc: method to be applied on strings to clean the content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
101 @param modifiedCb: method to be called when the text has been modified. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
102 If this method returns: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
103 - True: the modification will be saved and afterEditCb called; |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
104 - False: the modification won't be saved and afterEditCb called; |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
105 - None: the modification won't be saved and afterEditCb not called. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
106 @param afterEditCb: method to be called when the edition is done |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
107 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
108 if content is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
109 content = {'text': ''} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
110 assert('text' in content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
111 if strproc is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
112 def strproc(text): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
113 try: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
114 return text.strip() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
115 except (TypeError, AttributeError): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
116 return text |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
117 self.strproc = strproc |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
118 self.__modifiedCb = modifiedCb |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
119 self._afterEditCb = afterEditCb |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
120 self.initialized = 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:
358
diff
changeset
|
121 self.edit_listeners = [] |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
122 self.setContent(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
123 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
124 def setContent(self, content=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
125 """Set the editable content. The displayed content, which is set from the child class, could differ. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
126 @param content: dict with at least a 'text' key |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
127 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
128 if content is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
129 content = {'text': ''} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
130 elif not isinstance(content, dict): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
131 content = {'text': content} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
132 assert('text' in content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
133 self._original_content = {} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
134 for key in content: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
135 self._original_content[key] = self.strproc(content[key]) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
136 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
137 def getContent(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
138 """Get the current edited or editable content. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
139 @return: dict with at least a 'text' key |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
140 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
141 raise NotImplementedError |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
142 |
395
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
143 def setOriginalContent(self, content): |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
144 """Use this method with care! Content initialization should normally be |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
145 done with self.setContent. This method exists to let you trick the editor, |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
146 e.g. for self.modified to return True also when nothing has been modified. |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
147 @param content: dict |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
148 """ |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
149 self._original_content = content |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
150 |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
151 def getOriginalContent(self): |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
152 """ |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
153 @return the original content before modification (dict) |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
154 """ |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
155 return self._original_content |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
156 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
157 def modified(self, content=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
158 """Check if the content has been modified. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
159 Remark: we don't use the direct comparison because we want to ignore empty elements |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
160 @content: content to be check against the original content or None to use the current content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
161 @return: True if the content has been modified. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
162 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
163 if content is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
164 content = self.getContent() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
165 # the following method returns True if one non empty element exists in a but not in b |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
166 diff1 = lambda a, b: [a[key] for key in set(a.keys()).difference(b.keys()) if a[key]] != [] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
167 # the following method returns True if the values for the common keys are not equals |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
168 diff2 = lambda a, b: [1 for key in set(a.keys()).intersection(b.keys()) if a[key] != b[key]] != [] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
169 # finally the combination of both to return True if a difference is found |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
170 diff = lambda a, b: diff1(a, b) or diff1(b, a) or diff2(a, b) |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
171 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
172 return diff(content, self._original_content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
173 |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
174 def edit(self, edit, abort=False): |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
175 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
176 Remark: the editor must be visible before you call this method. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
177 @param edit: set to True to edit the content or False to only display it |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
178 @param abort: set to True to cancel the edition and loose the changes. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
179 If edit and abort are both True, self.abortEdition can be used to ask for a |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
180 confirmation. When edit is False and abort is True, abortion is actually done. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
181 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
182 if edit: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
183 self.setFocus(True) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
184 if abort: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
185 content = self.getContent() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
186 if not self.modified(content) or self.abortEdition(content): # e.g: ask for confirmation |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
187 self.edit(False, True) |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
188 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
189 else: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
190 if not self.initialized: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
191 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
192 content = self.getContent() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
193 if abort: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
194 self._afterEditCb(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
195 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
196 if self.__modifiedCb and self.modified(content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
197 result = self.__modifiedCb(content) # e.g.: send a message or update something |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
198 if result is not None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
199 if self._afterEditCb: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
200 self._afterEditCb(content) # e.g.: restore the display mode |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
201 if result is True: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
202 self.setContent(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
203 elif self._afterEditCb: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
204 self._afterEditCb(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
205 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
206 self.initialized = True |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
207 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
208 def setFocus(self, focus): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
209 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
210 @param focus: set to True to focus the editor |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
211 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
212 raise NotImplementedError |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
213 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
214 def abortEdition(self, content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
215 return True |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
216 |
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:
358
diff
changeset
|
217 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:
358
diff
changeset
|
218 """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:
358
diff
changeset
|
219 @param listener: method taking two arguments: sender, keycode""" |
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
220 self.edit_listeners.append(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:
358
diff
changeset
|
221 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
222 |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
223 class SimpleTextEditor(BaseTextEditor, FocusHandler, KeyboardHandler, ClickHandler): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
224 """Base class for manage a simple text editor.""" |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
225 |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
226 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, options=None): |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
227 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
228 @param content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
229 @param modifiedCb |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
230 @param afterEditCb |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
231 @param options: dict with the following value: |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
232 - no_xhtml: set to True to clean any xhtml content. |
467 | 233 - enhance_display: if True, the display text will be enhanced with strings.addURLToText |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
234 - listen_keyboard: set to True to terminate the edition with <enter> or <escape>. |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
235 - listen_focus: set to True to terminate the edition when the focus is lost. |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
236 - listen_click: set to True to start the edition when you click on the widget. |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
237 """ |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
238 self.options = {'no_xhtml': False, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
239 'enhance_display': True, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
240 'listen_keyboard': True, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
241 'listen_focus': False, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
242 'listen_click': False |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
243 } |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
244 if options: |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
245 self.options.update(options) |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
246 self.__shift_down = False |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
247 if self.options['listen_focus']: |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
248 FocusHandler.__init__(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
249 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
250 ClickHandler.__init__(self) |
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:
358
diff
changeset
|
251 KeyboardHandler.__init__(self) |
468
830b50593597
browser_side: fixes issues from the refactoring
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
252 strproc = lambda text: html_tools.html_sanitize(html_tools.html_strip(text)) if self.options['no_xhtml'] else html_tools.html_strip(text) |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
253 BaseTextEditor.__init__(self, content, strproc, modifiedCb, afterEditCb) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
254 self.textarea = self.display = None |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
255 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
256 def setContent(self, content=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
257 BaseTextEditor.setContent(self, content) |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
258 |
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
259 def getContent(self): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
260 raise NotImplementedError |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
261 |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
262 def edit(self, edit, abort=False): |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
263 BaseTextEditor.edit(self, edit) |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
264 if edit: |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
265 if self.options['listen_focus'] and self not in self.textarea._focusListeners: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
266 self.textarea.addFocusListener(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
267 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
268 self.display.clearClickListener() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
269 if self not in self.textarea._keyboardListeners: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
270 self.textarea.addKeyboardListener(self) |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
271 else: |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
272 self.setDisplayContent() |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
273 if self.options['listen_focus']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
274 try: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
275 self.textarea.removeFocusListener(self) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
276 except ValueError: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
277 pass |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
278 if self.options['listen_click'] and self not in self.display._clickListeners: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
279 self.display.addClickListener(self) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
280 try: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
281 self.textarea.removeKeyboardListener(self) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
282 except ValueError: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
283 pass |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
284 |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
285 def setDisplayContent(self): |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
286 text = self._original_content['text'] |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
287 if not self.options['no_xhtml']: |
467 | 288 text = strings.addURLToImage(text) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
289 if self.options['enhance_display']: |
467 | 290 text = strings.addURLToText(text) |
291 self.display.setHTML(html_tools.convertNewLinesToXHTML(text)) | |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
292 |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
293 def setFocus(self, focus): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
294 raise NotImplementedError |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
295 |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
296 def onKeyDown(self, sender, keycode, modifiers): |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
297 for listener in self.edit_listeners: |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
298 listener(self.textarea, keycode) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
299 if not self.options['listen_keyboard']: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
300 return |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
301 if keycode == KEY_SHIFT or self.__shift_down: # allow input a new line with <shift> + <enter> |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
302 self.__shift_down = True |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
303 return |
412
9977de10b7da
browser_side: editors do not listen for <escape> + display WYSIWIG in upper case
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
304 if keycode == KEY_ENTER: # finish the edition |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
305 self.textarea.setFocus(False) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
306 if not self.options['listen_focus']: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
307 self.edit(False) |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
308 |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
309 def onKeyUp(self, sender, keycode, modifiers): |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
310 if keycode == KEY_SHIFT: |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
311 self.__shift_down = False |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
312 |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
313 def onLostFocus(self, sender): |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
314 """Finish the edition when focus is lost""" |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
315 if self.options['listen_focus']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
316 self.edit(False) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
317 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
318 def onClick(self, sender=None): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
319 """Start the edition when the widget is clicked""" |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
320 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
321 self.edit(True) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
322 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
323 def onBrowserEvent(self, event): |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
324 if self.options['listen_focus']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
325 FocusHandler.onBrowserEvent(self, event) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
326 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
327 ClickHandler.onBrowserEvent(self, event) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
328 KeyboardHandler.onBrowserEvent(self, event) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
329 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
330 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
331 class HTMLTextEditor(SimpleTextEditor, HTML, FocusHandler, KeyboardHandler): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
332 """Manage a simple text editor with the HTML 5 "contenteditable" property.""" |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
333 |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
334 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, options=None): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
335 HTML.__init__(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
336 SimpleTextEditor.__init__(self, content, modifiedCb, afterEditCb, options) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
337 self.textarea = self.display = self |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
338 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
339 def getContent(self): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
340 text = DOM.getInnerHTML(self.getElement()) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
341 return {'text': self.strproc(text) if text else ''} |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
342 |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
343 def edit(self, edit, abort=False): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
344 if edit: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
345 self.textarea.setHTML(self._original_content['text']) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
346 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false') |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
347 SimpleTextEditor.edit(self, edit, abort) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
348 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
349 def setFocus(self, focus): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
350 if focus: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
351 self.getElement().focus() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
352 else: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
353 self.getElement().blur() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
354 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
355 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
356 class LightTextEditor(SimpleTextEditor, SimplePanel, FocusHandler, KeyboardHandler): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
357 """Manage a simple text editor with a TextArea for editing, HTML for display.""" |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
358 |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
359 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, options=None): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
360 SimplePanel.__init__(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
361 SimpleTextEditor.__init__(self, content, modifiedCb, afterEditCb, options) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
362 self.textarea = TextArea() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
363 self.display = HTML() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
364 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
365 def getContent(self): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
366 text = self.textarea.getText() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
367 return {'text': self.strproc(text) if text else ''} |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
368 |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
369 def edit(self, edit, abort=False): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
370 if edit: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
371 self.textarea.setText(self._original_content['text']) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
372 self.setWidget(self.textarea if edit else self.display) |
696
c2f22ca12e23
browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
373 SimpleTextEditor.edit(self, edit, abort) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
374 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
375 def setFocus(self, focus): |
491
c97fe4059f71
browser side: fixes NS_ERROR_FAILURE while opening microblog panels (bug from rev 442 - changeset 17259c2ff96f in MicroblogPanel.refresh)
souliane <souliane@mailoo.org>
parents:
468
diff
changeset
|
376 if focus and self.isAttached(): |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
377 self.textarea.setCursorPos(len(self.textarea.getText())) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
378 self.textarea.setFocus(focus) |