~ubuntu-branches/ubuntu/lucid/tomboy/lucid-proposed

« back to all changes in this revision

Viewing changes to Tomboy/NoteBuffer.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-28 14:11:49 UTC
  • mfrom: (1.3.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100128141149-snoxliun1ta8x8d2
Tags: 1.1.1-0ubuntu1
* New upstream version
* debian/control.in:
  - build-depends on cdbs to get strip-schema installed
  - updated cli build-depends for the new binary changes
* debian/rules:
  - set gettext domain in the desktop entry and run strip-schema on build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
using System;
3
3
using System.Collections.Generic;
 
4
using System.Reflection;
4
5
using System.IO;
5
6
using System.Xml;
 
7
using System.Xml.XPath;
 
8
using System.Xml.Xsl;
6
9
 
7
10
namespace Tomboy
8
11
{
48
51
                        }
49
52
                }
50
53
 
 
54
                private static bool text_buffer_serialize_func_fixed = typeof(Gtk.TextBufferSerializeFunc).GetMethod ("Invoke").ReturnType == typeof(byte[]);
 
55
 
51
56
                public NoteBuffer (Gtk.TextTagTable tags, Note note)
52
57
: base (tags)
53
58
                {
 
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"));
 
62
                        }
 
63
 
54
64
                        active_tags = new List<Gtk.TextTag> ();
55
65
                        undo_manager = new UndoManager (this);
56
66
 
68
78
                        this.note = note;
69
79
                }
70
80
 
 
81
                private static XslTransform html_transform;
 
82
                private static XslTransform HtmlTransform {
 
83
                        get {
 
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);
 
89
                                        reader.Close ();
 
90
                                }
 
91
                                return html_transform;
 
92
                        }
 
93
                }
 
94
 
 
95
                private byte [] SerializeToHtml (Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter start, Gtk.TextIter end, out ulong length)
 
96
                {
 
97
                        if (start.Equals (end) || start.Equals (Gtk.TextIter.Zero) || end.Equals (Gtk.TextIter.Zero) || HtmlTransform == null) {
 
98
                                length = 0;
 
99
                                return new byte [0];
 
100
                        }
 
101
 
 
102
                        Logger.Debug ("Handling text/html Clipboard copy/cut request");
 
103
                        var xsl = HtmlTransform;
 
104
 
 
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)
 
108
                        );
 
109
 
 
110
                        var reader = new StringReader (xml);
 
111
                        var doc = new XPathDocument (reader);
 
112
                        var args = new XsltArgumentList ();
 
113
 
 
114
                        var writer = new StringWriter ();
 
115
                        xsl.Transform (doc, args, writer);
 
116
 
 
117
                        string html = writer.ToString ();
 
118
                        byte [] bytes = System.Text.Encoding.UTF8.GetBytes (html);
 
119
                        length = (ulong)bytes.Length;
 
120
                        return bytes;
 
121
                }
 
122
 
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.