54
private static bool text_buffer_serialize_func_fixed = typeof(Gtk.TextBufferSerializeFunc).GetMethod ("Invoke").ReturnType == typeof(byte[]);
51
56
public NoteBuffer (Gtk.TextTagTable tags, Note note)
59
// Ensure Gtk# has the fix for BNC #555495
60
if (text_buffer_serialize_func_fixed) {
61
RegisterSerializeFormat ("text/html", (Gtk.TextBufferSerializeFunc) Delegate.CreateDelegate (typeof(Gtk.TextBufferSerializeFunc), this, "SerializeToHtml"));
54
64
active_tags = new List<Gtk.TextTag> ();
55
65
undo_manager = new UndoManager (this);
81
private static XslTransform html_transform;
82
private static XslTransform HtmlTransform {
84
if (html_transform == null) {
85
html_transform = new XslTransform ();
86
var resource = typeof(NoteBuffer).Assembly.GetManifestResourceStream ("tomboy-note-clipboard-html.xsl");
87
var reader = new XmlTextReader (resource);
88
html_transform.Load (reader, null, null);
91
return html_transform;
95
private byte [] SerializeToHtml (Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter start, Gtk.TextIter end, out ulong length)
97
if (start.Equals (end) || start.Equals (Gtk.TextIter.Zero) || end.Equals (Gtk.TextIter.Zero) || HtmlTransform == null) {
102
Logger.Debug ("Handling text/html Clipboard copy/cut request");
103
var xsl = HtmlTransform;
105
string xml = String.Format (
106
"<note version=\"0.3\" xmlns:link=\"http://beatniksoftware.com/tomboy/link\" xmlns:size=\"http://beatniksoftware.com/tomboy/size\">{0}</note>",
107
NoteBufferArchiver.Serialize (register_buffer, start, end)
110
var reader = new StringReader (xml);
111
var doc = new XPathDocument (reader);
112
var args = new XsltArgumentList ();
114
var writer = new StringWriter ();
115
xsl.Transform (doc, args, writer);
117
string html = writer.ToString ();
118
byte [] bytes = System.Text.Encoding.UTF8.GetBytes (html);
119
length = (ulong)bytes.Length;
71
123
// Signal that text has been inserted, and any active tags have
72
124
// been applied to the text. This allows undo to pull any
73
125
// active tags from the inserted text.