Class: Ruvi::EditorApp::DiffLogger::Difference

Inherits:
Object
  • Object
show all
Defined in:
lib/timemachine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, line_num = nil) ⇒ Difference

note - line_num.nil? -> generated via *Difference.from_s



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/timemachine.rb', line 291

def initialize buffer, line_num = nil
    @buffer = buffer
    @old_cursor, @new_cursor = nil, nil
    if line_num.nil?
        yield self
        @buffer.dlog << self
    else
        dbg(:ufw) { "a #{self.type.inspect} was new'ed" }
        @line_num = line_num
        pre_mod_callback
        yield # must provide a constructor block, for before and after data to be picked up
        post_mod_callback
        @buffer.dlog << self
        notify_of_play
    end
end

Instance Attribute Details

#new_cursorObject

Returns the value of attribute new_cursor.



289
290
291
# File 'lib/timemachine.rb', line 289

def new_cursor
  @new_cursor
end

#old_cursorObject

Returns the value of attribute old_cursor.



289
290
291
# File 'lib/timemachine.rb', line 289

def old_cursor
  @old_cursor
end

Class Method Details

.inherited(sub) ⇒ Object



356
357
358
# File 'lib/timemachine.rb', line 356

def Difference.inherited sub
    DifferenceTypes::instance.register_change_type sub
end

.transition_regexpObject



349
350
351
352
# File 'lib/timemachine.rb', line 349

def Difference.transition_regexp
    point_re = /\((.*?),(.*?)\)/
    /\[#{point_re }->#{point_re}]/
end

Instance Method Details

#correct_cursor_positionObject



329
330
331
332
333
334
335
336
337
338
# File 'lib/timemachine.rb', line 329

def correct_cursor_position
    # HACK - its possible that we went out of buffer!
    #        until we have made a method for making checks
    #        on the current position in the buffer and the 
    #        stored time_machine cursor position. then we
    #        should keep this workaround *just in case*
    if @buffer.y > @buffer.last_line_num
        @buffer.y = @buffer.last_line_num
    end
end

#cursor_transitionObject



353
354
355
# File 'lib/timemachine.rb', line 353

def cursor_transition
    "(#{@old_cursor.x},#{@old_cursor.y})->(#{@new_cursor.x},#{@new_cursor.y})"
end

#finalizeObject



319
320
321
322
# File 'lib/timemachine.rb', line 319

def finalize
    # test - TODO - no idea...
    @buffer.dlog.finalize
end

#notify_of_playObject



307
308
309
310
311
312
# File 'lib/timemachine.rb', line 307

def notify_of_play
    @buffer.app.change_listeners.each {
       |listener|
       listener.call self, true
    }
end

#notify_of_unplayObject



313
314
315
316
317
318
# File 'lib/timemachine.rb', line 313

def notify_of_unplay
    @buffer.app.change_listeners.each {
       |listener|
       listener.call self, false
    }
end

#post_mod_callbackObject



326
327
328
# File 'lib/timemachine.rb', line 326

def post_mod_callback
    @new_cursor = Point.new(@buffer.x, @buffer.y)
end

#pre_mod_callbackObject



323
324
325
# File 'lib/timemachine.rb', line 323

def pre_mod_callback
    @old_cursor = Point.new(@buffer.x, @buffer.y)
end

#redoObject



344
345
346
347
348
# File 'lib/timemachine.rb', line 344

def redo
    notify_of_unplay
    @buffer.move_to @new_cursor.x, @new_cursor.y
    correct_cursor_position
end

#undoObject



339
340
341
342
343
# File 'lib/timemachine.rb', line 339

def undo
    notify_of_play
    @buffer.move_to @old_cursor.x, @old_cursor.y
    correct_cursor_position
end