示例#1
1
		// Inserts a piece of text into the buffer, giving it the usual
		// appearance of a hyperlink in a web browser: blue and underlined.
		// Additionally, attaches some data on the tag, to make it recognizable
		// as a link.
		void InsertLink (TextBuffer buffer, ref TextIter iter, string text, int page)
		{
			TextTag tag = new TextTag (null);
			tag.Foreground = "blue";
			tag.Underline = Pango.Underline.Single;
			tag_pages [tag] = page;
			buffer.TagTable.Add (tag);
			buffer.InsertWithTags (ref iter, text, tag);
		}
示例#2
1
        public TalkView()
            : base(new TextBuffer(null))
        {
            CursorVisible = false;
            Editable = false;
            WrapMode = WrapMode.WordChar;

            lastMessage = DateTime.MinValue;

            normalCursor = new Gdk.Cursor(Gdk.CursorType.Xterm);
            handCursor = new Gdk.Cursor(Gdk.CursorType.Hand2);

            TextTag tag;
            tag = new TextTag("status");
            tag.Foreground = "darkgrey";
            tag.Weight = Pango.Weight.Bold;
            Buffer.TagTable.Add(tag);

            tag = new TextTag("error");
            tag.Foreground = "dark red";
            Buffer.TagTable.Add(tag);

            tag = new TextTag("time");
            tag.Foreground = "darkgrey";
            tag.Justification = Justification.Center;
            Buffer.TagTable.Add(tag);

            linkTag = new TextTag("link");
            linkTag.Foreground = "blue";
            linkTag.Underline = Pango.Underline.Single;
            Buffer.TagTable.Add(linkTag);

            tag = new TextTag("nick-self");
            tag.Foreground = "sea green";
            tag.Weight = Pango.Weight.Bold;
            Buffer.TagTable.Add(tag);

            tag = new TextTag("nick-other");
            tag.Foreground = "skyblue4";
            tag.Weight = Pango.Weight.Bold;
            Buffer.TagTable.Add(tag);

            endIter = Buffer.GetIterAtOffset(0);
            endMark = Buffer.CreateMark("end", endIter, true);
        }
示例#3
0
    public void PreviousWord(object o, EventArgs args)
    {
        if (startWordIter.Equal(Gtk.TextIter.Zero))
        {
            startWordIter = textBuffer.StartIter;
        }
        endWordIter = startWordIter;

        while (startWordIter.BackwardChar() && !startWordIter.StartsWord())
        {
        }

        curWord = startWordIter.GetText(endWordIter);

        curWord = Regex.Replace(curWord, @"--", "", RegexOptions.Multiline);
        curWord = curWord.TrimStart(new char[5] {
            ' ', '\n', '\t', '\r', '-'
        });
        curWord = curWord.TrimEnd(new char[5] {
            ' ', '\n', '\t', '\r', '-'
        });
        curWord = Regex.Replace(curWord, @"\s+", " ", RegexOptions.Multiline);
        //Console.WriteLine("Word: \"" + curWord +"\"");
        ShowWord(curWord);
        HilightWord();
        slideLock    = true;
        slider.Value = endWordIter.Offset;
        slideLock    = false;
    }
示例#4
0
 public void Log(string msg)
 {
     Gtk.Application.Invoke(delegate {
         Gtk.TextIter it = textview.Buffer.EndIter;
         textview.Buffer.Insert(ref it, msg + "\n");
     });
 }
示例#5
0
        void ApplyTag(string prefix, string variation, Gtk.TextIter start, Gtk.TextIter end, Action <Gtk.TextTag> apply)
        {
            var buffer       = Control.Buffer;
            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);
        }
示例#6
0
    public void HilightWord()
    {
        Gtk.TextIter prevEndCharIter = new Gtk.TextIter();
        //Gtk.TextIter nextCharIter = new Gtk.TextIter ();

        if (!(endHilightIter.Equal(Gtk.TextIter.Zero)))
        {
            textBuffer.RemoveTag("hilight", startHilightIter, endHilightIter);
        }

        startHilightIter = startWordIter;
        endHilightIter   = endWordIter;
        prevEndCharIter  = endWordIter;
        prevEndCharIter.BackwardChar();
        while (Regex.IsMatch(startHilightIter.Char, @"[\s-]", RegexOptions.None))
        {
            startHilightIter.ForwardChar();
        }

        while (Regex.IsMatch(prevEndCharIter.Char, @"\s", RegexOptions.None) &&
               Regex.IsMatch(endHilightIter.Char, @"\S", RegexOptions.None))
        {
            endHilightIter.BackwardChar();
            prevEndCharIter.BackwardChar();
        }

        textBuffer.ApplyTag(tag, startHilightIter, endHilightIter);
        textView.ScrollToIter(endWordIter, 0, false, 0, 0);


        if (!running)
        {
            statusBar.Push(0, "Stopped at position " + startWordIter.Offset);
        }
    }
 public Task GetTask(TextIter iter)
 {
     TaskTag tag = GetTaskTag (iter);
     if (tag != null)
         return tag.Task;
     return null;
 }
