Class: Ruber::AnnotationModel

Inherits:
KTextEditor::AnnotationModel
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruber/editor/document.rb

Defined Under Namespace

Classes: Annotation

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#find!

Constructor Details

#initialize(doc) ⇒ AnnotationModel

Returns a new instance of AnnotationModel.



541
542
543
544
545
546
# File 'lib/ruber/editor/document.rb', line 541

def initialize doc
  super()
  @doc = doc
  @annotations = Dictionary.alpha
  connect self, SIGNAL('annotation_changed(int)'), self, SIGNAL('lineChanged(int)')
end

Class Attribute Details

.annotation_typesObject (readonly)

Returns the value of attribute annotation_types.



532
533
534
# File 'lib/ruber/editor/document.rb', line 532

def annotation_types
  @annotation_types
end

Class Method Details

.register_annotation_type(type, back = nil, fore = nil) ⇒ Object

Raises:

  • (ArgumentError)


535
536
537
538
539
# File 'lib/ruber/editor/document.rb', line 535

def self.register_annotation_type type, back = nil, fore = nil
  raise ArgumentError, "Annotation type #{type} has already been added" if 
  @annotation_types.has_key?(type)
  @annotation_types[type] = [back, fore].map{|i| i ? Qt::Variant.fromValue(i) : Qt::Variant.new}
end

Instance Method Details

#add_annotation(*args) ⇒ Object



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/ruber/editor/document.rb', line 548

def add_annotation *args
  a = args.size == 1 ? args[0] : Annotation.new( *args )
  # TODO: see why this sometimes gives extremely weird errors
  #The begin/rescue clause is there to find out why sometimes I get a crash saying:
  # `<': comparison of Fixnum with Qt::Variant failed (ArgumentError)
  #       begin
  
  #         raise IndexError, "Invalid line: #{a.line}" unless a.line < @doc.lines
  #       rescue ArgumentError
  #         puts "a.line: #{a.line}(#{a.line.class})"
  #         puts "@doc.lines: #{@doc.lines}(#{@doc.lines.class})"
  #       end
  @annotations[a.line] = a
  emit annotations_changed
  emit annotation_changed( a.line)
end

#annotation(line) ⇒ Object Also known as: []



577
578
579
# File 'lib/ruber/editor/document.rb', line 577

def annotation line
  @annotations[line]
end

#clearObject



594
595
596
597
598
# File 'lib/ruber/editor/document.rb', line 594

def clear
  @annotations.clear
  emit annotations_changed
  emit reset
end

#data(line, role) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
# File 'lib/ruber/editor/document.rb', line 565

def data line, role
  a = @annotations[line]
  return Qt::Variant.new unless a
  case role
  when Qt::DisplayRole then Qt::Variant.new a.msg
  when Qt::ToolTipRole then Qt::Variant.new a.tool_tip
  when Qt::ForegroundRole then self.class.annotation_types[a.type][1]
  when Qt::BackgroundRole then self.class.annotation_types[a.type][0]
  else Qt::Variant.new
  end
end

#eachObject



607
608
609
# File 'lib/ruber/editor/document.rb', line 607

def each
  @annotations.each_pair{|k, v| yield v}
end

#empty?Boolean

Returns:

  • (Boolean)


590
591
592
# File 'lib/ruber/editor/document.rb', line 590

def empty?
  @annotations.empty?
end

#has_annotation?(line) ⇒ Boolean

Returns:

  • (Boolean)


582
583
584
# File 'lib/ruber/editor/document.rb', line 582

def has_annotation? line
  @annotations.has_key? line
end

#has_annotations?Boolean

Returns:

  • (Boolean)


586
587
588
# File 'lib/ruber/editor/document.rb', line 586

def has_annotations?
  !@annotations.empty?
end

#remove_annotation(line) ⇒ Object



600
601
602
603
604
605
# File 'lib/ruber/editor/document.rb', line 600

def remove_annotation line
  if @annotations.delete line
    emit annotations_changed 
    emit annotation_changed( line )
  end
end