Click here to Skip to main content
15,886,579 members
Articles / Desktop Programming / WPF

GoalBook - A Hybrid Smart Client

Rate me:
Please Sign up or sign in to vote.
4.86/5 (24 votes)
25 Sep 2009CPOL10 min read 79.1K   834   69  
A WPF hybrid smart client that synchronises your goals with the Toodledo online To-do service.
// <copyright file="FlowDocumentHelper.cs" company="GoalBook"> 
//    Copyright © 2009 Mark Brownsword. All rights reserved.
//    This source code and supporting files are licensed under The Code Project  
//    Open License (CPOL) as detailed at http://www.codeproject.com/info/cpol10.aspx. 
// </copyright>
namespace GoalBook.Infrastructure.Helpers
{
    #region Using Statements
    using System.Collections.Generic;
    using System.Windows.Documents;
    #endregion
    
    /// <summary>
    /// FlowDocument Helper.
    /// </summary>
    public class FlowDocumentHelper
    {
        #region Constants and Enums
        #endregion

        #region Instance and Shared Fields
        /// <summary>
        /// Declaration for flowDocument.
        /// </summary>
        private FlowDocument flowDocument;
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the FlowDocumentHelper class.
        /// </summary>
        /// <param name="flowDocument">FlowDocument parameter</param>
        public FlowDocumentHelper(FlowDocument flowDocument)
        {
            this.flowDocument = flowDocument;
        }
        #endregion

        #region Delegates and Events
        #endregion

        #region Properties
        #endregion

        #region Public and internal Methods
        /// <summary>
        /// Get Hyperlinks.
        /// </summary> 
        /// <returns>Hyperlink enumerable list</returns>
        public IEnumerable<Hyperlink> GetHyperlinks()
        {
            return this.LocateHyperlinks(this.flowDocument.Blocks);
        }
        #endregion

        #region Base Class Overrides
        #endregion

        #region Private and Protected Methods
        /// <summary>
        /// Locate Hyperlinks.
        /// </summary>
        /// <param name="blockCollection">BlockCollection parameter</param>
        /// <returns>Hyperlink enumerable list</returns>
        private IEnumerable<Hyperlink> LocateHyperlinks(BlockCollection blockCollection)
        {
            foreach (Block block in blockCollection)
            {
                if (block is Paragraph)
                {
                    foreach (Inline inline in (block as Paragraph).Inlines)
                    {
                        if (inline is Hyperlink)
                        {
                            yield return inline as Hyperlink;
                        }
                    }
                }
                else if (block is List)
                {
                    foreach (ListItem listItem in (block as List).ListItems)
                    {
                        // Recurse Blocks in each ListItem.
                        foreach (Hyperlink hyperlink in this.LocateHyperlinks(listItem.Blocks))
                        {
                            yield return hyperlink;
                        }
                    }
                }
            }
        }
        #endregion

        #region Event Handlers
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
I've been working as a software developer since 2000 and hold a Bachelor of Business degree from The Open Polytechnic of New Zealand. Computers are for people and I aim to build applications for people that they would want to use.

Comments and Discussions