正在加载图片...
702 INHERITANCE CASE STUDY:"UNDO"IN AN INTERACTIVE SYSTEM $21.2 This implements the convention suggested earlier that Undo applied just after Undo means Redo.A request to Undo or Redo is ignored if there is nothing to undo or redo.In a simple text editor with a keyboard interface,"Decode request"would analyze the user input,looking for such codes as control-I (for insert line),control-D (for delete line)and so on.With graphical interfaces you have to determine what input the user has entered, such as a choice in a menu,a button clicked in a menu,a key pressed. Remembering the last command With the notion of command object we can be more specific about the operations performed by basic interactive step.We will use an attribute requested:COMMAND --Command requested by interactive user representing the latest command that we have to execute,undo or redo.This enables us to refine the preceding scheme of basic interactive step into: "Get and decode latest user request" if“Request is normal command(not Undo)”then "Create appropriate command object and attach it to requested" --requested is created as an instance of some -descendant of COMMAND,such as LINE DELETION --(This instruction is detailed below.) Dynamic requested.execute;undoing mode :False Binding elseif "request is Undo"and requested /Void then if undoing mode then "This is a Redo;details left to the reader" else equested.undo undoing mode:=True end else "Erroneous request:output warning,or do nothing" end The boolean entity undoing mode determines whether the last operation was an Undo.In Exercise E21.2. this case an immediately following Undo request would mean a Redo,although the page 716. straightforward details have been left to the reader;we will see the full details of Redo implementation in the more interesting case of a multi-level mechanism. The information stored before each command execution is an instance of some See“Requirements descendant of COMMAND such as LINE DELET/ON.This means that,as announced,the on the solution”, solution satisfies the property labeled U3 in the list ofrequirements:what we store for each page 697. command is the difference between the new state and the previous one,not the full state.702 INHERITANCE CASE STUDY: “UNDO” IN AN INTERACTIVE SYSTEM §21.2 This implements the convention suggested earlier that Undo applied just after Undo means Redo. A request to Undo or Redo is ignored if there is nothing to undo or redo. In a simple text editor with a keyboard interface, “Decode request” would analyze the user input, looking for such codes as control-I (for insert line), control-D (for delete line) and so on. With graphical interfaces you have to determine what input the user has entered, such as a choice in a menu, a button clicked in a menu, a key pressed. Remembering the last command With the notion of command object we can be more specific about the operations performed by basic_interactive_step. We will use an attribute requested: COMMAND -- Command requested by interactive user representing the latest command that we have to execute, undo or redo. This enables us to refine the preceding scheme of basic_interactive_step into: “Get and decode latest user request” if “Request is normal command (not Undo)” then “Create appropriate command object and attach it to requested ” -- requested is created as an instance of some -- descendant of COMMAND, such as LINE_DELETION -- (This instruction is detailed below.) ; undoing_mode := False elseif “request is Undo” and requested /= Void then if undoing_mode then “This is a Redo; details left to the reader” else ; undoing_mode := True end else “Erroneous request: output warning, or do nothing” end The boolean entity undoing_mode determines whether the last operation was an Undo. In this case an immediately following Undo request would mean a Redo, although the straightforward details have been left to the reader; we will see the full details of Redo implementation in the more interesting case of a multi-level mechanism. The information stored before each command execution is an instance of some descendant of COMMAND such as LINE_DELETION. This means that, as announced, the solution satisfies the property labeled U3 in the list of requirements: what we store for each command is the difference between the new state and the previous one, not the full state. requested ● execute Dynamic Binding requested ● undo Exercise E21.2, page 716. See “Requirements on the solution”, page 697
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有