示例#8
0
        protected override bool OnActivate(NoteEditor editor,
                                           Gtk.TextIter start,
                                           Gtk.TextIter end)
        {
            string     persona = start.GetText(end);
            PersonLink plink   = (PersonLink)galago.Trie.Lookup(persona);

            try {
                plink.SendMessage();
            } catch (Exception e) {
                string title = Catalog.GetString("Cannot contact '{0}'");
                title = String.Format(title, persona);

                string message = Catalog.GetString("Error running gaim-remote: {0}");
                message = String.Format(message, e.Message);

                Logger.Log(message);

                HIGMessageDialog dialog =
                    new HIGMessageDialog(editor.Toplevel as Gtk.Window,
                                         Gtk.DialogFlags.DestroyWithParent,
                                         Gtk.MessageType.Info,
                                         Gtk.ButtonsType.Ok,
                                         title,
                                         message);
                dialog.Run();
                dialog.Destroy();
            }

            return(true);
        }
示例#9
0
        private void HighlightSearchTerms(string highlight)
        {
            TextBuffer buffer = conversation.Buffer;
            string     text   = buffer.GetText(buffer.StartIter, buffer.EndIter, false).ToLower();

            string [] words    = highlight.Split(' ');
            bool      scrolled = false;

            foreach (string word in words)
            {
                int idx = 0;

                if (word == String.Empty)
                {
                    continue;
                }

                while ((idx = text.IndexOf(word.ToLower(), idx)) != -1)
                {
                    Gtk.TextIter start = buffer.GetIterAtOffset(idx);
                    Gtk.TextIter end   = start;
                    end.ForwardChars(word.Length);
                    if (!scrolled)
                    {
                        scrolled = true;
                        TextMark mark = buffer.CreateMark(null, start, false);
                        conversation.ScrollMarkOnscreen(mark);
                    }
                    buffer.ApplyTag("highlight", start, end);

                    idx += word.Length;
                }
            }
        }
示例#10
0
		public bool InsertSource (TextIter iter, string filename, int startRow, int endRow)
		{
			Stream input;

			try {
				input = File.OpenRead (filename);
			} catch {
				return false;
			}

			StreamReader reader = new StreamReader (input);
			string text;
			int line = 1;

			PlaceCursor (iter);
			while ((text = reader.ReadLine()) != null) {
				if (line >= startRow && line <= endRow) {
					if (line == startRow)
						FirstLine (ref text, endRow - startRow + 1);
					else
						NextLine (ref text, line - startRow);
					InsertAtCursor (text + "\n");
				}
				line ++;
			}

                        Highlight();

			return true;
		}
示例#11
0
        /// <summary>Función para actualizar el texto de la barra de estado
        /// cuando cambia la posición del cursor en el cuadro de edición de
        /// texto ensamblador.</summary>
        /// <param name="o">El objeto que provoca la llamada.</param>
        /// <param name="args">Los argumentos.</param>

        private void ActualizadaPosicionCursor
            (object o, Gtk.MarkSetArgs args)
        {
            Gtk.TextMark mark = textoCodigo.InsertMark;
            Gtk.TextIter iter = textoCodigo.GetIterAtMark(mark);

            int lineasTotales = textoCodigo.LineCount;
            int caractTotales = textoCodigo.CharCount;
            int lineaActual   = iter.Line + 1;
            int columnaActual = iter.LineOffset + 1;
            int offset        = iter.Offset;
            int porc          =
                (caractTotales < 1) ? 0 : (100 * offset) / caractTotales;
            String mensaje = String.Format(
                GetText("Ventana_Statusbar_Texto"),
                lineaActual,
                lineasTotales,
                columnaActual,
                offset,
                porc);

            if (textoCodigo.Modified)
            {
                mensaje += " *";
            }
            PonerMensajeStatusbar(mensaje);
        }
示例#12
0
        public ILFormatter(Gtk.TextBuffer Out)
        {
            this.Out     = Out;
            this.endIter = Out.EndIter;

            CreateTags(Out);
        }
示例#13
0
        void GetBlockExtents(ref Gtk.TextIter start, ref Gtk.TextIter end)
        {
            // FIXME: Should only be processing the largest match string
            // size, so we don't slow down for large paragraphs

            start.LineOffset = 0;
            end.ForwardToLineEnd();
        }
示例#14
0
        private void gsIO(String mess, int len)
        {
            Gtk.TextBuffer buffer = m_gsoutput.m_textView.Buffer;
            Gtk.TextIter   ti     = buffer.EndIter;

            var part = mess.Substring(0, len);

            buffer.Insert(ref ti, part);
        }
示例#15
0
	public static void AddPaddingEmpty (TextBuffer buffer, ref TextIter insertAt, string suffix)
	{
		DocumentTagTable tagTable = (DocumentTagTable) buffer.TagTable;
		TextTag tag = tagTable.Lookup ("padding-empty" + suffix);
		
		if (tag == null)
			tag = tagTable.CreateDynamicTag ("padding-empty" + suffix);
		buffer.InsertWithTags (ref insertAt, " ", tag);
	}
