Exemplo n.º 1
0
        private void InsertToBuffer(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, UrlMessagePartModel urlPart)
        {
            var linkText = urlPart.Text ?? urlPart.Url;

            Uri uri;

            try {
                uri = new Uri(urlPart.Url);
            } catch (UriFormatException ex) {
#if LOG4NET
                _Logger.Error("AddMessage(): Invalid URL: " + urlPart.Url, ex);
#endif
                buffer.Insert(ref iter, linkText);
                return;
            }

            var tags = new List <Gtk.TextTag>();
            // link URI tag
            var linkTag = new LinkTag(uri);
            linkTag.TextEvent += OnLinkTagTextEvent;
            _MessageTextTagTable.Add(linkTag);
            tags.Add(linkTag);

            // link style tag
            tags.Add(LinkTag);

            buffer.InsertWithTags(ref iter, linkText, tags.ToArray());
        }
Exemplo n.º 2
0
        public static bool IncludeRichText(Gdk.Atom targets, int n_targets, Gtk.TextBuffer buffer)
        {
            bool raw_ret = gtk_targets_include_rich_text(targets == null ? IntPtr.Zero : targets.Handle, n_targets, buffer == null ? IntPtr.Zero : buffer.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Exemplo n.º 3
0
        public bool TargetsIncludeRichText(Gtk.TextBuffer buffer)
        {
            bool raw_ret = gtk_selection_data_targets_include_rich_text(Handle, buffer == null ? IntPtr.Zero : buffer.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Exemplo n.º 4
0
        public static string ConvertEditCategorieToDatabse(Gtk.TextBuffer buffer)
        {
            StringBuilder dbBuilder = new StringBuilder(buffer.Text);

            // Replace tags of the textBuffer and save them as HTML-Tags
            int buildOffset = 0;

            for (Gtk.TextIter iter = buffer.StartIter; !iter.IsEnd; iter.ForwardChar())
            {
                if (iter.BeginsTag(boldTag))
                {
                    dbBuilder.Insert(iter.Offset + buildOffset, "<b>", 1);
                    buildOffset += 3;
                }
                else
                if (iter.BeginsTag(italicTag))
                {
                    dbBuilder.Insert(iter.Offset + buildOffset, "<i>", 1);
                    buildOffset += 3;
                }
                if (iter.EndsTag(boldTag))
                {
                    dbBuilder.Insert(iter.Offset + buildOffset, "</b>", 1);
                    buildOffset += 4;
                }
                if (iter.EndsTag(italicTag))
                {
                    dbBuilder.Insert(iter.Offset + buildOffset, "</i>", 1);
                    buildOffset += 4;
                }
            }
            dbBuilder.Replace("\n", "<br>");
            return(dbBuilder.ToString());
        }
        byte [] InvokeNative(Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter start, Gtk.TextIter end, out ulong length)
        {
            IntPtr  native_start = GLib.Marshaller.StructureToPtrAlloc(start);
            IntPtr  native_end   = GLib.Marshaller.StructureToPtrAlloc(end);
            UIntPtr native_length;
            IntPtr  result_ptr = native_cb(register_buffer == null ? IntPtr.Zero : register_buffer.Handle, content_buffer == null ? IntPtr.Zero : content_buffer.Handle, native_start, native_end, out native_length, __data);

            start = Gtk.TextIter.New(native_start);
            Marshal.FreeHGlobal(native_start);
            end = Gtk.TextIter.New(native_end);
            Marshal.FreeHGlobal(native_end);
            length = (ulong)native_length;

            byte [] result = null;
            if (length > 0 && result_ptr != IntPtr.Zero)
            {
                result = new byte [length];
                Marshal.Copy(result_ptr, result, 0, (int)length);
            }

            if (result_ptr != IntPtr.Zero)
            {
                GLib.Marshaller.Free(result_ptr);
            }

            return(result == null ? empty_byte_array : result);
        }
Exemplo n.º 6
0
        public bool WaitIsRichTextAvailable(Gtk.TextBuffer buffer)
        {
            bool raw_ret = gtk_clipboard_wait_is_rich_text_available(Handle, buffer == null ? IntPtr.Zero : buffer.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
Exemplo n.º 7
0
 static void AddAlternativeText(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, ImageMessagePartModel imgPart)
 {
     if (!String.IsNullOrEmpty(imgPart.AlternativeText))
     {
         buffer.Insert(ref iter, imgPart.AlternativeText);
     }
 }
Exemplo n.º 8
0
        protected override void InsertTimeStamp(Gtk.TextBuffer buffer, ref Gtk.TextIter iter,
                                                string timestamp, MessageModel msg)
        {
            if (String.IsNullOrWhiteSpace(msg.ID))
            {
                buffer.Insert(ref iter, timestamp);
            }
            else
            {
                var uri = new Uri(String.Format("https://twitter.com/{0}/status/{1}", msg.GetNick(), msg.ID));

                var tags = new List <Gtk.TextTag>();
                // link URI tag
                var linkTag = new LinkTag(uri);
                linkTag.TextEvent += OnLinkTagTextEvent;
                _MessageTextTagTable.Add(linkTag);
                tags.Add(linkTag);

                // link style tag
                tags.Add(LinkTag);

                buffer.InsertWithTags(ref iter, timestamp, tags.ToArray());
            }

            buffer.Insert(ref iter, " ");
        }
Exemplo n.º 9
0
        public TextTagEnumerator(Gtk.TextBuffer buffer, Gtk.TextTag tag)
        {
            this.buffer = buffer;
            this.tag    = tag;

            this.mark  = buffer.CreateMark(null, buffer.StartIter, true);
            this.range = new TextRange(buffer.StartIter, buffer.StartIter);
        }
Exemplo n.º 10
0
 public void RequestRichText(Gtk.TextBuffer buffer, RichTextReceivedFunc cb)
 {
     if (rt_rcvd_marshaler == null)
     {
         rt_rcvd_marshaler = new RichTextReceivedFuncNative(RichTextReceivedCallback);
     }
     gtk_clipboard_request_rich_text(Handle, buffer == null ? IntPtr.Zero : buffer.Handle, rt_rcvd_marshaler, (IntPtr)GCHandle.Alloc(cb));
 }
Exemplo n.º 11
0
 protected void RemoveSplitTags(Gtk.TextBuffer buffer)
 {
     foreach (TagData tag in splitTags)
     {
         Gtk.TextIter start = buffer.GetIterAtOffset(tag.start);
         Gtk.TextIter end   = buffer.GetIterAtOffset(tag.end);
         buffer.RemoveTag(tag.tag, start, end);
     }
 }
        public ForwardTextIterator(IDocumentInformation docInfo, Gtk.TextView document, int endOffset)
        {
            Debug.Assert(endOffset >= 0 && endOffset < BufferLength);

            this.docInfo = docInfo;
            this.textBuffer = document.Buffer;
            this.endOffset = endOffset;
            Reset();
        }
Exemplo n.º 13
0
 public SourceUndoManager(Gtk.TextBuffer buffer) : base(IntPtr.Zero)
 {
     if (GetType() != typeof(SourceUndoManager))
     {
         throw new InvalidOperationException("Can't override this constructor.");
     }
     owned = true;
     Raw   = gtk_source_undo_manager_new(buffer == null ? IntPtr.Zero : buffer.Handle);
 }
Exemplo n.º 14
0
        bool InvokeNative(Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter iter, byte[] data, ulong length, bool create_tags)
        {
            IntPtr native_iter = GLib.Marshaller.StructureToPtrAlloc(iter);
            IntPtr error       = IntPtr.Zero;
            bool   __result    = native_cb(register_buffer == null ? IntPtr.Zero : register_buffer.Handle, content_buffer == null ? IntPtr.Zero : content_buffer.Handle, native_iter, data, new UIntPtr(length), create_tags, __data, out error);

            Marshal.FreeHGlobal(native_iter);
            return(__result);
        }
Exemplo n.º 15
0
        public override string ToString()
        {
            XmlElement fields;
            string     fieldName;
            string     fieldValue;
            string     fieldPrefix = "field_";

            //récupération de tous les widgets à sauvegarder
            Gtk.Widget[] widgets = glade.GetWidgetPrefix(fieldPrefix);

            //si plusieurs alors créer un noeud racine
            if (widgets.Length > 0)
            {
                fields = xmlDoc.AddNode(null, "Fields", "");
            }
            else
            {
                return(xmlDoc.ToString());
            }

            //parcours des widgets et constitution du flux
            foreach (Gtk.Widget w in widgets)
            {
                //nom du champ
                StringBuilder name = new StringBuilder(w.Name);
                name.Remove(0, fieldPrefix.Length);
                fieldName = name.ToString();

                //récupération de la valeur en fonction du type de widget
                Type entryType    = typeof(Gtk.Entry);
                Type textViewType = typeof(Gtk.TextView);
                fieldValue = "";

                //Entry
                if (entryType.IsInstanceOfType(w))
                {
                    fieldValue = w.GetType().GetProperty("Text").GetValue(w, null).ToString();
                    Console.WriteLine("lecture entry = " + fieldValue);
                }

                //TextView
                if (textViewType.IsInstanceOfType(w))
                {
                    Gtk.TextBuffer buffer = ((Gtk.TextBuffer)w.GetType().GetProperty("Buffer").GetValue(w, null));
                    fieldValue = buffer.GetType().GetProperty("Text").GetValue(buffer, null).ToString();
                    Console.WriteLine("lecture textview = " + fieldValue);
                }

                XmlElement field = xmlDoc.AddNode(fields, "Field", fieldValue);
                xmlDoc.AddAttributeNode(field, "name", fieldName);
            }

            Console.WriteLine("content = " + xmlDoc.ToString());

            return(xmlDoc.ToString());
        }
Exemplo n.º 16
0
        public void Redo(Gtk.TextBuffer buffer)
        {
            Gtk.TextIter start_iter, end_iter;
            start_iter = buffer.GetIterAtOffset(start);
            end_iter   = buffer.GetIterAtOffset(end);

            buffer.MoveMark(buffer.SelectionBound, start_iter);
            buffer.RemoveTag(tag, start_iter, end_iter);
            buffer.MoveMark(buffer.InsertMark, end_iter);
        }
Exemplo n.º 17
0
        public override void Redo(Gtk.TextBuffer buffer)
        {
            RemoveSplitTags(buffer);

            Gtk.TextIter start_iter = buffer.GetIterAtOffset(start);
            Gtk.TextIter end_iter   = buffer.GetIterAtOffset(end);
            buffer.Delete(ref start_iter, ref end_iter);
            buffer.MoveMark(buffer.InsertMark, buffer.GetIterAtOffset(start));
            buffer.MoveMark(buffer.SelectionBound, buffer.GetIterAtOffset(start));
        }
Exemplo n.º 18
0
        public InsertBugAction(Gtk.TextIter start,
                               string id,
                               Gtk.TextBuffer buffer,
                               BugzillaLink tag)
        {
            Tag = tag;
            Id  = id;

            Offset = start.Offset;
        }
 public EditableTextView ()
 {
     this.Build ();
     buffer = new Gtk.TextBuffer (TrackTagTable.Instance);
     textview = new Gtk.TextView (buffer);
     textview.WrapMode = Gtk.WrapMode.WordChar;
     scrolledwindow.Add (textview);
     this.ShowAll ();
     this.isEditable = false;
 }
Exemplo n.º 20
0
        void AddEmoji(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, ImageMessagePartModel imgPart, string shortName)
        {
            var unicode = Emojione.ShortnameToUnicode(shortName);

            if (unicode == null)
            {
                AddAlternativeText(buffer, ref iter, imgPart);
                return;
            }

            // A mark here serves two pusposes. One is to allow us to apply the
            // tag across the pixbuf. It also lets us know later where to put
            // the pixbuf if we need to load it from the network
            var mark = new Gtk.TextMark(null, true);

            buffer.AddMark(mark, iter);

            var    emojiName = unicode + ".png";
            string emojiPath;

            if (EmojiCache.TryGetIcon("emojione", emojiName, out emojiPath))
            {
                var emojiFile = new FileInfo(emojiPath);
                if (emojiFile.Exists && emojiFile.Length > 0)
                {
                    AddEmoji(buffer, ref iter, imgPart, shortName, mark, emojiPath);
                }
                else
                {
                    AddAlternativeText(buffer, ref iter, imgPart);
                }

                return;
            }

            var emojiUrl = Emojione.UnicodeToUrl(unicode);

            EmojiCache.BeginDownloadFile("emojione", emojiName, emojiUrl,
                                         (path) => {
                GLib.Idle.Add(delegate {
                    var markIter = buffer.GetIterAtMark(mark);
                    AddEmoji(buffer, ref markIter, imgPart, shortName, mark, path);
                    return(false);
                });
            },
                                         (ex) => {
                GLib.Idle.Add(delegate {
                    var markIter = buffer.GetIterAtMark(mark);
                    buffer.DeleteMark(mark);
                    AddAlternativeText(buffer, ref markIter, imgPart);
                    return(false);
                });
            }
                                         );
        }
Exemplo n.º 21
0
        public override void Redo(Gtk.TextBuffer buffer)
        {
            RemoveSplitTags(buffer);

            Gtk.TextIter idx_iter = buffer.GetIterAtOffset(index);
            buffer.InsertRange(ref idx_iter, chop.Start, chop.End);

            buffer.MoveMark(buffer.SelectionBound, buffer.GetIterAtOffset(index));
            buffer.MoveMark(buffer.InsertMark,
                            buffer.GetIterAtOffset(index + chop.Length));
        }
Exemplo n.º 22
0
        public ProbeLogDlg(Radionic radionic)
        {
            this.Build ();

            logBuff = textviewLog.Buffer;
            Port = "";

            this.radionic = radionic;

            probeStart ();
        }
Exemplo n.º 23
0
        protected void ApplySplitTags(Gtk.TextBuffer buffer)
        {
            foreach (TagData tag in splitTags)
            {
                int offset = GetSplitOffset();

                Gtk.TextIter start = buffer.GetIterAtOffset(tag.start - offset);
                Gtk.TextIter end   = buffer.GetIterAtOffset(tag.end - offset);
                buffer.ApplyTag(tag.tag, start, end);
            }
        }
Exemplo n.º 24
0
        public void Redo(Gtk.TextBuffer buffer)
        {
            Gtk.TextIter iter = buffer.GetIterAtOffset(offset);

            buffer.Insert(ref iter, "\n");

            ((NoteBuffer)buffer).InsertBullet(ref iter, depth, direction);

            buffer.MoveMark(buffer.InsertMark, iter);
            buffer.MoveMark(buffer.SelectionBound, iter);
        }
        byte[] InvokeNative(Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter start, Gtk.TextIter end)
        {
            IntPtr  native_start = GLib.Marshaller.StructureToPtrAlloc(start);
            IntPtr  native_end   = GLib.Marshaller.StructureToPtrAlloc(end);
            UIntPtr native_length;

            byte[] __result = (byte[])GLib.Marshaller.ArrayPtrToArray(native_cb(register_buffer == null ? IntPtr.Zero : register_buffer.Handle, content_buffer == null ? IntPtr.Zero : content_buffer.Handle, native_start, native_end, out native_length, __data), typeof(byte), (int)(ulong)native_length, true);
            Marshal.FreeHGlobal(native_start);
            Marshal.FreeHGlobal(native_end);
            return(__result);
        }
Exemplo n.º 26
0
        public MessageTextView()
        {
            Trace.Call();

            _MessageTextTagTable = BuildTagTable();
            _ThemeSettings       = new ThemeSettings();

            Buffer             = new Gtk.TextBuffer(_MessageTextTagTable);
            MotionNotifyEvent += OnMotionNotifyEvent;
            PopulatePopup     += OnPopulatePopup;
            ExposeEvent       += OnExposeEvent;
        }
Exemplo n.º 27
0
        public TextRange(Gtk.TextIter start,
                         Gtk.TextIter end)
        {
            if (start.Buffer != end.Buffer)
            {
                throw new Exception("Start buffer and end buffer do not match");
            }

            buffer     = start.Buffer;
            start_mark = buffer.CreateMark(null, start, true);
            end_mark   = buffer.CreateMark(null, end, true);
        }
Exemplo n.º 28
0
        public override void Undo(Gtk.TextBuffer buffer)
        {
            int tag_images = GetSplitOffset();

            Gtk.TextIter start_iter = buffer.GetIterAtOffset(index - tag_images);
            Gtk.TextIter end_iter   = buffer.GetIterAtOffset(index - tag_images + chop.Length);
            buffer.Delete(ref start_iter, ref end_iter);
            buffer.MoveMark(buffer.InsertMark, buffer.GetIterAtOffset(index - tag_images));
            buffer.MoveMark(buffer.SelectionBound, buffer.GetIterAtOffset(index - tag_images));

            ApplySplitTags(buffer);
        }
Exemplo n.º 29
0
 void ListAll(Gtk.TextBuffer t, System.Uri path)
 {
     GLib.File f = FileFactory.NewForUri(path);
     foreach (GLib.FileInfo info in f.EnumerateChildren("*", FileQueryInfoFlags.None, null))
     {
         t.Text += new System.Uri(path, info.Name).ToString() + Environment.NewLine;
         if (info.FileType == FileType.Directory)
         {
             ListAll(t, new System.Uri(path, info.Name + "/"));
         }
     }
 }
Exemplo n.º 30
0
        public override void Undo(Gtk.TextBuffer buffer)
        {
            // Tag images change the offset by one, but only when deleting.
            Gtk.TextIter start_iter = buffer.GetIterAtOffset(Offset);
            Gtk.TextIter end_iter   = buffer.GetIterAtOffset(Offset + chop.Length + 1);
            buffer.Delete(ref start_iter, ref end_iter);
            buffer.MoveMark(buffer.InsertMark, buffer.GetIterAtOffset(Offset));
            buffer.MoveMark(buffer.SelectionBound, buffer.GetIterAtOffset(Offset));

            Tag.WidgetLocation = null;

            ApplySplitTags(buffer);
        }
Exemplo n.º 31
0
        public override void Redo(Gtk.TextBuffer buffer)
        {
            RemoveSplitTags(buffer);

            Gtk.TextIter cursor = buffer.GetIterAtOffset(Offset);

            Gtk.TextTag[] tags = { Tag };
            buffer.InsertWithTags(ref cursor, Id, tags);

            buffer.MoveMark(buffer.SelectionBound, buffer.GetIterAtOffset(Offset));
            buffer.MoveMark(buffer.InsertMark,
                            buffer.GetIterAtOffset(Offset + chop.Length));
        }
Exemplo n.º 32
0
        public void Undo(Gtk.TextBuffer buffer)
        {
            Gtk.TextIter iter = buffer.GetIterAtOffset(offset);
            iter.ForwardLine();
            iter = buffer.GetIterAtLine(iter.Line);

            ((NoteBuffer)buffer).RemoveBullet(ref iter);

            iter.ForwardToLineEnd();

            buffer.MoveMark(buffer.InsertMark, iter);
            buffer.MoveMark(buffer.SelectionBound, iter);
        }
        // Creates a new note with the given title and guid with body based on
        // the template note.
        private Note CreateNoteFromTemplate(string title, Note template_note, string guid)
        {
            Tag template_save_title = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSaveTitleSystemTag);

            if (template_note.ContainsTag(template_save_title))
            {
                title = GetUniqueName(template_note.Title, notes.Count);
            }

            // Use the body from the template note
            string xml_content =
                template_note.XmlContent.Replace(XmlEncoder.Encode(template_note.Title),
                                                 XmlEncoder.Encode(title));

            xml_content = SanitizeXmlContent(xml_content);

            Note new_note = CreateNewNote(title, xml_content, guid);

            // Copy template note's properties
            Tag template_save_size = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSaveSizeSystemTag);

            if (template_note.Data.HasExtent() && template_note.ContainsTag(template_save_size))
            {
                new_note.Data.Height = template_note.Data.Height;
                new_note.Data.Width  = template_note.Data.Width;
            }

            Tag template_save_selection = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSaveSelectionSystemTag);

            if (template_note.Data.CursorPosition > 0 && template_note.ContainsTag(template_save_selection))
            {
                Gtk.TextBuffer buffer = new_note.Buffer;
                Gtk.TextIter   iter;

                // Because the titles will be different between template and
                // new note, we can't just drop the cursor at template's
                // CursorPosition. Whitespace after the title makes this more
                // complicated so let's just start counting from the line after the title.
                int title_offset_difference = buffer.GetIterAtLine(1).Offset - template_note.Buffer.GetIterAtLine(1).Offset;

                iter = buffer.GetIterAtOffset(template_note.Data.CursorPosition + title_offset_difference);
                buffer.PlaceCursor(iter);

                iter = buffer.GetIterAtOffset(template_note.Data.SelectionBoundPosition + title_offset_difference);
                buffer.MoveMark(buffer.SelectionBound.Name, iter);
            }

            return(new_note);
        }
Exemplo n.º 34
0
        public MessageTextView()
        {
            Trace.Call();

            _MessageTextTagTable = BuildTagTable();
            _ThemeSettings = new ThemeSettings();

            Buffer = new Gtk.TextBuffer(_MessageTextTagTable);
            MotionNotifyEvent += OnMotionNotifyEvent;
            PopulatePopup += OnPopulatePopup;
            ExposeEvent += OnExposeEvent;
            Realized += delegate {
                CheckStyle();
            };
            StyleSet += delegate(object o, Gtk.StyleSetArgs args) {
                if (!IsRealized) {
                    // HACK: avoid GTK+ crash in gtk_text_attributes_copy_values()
                    return;
                }
                CheckStyle();
            };
        }
 public override void Initialize()
 {
     Widget = new Gtk.TextView ();
     Widget.Show ();
     Buffer = Widget.Buffer;
 }
Exemplo n.º 36
0
        public MessageTextView()
        {
            Trace.Call();

            _MessageTextTagTable = BuildTagTable();
            _ThemeSettings = new ThemeSettings();

            Buffer = new Gtk.TextBuffer(_MessageTextTagTable);
            MotionNotifyEvent += OnMotionNotifyEvent;
            PopulatePopup += OnPopulatePopup;
            ExposeEvent += OnExposeEvent;
        }