Sha256: 79a397decda941e4fbb2d621f8a4d313c2fcd21aa9013c938bd719b0db85ae02

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'Context/Context'
require 'Context/Bridge'
require 'jldrill/model/Config'
require 'jldrill/contexts/FileProgressContext'

module JLDrill

    # Shows progress while merging two quiz files
	class MergeQuizContext < FileProgressContext
		
		def initialize(viewBridge)
			super(viewBridge)
            @quiz1 = nil
            @quiz2 = nil
		end

        def getFilename
            return "Merging #{@quiz1.name} with #{@quiz2.name} data"
        end

        def readFile
            size = @quiz2.length
            pos = 0
            sortedItems = @quiz1.contents.getSortedItems
            appendedItems = @quiz2.contents.allItems
            @mainView.idle_add do
                limit = pos + @quiz1.stepSize
                if limit > size then limit = size end
                while (pos < limit)
                    item = appendedItems[pos]
                    if !sortedItems.binarySearch(item)
                        item.position = -1
                        @quiz1.contents.addItem(item, item.bin)
                    end
                    pos += 1
                    @mainView.update(pos.to_f / size.to_f)
                end
                pos >= size
            end
        end

        def isValid?(parent)
            return !parent.nil? && !@quiz1.nil? && !@quiz2.nil?
        end

        def enter(parent, quiz1, quiz2)
            @quiz1 = quiz1
            @quiz2 = quiz2
            super(parent)
        end

        def exit
            @quiz1.updateLoad
            super
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.5.1.7 lib/jldrill/contexts/MergeQuizContext.rb