示例#16
0
        void OnDeleteRange(object sender, Gtk.DeleteRangeArgs args)
        {
            Gtk.TextIter start = args.Start;
            Gtk.TextIter end   = args.End;

            GetBlockExtents(ref start, ref end);

            UnhighlightInBlock(start, end);
            HighlightInBlock(start, end);
        }
示例#17
0
        void OnMenuItemActivated(object sender, EventArgs args)
        {
            NoteTag broken_link_tag = Note.TagTable.BrokenLinkTag;

            Gtk.TextIter note_start, note_end;

            // We get the whole note as a range
            // and then just remove the "broken link" tag from it
            Note.Buffer.GetBounds(out note_start, out note_end);

            // Sweep 'em & recreate WikiWord broken links (depending on Preferences),
            Buffer.RemoveTag(broken_link_tag, note_start, note_end);

            // HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
            // It turns WikiWords back into broken links after sweeping all broken links,
            // but only in case WikiWords are enabled.
            // Most probably there's more elegant way of doing this.

            if ((bool)Preferences.Get(Preferences.ENABLE_WIKIWORDS))
            {
                const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";

                Regex regex = new Regex(WIKIWORD_REGEX, RegexOptions.Compiled);

                NoteBuffer.GetBlockExtents(ref note_start,
                                           ref note_end,
                                           80 /* max wiki name */,
                                           broken_link_tag);

                //Buffer.RemoveTag (broken_link_tag, start, end);

                for (Match match = regex.Match(note_start.GetText(note_end));
                     match.Success;
                     match = match.NextMatch())
                {
                    System.Text.RegularExpressions.Group group = match.Groups [1];

                    Logger.Debug("Highlighting back wikiword: '{0}' at offset {1}",
                                 group,
                                 group.Index);

                    Gtk.TextIter start_cpy = note_start;
                    start_cpy.ForwardChars(group.Index);

                    note_end = start_cpy;
                    note_end.ForwardChars(group.Length);

                    if (Manager.Find(group.ToString()) == null)
                    {
                        Buffer.ApplyTag(broken_link_tag, start_cpy, note_end);
                    }
                }
            }
            /// End of hack
        }
示例#18
0
        /// <summary>
        /// Method used when user clicks on tag. Synchronusly starts DecryptPassAsync().
        /// </summary>
        /// <param name="tag"> NoteTag which was clicked. </param>
        /// <param name="editor"> NoteEditor in which NoteTag was clicked. </param>
        /// <param name="start"> TextIter pointiong to beginning of tag. </param>
        /// <param name="end"> TextIter pointiong to end of tag. </param>
        /// <returns> Returns true if password contained in tag is not empty string. </returns>
        protected bool PassEncryptTag_Activated(NoteTag tag, NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end)
        {
            string encPass = (tag as PassEncryptTag).Attributes[AtrName];

            if (string.IsNullOrWhiteSpace(encPass))
            {
                return(false);
            }
            DecryptPassAsync(encPass);
            return(true);
        }
示例#19
0
        private void HighlightEvent(Note note, int i)
        {
            NoteBuffer buf = note.Buffer;

            Console.WriteLine("Highlight line:" + i);
            Gtk.TextIter start = buf.GetIterAtLine(i);
            Gtk.TextIter end   = start;
            end.ForwardToLineEnd();

            buf.ApplyTag("reminder", start, end);
        }
	public static string Serialize (TextBuffer buffer, TextIter start, TextIter end)
	{
		StringWriter stream = new StringWriter ();
		XmlTextWriter xmlWriter = new XmlTextWriter (stream);
		xmlWriter.Formatting = Formatting.Indented;
		
		Serialize (buffer, start, end, xmlWriter);
		
		xmlWriter.Close ();
		return stream.ToString ();
	}
	public TextRange AddChop (TextIter startIter, TextIter endIter)
	{
		int chop_start, chop_end;
		TextIter current_end = EndIter;
		
		chop_start = EndIter.Offset;
		InsertRange (ref current_end, startIter, endIter);
		chop_end = EndIter.Offset;
		
		return new TextRange (GetIterAtOffset (chop_start), GetIterAtOffset (chop_end));
	}
示例#22
0
 public void SliderMoved(object o, EventArgs args)
 {
     if (!slideLock)
     {
         startWordIter.Offset = Convert.ToInt32(slider.Value);
         endWordIter          = startWordIter;
         curWord = GetNextWord();
         ShowWord(curWord);
         HilightWord();
     }
 }
示例#23
0
		public void InsertWithTags (ref TextIter iter, string text, params TextTag[] tags)
		{
			TextIter start;
			int offset = iter.Offset;
			Insert (ref iter, text);

			start = GetIterAtOffset (offset);
			iter = GetIterAtOffset (offset + text.Length);

			foreach (TextTag t in tags)
				this.ApplyTag (t, start, iter);
		}
