indexing description: "[ List of recent commands ]" date: "$Date$" revision: "$Revision$" class HISTORY inherit DS_BILINKED_LIST [COMMAND] export {NONE} all redefine make end create make feature -- Initialization make is -- Creates a history do Precursor {DS_BILINKED_LIST} create cursor.make (current) cursor.start ensure then cursor.off end feature -- Access execute_successful: BOOLEAN -- has the execute command been executed successfully? undo_successful: BOOLEAN -- has the undo command been executed successfully? redo_successful: BOOLEAN -- has the redo command been executed successfully? error_code: INTEGER -- error code from COMMAND elements: INTEGER is -- returns how many elements are in the history list do Result := count end feature -- Element Change execute (command: COMMAND; args: TUPLE) is -- executes a command. do command.execute (args) execute_successful := False if command.execute_successful then execute_successful := True if count = 0 then -- if this was the first command in the list force_last (command) cursor.start elseif not cursor.is_last then -- if there are more commands in the future, delete them if cursor.before then wipe_out else from variant count until cursor.is_last loop cursor.remove_right end end force_last (command) cursor.forth else force_last (command) cursor.forth end else error_code := command.error_code end ensure cursor_at_last_position: command.execute_successful implies cursor.is_last end undo (args: TUPLE) is -- undo the last step. require can_undo do cursor.item.undo (args) undo_successful := False if cursor.item.undo_successful then cursor.back undo_successful := True end end redo (args: TUPLE) is -- undo the last step. require can_redo do cursor.forth cursor.item.redo (args) if cursor.item.redo_successful then redo_successful := True else redo_successful := False cursor.back end end feature -- Status Report can_undo: BOOLEAN is -- Is there a step to undo? do Result := (not cursor.off) ensure result_correct: Result = (not cursor.off) end can_redo: BOOLEAN is -- Is there a step to redo? do Result := (not cursor.is_last) and cursor.container.count > 0 ensure result_correct: Result = ((not cursor.is_last) and cursor.container.count > 0) end feature {NONE} -- Implementation cursor: DS_BILINKED_LIST_CURSOR [COMMAND] -- A cursor of the current position in the history invariant cursor_not_void: cursor /= Void end