comparison src/browser/sat_browser/editor_widget.py @ 696:c2f22ca12e23

browser and server side: remove unibox
author souliane <souliane@mailoo.org>
date Mon, 20 Apr 2015 08:51:25 +0200
parents 9877607c719a
children 3b91225b457a
comparison
equal deleted inserted replaced
695:e86490a7c76e 696:c2f22ca12e23
169 # finally the combination of both to return True if a difference is found 169 # finally the combination of both to return True if a difference is found
170 diff = lambda a, b: diff1(a, b) or diff1(b, a) or diff2(a, b) 170 diff = lambda a, b: diff1(a, b) or diff1(b, a) or diff2(a, b)
171 171
172 return diff(content, self._original_content) 172 return diff(content, self._original_content)
173 173
174 def edit(self, edit, abort=False, sync=False): 174 def edit(self, edit, abort=False):
175 """ 175 """
176 Remark: the editor must be visible before you call this method. 176 Remark: the editor must be visible before you call this method.
177 @param edit: set to True to edit the content or False to only display it 177 @param edit: set to True to edit the content or False to only display it
178 @param abort: set to True to cancel the edition and loose the changes. 178 @param abort: set to True to cancel the edition and loose the changes.
179 If edit and abort are both True, self.abortEdition can be used to ask for a 179 If edit and abort are both True, self.abortEdition can be used to ask for a
180 confirmation. When edit is False and abort is True, abortion is actually done. 180 confirmation. When edit is False and abort is True, abortion is actually done.
181 @param sync: set to True to cancel the edition after the content has been saved somewhere else
182 """ 181 """
183 if edit: 182 if edit:
184 if not self.initialized:
185 self.syncToEditor() # e.g.: use the selected target and unibox content
186 self.setFocus(True) 183 self.setFocus(True)
187 if abort: 184 if abort:
188 content = self.getContent() 185 content = self.getContent()
189 if not self.modified(content) or self.abortEdition(content): # e.g: ask for confirmation 186 if not self.modified(content) or self.abortEdition(content): # e.g: ask for confirmation
190 self.edit(False, True, sync) 187 self.edit(False, True)
191 return 188 return
192 if sync:
193 self.syncFromEditor(content) # e.g.: save the content to unibox
194 return
195 else: 189 else:
196 if not self.initialized: 190 if not self.initialized:
197 return 191 return
198 content = self.getContent() 192 content = self.getContent()
199 if abort: 193 if abort:
214 def setFocus(self, focus): 208 def setFocus(self, focus):
215 """ 209 """
216 @param focus: set to True to focus the editor 210 @param focus: set to True to focus the editor
217 """ 211 """
218 raise NotImplementedError 212 raise NotImplementedError
219
220 def syncToEditor(self):
221 pass
222
223 def syncFromEditor(self, content):
224 pass
225 213
226 def abortEdition(self, content): 214 def abortEdition(self, content):
227 return True 215 return True
228 216
229 def addEditListener(self, listener): 217 def addEditListener(self, listener):
269 BaseTextEditor.setContent(self, content) 257 BaseTextEditor.setContent(self, content)
270 258
271 def getContent(self): 259 def getContent(self):
272 raise NotImplementedError 260 raise NotImplementedError
273 261
274 def edit(self, edit, abort=False, sync=False): 262 def edit(self, edit, abort=False):
275 BaseTextEditor.edit(self, edit) 263 BaseTextEditor.edit(self, edit)
276 if edit: 264 if edit:
277 if self.options['listen_focus'] and self not in self.textarea._focusListeners: 265 if self.options['listen_focus'] and self not in self.textarea._focusListeners:
278 self.textarea.addFocusListener(self) 266 self.textarea.addFocusListener(self)
279 if self.options['listen_click']: 267 if self.options['listen_click']:
350 338
351 def getContent(self): 339 def getContent(self):
352 text = DOM.getInnerHTML(self.getElement()) 340 text = DOM.getInnerHTML(self.getElement())
353 return {'text': self.strproc(text) if text else ''} 341 return {'text': self.strproc(text) if text else ''}
354 342
355 def edit(self, edit, abort=False, sync=False): 343 def edit(self, edit, abort=False):
356 if edit: 344 if edit:
357 self.textarea.setHTML(self._original_content['text']) 345 self.textarea.setHTML(self._original_content['text'])
358 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false') 346 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false')
359 SimpleTextEditor.edit(self, edit, abort, sync) 347 SimpleTextEditor.edit(self, edit, abort)
360 348
361 def setFocus(self, focus): 349 def setFocus(self, focus):
362 if focus: 350 if focus:
363 self.getElement().focus() 351 self.getElement().focus()
364 else: 352 else:
376 364
377 def getContent(self): 365 def getContent(self):
378 text = self.textarea.getText() 366 text = self.textarea.getText()
379 return {'text': self.strproc(text) if text else ''} 367 return {'text': self.strproc(text) if text else ''}
380 368
381 def edit(self, edit, abort=False, sync=False): 369 def edit(self, edit, abort=False):
382 if edit: 370 if edit:
383 self.textarea.setText(self._original_content['text']) 371 self.textarea.setText(self._original_content['text'])
384 self.setWidget(self.textarea if edit else self.display) 372 self.setWidget(self.textarea if edit else self.display)
385 SimpleTextEditor.edit(self, edit, abort, sync) 373 SimpleTextEditor.edit(self, edit, abort)
386 374
387 def setFocus(self, focus): 375 def setFocus(self, focus):
388 if focus and self.isAttached(): 376 if focus and self.isAttached():
389 self.textarea.setCursorPos(len(self.textarea.getText())) 377 self.textarea.setCursorPos(len(self.textarea.getText()))
390 self.textarea.setFocus(focus) 378 self.textarea.setFocus(focus)