示例#24
0
        void OnInsertText(object sender, Gtk.InsertTextArgs args)
        {
            Gtk.TextIter start = args.Pos;
            start.BackwardChars(args.Length);

            Gtk.TextIter end = args.Pos;

            GetBlockExtents(ref start, ref end);

            UnhighlightInBlock(start, end);
            HighlightInBlock(start, end);
        }
        public void InsertImage(TextIter iter, ImageInfo imageInfo, bool supportUndo)
        {
            Gdk.Pixbuf pixbuf = null;
            try {
                pixbuf = new Gdk.Pixbuf (imageInfo.FileContent);
            }
            catch {
                pixbuf = null;
            }
            if (pixbuf == null) {
                // TODO: Report the open image error.
                return;
            }

            if (imageInfo.DisplayWidth == 0) {
                imageInfo.DisplayWidth = pixbuf.Width;
                imageInfo.DisplayHeight = pixbuf.Height;
            }

            var imageWidget = new ImageWidget (pixbuf);
            imageWidget.ResizeImage (imageInfo.DisplayWidth, imageInfo.DisplayHeight);
            imageWidget.ShowAll ();
            InitImageWidgetContextMenu (imageWidget, imageInfo);
            imageWidget.Resized += imageWidget_Resized;

            if (supportUndo)
                Buffer.Undoer.FreezeUndo ();
            var anchorStart = iter;
            var anchor = Buffer.CreateChildAnchor (ref iter);

            var tag = new NoteTag ("dummy");
            tag.CanUndo = false;
            Buffer.ApplyTag (tag, anchorStart, iter);

            Window.Editor.AddChildAtAnchor (imageWidget, anchor);
            imageInfo.SetInBufferInfo (Buffer, anchor, imageWidget);

            //imageWidget.Destroyed += (o, e) =>
            //{
            //    if (!imageWidget.InsertUndone) {
            //        imageInfoList.Remove (imageInfo);
            //    }
            //};

            if (supportUndo) {
                Buffer.Undoer.ThawUndo ();
                var action = new InsertImageAction (this, imageInfo, imageInfoList);
                Buffer.Undoer.AddUndoAction (action);
            }
            imageInfoList.Add (imageInfo);
        }
示例#26
0
        public void InsertWithTags(ref TextIter iter, string text, params TextTag[] tags)
        {
            TextIter start;
            int      offset = iter.Offset;

            Insert(ref iter, text);

            start = GetIterAtOffset(offset);
            iter  = GetIterAtOffset(offset + text.Length);

            foreach (TextTag t in tags)
            {
                this.ApplyTag(t, start, iter);
            }
        }
示例#27
0
    public void StartRsvp(object o, EventArgs args)
    {
        stopButton.Sensitive    = true;
        stopMenuItem.Sensitive  = true;
        startButton.Sensitive   = false;
        startMenuItem.Sensitive = false;

        if (endWordIter.Equal(Gtk.TextIter.Zero))
        {
            endWordIter = textBuffer.StartIter;
        }
        running     = true;
        removeTimer = 0;
        statusBar.Push(0, "Reading...");
        DoRsvp();
    }
