private bool ProcessTaskUpdate(Task task,
                                       UIExtension.UpdateType type,
                                       HashSet <UIExtension.TaskAttribute> attribs)
        {
            if (!task.IsValid())
            {
                return(false);
            }

            CloudTaskItem item;
            bool          newTask = !m_Items.TryGetValue(task.GetID(), out item);

            if (newTask)
            {
                item             = new CloudTaskItem(task.GetID());
                m_Items[item.Id] = item;
            }

            item.ProcessTaskUpdate(task, type, attribs, newTask);

            // Process children
            Task subtask = task.GetFirstSubtask();

            while (subtask.IsValid() && ProcessTaskUpdate(subtask, type, attribs))
            {
                subtask = subtask.GetNextTask();
            }

            return(true);
        }
        CheckBoxState GetItemCheckboxState(CloudTaskItem taskItem)
        {
            if (taskItem.IsDone(false))
            {
                return(CheckBoxState.CheckedNormal);
            }

            if (taskItem.HasSomeSubtasksDone)
            {
                return(CheckBoxState.MixedNormal);
            }

            // else
            return(CheckBoxState.UncheckedNormal);
        }
        private void RebuldMatchList()
        {
            string selWord = m_WordCloud.SelectedWord;

            if (selWord != null)
            {
                CloudTaskItem selItem   = null;
                UInt32        selItemId = m_TaskMatchesList.GetSelectedMatchId();

                // Build a list of task items containing this value
                m_TaskMatchesList.BeginUpdate();
                m_TaskMatchesList.ClearMatches();

                foreach (var item in m_Items)
                {
                    if (item.Value.AttributeHasValue(m_Attrib, selWord, m_ExcludedWords))
                    {
                        m_TaskMatchesList.AddMatch(item.Value);

                        if (item.Value.Id == selItemId)
                        {
                            selItem = item.Value;
                        }
                    }
                }
                m_TaskMatchesList.EndUpdate();

                string headerText = m_Trans.Translate("Task Matches");

                if (m_TaskMatchesList.Items.Count > 0)
                {
                    // See if our currently selected task is in the new match list
                    selItemId = m_TaskMatchesList.SetSelectedMatchId(selItemId);

                    if ((selItem == null) || (selItemId != selItem.Id))
                    {
                        NotifyParentSelChange(selItemId);
                    }

                    m_TaskMatchesList.Columns[0].Text = String.Format("{0} ({1})", headerText, m_TaskMatchesList.Items.Count);
                }
                else
                {
                    m_TaskMatchesList.Columns[0].Text = headerText;
                }
            }
        }
        private bool ProcessTaskUpdate(Task task,
                                       UIExtension.UpdateType type,
                                       HashSet <UInt32> taskIds)
        {
            if (!task.IsValid())
            {
                return(false);
            }

            // Ignore reference tasks
            if (task.GetReferenceID() != 0)
            {
                return(true);
            }

            CloudTaskItem item;

            if (m_Items.TryGetValue(task.GetID(), out item))
            {
                item.ProcessTaskUpdate(task, type, false);
            }
            else
            {
                item = new CloudTaskItem(task.GetID());
                item.ProcessTaskUpdate(task, type, true);

                m_Items[item.Id] = item;
            }


            if (taskIds != null)
            {
                taskIds.Add(item.Id);
            }

            // Process children
            Task subtask = task.GetFirstSubtask();

            while (subtask.IsValid() && ProcessTaskUpdate(subtask, type, taskIds))
            {
                subtask = subtask.GetNextTask();
            }

            return(true);
        }
        public bool AddMatch(CloudTaskItem item)
        {
            var lvItem = new ListViewItem(item.Title);

            lvItem.Tag      = item;
            lvItem.Selected = false;
            lvItem.SubItems.Add(item.Id.ToString());
            lvItem.Checked = item.IsDone(false);

            if ((item.IsParent && m_ShowParentAsFolder) || item.HasIcon)
            {
                lvItem.ImageIndex      = 1;
                m_TaskMatchesHaveIcons = true;
            }

            if (this.Items.Add(lvItem) == null)
            {
                return(false);
            }

            return(true);
        }
        public bool SelectTask(String text, UIExtension.SelectTask selectTask, bool caseSensitive, bool wholeWord, bool findReplace)
        {
            if (text == String.Empty)
            {
                return(false);
            }

            if (!findReplace)
            {
                var words = CloudTaskItem.ToWords(text);

                if (!words.Any())
                {
                    return(false);
                }

                if (!m_WordCloud.SelectedWordMatches(words, caseSensitive, wholeWord))
                {
                    var matches = m_WordCloud.Match(words, false);

                    if (matches.Any())
                    {
                        m_WordCloud.SelectedWord = matches.First().Text;
                        return(true);
                    }

                    return(false);
                }
            }

            // Then on the match list
            if (m_TaskMatchesList.SelectMatch(text, selectTask, caseSensitive, wholeWord, findReplace))
            {
                return(true);
            }

            // all else
            return(false);
        }
        private String FixupWordCloudSelection(CloudTaskItem selMatch = null)
        {
            // Check if the currently selected word is still
            // present in the currently selected match
            String selWord = m_WordCloud.SelectedWord;

            if (selMatch == null)
            {
                selMatch = m_TaskMatchesList.GetSelectedMatch();
            }

            if ((selMatch != null) && (selWord != null))
            {
                var words = selMatch.GetWords(m_Attrib, m_ExcludedWords, false);

                // If not, find the first match between the item's text
                // and the wordcloud contents
                if (words.Any() && !words.Contains(selWord, StringComparer.InvariantCultureIgnoreCase))
                {
                    var matches = m_WordCloud.Match(words, false);

                    if (matches.Any())
                    {
                        selWord = matches.First().Text;
                    }
                }
            }

            if (selWord == null)
            {
                selWord = m_WordCloud.WeightedWords.SortByOccurrences().First().Text;
            }

            m_WordCloud.SelectedWord = selWord;

            return(selWord);
        }