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

Task Manager

, 1 Jan 2010
Manage your daily tasks and To-Do list using some exciting features of Windows 7.
TaskManager.zip
TaskManager
Core
AppRestartRecovery
Dialogs
Common
TaskDialogs
Interop
AppRestartRecovery
Dialogs
NetworkList
PowerManagement
TaskDialogs
NetworkList
PowerManagement
Properties
PropertySystem
SafeHandles
Shell
Common
CommonFileDialogs
Controls
Design
ShellObjects.cd
ShellThumbnailClassDiagram.cd
DesktopWindowManager
ExplorerBrowser
ExplorerBrowserDiagram.cd
Interop
Common
Dialogs
ExplorerBrowser
KnownFolders
PropertySystem
StockIcons
Taskbar
KnownFolders
Properties
PropertySystem
StockIcons
Taskbar
TaskManager
Common
Controls
Database
SqlTaskManager.edmx
TaskManager.mdf
TaskManager_log.LDF
Properties
Settings.settings
Resources
Add.png
AddCategory.png
AddResource.png
AddTask.png
Back.ico
backcolor.bmp
BlueCat.png
Blue_Category.ico
bold.bmp
Category.png
Category_Icon.ico
Close.bmp
Close.png
color.bmp
Delete.png
Delete_01.png
Delete_Icon.ico
edit.png
edit_Icon.ico
Empty.png
Forward.ico
GanttChart.png
GreenCat.png
Green_Category.ico
High_Priority.png
High_Priority_Icon.ico
indent.bmp
italic.bmp
Low_Priority.png
Low_Priority_Icon.ico
Medium_Priority.png
Medium_Priority_Icon.ico
NextWeek_Flag.png
NextWeek_Flag_Icon.ico
NoDate_Flag.png
NoDate_Flag_Icon.ico
ol.bmp
OrangeCat.png
Orange_Category.ico
outdent.bmp
PurpleCat.png
Purple_Category.ico
Question.ico
Question_Icon.ico
RedCat.png
Red_Category.ico
Resource.png
Resource_Icon.ico
Save.bmp
Save.png
Task manager.ico
Task.png
TaskSetting.png
Task_Icon.ico
ThisWeek_Flag.png
ThisWeek_Flag_Icon.ico
Today_Flag.png
Today_Flag_Icon.ico
Tomorrow_Flag.png
Tomorrow_Flag_Icon.ico
underscore.bmp
uol.bmp
YellowCat.png
Yellow_Category.ico
TaskManager.csproj.user
Window7
TaskManagerSimple.zip
TaskManagerSimple
TaskManagerSimple
Common
Controls
Database
SqlTaskManager.edmx
TaskManager.mdf
TaskManager_log.LDF
Properties
Settings.settings
Resources
Add.png
AddCategory.png
AddResource.png
AddTask.png
Back.ico
backcolor.bmp
BlueCat.png
Blue_Category.ico
bold.bmp
Category.png
Category_Icon.ico
Close.bmp
Close.png
color.bmp
Delete.png
Delete_01.png
Delete_Icon.ico
edit.png
edit_Icon.ico
Empty.png
Forward.ico
GanttChart.png
GreenCat.png
Green_Category.ico
High_Priority.png
High_Priority_Icon.ico
indent.bmp
italic.bmp
Low_Priority.png
Low_Priority_Icon.ico
Medium_Priority.png
Medium_Priority_Icon.ico
NextWeek_Flag.png
NextWeek_Flag_Icon.ico
NoDate_Flag.png
NoDate_Flag_Icon.ico
ol.bmp
OrangeCat.png
Orange_Category.ico
outdent.bmp
PurpleCat.png
Purple_Category.ico
Question.ico
Question_Icon.ico
RedCat.png
Red_Category.ico
Resource.png
Resource_Icon.ico
Save.bmp
Save.png
Task manager.ico
Task.png
TaskSetting.png
Task_Icon.ico
ThisWeek_Flag.png
ThisWeek_Flag_Icon.ico
Today_Flag.png
Today_Flag_Icon.ico
Tomorrow_Flag.png
Tomorrow_Flag_Icon.ico
underscore.bmp
uol.bmp
YellowCat.png
Yellow_Category.ico
TaskManager.csproj.user
//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using Microsoft.WindowsAPICodePack.Controls.WindowsForms;
using Microsoft.WindowsAPICodePack.Shell;

