Class: JLDrill::LoadQuizContext

Inherits:
Context::Context show all
Defined in:
lib/jldrill/contexts/LoadQuizContext.rb

Instance Attribute Summary collapse

Attributes inherited from Context::Context

#mainView, #parent, #viewBridge

Instance Method Summary collapse

Methods inherited from Context::Context

#addView, #exit, #isEntered?, #onExit, #peekAtView, #setupViews

Constructor Details

#initialize(viewBridge) ⇒ LoadQuizContext

Returns a new instance of LoadQuizContext.



17
18
19
20
21
22
23
24
25
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 17

def initialize(viewBridge)
	super(viewBridge)
          @loadFileContext = LoadFileContext.new(@viewBridge)
          @getFilenameContext = GetFilenameContext.new(@viewBridge)
          # Set the initial directory to the quiz Data dir
	@getFilenameContext.directory = Config::resolveDataFile(Config::QUIZ_DIR)
          @loadQuizFromEdictContext = LoadQuizFromEdictContext.new(@viewBridge)
          @filename = nil
end

Instance Attribute Details

#getFilenameContextObject (readonly)

Returns the value of attribute getFilenameContext.



15
16
17
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 15

def getFilenameContext
  @getFilenameContext
end

Instance Method Details

#createViewsObject



27
28
29
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 27

def createViews
    @mainView =  @viewBridge.VBoxView.new(self)
end

#destroyViewsObject



31
32
33
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 31

def destroyViews
    @mainView = nil
end

#enter(parent, quiz, filename = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 69

def enter(parent, quiz, filename=nil)
    super(parent)
    if filename.nil?
        filename = @getFilenameContext.enter(self, 
                                             GetFilenameContext::OPEN)
    end
    if filename.nil?
        exitLoadQuizContext
    else
        if !JLDrill::Quiz.drillFile?(filename)
            loadAsEdict(quiz, filename)
        else
            loadAsQuiz(quiz, filename)
        end
    end
end

#exitLoadQuizContextObject



35
36
37
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 35

def exitLoadQuizContext
    self.exit
end

#loadAsEdict(quiz, filename) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 39

def loadAsEdict(quiz, filename)
    if quiz.options.language == "Chinese"
        edict = CEDictionary.new
    else
        edict = JEDictionary.new
    end
    @loadFileContext.onExit do
        @loadQuizFromEdictContext.onExit do
            exitLoadQuizContext
        end
        @loadQuizFromEdictContext.enter(self, quiz, edict)
    end
    @loadFileContext.enter(self, edict, filename)
end

#loadAsQuiz(quiz, filename) ⇒ Object



54
55
56
57
58
59
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 54

def loadAsQuiz(quiz, filename)
    @loadFileContext.onExit do
        exitLoadQuizContext
    end
    @loadFileContext.enter(self, quiz, filename)
end

#startLongEventObject



61
62
63
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 61

def startLongEvent()
    @parent.startLongEvent()
end

#stopLongEventObject



65
66
67
# File 'lib/jldrill/contexts/LoadQuizContext.rb', line 65

def stopLongEvent()
    @parent.stopLongEvent()
end