Exemplo n.º 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.fillByData(task.Data);
                    //task_tag.CompletionDate = task.CompletionDate;
                    break;
                }
            } while (iter.ForwardLine());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        void ApplyTaskTagToBlock(ref Gtk.TextIter start, Gtk.TextIter end)
        {
            Gtk.TextIter line_end = start;
            while (line_end.EndsLine() == false)
            {
                line_end.ForwardChar();
            }
            // For some reason, the above code behaves like it should (i.e.,
            // without advancing to the next line).  The line below that's
            // commented out doesn't work.  It ends up advancing the iter to
            // the end of the next line.  Very strange!
//   line_end.ForwardToLineEnd ();


            TaskTag task_tag = GetTaskTagFromLineIter(ref start);

            if (task_tag != null)
            {
                Buffer.RemoveTag(task_tag, start, line_end);
            }
            else
            {
                task_tag = last_removed_tag;
            }

            string text = start.GetText(line_end);
//   Logger.Debug ("Evaluating with regex: {0}", text);

            TaskManager task_mgr = TasksApplicationAddin.DefaultTaskManager;
            Task        task;

            Match match = regex.Match(text);

            if (match.Success)
            {
                string summary = GetTaskSummaryFromLine(text);
                if (task_tag == null)
                {
                    task = task_mgr.Create(summary);
                    task.QueueSave(true);
                    task.OriginNoteUri = Note.Uri;
                    task_tag           = (TaskTag)
                                         Note.TagTable.CreateDynamicTag("task");
                    task_tag.Uri = task.Uri;
                }
                else
                {
                    task = task_mgr.FindByUri(task_tag.Uri);
                    if (task != null)
                    {
                        task.Summary = summary;
                    }
                    else
                    {
                        Logger.Debug("FIXME: Add code to remove the task tag if this case is hit");
                    }
                }
                task_tag.fillByData(task.Data);

                Buffer.ApplyTag(task_tag, start, line_end);
                last_removed_tag = null;
            }
            else if (task_tag != null)
            {
                // This task should be deleted
                task = task_mgr.FindByUri(task_tag.Uri);
                if (task != null)
                {
                    task_mgr.Delete(task);
                }

                last_removed_tag = null;
            }
        }