Class: JLDrill::LoadReferenceContext

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

Overview

Load the reference dictionary

Instance Attribute Summary

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) ⇒ LoadReferenceContext

Returns a new instance of LoadReferenceContext.



12
13
14
15
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 12

def initialize(viewBridge)
	super(viewBridge)
          @loadFileContext = LoadFileContext.new(@viewBridge)
end

Instance Method Details

#createViewsObject



17
18
19
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 17

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

#destroyViewsObject



21
22
23
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 21

def destroyViews
    @mainView = nil
end

#dictionaryName(options) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 25

def dictionaryName(options)
    if !options.nil? && !options.dictionary.nil?
        return options.dictionary
    else
        return Config::DICTIONARY_FILE
    end
end

#enter(parent, reference, deinflect, options) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 78

def enter(parent, reference, deinflect, options)
    super(parent)
    if (options.language == "Chinese")
        parent.reference = CEDictionary.new
    else
        parent.reference = JEDictionary.new
    end
    loadReference(parent.reference, deinflect, getFilename(options))
end

#exitLoadReferenceContextObject



66
67
68
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 66

def exitLoadReferenceContext
    self.exit
end

#getDeinflectionFilenameObject



48
49
50
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 48

def getDeinflectionFilename
    return Config::resolveDataFile(Config::DEINFLECTION_FILE)
end

#getFilename(options) ⇒ Object

Returns the filename of the dictionary including the path



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 34

def getFilename(options)
    dictFilename = File.join(Config::DICTIONARY_DIR, 
                             dictionaryName(options))
    retVal = Config::resolveDataFile(dictFilename)

    # Debian installs the edict dictionary in /usr/share/edict
    # so it might not be in a dict directory.
    if retVal.nil?
        retVal = Config::resolveDataFile(dictionaryName(options))
    end

    return retVal
end

#loadDeinflection(deinflect, filename) ⇒ Object



52
53
54
55
56
57
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 52

def loadDeinflection(deinflect, filename)
    @loadFileContext.onExit do
        exitLoadReferenceContext
    end
    @loadFileContext.enter(self, deinflect, filename)
end

#loadReference(reference, deinflect, filename) ⇒ Object



59
60
61
62
63
64
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 59

def loadReference(reference, deinflect, filename)
    @loadFileContext.onExit do
       loadDeinflection(deinflect, getDeinflectionFilename) 
    end
    @loadFileContext.enter(self, reference, filename)
end

#startLongEventObject



70
71
72
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 70

def startLongEvent()
    @parent.startLongEvent()
end

#stopLongEventObject



74
75
76
# File 'lib/jldrill/contexts/LoadReferenceContext.rb', line 74

def stopLongEvent()
    @parent.stopLongEvent()
end