/// <summary> /// Remove the task tag on the line specified by the TextIter. This /// will not remove the "todo:" text (i.e., it will not modify the /// actual characters of the TextBuffer. /// <param name="iter">The TextIter specifying the line where the /// TaskTag should be removed.</param> /// <returns>True if a TaskTag was removed, otherwise False.</returns> /// </summary> bool RemoveTaskTagFromLine(Gtk.TextIter iter) { Gtk.TextIter start = iter; Gtk.TextIter end = iter; TaskTag task_tag = GetTaskTagFromLineIter(ref start); if (task_tag == null) { return(false); } while (start.StartsLine() == false) { start.BackwardChar(); } while (end.EndsLine() == false) { end.ForwardChar(); } // end.ForwardToLineEnd (); last_removed_tag = null; Buffer.RemoveTag(task_tag, start, end); return(true); }
public void Insert(ref Gtk.TextIter iter, string text) { IntPtr native = GLib.Marshaller.StringToPtrGStrdup(text); gtk_text_buffer_insert(Handle, ref iter, native, -1); GLib.Marshaller.Free(native); }
void CheckBufferSize() { if (_BufferLines == -1) { // no limit defined return; } if (Buffer.LineCount > _BufferLines) { Gtk.TextIter start_iter = Buffer.StartIter; // TODO: maybe we should delete chunks instead of each line Gtk.TextIter end_iter = Buffer.GetIterAtLine(Buffer.LineCount - _BufferLines); int offset = end_iter.Offset; Buffer.Delete(ref start_iter, ref end_iter); // update markerline offset if present if (_MarkerlineBufferPosition != 0) { _MarkerlineBufferPosition -= offset; // remove markerline if it went out of buffer if (_MarkerlineBufferPosition < 0) { _MarkerlineBufferPosition = 0; } } } }
void OnInsertText(object sender, Gtk.InsertTextArgs args) { Gtk.TextIter start = args.Pos; start.BackwardChars(args.Length); ApplyUrlToBlock(start, args.Pos); }
bool OnLinkTagActivated(NoteTag sender, NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end) { return(OpenOrCreateLink(start, end)); }
void ApplyWikiwordToBlock(Gtk.TextIter start, Gtk.TextIter end) { NoteBuffer.GetBlockExtents(ref start, ref end, 80 /* max wiki name */, broken_link_tag); Buffer.RemoveTag(broken_link_tag, start, end); for (Match match = regex.Match(start.GetText(end)); match.Success; match = match.NextMatch()) { System.Text.RegularExpressions.Group group = match.Groups [1]; Logger.Debug("Highlighting wikiword: '{0}' at offset {1}", group, group.Index); Gtk.TextIter start_cpy = start; start_cpy.ForwardChars(group.Index); end = start_cpy; end.ForwardChars(group.Length); if (Manager.Find(group.ToString()) == null) { Buffer.ApplyTag(broken_link_tag, start_cpy, end); } } }
void ApplyUrlToBlock(Gtk.TextIter start, Gtk.TextIter end) { NoteBuffer.GetBlockExtents(ref start, ref end, 256 /* max url length */, Note.TagTable.UrlTag); Buffer.RemoveTag(Note.TagTable.UrlTag, start, end); for (Match match = regex.Match(start.GetSlice(end)); match.Success; match = match.NextMatch()) { System.Text.RegularExpressions.Group group = match.Groups [1]; /* * Logger.Log ("Highlighting url: '{0}' at offset {1}", * group, * group.Index); */ Gtk.TextIter start_cpy = start; start_cpy.ForwardChars(group.Index); end = start_cpy; end.ForwardChars(group.Length); Buffer.ApplyTag(Note.TagTable.UrlTag, start_cpy, end); } }
public GtkSourceView.SourceMarker GetPrevMarker(Gtk.TextIter iter) { IntPtr raw_ret = gtk_source_buffer_get_prev_marker(Handle, ref iter); GtkSourceView.SourceMarker ret = GLib.Object.GetObject(raw_ret) as GtkSourceView.SourceMarker; return(ret); }
public bool NthSubregion(uint subregion, Gtk.TextIter start, Gtk.TextIter end) { bool raw_ret = gtk_text_region_nth_subregion(Handle, subregion, ref start, ref end); bool ret = raw_ret; return(ret); }
public override void Merge(EditAction action) { EraseAction erase = (EraseAction)action; if (start == erase.start) { end += erase.end - erase.start; chop.End = erase.chop.End; // Delete the marks, leave the text erase.chop.Destroy(); } else { start = erase.start; Gtk.TextIter chop_start = chop.Start; chop.Buffer.InsertRange(ref chop_start, erase.chop.Start, erase.chop.End); // Delete the marks and text erase.Destroy(); } }
void ApplyTag(string name, string variation, Gtk.TextIter start, Gtk.TextIter end, Action <Gtk.TextTag> apply) { var buffer = Control.Buffer; var prefix = name + "-"; var tagName = prefix + variation; var tagsToRemove = new List <Gtk.TextTag>(); buffer.TagTable.Foreach(t => { if (t.Name != null && t.Name.StartsWith(prefix, StringComparison.Ordinal)) { tagsToRemove.Add(t); } }); foreach (var removeTag in tagsToRemove) { buffer.RemoveTag(removeTag, start, end); } var tag = buffer.TagTable.Lookup(tagName); if (tag == null) { tag = new Gtk.TextTag(tagName); apply(tag); buffer.TagTable.Add(tag); } buffer.ApplyTag(tag, start, end); }
/// <summary> /// Get the existing template note or create a new one /// if it doesn't already exist. /// </summary> /// <returns> /// A <see cref="Note"/> /// </returns> public Note GetOrCreateTemplateNote() { Note template_note = Find(NoteTemplateTitle); if (template_note == null) { template_note = Create(NoteTemplateTitle, GetNoteTemplateContent(NoteTemplateTitle)); // Select the initial text NoteBuffer buffer = template_note.Buffer; Gtk.TextIter iter = buffer.GetIterAtLineOffset(2, 0); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); // Flag this as a template note Tag tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag); template_note.AddTag(tag); template_note.QueueSave(ChangeType.ContentChanged); } return(template_note); }
/// <summary> /// If the specified task is included inside this note, this /// handler will update the task's status representation. /// </summary> private void OnTaskStatusChanged(Task task) { if (task.OriginNoteUri == null || task.OriginNoteUri != Note.Uri) { return; } // Search through the note looking for the TaskTag so that it can // be updated // Iterate through the lines looking for tasks Gtk.TextIter iter = Buffer.StartIter; iter.ForwardLine(); // Move past the note's title do { TaskTag task_tag = (TaskTag) Buffer.GetDynamicTag("task", iter); if (task_tag != null) { if (task_tag.Uri != task.Uri) { continue; } task_tag.CompletionDate = task.CompletionDate; break; } } while (iter.ForwardLine()); }
/// <summary> /// If the deleted task is included inside this note, this /// handler removes the TextTag surrounding the task. /// </summary> private void OnTaskDeleted(TaskManager manager, Task task) { if (task.OriginNoteUri == null || task.OriginNoteUri != Note.Uri) { return; } // Search through the note looking for the TaskTag so that it can // be renamed // Iterate through the lines looking for tasks Gtk.TextIter iter = Buffer.StartIter; iter.ForwardLine(); // Move past the note's title do { TaskTag task_tag = (TaskTag) Buffer.GetDynamicTag("task", iter); if (task_tag != null) { if (task_tag.Uri != task.Uri) { continue; } RemoveTaskFromLine(ref iter); break; } } while (iter.ForwardLine()); }
public bool PrintRangeAsync(Gtk.TextIter start, Gtk.TextIter end) { bool raw_ret = gtk_source_print_job_print_range_async(Handle, ref start, ref end); bool ret = raw_ret; return(ret); }
public GtkSourceView.TextRegion Intersect(Gtk.TextIter _start, Gtk.TextIter _end) { IntPtr raw_ret = gtk_text_region_intersect(Handle, ref _start, ref _end); GtkSourceView.TextRegion ret = raw_ret == IntPtr.Zero ? null : (GtkSourceView.TextRegion)GLib.Opaque.GetOpaque(raw_ret, typeof(GtkSourceView.TextRegion), false); return(ret); }
public void Log(string msg) { Gtk.Application.Invoke((o, args) => { Gtk.TextIter it = textview.Buffer.EndIter; textview.Buffer.Insert(ref it, msg + "\n"); }); }
void DisplayText() { string[] ScoreBoard = new string[4]; Gtk.TextIter Ti = this.TextView.Buffer.StartIter; string[] Temp = { "1\t2\t3\t4", "1\t2\t3\t4", "1\t2\t3\t4", "1\t2\t3\t4", "1\t2\t3\t4", "1\t2\t3\t4", }; foreach (string Line in Temp) { ScoreBoard = Line.Split('\t'); this.ActivelyWaitFor(1000); this.TextView.Buffer.Insert(ref Ti, ScoreBoard[0]); this.TextView.Buffer.Insert(ref Ti, " | "); this.TextView.Buffer.Insert(ref Ti, ScoreBoard[1]); this.TextView.Buffer.Insert(ref Ti, "\t"); this.TextView.Buffer.Insert(ref Ti, ScoreBoard[2]); this.TextView.Buffer.Insert(ref Ti, " | "); this.TextView.Buffer.Insert(ref Ti, ScoreBoard[3]); this.TextView.Buffer.Insert(ref Ti, "\n"); } }
string GetUrl(Gtk.TextIter start, Gtk.TextIter end) { string url = start.GetSlice(end); // FIXME: Needed because the file match is greedy and // eats a leading space. url = url.Trim(); // Simple url massaging. Add to 'http://' to the front // of www.foo.com, 'mailto:' to [email protected], 'file://' // to /home/alex/foo. if (url.StartsWith("www.")) { url = "http://" + url; } else if (url.StartsWith("/") && url.LastIndexOf("/") > 1) { url = "file://" + url; } else if (url.StartsWith("~/")) { url = "file://" + Path.Combine(Environment.GetEnvironmentVariable("HOME"), url.Substring(2)); } else if (Regex.IsMatch(url, @"^(?!(news|mailto|http|https|ftp|file|irc):).+@.{2,}$", RegexOptions.IgnoreCase)) { url = "mailto:" + url; } return(url); }
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, " "); }
void ApplyUrlToBlock(Gtk.TextIter start, Gtk.TextIter end) { NoteBuffer.GetBlockExtents(ref start, ref end, 256 /* max url length */, Note.TagTable.UrlTag); Buffer.RemoveTag(Note.TagTable.UrlTag, start, end); Gtk.TextIter searchiter = start; for (Match match = regex.Match(start.GetSlice(end)); match.Success; match = match.NextMatch()) { System.Text.RegularExpressions.Group group = match.Groups [1]; /* * Logger.Log ("Highlighting url: '{0}' at offset {1}", * group, * group.Index); */ // Use the ForwardSearch instead of group's Index to account for multibyte chars in the text. // We'll search using the exact match value within provided boundaries. Gtk.TextIter startiter, enditer; searchiter.ForwardSearch(group.Value, Gtk.TextSearchFlags.VisibleOnly, out startiter, out enditer, end); searchiter = enditer; Buffer.ApplyTag(Note.TagTable.UrlTag, startiter, enditer); } }
static void AddAlternativeText(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, ImageMessagePartModel imgPart) { if (!String.IsNullOrEmpty(imgPart.AlternativeText)) { buffer.Insert(ref iter, imgPart.AlternativeText); } }
bool OpenOrCreateLink(Gtk.TextIter start, Gtk.TextIter end) { string link_name = start.GetText(end); Note link = Manager.Find(link_name); if (link == null) { Logger.Debug("Creating note '{0}'...", link_name); try { link = Manager.Create(link_name); } catch { // Fail silently. } } // FIXME: We used to also check here for (link != this.Note), but // somehow this was causing problems receiving clicks for the // wrong instance of a note (see bug #413234). Since a // link:internal tag is never applied around text that's the same // as the current note's title, it's safe to omit this check and // also works around the bug. if (link != null) { Logger.Debug("Opening note '{0}' on click...", link_name); link.Window.Present(); return(true); } return(false); }
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()); }
void Update() { Gtk.TextIter insert = Buffer.GetIterAtMark(Buffer.InsertMark); Gtk.TextIter selection = Buffer.GetIterAtMark(Buffer.SelectionBound); // FIXME: Handle middle-click paste when insert or // selection isn't on line 0, which means we won't know // about the edit. if (insert.Line == 0 || selection.Line == 0) { if (!editing_title) { editing_title = true; } Changed(); } else { if (editing_title) { Changed(); UpdateNoteTitle(); editing_title = false; } } }
/// <summary> /// Return the template Tomboy Note that corresponds with /// this Notebook. /// </summary> /// <returns> /// A <see cref="Note"/> /// </returns> public virtual Note GetTemplateNote() { NoteManager noteManager = Tomboy.DefaultNoteManager; Note note = noteManager.Find(templateNoteTitle); if (note == null) { note = noteManager.Create(templateNoteTitle, NoteManager.GetNoteTemplateContent(templateNoteTitle)); // Select the initial text NoteBuffer buffer = note.Buffer; Gtk.TextIter iter = buffer.GetIterAtLineOffset(2, 0); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); // Flag this as a template note Tag tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag); note.AddTag(tag); // Add on the notebook system tag so Tomboy // will persist the tag/notebook across sessions // if no other notes are added to the notebook. tag = TagManager.GetOrCreateSystemTag(NotebookTagPrefix + Name); note.AddTag(tag); note.QueueSave(ChangeType.ContentChanged); } return(note); }
protected override bool OnActivate(NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end) { Process p = new Process(); p.StartInfo.FileName = "evolution"; p.StartInfo.Arguments = EmailUri; p.StartInfo.UseShellExecute = false; try { p.Start(); } catch (Exception e) { string message = String.Format("Error running Evolution: {0}", e.Message); Logger.Error(message); HIGMessageDialog dialog = new HIGMessageDialog(editor.Toplevel as Gtk.Window, Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Info, Gtk.ButtonsType.Ok, Catalog.GetString("Cannot open email"), message); dialog.Run(); dialog.Destroy(); } return(true); }
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()); }
private void UpdateChatUsersGUI() { Gtk.Application.Invoke(delegate { usersview.Buffer.Text = ""; Gtk.TextIter iter = usersview.Buffer.EndIter; string text = src.Name + " (me)\n"; usersview.Buffer.InsertWithTagsByName(ref iter, text, src.Username); foreach (User u in dest.Keys) { text = u.Name + "\n"; usersview.Buffer.InsertWithTagsByName(ref iter, text, u.Username); } if (dest.Count == 1) { this.Title = "Chat - " + dest.First().Key.Name; } else { this.Title = "Group Chat"; } }); }
/// <summary> /// Remove the task from the line specified by the TextIter. This /// will remove the TextTag and also the "todo:" portion of the line /// so it will no longer be a task. The task summary text will be /// left on the line. /// <param name="iter">The TextIter specifying the line where the /// task should be removed.</param> /// <returns>True if a task was removed, otherwise False.</returns> /// </summary> bool RemoveTaskFromLine(ref Gtk.TextIter iter) { if (RemoveTaskTagFromLine(iter) == false) { return(false); } while (iter.StartsLine() == false) { iter.BackwardChar(); } Gtk.TextIter line_end = iter; while (line_end.EndsLine() == false) { line_end.ForwardChar(); } // line_end.ForwardToLineEnd (); string text = iter.GetText(line_end); Buffer.Delete(ref iter, ref line_end); text = GetTaskSummaryFromLine(text); if (text.Length > 0) { Buffer.Insert(ref iter, text); } return(true); }