示例#28
0
        public void HighlightWikiWords(Note note)
        {
            NoteTag broken_link_tag = note.TagTable.BrokenLinkTag;

            Gtk.TextIter note_start, note_end;

            note.Buffer.GetBounds(out note_start, out note_end);

            // HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
            // It turns WikiWords back into broken links after sweeping all broken links,
            // but only in case WikiWords are enabled.
            // Most probably there's more elegant way of doing this.

            const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";

            Regex regex = new Regex(WIKIWORD_REGEX, RegexOptions.Compiled);

            NoteBuffer.GetBlockExtents(ref note_start,
                                       ref note_end,
                                       80 /* max wiki name */,
                                       broken_link_tag);

            for (Match match = regex.Match(note_start.GetText(note_end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                Logger.Debug("Highlighting back wikiword: '{0}' at offset {1}",
                             group,
                             group.Index);

                Gtk.TextIter start_cpy = note_start;
                start_cpy.ForwardChars(group.Index);

                note_end = start_cpy;
                note_end.ForwardChars(group.Length);

                if (note.Manager.Find(group.ToString()) == null)
                {
                    note.Buffer.ApplyTag(broken_link_tag, start_cpy, note_end);
                }
            }
            /// End of hack
        }
示例#29
0
    public void OpenFile(string filename)
    {
        string text;

        TextReader reader = File.OpenText(filename);

        try {
            statusBar.Push(0, "Opening file " + filename);
            text = reader.ReadToEnd();
        } finally {
            if (reader != null)
            {
                ((IDisposable)reader).Dispose();
            }
        }

        statusBar.Push(0, filename);
        textBuffer      = textView.Buffer;
        textBuffer.Text = text;

        //endWordIter = textBuffer.StartIter;
        endWordIter      = Gtk.TextIter.Zero;
        startWordIter    = Gtk.TextIter.Zero;
        endHilightIter   = Gtk.TextIter.Zero;
        startHilightIter = Gtk.TextIter.Zero;
        curWord          = "";
        slider.SetRange(0, textBuffer.CharCount);
        MakeHilightTag();

        if (endWordIter.Equal(Gtk.TextIter.Zero))
        {
            endWordIter = textBuffer.StartIter;
        }
        startWordIter = endWordIter;
        curWord       = GetNextWord();
        ShowWord(curWord);
        HilightWord();

        fileLoaded            = true;
        startButton.Sensitive = true;
        prevButton.Sensitive  = true;
        nextButton.Sensitive  = true;
    }
示例#30
0
	public InsertAction (TextIter start, string text, int length, ChopBuffer chop_buf)
	{
		#if DEBUG
		Console.WriteLine ("DEBUG: InsertAction: {0}", text);
		Console.WriteLine ("DEBUG: Insert Offset: {0} Char {1}", start.Offset, start.Char);
		#endif
		
		this.index = start.Offset - length;
		this.is_paste = length > 1;
		
		TextIter indexIter = start.Buffer.GetIterAtOffset (index);
		#if DEBUG
		Console.WriteLine ("DEBUG: Start Offset: {0} Char: {1}", indexIter.Offset, indexIter.Char);
		#endif
		this.chop = chop_buf.AddChop (indexIter, start);
		#if DEBUG
		Console.WriteLine ("DEBUG: Chop Text: {0}", chop.Text);
		#endif
	}
示例#31
0
        public void InsertWithTagsByName(ref TextIter iter, string text, params string[] tagnames)
        {
            TextIter start;
            int      offset = iter.Offset;

            Insert(ref iter, text);

            start = GetIterAtOffset(offset);
            iter  = GetIterAtOffset(offset + text.Length);

            foreach (string tagname in tagnames)
            {
                TextTag tag = TagTable.Lookup(tagname);
                if (tag != null)
                {
                    this.ApplyTag(tag, start, iter);
                }
            }
        }
示例#32
0
 public void NextWord(object o, EventArgs args)
 {
     if (!running)
     {
         if (endWordIter.Equal(Gtk.TextIter.Zero))
         {
             endWordIter = textBuffer.StartIter;
         }
         startWordIter = endWordIter;
         curWord       = GetNextWord();
         if (curWord == "")
         {
             return;
         }
         HilightWord();
         ShowWord(curWord);
         slideLock    = true;
         slider.Value = endWordIter.Offset;
         slideLock    = false;
     }
 }
示例#33
0
文件: Mon.cs 项目: linwx2020/SiKening
        /// <summary>
        /// Adds the string s to the textview at the cursor.
        /// </summary>
        /// <param name='s'>
        /// String to add.
        /// </param>
        private void addchars(string s)
        {
            // Add the text
            text_Monitor.Buffer.InsertAtCursor(s);

            // If there is too much text, remove some
            int linecount = text_Monitor.Buffer.LineCount;

            if (linecount > max_lines)
            {
                Gtk.TextIter startpoint = text_Monitor.Buffer.StartIter;
                Gtk.TextIter endpoint   = text_Monitor.Buffer.GetIterAtLine(linecount - max_lines);
                text_Monitor.Buffer.Delete(ref startpoint, ref endpoint);
            }

            // And if we are autoscrolling, do the right thing and keep the cursor visible
            if (check_Autoscroll.Active)
            {
                text_Monitor.ScrollMarkOnscreen(text_Monitor.Buffer.InsertMark);
            }
        }
示例#34
0
        private StringStatistics GetStatistics(TextIter start, TextIter end, bool include_strikethrough)
        {
            string str = "";

            if (include_strikethrough)
            {
                str = note.Buffer.GetText(start, end, false);
            } else
            {
                TextTagEnumerator enumerator =
                    new TextTagEnumerator (note.Buffer, "strikethrough");

                TextIter splice_start = start;
                TextIter splice_end = end;
                string splice = "";

                foreach (TextRange range in enumerator) {
                    if (range.Start.Offset > end.Offset)
                        break;

                    if (range.End.Offset < start.Offset)
                        continue;

                    str += splice;

                    if (range.Start.InRange (splice_start, splice_end))
                        splice = splice_start.GetVisibleText (range.Start);

                    if (!range.End.InRange (splice_start, splice_end))
                        splice_start = splice_end;
                    else
                        splice_start = range.End;
                }
                str += splice;
                str += splice_start.GetVisibleText (splice_end);
            }
            return GetTextStatistics (str);
        }
示例#35
0
        void HighlightInBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            foreach (TrieHit hit in galago.Trie.FindMatches(start.GetText(end)))
            {
                Gtk.TextIter match_start =
                    Buffer.GetIterAtOffset(start.Offset + hit.Start);

                // Don't create links inside note or URL links
                if (match_start.HasTag(url_tag) ||
                    match_start.HasTag(link_tag))
                {
                    continue;
                }

                Gtk.TextIter match_end = match_start;
                match_end.ForwardChars(hit.End - hit.Start);

                Logger.Log("Matching Person '{0}' at {1}-{2}...",
                           hit.Key,
                           hit.Start,
                           hit.End);
                Buffer.ApplyTag(person_tag, match_start, match_end);
            }
        }
示例#36
0
		// Looks at all tags covering the position of iter in the text view,
		// and if one of them is a link, follow it by showing the page identified
		// by the data attached to it.
		void FollowIfLink (TextView view, TextIter iter)
		{
			foreach (TextTag tag in iter.Tags) {
				int page = tag_pages [tag];
				ShowPage (view.Buffer, (int)page);
			}
		}
示例#37
0
	void InsertWithMarkup (TextBuffer buffer, ref TextIter iter, string text)
	{
		Match match = markupRegex.Match (text);
		if (!match.Success) {
			buffer.Insert (ref iter, text);
			return;
		}

		int start = 0, len, idx;
		var tags = new List <string> ();
		while (match.Success) {
			len = match.Index - start;
			if (len > 0)
				buffer.InsertWithTagsByName (ref iter, text.Substring (start, len), tags.ToArray ());

			switch (match.Value.ToLowerInvariant ()) {
				case "<i>":
					if (!tags.Contains ("italic"))
						tags.Add ("italic");
					break;

				case "</i>":
					idx = tags.IndexOf ("italic");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<b>":
					if (!tags.Contains ("bold"))
						tags.Add ("bold");
					break;

				case "</b>":
					idx = tags.IndexOf ("bold");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<big>":
					if (!tags.Contains ("big"))
						tags.Add ("big");
					break;

				case "</big>":
					idx = tags.IndexOf ("big");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<s>":
					if (!tags.Contains ("strikethrough"))
						tags.Add ("strikethrough");
					break;

				case "</s>":
					idx = tags.IndexOf ("strikethrough");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<sub>":
					if (!tags.Contains ("sub"))
						tags.Add ("sub");
					break;

				case "</sub>":
					idx = tags.IndexOf ("sub");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<sup>":
					if (!tags.Contains ("sup"))
						tags.Add ("sup");
					break;

				case "</sup>":
					idx = tags.IndexOf ("sup");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<small>":
					if (!tags.Contains ("small"))
						tags.Add ("small");
					break;

				case "</small>":
					idx = tags.IndexOf ("small");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<tt>":
					if (!tags.Contains ("monospace"))
						tags.Add ("monospace");
					break;

				case "</tt>":
					idx = tags.IndexOf ("monospace");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;

				case "<u>":
					if (!tags.Contains ("underline"))
						tags.Add ("underline");
					break;

				case "</u>":
					idx = tags.IndexOf ("underline");
					if (idx > -1)
						tags.RemoveAt (idx);
					break;
			}

			start = match.Index + match.Length;
			match = match.NextMatch ();
		}

		if (start < text.Length)
			buffer.InsertWithTagsByName (ref iter, text.Substring (start), tags.ToArray ());
	}
示例#38
0
	public static void AddText (TextBuffer buffer, ref TextIter insertAt, string data, TextTag tag)
	{
		DocumentTagTable tagTable = (DocumentTagTable) buffer.TagTable;
		TextTag textTag = tagTable.Lookup ("significant-whitespace" + "#" +  tag.Name);
		if (textTag == null)
			textTag = tagTable.CreateDynamicTag ("significant-whitespace" + "#" + tag.Name);
		
		string trimData = data.Trim ();
		int index = data.IndexOf (trimData);
		
		string startSpace = data.Substring (0, index);
		string prefixSpace = String.Empty;
		if (!startSpace.Equals (String.Empty)) {
			if (startSpace.Length == 1) {
				prefixSpace = startSpace;
				startSpace = String.Empty;
			} else {
				prefixSpace = startSpace.Substring (startSpace.Length - 1);
				startSpace = startSpace.Substring (0, startSpace.Length - 1);
			}
		}
		
		string endSpace = data.Substring (index + trimData.Length);
		string postSpace = String.Empty;
		if (!endSpace.Equals (String.Empty)) {
			if (endSpace.Length == 1) {
				if (endSpace.Equals (" ")) {
					postSpace = endSpace;
					endSpace = String.Empty;
				}
			} else {
				if (endSpace.Substring (0, 1).Equals (" ")) {
					postSpace = endSpace.Substring (0, 1);
					endSpace = endSpace.Substring (1);
				}
			}
		}
		
		buffer.InsertWithTags (ref insertAt, Escape (startSpace), textTag);
		buffer.InsertWithTags (ref insertAt, prefixSpace + trimData + postSpace, tag);
		buffer.InsertWithTags (ref insertAt, Escape (endSpace), textTag);
	}
示例#39
0
        //private void SearchItem_Keys(object sender, Gtk.KeyPressEventArgs keys)
        //{
        //    try
        //    {
        //        if (keys.Event.KeyValue == 65293)
        //        {
        //            SearchRun(Direction);
        //        }
        //    }
        //    catch (Exception fail)
        //    {
        //        Core.handleException(fail);
        //    }
        //}
        private void SearchRun(bool tp)
        {
            Direction = tp;
            Scrollback text = null;
            Gtk.TextView tv = null;
            if (Core.SystemForm.Chat == null || Core.SystemForm.Chat.scrollback == null)
            {
                return;
            }

            text = Core.SystemForm.Chat.scrollback;

            if (!text.IsSimple)
            {
                tv = text.RT.textView;
            }
            else
            {
                tv = text.simpleview;
            }
            TextIter start;
            TextIter stop;
            if (tp)
            {
                // we need to scroll down from current position
                if (!NeedReset)
                {
                    position = tv.Buffer.StartIter;
                }
                //position = tv.Buffer.GetIterAtOffset (tv.Buffer.CursorPosition);
                if (position.ForwardSearch(entry1.Text, TextSearchFlags.TextOnly, out start, out stop, tv.Buffer.EndIter))
                {
                    NeedReset = true;
                    entry1.ModifyBase(StateType.Normal, Core.FromColor (System.Drawing.Color.LightGreen));
                    position = stop;
                    tv.Buffer.SelectRange (start, stop);
                    tv.ScrollToIter (start, 0, false, 0, 0);
                } else
                {
                    NeedReset = true;
                    entry1.ModifyBase(StateType.Normal, Core.FromColor (System.Drawing.Color.Pink));
                }
            }
            else
            {
                // we need to scroll up from current position
                if (!NeedReset)
                {
                    position = tv.Buffer.EndIter;
                }
                if (position.BackwardSearch(entry1.Text, TextSearchFlags.TextOnly, out start, out stop, tv.Buffer.StartIter))
                {
                    NeedReset = true;
                    position = start;
                    entry1.ModifyBase(StateType.Normal, Core.FromColor (System.Drawing.Color.LightGreen));
                    tv.Buffer.SelectRange (start, stop);
                    tv.ScrollToIter (start, 0, false, 0, 0);
                } else
                {
                    NeedReset = true;
                    entry1.ModifyBase(StateType.Normal, Core.FromColor (System.Drawing.Color.Pink));
                }
            }
        }
		protected Gdk.Rectangle GetIterLocation (TextIter iter)
		{
			return textView.GetIterLocation (iter);
		}
示例#41
0
 public void Insert(TextIter iter, string text)
 {
     Insert (ref iter, text);
 }
示例#42
0
		void UpdatePositionLabel (TextIter iter)
		{
			int row = iter.Line + 1;
			int col = iter.LineOffset + 1;
			label3.Text = String.Format ("{0}/{1}", row, col);
		}
示例#43
0
 public void Delete(TextIter start, TextIter end )
 {
     Delete (ref start, ref end);
 }
 public bool InTaskList(TextIter cursor)
 {
     TaskListTag tlt = (TaskListTag) Buffer.GetDynamicTag ("tasklist", cursor);
     return (tlt!=null);
 }
示例#45
0
	public TextRange (TextIter start, 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);
	}
