コード例 #1
0
        /// <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());
        }
コード例 #2
0
        /// <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());
        }
コード例 #3
0
        /// <summary>
        /// If the renamed task is included inside this note, this
        /// handler will update the task summary in the note buffer.
        /// </summary>
        private void OnTaskRenamed(Task task, string old_title)
        {
            if (task.OriginNoteUri == null || task.OriginNoteUri != Note.Uri)
            {
                return;
            }

            // Search through the note looking for the TaskTag so that it can
            // be renamed

            if (!ContainsText(old_title))
            {
                return;
            }

            // 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;
                    }

                    Gtk.TextIter line_start = iter;
                    while (line_start.StartsLine() == false)
                    {
                        line_start.BackwardChar();
                    }
                    Gtk.TextIter line_end = iter;
                    while (line_end.EndsLine() == false)
                    {
                        line_end.ForwardChar();
                    }
//     line_end.ForwardToLineEnd ();

                    Buffer.Delete(ref line_start, ref line_end);
                    last_removed_tag = task_tag;
                    Buffer.Insert(ref line_start,
                                  string.Format("{0}: {1}",
                                                Catalog.GetString("todo"),
                                                task.Summary));
                    task_tag.fillByData(task.Data);
                    break;
                }
            } while (iter.ForwardLine());
        }
コード例 #4
0
        void UpdateTaskTagStatuses()
        {
            // FIXME: Should really just create an enumerator class for
            // enumerating a Buffer's TaskTags instead of doing it this
            // way in almost every method.
            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)
                {
                    continue;
                }

                task_tag.UpdateStatus();
            } while (iter.ForwardLine());
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <summary>
        /// This method should be called during a large deletion of a
        /// range of text so it can properly remove all the task tags.
        /// </summary>
        void RemoveTaskTagsFromRange(Gtk.TextIter start, Gtk.TextIter end)
        {
            TaskTag task_tag;

            Gtk.TextIter line;
            Gtk.TextIter line_start;
            Gtk.TextIter line_end;
            if (start.Line == end.Line)
            {
                // The iters are on the same line.

                // If there's only one character being deleted, don't do
                // anything here.  This condition will be taken care of
                // in ApplyTaskTagToBlock ().
                if (end.LineOffset - start.LineOffset == 1)
                {
                    return;
                }

                // Determine whether this line contains a TaskTag.  If it
                // does, determine whether deleting the range will delete
                // the todo.
                line     = start;
                task_tag = GetTaskTagFromLineIter(ref line);
                if (task_tag != null)
                {
                    if (start.LineIndex == 0)
                    {
                        // Start iter is at beginning of line
                        if (end.LineOffset >= Catalog.GetString("todo:").Length)
                        {
                            RemoveTaskTagFromLine(start);
                        }
                    }
                    else if (start.LineIndex < Catalog.GetString("todo:").Length)
                    {
                        // The start of the range is inside the "todo:" area,
                        // so the TaskTag needs to be removed.
                        RemoveTaskTagFromLine(start);
                    }
                    else
                    {
                        // Do nothing.  The deletion is just inside the
                        // summary of the task.
                    }
                }
            }
            else
            {
                // The iters are on different lines

                line = start;
                do
                {
                    task_tag = GetTaskTagFromLineIter(ref line);
                    if (task_tag != null)
                    {
                        // Handle the first and last lines special since their
                        // range may not span the entire line.
                        if (line.Line == start.Line)
                        {
                            // This is the first line
                            line_end = line;
                            while (line_end.EndsLine() == false)
                            {
                                line_end.ForwardChar();
                            }
//       line_end.ForwardToLineEnd ();
                            RemoveTaskTagsFromRange(start, line_end);
                        }
                        else if (line.Line == end.Line)
                        {
                            // This is the last line
                            line_start = line;
                            while (line_start.StartsLine() == false)
                            {
                                line_start.BackwardChar();
                            }
                            RemoveTaskTagsFromRange(line_start, end);
                        }
                        else
                        {
                            // This line is in the middle of the range
                            // so it's completely safe to remove the TaskTag
                            RemoveTaskTagFromLine(line);
                        }

                        // Delete the task
                        TaskManager task_mgr = TasksApplicationAddin.DefaultTaskManager;
                        Task        task     = task_mgr.FindByUri(task_tag.Uri);
                        if (task != null)
                        {
                            task_mgr.Delete(task);
                        }
                    }
                } while (line.ForwardLine() && line.Line <= end.Line);
            }
        }