[kupfer] plugin.notes: Implement AppendToNote losslessly
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] plugin.notes: Implement AppendToNote losslessly
- Date: Fri, 28 Aug 2009 17:27:23 +0000 (UTC)
commit 021d1c55f448f77a2bda49f8762fb7f0ba7beeb6
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Aug 28 18:58:17 2009 +0200
plugin.notes: Implement AppendToNote losslessly
Use Get/SetNoteCompleteXml to append text to the notes losslessly. We
do no XML parsing, we simply replace the endtag by the escaped text to
be inserted and endtag again.
In Gnote, this performs AppendToNote losslessly
kupfer/plugin/notes.py | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/kupfer/plugin/notes.py b/kupfer/plugin/notes.py
index 9bb151d..b97b90a 100644
--- a/kupfer/plugin/notes.py
+++ b/kupfer/plugin/notes.py
@@ -5,6 +5,7 @@ they support the same DBus protocol. This plugin takes this assumption.
import os
import time
+import xml.sax.saxutils
import dbus
import xdg.BaseDirectory as base
@@ -70,14 +71,16 @@ class AppendToNote (Action):
Action.__init__(self, _("Append to Note..."))
def activate(self, leaf, iobj):
- notes = _get_notes_interface()
+ notes = _get_notes_interface(activate=True)
noteuri = iobj.object
text = leaf.object
- # NOTE: We could append using the Note's XML content, but
- # it does not always work
- contents = notes.GetNoteContents(noteuri)
- contents += u"\n%s" % text
- notes.SetNoteContents(noteuri, contents)
+
+ # NOTE: We search and replace in the XML here
+ xmlcontents = notes.GetNoteCompleteXml(noteuri)
+ endtag = u"</note-content>"
+ xmltext = xml.sax.saxutils.escape(text)
+ xmlcontents = xmlcontents.replace(endtag, u"\n%s%s" % (xmltext, endtag))
+ notes.SetNoteCompleteXml(noteuri, xmlcontents)
def item_types(self):
yield TextLeaf
@@ -86,7 +89,7 @@ class AppendToNote (Action):
def object_types(self):
yield Note
def get_description(self):
- return _("Append text (note may lose formatting)")
+ return _("Add text to existing note")
def get_icon_name(self):
return "gtk-add"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]