示例#46
0
        private string GetUrl(TextIter start, TextIter end)
        {
            string url = start.GetText(end).Trim();

            // Add to 'http://' to the front of www.foo.com
            // 'ftp://' to ftp.foo.com,
            // 'mailto:' to [email protected]
            if (url.StartsWith("www.")) {
                url = "http://" + url;
            } else if (url.StartsWith("ftp.")) {
                url = "ftp://" + url;
            } else if (url.IndexOf("@") > 1 && url.IndexOf(".") > 3 && !url.StartsWith("mailto:")) {
                url = "mailto:" + url;
            }
            return(url);
        }
示例#47
0
        public void InsertWithTagsByName(ref TextIter iter, string text, params string[] tagnames)
        {
            TextIter start;
            int offset = iter.Offset;
            Insert (ref iter, text);

            start = GetIterAtOffset (offset);
            iter = GetIterAtOffset (offset + text.Length);

            foreach (string tagname in tagnames) {
                TextTag tag = TagTable.Lookup (tagname);
                if (tag != null)
                    this.ApplyTag (tag, start, iter);
            }
        }
示例#48
0
 public void InsertWithTags(TextIter iter, string text, params TextTag[] tags)
 {
     InsertWithTags(ref iter, text, tags);
 }
示例#49
0
 public void InsertRange(TextIter iter, TextIter start, TextIter end)
 {
     InsertRange(ref iter, start, end);
 }
