- 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
- GoalBook.Goals
- GoalBook.Infrastructure
- GoalBook.Notes
- GoalBook.Public
- GoalBook.Shell
- App.ico
- App.xaml
- App.xaml.cs
- Bootstrapper.cs
- Commands
- GoalBook.Shell.csproj
- GoalBook.Shell.csproj.user
- Journal.ico
- Journal48.ico
- Misc
- Modules
- Properties
- 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
- Splash.png
- Views
- vssver2.scc
- Windows
- GoalBook.sln
- GoalBook.snk
- GoalBook.Synchronisation
- GoalBook.Tasks
- License.txt
- ReadMe.txt
- SolutionInfo.cs
- vssver2.scc
|
//===============================================================================
// Goal Book.
// Copyright © 2009 Mark Brownsword.
//===============================================================================
#region Using Statements
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using GoalBook.Infrastructure;
using GoalBook.Infrastructure.Enums;
using GoalBook.Infrastructure.Interfaces;
using GoalBook.Shell.Misc;
using Microsoft.Practices.Composite.Presentation.Commands;
using Microsoft.Practices.Composite.Regions;
#endregion
namespace GoalBook.Shell.Services
{
public class NavigationService : INavigationService
{
private readonly IRegionManager _regionManager;
private readonly IShellView _shellView;
private readonly IGlobalCommandsProxy _commandProxy;
private IView _activeView;
private IView _activeActionView;
private List<MenuItem> _moduleMenuItems;
private List<DelegateCommand<CommandInfo>> _moduleCommands = new List<DelegateCommand<CommandInfo>>();
/// <summary>
/// Constructor.
/// </summary>
public NavigationService(IRegionManager regionManager, IShellView shellView, IGlobalCommandsProxy commandProxy)
{
_regionManager = regionManager;
_shellView = shellView;
_commandProxy = commandProxy;
_moduleMenuItems = new List<MenuItem>();
}
/// <summary>
/// Set Navigation Metadata.
/// </summary>
public void SetNavigationMetadata(params MenuInfo[] menuItems)
{
foreach (MenuInfo info in menuItems)
{
_shellView.AddMenuItem(info);
_moduleCommands.Add(info.MenuDelegateCommand);
info.MenuDelegateCommand.RaiseCanExecuteChanged();
}
}
/// <summary>
/// Load Search View.
/// </summary>
/// <param name="view">View parameter</param>
/// <returns>True after loading</returns>
public bool LoadSearchView(object view)
{
_regionManager.Regions[Constants.REGION_SEARCH].Add(view, view.GetType().Name);
return true;
}
/// <summary>
/// LoadModuleView. Loads the specified view into MainRegion.
/// </summary>
public bool LoadModuleView(string name, Uri imageUri, IView view, IView actionView, params MenuInfo[] menuItems)
{
if (view == _activeView) { return false; }
//Tear down existing view.
_shellView.ShowStatusMessage(string.Empty);
RemoveMenuItems();
RemoveViewFromMainRegion();
RemoveViewFromActionRegion();
//Add the new view.
AddViewToMainRegion(view);
AddViewToActionRegion(actionView);
AddMenuItems(menuItems);
//Raise CanExecute Changed for each module command. This allows the Go
//menu items to be enabled/disabled after modules are loaded.
_moduleCommands.ForEach(delegate(DelegateCommand<CommandInfo> command)
{
command.RaiseCanExecuteChanged();
});
//Update status message.
_shellView.DisplayModuleInfo(name, imageUri);
_shellView.ActiveModule = name;
return true;
}
/// <summary>
/// Register Info Command.
/// </summary>
/// <param name="type">GlobalCommand Type</param>
/// <param name="command">Command to register</param>
public void RegisterInfoCommand(GlobalCommandType type, DelegateCommand<CommandInfo> command)
{
switch (type)
{
case GlobalCommandType.Print:
_commandProxy.PrintCommand.RegisterCommand(command);
break;
case GlobalCommandType.Undo:
_commandProxy.UndoCommand.RegisterCommand(command);
break;
case GlobalCommandType.Delete:
_commandProxy.DeleteCommand.RegisterCommand(command);
break;
}
}
/// <summary>
/// Register String Command.
/// </summary>
/// <param name="type"></param>
/// <param name="command"></param>
public void RegisterStringCommand(GlobalCommandType type, DelegateCommand<string> command)
{
switch (type)
{
case GlobalCommandType.Search:
_commandProxy.SearchCommand.RegisterCommand(command);
break;
case GlobalCommandType.Clear:
_commandProxy.ClearCommand.RegisterCommand(command);
break;
}
}
/// <summary>
/// Show Status Message.
/// </summary>
/// <param name="message">message parameter</param>
public void ShowStatusMessage(string message)
{
_shellView.ShowStatusMessage(message);
}
/// <summary>
/// Remove existing modules MenuItems from Shell's main menu each
/// time a new module is loaded.
/// </summary>
private void RemoveMenuItems()
{
_moduleMenuItems.ForEach(delegate(MenuItem item)
{
_shellView.RemoveMenuItem(item, ParentMenuType.Module);
});
_moduleMenuItems.Clear();
}
/// <summary>
/// Add ModuleMenu Items. Adds specified items to the Shell's main
/// menu each time the module is activated.
/// </summary>
private void AddMenuItems(MenuInfo[] menuItems)
{
foreach (MenuInfo info in menuItems)
{
switch (info.MenuCommandInfo.ParentMenu)
{
case ParentMenuType.None:
break;
case ParentMenuType.Module:
_moduleMenuItems.Add(_shellView.AddMenuItem(info)); break;
case ParentMenuType.Edit:
break;
case ParentMenuType.View:
break;
case ParentMenuType.Go:
break;
case ParentMenuType.Tools:
break;
case ParentMenuType.Help:
break;
default:
break;
}
}
}
/// <summary>
/// Remove View From ActionRegion.
/// </summary>
private void RemoveViewFromActionRegion()
{
if (_activeActionView == null) { return; }
if (_regionManager.Regions[Constants.REGION_ACTION].GetView(_activeActionView.GetType().Name) != null)
{
//Remove currently active action view.
_regionManager.Regions[Constants.REGION_ACTION].Remove(_activeActionView);
_activeActionView = null;
}
}
/// <summary>
/// Add View to ActionRegion.
/// </summary>
private void AddViewToActionRegion(object view)
{
if (view == null) { return; }
//Add the new view.
_regionManager.Regions[Constants.REGION_ACTION].Add(view, view.GetType().Name);
//Store the new view as active action view.
_activeActionView = this._regionManager.Regions[Constants.REGION_ACTION].GetView(view.GetType().Name) as IView;
}
/// <summary>
/// Remove View From MainRegion.
/// </summary>
private void RemoveViewFromMainRegion()
{
if (_activeView == null) { return; }
if (_regionManager.Regions[Constants.REGION_MAIN].GetView(_activeView.GetType().Name) != null)
{
//Remove currently active view.
_regionManager.Regions[Constants.REGION_MAIN].Remove(_activeView);
_activeView = null;
}
}
/// <summary>
/// Add View to MainRegion. Also sets the ActiveView.
/// </summary>
private void AddViewToMainRegion(object view)
{
//Add the new view.
_regionManager.Regions[Constants.REGION_MAIN].Add(view, view.GetType().Name);
//Store the new view as active view.
_activeView = this._regionManager.Regions[Constants.REGION_MAIN].GetView(view.GetType().Name) as IView;
}
}
}
|
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.
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.