namespace Microsoft.WindowsAPICodePack.Controls
{

    /// <summary>
    /// The navigation log is a history of the locations visited by the explorer browser. 
    /// </summary>
    public class ExplorerBrowserNavigationLog
    {
        #region operations
        /// <summary>
        /// Clears the contents of the navigation log.
        /// </summary>
        public void ClearLog( )
        {
            // nothing to do
            if( Locations.Count == 0 )
                return;

            bool oldCanNavigateBackward = CanNavigateBackward;
            bool oldCanNavigateForward = CanNavigateForward;

            Locations.Clear( );
            this.currentLocationIndex = -1;

            NavigationLogEventArgs args = new NavigationLogEventArgs( );
            args.LocationsChanged = true;
            args.CanNavigateBackwardChanged = ( oldCanNavigateBackward != CanNavigateBackward );
            args.CanNavigateForwardChanged = ( oldCanNavigateForward != CanNavigateForward );
            if( NavigationLogChanged != null )
                NavigationLogChanged( this, args );
        }
        #endregion

        #region properties
        /// <summary>
        /// Indicates the presence of locations in the log that can be 
        /// reached by calling Navigate(Forward)
        /// </summary>
        public bool CanNavigateForward
        {
            get
            {
                return (CurrentLocationIndex < (Locations.Count - 1));
            }
        }

        /// <summary>
        /// Indicates the presence of locations in the log that can be 
        /// reached by calling Navigate(Backward)
        /// </summary>
        public bool CanNavigateBackward
        {
            get
            {
                return ( CurrentLocationIndex >= 1 );
            }
        }

        /// <summary>
        /// The navigation log
        /// </summary>
        public List<ShellObject> Locations
        {
            get;
            private set;
        }

        /// <summary>
        /// An index into the Locations collection. The ShellObject pointed to 
        /// by this index is the current location of the ExplorerBrowser.
        /// </summary>
        public int CurrentLocationIndex
        {
            get
            {
                return currentLocationIndex;
            }
        }


        /// <summary>
        /// Gets the shell object in the Locations collection pointed to
        /// by CurrentLocationIndex.
        /// </summary>
        public ShellObject CurrentLocation
        { 
            get
            {
                if( currentLocationIndex < 0 )
                    return null;

                return Locations[currentLocationIndex];
            }
        }
        #endregion

        #region events
        /// <summary>
        /// Fires when the navigation log changes or 
        /// the current navigation position changes
        /// </summary>
        public event NavigationLogChangedEventHandler NavigationLogChanged;
        #endregion

        #region implementation

        private ExplorerBrowser parent = null;

        /// <summary>
        /// The pending navigation log action. null if the user is not navigating 
        /// via the navigation log.
        /// </summary>
        private PendingNavigation pendingNavigation = null;
        
        /// <summary>
        /// The index into the Locations collection. -1 if the Locations colleciton 
        /// is empty.
        /// </summary>
        private int currentLocationIndex = -1;
 
        internal ExplorerBrowserNavigationLog( ExplorerBrowser parent )
        {
            if( parent == null )
                throw new ArgumentException( "parent can not be null!" );

            //
            Locations = new List<ShellObject>();

            // Hook navigation events from the parent to distinguish between
            // navigation log induced navigation, and other navigations.
            this.parent = parent;
            this.parent.NavigationComplete += new ExplorerBrowserNavigationCompleteEventHandler( OnNavigationComplete );
            this.parent.NavigationFailed += new ExplorerBrowserNavigationFailedEventHandler( OnNavigationFailed );
        }

