Class: TECSCDE::ChangeSetControl::ChangeSetManager
- Defined in:
- lib/tecscde/change_set_control/change_set_manager.rb
Overview
ChangeSetMangager class
contain all changes & execute undo
Instance Method Summary collapse
-
#add_change_set(tm_object) ⇒ Object
ChangeSetManager#add_change_set at the time modifying tm_object, record only the changed tm_object.
-
#initialize ⇒ ChangeSetManager
constructor
A new instance of ChangeSetManager.
- #modified? ⇒ Boolean
- #redo ⇒ Object
- #set_undo_point ⇒ Object
-
#undo ⇒ Object
assumed undo is done just after set_undo_point (this means @change_set_next has no contents).
Constructor Details
#initialize ⇒ ChangeSetManager
Returns a new instance of ChangeSetManager.
6 7 8 9 10 |
# File 'lib/tecscde/change_set_control/change_set_manager.rb', line 6 def initialize @change_no = 0 @change_set_list = [] @change_set_next = ChangeSet.new(@change_no) end |
Instance Method Details
#add_change_set(tm_object) ⇒ Object
ChangeSetManager#add_change_set
at the time modifying tm_object, record only the changed tm_object
14 15 16 17 |
# File 'lib/tecscde/change_set_control/change_set_manager.rb', line 14 def add_change_set(tm_object) # TECSCDE.logger.info("add_change_set #{tm_object.class} change_set=#{@change_no}") @change_set_next.add(tm_object) end |
#modified? ⇒ Boolean
57 58 59 |
# File 'lib/tecscde/change_set_control/change_set_manager.rb', line 57 def modified? @change_no > 1 end |
#redo ⇒ Object
50 51 52 53 54 55 |
# File 'lib/tecscde/change_set_control/change_set_manager.rb', line 50 def redo return if @change_set_list.length <= @change_no + 1 @change_no += 1 TECSCDE.logger.info("* redo change_no=#{@change_no}") @change_set_list[@change_no].apply end |
#set_undo_point ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tecscde/change_set_control/change_set_manager.rb', line 19 def set_undo_point count = @change_set_next.set_undo_point if count > 0 # TECSCDE.logger.info("* set_undo_point change_no=#{@change_no}, count=#{count}") # p "* set_undo_point change_no=#{@change_no}, count=#{count}\n" @change_set_list[@change_no] = @change_set_next @change_no += 1 @change_set_next = ChangeSet.new(@change_no) if @change_set_list.length > @change_no TECSCDE.logger.info("truncate undo buffer #{@change_set_list.length} to #{@change_no}") # print( "range: #{(@change_no)..(@change_set_list.length)-1}\n" ) # p "length0=#{@change_set_list.length}" @change_set_list.slice!(@change_no..(@change_set_list.length - 1)) # p "length1=#{@change_set_list.length}" end else TECSCDE.logger.info("* set_undo_point: nothing changed") end end |
#undo ⇒ Object
assumed undo is done just after set_undo_point (this means @change_set_next has no contents)
41 42 43 44 45 46 47 48 |
# File 'lib/tecscde/change_set_control/change_set_manager.rb', line 41 def undo return unless modified? @change_no -= 1 TECSCDE.logger.info("* undo change_no=#{@change_no}") @change_set_list[@change_no].apply # TECSCDE.logger.info("* undo1 change_no=#{@change_no}") @change_set_next = ChangeSet.new(@change_no) end |