示例#50
0
 public void Insert(TextIter iter, string text)
 {
     Insert(ref iter, text);
 }
示例#51
0
 public void Delete(TextIter start, TextIter end)
 {
     Delete(ref start, ref end);
 }
示例#52
0
	public EraseAction (TextIter startIter, TextIter endIter, ChopBuffer chop_buf)
	{
		#if DEBUG
		Console.WriteLine ("DEBUG: EraseAction: {0}", startIter.GetText (endIter));
		Console.WriteLine ("DEBUG: Start Offset: {0} Char: {1}", startIter.Offset, startIter.Char);
		Console.WriteLine ("DEBUG: End Offset: {0} Char: {1}", endIter.Offset, endIter.Char);
		#endif
		
		this.start = startIter.Offset;
		this.end = endIter.Offset;
		this.is_cut = end - start > 1;
		
		TextIter previousIter = startIter.Buffer.GetIterAtOffset (start - 1);
		bool startsRegion = previousIter.Char.Equals ("[");
		bool endsRegion = endIter.Char.Equals ("]");
		this.whole_region = startsRegion && endsRegion;
		
		TextIter insert = startIter.Buffer.GetIterAtMark (startIter.Buffer.InsertMark);
		this.is_forward = insert.Offset <= start;
		
		this.chop = chop_buf.AddChop (startIter, endIter);
	}