        private void OnNavigationFailed( object sender, NavigationFailedEventArgs args )
        {
            pendingNavigation = null;
        }

        private void OnNavigationComplete( object sender, NavigationCompleteEventArgs args )
        {
            NavigationLogEventArgs eventArgs = new NavigationLogEventArgs( );
            bool oldCanNavigateBackward = CanNavigateBackward;
            bool oldCanNavigateForward = CanNavigateForward;

            if( ( pendingNavigation != null ) )
            {
                // navigation log traversal in progress

                // determine if new location is the same as the traversal request
                int result = 0;
                pendingNavigation.location.NativeShellItem.Compare( 
                    args.NewLocation.NativeShellItem, SICHINTF.SICHINT_ALLFIELDS, out result );
                bool shellItemsEqual = ( result == 0 );
                if( shellItemsEqual == false )
                {
                    // new location is different than traversal request, 
                    // behave is if it never happened!
                    // remove history following currentLocationIndex, append new item
                    if( currentLocationIndex < ( Locations.Count - 1 ) )
                        Locations.RemoveRange( (int)currentLocationIndex + 1, (int)( Locations.Count - ( currentLocationIndex + 1 ) ) );
                    Locations.Add( args.NewLocation );
                    currentLocationIndex = (Locations.Count - 1);
                    eventArgs.LocationsChanged = true;
                }
                else
                {
                    // log traversal successful, update index
                    currentLocationIndex = (int)pendingNavigation.index;
                    eventArgs.LocationsChanged = false;
                }
                pendingNavigation = null;
            }
            else
            {
                // remove history following currentLocationIndex, append new item
                if( currentLocationIndex < (Locations.Count - 1) )
                    Locations.RemoveRange( (int)currentLocationIndex + 1, (int)( Locations.Count - (currentLocationIndex + 1)) );
                Locations.Add( args.NewLocation );
                currentLocationIndex = (Locations.Count - 1);
                eventArgs.LocationsChanged = true;
            }

            // update event args
            eventArgs.CanNavigateBackwardChanged = ( oldCanNavigateBackward != CanNavigateBackward );
            eventArgs.CanNavigateForwardChanged = ( oldCanNavigateForward != CanNavigateForward );

            if( NavigationLogChanged != null )
                NavigationLogChanged( this, eventArgs );
        }

        internal bool NavigateLog( NavigationLogDirection direction )
        {
            // determine proper index to navigate to
            int locationIndex = 0;
            if( (direction == NavigationLogDirection.Backward)  && CanNavigateBackward )
            {
                locationIndex = (currentLocationIndex - 1);
            }
            else if( (direction == NavigationLogDirection.Forward)  && CanNavigateForward )
            {
                locationIndex = (currentLocationIndex + 1);
            }
            else
            {
                return false;
            }

            // initiate traversal request
            ShellObject location = Locations[ (int)locationIndex ];
            pendingNavigation = new PendingNavigation( location, locationIndex );
            parent.Navigate( location );
            return true;
        }

        internal bool NavigateLog( int index )
        {
            // can't go anywhere
            if( index >= Locations.Count ||
                index < 0 )
                return false;

            // no need to re navigate to the same location
            if( index == currentLocationIndex )
                return false;

            // initiate traversal request
            ShellObject location = Locations[ (int)index ];
            pendingNavigation = new PendingNavigation( location, index );
            parent.Navigate( location );
            return true;
        }

        #endregion
    }

    /// <summary>
    /// A navigation traversal request
    /// </summary>
    internal class PendingNavigation
    {
        internal PendingNavigation( ShellObject location, int index )
        {
            this.location = location;
            this.index = index;
        }

        internal ShellObject location;
        internal int index;
    }
}

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

Shakeel Iqbal
Software Developer (Senior) TEO
Pakistan Pakistan
Passion and positive dedication is essential part of success. I believe on hardworking and sharing knowledge with others. I always try to be a better than I am and think positive for positive result.
 
My Blogs
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 2 Jan 2010
Article Copyright 2010 by Shakeel Iqbal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid