EditManager

1. Description

The EditManager maps the basic edit functions (e.g. copy, paste, ...) of an object to the edit menu of the application. This service mediates between the user interface and an object which handles the edit operations.

2. Motivation

It is common for a Windows-based application to contain an edit menu and various tool bar buttons for the most common edit functions (e.g. copy, paste, ...). Figure 1 shows the edit menu items of the Test Suite. The wiring of these edit buttons with TextBox, RichTextBox and other controls of the current view can be time consuming. Additionally, only the control with the focus should listen to the edit menu operations.

edit-menu.png
Figure 1

3. Solution

The EditManager takes over the task of binding the edit buttons with objects which should handle these edit operations. It keeps track of the current entered object and binds just this one to the edit buttons. These objects need to implement the IEditHandler interface (Figure 2).

edit-manager.png
Figure 2

Many of the Windows Forms and WPF controls provide some of the methods which are required by the IEditHandler interface. An adapter is necessary for using one of the UI controls as an edit handler. The Infrastructure.Module already contains a few adapters for common UI controls like the WPF TextBox. The EditManager service uses the AdapterFactoryCatalog to simplify the registration of an object.

4. Example

Listing 1 shows an extract of the VisualizerView class which represents a WPF user control. The fields "scaleX" and "scaleY" are WPF TextBox controls. The WPF TextBox control does not implement the IEditHandler interface. Yet it can still be registered because the AdapterFactoryCatalog<IEditHandler> service contains an adapter for the WPF TextBox control. Therefore the developer does not need to care about an adapter for the UI control as long as an adequate adapter is registered at the AdapterFactoryCatalog service.

[ServiceDependency]
public IEditManager EditManager
{
    set
    {
        editManager = value;
        editManager.Register(scaleX);
        editManager.Register(scaleY);
    }
}

Listing 1

The implementation of the EditHandler service can be found in the Infrastructure.Module project.

Last edited Oct 8, 2007 at 1:48 PM by jbe2277, version 7

Comments

No comments yet.