示例#53
0
 public void InsertWithTags(TextIter iter, string text, params TextTag[] tags)
 {
     InsertWithTags (ref iter, text, tags);
 }
示例#54
0
        void SetupTimer(Note note, TextIter start, TextIter end)
        {
            if (!start.StartsLine())
                start.BackwardLine();
            if (!end.EndsLine())
                end.ForwardToLineEnd ();

            Buffer.RemoveTag("reminder", start, end);
            //Buffer.RemoveAllTags(start, end); // This breaks stuff - what purpose does it serve?
            SetupTimer(Note, start.GetSlice(end), start.Line);
        }
示例#55
0
 void UnhighlightInBlock(Gtk.TextIter start, Gtk.TextIter end)
 {
     Buffer.RemoveTag(person_tag, start, end);
 }
 public TaskTag GetTaskTag(TextIter iter)
 {
     return (TaskTag)Buffer.GetDynamicTag ("task", iter);
 }
示例#57
0
 public void InsertRange(TextIter iter, TextIter start, TextIter end )
 {
     InsertRange (ref iter, start, end);
 }
 public TaskList GetTaskList(TextIter iter)
 {
     TaskListTag tag = GetTaskListTag (iter);
     if (tag != null)
         return tag.TaskList;
     return null;
 }
示例#59
0
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            if (Cursor.Compare(InputLineBegin) < 0)
            {
                Buffer.MoveMark(Buffer.SelectionBound, InputLineEnd);
                Buffer.MoveMark(Buffer.InsertMark, InputLineEnd);
            }

            switch (evnt.Key)
            {
            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                string input_line = InputLine;
                history [history.Count - 1] = input_line;
                history_cursor = history.Count;

                string expr_copy = expr = GetCurrentExpression();

                // Insert a new line before we evaluate.
                TextIter end = Buffer.EndIter;
                Buffer.InsertWithTagsByName(ref end, "\n", "Stdout");

                if (Evaluate(expr))
                {
                    if (expr_copy != input_line)
                    {
                        history.Add(expr_copy);
                        history_cursor = history.Count;
                    }
                }
                history.Add("");
                DumpHistory();
                if (InteractiveBase.QuitRequested && QuitRequested != null)
                {
                    QuitRequested(this, EventArgs.Empty);
                }
                return(true);

            case Gdk.Key.Up:
                if (history_cursor == 0)
                {
                    DumpHistory();
                    return(true);
                }
                string input = InputLine;
                if (!String.IsNullOrEmpty(input))
                {
                    DumpHistory();
                    history [history_cursor] = input;
                }
                history_cursor--;
                InputLine = (string)history [history_cursor];
                DumpHistory();
                return(true);

            case Gdk.Key.Down:
                if (history_cursor + 1 >= history.Count)
                {
                    DumpHistory();
                    return(true);
                }
                history_cursor++;
                InputLine = (string)history [history_cursor];
                DumpHistory();
                return(true);

            case Gdk.Key.Left:
                if (Cursor.Compare(InputLineBegin) <= 0)
                {
                    return(true);
                }
                break;

            case Gdk.Key.Home:
                Buffer.MoveMark(Buffer.InsertMark, InputLineBegin);
                if ((evnt.State & Gdk.ModifierType.ShiftMask) != Gdk.ModifierType.ShiftMask)
                {
                    Buffer.MoveMark(Buffer.SelectionBound, InputLineBegin);
                }
                return(true);

            case Gdk.Key.Tab:
                string    saved_text = InputLine;
                string    prefix;
                string [] completions = evaluator.GetCompletions(LineUntilCursor, out prefix);
                if (completions == null)
                {
                    return(true);
                }

                if (completions.Length == 1)
                {
                    TextIter cursor = Cursor;
                    Buffer.Insert(ref cursor, completions [0]);
                    return(true);
                }

                Console.WriteLine();
                foreach (var s in completions)
                {
                    Console.Write(prefix);
                    Console.Write(s);
                    Console.Write(" ");
                }
                // Insert a new line before we evaluate.
                end = Buffer.EndIter;
                Buffer.InsertWithTagsByName(ref end, "\n", "Stdout");
                ShowPrompt(false);
                InputLine = saved_text;
#if false
                Gtk.TextIter start = Cursor;
                if (prefix.Length != 0)
                {
                    MoveVisually(ref start, -prefix.Length);
                }
                int x, y;
                GdkWindow.GetOrigin(out x, out y);
                var r = GetIterLocation(start);
                x += r.X;
                y += r.Y;
                var w = new Gtk.Window(WindowType.Popup);
                w.SetUposition(x, y);
                w.SetUsize(100, 100);
                foreach (var s in completions)
                {
                    Console.WriteLine("{0}[{1}]", prefix, s);
                }
                w.ShowAll();
                Console.WriteLine("Position: x={0} y={1}", x + r.X, y + r.Y);
#endif
                return(true);

            default:
                break;
            }

            return(base.OnKeyPressEvent(evnt));
        }
示例#60
-1
	public static TextTag GetLastTag (TextIter iter)
	{
		TextTag [] tags = iter.Tags;
		int last_index = tags.Length  - 1;
		
		return tags [last_index];
	}