Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

GoalBook - A Hybrid Smart Client

, 25 Sep 2009 CPOL
A WPF hybrid smart client that synchronises your goals with the Toodledo online To-do service.
GoalBook.zip
GoalBook
Dependencies
CAG WPF 2
Microsoft.Practices.Composite.dll
Microsoft.Practices.Composite.Presentation.dll
Microsoft.Practices.Composite.UnityExtensions.dll
Microsoft.Practices.ObjectBuilder2.dll
Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.Unity.dll
vssver2.scc
CSLA
Csla.dll
Csla.XmlSerializers.dll
vssver2.scc
Infragistics
Infragistics3.Wpf.DataPresenter.v9.1.Express.dll
Infragistics3.Wpf.Editors.v9.1.Express.dll
Infragistics3.Wpf.v9.1.Express.dll
vssver2.scc
WPFToolkit
vssver2.scc
WPFToolkit.dll
GoalBook.Controls
CheckedList
vssver2.scc
Properties
vssver2.scc
vssver2.scc
GoalBook.Goals
GoalBook.Goals.csproj.user
Properties
vssver2.scc
Views
vssver2.scc
vssver2.scc
GoalBook.Infrastructure
Comparers
vssver2.scc
Constants
vssver2.scc
Controls
Converters
vssver2.scc
Enums
vssver2.scc
Events
vssver2.scc
GoalBook.Infrastructure.csproj.user
Helpers
vssver2.scc
Interfaces
vssver2.scc
ObjectModel
vssver2.scc
Printing
vssver2.scc
Properties
vssver2.scc
vssver2.scc
GoalBook.Notes
GoalBook.Notes.csproj.user
Properties
vssver2.scc
Resources
arrow_redo.png
arrow_undo.png
cut.png
page_copy.png
paste_plain.png
text_bold.png
text_indent.png
text_indent_remove.png
text_italic.png
text_list_bullets.png
text_list_numbers.png
vssver2.scc
world_link.png
Views
vssver2.scc
vssver2.scc
GoalBook.Public
Encryption
vssver2.scc
HtmlConverter
vssver2.scc
HtmlParser
vssver2.scc
Misc
vssver2.scc
Properties
vssver2.scc
vssver2.scc
GoalBook.Shell
App.ico
Commands
vssver2.scc
GoalBook.Shell.csproj.user
Journal.ico
Journal48.ico
Misc
vssver2.scc
Modules
vssver2.scc
Properties
licenses.licx
vssver2.scc
Resources
arrow_refresh.png
arrow_undo.png
checked.gif
cross.png
disk.png
email.png
erase.png
error.png
exclamation.png
flag_red.png
group.png
help.png
information.png
magnifier.png
page_red.png
pencil.png
printer.png
user.png
vssver2.scc
Wave.jpg
world.png
world_link.png
Services
vssver2.scc
Splash.png
Views
vssver2.scc
vssver2.scc
Windows
vssver2.scc
GoalBook.snk
GoalBook.Synchronisation
Events
vssver2.scc
Properties
vssver2.scc
ToodleDo
vssver2.scc
vssver2.scc
GoalBook.Tasks
Controls
vssver2.scc
Properties
vssver2.scc
Views
vssver2.scc
vssver2.scc
vssver2.scc
//===============================================================================
// Goal Book.
// Copyright © 2009 Mark Brownsword. 
//===============================================================================

#region Using Statements
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
#endregion

namespace GoalBook.Shell.Windows
{
    /// <summary>
    /// Interaction logic for Dialog.xaml
    /// </summary>
    public partial class Dialog : Window
    {        
        #region Constructor
        /// <summary>
        /// Initializes a new instance of <see cref="ViewDialog"/>
        /// </summary>
        public Dialog()
        {
            InitializeComponent();                       
        }
        #endregion

        #region Events
        /// <summary>
        /// Gets fired when the dialog needs to be validated.
        /// </summary>
        public event EventHandler<CancelEventArgs> ValidateDialog;

        /// <summary>
        /// Gets fired before the dialog closes.
        /// </summary>
        public event EventHandler<CancelEventArgs> CanCloseDialog;
        #endregion

        #region Private Members
        /// <summary>
        /// On Can Close Dialog.
        /// </summary>
        /// <returns>True when Can Close Dialog</returns>
        private bool OnCanCloseDialog()
        {
            EventHandler<CancelEventArgs> canCloseDialog = CanCloseDialog;
            bool cancelled = false;

            if (canCloseDialog != null)
            {
                CancelEventArgs args = new CancelEventArgs();
                canCloseDialog(this, args);

                cancelled = args.Cancel;
            }

            return !cancelled;
        }

