[ Pobierz całość w formacie PDF ]
.The action has the following code that saves thecurrent action manager settings to a memory stream, converts it to text, and shows it insidethe memo (refer to Chapter 5 for more information about streaming):procedure TForm1.ActionShowStatusExecute(Sender: TObject);varmemStr, memStr2: TMemoryStream;beginmemStr := TMemoryStream.Create;trymemStr2 := TMemoryStream.Create;tryActionManager1.SaveToStream(memStr);memStr.Position := 0;ObjectBinaryToText(memStr, memStr2);memStr2.Position := 0;RichEdit1.Lines.LoadFromStream(memStr2);finallymemStr2.Free;end;finallymemStr.Free;end;end;The output you obtain is the textual version of the settings file automatically updated ateach execution of the program.Here a small portion of this file, with the details of one ofpull-down menus and plenty of extra comments:item // File pulldown of the main menu action barItems =Caption = &FileLastSession = 19UsageCount = 5 // the sum of the usage count of the itemsendPorting an Existing ProgramIf this architecture is nice, you ll probably need to redo most of your applications to take advan-tage of it.However, if you re already using actions (with the ActionList component), this con-version will be much simpler.In fact, the ActionManager has its own set of actions but can alsouse actions from another ActionManager or ActionList.The LinkedActionListsproperty ofthe ActionManager is a collection of other containers of actions (ActionLists or ActionMan-agers), which can be associated with the current one.Associating all the various groups ofaction is useful to let a user customize the entire user interface with a single dialog box.If you hook external actions and open the ActionManager editor, you ll see in the Actionspage a combo box listing the current ActionManager plus the other action containers linkedto it.You can choose one of these containers to see its set of actions and change their proper-ties.The All Action option of this combo box allows you to work on all of the actions fromthe various containers at once, but I ve noticed that at startup it is selected but not alwayseffective.Reselect it to actually see all of the actions.As an example of porting an existing application, I ve extended the program built through-out this chapter, into the MdEdit3 example.This example uses the same action list of theprevious version hooked to an ActionManager that has the extra customize property, to letCopyright ©2001 SYBEX, Inc., Alameda, CA www.sybex.com2874c08.qxd 7/2/01 4:27 PM Page 316316 Chapter8 " Building the User Interfaceusers rearrange the user interface.Differently from the earlier AcManDemo program, theMdEdit3 example uses a ControlBar as a container for the action bars (a menu, three tool-bars, and the usual combo boxes) and has full support for dragging them outside of the con-tainer as floating bars and dropping them into the lower ControlBar.To accomplish this, I only had to modify the source code slightly to refer to the new classesfor the containers (that is, TCustomActionToolBar instead of TToolBar) in the ControlBar-LowerDockOver method.I also found out that the OnEndDock event of the ActionToolBar com-ponent passes as parameter an empty target when the system creates a floating form to hostthe control, so that I couldn t easily give to this forms a new custom caption (see the EndDockmethod of the form).Using List ActionsWe ll see more examples of the use of this architecture in the chapters devoted to MDI anddatabase programming.For the moment, I just want to add an extra example showing how touse a rather complex group of standard actions introduced in Delphi 6, the list actions.Listactions, in fact, comprise two different groups.Some of them (such as the Move, Copy,Delete, Clear, and Select All) actions are normal actions working on list boxes or other lists.The VirtualListAction and StaticListAction elements, instead, define actions based multiplechoices, which are going to be displayed in a toolbar as a combo box.The ListActions demo highlights both groups of list actions, as its ActionManager has fiveof them, displayed on two separate toolbars.This is a summary of the actions of the actionsmanager (I ve omitted the action bars portion of the component s DFM file):object ActionManager1: TActionManagerActionBars.SessionCount = 1ActionBars =object StaticListAction1: TStaticListActionCaption = NumbersItems.CaseSensitive = FalseItems.SortType = stNoneItems =OnItemSelected = ListActionItemSelectedendobject VirtualListAction1: TVirtualListActionCaption = ItemsCopyright ©2001 SYBEX, Inc., Alameda, CA www.sybex.com2874c08.qxd 7/2/01 4:27 PM Page 317The ActionManager Architecture 317OnGetItem = VirtualListAction1GetItemOnGetItemCount = VirtualListAction1GetItemCountOnItemSelected = ListActionItemSelectedendobject ListControlCopySelection1: TListControlCopySelectionCaption = CopyDestination = ListBox2ListControl = ListBox1endobject ListControlDeleteSelection1: TListControlDeleteSelectionCaption = Deleteendobject ListControlMoveSelection2: TListControlMoveSelectionCaption = MoveDestination = ListBox2ListControl = ListBox1endendThe program has also two list boxes in its form, used as action targets.The Copy and Moveactions are tied to these two list boxes by their ListControl and Destinationproperties.TheDelete action, instead, automatically works with the list box having the input focus.The StaticListAction defines a series of alternative items, in its Items collection.This isnot a plain string list, as any item has also an ImageIndex, which allows turning the combobox in graphical selection.You can, of course, add more items to this list programmatically.However, in case of a highly dynamic list, you can also use the VirtualListAction.This com-ponent doesn t define a list of items but has two events you can use to provide strings andimages for the list.The OnGetItemCount event allows you to indicate the number of items todisplay; the OnGetItem event is then called for each specific item.In the ListActions demo, the VirtualListAction has the following event handlers for its def-inition, producing the list you can see in the active combo box of Figure 8.12:procedure TForm1.VirtualListAction1GetItemCount(Sender: TCustomListAction;var Count: Integer);beginCount := 100;end;procedure TForm1.VirtualListAction1GetItem(Sender: TCustomListAction;const Index: Integer; var Value: String;var ImageIndex: Integer; var Data: Pointer);beginValue := Item + IntToStr (Index);end;Copyright ©2001 SYBEX, Inc., Alameda, CA www.sybex.com2874c08.qxd 7/2/01 4:27 PM Page 318318 Chapter8 " Building the User InterfaceFI GURE 8.12:The ListActions applicationhas a toolbar hosting astatic list and a virtual one.NOTEI thought that the virtual action items were actually requested only when needed to displaythem, making this actually a virtual list
[ Pobierz całość w formacie PDF ]