        /// <summary>
        /// Do Event. Validate form.
        /// </summary>
        /// <returns>True if valid</returns>
        private bool OnValidate()
        {
            EventHandler<CancelEventArgs> validateDialog = ValidateDialog;
            bool cancelled = false;

            if (validateDialog != null)
            {
                CancelEventArgs args = new CancelEventArgs();
                validateDialog(this, args);

                cancelled = args.Cancel;
            }

            return !cancelled;
        }

        /// <summary>
        /// Close Dialog with specified result.
        /// </summary>
        /// <param name="result">result parameter</param>
        private void CloseDialog(bool? result)
        {            
            this.IsCancelled = result == null;
            this.DialogResult = result;

            this.Close();            
        }
        #endregion

        #region Event handlers
        /// <summary>
        /// Handle Window_Loaded event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">RoutedEventArgs parameter</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IsCancelled = true;
            IsDirty = false;
        }

        /// <summary>
        /// Handle ButtonAccept_PreviewKeyUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">KeyEventArgs parameter</param>
        private void ButtonAccept_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (OnValidate())
                {
                    e.Handled = true;
                    CloseDialog(true);
                }
            }
        }

        /// <summary>
        /// Handle ButtonAccept_PreviewMouseLeftButtonUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">MouseButtonEventArgs parameter</param>
        private void ButtonAccept_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (OnValidate())
            {
                e.Handled = true;
                CloseDialog(true);
            }
        }

        /// <summary>
        /// Handle ButtonReject_PreviewKeyUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">KeyEventArgs parameter</param>
        private void ButtonReject_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {                
                e.Handled = true;
                CloseDialog(false);
            }            
        }

        /// <summary>
        /// Handle ButtonReject_PreviewMouseLeftButtonUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">MouseButtonEventArgs parameter</param>
        private void ButtonReject_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {            
            e.Handled = true;
            CloseDialog(false);                   
        }

        /// <summary>
        /// Handle ButtonCancel_PreviewKeyUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">KeyEventArgs parameter</param>
        private void ButtonCancel_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                CloseDialog(null);
            } 
        }

        /// <summary>
        /// Handle ButtonCancel_PreviewMouseLeftButtonUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">MouseButtonEventArgs parameter</param>
        private void ButtonCancel_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            CloseDialog(null); 
        }

        /// <summary>
        /// Handle Window_PreviewKeyUp event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">KeyEventArgs parameter</param>
        private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                CloseDialog(null);
            }
        }

        /// <summary>
        /// Handle Window_Closing event.
        /// </summary>
        /// <param name="sender">sender parameter</param>
        /// <param name="e">CancelEventArgs parameter</param>
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (this.IsCancelled && this.IsDirty)
            {
                e.Cancel = !OnCanCloseDialog();               
            }            
        }
        #endregion

        #region Properties
        /// <summary>
        /// Reference to ButtonPanelVisibility. Using a DependencyProperty as the backing store for 
        /// ButtonPanelVisibility.  This enables animation, styling, binding, etc... 
        /// </summary>
        public Visibility ButtonPanelVisibility
        {
            get { return (Visibility)GetValue(ButtonPanelVisibilityProperty); }
            set { SetValue(ButtonPanelVisibilityProperty, value); }
        }        
        public static readonly DependencyProperty ButtonPanelVisibilityProperty = DependencyProperty.Register("ButtonPanelVisibility", 
            typeof(Visibility), typeof(Dialog), new UIPropertyMetadata(Visibility.Visible));
        
        /// <summary>
        /// Gets or sets the view to show in the dialog
        /// </summary>
        public DependencyObject View
        {
            get { return (DependencyObject)GetValue(ViewProperty); }
            set { SetValue(ViewProperty, value); }
        }
        public static readonly DependencyProperty ViewProperty = DependencyProperty.Register("View",
            typeof(DependencyObject), typeof(Dialog), new UIPropertyMetadata(null));

        /// <summary>
        /// Gets value of IsCancelled property.
        /// </summary>
        public bool IsCancelled { get; private set; }

        /// <summary>
        /// Gets or sets value of IsDirty property.
        /// </summary>
        public bool IsDirty { get; set; }
        #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)

Share

About the Author

Mark Brownsword
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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 25 Sep 2009
Article Copyright 2009 by Mark Brownsword
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid